diff --git a/android/src/com/mapswithme/country/DownloadAdapter.java b/android/src/com/mapswithme/country/DownloadAdapter.java index ce0bd57d2d..a2deccbcc5 100644 --- a/android/src/com/mapswithme/country/DownloadAdapter.java +++ b/android/src/com/mapswithme/country/DownloadAdapter.java @@ -228,7 +228,7 @@ class DownloadAdapter extends BaseAdapter else { mStorage.downloadCountry(idx); - Statistics.INSTANCE.trackCountryDownload(mContext); + Statistics.INSTANCE.trackCountryDownload(); } } @@ -260,7 +260,7 @@ class DownloadAdapter extends BaseAdapter else { mStorage.downloadCountry(idx); - Statistics.INSTANCE.trackCountryUpdate(mContext); + Statistics.INSTANCE.trackCountryUpdate(); } } @@ -276,7 +276,7 @@ class DownloadAdapter extends BaseAdapter public void onClick(DialogInterface dlg, int which) { mStorage.deleteCountry(idx); - Statistics.INSTANCE.trackCountryDeleted(mContext); + Statistics.INSTANCE.trackCountryDeleted(); dlg.dismiss(); } }) diff --git a/android/src/com/mapswithme/maps/MWMActivity.java b/android/src/com/mapswithme/maps/MWMActivity.java index bb7836168c..874fa72092 100644 --- a/android/src/com/mapswithme/maps/MWMActivity.java +++ b/android/src/com/mapswithme/maps/MWMActivity.java @@ -873,7 +873,7 @@ public class MWMActivity extends NvEventQueueActivity else Yota.showMap(getApplicationContext(), latLon[0], latLon[1], zoom, null, locState.hasPosition()); - Statistics.INSTANCE.trackBackscreenCall(getApplication(), "Map"); + Statistics.INSTANCE.trackBackscreenCall("Map"); } }); } diff --git a/android/src/com/mapswithme/maps/SearchActivity.java b/android/src/com/mapswithme/maps/SearchActivity.java index 6ed066b604..bdee633352 100644 --- a/android/src/com/mapswithme/maps/SearchActivity.java +++ b/android/src/com/mapswithme/maps/SearchActivity.java @@ -420,7 +420,7 @@ public class SearchActivity extends MapsWithMeBaseListActivity implements Locati break; case CATEGORY_TYPE: final String category = getCategoryName(mCategories[position]); - Statistics.INSTANCE.trackSearchCategoryClicked(mContext, category); + Statistics.INSTANCE.trackSearchCategoryClicked(category); return category + ' '; } diff --git a/android/src/com/mapswithme/maps/bookmarks/BookmarkActivity.java b/android/src/com/mapswithme/maps/bookmarks/BookmarkActivity.java index ff966c481d..0c4df3e7eb 100644 --- a/android/src/com/mapswithme/maps/bookmarks/BookmarkActivity.java +++ b/android/src/com/mapswithme/maps/bookmarks/BookmarkActivity.java @@ -173,7 +173,7 @@ public class BookmarkActivity extends MapsWithMeBaseActivity final String descr = mDescr.getText().toString().trim(); final String oldDescr = mPin.getBookmarkDescription().trim(); if (!TextUtils.equals(descr, oldDescr)) - Statistics.INSTANCE.trackDescriptionChanged(this); + Statistics.INSTANCE.trackDescriptionChanged(); mPin.setParams(mName.getText().toString(), mIcon, descr); } @@ -198,7 +198,7 @@ public class BookmarkActivity extends MapsWithMeBaseActivity refreshValuesInViews(); if (mCurrentCategoryId != mPin.getCategoryId()) - Statistics.INSTANCE.trackGroupChanged(this); + Statistics.INSTANCE.trackGroupChanged(); mCurrentCategoryId = mPin.getCategoryId(); } diff --git a/android/src/com/mapswithme/maps/bookmarks/ChooseBookmarkCategoryActivity.java b/android/src/com/mapswithme/maps/bookmarks/ChooseBookmarkCategoryActivity.java index 367fa90b6e..e22f497337 100644 --- a/android/src/com/mapswithme/maps/bookmarks/ChooseBookmarkCategoryActivity.java +++ b/android/src/com/mapswithme/maps/bookmarks/ChooseBookmarkCategoryActivity.java @@ -176,7 +176,7 @@ public class ChooseBookmarkCategoryActivity extends AbstractBookmarkCategoryActi getAdapter().chooseItem(index); - Statistics.INSTANCE.trackGroupCreated(ChooseBookmarkCategoryActivity.this); + Statistics.INSTANCE.trackGroupCreated(); } private void switchToAddButton() diff --git a/android/src/com/mapswithme/maps/bookmarks/data/BookmarkManager.java b/android/src/com/mapswithme/maps/bookmarks/data/BookmarkManager.java index 822b3f9251..9f2e4f42fb 100644 --- a/android/src/com/mapswithme/maps/bookmarks/data/BookmarkManager.java +++ b/android/src/com/mapswithme/maps/bookmarks/data/BookmarkManager.java @@ -50,7 +50,7 @@ public class BookmarkManager public int addBookmarkToLastEditedCategory(String name, double lat, double lon) { - Statistics.INSTANCE.trackBookmarkCreated(mContext); + Statistics.INSTANCE.trackBookmarkCreated(); return nativeAddBookmarkToLastEditedCategory(name, lat, lon); } diff --git a/android/src/com/mapswithme/maps/location/LocationService.java b/android/src/com/mapswithme/maps/location/LocationService.java index 7349d7e16c..0a54f939a1 100644 --- a/android/src/com/mapswithme/maps/location/LocationService.java +++ b/android/src/com/mapswithme/maps/location/LocationService.java @@ -179,7 +179,7 @@ public class LocationService implements private void startWifiLocationUpdate() { - if (Statistics.INSTANCE.isStatisticsEnabled(mApplication) && + if (Statistics.INSTANCE.isStatisticsEnabled() && ConnectionState.isWifiConnected(mApplication)) { if (mWifiScanner == null) diff --git a/android/src/com/mapswithme/maps/location/WifiLocationScanner.java b/android/src/com/mapswithme/maps/location/WifiLocationScanner.java index d45bd4100a..f90e23a5ec 100644 --- a/android/src/com/mapswithme/maps/location/WifiLocationScanner.java +++ b/android/src/com/mapswithme/maps/location/WifiLocationScanner.java @@ -116,7 +116,7 @@ public class WifiLocationScanner extends BroadcastReceiver final StringBuilder json = new StringBuilder("{\"version\":\"2.0\""); appendId(json); - final boolean statsEnabled = Statistics.INSTANCE.isStatisticsEnabled(context); + final boolean statsEnabled = Statistics.INSTANCE.isStatisticsEnabled(); boolean wifiHeaderAdded = false; List results = mWifi.getScanResults(); diff --git a/android/src/com/mapswithme/maps/settings/SettingsActivity.java b/android/src/com/mapswithme/maps/settings/SettingsActivity.java index bdc2e095e0..0fc0355fad 100644 --- a/android/src/com/mapswithme/maps/settings/SettingsActivity.java +++ b/android/src/com/mapswithme/maps/settings/SettingsActivity.java @@ -77,7 +77,7 @@ public class SettingsActivity extends PreferenceActivity implements OnPreference lPref.setOnPreferenceChangeListener(this); final CheckBoxPreference allowStatsPreference = (CheckBoxPreference) findPreference(getString(R.string.pref_allow_stat)); - allowStatsPreference.setChecked(Statistics.INSTANCE.isStatisticsEnabled(this)); + allowStatsPreference.setChecked(Statistics.INSTANCE.isStatisticsEnabled()); allowStatsPreference.setOnPreferenceChangeListener(this); final CheckBoxPreference enableZoomButtons = (CheckBoxPreference) findPreference(getString(R.string.pref_zoom_btns_enabled)); @@ -401,7 +401,7 @@ public class SettingsActivity extends PreferenceActivity implements OnPreference if (key.equals(getString(R.string.pref_munits))) UnitLocale.setUnits(Integer.parseInt((String) newValue)); else if (key.equals(getString(R.string.pref_allow_stat))) - Statistics.INSTANCE.setStatEnabled(getApplicationContext(), (Boolean) newValue); + Statistics.INSTANCE.setStatEnabled((Boolean) newValue); else if (key.equals(getString(R.string.pref_zoom_btns_enabled))) MWMApplication.get().nativeSetBoolean(ZOOM_BUTTON_ENABLED, (Boolean) newValue); diff --git a/android/src/com/mapswithme/maps/widget/MapInfoView.java b/android/src/com/mapswithme/maps/widget/MapInfoView.java index 04e00145a3..dad9cdcc11 100644 --- a/android/src/com/mapswithme/maps/widget/MapInfoView.java +++ b/android/src/com/mapswithme/maps/widget/MapInfoView.java @@ -781,7 +781,7 @@ public class MapInfoView extends LinearLayout implements View.OnClickListener final String from = oldIcon.getName(); final String to = icon.getName(); if (!TextUtils.equals(from, to)) - Statistics.INSTANCE.trackColorChanged(getContext(), from, to); + Statistics.INSTANCE.trackColorChanged(from, to); mColorImage.setImageDrawable(UiUtils .drawCircleForPin(to, (int) getResources().getDimension(R.dimen.color_chooser_radius), getResources())); } diff --git a/android/src/com/mapswithme/util/FbUtil.java b/android/src/com/mapswithme/util/FbUtil.java index bd9ba8be69..2751481e01 100644 --- a/android/src/com/mapswithme/util/FbUtil.java +++ b/android/src/com/mapswithme/util/FbUtil.java @@ -25,7 +25,7 @@ public class FbUtil public static void activate(Context context) { - if (!Statistics.INSTANCE.isStatisticsEnabled(context)) + if (!Statistics.INSTANCE.isStatisticsEnabled()) return; mLogger.d("ACTIVATING"); diff --git a/android/src/com/mapswithme/util/ShareAction.java b/android/src/com/mapswithme/util/ShareAction.java index 5243f6ee41..406d7d706e 100644 --- a/android/src/com/mapswithme/util/ShareAction.java +++ b/android/src/com/mapswithme/util/ShareAction.java @@ -131,7 +131,7 @@ public abstract class ShareAction shareWithText(activity, body, subject); - Statistics.INSTANCE.trackPlaceShared(activity, this.getClass().getSimpleName()); + Statistics.INSTANCE.trackPlaceShared(this.getClass().getSimpleName()); } /** @@ -177,7 +177,7 @@ public abstract class ShareAction shareWithText(activity, body, ""); - Statistics.INSTANCE.trackPlaceShared(activity, this.getClass().getSimpleName()); + Statistics.INSTANCE.trackPlaceShared(this.getClass().getSimpleName()); } } diff --git a/android/src/com/mapswithme/util/statistics/Event.java b/android/src/com/mapswithme/util/statistics/Event.java index d44dee8b89..b1d9c086ca 100644 --- a/android/src/com/mapswithme/util/statistics/Event.java +++ b/android/src/com/mapswithme/util/statistics/Event.java @@ -2,38 +2,26 @@ package com.mapswithme.util.statistics; import com.mapswithme.util.Utils; -import java.util.List; import java.util.Map; public class Event { protected String mName; protected Map mParams; - protected List mEngines; public void setName(String name) { mName = name; } public void setParams(Map params) { mParams = params; } - public void setEngines(List engines) { mEngines = engines; } - public String getName() { return mName; } public Map getParams() { return mParams; } - public List getEngines() { return mEngines; } - public boolean hasParams() { return mParams != null && !mParams.isEmpty(); } - public void post() - { - for (StatisticsEngine engine : mEngines) - engine.postEvent(this); - } - @Override public String toString() { diff --git a/android/src/com/mapswithme/util/statistics/EventBuilder.java b/android/src/com/mapswithme/util/statistics/EventBuilder.java index 2b01b814c8..dfb28c1f0f 100644 --- a/android/src/com/mapswithme/util/statistics/EventBuilder.java +++ b/android/src/com/mapswithme/util/statistics/EventBuilder.java @@ -1,54 +1,34 @@ package com.mapswithme.util.statistics; import java.util.HashMap; -import java.util.List; import java.util.Map; public class EventBuilder { - protected Event mEvent = new Event(); - protected List mEngines; - - public EventBuilder(List engine) - { - mEngines = engine; - } + protected String mName; + protected Map mParams; public EventBuilder setName(String name) { - mEvent.setName(name); + mName = name; return this; } public EventBuilder addParam(String key, String value) { - Map params = mEvent.getParams(); - if (params == null) - params = new HashMap(); - params.put(key, value); - mEvent.setParams(params); + if (mParams == null) + mParams = new HashMap(); + mParams.put(key, value); return this; } - public EventBuilder reset() + public Event buildEvent() { - mEvent = new Event(); - return this; - } - - public Event getEvent() - { - mEvent.setEngines(mEngines); - return mEvent; - } - - public Event getSimpleNamedEvent(String name) - { - return reset().setName(name).getEvent(); - } - - public void setEngines(List engine) - { - mEngines = engine; + final Event event = new Event(); + event.setName(mName); + event.setParams(mParams); + mName = ""; + mParams = null; + return event; } } diff --git a/android/src/com/mapswithme/util/statistics/Statistics.java b/android/src/com/mapswithme/util/statistics/Statistics.java index 9a84839624..8a0ea09a46 100644 --- a/android/src/com/mapswithme/util/statistics/Statistics.java +++ b/android/src/com/mapswithme/util/statistics/Statistics.java @@ -1,8 +1,6 @@ package com.mapswithme.util.statistics; import android.app.Activity; -import android.content.Context; -import android.util.Log; import com.mapswithme.maps.MWMApplication; import com.mapswithme.maps.R; @@ -25,12 +23,12 @@ public enum Statistics private final static double ACTIVE_USER_MIN_FOREGROUND_TIME = 5 * 60; // 5 minutes - // Statistics - private EventBuilder mEventBuilder; private List mStatisticsEngines; - // Statistics params + private EventBuilder mEventBuilder; + private final boolean DEBUG = false; private final Logger mLogger = DEBUG ? SimpleLogger.get("MwmStatistics") : StubLogger.get(); + // Statistics counters private int mBookmarksCreated = 0; private int mSharedTimes = 0; @@ -64,221 +62,228 @@ public enum Statistics public static final String SETTINGS_COPYRIGHT = "Settings. Copyright."; public static final String SEARCH_KEY_CLICKED = "Search key pressed."; public static final String SEARCH_ON_MAP_CLICKED = "Search on map clicked."; - + public static final String STATISTICS_STATUS_CHANGED = "Statistics status changed"; } + public static class EventParam + { + public static final String FROM = "from"; + public static final String TO = "to"; + public static final String CATEGORY = "category"; + public static final String COUNT = "Count"; + public static final String CHANNEL = "Channel"; + public static final String CALLER_ID = "Caller ID"; + public static final String HAD_VALID_LOCATION = "Had valid location"; + public static final String DELAY_MILLIS = "Delay in milliseconds"; + public static final String BOOKMARK_NUMBER_AVG = "Average number of bmks"; + public static final String CATEGORIES_COUNT = "Categories count"; + public static final String FG_TIME = "Foreground time"; + public static final String PRO_STAT = "One time PRO stat"; + public static final String ENABLED = "Enabled"; + } private Statistics() { - Log.d(TAG, "Created Statistics instance."); + configure(); + mLogger.d("Created Statistics instance."); } - private EventBuilder getEventBuilder() + public void trackIfEnabled(Event event) { - return mEventBuilder; - } - - public void trackIfEnabled(Context context, Event event) - { - if (isStatisticsEnabled(context)) + if (isStatisticsEnabled()) { - event.post(); + post(event); mLogger.d("Posted event:", event); } else mLogger.d("Skipped event:", event); } - public void trackBackscreenCall(Context context, String from) + private void post(Event event) { - final Event event = getEventBuilder().reset() + for (StatisticsEngine engine : mStatisticsEngines) + engine.postEvent(event); + } + + public void trackBackscreenCall(String from) + { + final Event event = mEventBuilder .setName(EventName.YOTA_BACK_CALL) - .addParam("from", from) - .getEvent(); + .addParam(EventParam.FROM, from) + .buildEvent(); - trackIfEnabled(context, event); + trackIfEnabled(event); } - public void trackCountryDownload(Context context) + public void trackCountryDownload() { - trackIfEnabled(context, getEventBuilder().getSimpleNamedEvent(EventName.COUNTRY_DOWNLOAD)); + trackIfEnabled(mEventBuilder.setName(EventName.COUNTRY_DOWNLOAD).buildEvent()); } - public void trackCountryUpdate(Context context) + public void trackCountryUpdate() { - trackIfEnabled(context, getEventBuilder().getSimpleNamedEvent(EventName.COUNTRY_UPDATE)); + trackIfEnabled(mEventBuilder.setName(EventName.COUNTRY_UPDATE).buildEvent()); } - public void trackCountryDeleted(Context context) + public void trackCountryDeleted() { - trackIfEnabled(context, getEventBuilder().getSimpleNamedEvent(EventName.COUNTRY_DELETE)); + trackIfEnabled(mEventBuilder.setName(EventName.COUNTRY_DELETE).buildEvent()); } - public void trackSearchCategoryClicked(Context context, String category) + public void trackSearchCategoryClicked(String category) { - final Event event = getEventBuilder().reset() + final Event event = mEventBuilder .setName(EventName.SEARCH_CAT_CLICKED) - .addParam("category", category) - .getEvent(); + .addParam(EventParam.CATEGORY, category) + .buildEvent(); - trackIfEnabled(context, event); + trackIfEnabled(event); } - public void trackGroupChanged(Context context) + public void trackGroupChanged() { - trackIfEnabled(context, getEventBuilder().getSimpleNamedEvent(EventName.BOOKMARK_GROUP_CHANGED)); + trackIfEnabled(mEventBuilder.setName(EventName.BOOKMARK_GROUP_CHANGED).buildEvent()); } - public void trackDescriptionChanged(Context context) + public void trackDescriptionChanged() { - trackIfEnabled(context, getEventBuilder().getSimpleNamedEvent(EventName.DESCRIPTION_CHANGED)); + trackIfEnabled(mEventBuilder.setName(EventName.DESCRIPTION_CHANGED).buildEvent()); } - public void trackGroupCreated(Context context) + public void trackGroupCreated() { - trackIfEnabled(context, getEventBuilder().getSimpleNamedEvent(EventName.GROUP_CREATED)); + trackIfEnabled(mEventBuilder.setName(EventName.GROUP_CREATED).buildEvent()); } - public void trackSearchContextChanged(Context context, String from, String to) + public void trackSearchContextChanged(String from, String to) { - final Event event = getEventBuilder().reset() + final Event event = mEventBuilder .setName(EventName.SEARCH_CONTEXT_CNAHGED) - .addParam("from", from) - .addParam("to", to) - .getEvent(); + .addParam(EventParam.FROM, from) + .addParam(EventParam.TO, to) + .buildEvent(); - trackIfEnabled(context, event); + trackIfEnabled(event); } - public void trackColorChanged(Context context, String from, String to) + public void trackColorChanged(String from, String to) { - final Event event = getEventBuilder().reset() + final Event event = mEventBuilder .setName(EventName.COLOR_CHANGED) - .addParam("from", from) - .addParam("to", to) - .getEvent(); + .addParam(EventParam.FROM, from) + .addParam(EventParam.TO, to) + .buildEvent(); - trackIfEnabled(context, event); + trackIfEnabled(event); } - public void trackBookmarkCreated(Context context) + public void trackBookmarkCreated() { - final Event event = getEventBuilder().reset() + final Event event = mEventBuilder .setName(EventName.BOOKMARK_CREATED) - .addParam("Count", String.valueOf(++mBookmarksCreated)) - .getEvent(); + .addParam(EventParam.COUNT, String.valueOf(++mBookmarksCreated)) + .buildEvent(); - trackIfEnabled(context, event); + trackIfEnabled(event); } - public void trackPlaceShared(Context context, String channel) + public void trackPlaceShared(String channel) { - final Event event = getEventBuilder().reset() + final Event event = mEventBuilder .setName(EventName.PLACE_SHARED) - .addParam("Channel", channel) - .addParam("Count", String.valueOf(++mSharedTimes)) - .getEvent(); + .addParam(EventParam.CHANNEL, channel) + .addParam(EventParam.COUNT, String.valueOf(++mSharedTimes)) + .buildEvent(); - trackIfEnabled(context, event); + trackIfEnabled(event); } public void trackApiCall(ParsedMmwRequest request) { if (request != null && request.getCallerInfo() != null) { - ensureConfigured(MWMApplication.get()); //@formatter:off - final Event event = getEventBuilder().reset() + final Event event = mEventBuilder .setName(EventName.API_CALLED) - .addParam("Caller ID", request.getCallerInfo().packageName) - .getEvent(); + .addParam(EventParam.CALLER_ID, request.getCallerInfo().packageName) + .buildEvent(); //@formatter:on - trackIfEnabled(MWMApplication.get(), event); + trackIfEnabled(event); } } public void trackWifiConnected(boolean hasValidLocation) { - ensureConfigured(MWMApplication.get()); - final Event event = getEventBuilder().reset(). + final Event event = mEventBuilder. setName(EventName.WIFI_CONNECTED). - addParam("Had valid location", String.valueOf(hasValidLocation)). - getEvent(); - trackIfEnabled(MWMApplication.get(), event); + addParam(EventParam.HAD_VALID_LOCATION, String.valueOf(hasValidLocation)). + buildEvent(); + trackIfEnabled(event); } public void trackWifiConnectedAfterDelay(boolean isLocationExpired, long delayMillis) { - ensureConfigured(MWMApplication.get()); - final Event event = getEventBuilder().reset(). + final Event event = mEventBuilder. setName(EventName.WIFI_CONNECTED). - addParam("Had valid location", String.valueOf(isLocationExpired)). - addParam("Delay in milliseconds", String.valueOf(delayMillis)). - getEvent(); - trackIfEnabled(MWMApplication.get(), event); + addParam(EventParam.HAD_VALID_LOCATION, String.valueOf(isLocationExpired)). + addParam(EventParam.DELAY_MILLIS, String.valueOf(delayMillis)). + buildEvent(); + trackIfEnabled(event); } public void trackDownloadCountryNotificationShown() { - ensureConfigured(MWMApplication.get()); - getEventBuilder().getSimpleNamedEvent(EventName.DOWNLOAD_COUNTRY_NOTIFICATION_SHOWN).post(); + trackIfEnabled(mEventBuilder.setName(EventName.DOWNLOAD_COUNTRY_NOTIFICATION_SHOWN).buildEvent()); } public void trackDownloadCountryNotificationClicked() { - ensureConfigured(MWMApplication.get()); - getEventBuilder().getSimpleNamedEvent(EventName.DOWNLOAD_COUNTRY_NOTIFICATION_CLICKED).post(); + trackIfEnabled(mEventBuilder.setName(EventName.DOWNLOAD_COUNTRY_NOTIFICATION_CLICKED).buildEvent()); } public void trackSimpleNamedEvent(String eventName) { - ensureConfigured(MWMApplication.get()); - getEventBuilder().getSimpleNamedEvent(eventName).post(); + trackIfEnabled(mEventBuilder.setName(eventName).buildEvent()); } public void startActivity(Activity activity) { - ensureConfigured(activity); - - if (isStatisticsEnabled(activity)) + if (isStatisticsEnabled()) { for (StatisticsEngine engine : mStatisticsEngines) engine.onStartActivity(activity); - if (doCollectStatistics(activity)) + if (doCollectStatistics()) collectOneTimeStatistics(activity); } } - private boolean doCollectStatistics(Context context) + private boolean doCollectStatistics() { - return isStatisticsEnabled(context) - && !isStatisticsCollected(context) - && isActiveUser(context, MWMApplication.get().getForegroundTime()); + return isStatisticsEnabled() + && !isStatisticsCollected() + && isActiveUser(MWMApplication.get().getForegroundTime()); } - private void ensureConfigured(Context context) + private void configure() { - if (mEventBuilder == null || mStatisticsEngines == null) - { - final String key = context.getResources().getString(R.string.flurry_app_key); - mStatisticsEngines = new ArrayList<>(); + final String key = MWMApplication.get().getResources().getString(R.string.flurry_app_key); + mStatisticsEngines = new ArrayList<>(); - final StatisticsEngine flurryEngine = new FlurryEngine(DEBUG, key); - flurryEngine.configure(null, null); - mStatisticsEngines.add(flurryEngine); + final StatisticsEngine flurryEngine = new FlurryEngine(DEBUG, key); + flurryEngine.configure(null, null); + mStatisticsEngines.add(flurryEngine); - final StatisticsEngine localyticsEngine = new LocalyticsEngine(); - mStatisticsEngines.add(localyticsEngine); + final StatisticsEngine localyticsEngine = new LocalyticsEngine(); + mStatisticsEngines.add(localyticsEngine); - mEventBuilder = new EventBuilder(mStatisticsEngines); - } + mEventBuilder = new EventBuilder(); } public void stopActivity(Activity activity) { - if (isStatisticsEnabled(activity)) + if (isStatisticsEnabled()) { for (StatisticsEngine engine : mStatisticsEngines) engine.onEndActivity(activity); @@ -287,10 +292,9 @@ public enum Statistics private void collectOneTimeStatistics(Activity activity) { - // Only when bookmarks available. if (MWMApplication.get().hasBookmarks()) { - final EventBuilder eventBuilder = getEventBuilder().reset(); + mEventBuilder.setName(EventParam.PRO_STAT); // Number of sets final BookmarkManager manager = BookmarkManager.getBookmarkManager(activity); @@ -303,51 +307,45 @@ public enum Statistics sizes[catIndex] = manager.getCategoryById(catIndex).getSize(); final double average = MathUtils.average(sizes); - eventBuilder.addParam("Average number of bmks", String.valueOf(average)); + mEventBuilder.addParam(EventParam.BOOKMARK_NUMBER_AVG, String.valueOf(average)); } - eventBuilder.addParam("Categories count", String.valueOf(categoriesCount)) - .addParam("Foreground time", String.valueOf(MWMApplication.get().getForegroundTime())) - .setName("One time PRO stat"); + mEventBuilder.addParam(EventParam.CATEGORIES_COUNT, String.valueOf(categoriesCount)) + .addParam(EventParam.FG_TIME, String.valueOf(MWMApplication.get().getForegroundTime())); - trackIfEnabled(activity, eventBuilder.getEvent()); + trackIfEnabled(mEventBuilder.buildEvent()); } - setStatisticsCollected(activity, true); + setStatisticsCollected(true); } - - private boolean isStatisticsCollected(Context context) + private boolean isStatisticsCollected() { return MWMApplication.get().nativeGetBoolean(KEY_STAT_COLLECTED, false); } - private void setStatisticsCollected(Context context, boolean isCollected) + private void setStatisticsCollected(boolean isCollected) { MWMApplication.get().nativeSetBoolean(KEY_STAT_COLLECTED, isCollected); } - public boolean isStatisticsEnabled(Context context) + public boolean isStatisticsEnabled() { return MWMApplication.get().nativeGetBoolean(KEY_STAT_ENABLED, true); } - public void setStatEnabled(Context context, boolean isEnabled) + public void setStatEnabled(boolean isEnabled) { - final MWMApplication app = MWMApplication.get(); - app.nativeSetBoolean(KEY_STAT_ENABLED, isEnabled); + MWMApplication.get().nativeSetBoolean(KEY_STAT_ENABLED, isEnabled); // We track if user turned on/off // statistics to understand data better. - getEventBuilder().reset() - .setName("Statistics status changed") - .addParam("Enabled", String.valueOf(isEnabled)) - .getEvent() - .post(); + post(mEventBuilder + .setName(EventName.STATISTICS_STATUS_CHANGED) + .addParam(EventParam.ENABLED, String.valueOf(isEnabled)) + .buildEvent()); } - private boolean isActiveUser(Context context, double foregroundTime) + private boolean isActiveUser(double foregroundTime) { return foregroundTime > ACTIVE_USER_MIN_FOREGROUND_TIME; } - - private final static String TAG = "MWMStat"; } diff --git a/android/tests/src/com/mapswithme/maps/tests/SettingsActivityTest.java b/android/tests/src/com/mapswithme/maps/tests/SettingsActivityTest.java index becda925f5..f6c5c6e9b1 100644 --- a/android/tests/src/com/mapswithme/maps/tests/SettingsActivityTest.java +++ b/android/tests/src/com/mapswithme/maps/tests/SettingsActivityTest.java @@ -37,6 +37,6 @@ public class SettingsActivityTest extends ActivityInstrumentationTestCase2