Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/mapsme/omim.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorr.kuznetsov <r.kuznetsov@corp.mail.ru>2016-07-21 16:42:09 +0300
committerr.kuznetsov <r.kuznetsov@corp.mail.ru>2016-07-21 16:55:41 +0300
commit2740af53d860ec062df06e58f598103a6977a54a (patch)
tree93cce378e5744ffba96b875a0e3c2d949aaeb6db /android
parent60ac6dc7d9300fb0bc47e530617718d69255c3fc (diff)
Added tags to PushWoosh
Diffstat (limited to 'android')
-rw-r--r--android/jni/com/mapswithme/platform/Platform.cpp31
-rw-r--r--android/jni/com/mapswithme/platform/Platform.hpp5
-rw-r--r--android/src/com/mapswithme/maps/MwmApplication.java20
-rw-r--r--android/src/com/mapswithme/maps/routing/RoutingController.java3
-rw-r--r--android/src/com/mapswithme/util/statistics/PushwooshHelper.java156
-rw-r--r--android/src/com/mapswithme/util/statistics/Statistics.java11
6 files changed, 219 insertions, 7 deletions
diff --git a/android/jni/com/mapswithme/platform/Platform.cpp b/android/jni/com/mapswithme/platform/Platform.cpp
index 6b0b1d76ce..56c61df873 100644
--- a/android/jni/com/mapswithme/platform/Platform.cpp
+++ b/android/jni/com/mapswithme/platform/Platform.cpp
@@ -69,6 +69,21 @@ void Platform::RunOnGuiThread(TFunctor const & fn)
android::Platform::Instance().RunOnGuiThread(fn);
}
+void Platform::SendPushWooshTag(string const & tag)
+{
+ SendPushWooshTag(tag, vector<string>{ "1" });
+}
+
+void Platform::SendPushWooshTag(string const & tag, string const & value)
+{
+ SendPushWooshTag(tag, vector<string>{ value });
+}
+
+void Platform::SendPushWooshTag(string const & tag, vector<string> const & values)
+{
+ android::Platform::Instance().SendPushWooshTag(tag, values);
+}
+
Platform::EConnectionType Platform::ConnectionStatus()
{
JNIEnv * env = jni::GetEnv();
@@ -94,6 +109,7 @@ namespace android
m_functorProcessObject = env->NewGlobalRef(functorProcessObject);
jclass const functorProcessClass = env->GetObjectClass(functorProcessObject);
m_functorProcessMethod = env->GetMethodID(functorProcessClass, "forwardToMainThread", "(J)V");
+ m_sendPushWooshTagsMethod = env->GetMethodID(functorProcessClass, "sendPushWooshTags", "(Ljava/lang/String;[Ljava/lang/String;)V");
string const flavor = jni::ToNativeString(env, flavorName);
string const build = jni::ToNativeString(env, buildType);
@@ -183,7 +199,20 @@ namespace android
TFunctor * functor = new TFunctor(fn);
jni::GetEnv()->CallVoidMethod(m_functorProcessObject, m_functorProcessMethod, reinterpret_cast<jlong>(functor));
}
-}
+
+ void Platform::SendPushWooshTag(string const & tag, vector<string> const & values)
+ {
+ if (values.empty())
+ return;
+
+ JNIEnv * env = jni::GetEnv();
+ if (env == nullptr)
+ return;
+
+ env->CallVoidMethod(m_functorProcessObject, m_sendPushWooshTagsMethod, jni::ToJavaString(env, tag),
+ jni::TScopedLocalObjectArrayRef(env, jni::ToJavaStringArray(env, values)).get());
+ }
+} // namespace android
Platform & GetPlatform()
{
diff --git a/android/jni/com/mapswithme/platform/Platform.hpp b/android/jni/com/mapswithme/platform/Platform.hpp
index 2b11f6c9a5..f47bf1645f 100644
--- a/android/jni/com/mapswithme/platform/Platform.hpp
+++ b/android/jni/com/mapswithme/platform/Platform.hpp
@@ -29,10 +29,13 @@ namespace android
bool HasAvailableSpaceForWriting(uint64_t size) const;
void RunOnGuiThread(TFunctor const & fn);
+ void SendPushWooshTag(string const & tag, vector<string> const & values);
+
static Platform & Instance();
private:
jobject m_functorProcessObject;
jmethodID m_functorProcessMethod;
+ jmethodID m_sendPushWooshTagsMethod;
};
-}
+} // namespace android
diff --git a/android/src/com/mapswithme/maps/MwmApplication.java b/android/src/com/mapswithme/maps/MwmApplication.java
index 24eff6cbd8..3440484701 100644
--- a/android/src/com/mapswithme/maps/MwmApplication.java
+++ b/android/src/com/mapswithme/maps/MwmApplication.java
@@ -30,6 +30,7 @@ import com.mapswithme.util.Config;
import com.mapswithme.util.Constants;
import com.mapswithme.util.ThemeSwitcher;
import com.mapswithme.util.UiUtils;
+import com.mapswithme.util.statistics.PushwooshHelper;
import com.mapswithme.util.statistics.Statistics;
import com.pushwoosh.PushManager;
import io.fabric.sdk.android.Fabric;
@@ -253,6 +254,25 @@ public class MwmApplication extends Application
pushManager.onStartup(this);
pushManager.registerForPushNotifications();
pushManager.startTrackingGeoPushes();
+
+ PushwooshHelper.get().setContext(this);
+ PushwooshHelper.get().synchronize();
+ }
+ catch(Exception e)
+ {
+ Log.e("Pushwoosh", e.getLocalizedMessage());
+ }
+ }
+
+ @SuppressWarnings("unused")
+ void sendPushWooshTags(String tag, String[] values)
+ {
+ try
+ {
+ if (values.length == 1)
+ PushwooshHelper.get().sendTag(tag, values[0]);
+ else
+ PushwooshHelper.get().sendTag(tag, values);
}
catch(Exception e)
{
diff --git a/android/src/com/mapswithme/maps/routing/RoutingController.java b/android/src/com/mapswithme/maps/routing/RoutingController.java
index e0b0cdeccb..63933e1b26 100644
--- a/android/src/com/mapswithme/maps/routing/RoutingController.java
+++ b/android/src/com/mapswithme/maps/routing/RoutingController.java
@@ -247,10 +247,9 @@ public class RoutingController
setBuildState(BuildState.BUILDING);
updatePlan();
- Statistics.INSTANCE.trackRouteBuild(Statistics.getPointType(mStartPoint), Statistics.getPointType(mEndPoint));
+ Statistics.INSTANCE.trackRouteBuild(mLastRouterType, mStartPoint, mEndPoint);
org.alohalytics.Statistics.logEvent(AlohaHelper.ROUTING_BUILD, new String[] {Statistics.EventParam.FROM, Statistics.getPointType(mStartPoint),
Statistics.EventParam.TO, Statistics.getPointType(mEndPoint)});
-
Framework.nativeBuildRoute(mStartPoint.getLat(), mStartPoint.getLon(), mEndPoint.getLat(), mEndPoint.getLon());
}
diff --git a/android/src/com/mapswithme/util/statistics/PushwooshHelper.java b/android/src/com/mapswithme/util/statistics/PushwooshHelper.java
new file mode 100644
index 0000000000..55cbb9a980
--- /dev/null
+++ b/android/src/com/mapswithme/util/statistics/PushwooshHelper.java
@@ -0,0 +1,156 @@
+package com.mapswithme.util.statistics;
+
+import android.content.Context;
+import android.os.AsyncTask;
+import android.os.Handler;
+import android.os.Looper;
+import android.util.Log;
+
+import com.mapswithme.maps.Framework;
+import com.pushwoosh.PushManager;
+import com.pushwoosh.SendPushTagsCallBack;
+
+import java.util.HashMap;
+import java.util.LinkedList;
+import java.util.List;
+import java.util.Map;
+
+public final class PushwooshHelper implements SendPushTagsCallBack
+{
+ public final static String ADD_MAP_OBJECT = "editor_add_discovered";
+ public final static String EDIT_MAP_OBJECT = "editor_edit_discovered";
+
+ private static final PushwooshHelper sInstance = new PushwooshHelper();
+
+ private Context mContext;
+ private final Object mSyncObject = new Object();
+ private AsyncTask<Void, Void, Void> mTask;
+ private List<Map<String, Object>> mTagsQueue = new LinkedList<>();
+
+ private PushwooshHelper() {}
+
+ public static PushwooshHelper get() { return sInstance; }
+
+ public void setContext(Context context)
+ {
+ synchronized (mSyncObject)
+ {
+ mContext = context;
+ }
+ }
+
+ public void synchronize()
+ {
+ sendTags(null);
+ }
+
+ public void sendTag(String tag)
+ {
+ sendTag(tag, "1");
+ }
+
+ public void sendTag(String tag, Object value)
+ {
+ Map<String, Object> tags = new HashMap<>();
+ tags.put(tag, value);
+ sendTags(tags);
+ }
+
+ public void sendTags(Map<String, Object> tags)
+ {
+ synchronized (mSyncObject)
+ {
+ if (!canSendTags())
+ {
+ mTagsQueue.add(tags);
+ return;
+ }
+
+ final Map<String, Object> tagsToSend = new HashMap<>();
+ for (Map<String, Object> t: mTagsQueue)
+ {
+ if (t != null)
+ tagsToSend.putAll(t);
+ }
+ if (tags != null)
+ tagsToSend.putAll(tags);
+
+ mTagsQueue.clear();
+
+ if (tagsToSend.isEmpty())
+ return;
+
+ mTask = new AsyncTask<Void, Void, Void>()
+ {
+ @Override
+ protected Void doInBackground(Void... params)
+ {
+ PushManager.sendTags(mContext, tagsToSend, PushwooshHelper.this);
+ return null;
+ }
+ };
+ mTask.execute((Void) null);
+ }
+ }
+
+ @Override
+ public void taskStarted() {}
+
+ @Override
+ public void onSentTagsSuccess(Map<String, String> map)
+ {
+ new Handler(Looper.getMainLooper()).post(new Runnable()
+ {
+ @Override
+ public void run()
+ {
+ synchronized (mSyncObject)
+ {
+ mTask = null;
+ }
+ }
+ });
+ }
+
+ @Override
+ public void onSentTagsError(final Exception e)
+ {
+ new Handler(Looper.getMainLooper()).post(new Runnable()
+ {
+ @Override
+ public void run()
+ {
+ synchronized (mSyncObject)
+ {
+ if (e != null)
+ Log.e("Pushwoosh", e.getLocalizedMessage());
+ mTask = null;
+ }
+ }
+ });
+ }
+
+ private boolean canSendTags()
+ {
+ return mContext != null && mTask == null;
+ }
+
+ public static String getRoutingTag(int routerType, boolean isP2P)
+ {
+ String result = "routing_";
+ if (isP2P)
+ result += "p2p_";
+
+ if (routerType == Framework.ROUTER_TYPE_VEHICLE)
+ result += "vehicle";
+ else if (routerType == Framework.ROUTER_TYPE_PEDESTRIAN)
+ result += "pedestrian";
+ else if (routerType == Framework.ROUTER_TYPE_BICYCLE)
+ result += "bicycle";
+ else
+ result += "unknown";
+
+ result += "_discovered";
+ return result;
+ }
+}
diff --git a/android/src/com/mapswithme/util/statistics/Statistics.java b/android/src/com/mapswithme/util/statistics/Statistics.java
index 4f0d736d73..0bfca87bc0 100644
--- a/android/src/com/mapswithme/util/statistics/Statistics.java
+++ b/android/src/com/mapswithme/util/statistics/Statistics.java
@@ -380,10 +380,13 @@ public enum Statistics
}
}
- public void trackRouteBuild(String from, String to)
+ public void trackRouteBuild(int routerType, MapObject from, MapObject to)
{
- trackEvent(EventName.ROUTING_BUILD, params().add(EventParam.FROM, from)
- .add(EventParam.TO, to));
+ trackEvent(EventName.ROUTING_BUILD, params().add(EventParam.FROM, Statistics.getPointType(from))
+ .add(EventParam.TO, Statistics.getPointType(to)));
+
+ boolean isP2P = !MapObject.isOfType(MapObject.MY_POSITION, from) && !MapObject.isOfType(MapObject.MY_POSITION, to);
+ PushwooshHelper.get().sendTag(PushwooshHelper.getRoutingTag(routerType, isP2P));
}
public void trackEditorLaunch(boolean newObject)
@@ -391,6 +394,8 @@ public enum Statistics
trackEvent(newObject ? EventName.EDITOR_START_CREATE : EventName.EDITOR_START_EDIT,
editorMwmParams().add(EventParam.IS_AUTHENTICATED, String.valueOf(OsmOAuth.isAuthorized()))
.add(EventParam.IS_ONLINE, String.valueOf(ConnectionState.isConnected())));
+
+ PushwooshHelper.get().sendTag(newObject ? PushwooshHelper.ADD_MAP_OBJECT : PushwooshHelper.EDIT_MAP_OBJECT);
}
public void trackEditorSuccess(boolean newObject)