com.google.gson.internal.bind.DateTypeAdapter#com.activeandroid.query.Select源码实例Demo

下面列出了com.google.gson.internal.bind.DateTypeAdapter#com.activeandroid.query.Select 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。

源代码1 项目: xDrip   文件: AlertType.java
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(); // always leave this as commit

    return true;

}
 
源代码2 项目: xDrip-plus   文件: Calibration.java
public static double max_recent() {
    Sensor sensor = Sensor.currentSensor();
    Calibration calibration = new Select()
            .from(Calibration.class)
            .where("Sensor = ? ", sensor.getId())
            .where("slope_confidence != 0")
            .where("sensor_confidence != 0")
            .where("timestamp > ?", (new Date().getTime() - (60000 * 60 * 24 * 4)))
            .orderBy("bg desc")
            .executeSingle();
    if (calibration != null) {
        return calibration.bg;
    } else {
        return 120;
    }
}
 
源代码3 项目: xDrip-plus   文件: BgReading.java
public static BgReading getForPreciseTimestamp(long timestamp, long precision, boolean lock_to_sensor) {
    final Sensor sensor = Sensor.currentSensor();
    if ((sensor != null) || !lock_to_sensor) {
        final BgReading bgReading = new Select()
                .from(BgReading.class)
                .where(lock_to_sensor ? "Sensor = ?" : "timestamp > ?", (lock_to_sensor ? sensor.getId() : 0))
                .where("timestamp <= ?", (timestamp + precision))
                .where("timestamp >= ?", (timestamp - precision))
                .orderBy("abs(timestamp - " + timestamp + ") asc")
                .executeSingle();
        if (bgReading != null && Math.abs(bgReading.timestamp - timestamp) < precision) { //cool, so was it actually within precision of that bg reading?
            //Log.d(TAG, "getForPreciseTimestamp: Found a BG timestamp match");
            return bgReading;
        }
    }
    Log.d(TAG, "getForPreciseTimestamp: No luck finding a BG timestamp match: " + JoH.dateTimeText((long) timestamp) + " precision:" + precision + " Sensor: " + ((sensor == null) ? "null" : sensor.getId()));
    return null;
}
 
源代码4 项目: xDrip-plus   文件: UploaderQueue.java
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;
    }
}
 
源代码5 项目: xDrip-plus   文件: AlertType.java
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;

}
 
源代码6 项目: xDrip   文件: UserNotification.java
public static UserNotification GetNotificationByType(String type) {
    if (legacy_types.contains(type)) {
        type = type + " = ?";
        return new Select()
                .from(UserNotification.class)
                .where(type, true)
                .orderBy("_ID desc")
                .executeSingle();
    } else {
        final String timestamp = PersistentStore.getString("UserNotification:timestamp:" + type);
        if (timestamp.equals("")) return null;
        final String message = PersistentStore.getString("UserNotification:message:" + type);
        if (message.equals("")) return null;
        UserNotification userNotification = new UserNotification();
        userNotification.timestamp = JoH.tolerantParseDouble(timestamp, -1);
        if (userNotification.timestamp == -1) return null; // bad data
        userNotification.message = message;
        Log.d(TAG, "Workaround for: " + type + " " + userNotification.message + " timestamp: " + userNotification.timestamp);
        return userNotification;
    }
}
 
源代码7 项目: xDrip   文件: Reminder.java
public static Reminder getNextActiveReminder() {
    fixUpTable(schema);
    final boolean onHomeWifi = !HomeWifi.isSet() || HomeWifi.isConnected();
    final long now = JoH.tsl();
    final Reminder reminder = new Select()
            .from(Reminder.class)
            .where("enabled = ?", true)
            .where("next_due < ?", now)
            .where("snoozed_till < ?", now)
            .where("last_fired < (? - (600000 * alerted_times))", now)
            // if on home wifi or not set then anything otherwise only home only = false
            .where(onHomeWifi ? "homeonly > -1 " : "homeonly = 0")
            .orderBy("enabled desc, priority desc, next_due asc")
            .executeSingle();
    return reminder;
}
 
源代码8 项目: xDrip-plus   文件: TransmitterData.java
public static TransmitterData getForTimestamp(double timestamp) {//KS
    try {
        Sensor sensor = Sensor.currentSensor();
        if (sensor != null) {
            TransmitterData bgReading = new Select()
                    .from(TransmitterData.class)
                    .where("timestamp <= ?", (timestamp + (60 * 1000))) // 1 minute padding (should never be that far off, but why not)
                    .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;
            }
        }
    } catch (Exception e) {
        Log.e(TAG,"getForTimestamp() Got exception on Select : "+e.toString());
        return null;
    }
    Log.d(TAG, "getForTimestamp: No luck finding a BG timestamp match");
    return null;
}
 
源代码9 项目: xDrip   文件: Calibration.java
public static List<Calibration> latestValid(int number, long until) {
    Sensor sensor = Sensor.currentSensor();
    if (sensor == null) {
        return null;
    }
    // we don't filter invalid intercepts here as they will be filtered in the plugin itself
    return new Select()
            .from(Calibration.class)
            .where("Sensor = ? ", sensor.getId())
            .where("slope_confidence != 0")
            .where("sensor_confidence != 0")
            .where("slope != 0")
            .where("timestamp <= ?", until)
            .orderBy("timestamp desc")
            .limit(number)
            .execute();
}
 
private List<Notification> getAll() {
    //Getting all items stored in Inventory table
    return new Select()
            .from(Notification.class)
            .limit(10)
            .execute();
}
 
public void markAsRead(View view) {

        List<Notification> listtodel= new Select()
                .from(Notification.class)
                .limit(10)
                .execute();

        for (int i=listtodel.size()-1;i>=0;i--){
            Notification.delete(Notification.class,i);
        }
        Intent refresh = new Intent(this, NotificationActivity.class);
        startActivity(refresh);//Start the same Activity
        finish(); //finish Activity.
    }
 
源代码12 项目: xDrip-plus   文件: UserError.java
public static void cleanup(long timestamp) {
    patched = fixUpTable(schema, patched);
    List<UserError> userErrors = new Select()
            .from(UserError.class)
            .where("timestamp < ?", timestamp)
            .orderBy("timestamp desc")
            .execute();
    if (userErrors != null) Log.d(TAG, "cleanup UserError size=" + userErrors.size());
    new Cleanup().execute(userErrors);
}
 
源代码13 项目: xDrip-plus   文件: BgReading.java
public static List<BgReading> latestForGraphAsc(int number, long startTime, long endTime) {//KS
    return new Select()
            .from(BgReading.class)
            .where("timestamp >= " + Math.max(startTime, 0))
            .where("timestamp <= " + endTime)
            .where("calculated_value != 0")
            .where("raw_data != 0")
            .orderBy("timestamp asc")
            .limit(number)
            .execute();
}
 
源代码14 项目: xDrip-plus   文件: AlertType.java
public static List<AlertType> getAll(boolean above) {
    String order;
    if (above) {
        order = "threshold asc";
    } else {
        order = "threshold desc";
    }
    List<AlertType> alerts  = new Select()
        .from(AlertType.class)
        .where("above = ?", above)
        .orderBy(order)
        .execute();

    return alerts;
}
 
源代码15 项目: xDrip-plus   文件: Calibration.java
public static Calibration lastValid() {
    Sensor sensor = Sensor.currentSensor();
    if (sensor == null) {
        return null;
    }
    return new Select()
            .from(Calibration.class)
            .where("Sensor = ? ", sensor.getId())
            .where("slope_confidence != 0")
            .where("sensor_confidence != 0")
            .where("slope != 0")
            .orderBy("timestamp desc")
            .executeSingle();
}
 
源代码16 项目: xDrip   文件: LibreBlock.java
public static LibreBlock getForTimestamp(long timestamp) {
    final long margin = (3 * 1000);
    return new Select()
            .from(LibreBlock.class)
            .where("timestamp >= ?", (timestamp - margin))
            .where("timestamp <= ?", (timestamp + margin))
            .executeSingle();
}
 
源代码17 项目: xDrip   文件: BgReading.java
public static List<BgReading> latest(int number, boolean is_follower) {
    if (is_follower) {
        // exclude sensor information when working as a follower
        return new Select()
                .from(BgReading.class)
                .where("calculated_value != 0")
                .where("raw_data != 0")
        //        .where("timestamp <= ?", JoH.tsl())
                .orderBy("timestamp desc")
                .limit(number)
                .execute();
    } else {
        Sensor sensor = Sensor.currentSensor();
        if (sensor == null) {
            return null;
        }
        return new Select()
                .from(BgReading.class)
                .where("Sensor = ? ", sensor.getId())
                .where("calculated_value != 0")
                .where("raw_data != 0")
          //      .where("timestamp <= ?", JoH.tsl())
                .orderBy("timestamp desc")
                .limit(number)
                .execute();
    }
}
 
源代码18 项目: xDrip   文件: AlertType.java
public static void remove_all() {
    List<AlertType> Alerts  = new Select()
    .from(AlertType.class)
    .execute();

    for (AlertType alert : Alerts) {
        alert.delete();
    }
    ActiveBgAlert.ClearData();
}
 
源代码19 项目: xDrip   文件: BgReading.java
public static BgReading byUUID(String uuid) {
    if (uuid == null) return null;
    return new Select()
            .from(BgReading.class)
            .where("uuid = ?", uuid)
            .executeSingle();
}
 
源代码20 项目: xDrip   文件: Treatments.java
public static List<Treatments> latest(int num) {
    try {
        return new Select()
                .from(Treatments.class)
                .orderBy("timestamp desc")
                .limit(num)
                .execute();
    } catch (android.database.sqlite.SQLiteException e) {
        fixUpTable();
        return null;
    }
}
 
源代码21 项目: xDrip   文件: Reminder.java
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;
}
 
源代码22 项目: xDrip   文件: UserError.java
public static List<UserError> bySeverity(Integer[] levels) {
    String levelsString = " ";
    for (int level : levels) {
        levelsString += level + ",";
    }
    Log.d("UserError", "severity in ("+levelsString.substring(0,levelsString.length() - 1)+")");
    return new Select()
            .from(UserError.class)
            .where("severity in ("+levelsString.substring(0,levelsString.length() - 1)+")")
            .orderBy("timestamp desc")
            .limit(10000)//too many data can kill akp
            .execute();
}
 
源代码23 项目: GankLock   文件: DailyGankData.java
public List<GankDaily> getDailyDataFromDB(Observer<List<GankDaily>> observer) {
    Observable.create(new ObservableOnSubscribe<List<GankDaily>>() {
        @Override
        public void subscribe(ObservableEmitter<List<GankDaily>> emitter) throws Exception {
            List<GankDaily> list = new Select().from(GankDaily.class)
                    .orderBy("publishedAt DESC")//DESC ASC
                    .execute();
            emitter.onNext(list);
        }
    }).subscribeOn(Schedulers.io())
        .subscribe(observer);
    return mList;
}
 
源代码24 项目: xDrip   文件: SensorSendQueue.java
public static List<SensorSendQueue> queue() {
    return new Select()
            .from(SensorSendQueue.class)
            .where("success = ?", false)
            .orderBy("_ID desc")
            .execute();
}
 
源代码25 项目: xDrip-plus   文件: BgReading.java
public static List<BgReading> futureReadings() {
    double timestamp = new Date().getTime();
    return new Select()
            .from(BgReading.class)
            .where("timestamp > " + timestamp)
            .orderBy("timestamp desc")
            .execute();
}
 
源代码26 项目: xDrip-plus   文件: Sensor.java
public static Sensor currentSensor() {
    try {//KS
        Sensor sensor = new Select()
                .from(Sensor.class)
                .where("started_at != 0")
                .where("stopped_at = 0")
                .orderBy("_ID desc")
                .limit(1)
                .executeSingle();
        return sensor;
    }
    catch (Exception e) {
        return null;
    }
}
 
源代码27 项目: xDrip   文件: BgReading.java
public static List<BgReading> latestForGraphSensor(int number, long startTime, long endTime) {
    Sensor sensor = Sensor.currentSensor();
    if (sensor == null) { return null; }
    return new Select()
            .from(BgReading.class)
            .where("Sensor = ? ", sensor.getId())
            .where("timestamp >= " + Math.max(startTime, 0))
            .where("timestamp <= " + endTime)
            .where("calculated_value != 0")
            .where("raw_data != 0")
            .where("calibration_uuid != \"\"")
            .orderBy("timestamp desc")
            .limit(number)
            .execute();
}
 
源代码28 项目: xDrip-plus   文件: UploaderQueue.java
private static List<String> getClasses() {
    fixUpTable();
    final ArrayList<String> results = new ArrayList<>();
    final String query = new Select("distinct otype as otypes").from(UploaderQueue.class).toSql();
    final Cursor resultCursor = Cache.openDatabase().rawQuery(query, null);
    while (resultCursor.moveToNext()) {
        results.add(resultCursor.getString(0));
    }
    resultCursor.close();
    return results;
}
 
源代码29 项目: xDrip   文件: BloodTest.java
public static List<BloodTest> last(int num) {
    try {
        return new Select()
                .from(BloodTest.class)
                .orderBy("timestamp desc")
                .limit(num)
                .execute();
    } catch (android.database.sqlite.SQLiteException e) {
        fixUpTable();
        return null;
    }
}
 
源代码30 项目: xDrip   文件: UserError.java
public static List<UserError> bySeverity(Integer[] levels) {
    String levelsString = " ";
    for (int level : levels) {
        levelsString += level + ",";
    }
    Log.d("UserError", "severity in ("+levelsString.substring(0,levelsString.length() - 1)+")");
    return new Select()
            .from(UserError.class)
            .where("severity in ("+levelsString.substring(0,levelsString.length() - 1)+")")
            .orderBy("timestamp desc")
            .execute();
}