Java Code Examples for android.database.Cursor
The following code examples are extracted from open source projects. You can click to
vote up the examples that are useful to you.
Example 1
From project aksunai, under directory /src/org/androidnerds/app/aksunai/data/.
Source file: ServerDbAdapter.java

public Vector<String> getTitles(){ SQLiteDatabase db=getReadableDatabase(); Vector<String> titles=new Vector<String>(); Cursor c=db.query(DB_TABLE,null,null,null,null,null,null); while (c.moveToNext()) { titles.add(c.getString(1)); } c.close(); db.close(); return titles; }
Example 2
From project ActionBarSherlock, under directory /library/src/com/actionbarsherlock/widget/.
Source file: SearchView.java

/** * Launches an intent based on a suggestion. * @param position The index of the suggestion to create the intent from. * @param actionKey The key code of the action key that was pressed,or {@link KeyEvent#KEYCODE_UNKNOWN} if none. * @param actionMsg The message for the action key that was pressed,or <code>null</code> if none. * @return true if a successful launch, false if could not (e.g. bad position). */ private boolean launchSuggestion(int position,int actionKey,String actionMsg){ Cursor c=mSuggestionsAdapter.getCursor(); if ((c != null) && c.moveToPosition(position)) { Intent intent=createIntentFromSuggestion(c,actionKey,actionMsg); launchIntent(intent); return true; } return false; }
Example 3
From project AirCastingAndroidClient, under directory /src/main/java/pl/llp/aircasting/repository/db/.
Source file: UncalibratedMeasurementCalibrator.java

public int sessionsToCalibrate(){ return airCastingDB.executeReadOnlyTask(new ReadOnlyDatabaseTask<Integer>(){ @Override public Integer execute( SQLiteDatabase readOnlyDatabase){ Cursor c=readOnlyDatabase.rawQuery("SELECT COUNT(*) FROM " + SESSION_TABLE_NAME + " WHERE "+ SESSION_CALIBRATED+ " = 0",null); c.moveToFirst(); if (c.getCount() < 1) { return 0; } return c.getInt(0); } } ); }
Example 4
From project AirCastingAndroidClient, under directory /src/main/java/pl/llp/aircasting/repository/.
Source file: SessionRepository.java

@Internal Cursor notDeletedCursor(@Nullable Sensor sensor,SQLiteDatabase readOnlyDatabase){ Cursor result; if (sensor == null) { result=readOnlyDatabase.query(SESSION_TABLE_NAME,null,SESSION_MARKED_FOR_REMOVAL + " = 0",null,null,null,SESSION_START + " DESC"); } else { result=readOnlyDatabase.rawQuery(SESSIONS_BY_SENSOR_QUERY,new String[]{sensor.getSensorName()}); } return result; }
Example 5
public Cursor getAirportDetails(String siteNumber){ SQLiteDatabase db=getDatabase(DatabaseManager.DB_FADDS); SQLiteQueryBuilder builder=new SQLiteQueryBuilder(); builder.setTables(Airports.TABLE_NAME + " a LEFT OUTER JOIN " + States.TABLE_NAME+ " s"+ " ON a."+ Airports.ASSOC_STATE+ "=s."+ States.STATE_CODE); Cursor c=builder.query(db,new String[]{"*"},Airports.SITE_NUMBER + "=?",new String[]{siteNumber},null,null,null,null); if (!c.moveToFirst()) { return null; } return c; }
Example 6
From project Airports, under directory /src/com/nadmm/airports/aeronav/.
Source file: ChartsDownloadActivity.java

@Override protected Cursor[] doInBackground(String... params){ Cursor[] result=new Cursor[2]; SQLiteDatabase db=getDatabase(DatabaseManager.DB_DTPP); SQLiteQueryBuilder builder=new SQLiteQueryBuilder(); builder.setTables(DtppCycle.TABLE_NAME); Cursor c=builder.query(db,new String[]{"*"},null,null,null,null,null,null); result[0]=c; builder=new SQLiteQueryBuilder(); builder.setTables(Dtpp.TABLE_NAME); c=builder.query(db,new String[]{Dtpp.TPP_VOLUME,"count(DISTINCT " + Dtpp.PDF_NAME + ") AS total"},Dtpp.USER_ACTION + "!='D'",null,Dtpp.TPP_VOLUME,null,null,null); result[1]=c; return result; }
Example 7
From project aksunai, under directory /src/org/androidnerds/app/aksunai/data/.
Source file: ServerDbAdapter.java

public Vector<Long> getIds(){ SQLiteDatabase db=getReadableDatabase(); Vector<Long> ids=new Vector<Long>(); Cursor c=db.query(DB_TABLE,null,null,null,null,null,null); while (c.moveToNext()) { ids.add(new Long(c.getLong(0))); } c.close(); db.close(); return ids; }
Example 8
From project Alerte-voirie-android, under directory /src/com/fabernovel/alertevoirie/.
Source file: ReportDetailsActivity.java

public String getPath(Uri uri){ String[] projection={MediaStore.Images.Media.DATA}; Cursor cursor=managedQuery(uri,projection,null,null,null); if (cursor != null) { int column_index=cursor.getColumnIndexOrThrow(MediaStore.Images.Media.DATA); cursor.moveToFirst(); return cursor.getString(column_index); } else return null; }
Example 9
From project Alerte-voirie-android, under directory /src/com/fabernovel/alertevoirie/.
Source file: SelectCategoryActivity.java

@Override public View getView(int position,View convertView,ViewGroup parent){ View v=super.getView(position,convertView,parent); Cursor cur=(Cursor)getItem(position); int d=getResources().getIdentifier("pictocat" + cur.getLong(cur.getColumnIndex(BaseColumns._ID)),TYPEDRAWABLE,R.class.getPackage().getName()); ((ImageView)v.findViewById(R.id.ImageViewCat)).setImageResource(d); return v; }
Example 10
From project AmDroid, under directory /AmDroid/src/main/java/com/jaeckel/amenoid/db/.
Source file: AmenDaoImpl.java

private User findUserById(long id){ SQLiteDatabase db=dbHelper.getReadableDatabase(); Cursor cursor=db.query(AmenDBHelper.USERS_TABLE,null,AmenDBHelper.KEY_ID + "=?",new String[]{"" + id},null,null,null); if (cursor.getCount() == 0) { return null; } cursor.moveToFirst(); User result=new User(); result.setId(cursor.getLong(cursor.getColumnIndex(AmenDBHelper.KEY_ID))); return result; }
Example 11
From project AmDroid, under directory /AmDroid/src/main/java/com/jaeckel/amenoid/db/.
Source file: AmenDaoImpl.java

public Statement findStatementById(Long id){ SQLiteDatabase db=dbHelper.getReadableDatabase(); Cursor cursor=db.query(AmenDBHelper.STATEMENTS_TABLE,null,AmenDBHelper.KEY_ID + "=?",new String[]{"" + id},null,null,null); if (cursor.getCount() == 0) { return null; } cursor.moveToFirst(); Statement result=new Statement(); result.setId(cursor.getLong(cursor.getColumnIndex(AmenDBHelper.KEY_ID))); return result; }
Example 12
From project and-bible, under directory /AndBible/src/net/bible/service/db/bookmark/.
Source file: BookmarkDBAdapter.java

public BookmarkDto getBookmarkDto(long id){ BookmarkDto bookmark=null; Cursor c=db.query(BookmarkQuery.TABLE,BookmarkQuery.COLUMNS,BookmarkColumn._ID + "=?",new String[]{String.valueOf(id)},null,null,null); try { if (c.moveToFirst()) { bookmark=getBookmarkDto(c); } } finally { c.close(); } return bookmark; }
Example 13
From project and-bible, under directory /AndBible/src/net/bible/service/db/bookmark/.
Source file: BookmarkDBAdapter.java

public BookmarkDto getBookmarkByKey(String key){ BookmarkDto bookmark=null; Cursor c=db.query(BookmarkQuery.TABLE,BookmarkQuery.COLUMNS,BookmarkColumn.KEY + "=?",new String[]{key},null,null,null); try { if (c.moveToFirst()) { bookmark=getBookmarkDto(c); } } finally { c.close(); } return bookmark; }
Example 14
From project 2Degrees-Toolbox, under directory /Toolbox/src/biz/shadowservices/DegreesToolbox/.
Source file: DBLog.java

public static void insertMessage(Context c,String severity,String tag,String message){ DBOpenHelper dbHelper=new DBOpenHelper(c); SQLiteDatabase db=dbHelper.getWritableDatabase(); ContentValues values=new ContentValues(); Date now=new Date(); values.put("date_time",DateFormatters.ISO8601FORMAT.format(now)); values.put("severity",severity); values.put("tag",tag); values.put("message",message); db.insert("log",null,values); if ((int)(Math.random() * 200) == 5) { Cursor results=db.rawQuery("SELECT COUNT(1) FROM log",null); results.moveToFirst(); int noLines=results.getInt(0); results.close(); if (noLines > 50) { String sql="DELETE FROM log WHERE `id` IN (SELECT `id` FROM log ORDER BY `id` ASC LIMIT " + (noLines - 50) + ")"; Log.d("2DegreesDBLog","Deleting " + (noLines - 50) + "rows. Sql: "+ sql); db.execSQL(sql); } } db.close(); }
Example 15
From project 2Degrees-Toolbox, under directory /Toolbox/src/biz/shadowservices/DegreesToolbox/.
Source file: LogViewActivity.java

private void refreshLog(){ LinearLayout layout=(LinearLayout)this.findViewById(R.id.logLinesLayout); layout.removeAllViews(); DBOpenHelper dbHelper=new DBOpenHelper(this); SQLiteDatabase db=dbHelper.getReadableDatabase(); Cursor logLines=db.query("log",null,null,null,null,null,"id DESC"); logLines.moveToFirst(); for (int i=0; i < logLines.getCount(); i++) { StringBuilder text=new StringBuilder(logLines.getString(1).replace("T"," ")); text.append(" "); text.append(logLines.getString(4)); TextView textView=new TextView(this); textView.setText(text); layout.addView(textView); logLines.moveToNext(); } logLines.close(); db.close(); }
Example 16
From project ActionBarSherlock, under directory /library/src/com/actionbarsherlock/widget/.
Source file: SearchView.java

/** * Query rewriting. */ private void rewriteQueryFromSuggestion(int position){ CharSequence oldQuery=mQueryTextView.getText(); Cursor c=mSuggestionsAdapter.getCursor(); if (c == null) { return; } if (c.moveToPosition(position)) { CharSequence newQuery=mSuggestionsAdapter.convertToString(c); if (newQuery != null) { setQuery(newQuery); } else { setQuery(oldQuery); } } else { setQuery(oldQuery); } }
Example 17
From project agit, under directory /agit/src/main/java/com/madgag/agit/db/.
Source file: ReposDataSource.java

public List<RepoRecord> getAllRepos(){ registerReposInStandardDir(); List<RepoRecord> allRepos=newArrayList(); Set<Long> missingReposIds=newHashSet(); Cursor cursor=database.query(DatabaseHelper.TABLE_REPOS,new String[]{DatabaseHelper.COLUMN_ID,DatabaseHelper.COLUMN_GITDIR},null,null,null,null,null); cursor.moveToFirst(); while (!cursor.isAfterLast()) { RepoRecord repoRecord=cursorToRepo(cursor); Log.d(TAG,"Found " + repoRecord); File currentGitDir=RepositoryCache.FileKey.resolve(repoRecord.gitdir,FILESYSTEM); if (currentGitDir == null) { missingReposIds.add(repoRecord.id); } else { allRepos.add(repoRecord); } cursor.moveToNext(); } cursor.close(); Log.d(TAG,"Found " + allRepos.size() + " repos, "+ missingReposIds.size()+ " missing repos"); for ( Long repoId : missingReposIds) { Log.d(TAG,"Deleting missing repo..."); database.delete(DatabaseHelper.TABLE_REPOS,DatabaseHelper.COLUMN_ID + " = " + repoId,null); } return allRepos; }
Example 18
From project alljoyn_java, under directory /samples/android/contacts/ContactsService/src/org/alljoyn/bus/samples/contacts_service/.
Source file: ContactsService.java

public NameId[] getAllContactNames(){ Log.i(TAG,String.format("Client requested a list of contacts")); Cursor cursor=getContentResolver().query(ContactsContract.Contacts.CONTENT_URI,null,null,null,ContactsContract.Contacts.DISPLAY_NAME + " ASC"); startManagingCursor(cursor); int nameIdx=cursor.getColumnIndexOrThrow(ContactsContract.Contacts.DISPLAY_NAME); int idIdx=cursor.getColumnIndexOrThrow(ContactsContract.Contacts._ID); NameId[] result; int count=cursor.getCount(); if (count > 0) { result=new NameId[cursor.getCount()]; if (cursor.moveToFirst()) { do { result[cursor.getPosition()]=new NameId(); result[cursor.getPosition()].displayName=cursor.getString(nameIdx); result[cursor.getPosition()].userId=cursor.getInt(idIdx); } while (cursor.moveToNext()); } } else { result=new NameId[1]; result[0]=new NameId(); result[0].displayName=""; result[0].userId=0; } stopManagingCursor(cursor); String action=String.format("Sending list of %d contacts to Client",count); Message msg=mHandler.obtainMessage(MESSAGE_ACTION,action); mHandler.sendMessage(msg); Log.i(TAG,action); return result; }
Example 19
From project agit, under directory /agit/src/main/java/com/madgag/agit/.
Source file: GitInfoProvider.java

@Override public Cursor query(Uri uri,String[] projection,String selection,String[] selectionArgs,String sortOrder){ MatrixCursor matrixCursor=new MatrixCursor(new String[]{"_id","gitdir"}); for ( File repoDir : reposDir.listFiles()) { File gitdir=RepositoryCache.FileKey.resolve(repoDir,FS.detect()); if (gitdir != null) { matrixCursor.newRow().add(gitdir.hashCode()).add(gitdir); } } return matrixCursor; }