com.activeandroid.Cache Java Examples
The following examples show how to use
com.activeandroid.Cache.
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: Sensor.java From xDrip with GNU General Public License v3.0 | 6 votes |
public static boolean TableExists(String table) {//KS try { SQLiteDatabase db = Cache.openDatabase(); if (db != null) { db.rawQuery("SELECT * FROM " + table, null); Log.d("wearSENSOR", "TableExists table does NOT exist:" + table); return true; } else { Log.d("wearSENSOR", "TableExists Cache.openDatabase() failed."); return false; } } catch (Exception e) { Log.d("wearSENSOR", "TableExists CATCH error table:" + table); return false; } }
Example #2
Source File: Sensor.java From xDrip-plus with GNU General Public License v3.0 | 6 votes |
public static boolean TableExists(String table) {//KS try { SQLiteDatabase db = Cache.openDatabase(); if (db != null) { db.rawQuery("SELECT * FROM " + table, null); Log.d("wearSENSOR", "TableExists table does NOT exist:" + table); return true; } else { Log.d("wearSENSOR", "TableExists Cache.openDatabase() failed."); return false; } } catch (Exception e) { Log.d("wearSENSOR", "TableExists CATCH error table:" + table); return false; } }
Example #3
Source File: Sensor.java From xDrip-plus with GNU General Public License v3.0 | 6 votes |
public static void InitDb(Context context) {//KS Configuration dbConfiguration = new Configuration.Builder(context).create(); try { SQLiteDatabase db = Cache.openDatabase(); if (db != null) { Log.d("wearSENSOR", "InitDb DB exists"); } else { ActiveAndroid.initialize(dbConfiguration); Log.d("wearSENSOR", "InitDb DB does NOT exist. Call ActiveAndroid.initialize()"); } } catch (Exception e) { ActiveAndroid.initialize(dbConfiguration); Log.d("wearSENSOR", "InitDb CATCH: DB does NOT exist. Call ActiveAndroid.initialize()"); } }
Example #4
Source File: ContentProvider.java From clear-todolist with GNU General Public License v3.0 | 6 votes |
@Override public boolean onCreate() { ActiveAndroid.initialize(getConfiguration()); sAuthority = getAuthority(); final List<TableInfo> tableInfos = new ArrayList<TableInfo>(Cache.getTableInfos()); final int size = tableInfos.size(); for (int i = 0; i < size; i++) { final TableInfo tableInfo = tableInfos.get(i); final int tableKey = (i * 2) + 1; final int itemKey = (i * 2) + 2; // content://<authority>/<table> URI_MATCHER.addURI(sAuthority, tableInfo.getTableName().toLowerCase(), tableKey); TYPE_CODES.put(tableKey, tableInfo.getType()); // content://<authority>/<table>/<id> URI_MATCHER.addURI(sAuthority, tableInfo.getTableName().toLowerCase() + "/#", itemKey); TYPE_CODES.put(itemKey, tableInfo.getType()); } return true; }
Example #5
Source File: DBSearchUtil.java From xDrip with GNU General Public License v3.0 | 6 votes |
public static List<BgReadingStats> getReadings(boolean ordered) { try { Bounds bounds = new Bounds().invoke(); String orderBy = ordered ? "calculated_value desc" : null; SQLiteDatabase db = Cache.openDatabase(); Cursor cur = db.query("bgreadings", new String[]{"timestamp", "calculated_value"}, "timestamp >= ? AND timestamp <= ? AND calculated_value > ? AND snyced == 0", new String[]{"" + bounds.start, "" + bounds.stop, CUTOFF}, null, null, orderBy); List<BgReadingStats> readings = new Vector<BgReadingStats>(); BgReadingStats reading; if (cur.moveToFirst()) { do { reading = new BgReadingStats(); reading.timestamp = (Long.parseLong(cur.getString(0))); reading.calculated_value = (Double.parseDouble(cur.getString(1))); readings.add(reading); } while (cur.moveToNext()); } return readings; } catch (Exception e) { JoH.static_toast_long(e.getMessage()); return null; } }
Example #6
Source File: ContentProvider.java From clear-todolist with GNU General Public License v3.0 | 6 votes |
@Override public Cursor query(Uri uri, String[] projection, String selection, String[] selectionArgs, String sortOrder) { final Class<? extends Model> type = getModelType(uri); final Cursor cursor = Cache.openDatabase().query( Cache.getTableName(type), projection, selection, selectionArgs, null, null, sortOrder); cursor.setNotificationUri(getContext().getContentResolver(), uri); return cursor; }
Example #7
Source File: DBSearchUtil.java From NightWatch with GNU General Public License v3.0 | 6 votes |
public static List<BgReadingStats> getReadings() { Bounds bounds = new Bounds().invoke(); SQLiteDatabase db = Cache.openDatabase(); //Cursor cur = db.query("bgreadings", new String[]{"datetime", "sgv"}, "datetime >= ? AND datetime <= ? AND calculated_value > ?", new String[]{"" + bounds.start, "" + bounds.stop, CUTOFF}, null, null, orderBy); Cursor cur = db.query("Bg", new String[]{"datetime", "sgv"}, "datetime >= ? AND datetime <= ?", new String[]{"" + bounds.start, "" + bounds.stop}, null, null, null); List<BgReadingStats> readings = new Vector<BgReadingStats>(); BgReadingStats reading; if (cur.moveToFirst()) { do { reading = new BgReadingStats(); //reading.timestamp = (long)(Double.parseDouble(cur.getString(0))); reading.timestamp = (long)cur.getDouble(0); reading.calculated_value = doubleFromSgv(cur.getString(1)); if(reading.calculated_value >= CUTOFF) { readings.add(reading); Log.d("Double timestamp", "" + reading.timestamp + " | " + cur.getString(0)); } } while (cur.moveToNext()); } return readings; }
Example #8
Source File: DBSearchUtil.java From xDrip-plus with GNU General Public License v3.0 | 6 votes |
public static List<BgReadingStats> getReadings(boolean ordered) { try { Bounds bounds = new Bounds().invoke(); String orderBy = ordered ? "calculated_value desc" : null; SQLiteDatabase db = Cache.openDatabase(); Cursor cur = db.query("bgreadings", new String[]{"timestamp", "calculated_value"}, "timestamp >= ? AND timestamp <= ? AND calculated_value > ? AND snyced == 0", new String[]{"" + bounds.start, "" + bounds.stop, CUTOFF}, null, null, orderBy); List<BgReadingStats> readings = new Vector<BgReadingStats>(); BgReadingStats reading; if (cur.moveToFirst()) { do { reading = new BgReadingStats(); reading.timestamp = (Long.parseLong(cur.getString(0))); reading.calculated_value = (Double.parseDouble(cur.getString(1))); readings.add(reading); } while (cur.moveToNext()); } return readings; } catch (Exception e) { JoH.static_toast_long(e.getMessage()); return null; } }
Example #9
Source File: UploaderQueue.java From xDrip with GNU General Public License v3.0 | 6 votes |
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; } }
Example #10
Source File: UploaderQueue.java From xDrip with GNU General Public License v3.0 | 6 votes |
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; } }
Example #11
Source File: ContentProvider.java From mobile-android-survey-app with MIT License | 6 votes |
@Override public Cursor query(Uri uri, String[] projection, String selection, String[] selectionArgs, String sortOrder) { final Class<? extends Model> type = getModelType(uri); final Cursor cursor = Cache.openDatabase().query( Cache.getTableName(type), projection, selection, selectionArgs, null, null, sortOrder); cursor.setNotificationUri(getContext().getContentResolver(), uri); return cursor; }
Example #12
Source File: DBSearchUtil.java From xDrip-Experimental with GNU General Public License v3.0 | 6 votes |
public static List<BgReadingStats> getReadings(boolean ordered) { Bounds bounds = new Bounds().invoke(); String orderBy = ordered ? "calculated_value desc" : null; SQLiteDatabase db = Cache.openDatabase(); Cursor cur = db.query("bgreadings", new String[]{"timestamp", "calculated_value"}, "timestamp >= ? AND timestamp <= ? AND calculated_value > ? AND snyced == 0", new String[]{"" + bounds.start, "" + bounds.stop, CUTOFF}, null, null, orderBy); List<BgReadingStats> readings = new Vector<BgReadingStats>(); BgReadingStats reading; if (cur.moveToFirst()) { do { reading = new BgReadingStats(); reading.timestamp = (Long.parseLong(cur.getString(0))); reading.calculated_value = (Double.parseDouble(cur.getString(1))); readings.add(reading); } while (cur.moveToNext()); } return readings; }
Example #13
Source File: DBSearchUtil.java From NightWatch with GNU General Public License v3.0 | 6 votes |
public static List<BgReadingStats> getReadings() { Bounds bounds = new Bounds().invoke(); SQLiteDatabase db = Cache.openDatabase(); //Cursor cur = db.query("bgreadings", new String[]{"datetime", "sgv"}, "datetime >= ? AND datetime <= ? AND calculated_value > ?", new String[]{"" + bounds.start, "" + bounds.stop, CUTOFF}, null, null, orderBy); Cursor cur = db.query("Bg", new String[]{"datetime", "sgv"}, "datetime >= ? AND datetime <= ?", new String[]{"" + bounds.start, "" + bounds.stop}, null, null, null); List<BgReadingStats> readings = new Vector<BgReadingStats>(); BgReadingStats reading; if (cur.moveToFirst()) { do { reading = new BgReadingStats(); //reading.timestamp = (long)(Double.parseDouble(cur.getString(0))); reading.timestamp = (long)cur.getDouble(0); reading.calculated_value = doubleFromSgv(cur.getString(1)); if(reading.calculated_value >= CUTOFF) { readings.add(reading); Log.d("Double timestamp", "" + reading.timestamp + " | " + cur.getString(0)); } } while (cur.moveToNext()); } return readings; }
Example #14
Source File: UploaderQueue.java From xDrip-plus with GNU General Public License v3.0 | 6 votes |
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; } }
Example #15
Source File: Sensor.java From xDrip with GNU General Public License v3.0 | 6 votes |
public static void InitDb(Context context) {//KS Configuration dbConfiguration = new Configuration.Builder(context).create(); try { SQLiteDatabase db = Cache.openDatabase(); if (db != null) { Log.d("wearSENSOR", "InitDb DB exists"); } else { ActiveAndroid.initialize(dbConfiguration); Log.d("wearSENSOR", "InitDb DB does NOT exist. Call ActiveAndroid.initialize()"); } } catch (Exception e) { ActiveAndroid.initialize(dbConfiguration); Log.d("wearSENSOR", "InitDb CATCH: DB does NOT exist. Call ActiveAndroid.initialize()"); } }
Example #16
Source File: ContentProvider.java From mobile-android-survey-app with MIT License | 6 votes |
@Override public boolean onCreate() { ActiveAndroid.initialize(getConfiguration()); sAuthority = getAuthority(); final List<TableInfo> tableInfos = new ArrayList<TableInfo>(Cache.getTableInfos()); final int size = tableInfos.size(); for (int i = 0; i < size; i++) { final TableInfo tableInfo = tableInfos.get(i); final int tableKey = (i * 2) + 1; final int itemKey = (i * 2) + 2; // content://<authority>/<table> URI_MATCHER.addURI(sAuthority, tableInfo.getTableName().toLowerCase(), tableKey); TYPE_CODES.put(tableKey, tableInfo.getType()); // content://<authority>/<table>/<id> URI_MATCHER.addURI(sAuthority, tableInfo.getTableName().toLowerCase() + "/#", itemKey); TYPE_CODES.put(itemKey, tableInfo.getType()); } return true; }
Example #17
Source File: PerfTestActiveAndroid.java From android-database-performance with Apache License 2.0 | 5 votes |
@Override public void tearDown() throws Exception { if (Cache.isInitialized()) { ActiveAndroid.dispose(); } getTargetContext().deleteDatabase(DATABASE_NAME); super.tearDown(); }
Example #18
Source File: StatsResult.java From xDrip-plus with GNU General Public License v3.0 | 5 votes |
public int getTotal_steps() { if (total_steps < 0) { Cursor cursor = Cache.openDatabase().rawQuery("select sum(t.metric)\n" + "from PebbleMovement t\n" + "inner join (\n" + " select metric, max(timestamp) as MaxDate\n" + " from PebbleMovement\n" + " group by date(timestamp/1000,'unixepoch','localtime') \n" + ") tm on t.metric = tm.metric and t.timestamp = tm.MaxDate where timestamp >= " + from + " AND timestamp <= " + to, null); cursor.moveToFirst(); total_steps = cursor.getInt(0); cursor.close(); } return total_steps; }
Example #19
Source File: StatsResult.java From xDrip-Experimental with GNU General Public License v3.0 | 5 votes |
public StatsResult(SharedPreferences settings){ 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; } long today = DBSearchUtil.getTodayTimestamp(); SQLiteDatabase db = Cache.openDatabase(); Cursor cursor= db.rawQuery("select count(*) from bgreadings where timestamp >= " + today + " AND calculated_value >= " + low + " AND calculated_value <= " + high + " AND snyced == 0", null); cursor.moveToFirst(); in = cursor.getInt(0); cursor.close(); cursor= db.rawQuery("select count(*) from bgreadings where timestamp >= " + today + " AND calculated_value > " + DBSearchUtil.CUTOFF + " AND calculated_value < " + low + " AND snyced == 0", null); cursor.moveToFirst(); below = cursor.getInt(0); cursor.close(); cursor= db.rawQuery("select count(*) from bgreadings where timestamp >= " + today + " AND calculated_value > " + high + " AND snyced == 0", null); cursor.moveToFirst(); above = cursor.getInt(0); cursor.close(); if(getTotalReadings() > 0){ cursor= db.rawQuery("select avg(calculated_value) from bgreadings where timestamp >= " + today + " AND calculated_value > " + DBSearchUtil.CUTOFF + " AND snyced == 0", null); cursor.moveToFirst(); avg = cursor.getDouble(0); cursor.close(); } else { avg = 0; } }
Example #20
Source File: StatsResult.java From xDrip-plus with GNU General Public License v3.0 | 5 votes |
public double getTotal_carbs() { if (total_carbs < 0) { Cursor cursor = Cache.openDatabase().rawQuery("select sum(carbs) from treatments where timestamp >= " + from + " AND timestamp <= " + to, null); cursor.moveToFirst(); total_carbs = cursor.getDouble(0); cursor.close(); } return total_carbs; }
Example #21
Source File: From.java From clear-todolist with GNU General Public License v3.0 | 5 votes |
public <T extends Model> List<T> execute() { if (mQueryBase instanceof Select) { return SQLiteUtils.rawQuery(mType, toSql(), getArguments()); } else { SQLiteUtils.execSql(toSql(), getArguments()); Cache.getContext().getContentResolver().notifyChange(ContentProvider.createUri(mType, null), null); return null; } }
Example #22
Source File: ContentProvider.java From mobile-android-survey-app with MIT License | 5 votes |
@Override public String getType(Uri uri) { final int match = URI_MATCHER.match(uri); String cachedMimeType = sMimeTypeCache.get(match); if (cachedMimeType != null) { return cachedMimeType; } final Class<? extends Model> type = getModelType(uri); final boolean single = ((match % 2) == 0); StringBuilder mimeType = new StringBuilder(); mimeType.append("vnd"); mimeType.append("."); mimeType.append(sAuthority); mimeType.append("."); mimeType.append(single ? "item" : "dir"); mimeType.append("/"); mimeType.append("vnd"); mimeType.append("."); mimeType.append(sAuthority); mimeType.append("."); mimeType.append(Cache.getTableName(type)); sMimeTypeCache.append(match, mimeType.toString()); return mimeType.toString(); }
Example #23
Source File: From.java From clear-todolist with GNU General Public License v3.0 | 5 votes |
private void addFrom(final StringBuilder sql) { sql.append("FROM "); sql.append(Cache.getTableName(mType)).append(" "); if (mAlias != null) { sql.append("AS "); sql.append(mAlias); sql.append(" "); } }
Example #24
Source File: Update.java From clear-todolist with GNU General Public License v3.0 | 5 votes |
@Override public String toSql() { StringBuilder sql = new StringBuilder(); sql.append("UPDATE "); sql.append(Cache.getTableName(mType)); sql.append(" "); return sql.toString(); }
Example #25
Source File: StatsResult.java From xDrip-plus with GNU General Public License v3.0 | 5 votes |
public void calc_StdDev() { if (stdev < 0) { if(getTotalReadings() > 0){ Cursor cursor= Cache.openDatabase().rawQuery("select ((count(*)*(sum(calculated_value * calculated_value)) - (sum(calculated_value)*sum(calculated_value)) )/((count(*)-1)*(count(*))) ) from bgreadings where timestamp >= " + from + " AND timestamp <= " + to + " AND calculated_value > " + DBSearchUtil.CUTOFF + " AND snyced == 0", null); cursor.moveToFirst(); stdev = cursor.getDouble(0); stdev = Math.sqrt(stdev); cursor.close(); } else { stdev = 0; } } }
Example #26
Source File: Join.java From clear-todolist with GNU General Public License v3.0 | 5 votes |
@Override public String toSql() { StringBuilder sql = new StringBuilder(); if (mJoinType != null) { sql.append(mJoinType.toString()).append(" "); } sql.append("JOIN "); sql.append(Cache.getTableName(mType)); sql.append(" "); if (mAlias != null) { sql.append("AS "); sql.append(mAlias); sql.append(" "); } if (mOn != null) { sql.append("ON "); sql.append(mOn); sql.append(" "); } else if (mUsing != null) { sql.append("USING ("); sql.append(TextUtils.join(", ", mUsing)); sql.append(") "); } return sql.toString(); }
Example #27
Source File: ContentProvider.java From mobile-android-survey-app with MIT License | 5 votes |
public static Uri createUri(Class<? extends Model> type, Long id) { final StringBuilder uri = new StringBuilder(); uri.append("content://"); uri.append(sAuthority); uri.append("/"); uri.append(Cache.getTableName(type).toLowerCase()); if (id != null) { uri.append("/"); uri.append(id.toString()); } return Uri.parse(uri.toString()); }
Example #28
Source File: DBSearchUtil.java From xDrip-plus with GNU General Public License v3.0 | 5 votes |
public static List<BgReadingStats> getFilteredReadingsWithFallback(boolean ordered) { try { Bounds bounds = new Bounds().invoke(); String orderBy = ordered ? "calculated_value desc" : null; SQLiteDatabase db = Cache.openDatabase(); Cursor cur = db.query("bgreadings", new String[]{"timestamp", "calculated_value", "filtered_calculated_value"}, "timestamp >= ? AND timestamp <= ? AND calculated_value > ? AND snyced == 0", new String[]{"" + bounds.start, "" + bounds.stop, CUTOFF}, null, null, orderBy); List<BgReadingStats> readings = new Vector<BgReadingStats>(); BgReadingStats reading; if (cur.moveToFirst()) { do { reading = new BgReadingStats(); reading.timestamp = (Long.parseLong(cur.getString(0))); reading.calculated_value = (Double.parseDouble(cur.getString(2))); if(reading.calculated_value == 0) reading.calculated_value = (Double.parseDouble(cur.getString(1))); readings.add(reading); } while (cur.moveToNext()); } return readings; } catch (Exception e) { JoH.static_toast_long(e.getMessage()); return null; } }
Example #29
Source File: StatsResult.java From xDrip-plus with GNU General Public License v3.0 | 5 votes |
public void calc_GVI() { if (GVI < 0 || PGS < 0) { if(getTotalReadings() > 0){ int totalReadings = getTotalReadings(); double NormalReadingspct = getIn()*100/getTotalReadings(); Cursor cursor= Cache.openDatabase().rawQuery("select calculated_value from bgreadings where timestamp >= " + from + " AND timestamp <= " + to + " AND calculated_value > " + DBSearchUtil.CUTOFF + " AND snyced == 0", null); cursor.moveToFirst(); double glucoseFirst = cursor.getDouble(0); double glucoseLast = glucoseFirst; double GVITotal = 0; double glucoseTotal = glucoseLast; int usedRecords = 1; while(cursor.moveToNext()) { double delta = cursor.getDouble(0) - glucoseLast; GVITotal += Math.sqrt(25 + Math.pow(delta, 2)); usedRecords += 1; glucoseLast = cursor.getDouble(0); glucoseTotal += glucoseLast; } double GVIDelta = Math.abs(glucoseLast - glucoseFirst);//Math.floor(glucose_data[0].bgValue,glucose_data[glucose_data.length-1].bgValue); double GVIIdeal = Math.sqrt(Math.pow(usedRecords*5,2) + Math.pow(GVIDelta,2)); GVI = (GVITotal / GVIIdeal * 100) / 100; UserError.Log.d(TAG, "from=" + from + " " + JoH.dateTimeText(from) + " to=" + to + " " + JoH.dateTimeText(to) + " Below=" + getBelow() + " " + getLowPercentage() + " in=" + getIn() + " " + getInPercentage() + " Above=" + getAbove() + " " + getHighPercentage() + " TotalReadings=" + getTotalReadings()); UserError.Log.d(TAG, "GVI=" + GVI + " GVIIdeal=" + GVIIdeal + " GVITotal=" + GVITotal + " GVIDelta=" + GVIDelta + " usedRecords=" + usedRecords); double glucoseMean = Math.floor(glucoseTotal / usedRecords); double tirMultiplier = NormalReadingspct / 100.0; PGS = (GVI * glucoseMean * (1-tirMultiplier) * 100) / 100; UserError.Log.d(TAG, "NormalReadingspct=" + NormalReadingspct + " glucoseMean=" + glucoseMean + " tirMultiplier=" + tirMultiplier + " PGS=" + PGS); cursor.close(); } else { GVI = 0; PGS = 0; } } }
Example #30
Source File: StatsResult.java From xDrip-plus with GNU General Public License v3.0 | 5 votes |
public double getTotal_insulin() { if (total_insulin < 0) { Cursor cursor = Cache.openDatabase().rawQuery("select sum(insulin) from treatments where timestamp >= " + from + " AND timestamp <= " + to, null); cursor.moveToFirst(); total_insulin = cursor.getDouble(0); cursor.close(); } return total_insulin; }