use of com.google.android.gms.analytics.Tracker in project android-uploader by nightscout.
the class SyncingService method handleActionSync.
/**
* Handle action Sync in the provided background thread with the provided
* parameters.
*/
protected void handleActionSync(int numOfPages, Context context, DeviceTransport serialDriver) {
boolean broadcastSent = false;
AndroidPreferences preferences = new AndroidPreferences(context);
Tracker tracker = ((Nightscout) context).getTracker();
PowerManager pm = (PowerManager) context.getSystemService(Context.POWER_SERVICE);
PowerManager.WakeLock wl = pm.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, "NSDownload");
wl.acquire();
if (serialDriver != null) {
AbstractUploaderDevice uploaderDevice = AndroidUploaderDevice.getUploaderDevice(context);
AbstractDevice device = new DexcomG4(serialDriver, preferences, uploaderDevice);
((DexcomG4) device).setNumOfPages(numOfPages);
((CdcAcmSerialDriver) serialDriver).setPowerManagementEnabled(preferences.isRootEnabled());
try {
DownloadResults results = device.download();
G4Download download = results.getDownload();
Uploader uploader = new Uploader(context, preferences);
boolean uploadStatus;
if (numOfPages < 20) {
uploadStatus = uploader.upload(results, 1);
} else {
uploadStatus = uploader.upload(results);
}
EGVRecord recentEGV;
if (download.download_status == DownloadStatus.SUCCESS) {
recentEGV = new EGVRecord(download.sgv.get(download.sgv.size() - 1));
} else {
recentEGV = new EGVRecord(-1, TrendArrow.NONE, new Date(), new Date(), G4Noise.NOISE_NONE);
}
broadcastSGVToUI(recentEGV, uploadStatus, results.getNextUploadTime() + TIME_SYNC_OFFSET, results.getDisplayTime(), results.getResultArray(), download.receiver_battery);
broadcastSent = true;
} catch (ArrayIndexOutOfBoundsException e) {
Log.wtf("Unable to read from the dexcom, maybe it will work next time", e);
tracker.send(new HitBuilders.ExceptionBuilder().setDescription("Array Index out of bounds").setFatal(false).build());
} catch (NegativeArraySizeException e) {
Log.wtf("Negative array exception from receiver", e);
tracker.send(new HitBuilders.ExceptionBuilder().setDescription("Negative Array size").setFatal(false).build());
} catch (IndexOutOfBoundsException e) {
Log.wtf("IndexOutOfBounds exception from receiver", e);
tracker.send(new HitBuilders.ExceptionBuilder().setDescription("IndexOutOfBoundsException").setFatal(false).build());
} catch (CRCFailError e) {
// FIXME: may consider localizing this catch at a lower level (like ReadData) so that
// if the CRC check fails on one type of record we can capture the values if it
// doesn't fail on other types of records. This means we'd need to broadcast back
// partial results to the UI. Adding it to a lower level could make the ReadData class
// more difficult to maintain - needs discussion.
Log.wtf("CRC failed", e);
tracker.send(new HitBuilders.ExceptionBuilder().setDescription("CRC Failed").setFatal(false).build());
} catch (Exception e) {
Log.wtf("Unhandled exception caught", e);
tracker.send(new HitBuilders.ExceptionBuilder().setDescription("Catch all exception in handleActionSync").setFatal(false).build());
}
}
if (!broadcastSent)
broadcastSGVToUI();
wl.release();
}
use of com.google.android.gms.analytics.Tracker in project baker-android by bakerframework.
the class ABakerApp method getTracker.
/**
* We return our only configured tracker.
*
* @param trackerId the name of tracker, in case others are added.
* @return Tracker the Tracker.
*/
synchronized Tracker getTracker(TrackerName trackerId) {
if (!mTrackers.containsKey(trackerId)) {
GoogleAnalytics analytics = GoogleAnalytics.getInstance(this);
Tracker tracker = (trackerId == TrackerName.GLOBAL_TRACKER) ? analytics.newTracker(R.xml.global_tracker) : null;
mTrackers.put(trackerId, tracker);
}
return mTrackers.get(trackerId);
}
use of com.google.android.gms.analytics.Tracker in project baker-android by bakerframework.
the class ABakerApp method sendEvent.
@Override
public void sendEvent(String category, String action, String label) {
Tracker tracker = this.getTracker(TrackerName.GLOBAL_TRACKER);
Log.d(this.getClass().getName(), "Sending event to Google Analytics with Category: " + category + ", Action: " + action + ", Label: " + label);
tracker.send(new HitBuilders.EventBuilder().setCategory(category).setAction(action).setLabel(label).build());
}
use of com.google.android.gms.analytics.Tracker in project saga-android by AnandChowdhary.
the class MainActivity method onCreate.
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
SharedPreferences sp = PreferenceManager.getDefaultSharedPreferences(this);
if (!sp.getBoolean("tos_accepted", false)) {
Intent intent = new Intent(this, WelcomeActivity.class);
startActivity(intent);
finish();
}
final ViewPager pager;
final ViewPagerAdapter adapter;
SlidingTabLayout tabs;
File folder = new File(Utils.getStoragePath(this));
if (!folder.exists()) {
folder.mkdirs();
}
try {
// Get tracker.
Tracker t = ((ApplicationWrapper) getApplication()).getTracker(ApplicationWrapper.TrackerName.APP_TRACKER);
// Set screen name.
t.setScreenName("MainActivity");
// Send a screen view.
t.send(new HitBuilders.ScreenViewBuilder().build());
} catch (Exception e) {
//just as a protective measure
}
setContentView(R.layout.activity_main);
String title = "";
if (mToolbar == null) {
mToolbar = (Toolbar) findViewById(R.id.toolbar);
if (mToolbar != null) {
setSupportActionBar(mToolbar);
getSupportActionBar().setTitle(title);
}
}
adapter = new ViewPagerAdapter(getSupportFragmentManager());
pager = (ViewPager) findViewById(R.id.pager);
pager.setAdapter(adapter);
tabs = (SlidingTabLayout) findViewById(R.id.tabs);
tabs.setDistributeEvenly(true);
tabs.setCustomTabColorizer(new SlidingTabLayout.TabColorizer() {
@Override
public int getIndicatorColor(int position) {
return getResources().getColor(R.color.colorAccent);
}
});
tabs.setViewPager(pager);
}
use of com.google.android.gms.analytics.Tracker in project Telecine by JakeWharton.
the class TelecineModule method provideAnalytics.
@Provides
@Singleton
Analytics provideAnalytics() {
if (BuildConfig.DEBUG) {
return new Analytics() {
@Override
public void send(Map<String, String> params) {
Timber.tag("Analytics").d(String.valueOf(params));
}
};
}
GoogleAnalytics googleAnalytics = GoogleAnalytics.getInstance(app);
Tracker tracker = googleAnalytics.newTracker(BuildConfig.ANALYTICS_KEY);
// ms? s? better be s.
tracker.setSessionTimeout(300);
return new Analytics.GoogleAnalytics(tracker);
}
Aggregations