Search in sources :

Example 31 with Select

use of com.activeandroid.query.Select in project xDrip-plus by jamorham.

the class PenData method getMissingIndex.

public static long getMissingIndex(final String mac) {
    if (mac == null)
        return -1;
    final List<PenData> list = new Select().from(PenData.class).where("pen_mac = ?", mac).where("timestamp > ?", JoH.tsl() - Constants.WEEK_IN_MS).orderBy("idx desc").execute();
    long got = -1;
    for (final PenData pd : list) {
        if (got != -1 && pd.index != got - 1) {
            UserError.Log.d(TAG, "Tripped missing index on: " + got + " vs " + pd.index);
            return got - 1;
        }
        got = pd.index;
    }
    return -1;
}
Also used : Select(com.activeandroid.query.Select)

Example 32 with Select

use of com.activeandroid.query.Select in project xDrip-plus by jamorham.

the class Reminder method getAllReminders.

public static List<Reminder> getAllReminders() {
    fixUpTable(schema);
    final List<Reminder> reminders = new Select().from(Reminder.class).orderBy("enabled desc, priority desc, next_due asc").execute();
    return reminders;
}
Also used : Select(com.activeandroid.query.Select)

Example 33 with Select

use of com.activeandroid.query.Select in project xDrip-plus by jamorham.

the class BluetoothScan method onListItemClick.

@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();
    final SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(getApplicationContext());
    synchronized (ActiveBluetoothDevice.table_lock) {
        ActiveBluetoothDevice btDevice = new Select().from(ActiveBluetoothDevice.class).orderBy("_ID desc").executeSingle();
        prefs.edit().putString("last_connected_device_address", device.getAddress()).apply();
        Blukon.clearPin();
        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();
        }
        startWatchUpdaterService(this, WatchUpdaterService.ACTION_SYNC_ACTIVEBTDEVICE, TAG);
    }
    // automatically set or unset the option for "Transmiter" device
    boolean using_transmiter = false;
    // Experimental support for rfduino from Tomasz Stachowicz
    // automatically set or unset the option for "RFDuino" device
    boolean using_rfduino = false;
    try {
        if (device.getName().toLowerCase().contains("limitter") && (adverts.containsKey(device.getAddress()) && ((new String(adverts.get(device.getAddress()), "UTF-8").contains("eLeR")) || (new String(adverts.get(device.getAddress()), "UTF-8").contains("data")))) || device.getName().toLowerCase().contains("limitterd")) {
            String msg = "Auto-detected transmiter_pl device!";
            Log.e(TAG, msg);
            JoH.static_toast_long(msg);
            using_transmiter = true;
        }
        prefs.edit().putBoolean("use_transmiter_pl_bluetooth", using_transmiter).apply();
        // Experimental support for rfduino from Tomasz Stachowicz
        if (device.getName().toLowerCase().contains("xbridge") && (adverts.containsKey(device.getAddress()) && (new String(adverts.get(device.getAddress()), "UTF-8").contains("rfduino")))) {
            String msg = "Auto-detected rfduino device!";
            Log.e(TAG, msg);
            JoH.static_toast_long(msg);
            using_rfduino = true;
        }
        prefs.edit().putBoolean("use_rfduino_bluetooth", using_rfduino).apply();
        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.isDexBridgeOrWifiandDexBridge())
                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.isBTWixelOrLimiTTer(getApplicationContext()) || CollectionServiceStarter.isWifiandBTWixel(getApplicationContext())) || CollectionServiceStarter.isLimitter()) {
                prefs.edit().putString("dex_collection_method", "BluetoothWixel").apply();
            }
            returnToHome();
        } else if (device.getName().toLowerCase().contains("limitter")) {
            if (!CollectionServiceStarter.isLimitter()) {
                prefs.edit().putString("dex_collection_method", "LimiTTer").apply();
            }
            returnToHome();
        } else if (device.getName().toLowerCase().contains("bluereader")) {
            if (!CollectionServiceStarter.isLimitter()) {
                prefs.edit().putString("dex_collection_method", "LimiTTer").apply();
            }
            returnToHome();
        } else if ((device.getName().toLowerCase().contains("miaomiao")) || (device.getName().toLowerCase().startsWith("watlaa"))) {
            if (!(CollectionServiceStarter.isLimitter() || CollectionServiceStarter.isWifiandBTLibre())) {
                prefs.edit().putString("dex_collection_method", "LimiTTer").apply();
            }
            returnToHome();
        } else if (device.getName().toLowerCase().contains("sweetreader")) {
            if (!CollectionServiceStarter.isLimitter()) {
                prefs.edit().putString("dex_collection_method", "LimiTTer").apply();
            }
            returnToHome();
        } else if (device.getName().matches("^BLU[0-9][0-9][0-9][0-9][0-9].*$")) {
            Blukon.doPinDialog(this, new Runnable() {

                @Override
                public void run() {
                    if (!CollectionServiceStarter.isLimitter()) {
                        prefs.edit().putString("dex_collection_method", "LimiTTer").apply();
                    }
                    returnToHome();
                }
            });
        } else if (device.getName().matches("MT")) {
            if (Medtrum.saveSerialFromLegacy(adverts.get(device.getAddress()))) {
                JoH.static_toast_long("Set Medtrum serial number");
                CollectionServiceStarter.restartCollectionServiceBackground();
                returnToHome();
            } else {
                JoH.static_toast_long("Failed to find Medtrum serial number");
            }
        } else {
            returnToHome();
        }
    } catch (UnsupportedEncodingException | NullPointerException e) {
        Log.d(TAG, "Got exception in listitemclick: " + Arrays.toString(e.getStackTrace()));
    }
}
Also used : ActiveBluetoothDevice(com.eveningoutpost.dexdrip.Models.ActiveBluetoothDevice) BluetoothDevice(android.bluetooth.BluetoothDevice) ActiveBluetoothDevice(com.eveningoutpost.dexdrip.Models.ActiveBluetoothDevice) SharedPreferences(android.content.SharedPreferences) Select(com.activeandroid.query.Select) UnsupportedEncodingException(java.io.UnsupportedEncodingException)

Example 34 with Select

use of com.activeandroid.query.Select in project xDrip-plus by jamorham.

the class DBSearchUtil method noReadingsInRange.

public static int noReadingsInRange(Context context) {
    Bounds bounds = new Bounds().invoke();
    SharedPreferences settings = PreferenceManager.getDefaultSharedPreferences(context);
    boolean mgdl = "mgdl".equals(settings.getString("units", "mgdl"));
    double high = Double.parseDouble(settings.getString("highValue", "170"));
    double low = Double.parseDouble(settings.getString("lowValue", "70"));
    if (!mgdl) {
        high *= Constants.MMOLL_TO_MGDL;
        low *= Constants.MMOLL_TO_MGDL;
    }
    int count = new Select().from(BgReading.class).where("timestamp >= " + bounds.start).where("timestamp <= " + bounds.stop).where("calculated_value > " + CUTOFF).where("calculated_value <= " + high).where("calculated_value >= " + low).where("snyced == 0").count();
    Log.d("DrawStats", "In count: " + count);
    return count;
}
Also used : SharedPreferences(android.content.SharedPreferences) Select(com.activeandroid.query.Select) BgReading(com.eveningoutpost.dexdrip.Models.BgReading)

Example 35 with Select

use of com.activeandroid.query.Select in project xDrip-plus by jamorham.

the class UploaderQueue method getCount.

private static int getCount(String where) {
    try {
        final String query = new Select("COUNT(*) as total").from(UploaderQueue.class).toSql();
        final Cursor resultCursor = Cache.openDatabase().rawQuery(query + where, null);
        if (resultCursor.moveToNext()) {
            final int total = resultCursor.getInt(0);
            resultCursor.close();
            return total;
        } else {
            return 0;
        }
    } catch (Exception e) {
        Log.d(TAG, "Got exception getting count: " + e);
        return 0;
    }
}
Also used : Select(com.activeandroid.query.Select) Cursor(android.database.Cursor) JSONException(org.json.JSONException)

Aggregations

Select (com.activeandroid.query.Select)80 SharedPreferences (android.content.SharedPreferences)14 From (com.activeandroid.query.From)11 MockModel (com.activeandroid.test.MockModel)11 DecimalFormat (java.text.DecimalFormat)8 ArrayList (java.util.ArrayList)7 Date (java.util.Date)7 Cursor (android.database.Cursor)6 ActiveBluetoothDevice (com.eveningoutpost.dexdrip.Models.ActiveBluetoothDevice)6 JSONException (org.json.JSONException)5 GsonBuilder (com.google.gson.GsonBuilder)4 PendingIntent (android.app.PendingIntent)2 BluetoothDevice (android.bluetooth.BluetoothDevice)2 Intent (android.content.Intent)2 Update (com.activeandroid.query.Update)2 BgReading (com.eveningoutpost.dexdrip.Models.BgReading)2 MissedReadingService (com.eveningoutpost.dexdrip.Services.MissedReadingService)2 Gson (com.google.gson.Gson)2 DateTypeAdapter (com.google.gson.internal.bind.DateTypeAdapter)2 UnsupportedEncodingException (java.io.UnsupportedEncodingException)2