List of usage examples for android.database Cursor isLast
boolean isLast();
From source file:com.lifeappv1.ContactsListFragment.java
@Override public void onListItemClick(ListView l, View v, int position, long id) { /* Retrieving the phone numbers in order to see if we have more than one */ String phoneNumber = null;//from w ww. j av a 2 s. c o m String name = null; String[] projection = new String[] { Phone.DISPLAY_NAME, Phone.NUMBER }; final Cursor phoneCursor = getActivity().getContentResolver().query(Phone.CONTENT_URI, projection, Data.CONTACT_ID + "=?", new String[] { String.valueOf(id) }, null); if (phoneCursor.moveToFirst() && phoneCursor.isLast()) { final int contactNumberColumnIndex = phoneCursor.getColumnIndex(Phone.NUMBER); phoneNumber = phoneCursor.getString(contactNumberColumnIndex); name = phoneCursor.getString(phoneCursor.getColumnIndex(Phone.DISPLAY_NAME)); } if (phoneNumber != null) { mContactsListener.onContactNumberSelected(phoneNumber, name); } else { mContactsListener.onContactNameSelected(id); } }
From source file:edu.stanford.mobisocial.dungbeetle.ui.fragments.FeedSlideshowFragment.java
private void startSlideshow() { Cursor c = getActivity().getContentResolver().query(mFeedUri, null, getFeedObjectClause(), null, DbObject._ID + " ASC"); try {//w ww .j a v a2 s .c om if (!c.moveToFirst()) { Log.d(TAG, "No items to display."); return; } while (!c.isLast()) { View v = getActivity().findViewById(R.id.feed_view); DbObject.bindView(v, getActivity(), c, false); // TODO: background thread that wakes up and updates foreground activity. try { Thread.sleep(3000); // TODO: diff timestamps; beware of sync death! } catch (InterruptedException e) { } } } finally { c.close(); } }
From source file:com.codinguser.android.contactpicker.ContactsListFragment.java
@Override public void onListItemClick(ListView l, View v, int position, long id) { /* Retrieving the phone numbers in order to see if we have more than one */ String phoneNumber = null;//from www . ja v a 2s. c om String name = null; String email = null; String[] projection = new String[] { Phone.DISPLAY_NAME, Phone.NUMBER }; final Cursor phoneCursor = getActivity().getContentResolver().query(Phone.CONTENT_URI, projection, Data.CONTACT_ID + "=?", new String[] { String.valueOf(id) }, null); if (phoneCursor.moveToFirst() && phoneCursor.isLast()) { final int contactNumberColumnIndex = phoneCursor.getColumnIndex(Phone.NUMBER); phoneNumber = phoneCursor.getString(contactNumberColumnIndex); name = phoneCursor.getString(phoneCursor.getColumnIndex(Phone.DISPLAY_NAME)); // email = phoneCursor.getString(2); } if (phoneNumber != null) { mContactsListener.onContactNumberSelected(phoneNumber, name); } else { mContactsListener.onContactNameSelected(id); } }
From source file:com.github.gw2app.events.Gw2ApiEvents.java
private HashMap<Integer, String> _getMapNamesFromDB() { Log.d("Gw2", "Fetching map names from DB."); SQLiteDatabase db = this.dbhelper.getReadableDatabase(); Cursor cursor = db.query(Gw2DB.MAP_NAMES_TABLE, null, null, null, null, null, null); cursor.moveToFirst();/*from w ww. j av a2s .c om*/ HashMap<Integer, String> mapNames = new HashMap<Integer, String>(); while (!cursor.isLast()) { Integer id = cursor.getInt(0); String name = cursor.getString(1); mapNames.put(id, name); cursor.moveToNext(); } cursor.close(); return mapNames; }
From source file:com.github.gw2app.events.Gw2ApiEvents.java
private HashMap<Integer, String> _getWorldNamesFromDB() { Log.d("Gw2", "Fetching world names from DB."); SQLiteDatabase db = this.dbhelper.getReadableDatabase(); Cursor cursor = db.query(Gw2DB.WORLD_NAMES_TABLE, null, null, null, null, null, null); cursor.moveToFirst();/*from w w w .jav a 2 s. co m*/ HashMap<Integer, String> worldNames = new HashMap<Integer, String>(); while (!cursor.isLast()) { Integer id = cursor.getInt(0); String name = cursor.getString(1); worldNames.put(id, name); cursor.moveToNext(); } cursor.close(); return worldNames; }
From source file:com.yozio.android.YozioDataStoreImpl.java
public Events getEvents(int limit) { synchronized (this) { JSONArray jsonArray = null;//from www . j ava2 s .co m String lastEventId = null; try { Cursor cursor = dbHelper.getReadableDatabase().rawQuery("SELECT _id, " + DATA + " FROM " + EVENTS_TABLE + where() + " ORDER BY _id ASC LIMIT " + limit, null); jsonArray = new JSONArray(); while (cursor.moveToNext()) { if (cursor.isLast()) { lastEventId = cursor.getString(0); } try { jsonArray.put(new JSONObject(cursor.getString(1))); } catch (JSONException e) { // Ignore event. } } cursor.close(); } catch (SQLException e) { Log.e(LOGTAG, "getEvents", e); } finally { dbHelper.close(); } if (jsonArray != null && lastEventId != null) { return new Events(jsonArray, lastEventId); } else { return null; } } }
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();//ww w .j av a2s. co m 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:net.benmoran.affectsampler.AffectSerializer.java
public JSONArray toJSONArray() throws JSONException { Uri samples = AffectSamples.CONTENT_URI; String[] projection = new String[] { AffectSamples.COMMENT, AffectSamples.SCHEDULED_DATE, AffectSamples.CREATED_DATE, AffectSamples.EMOTION, AffectSamples.INTENSITY }; Cursor cursor = mContentResolver.query(samples, projection, null, null, AffectSamples.CREATED_DATE + " ASC"); JSONArray arr = new JSONArray(); int emIndex = cursor.getColumnIndex(AffectSamples.EMOTION); int inIndex = cursor.getColumnIndex(AffectSamples.INTENSITY); int cdIndex = cursor.getColumnIndex(AffectSamples.CREATED_DATE); int sdIndex = cursor.getColumnIndex(AffectSamples.SCHEDULED_DATE); int coIndex = cursor.getColumnIndex(AffectSamples.COMMENT); for (cursor.moveToPosition(0); !cursor.isLast(); cursor.moveToNext()) { JSONObject o = new JSONObject(); o.put(AffectSamples.EMOTION, cursor.getDouble(emIndex)); o.put(AffectSamples.INTENSITY, cursor.getDouble(inIndex)); if (cursor.getLong(sdIndex) > 0) { o.put(AffectSamples.SCHEDULED_DATE, cursor.getLong(sdIndex)); } else {/*from w w w .j av a 2 s . c o m*/ o.put(AffectSamples.SCHEDULED_DATE, null); } o.put(AffectSamples.CREATED_DATE, cursor.getLong(cdIndex)); if (cursor.getString(coIndex) != null) { o.put(AffectSamples.COMMENT, cursor.getString(coIndex)); } else { o.put(AffectSamples.COMMENT, null); } arr.put(o); } cursor.close(); return arr; }
From source file:com.kynetx.api.java
public void setApp(Cursor apps) { appId = "";/*from ww w . j ava 2 s .c o m*/ appVersions = ""; apps.moveToFirst(); while (apps.isAfterLast() == false) { if (!apps.getString(apps.getColumnIndex(KynetxSQLHelper.KEY_VERSION)).equals("none")) { appId += apps.getString(apps.getColumnIndex(KynetxSQLHelper.KEY_APPID)); appVersions += appId + ":kynetx_app_version=" + apps.getString(apps.getColumnIndex(KynetxSQLHelper.KEY_VERSION)) + "&"; if (!apps.isLast()) { appId += ";"; } } apps.moveToNext(); } apps.close(); }
From source file:barqsoft.footballscores.service.FetchScores.java
@Override public boolean onStartJob(JobParameters params) { getData("n7"); getData("p7"); // Adding crest urls only once for (String league : LEAGUES) { // To prevent excessive calls to the API we check if we have teams in the db and links to their crests Cursor cursor = getApplicationContext().getContentResolver().query( DatabaseContract.teams_table.CONTENT_URI, null, DatabaseContract.teams_table.COL_LEAGUE_ID + " = ?", new String[] { league }, null); if (cursor != null && !cursor.moveToFirst()) { getCrestUrl(league);//from w ww. j av a 2 s. c om } else { Cursor cursor1 = getApplicationContext().getContentResolver().query( DatabaseContract.teams_table.CONTENT_URI, null, DatabaseContract.teams_table.COL_LEAGUE_ID + " = ?", new String[] { league }, null); cursor1.moveToFirst(); while (!cursor1.isLast()) { cursor1.moveToNext(); } cursor1.close(); } if (cursor != null) { cursor.close(); } } return true; }