List of usage examples for android.database Cursor moveToNext
boolean moveToNext();
From source file:gov.wa.wsdot.android.wsdot.service.BorderWaitSyncService.java
/** * Check the travel border wait table for any starred entries. If we find some, save them * to a list so we can re-star those after we flush the database. *///from ww w . j a v a2 s . c o m private List<Integer> getStarred() { ContentResolver resolver = getContentResolver(); Cursor cursor = null; List<Integer> starred = new ArrayList<Integer>(); try { cursor = resolver.query(BorderWait.CONTENT_URI, new String[] { BorderWait.BORDER_WAIT_ID }, BorderWait.BORDER_WAIT_IS_STARRED + "=?", new String[] { "1" }, null); if (cursor != null && cursor.moveToFirst()) { while (!cursor.isAfterLast()) { starred.add(cursor.getInt(0)); cursor.moveToNext(); } } } finally { if (cursor != null) { cursor.close(); } } return starred; }
From source file:com.ibm.commerce.worklight.android.search.SearchSuggestionsProvider.java
/** * Performs the search by projections and selection arguments * @param uri The URI to be used// w w w. j a v a 2s . c o m * @param projection The string array for the search * @param selection The selection string * @param selectionArgs The selection arguments * @param sortOrder The sort order * @return The cursor containing the suggestions */ @Override public Cursor query(Uri uri, String[] projection, String selection, String[] selectionArgs, String sortOrder) { final String METHOD_NAME = CLASS_NAME + ".query()"; boolean loggingEnabled = Log.isLoggable(LOG_TAG, Log.DEBUG); if (loggingEnabled) { Log.d(METHOD_NAME, "ENTRY"); } int id = 1; MatrixCursor suggestionCursor = new MatrixCursor(COLUMNS); Cursor recentSearchCursor = null; try { recentSearchCursor = super.query(uri, projection, selection, selectionArgs, sortOrder); // get search history if (recentSearchCursor != null) { int searchTermIndex = recentSearchCursor.getColumnIndex(SearchManager.SUGGEST_COLUMN_TEXT_1); while (recentSearchCursor.moveToNext() && id <= MAX_RECENT_TERM) { suggestionCursor.addRow(createRecentRow(id, recentSearchCursor.getString(searchTermIndex))); id++; } } } finally { if (recentSearchCursor != null) { recentSearchCursor.close(); recentSearchCursor = null; } } // get search suggestion if (selectionArgs[0] != null && !selectionArgs[0].equals("")) { List<String> suggestionList = getSearchTermSuggestions(selectionArgs[0]); if (suggestionList != null) { for (String aSuggestion : suggestionList) { suggestionCursor.addRow(createSuggestionRow(id, aSuggestion)); id++; } } } if (loggingEnabled) { Log.d(METHOD_NAME, "EXIT"); } return suggestionCursor; }
From source file:foam.zizim.android.BoskoiService.java
public static List<BlogData> getBlogData() { Cursor cursor; cursor = BoskoiApplication.mDb.fetchAllBlog(); List blog = new ArrayList<BlogData>(); if (cursor.moveToFirst()) { int idIndex = cursor.getColumnIndexOrThrow(BoskoiDatabase.BLOG_ID); int titleIndex = cursor.getColumnIndexOrThrow(BoskoiDatabase.BLOG_TITLE); int dateIndex = cursor.getColumnIndexOrThrow(BoskoiDatabase.BLOG_DATE); int descIndex = cursor.getColumnIndexOrThrow(BoskoiDatabase.BLOG_DESCRIPTION); int linkIndex = cursor.getColumnIndexOrThrow(BoskoiDatabase.BLOG_LINK); do {// ww w .java2 s . c om BlogData blogData = new BlogData(); blogData.setId(Util.toInt(cursor.getString(idIndex))); blogData.setTitle(cursor.getString(titleIndex)); blogData.setDescription(cursor.getString(descIndex)); blogData.setLink(cursor.getString(linkIndex)); blogData.setDate(cursor.getString(dateIndex)); blog.add(blogData); } while (cursor.moveToNext()); } cursor.close(); return blog; }
From source file:com.morphoss.acal.service.UpdateTimezones.java
private void refreshTimezoneData() { try {/* www . j a v a 2 s . co m*/ HashMap<String, Long> currentZones = new HashMap<String, Long>(); HashMap<String, Long> updatedZones = new HashMap<String, Long>(); HashMap<String, Long> insertedZones = new HashMap<String, Long>(); Cursor allZones = cr.query(Timezones.CONTENT_URI, new String[] { Timezones.TZID, Timezones.LAST_MODIFIED }, null, null, null); Long maxModified = 0L; for (allZones.moveToFirst(); !allZones.isAfterLast(); allZones.moveToNext()) { if (Constants.LOG_VERBOSE) Log.println(Constants.LOGV, TAG, "Found existing zone of '" + allZones.getString(0) + "' modified: " + AcalDateTime.fromMillis(allZones.getLong(1) * 1000L).toString()); currentZones.put(allZones.getString(0), allZones.getLong(1)); if (allZones.getLong(1) > maxModified) maxModified = allZones.getLong(1); } AcalDateTime mostRecentChange = AcalDateTime.getUTCInstance().setEpoch(maxModified); Log.println(Constants.LOGI, TAG, "Found " + allZones.getCount() + " existing timezones, most recent change on " + mostRecentChange.toString()); if (allZones.getCount() > 350 && mostRecentChange.after(AcalDateTime.getUTCInstance().addDays(-30))) { Log.println(Constants.LOGI, TAG, "Skipping update - our database is pretty recent"); return; } requestor.interpretUriString(tzUrl("list", null)); JSONObject root = requestor.doJsonRequest("GET", null, null, null); if (requestor.wasRedirected()) { Uri tzUri = Uri.parse(requestor.fullUrl()); String redirectedUrl = tzUri.getScheme() + "://" + tzUri.getAuthority() + tzUri.getPath(); if (Constants.debugTimeZone && Constants.LOG_DEBUG) Log.println(Constants.LOGD, TAG, "Redirected to Timezone Server at " + redirectedUrl); tzServerBaseUrl = redirectedUrl; AcalApplication.setPreferenceString(PrefNames.tzServerBaseUrl, redirectedUrl); } if (requestor.getStatusCode() >= 399) { Log.println(Constants.LOGI, TAG, "Bad response " + requestor.getStatusCode() + " from Timezone Server at " + tzUrl("list", null)); } if (root == null) { Log.println(Constants.LOGI, TAG, "No JSON from GET " + tzUrl("list", null)); return; } String tzid; String tzData = ""; long lastModified; StringBuilder localNames; StringBuilder aliases; ContentValues zoneValues = new ContentValues(); String tzDateStamp = root.getString("dtstamp"); JSONArray tzArray = root.getJSONArray("timezones"); for (int i = 0; i < tzArray.length(); i++) { JSONObject zoneNode = tzArray.getJSONObject(i); tzid = zoneNode.getString("tzid"); if (updatedZones.containsKey(tzid) || insertedZones.containsKey(tzid)) continue; if (Constants.debugTimeZone && Constants.LOG_DEBUG) Log.println(Constants.LOGD, TAG, "Working on " + tzid); lastModified = AcalDateTime.fromString(zoneNode.getString("last-modified")).getEpoch(); if (currentZones.containsKey(tzid) && currentZones.get(tzid) <= lastModified) { currentZones.remove(tzid); continue; } tzData = getTimeZone(tzid); if (tzData == null) continue; localNames = new StringBuilder(); try { JSONArray nameNodes = zoneNode.getJSONArray("local_names"); for (int j = 0; j < nameNodes.length(); j++) { if (localNames.length() > 0) localNames.append("\n"); localNames.append(nameNodes.getJSONObject(j).getString("lang")).append('~') .append(nameNodes.getJSONObject(j).getString("lname")); } } catch (JSONException je) { } aliases = new StringBuilder(); try { JSONArray aliasNodes = zoneNode.getJSONArray("aliases"); for (int j = 0; j < aliasNodes.length(); j++) { if (aliases.length() > 0) aliases.append("\n"); aliases.append(aliasNodes.getString(j)); } } catch (JSONException je) { } zoneValues.put(Timezones.TZID, tzid); zoneValues.put(Timezones.ZONE_DATA, tzData); zoneValues.put(Timezones.LAST_MODIFIED, lastModified); zoneValues.put(Timezones.TZ_NAMES, localNames.toString()); zoneValues.put(Timezones.TZID_ALIASES, aliases.toString()); Uri tzUri = Uri.withAppendedPath(Timezones.CONTENT_URI, "tzid/" + StaticHelpers.urlescape(tzid, false)); if (currentZones.containsKey(tzid)) { if (cr.update(tzUri, zoneValues, null, null) != 1) { Log.e(TAG, "Failed update for TZID '" + tzid + "'"); } updatedZones.put(tzid, currentZones.get(tzid)); currentZones.remove(tzid); } else { if (cr.insert(tzUri, zoneValues) == null) Log.e(TAG, "Failed insert for TZID '" + tzid + "'"); insertedZones.put(tzid, currentZones.get(tzid)); } if (context.workWaiting()) { Log.println(Constants.LOGI, TAG, "Something is waiting - deferring timezone sync until later."); deferMe = true; break; } // Let other stuff have a chance Thread.sleep(350); } int removed = 0; if (currentZones.size() > 0) { StringBuilder s = new StringBuilder(); for (String tz : currentZones.keySet()) { if (s.length() > 0) s.append(','); s.append("'").append(tz).append("'"); } removed = cr.delete(Timezones.CONTENT_URI, Timezones.TZID + " IN (" + s + ")", null); } Log.println(Constants.LOGI, TAG, "Updated data for " + updatedZones.size() + " zones, added data for " + insertedZones.size() + " new zones, removed data for " + removed); } catch (Exception e) { Log.e(TAG, Log.getStackTraceString(e)); } }
From source file:com.zsxj.pda.ui.client.LoginActivity.java
private boolean downloading() { DownloadManager.Query query = new DownloadManager.Query(); SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(this); long downloadId = prefs.getLong(PrefKeys.DOWNLOAD_ID, 0); query.setFilterById(downloadId);// w ww . j a v a 2 s . co m DownloadManager dm = (DownloadManager) getSystemService(Context.DOWNLOAD_SERVICE); Cursor c = dm.query(query); if (c.moveToNext()) { int statusIdx = c.getColumnIndex(DownloadManager.COLUMN_STATUS); int status = c.getInt(statusIdx); if (DownloadManager.STATUS_RUNNING == status) { return true; } } return false; }
From source file:com.google.zxing.client.android.history.HistoryManager.java
public List<HistoryItem> buildHistoryItems() { SQLiteOpenHelper helper = new DBHelper(activity); List<HistoryItem> items = new ArrayList<HistoryItem>(); SQLiteDatabase db = null;/*from ww w . j a v a 2s .c o m*/ Cursor cursor = null; try { db = helper.getReadableDatabase(); cursor = db.query(DBHelper.TABLE_NAME, COLUMNS, null, null, null, null, DBHelper.TIMESTAMP_COL + " DESC"); while (cursor.moveToNext()) { String text = cursor.getString(0); String display = cursor.getString(1); String format = cursor.getString(2); long timestamp = cursor.getLong(3); // String details = cursor.getString(4); Result result = new Result(text, null, null, BarcodeFormat.valueOf(format), timestamp); // items.add(new HistoryItem(result, display, details)); items.add(new HistoryItem(result, display)); } } finally { close(cursor, db); } return items; }
From source file:com.rjfun.cordova.sms.SMSPlugin.java
private PluginResult listSMS(JSONObject filter, CallbackContext callbackContext) { Log.i(LOGTAG, ACTION_LIST_SMS);/*from ww w . ja v a2s .c o m*/ String uri_filter = filter.has(BOX) ? filter.optString(BOX) : "inbox"; int fread = filter.has(READ) ? filter.optInt(READ) : -1; int fid = filter.has("_id") ? filter.optInt("_id") : -1; String faddress = filter.optString(ADDRESS); String fcontent = filter.optString(BODY); int indexFrom = filter.has("indexFrom") ? filter.optInt("indexFrom") : 0; int maxCount = filter.has("maxCount") ? filter.optInt("maxCount") : 10; JSONArray jsons = new JSONArray(); Activity ctx = this.cordova.getActivity(); Uri uri = Uri.parse((SMS_URI_ALL + uri_filter)); Cursor cur = ctx.getContentResolver().query(uri, (String[]) null, "", (String[]) null, null); int i = 0; while (cur.moveToNext()) { JSONObject json; boolean matchFilter = false; if (fid > -1) { matchFilter = (fid == cur.getInt(cur.getColumnIndex("_id"))); } else if (fread > -1) { matchFilter = (fread == cur.getInt(cur.getColumnIndex(READ))); } else if (faddress.length() > 0) { matchFilter = faddress.equals(cur.getString(cur.getColumnIndex(ADDRESS)).trim()); } else if (fcontent.length() > 0) { matchFilter = fcontent.equals(cur.getString(cur.getColumnIndex(BODY)).trim()); } else { matchFilter = true; } if (!matchFilter) continue; if (i < indexFrom) continue; if (i >= indexFrom + maxCount) break; ++i; if ((json = this.getJsonFromCursor(cur)) == null) { callbackContext.error("failed to get json from cursor"); cur.close(); return null; } jsons.put((Object) json); } cur.close(); callbackContext.success(jsons); return null; }
From source file:edu.htl3r.schoolplanner.backend.database.AutoSelectDatabase.java
@Override public AutoSelectSet getAutoSelect() { AutoSelectSet autoSelectSet = new AutoSelectSet(); SQLiteDatabase database = this.database.openDatabase(false); Cursor query = this.database.queryWithLoginSetKey(database, DatabaseAutoSelectConstants.TABLE_AUTO_SELECT_NAME); Assert.isTrue(query.getCount() <= 1, "More than one auto-select entry for " + this.database.getLoginSetKeyForTable() + "."); int indexEnabled = query.getColumnIndex(DatabaseAutoSelectConstants.ENABLED); int indexType = query.getColumnIndex(DatabaseAutoSelectConstants.TYPE); int indexValue = query.getColumnIndex(DatabaseAutoSelectConstants.VALUE); while (query.moveToNext()) { boolean enabled = query.getInt(indexEnabled) > 0; String type = query.getString(indexType); int value = query.getInt(indexValue); autoSelectSet.setEnabled(enabled); autoSelectSet.setAutoSelectType(type); autoSelectSet.setAutoSelectValue(value); }//w w w. j a va 2 s .c o m query.close(); this.database.closeDatabase(database); return autoSelectSet; }
From source file:gov.wa.wsdot.android.wsdot.service.TravelTimesSyncService.java
/** * Check the travel times table for any starred entries. If we find some, save them * to a list so we can re-star those after we flush the database. *//* w ww . j av a 2s. c om*/ private List<Integer> getStarred() { ContentResolver resolver = getContentResolver(); Cursor cursor = null; List<Integer> starred = new ArrayList<Integer>(); try { cursor = resolver.query(TravelTimes.CONTENT_URI, new String[] { TravelTimes.TRAVEL_TIMES_ID }, TravelTimes.TRAVEL_TIMES_IS_STARRED + "=?", new String[] { "1" }, null); if (cursor != null && cursor.moveToFirst()) { while (!cursor.isAfterLast()) { starred.add(cursor.getInt(0)); cursor.moveToNext(); } } } finally { if (cursor != null) { cursor.close(); } } return starred; }
From source file:curso.android.DAO.PerguntaDAO.java
public static List<Pergunta> getPerguntasUsuario() { Cursor cursor = null; try {/*from www .j a va 2 s. c o m*/ List<Pergunta> questions = new ArrayList<Pergunta>(); cursor = Const.db.rawQuery("SELECT * FROM pergunta WHERE user_id =" + Const.config.idUser, null); if (cursor.getCount() > 0) { int idIndex = cursor.getColumnIndex("ask_id"); int userIndex = cursor.getColumnIndex("user_id"); int perguntaIndex = cursor.getColumnIndex("ask_pergunta"); int nameIndex = cursor.getColumnIndex("user_name"); int statusIndex = cursor.getColumnIndex("status"); cursor.moveToFirst(); do { Long id = Long.valueOf(cursor.getInt(idIndex)); Long user = Long.valueOf(cursor.getString(userIndex)); String pergunta = cursor.getString(perguntaIndex); String user_name = cursor.getString(nameIndex); String status = cursor.getString(statusIndex); Pergunta ask = new Pergunta(); ask.setAsk_id(id); ask.setUser_id(user); ask.setAsk_pergunta(pergunta); ask.setUser_name(user_name); ask.setStatus(Integer.valueOf(status) == 1); questions.add(ask); cursor.moveToNext(); } while (!cursor.isAfterLast()); } return questions; } finally { if (cursor != null) { cursor.close(); } } }