Java Code Examples for com.eveningoutpost.dexdrip.UtilityModels.CollectionServiceStarter#startBtService()

The following examples show how to use com.eveningoutpost.dexdrip.UtilityModels.CollectionServiceStarter#startBtService() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ListenerService.java    From xDrip with GNU General Public License v3.0 6 votes vote down vote up
private synchronized void startBtService() {//KS
    Log.d(TAG, "startBtService");
    if (is_using_bt) {
        if (checkLocationPermissions()) {
            Log.d(TAG, "startBtService start BT Collection Service: " + DexCollectionType.getDexCollectionType());
            //if (restartWatchDog()) {
            //    stopBtService();
            //}
            if (!isCollectorRunning()) {
                if (JoH.ratelimit("start-collector", 2)) {
                    CollectionServiceStarter.startBtService(getApplicationContext());
                }
                Log.d(TAG, "startBtService AFTER startService mLocationPermissionApproved " + mLocationPermissionApproved);
            } else {
                Log.d(TAG, "startBtService collector already running!");
            }
        }
    }
}
 
Example 2
Source File: ListenerService.java    From xDrip-plus with GNU General Public License v3.0 6 votes vote down vote up
private synchronized void startBtService() {//KS
    Log.d(TAG, "startBtService");
    if (is_using_bt) {
        if (checkLocationPermissions()) {
            Log.d(TAG, "startBtService start BT Collection Service: " + DexCollectionType.getDexCollectionType());
            //if (restartWatchDog()) {
            //    stopBtService();
            //}
            if (!isCollectorRunning()) {
                if (JoH.ratelimit("start-collector", 2)) {
                    CollectionServiceStarter.startBtService(getApplicationContext());
                }
                Log.d(TAG, "startBtService AFTER startService mLocationPermissionApproved " + mLocationPermissionApproved);
            } else {
                Log.d(TAG, "startBtService collector already running!");
            }
        }
    }
}
 
Example 3
Source File: WatchUpdaterService.java    From xDrip with GNU General Public License v3.0 5 votes vote down vote up
private void startBtService() {//KS
    Log.d(TAG, "startBtService");
    is_using_bt = DexCollectionType.hasBluetooth();//(getDexCollectionType() == DexCollectionType.DexcomG5)
    if (is_using_bt) {
        if (!isCollectorRunning()) {
            CollectionServiceStarter.startBtService(getApplicationContext());
            Log.d(TAG, "startBtService startService");
        } else {
            Log.d(TAG, "startBtService collector already running!");
        }
    } else {
        Log.d(TAG, "Not starting any BT Collector service as it is not our data source");
    }
}
 
Example 4
Source File: WatchUpdaterService.java    From xDrip-plus with GNU General Public License v3.0 5 votes vote down vote up
private void startBtService() {//KS
    Log.d(TAG, "startBtService");
    is_using_bt = DexCollectionType.hasBluetooth();//(getDexCollectionType() == DexCollectionType.DexcomG5)
    if (is_using_bt) {
        if (!isCollectorRunning()) {
            CollectionServiceStarter.startBtService(getApplicationContext());
            Log.d(TAG, "startBtService startService");
        } else {
            Log.d(TAG, "startBtService collector already running!");
        }
    } else {
        Log.d(TAG, "Not starting any BT Collector service as it is not our data source");
    }
}
 
Example 5
Source File: MissedReadingService.java    From xDrip with GNU General Public License v3.0 4 votes vote down vote up
@Override
protected void onHandleIntent(Intent intent) {
    final SharedPreferences prefs;
    final boolean bg_missed_alerts;
    final Context context;
    final int bg_missed_minutes;


    context = getApplicationContext();
    prefs = PreferenceManager.getDefaultSharedPreferences(context);

    Log.d(TAG, "MissedReadingService onHandleIntent");

    final long stale_millis = Home.stale_data_millis();

    // send to pebble
    /*if (prefs.getBoolean("broadcast_to_pebble", false) && (PebbleUtil.getCurrentPebbleSyncType(prefs) != 1) && !BgReading.last_within_millis(stale_millis)) {
        if (JoH.ratelimit("peb-miss",120)) context.startService(new Intent(context, PebbleWatchSync.class));
        // update pebble even when we don't have data to ensure missed readings show
    }*/

    /*if ((Home.get_forced_wear()) && prefs.getBoolean("disable_wearG5_on_missedreadings", false)) {
        int bg_wear_missed_minutes = readPerfsInt(prefs, "disable_wearG5_on_missedreadings_level", 30);
        if (BgReading.getTimeSinceLastReading() >= (bg_wear_missed_minutes * 1000 * 60)) {
            Log.d(TAG, "Request WatchUpdaterService to disable force_wearG5 when wear is connected");
            startWatchUpdaterService(context, WatchUpdaterService.ACTION_DISABLE_FORCE_WEAR, TAG);
        }
    }*/

    if ((prefs.getBoolean("aggressive_service_restart", false) || DexCollectionType.isFlakey())) {//!Home.get_enable_wear() &&
        if (!BgReading.last_within_millis(stale_millis) && Sensor.isActive() && (!getLocalServiceCollectingState())) {
            if (JoH.ratelimit("aggressive-restart", aggressive_backoff_timer)) {
                Log.e(TAG, "Aggressively restarting collector service due to lack of reception: backoff: "+aggressive_backoff_timer);
                if (aggressive_backoff_timer < 1200) aggressive_backoff_timer+=60;
                CollectionServiceStarter.startBtService(context);
            } else {
                aggressive_backoff_timer = 120; // reset
            }
        }
    }
    //Reminder.processAnyDueReminders();
    //BluetoothGlucoseMeter.immortality();

    bg_missed_alerts =  prefs.getBoolean("bg_missed_alerts", false);//KS TODO bg_missed_alerts pref not supported
    if (!bg_missed_alerts || !Pref.getBoolean("bg_notifications", false)) {
        // we should not do anything in this case. if the ui, changes will be called again
        return;
    }

    bg_missed_minutes =  readPerfsInt(prefs, "bg_missed_minutes", 30);
    final long now = new Date().getTime();

    if (BgReading.getTimeSinceLastReading() >= (bg_missed_minutes * 1000 * 60) &&
            prefs.getLong("alerts_disabled_until", 0) <= now &&
            inTimeFrame(prefs)) {
        Notifications.bgMissedAlert(context);
        checkBackAfterSnoozeTime(context, now);
    } else  {

        long disabletime = prefs.getLong("alerts_disabled_until", 0) - now;

        long missedTime = bg_missed_minutes* 1000 * 60 - BgReading.getTimeSinceLastReading();
        long alarmIn = Math.max(disabletime, missedTime);
        checkBackAfterMissedTime(alarmIn);
    }
}
 
Example 6
Source File: MenuActivity.java    From xDrip with GNU General Public License v3.0 4 votes vote down vote up
private void updateTab() {

        String msg;
        final int offColor = Color.DKGRAY;
        final int onColor = Color.RED;

        addtreatmentbutton.setBackgroundColor(offColor);
        refreshdbbutton.setBackgroundColor(offColor);
        restartcollectorbutton.setBackgroundColor(offColor);
        xdripprefsbutton.setBackgroundColor(offColor);
        bloodtesttabbutton.setBackgroundColor(offColor);
        treatmenttabbutton.setBackgroundColor(offColor);
        calibrationtabbutton.setBackgroundColor(offColor);
        bgtabbutton.setBackgroundColor(offColor);

        switch (currenttab) {
            case "addtreatment":
                addtreatmentbutton.setBackgroundColor(onColor);
                startIntent(KeypadInputActivity.class);
                break;
            case "refreshdb":
                refreshdbbutton.setBackgroundColor(onColor);
                ListenerService.SendData(this, WEARABLE_INITTREATMENTS_PATH, null);
                msg = getResources().getString(R.string.notify_refreshdb);
                JoH.static_toast(xdrip.getAppContext(), msg, Toast.LENGTH_SHORT);
                break;
            case "restartcollector":
                restartcollectorbutton.setBackgroundColor(onColor);
                CollectionServiceStarter.startBtService(getApplicationContext());
                msg = getResources().getString(R.string.notify_collector_started, DexCollectionType.getDexCollectionType());
                JoH.static_toast(xdrip.getAppContext(), msg, Toast.LENGTH_SHORT);
                break;
            case "xdripprefs":
                xdripprefsbutton.setBackgroundColor(onColor);
                startIntent(NWPreferences.class);
                break;
            //View DB Tables:
            case "bloodtest":
                bloodtesttabbutton.setBackgroundColor(onColor);
                startIntent(BloodTestTable.class);// TODO get mgdl or mmol here
                break;
            case "treatments":
                treatmenttabbutton.setBackgroundColor(onColor);
                startIntent(TreatmentsTable.class);
                break;
            case "calibrations":
                calibrationtabbutton.setBackgroundColor(onColor);
                startIntent(CalibrationDataTable.class);
                break;
            case "bgreadings":
                bgtabbutton.setBackgroundColor(onColor);
                startIntent(BgReadingTable.class);
                break;
        }

    }
 
Example 7
Source File: MissedReadingService.java    From xDrip-plus with GNU General Public License v3.0 4 votes vote down vote up
@Override
protected void onHandleIntent(Intent intent) {
    final SharedPreferences prefs;
    final boolean bg_missed_alerts;
    final Context context;
    final int bg_missed_minutes;


    context = getApplicationContext();
    prefs = PreferenceManager.getDefaultSharedPreferences(context);

    Log.d(TAG, "MissedReadingService onHandleIntent");

    final long stale_millis = Home.stale_data_millis();

    // send to pebble
    /*if (prefs.getBoolean("broadcast_to_pebble", false) && (PebbleUtil.getCurrentPebbleSyncType(prefs) != 1) && !BgReading.last_within_millis(stale_millis)) {
        if (JoH.ratelimit("peb-miss",120)) context.startService(new Intent(context, PebbleWatchSync.class));
        // update pebble even when we don't have data to ensure missed readings show
    }*/

    /*if ((Home.get_forced_wear()) && prefs.getBoolean("disable_wearG5_on_missedreadings", false)) {
        int bg_wear_missed_minutes = readPerfsInt(prefs, "disable_wearG5_on_missedreadings_level", 30);
        if (BgReading.getTimeSinceLastReading() >= (bg_wear_missed_minutes * 1000 * 60)) {
            Log.d(TAG, "Request WatchUpdaterService to disable force_wearG5 when wear is connected");
            startWatchUpdaterService(context, WatchUpdaterService.ACTION_DISABLE_FORCE_WEAR, TAG);
        }
    }*/

    if ((prefs.getBoolean("aggressive_service_restart", false) || DexCollectionType.isFlakey())) {//!Home.get_enable_wear() &&
        if (!BgReading.last_within_millis(stale_millis) && Sensor.isActive() && (!getLocalServiceCollectingState())) {
            if (JoH.ratelimit("aggressive-restart", aggressive_backoff_timer)) {
                Log.e(TAG, "Aggressively restarting collector service due to lack of reception: backoff: "+aggressive_backoff_timer);
                if (aggressive_backoff_timer < 1200) aggressive_backoff_timer+=60;
                CollectionServiceStarter.startBtService(context);
            } else {
                aggressive_backoff_timer = 120; // reset
            }
        }
    }
    //Reminder.processAnyDueReminders();
    //BluetoothGlucoseMeter.immortality();

    bg_missed_alerts =  prefs.getBoolean("bg_missed_alerts", false);//KS TODO bg_missed_alerts pref not supported
    if (!bg_missed_alerts || !Pref.getBoolean("bg_notifications", false)) {
        // we should not do anything in this case. if the ui, changes will be called again
        return;
    }

    bg_missed_minutes =  readPerfsInt(prefs, "bg_missed_minutes", 30);
    final long now = new Date().getTime();

    if (BgReading.getTimeSinceLastReading() >= (bg_missed_minutes * 1000 * 60) &&
            prefs.getLong("alerts_disabled_until", 0) <= now &&
            inTimeFrame(prefs)) {
        Notifications.bgMissedAlert(context);
        checkBackAfterSnoozeTime(context, now);
    } else  {

        long disabletime = prefs.getLong("alerts_disabled_until", 0) - now;

        long missedTime = bg_missed_minutes* 1000 * 60 - BgReading.getTimeSinceLastReading();
        long alarmIn = Math.max(disabletime, missedTime);
        checkBackAfterMissedTime(alarmIn);
    }
}
 
Example 8
Source File: MenuActivity.java    From xDrip-plus with GNU General Public License v3.0 4 votes vote down vote up
private void updateTab() {

        String msg;
        final int offColor = Color.DKGRAY;
        final int onColor = Color.RED;

        addtreatmentbutton.setBackgroundColor(offColor);
        refreshdbbutton.setBackgroundColor(offColor);
        restartcollectorbutton.setBackgroundColor(offColor);
        xdripprefsbutton.setBackgroundColor(offColor);
        bloodtesttabbutton.setBackgroundColor(offColor);
        treatmenttabbutton.setBackgroundColor(offColor);
        calibrationtabbutton.setBackgroundColor(offColor);
        bgtabbutton.setBackgroundColor(offColor);

        switch (currenttab) {
            case "addtreatment":
                addtreatmentbutton.setBackgroundColor(onColor);
                startIntent(KeypadInputActivity.class);
                break;
            case "refreshdb":
                refreshdbbutton.setBackgroundColor(onColor);
                ListenerService.SendData(this, WEARABLE_INITTREATMENTS_PATH, null);
                msg = getResources().getString(R.string.notify_refreshdb);
                JoH.static_toast(xdrip.getAppContext(), msg, Toast.LENGTH_SHORT);
                break;
            case "restartcollector":
                restartcollectorbutton.setBackgroundColor(onColor);
                CollectionServiceStarter.startBtService(getApplicationContext());
                msg = getResources().getString(R.string.notify_collector_started, DexCollectionType.getDexCollectionType());
                JoH.static_toast(xdrip.getAppContext(), msg, Toast.LENGTH_SHORT);
                break;
            case "xdripprefs":
                xdripprefsbutton.setBackgroundColor(onColor);
                startIntent(NWPreferences.class);
                break;
            //View DB Tables:
            case "bloodtest":
                bloodtesttabbutton.setBackgroundColor(onColor);
                startIntent(BloodTestTable.class);// TODO get mgdl or mmol here
                break;
            case "treatments":
                treatmenttabbutton.setBackgroundColor(onColor);
                startIntent(TreatmentsTable.class);
                break;
            case "calibrations":
                calibrationtabbutton.setBackgroundColor(onColor);
                startIntent(CalibrationDataTable.class);
                break;
            case "bgreadings":
                bgtabbutton.setBackgroundColor(onColor);
                startIntent(BgReadingTable.class);
                break;
        }

    }