Search in sources :

Example 66 with Select

use of com.activeandroid.query.Select in project xDrip by NightscoutFoundation.

the class BgReading method is_new.

public static boolean is_new(SensorRecord sensorRecord, long addativeOffset) {
    double timestamp = sensorRecord.getSystemTime().getTime() + addativeOffset;
    Sensor sensor = Sensor.currentSensor();
    if (sensor != null) {
        BgReading bgReading = new Select().from(BgReading.class).where("Sensor = ? ", sensor.getId()).where("timestamp <= ?", // 1 minute padding (should never be that far off, but why not)
        (timestamp + (60 * 1000))).orderBy("timestamp desc").executeSingle();
        if (bgReading != null && Math.abs(bgReading.timestamp - timestamp) < (3 * 60 * 1000)) {
            // cool, so was it actually within 4 minutes of that bg reading?
            Log.i(TAG, "isNew; Old Reading");
            return false;
        }
    }
    Log.i(TAG, "isNew: New Reading");
    return true;
}
Also used : Select(com.activeandroid.query.Select)

Example 67 with Select

use of com.activeandroid.query.Select in project xDrip by NightscoutFoundation.

the class BgReading method getForTimestamp.

public static BgReading getForTimestamp(double timestamp) {
    Sensor sensor = Sensor.currentSensor();
    if (sensor != null) {
        BgReading bgReading = new Select().from(BgReading.class).where("Sensor = ? ", sensor.getId()).where("timestamp <= ?", // 1 minute padding (should never be that far off, but why not)
        (timestamp + (60 * 1000))).where("calculated_value = 0").where("raw_calculated = 0").orderBy("timestamp desc").executeSingle();
        if (bgReading != null && Math.abs(bgReading.timestamp - timestamp) < (3 * 60 * 1000)) {
            // cool, so was it actually within 4 minutes of that bg reading?
            Log.i(TAG, "getForTimestamp: Found a BG timestamp match");
            return bgReading;
        }
    }
    Log.d(TAG, "getForTimestamp: No luck finding a BG timestamp match");
    return null;
}
Also used : Select(com.activeandroid.query.Select)

Example 68 with Select

use of com.activeandroid.query.Select in project xDrip by NightscoutFoundation.

the class AlertType method toSettings.

// Convert all settings to a string and save it in the references. This is needed to allow it's backup.
public static boolean toSettings(Context context) {
    SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context);
    List<AlertType> alerts = new Select().from(AlertType.class).execute();
    Gson gson = new GsonBuilder().excludeFieldsWithoutExposeAnnotation().registerTypeAdapter(Date.class, new DateTypeAdapter()).serializeSpecialFloatingPointValues().create();
    String output = gson.toJson(alerts);
    Log.e(TAG, "Created the string " + output);
    prefs.edit().putString("saved_alerts", output).commit();
    return true;
}
Also used : DateTypeAdapter(com.google.gson.internal.bind.DateTypeAdapter) SharedPreferences(android.content.SharedPreferences) GsonBuilder(com.google.gson.GsonBuilder) Select(com.activeandroid.query.Select) Gson(com.google.gson.Gson)

Example 69 with Select

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

the class ShareTest method attemptConnection.

public void attemptConnection() {
    mBluetoothManager = (BluetoothManager) getSystemService(Context.BLUETOOTH_SERVICE);
    if (device != null) {
        details.append("\nConnection state: " + " Device is not null");
        mConnectionState = mBluetoothManager.getConnectionState(device, BluetoothProfile.GATT);
    }
    Log.i(TAG, "Connection state: " + mConnectionState);
    details.append("\nConnection state: " + mConnectionState);
    if (mConnectionState == STATE_DISCONNECTED || mConnectionState == STATE_DISCONNECTING) {
        ActiveBluetoothDevice btDevice = new Select().from(ActiveBluetoothDevice.class).orderBy("_ID desc").executeSingle();
        if (btDevice != null) {
            details.append("\nBT Device: " + btDevice.name);
            mDeviceName = btDevice.name;
            mDeviceAddress = btDevice.address;
            mBluetoothAdapter = mBluetoothManager.getAdapter();
            boolean newConnection = true;
            if (newConnection) {
                is_connected = connect(mDeviceAddress);
                details.append("\nConnecting...: ");
            }
        }
    }
}
Also used : ActiveBluetoothDevice(com.eveningoutpost.dexdrip.Models.ActiveBluetoothDevice) Select(com.activeandroid.query.Select)

Example 70 with Select

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

the class UploaderQueue method getLegacyCount.

private static int getLegacyCount(Class which, Boolean rest, Boolean mongo, Boolean and) {
    try {
        String where = "";
        if (rest != null)
            where += " success = " + (rest ? "1 " : "0 ");
        if (and != null)
            where += (and ? " and " : " or ");
        if (mongo != null)
            where += " mongo_success = " + (mongo ? "1 " : "0 ");
        final String query = new Select("COUNT(*) as total").from(which).toSql();
        final Cursor resultCursor = Cache.openDatabase().rawQuery(query + ((where.length() > 0) ? " where " + 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 -1;
    }
}
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