List of usage examples for android.database Cursor moveToNext
boolean moveToNext();
From source file:com.buddi.client.dfu.DfuActivity.java
@Override public void onLoadFinished(final Loader<Cursor> loader, final Cursor data) { if (data != null && data.moveToNext()) { /*// w ww . j a va2 s . c o m * Here we have to check the column indexes by name as we have requested for all. The order may be different. */ final String fileName = data .getString(data.getColumnIndex(MediaStore.MediaColumns.DISPLAY_NAME)/* 0 DISPLAY_NAME */); final int fileSize = data.getInt(data.getColumnIndex(MediaStore.MediaColumns.SIZE) /* 1 SIZE */); String filePath = null; final int dataIndex = data.getColumnIndex(MediaStore.MediaColumns.DATA); if (dataIndex != -1) filePath = data.getString(dataIndex /* 2 DATA */); if (!TextUtils.isEmpty(filePath)) mFilePath = filePath; updateFileInfo(fileName, fileSize, mFileType); } else { mFileNameView.setText(null); mFileTypeView.setText(null); mFileSizeView.setText(null); mFilePath = null; mFileStreamUri = null; mFileStatusView.setText(R.string.dfu_file_status_error); mStatusOk = false; } }
From source file:cn.code.notes.gtask.data.SqlNote.java
private void loadDataContent() { Cursor c = null; mDataList.clear();/* ww w. jav a2 s. c o m*/ try { c = mContentResolver.query(Notes.CONTENT_DATA_URI, SqlData.PROJECTION_DATA, "(note_id=?)", new String[] { String.valueOf(mId) }, null); if (c != null) { if (c.getCount() == 0) { Log.w(TAG, "it seems that the note has not data"); return; } while (c.moveToNext()) { SqlData data = new SqlData(mContext, c); mDataList.add(data); } } else { Log.w(TAG, "loadDataContent: cursor = null"); } } finally { if (c != null) c.close(); } }
From source file:com.borqs.browser.combo.BookmarksPageCallbacks.java
@Override public void onLoadFinished(Loader<Cursor> loader, Cursor cursor) { if (loader.getId() == LOADER_ACCOUNTS) { LoaderManager lm = getLoaderManager(); int id = LOADER_BOOKMARKS; while (cursor.moveToNext()) { String accountName = cursor.getString(0); String accountType = cursor.getString(1); Bundle args = new Bundle(); args.putString(ACCOUNT_NAME, accountName); args.putString(ACCOUNT_TYPE, accountType); BrowserBookmarksAdapter adapter = new BrowserBookmarksAdapter(this); mBookmarkAdapters.put(id, adapter); boolean expand = true; try { expand = mState.getBoolean( accountName != null ? accountName : BookmarkExpandableView.LOCAL_ACCOUNT_NAME); } catch (JSONException e) { } // no state for accountName mGrid.addAccount(accountName, adapter, expand); lm.restartLoader(id, args, this); id++;// ww w.j a v a 2s . co m } // TODO: Figure out what a reload of these means // Currently, a reload is triggered whenever bookmarks change // This is less than ideal // It also causes UI flickering as a new adapter is created // instead of re-using an existing one when the account_name is the // same. // For now, this is a one-shot load getLoaderManager().destroyLoader(LOADER_ACCOUNTS); } else if (loader.getId() >= LOADER_BOOKMARKS) { BrowserBookmarksAdapter adapter = mBookmarkAdapters.get(loader.getId()); adapter.changeCursor(cursor); } }
From source file:com.triarc.sync.SyncAdapter.java
private void appendEntity(SyncType type, SQLiteDatabase openDatabase, JSONObject jsonObject, String id) { Cursor fullEntityCursor = null; try {/*from ww w. ja v a 2 s .c om*/ fullEntityCursor = openDatabase.query(type.getName(), null, "_id=" + id, null, null, null, null); if (fullEntityCursor.moveToNext()) { try { jsonObject.put("entity", readEntity(type, fullEntityCursor)); } catch (Exception e) { syncResult.stats.numIoExceptions++; syncResult.databaseError = true; e.printStackTrace(); sendLogs(); } } else { Log.w(TAG, "should not happen, check appendEntity"); } } finally { if (fullEntityCursor != null) fullEntityCursor.close(); } }
From source file:com.iyedb.sunshine.FetchWeatherTask.java
@Override protected Void doInBackground(String... params) { Log.d(LOG_TAG, "in doInBackground"); // If there's no zip code, there's nothing to look up. Verify size of params. if (params.length == 0) { return null; }/* w ww . j ava 2 s .c om*/ String locationParam = params[0]; Log.d(LOG_TAG, "getting weather data for " + locationParam); // These two need to be declared outside the try/catch // so that they can be closed in the finally block. HttpURLConnection urlConnection = null; BufferedReader reader = null; // Will contain the raw JSON response as a string. String forecastJsonStr = null; String format = "json"; String units = "metric"; int numDays = 14; try { // Construct the URL for the OpenWeatherMap query // Possible parameters are avaiable at OWM's forecast API page, at // http://openweathermap.org/API#forecast final String FORECAST_BASE_URL = "http://api.openweathermap.org/data/2.5/forecast/daily?"; final String QUERY_PARAM = "q"; final String FORMAT_PARAM = "mode"; final String UNITS_PARAM = "units"; final String DAYS_PARAM = "cnt"; Uri builtUri = Uri.parse(FORECAST_BASE_URL).buildUpon().appendQueryParameter(QUERY_PARAM, params[0]) .appendQueryParameter(FORMAT_PARAM, format).appendQueryParameter(UNITS_PARAM, units) .appendQueryParameter(DAYS_PARAM, Integer.toString(numDays)).build(); URL url = new URL(builtUri.toString()); // Create the request to OpenWeatherMap, and open the connection urlConnection = (HttpURLConnection) url.openConnection(); urlConnection.setRequestMethod("GET"); urlConnection.connect(); // Read the input stream into a String InputStream inputStream = urlConnection.getInputStream(); StringBuffer buffer = new StringBuffer(); if (inputStream == null) { // Nothing to do. return null; } reader = new BufferedReader(new InputStreamReader(inputStream)); String line; while ((line = reader.readLine()) != null) { // Since it's JSON, adding a newline isn't necessary (it won't affect parsing) // But it does make debugging a *lot* easier if you print out the completed // buffer for debugging. buffer.append(line + "\n"); } if (buffer.length() == 0) { // Stream was empty. No point in parsing. return null; } forecastJsonStr = buffer.toString(); } catch (IOException e) { Log.e(LOG_TAG, "Error ", e); // If the code didn't successfully get the weather data, there's no point in attemping // to parse it. return null; } finally { if (urlConnection != null) { urlConnection.disconnect(); } if (reader != null) { try { reader.close(); } catch (final IOException e) { Log.e(LOG_TAG, "Error closing stream", e); } } } try { getWeatherDataFromJson(forecastJsonStr, numDays, locationParam); if (DEBUG) { Cursor cursor = mContext .getContentResolver().query( WeatherEntry.CONTENT_URI, new String[] { WeatherEntry._ID, WeatherEntry.COLUMN_LOC_KEY, WeatherEntry.COLUMN_WEATHER_ID }, null, null, null); Log.d(LOG_TAG, "Weather table contents:"); while (cursor.moveToNext()) { ContentValues resultValues = new ContentValues(); DatabaseUtils.cursorRowToContentValues(cursor, resultValues); StringBuilder stringBuilder = new StringBuilder(); for (String key : resultValues.keySet()) { stringBuilder.append(key).append(':').append(resultValues.getAsString(key)).append('|'); } Log.v(LOG_TAG, stringBuilder.toString()); } Cursor cursorLoc = mContext.getContentResolver() .query(LocationEntry.CONTENT_URI, new String[] { LocationEntry._ID, LocationEntry.COLUMN_LOCATION_SETTING, LocationEntry.COLUMN_CITY_NAME }, null, null, null); Log.d(LOG_TAG, "Location table contents:"); while (cursorLoc.moveToNext()) { ContentValues resultValues = new ContentValues(); DatabaseUtils.cursorRowToContentValues(cursorLoc, resultValues); StringBuilder stringBuilder = new StringBuilder(); for (String key : resultValues.keySet()) { stringBuilder.append(key).append(':').append(resultValues.getAsString(key)).append('|'); } Log.v(LOG_TAG, stringBuilder.toString()); } } } catch (JSONException e) { Log.e(LOG_TAG, e.getMessage(), e); e.printStackTrace(); } // This will only happen if there was an error getting or parsing the forecast. return null; }
From source file:com.phonegap.ContactAccessorSdk3_4.java
/** * Create a ContactAddress JSONArray/* w ww . j a va 2 s .c o m*/ * @param cr database access object * @param contactId the ID to search the database for * @return a JSONArray representing a set of ContactAddress */ private JSONArray addressQuery(ContentResolver cr, String contactId) { String addrWhere = ContactMethods.PERSON_ID + " = ? AND " + ContactMethods.KIND + " = ?"; String[] addrWhereParams = new String[] { contactId, ContactMethods.CONTENT_POSTAL_ITEM_TYPE }; Cursor cursor = cr.query(ContactMethods.CONTENT_URI, null, addrWhere, addrWhereParams, null); JSONArray addresses = new JSONArray(); JSONObject address; while (cursor.moveToNext()) { address = new JSONObject(); try { address.put("id", cursor.getString(cursor.getColumnIndex(ContactMethods._ID))); address.put("formatted", cursor.getString(cursor.getColumnIndex(ContactMethodsColumns.DATA))); addresses.put(address); } catch (JSONException e) { Log.e(LOG_TAG, e.getMessage(), e); } } return addresses; }
From source file:com.earthblood.tictactoe.activity.GameActivity.java
@Override public void onLoadFinished(Loader<Cursor> loader, Cursor data) { int[] XIds = new int[9]; int countX = 0; int[] OIds = new int[9]; int countO = 0; data.moveToFirst();//from ww w . ja va 2 s. c om while (data.isAfterLast() == false) { int boxId = data.getInt(1); int gameSymbolId = data.getInt(2); if (GameSymbol.X.getId() == gameSymbolId) { XIds[countX++] = boxId; } else { OIds[countO++] = boxId; } Button button = (Button) gridLayout.findViewById(GameBox.byLayoutId(boxId).layoutBoxId()); button.setText(GameSymbol.byId(gameSymbolId).getValue()); button.setEnabled(false); data.moveToNext(); } if (toeGame.inProgress()) { endTurn(XIds, OIds, data.getCount()); } }
From source file:com.eTilbudsavis.etasdk.DbHelper.java
/** * Get all {@link ShoppinglistItem} from a {@link Shoppinglist}. * @param shoppinglistId from which to get items * @return A list of shoppinglistitems//from w ww . ja va 2s . c o m */ public List<ShoppinglistItem> getItems(String shoppinglistId, User user, boolean includeDeleted) { String id = escape(shoppinglistId); String q = null; if (includeDeleted) { q = String.format("SELECT * FROM %s WHERE %s=%s AND %s=%s", ITEM_TABLE, SHOPPINGLIST_ID, id, USER, user.getUserId()); } else { q = String.format("SELECT * FROM %s WHERE %s=%s AND %s!=%s AND %s=%s", ITEM_TABLE, SHOPPINGLIST_ID, id, STATE, SyncState.DELETE, USER, user.getUserId()); } List<ShoppinglistItem> items = new ArrayList<ShoppinglistItem>(); Cursor c = null; try { c = execQuery(q); if (c.moveToFirst()) { do { items.add(cursorToSli(c)); } while (c.moveToNext()); } } catch (IllegalStateException e) { EtaLog.d(TAG, e.getMessage(), e); } finally { closeCursorAndDB(c); } return items; }
From source file:fr.openbike.android.database.OpenBikeDBAdapter.java
public int getStationCount() throws SQLException { Cursor cursor = mDb.rawQuery( "SELECT COUNT(*) AS count FROM " + STATIONS_TABLE + " WHERE " + KEY_NETWORK + " = ?", new String[] { String.valueOf(mPreferences.getInt(AbstractPreferencesActivity.NETWORK_PREFERENCE, AbstractPreferencesActivity.NO_NETWORK)) }); cursor.moveToNext(); int count = cursor.getInt(0); cursor.close();//from ww w . ja v a 2 s. c o m return count; }
From source file:com.phonegap.ContactAccessorSdk3_4.java
/** * Create a ContactOrganization JSONArray * @param cr database access object/*from w w w . j a va 2s .c o m*/ * @param contactId the ID to search the database for * @return a JSONArray representing a set of ContactOrganization */ private JSONArray organizationQuery(ContentResolver cr, String contactId) { String orgWhere = ContactMethods.PERSON_ID + " = ?"; String[] orgWhereParams = new String[] { contactId }; Cursor cursor = cr.query(Organizations.CONTENT_URI, null, orgWhere, orgWhereParams, null); JSONArray organizations = new JSONArray(); JSONObject organization; while (cursor.moveToNext()) { organization = new JSONObject(); try { organization.put("id", cursor.getString(cursor.getColumnIndex(Organizations._ID))); organization.put("name", cursor.getString(cursor.getColumnIndex(Organizations.COMPANY))); organization.put("title", cursor.getString(cursor.getColumnIndex(Organizations.TITLE))); // organization.put("department", cursor.getString(cursor.getColumnIndex(Organizations))); organizations.put(organization); } catch (JSONException e) { Log.e(LOG_TAG, e.getMessage(), e); } } return organizations; }