use of com.nightscout.android.wearables.Pebble in project android-uploader by nightscout.
the class MainActivityTest method testOnResume_ShouldCallPebbleConfig.
@Test
public void testOnResume_ShouldCallPebbleConfig() {
activityController.create().start();
Activity activity = activityController.get();
Pebble pebble = mock(Pebble.class);
((MainActivity) activity).setPebble(pebble);
activityController.stop().resume();
verify(pebble, times(1)).config(anyString(), (GlucoseUnit) anyObject(), (Context) anyObject());
}
use of com.nightscout.android.wearables.Pebble in project android-uploader by nightscout.
the class MainActivity method onCreate.
@SuppressLint("SetJavaScriptEnabled")
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
Log.d(TAG, "OnCreate called.");
preferences = new AndroidPreferences(getApplicationContext());
migrateToNewStyleRestUris();
ensureSavedUrisAreValid();
ensureIUnderstandDialogDisplayed();
// Add timezone ID to ACRA report
ACRA.getErrorReporter().putCustomData("timezone", TimeZone.getDefault().getID());
mTracker = ((Nightscout) getApplicationContext()).getTracker();
mContext = getApplicationContext();
// Register USB attached/detached and battery changes intents
IntentFilter deviceStatusFilter = new IntentFilter();
deviceStatusFilter.addAction(UsbManager.ACTION_USB_DEVICE_ATTACHED);
deviceStatusFilter.addAction(UsbManager.ACTION_USB_DEVICE_DETACHED);
deviceStatusFilter.addAction(ACTION_POLL);
registerReceiver(mDeviceStatusReceiver, deviceStatusFilter);
// Register Broadcast Receiver for response messages from mSyncingServiceIntent service
mCGMStatusReceiver = new CGMStatusReceiver();
IntentFilter filter = new IntentFilter(CGMStatusReceiver.PROCESS_RESPONSE);
filter.addCategory(Intent.CATEGORY_DEFAULT);
registerReceiver(mCGMStatusReceiver, filter);
toastReceiver = new ToastReceiver();
IntentFilter toastFilter = new IntentFilter(ToastReceiver.ACTION_SEND_NOTIFICATION);
toastFilter.addCategory(Intent.CATEGORY_DEFAULT);
registerReceiver(toastReceiver, toastFilter);
// Setup UI components
setContentView(R.layout.activity_main);
mTextSGV = (TextView) findViewById(R.id.sgValue);
mTextSGV.setTag(R.string.display_sgv, -1);
mTextSGV.setTag(R.string.display_trend, 0);
mTextTimestamp = (TextView) findViewById(R.id.timeAgo);
mWebView = (WebView) findViewById(R.id.webView);
mWebView.setLayerType(View.LAYER_TYPE_SOFTWARE, null);
WebSettings webSettings = mWebView.getSettings();
webSettings.setJavaScriptEnabled(true);
webSettings.setDatabaseEnabled(true);
webSettings.setDomStorageEnabled(true);
webSettings.setAppCacheEnabled(true);
webSettings.setCacheMode(WebSettings.LOAD_NO_CACHE);
webSettings.setUseWideViewPort(false);
mWebView.setVerticalScrollBarEnabled(false);
mWebView.setHorizontalScrollBarEnabled(false);
mWebView.setBackgroundColor(0);
mWebView.loadUrl("file:///android_asset/index.html");
statusBarIcons = new StatusBarIcons();
// If app started due to android.hardware.usb.action.USB_DEVICE_ATTACHED intent, start syncing
Intent startIntent = getIntent();
String action = startIntent.getAction();
if (UsbManager.ACTION_USB_DEVICE_ATTACHED.equals(action) || SyncingService.isG4Connected(getApplicationContext())) {
statusBarIcons.setUSB(true);
Log.d(TAG, "Starting syncing in OnCreate...");
SyncingService.startActionSingleSync(mContext, SyncingService.MIN_SYNC_PAGES);
} else {
// reset the top icons to their default state
statusBarIcons.setDefaults();
}
// Check (only once) to see if they have opted in to shared data for research
if (!preferences.hasAskedForData()) {
// Prompt user to ask to donate data to research
AlertDialog.Builder dataDialog = new AlertDialog.Builder(this).setCancelable(false).setTitle(R.string.donate_dialog_title).setMessage(R.string.donate_dialog_summary).setPositiveButton(R.string.donate_dialog_yes, new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int which) {
mTracker.send(new HitBuilders.EventBuilder("DataDonateQuery", "Yes").build());
preferences.setDataDonateEnabled(true);
}
}).setNegativeButton(R.string.donate_dialog_no, new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int which) {
mTracker.send(new HitBuilders.EventBuilder("DataDonateQuery", "No").build());
preferences.setDataDonateEnabled(true);
}
}).setIcon(R.drawable.ic_launcher);
dataDialog.show();
preferences.setAskedForData(true);
}
// Report API vs mongo stats once per session
reportUploadMethods(mTracker);
pebble = new Pebble(getApplicationContext());
pebble.setUnits(preferences.getPreferredUnits());
pebble.setPwdName(preferences.getPwdName());
uploaderDevice = AndroidUploaderDevice.getUploaderDevice(getApplicationContext());
alarmManager = (AlarmManager) getSystemService(ALARM_SERVICE);
Intent syncIntent = new Intent(MainActivity.ACTION_POLL);
syncManager = PendingIntent.getBroadcast(getApplicationContext(), 1, syncIntent, 0);
}
Aggregations