List of usage examples for android.database Cursor isAfterLast
boolean isAfterLast();
From source file:com.appjma.appdeployer.adapter.DownloadLoader.java
@Override public Map<String, DownloadLoader.DownloadItem> loadInBackground() { Map<String, DownloadLoader.DownloadItem> map = Maps.newHashMap(); Cursor cursor = mDownloadManager.query(new DownloadManager.Query()); int columnId = cursor.getColumnIndex(DownloadManager.COLUMN_ID); int columnStatus = cursor.getColumnIndex(DownloadManager.COLUMN_STATUS); try {/* ww w . j a v a 2 s. c o m*/ for (cursor.moveToFirst(); !cursor.isAfterLast(); cursor.moveToNext()) { String id = cursor.getString(columnId); int status = cursor.getInt(columnStatus); map.put(id, new DownloadItem(id, status)); } } finally { cursor.close(); } return map; }
From source file:com.google.android.apps.dashclock.gmail.GmailExtension.java
@Override protected void onUpdateData(int reason) { SharedPreferences sp = PreferenceManager.getDefaultSharedPreferences(this); String labelCanonical = sp.getString(PREF_LABEL, "i"); Set<String> selectedAccounts = getSelectedAccounts(); if ("i".equals(labelCanonical)) { labelCanonical = GmailContract.Labels.LabelCanonicalNames.CANONICAL_NAME_INBOX; } else if ("p".equals(labelCanonical)) { labelCanonical = GmailContract.Labels.LabelCanonicalNames.CANONICAL_NAME_PRIORITY_INBOX; }//from w w w . j a v a2 s .c o m int unread = 0; List<Pair<String, Integer>> unreadPerAccount = new ArrayList<Pair<String, Integer>>(); String lastUnreadLabelUri = null; for (String account : selectedAccounts) { Cursor cursor = tryOpenLabelsCursor(account); if (cursor == null || cursor.isAfterLast()) { LOGD(TAG, "No Gmail inbox information found for account."); if (cursor != null) { cursor.close(); } continue; } int accountUnread = 0; while (cursor.moveToNext()) { int thisUnread = cursor.getInt(LabelsQuery.NUM_UNREAD_CONVERSATIONS); String thisCanonicalName = cursor.getString(LabelsQuery.CANONICAL_NAME); if (labelCanonical.equals(thisCanonicalName)) { accountUnread = thisUnread; if (thisUnread > 0) { lastUnreadLabelUri = cursor.getString(LabelsQuery.URI); } break; } else if (!TextUtils.isEmpty(thisCanonicalName) && thisCanonicalName.startsWith(SECTIONED_INBOX_CANONICAL_NAME_PREFIX)) { accountUnread += thisUnread; if (thisUnread > 0 && SECTIONED_INBOX_CANONICAL_NAME_PERSONAL.equals(thisCanonicalName)) { lastUnreadLabelUri = cursor.getString(LabelsQuery.URI); } } } if (accountUnread > 0) { unreadPerAccount.add(new Pair<String, Integer>(account, accountUnread)); unread += accountUnread; } cursor.close(); } StringBuilder body = new StringBuilder(); for (Pair<String, Integer> pair : unreadPerAccount) { if (pair.second == 0) { continue; } if (body.length() > 0) { body.append("\n"); } body.append(pair.first).append(" (").append(pair.second).append(")"); } Intent clickIntent = null; if (lastUnreadLabelUri != null) { try { clickIntent = new Intent(Intent.ACTION_VIEW, Uri.parse(lastUnreadLabelUri)); if (getPackageManager().resolveActivity(clickIntent, 0) == null) { throw new IllegalStateException("Gmail can't open this label directly."); } } catch (Exception e) { LOGW(TAG, "Can't open Gmail label directly.", e); clickIntent = null; } } if (clickIntent == null) { clickIntent = new Intent(Intent.ACTION_MAIN).setPackage("com.google.android.gm") .addCategory(Intent.CATEGORY_LAUNCHER); } publishUpdate(new ExtensionData().visible(unread > 0).status(Integer.toString(unread)) .expandedTitle(getResources().getQuantityString(R.plurals.gmail_title_template, unread, unread)) .icon(R.drawable.ic_extension_gmail).expandedBody(body.toString()).clickIntent(clickIntent)); }
From source file:com.clutch.ClutchStats.java
public int getCachedChoice(String name) { int resp = -1; SQLiteDatabase db = getReadableDatabase(); String[] args = { name };/*from ww w.j a v a 2 s . c om*/ Cursor cur = db.rawQuery("SELECT choice FROM abcache WHERE name = ?", args); cur.moveToFirst(); while (!cur.isAfterLast()) { resp = cur.getInt(0); cur.moveToNext(); } db.close(); return resp; }
From source file:com.example.xyzreader.ui.articledetail.ArticleDetailActivity.java
@Override public void onLoadFinished(Loader<Cursor> loader, Cursor data) { Log.d(LOG_TAG, "onLoadFinished, data = " + data.toString()); mCursor = data;/* www. j av a 2 s.c om*/ mSectionsPagerAdapter.notifyDataSetChanged(); for (data.moveToFirst(); !data.isAfterLast(); data.moveToNext()) { if (data.getLong(ArticleLoader.Query._ID) == mStartId) { final int position = data.getPosition(); mViewPager.setCurrentItem(position, false); break; } } }
From source file:com.QuarkLabs.BTCeClient.UpdateWidgetsTask.java
@Override protected JSONObject doInBackground(Void... params) { Set<String> set = new HashSet<>(); JSONObject response = null;/*from w ww . ja v a 2 s . com*/ for (int x : mMap.keySet()) { set.add(mMap.get(x)); } try { response = App.getPairInfo(set.toArray(new String[set.size()])); response = response == null ? new JSONObject() : response; Context context = mContext.get(); if (context == null) { return null; } DBWorker dbWorker = DBWorker.getInstance(context); String[] columns = { "pair", "last" }; Cursor cursor = dbWorker.pullWidgetData(columns); Map<String, Double> values = new HashMap<>(); if (cursor.moveToFirst()) { while (!cursor.isAfterLast()) { values.put(cursor.getString(cursor.getColumnIndex(columns[0])), cursor.getDouble(cursor.getColumnIndex(columns[1]))); cursor.moveToNext(); } } cursor.close(); for (@SuppressWarnings("unchecked") Iterator<String> x = response.keys(); x.hasNext();) { String pair = x.next(); String pairInDB = pair.replace("_", "/").toUpperCase(Locale.US); ContentValues cv = new ContentValues(4); double last = response.getJSONObject(pair).getDouble("last"); double sell = response.getJSONObject(pair).getDouble("sell"); double buy = response.getJSONObject(pair).getDouble("buy"); cv.put("last", last); cv.put("buy", buy); cv.put("sell", sell); if (values.containsKey(pairInDB)) { if (last >= values.get(pairInDB)) { response.getJSONObject(pair).put("color", "green"); } else { response.getJSONObject(pair).put("color", "red"); } } else { response.getJSONObject(pair).put("color", "green"); } int result = dbWorker.updateWidgetData(cv, pair.replace("_", "/").toUpperCase(Locale.US)); if (result == 0) { cv.put("pair", pair.replace("_", "/").toUpperCase(Locale.US)); dbWorker.insertToWidgetData(cv); } } } catch (JSONException e) { e.printStackTrace(); } return response; }
From source file:com.jbirdvegas.mgerrit.DiffViewer.java
@Override public void onLoadFinished(Loader<Cursor> cursorLoader, Cursor cursor) { mAdapter.swapCursor(cursor);/* w w w . j a v a 2 s . c o m*/ if (cursor != null && cursor.isAfterLast()) { if (request != null) request.cancel(); mDiffTextView.setText(getString(R.string.diff_no_files)); } int pos = mAdapter.getPositionOfFile(mFilePath); if (pos >= 0) mSpinner.setSelection(pos); }
From source file:it.ms.theing.loquitur.functions.Storage.java
/** * Get a key value// ww w.j a v a 2 s. c o m * @param genre * The genre of the key * @param key * The key * @return * The key value */ @JavascriptInterface public String getKey(String genre, String key) { Cursor cursor = dataBase.rawQuery("select * from alias where genre=? and key=?", new String[] { genre.toUpperCase(), key }); cursor.moveToFirst(); if (cursor.isAfterLast()) { return ""; } String s = cursor.getString(2); cursor.close(); return s; }
From source file:com.samknows.measurement.storage.TestResultDataSource.java
public List<AggregateTestResult> getAverageResults(long starttime, long endtime) { List<AggregateTestResult> ret = new ArrayList<AggregateTestResult>(); String selection = String.format("dtime BETWEEN %d AND %d AND success <> 0", starttime, endtime); String averageColumn = String.format("AVG(%s)", SKSQLiteHelper.TR_COLUMN_RESULT); String[] columns = { SKSQLiteHelper.TR_COLUMN_TYPE, averageColumn, "COUNT(*)" }; String groupBy = SKSQLiteHelper.TR_COLUMN_TYPE; Cursor cursor = database.query(SKSQLiteHelper.TABLE_TESTRESULT, columns, selection, null, groupBy, null, null);//w w w . j a va2 s .c o m cursor.moveToFirst(); while (!cursor.isAfterLast()) { AggregateTestResult curr = new AggregateTestResult(); curr.testType = cursor.getString(0); curr.aggregateFunction = "average"; curr.value = cursor.getDouble(1); curr.numberOfResults = cursor.getInt(2); ret.add(curr); } cursor.close(); return ret; }
From source file:com.clutch.ClutchStats.java
public ArrayList<ABRow> getABLogs() { SQLiteDatabase db = getReadableDatabase(); String[] args = {};/*from w ww. j av a2 s . co m*/ ArrayList<ABRow> res = new ArrayList<ABRow>(); Cursor cur = db.rawQuery("SELECT uuid, ts, data FROM ablog ORDER BY ts", args); cur.moveToFirst(); while (!cur.isAfterLast()) { String uuid = cur.getString(0); double ts = cur.getDouble(1); JSONObject data; try { data = new JSONObject(cur.getString(2)); } catch (JSONException e) { Log.w(TAG, "Could not serialize to JSON: " + cur.getString(3)); cur.moveToNext(); continue; } res.add(new ABRow(uuid, ts, data)); cur.moveToNext(); } db.close(); return res; }
From source file:com.clutch.ClutchStats.java
public ArrayList<StatRow> getLogs() { SQLiteDatabase db = getReadableDatabase(); String[] args = {};//w w w .j ava 2 s .com ArrayList<StatRow> res = new ArrayList<StatRow>(); Cursor cur = db.rawQuery("SELECT uuid, ts, action, data FROM stats ORDER BY ts", args); cur.moveToFirst(); while (!cur.isAfterLast()) { String uuid = cur.getString(0); double ts = cur.getDouble(1); String action = cur.getString(2); JSONObject data; try { data = new JSONObject(cur.getString(3)); } catch (JSONException e) { Log.w(TAG, "Could not serialize to JSON: " + cur.getString(3)); cur.moveToNext(); continue; } res.add(new StatRow(uuid, ts, action, data)); cur.moveToNext(); } db.close(); return res; }