diff --git a/OsmAnd/build.gradle b/OsmAnd/build.gradle index 16d11b119a..122a68c6a4 100644 --- a/OsmAnd/build.gradle +++ b/OsmAnd/build.gradle @@ -350,9 +350,17 @@ repositories { // mavenCentral() } +def analytics = (System.getenv("APP_FEATURES") && System.getenv("APP_FEATURES").contains("+play_market") && + System.getenv("PACKAGE_TO_BUILT").equals("net.osmand") ) || System.getenv("USE_FIREBASE") dependencies { compile project(path: ':OsmAnd-java', configuration: 'android') + if(analytics) { + compile 'com.google.firebase:firebase-core:9.8.0' + compile 'com.google.firebase:firebase-config:9.8.0' + + } + // compile project(':eclipse-compile:design') // compile project(':eclipse-compile:cardview') @@ -368,8 +376,7 @@ dependencies { qtcoreCompile "net.osmand:OsmAndCore_androidNativeRelease:0.1-SNAPSHOT@aar" qtcoreCompile "net.osmand:OsmAndCore_android:0.1-SNAPSHOT@aar" } -if(System.getenv("APP_FEATURES") && System.getenv("APP_FEATURES").contains("+play_market") && - System.getenv("PACKAGE_TO_BUILT").equals("net.osmand")) { +if(analytics) { println "Apply GMS plugin" apply plugin: 'com.google.gms.google-services' } diff --git a/OsmAnd/src/net/osmand/plus/OsmandApplication.java b/OsmAnd/src/net/osmand/plus/OsmandApplication.java index 3b6e110838..32f3489530 100644 --- a/OsmAnd/src/net/osmand/plus/OsmandApplication.java +++ b/OsmAnd/src/net/osmand/plus/OsmandApplication.java @@ -11,6 +11,7 @@ import android.content.pm.PackageManager.NameNotFoundException; import android.content.res.Configuration; import android.os.AsyncTask; import android.os.Build; +import android.os.Bundle; import android.os.Handler; import android.os.Message; import android.support.multidex.MultiDex; @@ -57,6 +58,7 @@ import java.io.File; import java.io.FileWriter; import java.io.PrintStream; import java.lang.Thread.UncaughtExceptionHandler; +import java.lang.reflect.Method; import java.util.ArrayList; import java.util.Locale; @@ -776,4 +778,18 @@ public class OsmandApplication extends MultiDexApplication { } return l; } + + public void logEvent(Activity ctx, String event) { + try { + if(Version.isGooglePlayEnabled(this) && Version.isFreeVersion(this)) { + Class cl = Class.forName("com.google.firebase.analytics.FirebaseAnalytics"); + Method mm = cl.getMethod("getInstance", Context.class); + Object inst = mm.invoke(null, ctx == null ? this : ctx); + Method log = cl.getMethod("logEvent", String.class, Bundle.class); + log.invoke(inst, event, new Bundle()); + } + } catch (Exception e) { + e.printStackTrace(); + } + } } diff --git a/OsmAnd/src/net/osmand/plus/download/DownloadIndexesThread.java b/OsmAnd/src/net/osmand/plus/download/DownloadIndexesThread.java index 4631d7f5e6..1a75e5e694 100644 --- a/OsmAnd/src/net/osmand/plus/download/DownloadIndexesThread.java +++ b/OsmAnd/src/net/osmand/plus/download/DownloadIndexesThread.java @@ -264,6 +264,9 @@ public class DownloadIndexesThread { return; } } + if(uiActivity instanceof Activity) { + app.logEvent((Activity) uiActivity, "download_files"); + } for(IndexItem item : items) { if (!item.equals(currentDownloadingItem) && !indexItemDownloading.contains(item)) { indexItemDownloading.add(item); diff --git a/OsmAnd/src/net/osmand/plus/views/MapControlsLayer.java b/OsmAnd/src/net/osmand/plus/views/MapControlsLayer.java index 81e6149296..7c4ec4cf59 100644 --- a/OsmAnd/src/net/osmand/plus/views/MapControlsLayer.java +++ b/OsmAnd/src/net/osmand/plus/views/MapControlsLayer.java @@ -2,6 +2,7 @@ package net.osmand.plus.views; import android.Manifest; import android.annotation.SuppressLint; +import android.app.Activity; import android.content.DialogInterface; import android.content.Intent; import android.content.pm.PackageManager; @@ -26,7 +27,6 @@ import android.widget.ImageView; import android.widget.LinearLayout; import android.widget.SeekBar; import android.widget.TextView; - import net.osmand.AndroidUtils; import net.osmand.core.android.MapRendererContext; import net.osmand.data.LatLon; @@ -582,6 +582,7 @@ public class MapControlsLayer extends OsmandMapLayer { mapRouteInfoMenu.show(); } else { touchEvent = 0; + app.logEvent(mapActivity, "start_navigation"); app.getSettings().APPLICATION_MODE.set(routingHelper.getAppMode()); mapActivity.getMapViewTrackingUtilities().backToLocationImpl(); app.getSettings().FOLLOW_THE_ROUTE.set(true);