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

The following examples show how to use com.eveningoutpost.dexdrip.UtilityModels.CollectionServiceStarter#isBTShare() . 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: DexShareCollectionService.java    From xDrip with GNU General Public License v3.0 6 votes vote down vote up
@Override
public int onStartCommand(Intent intent, int flags, int startId) {
    if (android.os.Build.VERSION.SDK_INT < Build.VERSION_CODES.KITKAT){
        stopSelf();
        return START_NOT_STICKY;
    }
    if (CollectionServiceStarter.isBTShare(getApplicationContext())) {
        setFailoverTimer();
    } else {
        stopSelf();
        return START_NOT_STICKY;
    }
    if (Sensor.currentSensor() == null) {
        setRetryTimer();
        return START_NOT_STICKY;
    }
    Log.w(TAG, "STARTING SERVICE");
    attemptConnection();
    return START_STICKY;
}
 
Example 2
Source File: DexShareCollectionService.java    From xDrip with GNU General Public License v3.0 6 votes vote down vote up
public void setFailoverTimer() { //Sometimes it gets stuck in limbo on 4.4, this should make it try again
    if (CollectionServiceStarter.isBTShare(getApplicationContext())) {
        long retry_in = (1000 * 60 * 5);
        Log.d(TAG, "Fallover Restarting in: " + (retry_in / (60 * 1000)) + " minutes");
        Calendar calendar = Calendar.getInstance();
        AlarmManager alarm = (AlarmManager) getSystemService(ALARM_SERVICE);
        if (pendingIntent != null)
            alarm.cancel(pendingIntent);
        long wakeTime = calendar.getTimeInMillis() + retry_in;
        pendingIntent = PendingIntent.getService(this, 0, new Intent(this, this.getClass()), 0);
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
            alarm.setExactAndAllowWhileIdle(AlarmManager.RTC_WAKEUP, wakeTime, pendingIntent);
        } else if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
            alarm.setExact(AlarmManager.RTC_WAKEUP, wakeTime, pendingIntent);
        } else
            alarm.set(AlarmManager.RTC_WAKEUP, wakeTime, pendingIntent);
    } else {
        stopSelf();
    }
}
 
Example 3
Source File: DexShareCollectionService.java    From xDrip-Experimental with GNU General Public License v3.0 6 votes vote down vote up
public void setFailoverTimer() { //Sometimes it gets stuck in limbo on 4.4, this should make it try again
    if (CollectionServiceStarter.isBTShare(getApplicationContext())) {
        long retry_in = (1000 * 60 * 5);
        Log.d(TAG, "Fallover Restarting in: " + (retry_in / (60 * 1000)) + " minutes");
        Calendar calendar = Calendar.getInstance();
        AlarmManager alarm = (AlarmManager) getSystemService(ALARM_SERVICE);
        if (pendingIntent != null)
            alarm.cancel(pendingIntent);
        long wakeTime = calendar.getTimeInMillis() + retry_in;
        pendingIntent = PendingIntent.getService(this, 0, new Intent(this, this.getClass()), 0);
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
            alarm.setExactAndAllowWhileIdle(AlarmManager.RTC_WAKEUP, wakeTime, pendingIntent);
        } else if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
            alarm.setExact(AlarmManager.RTC_WAKEUP, wakeTime, pendingIntent);
        } else
            alarm.set(AlarmManager.RTC_WAKEUP, wakeTime, pendingIntent);
    } else {
        stopSelf();
    }
}
 
Example 4
Source File: DexShareCollectionService.java    From xDrip-plus with GNU General Public License v3.0 6 votes vote down vote up
public void setRetryTimer() {
    if (CollectionServiceStarter.isBTShare(getApplicationContext())) {
        BgReading bgReading = BgReading.last();
        long retry_in;
        if (bgReading != null) {
            retry_in = Math.min(Math.max((1000 * 30), (1000 * 60 * 5) - (new Date().getTime() - bgReading.timestamp) + (1000 * 5)), (1000 * 60 * 5));
        } else {
            retry_in = (1000 * 20);
        }
        Log.d(TAG, "Restarting in: " + (retry_in / (60 * 1000)) + " minutes");
        Calendar calendar = Calendar.getInstance();
        AlarmManager alarm = (AlarmManager) getSystemService(ALARM_SERVICE);
        if (pendingIntent != null)
            alarm.cancel(pendingIntent);
        long wakeTime = calendar.getTimeInMillis() + retry_in;
        pendingIntent = PendingIntent.getService(this, 0, new Intent(this, this.getClass()),  PendingIntent.FLAG_UPDATE_CURRENT);
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
            alarm.setExactAndAllowWhileIdle(AlarmManager.RTC_WAKEUP, wakeTime, pendingIntent);
        } else if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
            alarm.setExact(AlarmManager.RTC_WAKEUP, wakeTime, pendingIntent);
        } else
            alarm.set(AlarmManager.RTC_WAKEUP, wakeTime, pendingIntent);
    }
}
 
Example 5
Source File: DexShareCollectionService.java    From xDrip-Experimental with GNU General Public License v3.0 6 votes vote down vote up
public void setRetryTimer() {
    if (CollectionServiceStarter.isBTShare(getApplicationContext())) {
        BgReading bgReading = BgReading.last();
        long retry_in;
        if (bgReading != null) {
            retry_in = Math.min(Math.max((1000 * 30), (1000 * 60 * 5) - (new Date().getTime() - bgReading.timestamp) + (1000 * 5)), (1000 * 60 * 5));
        } else {
            retry_in = (1000 * 20);
        }
        Log.d(TAG, "Restarting in: " + (retry_in / (60 * 1000)) + " minutes");
        Calendar calendar = Calendar.getInstance();
        AlarmManager alarm = (AlarmManager) getSystemService(ALARM_SERVICE);
        if (pendingIntent != null)
            alarm.cancel(pendingIntent);
        long wakeTime = calendar.getTimeInMillis() + retry_in;
        pendingIntent = PendingIntent.getService(this, 0, new Intent(this, this.getClass()), 0);
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
            alarm.setExactAndAllowWhileIdle(AlarmManager.RTC_WAKEUP, wakeTime, pendingIntent);
        } else if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
            alarm.setExact(AlarmManager.RTC_WAKEUP, wakeTime, pendingIntent);
        } else
            alarm.set(AlarmManager.RTC_WAKEUP, wakeTime, pendingIntent);
    }
}
 
Example 6
Source File: DexShareCollectionService.java    From xDrip-plus with GNU General Public License v3.0 6 votes vote down vote up
public void setFailoverTimer() { //Sometimes it gets stuck in limbo on 4.4, this should make it try again
    if (CollectionServiceStarter.isBTShare(getApplicationContext())) {
        long retry_in = (1000 * 60 * 5);
        Log.d(TAG, "Fallover Restarting in: " + (retry_in / (60 * 1000)) + " minutes");
        Calendar calendar = Calendar.getInstance();
        AlarmManager alarm = (AlarmManager) getSystemService(ALARM_SERVICE);
        if (pendingIntent != null)
            alarm.cancel(pendingIntent);
        long wakeTime = calendar.getTimeInMillis() + retry_in;
        pendingIntent = PendingIntent.getService(this, 0, new Intent(this, this.getClass()), 0);
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
            alarm.setExactAndAllowWhileIdle(AlarmManager.RTC_WAKEUP, wakeTime, pendingIntent);
        } else if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
            alarm.setExact(AlarmManager.RTC_WAKEUP, wakeTime, pendingIntent);
        } else
            alarm.set(AlarmManager.RTC_WAKEUP, wakeTime, pendingIntent);
    } else {
        stopSelf();
    }
}
 
Example 7
Source File: DexShareCollectionService.java    From xDrip-plus with GNU General Public License v3.0 6 votes vote down vote up
public void setRetryTimer() {
    if (CollectionServiceStarter.isBTShare(getApplicationContext())) {
        BgReading bgReading = BgReading.last();
        long retry_in;
        if (bgReading != null) {
            retry_in = Math.min(Math.max((1000 * 30), (1000 * 60 * 5) - (new Date().getTime() - bgReading.timestamp) + (1000 * 5)), (1000 * 60 * 5));
        } else {
            retry_in = (1000 * 20);
        }
        Log.d(TAG, "Restarting in: " + (retry_in / (60 * 1000)) + " minutes");
        Calendar calendar = Calendar.getInstance();
        AlarmManager alarm = (AlarmManager) getSystemService(ALARM_SERVICE);
        if (pendingIntent != null)
            alarm.cancel(pendingIntent);
        long wakeTime = calendar.getTimeInMillis() + retry_in;
        pendingIntent = PendingIntent.getService(this, 0, new Intent(this, this.getClass()), 0);
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
            alarm.setExactAndAllowWhileIdle(AlarmManager.RTC_WAKEUP, wakeTime, pendingIntent);
        } else if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
            alarm.setExact(AlarmManager.RTC_WAKEUP, wakeTime, pendingIntent);
        } else
            alarm.set(AlarmManager.RTC_WAKEUP, wakeTime, pendingIntent);
    }
}
 
Example 8
Source File: DoubleCalibrationActivity.java    From xDrip-Experimental with GNU General Public License v3.0 5 votes vote down vote up
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    if(CollectionServiceStarter.isBTShare(getApplicationContext())) {
        Intent intent = new Intent(this, Home.class);
        startActivity(intent);
        finish();
    }
    setContentView(R.layout.activity_double_calibration);
    addListenerOnButton();
}
 
Example 9
Source File: DexShareCollectionService.java    From xDrip with GNU General Public License v3.0 5 votes vote down vote up
public void setRetryTimer() {
    if (CollectionServiceStarter.isBTShare(getApplicationContext())) {
        BgReading bgReading = BgReading.last();
        long retry_in;
        if (bgReading != null) {
            retry_in = Math.min(Math.max((1000 * 30), (1000 * 60 * 5) - (new Date().getTime() - bgReading.timestamp) - (1000 * 15)), (1000 * 60 * 5));
        } else {
            retry_in = (1000 * 20);
        }
        Log.d(TAG, "Restarting in: " + (retry_in / (60 * 1000)) + " minutes");
        Calendar calendar = Calendar.getInstance();
        AlarmManager alarm = (AlarmManager) getSystemService(ALARM_SERVICE);
        alarm.setExact(alarm.RTC_WAKEUP, calendar.getTimeInMillis() + retry_in, PendingIntent.getService(this, 0, new Intent(this, DexShareCollectionService.class), 0));
    }
}
 
Example 10
Source File: CalibrationOverride.java    From xDrip with GNU General Public License v3.0 5 votes vote down vote up
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    if(CollectionServiceStarter.isBTShare(getApplicationContext())) {
        Intent intent = new Intent(this, Home.class);
        startActivity(intent);
        finish();
    }
    setContentView(R.layout.activity_calibration_override);
    addListenerOnButton();
}
 
Example 11
Source File: CalibrationOverride.java    From xDrip with GNU General Public License v3.0 5 votes vote down vote up
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    if(CollectionServiceStarter.isBTShare(getApplicationContext())) {
        Intent intent = new Intent(this, Home.class);
        startActivity(intent);
        finish();
    }
    setContentView(R.layout.activity_calibration_override);
    addListenerOnButton();
}
 
Example 12
Source File: AddCalibration.java    From xDrip with GNU General Public License v3.0 5 votes vote down vote up
@Override
protected void onCreate(Bundle savedInstanceState) {
    xdrip.checkForcedEnglish(this);
    super.onCreate(savedInstanceState);
    if (CollectionServiceStarter.isBTShare(getApplicationContext())) {
        Intent intent = new Intent(this, Home.class);
        startActivity(intent);
        finish();
    }
    setContentView(R.layout.activity_add_calibration);
    addListenerOnButton();
    automatedCalibration();
}
 
Example 13
Source File: DexShareCollectionService.java    From xDrip-Experimental with GNU General Public License v3.0 5 votes vote down vote up
@Override
public int onStartCommand(Intent intent, int flags, int startId) {
    PowerManager powerManager = (PowerManager) getApplicationContext().getSystemService(POWER_SERVICE);
    PowerManager.WakeLock wakeLock = powerManager.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, "DexShareCollectionStart");
    wakeLock.acquire(40000);
    Log.d(TAG, "onStartCommand");
    try {

        if (android.os.Build.VERSION.SDK_INT < Build.VERSION_CODES.KITKAT) {
            stopSelf();
            return START_NOT_STICKY;
        }
        if (CollectionServiceStarter.isBTShare(getApplicationContext())) {
            setFailoverTimer();
        } else {
            stopSelf();
            return START_NOT_STICKY;
        }
        if (Sensor.currentSensor() == null) {
            setRetryTimer();
            return START_NOT_STICKY;
        }
        Log.i(TAG, "STARTING SERVICE");
        attemptConnection();
    } finally {
        if(wakeLock != null && wakeLock.isHeld()) wakeLock.release();
    }
    return START_STICKY;
}
 
Example 14
Source File: DoubleCalibrationActivity.java    From xDrip with GNU General Public License v3.0 5 votes vote down vote up
@Override
protected void onCreate(Bundle savedInstanceState) {
    xdrip.checkForcedEnglish(this);
    super.onCreate(savedInstanceState);
    if (CollectionServiceStarter.isBTShare(getApplicationContext())) {
        Intent intent = new Intent(this, Home.class);
        startActivity(intent);
        finish();
    }
    ActivityDoubleCalibrationBinding binding = ActivityDoubleCalibrationBinding.inflate(getLayoutInflater());
    binding.setPrefs(new PrefsViewImpl());
    setContentView(binding.getRoot());
    addListenerOnButton();
}
 
Example 15
Source File: NavDrawerBuilder.java    From xDrip-Experimental with GNU General Public License v3.0 4 votes vote down vote up
public NavDrawerBuilder(Context aContext) {
    context = aContext;
    boolean xDripViewer = XDripViewer.isxDripViewerMode(aContext);
    
    SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context);
    boolean IUnderstand = prefs.getBoolean("I_understand", false);
    if (IUnderstand == false) {
        this.nav_drawer_options.add("Settings");
        this.nav_drawer_intents.add(new Intent(context, Preferences.class));
        return;
    }

    this.nav_drawer_options.add(Home.menu_name);
    this.nav_drawer_intents.add(new Intent(context, Home.class));
    if (is_active_sensor) {
        this.nav_drawer_options.add("Calibration Graph");
        this.nav_drawer_intents.add(new Intent(context, CalibrationGraph.class));
    }

    if (prefs.getBoolean("show_data_tables", false)) {
        this.nav_drawer_options.add("BG Data Table");
        this.nav_drawer_intents.add(new Intent(context, BgReadingTable.class));
        this.nav_drawer_options.add("Calibration Data Table");
        this.nav_drawer_intents.add(new Intent(context, CalibrationDataTable.class));
    }

    if(!xDripViewer) {
        if(is_active_sensor) {
            if(!CollectionServiceStarter.isBTShare(context)) {
                if (last_two_bgReadings.size() > 1) {
                    if (last_two_calibrations.size() > 1) {
                        if (bGreadings_in_last_30_mins.size() >= 2) {
                            if (time_now - last_two_calibrations.get(0).timestamp < (1000 * 60 * 60)) { //Put steps in place to discourage over calibration
                                this.nav_drawer_options.add(CalibrationOverride.menu_name);
                                this.nav_drawer_intents.add(new Intent(context, CalibrationOverride.class));
                            } else {
                                this.nav_drawer_options.add(AddCalibration.menu_name);
                                this.nav_drawer_intents.add(new Intent(context, AddCalibration.class));
                            }
                        } else {
                            this.nav_drawer_options.add("Cannot Calibrate right now");
                            this.nav_drawer_intents.add(new Intent(context, Home.class));
                        }
                    } else {
                        this.nav_drawer_options.add(DoubleCalibrationActivity.menu_name);
                        this.nav_drawer_intents.add(new Intent(context, DoubleCalibrationActivity.class));
                    }
                }
            }
            this.nav_drawer_options.add(StopSensor.menu_name);
            this.nav_drawer_intents.add(new Intent(context, StopSensor.class));
        } else {
            this.nav_drawer_options.add(StartNewSensor.menu_name);
            this.nav_drawer_intents.add(new Intent(context, StartNewSensor.class));
        }
    }

    if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.JELLY_BEAN_MR2) {
        if(CollectionServiceStarter.isBteWixelorWifiandBtWixel(context) || CollectionServiceStarter.isDexbridgeWixelorWifiandDexbridgeWixel(context)|| CollectionServiceStarter.isBTShare(context) ) {
            this.nav_drawer_options.add(BluetoothScan.menu_name);
            this.nav_drawer_intents.add(new Intent(context, BluetoothScan.class));
        }
    }

    if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.JELLY_BEAN_MR2) {
        this.nav_drawer_options.add(SystemStatus.menu_name);
        this.nav_drawer_intents.add(new Intent(context, SystemStatus.class));
    }

    boolean bg_alerts = prefs.getBoolean("bg_alerts_from_main_menu", false);
    if (bg_alerts) {
        this.nav_drawer_options.add(AlertList.menu_name);
        this.nav_drawer_intents.add(new Intent(context, AlertList.class));
    }
    this.nav_drawer_options.add(SnoozeActivity.menu_name);
    this.nav_drawer_intents.add(new Intent(context, SnoozeActivity.class));

    this.nav_drawer_options.add(StatsActivity.MENU_NAME);
    this.nav_drawer_intents.add(new Intent(context, StatsActivity.class));

    this.nav_drawer_options.add(BGHistory.menu_name);
    this.nav_drawer_intents.add(new Intent(context, BGHistory.class));

    this.nav_drawer_options.add("Settings");
    this.nav_drawer_intents.add(new Intent(context, Preferences.class));
}
 
Example 16
Source File: NavDrawerBuilder.java    From xDrip with GNU General Public License v3.0 4 votes vote down vote up
private final List<String> nav_drawer_options() {
        List<String> options = new ArrayList<String>();
        SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context);
        boolean IUnderstand = prefs.getBoolean("I_understand", false);
        if(IUnderstand == false) {
            options.add("Settings");
            return options;
        }

        options.add("xDrip");
        if(is_active_sensor) {
            options.add("Calibration Graph");
        }
        options.add("BG Data Table");
        options.add("Calibration Data Table");
//        options.add("Sensor Data Table");

        if(is_active_sensor) {
            if(!CollectionServiceStarter.isBTShare(context)) {
                if (last_two_bgReadings.size() > 1) {
                    if (last_two_calibrations.size() > 1) {
                        if (bGreadings_in_last_30_mins.size() >= 2) {
                            if (time_now - last_two_calibrations.get(0).timestamp < (1000 * 60 * 60)) { //Put steps in place to discourage over calibration
                                options.add("Override Calibration");
                            } else {
                                options.add("Add Calibration");
                            }
                        } else {
                            options.add("Cannot Calibrate right now");
                        }
                        if (last_two_calibrations.get(0).slope >= 1.4 || last_two_calibrations.get(0).slope <= 0.5) {
                            options.add("Add Double Calibration");
                        }
                    } else {
                        options.add("Add Double Calibration");
                    }
                }
            }
            options.add("Stop Sensor");
        } else { options.add("Start Sensor"); }
        if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.JELLY_BEAN_MR2) {
            if(CollectionServiceStarter.isBTWixel(context) || CollectionServiceStarter.isBTShare(context)) {
                options.add("Scan for BT");
            }
        }
        options.add("System Status");
        options.add("Settings");
//        options.add("Fake Numbers");
//        options.add("Add Double Calibration");
//        options.add("Share Test");
        return options;
    }
 
Example 17
Source File: DexShareCollectionService.java    From xDrip with GNU General Public License v3.0 4 votes vote down vote up
private static boolean shouldServiceRun(Context context) {
    if (android.os.Build.VERSION.SDK_INT < Build.VERSION_CODES.JELLY_BEAN_MR2) return false;
    final boolean result = CollectionServiceStarter.isBTShare(context) && !Home.get_forced_wear();
    Log.d(TAG, "shouldServiceRun() returning: " + result);
    return result;
}
 
Example 18
Source File: Home.java    From xDrip-Experimental with GNU General Public License v3.0 4 votes vote down vote up
private void updateCurrentBgInfo() {
     setupCharts();
     final TextView notificationText = (TextView) findViewById(R.id.notices);
     notificationText.setText("");
     notificationText.setTextColor(Color.parseColor("#FF0000"));
     boolean isBTWixel = CollectionServiceStarter.isBteWixelorWifiandBtWixel(getApplicationContext());
     boolean isDexbridgeWixel = CollectionServiceStarter.isDexbridgeWixelorWifiandDexbridgeWixel(getApplicationContext());
     isBTShare = CollectionServiceStarter.isBTShare(getApplicationContext());
     isG5Share = CollectionServiceStarter.isBTG5(getApplicationContext());
     boolean isWifiWixel = CollectionServiceStarter.isWifiWixel(getApplicationContext());
     alreadyDisplayedBgInfoCommon = false; // reset flag
     
     boolean xDripViewer = XDripViewer.isxDripViewerMode(getApplicationContext());
     
     if(xDripViewer) {
         updateCurrentBgInfoForxDripViewer(notificationText);
     } else if (isBTShare) {
         updateCurrentBgInfoForBtShare(notificationText);
     } else if (isBTWixel || isDexbridgeWixel) {
         updateCurrentBgInfoForBtBasedWixel(notificationText);
     } else if (isWifiWixel) {
         updateCurrentBgInfoForWifiWixel(notificationText);
     }
     if (isG5Share) {
         updateCurrentBgInfoCommon(notificationText);
     }

     if (mPreferences.getLong("alerts_disabled_until", 0) > new Date().getTime()) {
         notificationText.append("\n ALL ALERTS DISABLED");
     } else if (mPreferences.getLong("low_alerts_disabled_until", 0) > new Date().getTime()
&&
mPreferences.getLong("high_alerts_disabled_until", 0) > new Date().getTime()) {
         notificationText.append("\nLOW AND HIGH ALERTS DISABLED");
     } else if (mPreferences.getLong("low_alerts_disabled_until", 0) > new Date().getTime()) {
         notificationText.append("\nLOW ALERTS DISABLED");
     } else if (mPreferences.getLong("high_alerts_disabled_until", 0) > new Date().getTime()) {
         notificationText.append("\nHIGH ALERTS DISABLED");
     }
     if(mPreferences.getBoolean("extra_status_line", false)) {
         extraStatusLineText.setText(extraStatusLine(mPreferences));
         extraStatusLineText.setVisibility(View.VISIBLE);
     } else {
         extraStatusLineText.setText("");
         extraStatusLineText.setVisibility(View.GONE);
     }
     NavigationDrawerFragment navigationDrawerFragment = (NavigationDrawerFragment) getFragmentManager().findFragmentById(R.id.navigation_drawer);
     navigationDrawerFragment.setUp(R.id.navigation_drawer, (DrawerLayout) findViewById(R.id.drawer_layout), menu_name, this);
 }
 
Example 19
Source File: BluetoothScan.java    From xDrip-Experimental with GNU General Public License v3.0 4 votes vote down vote up
@Override
protected void onListItemClick(ListView l, View v, int position, long id) {
    Log.d(TAG, "Item Clicked");
    final BluetoothDevice device = mLeDeviceListAdapter.getDevice(position);
    if (device == null || device.getName() == null) return;
    Toast.makeText(this, R.string.connecting_to_device, Toast.LENGTH_LONG).show();

    ActiveBluetoothDevice btDevice = new Select().from(ActiveBluetoothDevice.class)
            .orderBy("_ID desc")
            .executeSingle();

    final SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(getApplicationContext());
    prefs.edit().putString("last_connected_device_address", device.getAddress()).apply();
    if (btDevice == null) {
        ActiveBluetoothDevice newBtDevice = new ActiveBluetoothDevice();
        newBtDevice.name = device.getName();
        newBtDevice.address = device.getAddress();
        newBtDevice.save();
    } else {
        btDevice.name = device.getName();
        btDevice.address = device.getAddress();
        btDevice.save();
    }
    if(device.getName().toLowerCase().contains("dexcom")) {
        if(!CollectionServiceStarter.isBTShare(getApplicationContext())) {
            prefs.edit().putString("dex_collection_method", "DexcomShare").apply();
            prefs.edit().putBoolean("calibration_notifications", false).apply();
        }
        if(prefs.getString("share_key", "SM00000000").compareTo("SM00000000") == 0 || prefs.getString("share_key", "SM00000000").length() < 10) {
            requestSerialNumber(prefs);
        } else returnToHome();

    } else if(device.getName().toLowerCase().contains("bridge")) {
        if(!CollectionServiceStarter.isDexbridgeWixelorWifiandDexbridgeWixel(getApplicationContext()))
            prefs.edit().putString("dex_collection_method", "DexbridgeWixel").apply();
        if(prefs.getString("dex_txid", "00000").compareTo("00000") == 0 || prefs.getString("dex_txid", "00000").length() < 5) {
            requestTransmitterId(prefs);
        } else returnToHome();

    } else if(device.getName().toLowerCase().contains("drip")) {
        if (!
                (CollectionServiceStarter.isBteWixelorWifiandBtWixel(getApplicationContext())
                ) || CollectionServiceStarter.isLimitter(getApplicationContext())) {
            prefs.edit().putString("dex_collection_method", "BluetoothWixel").apply();
        }
        returnToHome();
    } else if(device.getName().toLowerCase().contains("limitter")) {
        if (!CollectionServiceStarter.isLimitter(getApplicationContext())) {
            prefs.edit().putString("dex_collection_method", "LimiTTer").apply();
        }
        returnToHome();
    } else {
        returnToHome();
    }
}
 
Example 20
Source File: DexShareCollectionService.java    From xDrip with GNU General Public License v3.0 4 votes vote down vote up
private static boolean shouldServiceRun(Context context) {
    if (android.os.Build.VERSION.SDK_INT < Build.VERSION_CODES.KITKAT) return false;
    final boolean result = CollectionServiceStarter.isBTShare(context) && PersistentStore.getBoolean(CollectionServiceStarter.pref_run_wear_collector);
    Log.d(TAG, "shouldServiceRun() returning: " + result);
    return result;
}