Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Google Analytics update #829

Merged
merged 19 commits into from
Jun 28, 2014
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
19 commits
Select commit Hold shift + click to select a range
df3a926
integration of google analytics within droidplanner.
m4gr3d Jun 12, 2014
81863bd
fixed issues preventing google analytics from dispatching recorded hits.
m4gr3d Jun 12, 2014
03272b8
cleaned up the styles resource file.
m4gr3d Jun 12, 2014
c797a1e
Added 'mode details panel' usage tracking.
m4gr3d Jun 12, 2014
95521ec
created package for analytics related code/logic.
m4gr3d Jun 13, 2014
d384ceb
Merge branch 'master' of https://github.com/DroidPlanner/droidplanner…
m4gr3d Jun 26, 2014
b1df544
Merge branch 'master' of https://github.com/DroidPlanner/droidplanner…
m4gr3d Jun 26, 2014
93516f6
added ga tracking for the flight action buttons usage.
m4gr3d Jun 26, 2014
e03dd52
added documentation stub for the drone event types.
m4gr3d Jun 26, 2014
94e21ca
added tracking for mavlink connection methods.
m4gr3d Jun 26, 2014
93bdb3a
second attempt at fixing travis ci license issue.
m4gr3d Jun 26, 2014
5c2c7fe
fix gradle tools version.
m4gr3d Jun 27, 2014
3f98c72
Merge branch 'master' of https://github.com/DroidPlanner/droidplanner…
m4gr3d Jun 27, 2014
2f4056a
updated gradle tools version to support android studio beta release.
m4gr3d Jun 27, 2014
dd6c11e
updated the android plugin declaration style.
m4gr3d Jun 27, 2014
fdc8775
completed analytics feature list.
m4gr3d Jun 27, 2014
6854979
Merge branch 'master' of https://github.com/DroidPlanner/droidplanner…
m4gr3d Jun 27, 2014
57ef7fe
specifying required libraries for the travis ci build.
m4gr3d Jun 27, 2014
354d681
attempt to fix travis ci build issues by using deprecated google anal…
m4gr3d Jun 27, 2014
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ language: android
android:
components:
- build-tools-19.1.0
- android-19
licenses:
- 'android-sdk-license-.+'

Expand Down
2 changes: 1 addition & 1 deletion Android/build.gradle
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
apply plugin: 'android'
apply plugin: 'com.android.application'

repositories {
mavenCentral()
Expand Down
1 change: 1 addition & 0 deletions Android/res/values/preferences_keys.xml
Original file line number Diff line number Diff line change
Expand Up @@ -28,4 +28,5 @@ This file is used to store the preferences keys so that it's accessible and modi
<string name="pref_mavlink_version_key">pref_mavlink_version</string>
<string name="pref_usage_statistics_key">pref_usage_statistics</string>
<string name="pref_version_key">pref_version</string>
<string name="pref_keep_screen_bright_key">pref_keep_screen_bright</string>
</resources>
1 change: 0 additions & 1 deletion Android/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -356,7 +356,6 @@
<string name="expandable_listview_icon_desc">Expandable listview icon</string>

<!-- Google Analytics -->
<string name="ga_mode_details_panel_category">Mode Details Panel</string>
<string name="ga_mode_details_open_panel">Panel Open Time</string>
<string name="ga_mode_details_close_panel">Panel Close Time</string>

Expand Down
2 changes: 1 addition & 1 deletion Android/res/xml/preferences.xml
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
android:title="@string/pref_title_screen" >
<CheckBoxPreference
android:defaultValue="true"
android:key="pref_keep_screen_bright"
android:key="@string/pref_keep_screen_bright_key"
android:summary="@string/pref_keep_screen_bright_summary"
android:title="@string/pref_keep_screen_bright" />
<CheckBoxPreference
Expand Down
50 changes: 9 additions & 41 deletions Android/src/org/droidplanner/android/DroidPlannerApp.java
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
package org.droidplanner.android;

import org.droidplanner.BuildConfig;
import org.droidplanner.R;
import org.droidplanner.android.gcs.FollowMe;
import org.droidplanner.android.utils.analytics.GAUtils;
import org.droidplanner.core.bus.events.DroneConnectedEvent;
import org.droidplanner.core.bus.events.DroneDisconnectedEvent;
import org.droidplanner.android.proxy.mission.MissionProxy;
Expand All @@ -18,16 +17,11 @@
import org.droidplanner.core.drone.DroneInterfaces.Clock;
import org.droidplanner.core.drone.DroneInterfaces.DroneEventsType;
import org.droidplanner.core.drone.DroneInterfaces.Handler;
import org.droidplanner.core.drone.Preferences;

import android.content.Context;
import android.os.SystemClock;

import com.MAVLink.Messages.MAVLinkMessage;
import com.google.android.gms.analytics.GoogleAnalytics;
import com.google.android.gms.analytics.Logger;
import com.google.android.gms.analytics.Tracker;

import java.util.concurrent.atomic.AtomicReference;

import de.greenrobot.event.EventBus;

Expand All @@ -39,11 +33,6 @@ public class DroidPlannerApp extends ErrorReportApp implements MAVLinkStreams.Ma
public MissionProxy missionProxy;
private MavLinkMsgHandler mavLinkMsgHandler;

/**
* Stores a reference to the google analytics app tracker.
*/
private Tracker mAppTracker;

/**
* Handles dispatching of status bar, and audible notification.
*/
Expand All @@ -53,7 +42,8 @@ public class DroidPlannerApp extends ErrorReportApp implements MAVLinkStreams.Ma
public void onCreate() {
super.onCreate();

mNotificationHandler = new NotificationHandler(getApplicationContext());
final Context context = getApplicationContext();
mNotificationHandler = new NotificationHandler(context);

MAVLinkClient MAVClient = new MAVLinkClient(this, this);
Clock clock = new Clock() {
Expand All @@ -75,17 +65,19 @@ public void postDelayed(Runnable thread, long timeout) {
handler.postDelayed(thread, timeout);
}
};
DroidplannerPrefs pref = new DroidplannerPrefs(getApplicationContext());

DroidplannerPrefs pref = new DroidplannerPrefs(context);
drone = new Drone(MAVClient, clock, handler, pref);
drone.events.addDroneListener(this);

missionProxy = new MissionProxy(drone.mission);
mavLinkMsgHandler = new org.droidplanner.core.MAVLink.MavLinkMsgHandler(drone);

followMe = new FollowMe(this, drone);
NetworkStateReceiver.register(getApplicationContext());
NetworkStateReceiver.register(context);

initGATracker(pref);
GAUtils.initGATracker(this);
GAUtils.startNewSession(context);
}

@Override
Expand Down Expand Up @@ -127,28 +119,4 @@ public void onDroneEvent(DroneEventsType event, Drone drone) {
break;
}
}

private void initGATracker(DroidplannerPrefs pref){
final GoogleAnalytics analytics = GoogleAnalytics.getInstance(this);
//Call is needed for now to allow dispatching of auto activity reports
// (http://stackoverflow.com/a/23256722/1088814)
analytics.enableAutoActivityReports(this);

analytics.setAppOptOut(!pref.isUsageStatisticsEnabled());

//If we're in debug mode, set log level to verbose.
if(BuildConfig.DEBUG){
analytics.getLogger().setLogLevel(Logger.LogLevel.VERBOSE);
}

mAppTracker = analytics.newTracker(R.xml.google_analytics_tracker);
}

/**
* @return handles to the google analytics tracker.
*/
public Tracker getTracker(){
return mAppTracker;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import org.droidplanner.android.fragments.TelemetryFragment;
import org.droidplanner.android.fragments.helpers.FlightSlidingDrawerContent;
import org.droidplanner.android.fragments.mode.FlightModePanel;
import org.droidplanner.android.utils.analytics.GAUtils;
import org.droidplanner.core.drone.Drone;
import org.droidplanner.core.drone.DroneInterfaces.DroneEventsType;
import org.droidplanner.core.drone.DroneInterfaces.OnDroneListener;
Expand Down Expand Up @@ -55,11 +56,10 @@ public void onDrawerClosed() {
updateMapPadding();

//Stop tracking how long this was opened for.
mTracker.send(new HitBuilders.TimingBuilder()
.setCategory(getString(R.string.ga_mode_details_panel_category))
GAUtils.sendTiming(new HitBuilders.TimingBuilder()
.setCategory(GAUtils.Category.FLIGHT_DATA_DETAILS_PANEL.toString())
.setVariable(getString(R.string.ga_mode_details_close_panel))
.setValue(System.currentTimeMillis())
.build());
.setValue(System.currentTimeMillis()));
}
});

Expand All @@ -69,11 +69,10 @@ public void onDrawerOpened() {
updateMapPadding();

//Track how long this is opened for.
mTracker.send(new HitBuilders.TimingBuilder()
.setCategory(getString(R.string.ga_mode_details_panel_category))
GAUtils.sendTiming(new HitBuilders.TimingBuilder()
.setCategory(GAUtils.Category.FLIGHT_DATA_DETAILS_PANEL.toString())
.setVariable(getString(R.string.ga_mode_details_open_panel))
.setValue(System.currentTimeMillis())
.build());
.setValue(System.currentTimeMillis()));
}
});

Expand All @@ -85,12 +84,10 @@ public void onDrawerOpened() {
.add(R.id.mapFragment, mapFragment).commit();
}

editorTools = fragmentManager
.findFragmentById(R.id.editorToolsFragment);
editorTools = fragmentManager.findFragmentById(R.id.editorToolsFragment);
if (editorTools == null) {
editorTools = new FlightActionsFragment();
fragmentManager.beginTransaction()
.add(R.id.editorToolsFragment, editorTools).commit();
fragmentManager.beginTransaction().add(R.id.editorToolsFragment, editorTools).commit();
}

/*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import org.droidplanner.android.fragments.helpers.BTDeviceListFragment;
import org.droidplanner.android.maps.providers.google_map.GoogleMapFragment;
import org.droidplanner.android.utils.Constants;
import org.droidplanner.android.utils.DroidplannerPrefs;
import org.droidplanner.android.utils.Utils;
import org.droidplanner.android.widgets.actionProviders.InfoBarActionProvider;
import org.droidplanner.core.drone.Drone;
Expand All @@ -23,18 +24,17 @@

import com.google.android.gms.analytics.Tracker;

public abstract class SuperUI extends FragmentActivity implements
OnDroneListener {
public abstract class SuperUI extends FragmentActivity implements OnDroneListener {
private ScreenOrientation screenOrientation = new ScreenOrientation(this);
private InfoBarActionProvider infoBar;
private GCSHeartbeat gcsHeartbeat;
public DroidPlannerApp app;
public Drone drone;

/**
* Google analytics tracker used by the children activities.
* Handle to the app preferences.
*/
protected Tracker mTracker;
protected DroidplannerPrefs mAppPrefs;

@Override
public void onCreate(Bundle savedInstanceState) {
Expand All @@ -45,28 +45,26 @@ public void onCreate(Bundle savedInstanceState) {
actionBar.setDisplayHomeAsUpEnabled(true);
}

app = (DroidPlannerApp) getApplication();
this.drone = app.drone;
gcsHeartbeat = new GCSHeartbeat(drone, 1);
mAppPrefs = new DroidplannerPrefs(getApplicationContext());

PreferenceManager.setDefaultValues(this, R.xml.preferences, false);

/*
* Used to supplant wake lock acquisition (previously in
* org.droidplanner.android.service .MAVLinkService) as suggested by the
* android android.os.PowerManager#newWakeLock documentation.
*/
if (PreferenceManager.getDefaultSharedPreferences(
getApplicationContext()).getBoolean("pref_keep_screen_bright", false)) {
if (mAppPrefs.keepScreenOn()) {
getWindow().addFlags(android.view.WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);
}

app = (DroidPlannerApp) getApplication();
this.drone = app.drone;

setVolumeControlStream(AudioManager.STREAM_MUSIC);

screenOrientation.unlock();
Utils.updateUILanguage(getApplicationContext());
gcsHeartbeat = new GCSHeartbeat(drone, 1);

mTracker = app.getTracker();
}

@Override
Expand Down Expand Up @@ -192,10 +190,7 @@ public boolean onMenuItemSelected(int featureId, MenuItem item) {

protected void toggleDroneConnection() {
if (!drone.MavClient.isConnected()) {
final String connectionType = PreferenceManager
.getDefaultSharedPreferences(getApplicationContext())
.getString(Constants.PREF_CONNECTION_TYPE,
Constants.DEFAULT_CONNECTION_TYPE);
final String connectionType = mAppPrefs.getMavLinkConnectionType();

if (Utils.ConnectionType.BLUETOOTH.name().equals(connectionType)) {
// Launch a bluetooth device selection screen for the user
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@

import org.droidplanner.android.communication.service.UploaderService;
import org.droidplanner.android.utils.DroidplannerPrefs;
import org.droidplanner.android.utils.analytics.GAUtils;
import org.droidplanner.android.utils.file.FileStream;

import android.content.Context;
Expand Down Expand Up @@ -75,7 +76,11 @@ public void run() {
try {
parser.stats.mavlinkResetStats();
openConnection();


//Start a new ga analytics session. The new session will be tagged with the mavlink
// connection mechanism, as well as whether the user has an active droneshare account.
GAUtils.startNewSession(parentContext);

logFile = FileStream.getTLogFile();
logWriter = FileStream.openOutputStream(logFile);
logBuffer = ByteBuffer.allocate(Long.SIZE / Byte.SIZE);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,7 @@ public void close() {
// it, then now is the time to unregister.
if (mService != null) {
try {
Message msg = Message.obtain(null,
MAVLinkService.MSG_UNREGISTER_CLIENT);
Message msg = Message.obtain(null, MAVLinkService.MSG_UNREGISTER_CLIENT);
msg.replyTo = mMessenger;
mService.send(msg);

Expand Down
Loading