Search in sources :

Example 1 with Pebble

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());
}
Also used : Activity(android.app.Activity) Pebble(com.nightscout.android.wearables.Pebble) Test(org.junit.Test)

Example 2 with Pebble

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);
}
Also used : AndroidPreferences(com.nightscout.android.preferences.AndroidPreferences) AlertDialog(android.app.AlertDialog) IntentFilter(android.content.IntentFilter) HitBuilders(com.google.android.gms.analytics.HitBuilders) DialogInterface(android.content.DialogInterface) PendingIntent(android.app.PendingIntent) Intent(android.content.Intent) SuppressLint(android.annotation.SuppressLint) Pebble(com.nightscout.android.wearables.Pebble) WebSettings(android.webkit.WebSettings) SuppressLint(android.annotation.SuppressLint)

Aggregations

Pebble (com.nightscout.android.wearables.Pebble)2 SuppressLint (android.annotation.SuppressLint)1 Activity (android.app.Activity)1 AlertDialog (android.app.AlertDialog)1 PendingIntent (android.app.PendingIntent)1 DialogInterface (android.content.DialogInterface)1 Intent (android.content.Intent)1 IntentFilter (android.content.IntentFilter)1 WebSettings (android.webkit.WebSettings)1 HitBuilders (com.google.android.gms.analytics.HitBuilders)1 AndroidPreferences (com.nightscout.android.preferences.AndroidPreferences)1 Test (org.junit.Test)1