List of usage examples for android.database Cursor isAfterLast
boolean isAfterLast();
From source file:org.openbmap.soapclient.GpxExporter.java
/** * Iterates on way points and write them. * @param bw Writer to the target file.// w w w. j av a2s . c o m * @param c Cursor to way points. * @throws IOException */ private void writeWifis(final BufferedWriter bw) throws IOException { Log.i(TAG, "Writing wifi waypoints"); Cursor c = mDbHelper.getReadableDatabase().rawQuery(WIFI_POINTS_SQL_QUERY, new String[] { String.valueOf(mSession), String.valueOf(0) }); //Log.i(TAG, WIFI_POINTS_SQL_QUERY); final int colLatitude = c.getColumnIndex(Schema.COL_LATITUDE); final int colLongitude = c.getColumnIndex(Schema.COL_LONGITUDE); final int colAltitude = c.getColumnIndex(Schema.COL_ALTITUDE); final int colTimestamp = c.getColumnIndex(Schema.COL_TIMESTAMP); final int colSsid = c.getColumnIndex(Schema.COL_SSID); long outer = 0; while (!c.isAfterLast()) { c.moveToFirst(); //StringBuffer out = new StringBuffer(); while (!c.isAfterLast()) { bw.write("\t<wpt lat=\""); bw.write(String.valueOf(c.getDouble(colLatitude))); bw.write("\" "); bw.write("lon=\""); bw.write(String.valueOf(c.getDouble(colLongitude))); bw.write("\">\n"); bw.write("\t\t<ele>"); bw.write(String.valueOf(c.getDouble(colAltitude))); bw.write("</ele>\n"); bw.write("\t\t<time>"); // time stamp conversion to ISO 8601 bw.write(getGpxDate(c.getLong(colTimestamp))); bw.write("</time>\n"); bw.write("\t\t<name>"); bw.write(StringEscapeUtils.escapeXml(c.getString(colSsid))); bw.write("</name>\n"); bw.write("\t</wpt>\n"); c.moveToNext(); } //bw.write(out.toString()); //out = null; // fetch next CURSOR_SIZE records outer += CURSOR_SIZE; c.close(); c = mDbHelper.getReadableDatabase().rawQuery(WIFI_POINTS_SQL_QUERY, new String[] { String.valueOf(mSession), String.valueOf(outer) }); } c.close(); System.gc(); }
From source file:org.sensapp.android.sensappdroid.fragments.ManageGraphSensorFragment.java
@Override public Dialog onCreateDialog(Bundle savedInstanceState) { final String graphName = getArguments().getString(GRAPH_NAME); final Long graphID = getArguments().getLong(GRAPH_ID); cursor = getActivity().getContentResolver().query(SensAppContract.Sensor.CONTENT_URI, null, null, null, SensAppContract.Sensor.NAME + " ASC"); Cursor cursorGraphSensor = getActivity().getContentResolver().query( Uri.parse(SensAppContract.GraphSensor.CONTENT_URI + "/graph/" + graphID), null, null, null, SensAppContract.GraphSensor.SENSOR + " ASC"); String[] sensorNames = new String[cursor.getCount()]; boolean[] sensorStatus = new boolean[cursor.getCount()]; cursorGraphSensor.moveToFirst();/*from ww w. ja va2 s.c om*/ int columnIDSensorName = cursor.getColumnIndexOrThrow(SensAppContract.Sensor.NAME); int columnIDGraphSensor = cursorGraphSensor.getColumnIndexOrThrow(SensAppContract.GraphSensor.SENSOR); for (int i = 0; cursor.moveToNext(); i++) { //Init sensorNames and put sensorStatus to true if the sensor is in the graph sensorNames[i] = cursor.getString(columnIDSensorName); if (!cursorGraphSensor.isAfterLast() && cursor.getString(columnIDSensorName) .equals(cursorGraphSensor.getString(columnIDGraphSensor))) { sensorStatus[i] = true; } else sensorStatus[i] = false; if (sensorStatus[i]) cursorGraphSensor.moveToNext(); } //Make and display the Dialog return new AlertDialog.Builder(getActivity()).setTitle("Add sensors to the graph " + graphName) .setMultiChoiceItems(sensorNames, sensorStatus, new DialogInterface.OnMultiChoiceClickListener() { public void onClick(DialogInterface dialog, int which, boolean isChecked) { cursor.moveToPosition(which); String sensorName = cursor .getString(cursor.getColumnIndexOrThrow(SensAppContract.Sensor.NAME)); if (isChecked) { sensorsRemoved.remove(sensorName); sensorsAdded.add(sensorName); } else { sensorsAdded.remove(sensorName); sensorsRemoved.add(sensorName); } } }).setPositiveButton("Done", new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int whichButton) { ContentValues values = new ContentValues(); for (String name : sensorsAdded) { values.put(SensAppContract.GraphSensor.TITLE, name); values.put(SensAppContract.GraphSensor.STYLE, GraphBaseView.LINECHART); values.put(SensAppContract.GraphSensor.COLOR, Color.BLUE); values.put(SensAppContract.GraphSensor.MAX, Integer.MAX_VALUE); values.put(SensAppContract.GraphSensor.MIN, Integer.MIN_VALUE); values.put(SensAppContract.GraphSensor.GRAPH, graphID); values.put(SensAppContract.GraphSensor.SENSOR, name); getActivity().getContentResolver().insert(SensAppContract.GraphSensor.CONTENT_URI, values); values.clear(); } for (String name : sensorsRemoved) { String where = SensAppContract.GraphSensor.SENSOR + " = \"" + name + "\" AND " + SensAppContract.GraphSensor.GRAPH + " = " + graphID; getActivity().getContentResolver().delete(SensAppContract.GraphSensor.CONTENT_URI, where, null); } cursor.close(); } }).create(); }
From source file:com.google.samples.search.recipe_app.client.RecipeActivity.java
private void showRecipe(Uri recipeUri) { Log.d("Recipe Uri", recipeUri.toString()); String[] projection = { RecipeTable.ID, RecipeTable.TITLE, RecipeTable.DESCRIPTION, RecipeTable.PHOTO, RecipeTable.PREP_TIME };//from w ww . j a v a2 s. c om Cursor cursor = getContentResolver().query(recipeUri, projection, null, null, null); if (cursor != null && cursor.moveToFirst()) { recipe = Recipe.fromCursor(cursor); Uri ingredientsUri = RecipeContentProvider.CONTENT_URI.buildUpon().appendPath("ingredients") .appendPath(recipe.getId()).build(); Cursor ingredientsCursor = getContentResolver().query(ingredientsUri, projection, null, null, null); if (ingredientsCursor != null && ingredientsCursor.moveToFirst()) { do { Recipe.Ingredient ingredient = new Recipe.Ingredient(); ingredient.setAmount(ingredientsCursor.getString(0)); ingredient.setDescription(ingredientsCursor.getString(1)); recipe.addIngredient(ingredient); ingredientsCursor.moveToNext(); } while (!ingredientsCursor.isAfterLast()); ingredientsCursor.close(); } Uri instructionsUri = RecipeContentProvider.CONTENT_URI.buildUpon().appendPath("instructions") .appendPath(recipe.getId()).build(); Cursor instructionsCursor = getContentResolver().query(instructionsUri, projection, null, null, null); if (instructionsCursor != null && instructionsCursor.moveToFirst()) { do { Recipe.Step step = new Recipe.Step(); step.setDescription(instructionsCursor.getString(1)); step.setPhoto(instructionsCursor.getString(2)); recipe.addStep(step); instructionsCursor.moveToNext(); } while (!instructionsCursor.isAfterLast()); instructionsCursor.close(); } // always close the cursor cursor.close(); } else { Toast toast = Toast.makeText(getApplicationContext(), "No match for deep link " + recipeUri.toString(), Toast.LENGTH_SHORT); toast.show(); } if (recipe != null) { // Create the adapter that will return a fragment for each of the steps of the recipe. mSectionsPagerAdapter = new SectionsPagerAdapter(getFragmentManager()); // Set up the ViewPager with the sections adapter. mViewPager = (ViewPager) findViewById(R.id.pager); mViewPager.setAdapter(mSectionsPagerAdapter); // Set the recipe title TextView recipeTitle = (TextView) findViewById(R.id.recipeTitle); recipeTitle.setText(recipe.getTitle()); // Set the recipe prep time TextView recipeTime = (TextView) findViewById(R.id.recipeTime); recipeTime.setText(" " + recipe.getPrepTime()); } }
From source file:com.amsterdam.marktbureau.makkelijkemarkt.LoginFragment.java
/** * Add the loaded accounts into the accounts adapter when done loading from the db * @param loader the accounts loader attached to the spinner * @param data the loaded data/*w w w .j a va2 s . c om*/ */ @Override public void onLoadFinished(Loader<Cursor> loader, Cursor data) { // populate the adapter with the loaded accounts mAccountsAdapter.swapCursor(data); // get the id of previously selected account from the shared preferences SharedPreferences settings = PreferenceManager.getDefaultSharedPreferences(getContext()); int accountId = settings.getInt(getContext().getString(R.string.sharedpreferences_key_account_id), -1); if (accountId != -1) { // update selected account id member var mSelectedAccountId = accountId; // select the account in the spinner dropdown if (data.moveToFirst()) { while (!data.isAfterLast()) { if (data.getLong( data.getColumnIndex(MakkelijkeMarktProvider.Account.COL_ID)) == mSelectedAccountId) { mAccount.setSelection(data.getPosition()); break; } data.moveToNext(); } } } }
From source file:org.openbmap.soapclient.GpxSerializer.java
/** * Iterates on way points and write them. * * @param bw/*from w w w. ja va2s. co m*/ * Writer to the target file. */ private void writeCells(final BufferedWriter bw) throws IOException { Log.i(TAG, "Writing cell waypoints"); //@formatter:off Cursor c = mDbHelper.getReadableDatabase().rawQuery(CELL_POINTS_SQL_QUERY, new String[] { String.valueOf(mSession), String.valueOf(0) }); //@formatter:on final int colLatitude = c.getColumnIndex(Schema.COL_LATITUDE); final int colLongitude = c.getColumnIndex(Schema.COL_LONGITUDE); final int colAltitude = c.getColumnIndex(Schema.COL_ALTITUDE); final int colTimestamp = c.getColumnIndex(Schema.COL_TIMESTAMP); final int colName = c.getColumnIndex("name"); long outer = 0; while (!c.isAfterLast()) { c.moveToFirst(); while (!c.isAfterLast()) { StringBuffer out = new StringBuffer(); out.append("<wpt lat=\""); out.append(String.valueOf(c.getDouble(colLatitude))); out.append("\" "); out.append("lon=\""); out.append(String.valueOf(c.getDouble(colLongitude))); out.append("\">"); out.append("<ele>"); out.append(String.valueOf(c.getDouble(colAltitude))); out.append("</ele>"); out.append("<time>"); // time stamp conversion to ISO 8601 out.append(getGpxDate(c.getLong(colTimestamp))); out.append("</time>"); out.append("<name>"); out.append(StringEscapeUtils.escapeXml10(c.getString(colName))); out.append("</name>"); out.append("</wpt>"); bw.write(out.toString()); bw.flush(); c.moveToNext(); } //bw.write(out.toString()); //out = null; // fetch next CURSOR_SIZE records outer += CURSOR_SIZE; c.close(); //@formatter:off c = mDbHelper.getReadableDatabase().rawQuery(CELL_POINTS_SQL_QUERY, new String[] { String.valueOf(mSession), String.valueOf(outer) }); //@formatter:on } c.close(); }
From source file:org.openbmap.soapclient.GpxSerializer.java
/** * Iterates on way points and write them. * * @param bw/*from www . ja v a2s . c om*/ * Writer to the target file. */ private void writeWifis(final BufferedWriter bw) throws IOException { Log.i(TAG, "Writing wifi waypoints"); //@formatter:off Cursor c = mDbHelper.getReadableDatabase().rawQuery(WIFI_POINTS_SQL_QUERY, new String[] { String.valueOf(mSession), String.valueOf(0) }); //@formatter:on final int colLatitude = c.getColumnIndex(Schema.COL_LATITUDE); final int colLongitude = c.getColumnIndex(Schema.COL_LONGITUDE); final int colAltitude = c.getColumnIndex(Schema.COL_ALTITUDE); final int colTimestamp = c.getColumnIndex(Schema.COL_TIMESTAMP); final int colSsid = c.getColumnIndex(Schema.COL_SSID); long outer = 0; while (!c.isAfterLast()) { c.moveToFirst(); while (!c.isAfterLast()) { StringBuffer out = new StringBuffer(); out.append("<wpt lat=\""); out.append(String.valueOf(c.getDouble(colLatitude))); out.append("\" "); out.append("lon=\""); out.append(String.valueOf(c.getDouble(colLongitude))); out.append("\">"); out.append("<ele>"); out.append(String.valueOf(c.getDouble(colAltitude))); out.append("</ele>\n"); out.append("<time>"); // time stamp conversion to ISO 8601 out.append(getGpxDate(c.getLong(colTimestamp))); out.append("</time>"); out.append("<name>"); out.append(StringEscapeUtils.escapeXml10(c.getString(colSsid))); out.append("</name>"); out.append("</wpt>"); bw.write(out.toString()); bw.flush(); c.moveToNext(); } // fetch next CURSOR_SIZE records outer += CURSOR_SIZE; c.close(); //@formatter:off c = mDbHelper.getReadableDatabase().rawQuery(WIFI_POINTS_SQL_QUERY, new String[] { String.valueOf(mSession), String.valueOf(outer) }); //@formatter:on } c.close(); }
From source file:com.oxgcp.photoList.PhotolistModule.java
@Kroll.method public KrollDict getPhotos(Integer date, Integer limit) { Uri externalPhotosUri = MediaStore.Images.Media.EXTERNAL_CONTENT_URI; // Uri internalPhotosUri = MediaStore.Images.Media.INTERNAL_CONTENT_URI; Activity activity = this.getActivity(); Gson gson = new Gson(); String orderBy;/*from w w w. j a va2 s .c o m*/ if (date == null) date = 0; if (limit == null) { orderBy = MediaStore.Images.ImageColumns.DATE_TAKEN + " DESC"; } else { orderBy = MediaStore.Images.ImageColumns.DATE_TAKEN + " DESC LIMIT " + limit; } String[] where = { date.toString() }; HashMap<String, String> obj = new HashMap<String, String>(); // HashMap<String, KrollDict> photos = new HashMap<String, KrollDict>(); // KrollDict dict; // String[] projection = new String[]{ // MediaStore.Images.Media._ID, // MediaStore.Images.Media.BUCKET_DISPLAY_NAME, // MediaStore.Images.Media.DATE_TAKEN // }; Cursor externalList = activity.managedQuery(externalPhotosUri, null, MediaStore.Images.ImageColumns.DATE_TAKEN + " > ? ", where, orderBy); // null, MediaStore.Images.ImageColumns.DATE_TAKEN + " DESC WHERE " + MediaStore.Images.ImageColumns._ID + " > " + id + " LIMIT " + limit); // Cursor internalList = activity.managedQuery(internalPhotosUri, null, null, null, MediaStore.Images.ImageColumns.DATE_TAKEN + " DESC"); // ArrayList<String> arrayList = new ArrayList<String>(); KrollDict arrayList = new KrollDict(externalList.getCount()); externalList.moveToFirst(); // internalList.moveToFirst(); Log.d("TiAPI", "externalList's count: " + externalList.getCount()); if (externalList.getCount() > 0) { for (Integer i = 0; !externalList.isAfterLast(); i++) { obj.put("path", externalList.getString(externalList.getColumnIndex(MediaStore.MediaColumns.DATA))); obj.put("date", externalList .getString(externalList.getColumnIndex(MediaStore.Images.ImageColumns.DATE_TAKEN))); // dict = new KrollDict(obj); arrayList.put(i.toString(), new KrollDict(obj)); //add the item externalList.moveToNext(); } } // Log.d("TiAPI", "internalList's count: " + internalList.getCount()); // if (internalList.getCount() > 0) { // while(!internalList.isAfterLast()) { // arrayList.add(internalList.getString(internalList.getColumnIndex(MediaStore.MediaColumns.DATA))); //add the item // internalList.moveToNext(); // } // } return arrayList;//gson.toJson(arrayList); }
From source file:cz.tsystems.portablecheckin.MainActivity.java
private void setPalivoSpinner() { Cursor cursor = app.getPaliva(); final int columnIndex = cursor.getColumnIndex("FUEL_ID"); final int fuelId = app.getCheckin().fuel_id; int pos = -1; while (!cursor.isAfterLast()) { pos++;/*from w w w .j a v a2 s . c o m*/ if (cursor.getInt(columnIndex) == fuelId) break; cursor.moveToNext(); } final SimpleCursorAdapter adapter = new SimpleCursorAdapter(getActivity(), android.R.layout.simple_spinner_dropdown_item, cursor, new String[] { "TEXT" }, new int[] { android.R.id.text1 }, 0); spTypPaliva.setAdapter(adapter); spTypPaliva.setSelection(pos, true); spTypPaliva.setOnItemSelectedListener(new OnItemSelectedListener() { @Override public void onItemSelected(AdapterView<?> parent, View view, int position, long id) { ((FragmentPagerActivity) getActivity()).unsavedCheckin(); Cursor c = (Cursor) spTypPaliva.getSelectedItem(); app.getCheckin().fuel_id = c.getShort(c.getColumnIndex("FUEL_ID")); } @Override public void onNothingSelected(AdapterView<?> parent) { } }); }
From source file:com.spoiledmilk.ibikecph.util.DB.java
public ArrayList<SearchListItem> getSearchHistory() { ArrayList<SearchListItem> ret = new ArrayList<SearchListItem>(); SQLiteDatabase db = getReadableDatabase(); if (db == null) return null; String[] columns = { KEY_ID, KEY_NAME, KEY_ADDRESS, KEY_START_DATE, KEY_END_DATE, KEY_SOURCE, KEY_SUBSOURCE, KEY_LAT, KEY_LONG };/*w w w . j ava 2s.co m*/ Cursor cursor = db.query(TABLE_SEARCH_HISTORY, columns, null, null, null, null, KEY_START_DATE + " DESC", null); if (cursor != null && cursor.moveToFirst()) { while (cursor != null && !cursor.isAfterLast()) { int colId = cursor.getColumnIndex(KEY_ID); int colName = cursor.getColumnIndex(KEY_NAME); int colAddress = cursor.getColumnIndex(KEY_ADDRESS); int colStartDate = cursor.getColumnIndex(KEY_START_DATE); int colEndDate = cursor.getColumnIndex(KEY_END_DATE); int colSource = cursor.getColumnIndex(KEY_SOURCE); int colSubSource = cursor.getColumnIndex(KEY_SUBSOURCE); int colLat = cursor.getColumnIndex(KEY_LAT); int colLong = cursor.getColumnIndex(KEY_LONG); HistoryData hd = new HistoryData(cursor.getInt(colId), cursor.getString(colName), cursor.getString(colAddress), cursor.getString(colStartDate), cursor.getString(colEndDate), cursor.getString(colSource), cursor.getString(colSubSource), cursor.getDouble(colLat), cursor.getDouble(colLong)); if (hd.getName() != null && !hd.getName().trim().equals("")) { ret.add(hd); } if (ret.size() > 10) { break; } cursor.moveToNext(); } } if (cursor != null) cursor.close(); db.close(); return ret; }
From source file:com.spoiledmilk.ibikecph.util.DB.java
public SearchListItem getFavoriteByName(String name) { SearchListItem ret = null;//w w w . ja v a2 s. c o m SQLiteDatabase db = getReadableDatabase(); if (db == null) return null; String[] columns = { KEY_ID, KEY_NAME, KEY_ADDRESS, KEY_SOURCE, KEY_SUBSOURCE, KEY_LAT, KEY_LONG, KEY_API_ID }; Cursor cursor = db.query(TABLE_FAVORITES, columns, KEY_NAME + " = ? ", new String[] { name.trim() }, null, null, null, null); if (cursor != null && cursor.moveToFirst()) { while (cursor != null && !cursor.isAfterLast()) { int colId = cursor.getColumnIndex(KEY_ID); int colName = cursor.getColumnIndex(KEY_NAME); int colAddress = cursor.getColumnIndex(KEY_ADDRESS); int colSubSource = cursor.getColumnIndex(KEY_SUBSOURCE); int colLat = cursor.getColumnIndex(KEY_LAT); int colLong = cursor.getColumnIndex(KEY_LONG); int colApiId = cursor.getColumnIndex(KEY_API_ID); ret = new FavoritesData(cursor.getInt(colId), cursor.getString(colName), cursor.getString(colAddress), cursor.getString(colSubSource), cursor.getDouble(colLat), cursor.getDouble(colLong), cursor.getInt(colApiId)); break; } } if (cursor != null) cursor.close(); db.close(); return ret; }