List of usage examples for android.database Cursor moveToNext
boolean moveToNext();
From source file:co.nerdart.ourss.activity.EditFeedActivity.java
@Override protected void onCreate(Bundle savedInstanceState) { UiUtils.setPreferenceTheme(this); super.onCreate(savedInstanceState); ActionBar actionBar = getActionBar(); actionBar.setDisplayHomeAsUpEnabled(true); setContentView(R.layout.feed_edit);//from w ww . j a v a 2 s . c o m setResult(RESULT_CANCELED); Intent intent = getIntent(); mNameEditText = (EditText) findViewById(R.id.feed_title); mUrlEditText = (EditText) findViewById(R.id.feed_url); mRetrieveFulltextCb = (CheckBox) findViewById(R.id.retrieve_fulltext); mFiltersListView = (ListView) findViewById(android.R.id.list); View filtersLayout = findViewById(R.id.filters_layout); View buttonLayout = findViewById(R.id.button_layout); if (intent.getAction().equals(Intent.ACTION_INSERT) || intent.getAction().equals(Intent.ACTION_SEND)) { setTitle(R.string.new_feed_title); filtersLayout.setVisibility(View.GONE); if (intent.hasExtra(Intent.EXTRA_TEXT)) { mUrlEditText.setText(intent.getStringExtra(Intent.EXTRA_TEXT)); } restoreInstanceState(savedInstanceState); } else if (intent.getAction().equals(Intent.ACTION_EDIT)) { setTitle(R.string.edit_feed_title); buttonLayout.setVisibility(View.GONE); mFiltersCursorAdapter = new FiltersCursorAdapter(this, null); mFiltersListView.setAdapter(mFiltersCursorAdapter); mFiltersListView.setOnItemLongClickListener(new OnItemLongClickListener() { @Override public boolean onItemLongClick(AdapterView<?> parent, View view, int position, long id) { startActionMode(mFilterActionModeCallback); mFiltersCursorAdapter.setSelectedFilter(position); mFiltersListView.invalidateViews(); return true; } }); getLoaderManager().initLoader(0, null, this); if (!restoreInstanceState(savedInstanceState)) { Cursor cursor = getContentResolver().query(intent.getData(), FEED_PROJECTION, null, null, null); if (cursor.moveToNext()) { mPreviousName = cursor.getString(0); mNameEditText.setText(mPreviousName); mUrlEditText.setText(cursor.getString(1)); mRetrieveFulltextCb.setChecked(cursor.getInt(2) == 1); cursor.close(); } else { cursor.close(); Crouton.makeText(EditFeedActivity.this, R.string.error, Style.INFO); finish(); } } } }
From source file:edu.gatech.ppl.cycleatlanta.TripUploader.java
@Override protected Boolean doInBackground(Long... tripid) { // First, send the trip user asked for: Boolean result = true;/* ww w. ja va 2 s .co m*/ if (tripid.length != 0) { result = uploadOneTrip(tripid[0]); } // Then, automatically try and send previously-completed trips // that were not sent successfully. Vector<Long> unsentTrips = new Vector<Long>(); mDb.openReadOnly(); Cursor cur = mDb.fetchUnsentTrips(); if (cur != null && cur.getCount() > 0) { // pd.setMessage("Sent. You have previously unsent trips; submitting those now."); while (!cur.isAfterLast()) { unsentTrips.add(Long.valueOf(cur.getLong(0))); cur.moveToNext(); } cur.close(); } mDb.close(); for (Long trip : unsentTrips) { result &= uploadOneTrip(trip); } return result; }
From source file:com.clutch.ClutchStats.java
public ArrayList<StatRow> getLogs() { SQLiteDatabase db = getReadableDatabase(); String[] args = {};/*from w w w . j ava 2 s .co m*/ 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; }
From source file:com.github.gw2app.events.Gw2ApiEvents.java
private List<Gw2Event> _getEvents(String url) { Log.d("Gw2", "Fetching event names from DB."); SQLiteDatabase db = this.dbhelper.getWritableDatabase(); Cursor cursor = db.query(Gw2DB.EVENT_NAMES_TABLE, null, null, null, null, null, null); HashMap<String, String> eventNames = new HashMap<String, String>(); if (cursor.getCount() == 0) { cursor.close();/*from w w w . j a va2s. c om*/ return new ArrayList<Gw2Event>(); } cursor.moveToFirst(); while (!cursor.isLast()) { String id = cursor.getString(0); String name = cursor.getString(1); eventNames.put(id, name); cursor.moveToNext(); } cursor.close(); Log.d("Gw2", "Fetching event data from JSON"); ArrayList<Gw2Event> list = new ArrayList<Gw2Event>(); try { //Log.d("Gw2", url); String result = this.fetchJSONfromURL(url); JSONObject jsData = new JSONObject(result); JSONArray jsArray = jsData.getJSONArray("events"); for (int i = 0; i < jsArray.length(); i++) { JSONObject obj = jsArray.getJSONObject(i); int world_id = obj.getInt("world_id"); int map_id = obj.getInt("map_id"); String event_id = obj.getString("event_id"); String state = obj.getString("state"); list.add(new Gw2Event(world_id, map_id, event_id, state, eventNames.get(event_id))); } } catch (JSONException e) { e.printStackTrace(); } return list; }
From source file:com.jsonstore.database.ReadableDatabase.java
protected String findOperationForObjectById(int id) { Cursor cursor = rawQuery(JSONStoreUtil.formatString(ReadableDatabase.SQL_FIND_OP, DatabaseConstants.FIELD_OPERATION, this.schema.getName(), DatabaseConstants.FIELD_ID), new String[] { "" + id }); //$NON-NLS-1$ String result;// ww w .j a v a 2s . c om if (cursor.getCount() < 1) { cursor.close(); return null; } cursor.moveToNext(); result = cursor.getString(0); cursor.close(); return result; }
From source file:org.noorganization.instalistsynch.controller.synch.impl.TagSynch.java
@Override public void indexLocal(int _groupId, Date _lastIndexTime) { String lastIndexTime = ISO8601Utils.format(_lastIndexTime, false, TimeZone.getTimeZone("GMT+0000"));//.concat("+0000"); boolean isLocal = false; GroupAuth groupAuth = mGroupAuthDbController.getLocalGroup(); if (groupAuth != null) { isLocal = groupAuth.getGroupId() == _groupId; }/*from w w w .j a v a2 s .c o m*/ Cursor tagLogCursor = mClientLogDbController.getLogsSince(lastIndexTime, mModelType); if (tagLogCursor.getCount() == 0) { tagLogCursor.close(); return; } try { while (tagLogCursor.moveToNext()) { // fetch the action type int actionId = tagLogCursor.getInt(tagLogCursor.getColumnIndex(LogInfo.COLUMN.ACTION)); eActionType actionType = eActionType.getTypeById(actionId); List<ModelMapping> modelMappingList = mTagModelMappingController.get( ModelMapping.COLUMN.GROUP_ID + " = ? AND " + ModelMapping.COLUMN.CLIENT_SIDE_UUID + " LIKE ?", new String[] { String.valueOf(_groupId), tagLogCursor.getString(tagLogCursor.getColumnIndex(LogInfo.COLUMN.ITEM_UUID)) }); ModelMapping modelMapping = modelMappingList.size() == 0 ? null : modelMappingList.get(0); switch (actionType) { case INSERT: // skip insertion because this should be decided by the user if the non local groups should have access to the category // and also skip if a mapping for this case already exists! if (!isLocal || modelMapping != null) { continue; } String clientUuid = tagLogCursor .getString(tagLogCursor.getColumnIndex(LogInfo.COLUMN.ITEM_UUID)); Date clientDate = ISO8601Utils.parse( tagLogCursor.getString(tagLogCursor.getColumnIndex(LogInfo.COLUMN.ACTION_DATE)), new ParsePosition(0)); modelMapping = new ModelMapping(null, groupAuth.getGroupId(), null, clientUuid, new Date(Constants.INITIAL_DATE), clientDate, false); mTagModelMappingController.insert(modelMapping); break; case UPDATE: if (modelMapping == null) { Log.i(TAG, "indexLocal: the model is null but shouldn't be"); continue; } String timeString = tagLogCursor .getString(tagLogCursor.getColumnIndex(LogInfo.COLUMN.ACTION_DATE)); clientDate = ISO8601Utils.parse(timeString, new ParsePosition(0)); modelMapping.setLastClientChange(clientDate); mTagModelMappingController.update(modelMapping); break; case DELETE: if (modelMapping == null) { Log.i(TAG, "indexLocal: the model is null but shouldn't be"); continue; } modelMapping.setDeleted(true); timeString = tagLogCursor.getString(tagLogCursor.getColumnIndex(LogInfo.COLUMN.ACTION_DATE)); clientDate = ISO8601Utils.parse(timeString, new ParsePosition(0)); modelMapping.setLastClientChange(clientDate); mTagModelMappingController.update(modelMapping); break; default: } } } catch (Exception e) { tagLogCursor.close(); } }
From source file:com.cryart.sabbathschool.util.SSCore.java
public ArrayList<SSDay> ssGetDaysByLessonSerial(int ssLessonSerial) { SQLiteDatabase db = this.getReadableDatabase(); Cursor c = db.rawQuery( "SELECT ss_days.* " + "FROM ss_days WHERE day_lesson_serial = ? " + "ORDER BY serial ASC", new String[] { String.valueOf(ssLessonSerial) }); ArrayList<SSDay> ret = new ArrayList<SSDay>(); if (c.moveToFirst()) { do {/*from w ww . j a va 2 s . c o m*/ ret.add(new SSDay(c.getInt(0), c.getString(2), c.getString(3), c.getString(7))); } while (c.moveToNext()); } return ret; }
From source file:com.andrew.apollo.utils.MusicUtils.java
/** * @param context The {@link Context} to use * @return The song list for the last added playlist *///from w w w . j a va 2 s. co m public static long[] getSongListForLastAdded(final Context context) { final Cursor cursor = LastAddedLoader.makeLastAddedCursor(context); if (cursor != null) { final int count = cursor.getCount(); final long[] list = new long[count]; for (int i = 0; i < count; i++) { cursor.moveToNext(); list[i] = cursor.getLong(0); } return list; } return sEmptyList; }
From source file:com.jaspersoft.android.jaspermobile.util.SavedItemHelper.java
public void deleteUnsavedItems() { String selection = SavedItemsTable.DOWNLOADED + " =?"; Cursor cursor = context.getContentResolver().query(MobileDbProvider.SAVED_ITEMS_CONTENT_URI, new String[] { SavedItemsTable._ID, SavedItemsTable.FILE_PATH }, selection, new String[] { "0" }, null);/* w ww. ja v a 2 s. com*/ if (cursor == null) return; if (cursor.moveToFirst()) { do { int id = cursor.getInt(cursor.getColumnIndex(SavedItemsTable._ID)); Uri uri = Uri.withAppendedPath(JasperMobileDbProvider.SAVED_ITEMS_CONTENT_URI, String.valueOf(id)); deleteSavedItem(uri); } while (cursor.moveToNext()); } cursor.close(); }
From source file:com.dileepindia.cordova.sms.SMSPlugin.java
private PluginResult listSMS(JSONObject filter, CallbackContext callbackContext) { Log.e("SMSPlugin", "listSMS"); String uri_filter = filter.optString("box"); int fread = filter.optInt("read"); int fid = filter.optInt("_id"); String faddress = filter.optString("address"); String fcontent = filter.optString("body"); long fdate1 = filter.optLong("date"); int indexFrom = filter.has("indexFrom") ? filter.optInt("indexFrom") : 0; int maxCount = filter.has("maxCount") ? filter.optInt("maxCount") : 100; JSONArray jsons = new JSONArray(); Context ctx = this.cordova.getActivity(); Uri uri = Uri.parse("content://sms/" + uri_filter); Cursor cur = ctx.getContentResolver().query(uri, null, "", null, null); int i = 0;// w w w . j av a 2s .c om while (cur.moveToNext()) if (i >= indexFrom) { i++; if (i >= indexFrom + maxCount) break; boolean matchFilter = false; if (fid > -1) { int _id = cur.getInt(cur.getColumnIndex("_id")); matchFilter = fid == _id; } else if (fread > -1) { int read = cur.getInt(cur.getColumnIndex("read")); matchFilter = fread == read; } else if (faddress.length() > 0) { String address = cur.getString(cur.getColumnIndex("address")).trim(); matchFilter = address.contains(faddress); } else if (fdate1 > 0) { System.out.println(fdate1); long dateInMillis = cur.getLong(cur.getColumnIndex("date")); matchFilter = fdate1 <= dateInMillis; } else if (fcontent.length() > 0) { String body = cur.getString(cur.getColumnIndex("body")).trim(); matchFilter = body.equals(fcontent); } else { matchFilter = true; } if (matchFilter) { JSONObject json = getJsonFromCursor(cur); if (json == null) { callbackContext.error("failed to get json from cursor"); cur.close(); return null; } jsons.put(json); } } cur.close(); callbackContext.success(jsons); return null; }