List of usage examples for android.database Cursor getCount
int getCount();
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();//ww w . ja v a 2 s . co m 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:fr.openbike.android.database.OpenBikeDBAdapter.java
public Cursor getStation(int id, String[] columns) throws SQLException { Cursor cursor = mDb.query(true, STATIONS_TABLE, columns, BaseColumns._ID + " = ? AND " + KEY_NETWORK + " = ?", new String[] { String.valueOf(id), String.valueOf(mPreferences.getInt(AbstractPreferencesActivity.NETWORK_PREFERENCE, AbstractPreferencesActivity.NO_NETWORK)) }, null, null, null, null);// w w w. j a va 2 s . c om if ((cursor.getCount() == 0) || !cursor.moveToFirst()) { throw new SQLException("No Station found with ID " + id); } return cursor; }
From source file:eu.operando.operandoapp.database.DatabaseHelper.java
public int getResponseFilterCount() { String countQuery = "SELECT * FROM " + TABLE_RESPONSE_FILTERS; SQLiteDatabase db = this.getReadableDatabase(); Cursor cursor = db.rawQuery(countQuery, null); int count = cursor.getCount(); cursor.close();//from w ww.j a va 2 s . c om // return count return count; }
From source file:eu.operando.operandoapp.database.DatabaseHelper.java
public int getDomainFilterCount() { String countQuery = "SELECT * FROM " + TABLE_DOMAIN_FILTERS; SQLiteDatabase db = this.getReadableDatabase(); Cursor cursor = db.rawQuery(countQuery, null); int count = cursor.getCount(); cursor.close();/*from w ww.j a v a 2s .c om*/ // return count return count; }
From source file:org.deviceconnect.android.deviceplugin.chromecast.profile.ChromeCastMediaPlayerProfile.java
/** * ??URI?key?value?????Cursor??//from w w w . jav a2 s. co m * * @param uri URI * @param key * @param value ? * @return cursor */ private Cursor getCursorFrom(Uri uri, String key, String value) { Cursor cursor = getContext().getApplicationContext().getContentResolver().query(uri, null, key + "=" + value + "", null, null); if (cursor != null) { if (cursor.moveToFirst()) { if (cursor.getCount() == 1) { return cursor; } cursor.close(); } } return null; }
From source file:com.android.quicksearchbox.ShortcutRepositoryImplLog.java
private boolean hasHistory(SQLiteDatabase db) { Cursor cursor = db.rawQuery(HAS_HISTORY_QUERY, null); try {//from w ww . j a v a 2s . co m if (DBG) Log.d(TAG, "hasHistory(): cursor=" + cursor); return cursor != null && cursor.getCount() > 0; } finally { if (cursor != null) cursor.close(); } }
From source file:com.android.quicksearchbox.ShortcutRepositoryImplLog.java
/** * Returns the source ranking for sources with a minimum number of clicks. * * @param minClicks The minimum number of clicks a source must have. * @return The list of sources, ranked by total clicks. *///w ww . j a v a2 s .co m Map<String, Integer> getCorpusScores(int minClicks) { SQLiteDatabase db = mOpenHelper.getReadableDatabase(); final Cursor cursor = db.rawQuery(SOURCE_RANKING_SQL, new String[] { String.valueOf(minClicks) }); try { Map<String, Integer> corpora = new HashMap<String, Integer>(cursor.getCount()); while (cursor.moveToNext()) { String name = cursor.getString(SourceStats.corpus.ordinal()); int clicks = cursor.getInt(SourceStats.total_clicks.ordinal()); corpora.put(name, clicks); } return corpora; } finally { cursor.close(); } }
From source file:com.nadmm.airports.DownloadActivity.java
protected void updateDownloadList() { Cursor c = createCursor(); DownloadListAdapter adapter = new DownloadListAdapter(this, c); mListView.setAdapter(adapter);/* ww w. j a va 2 s .co m*/ setContentShown(true); if (c.getCount() == 0) { TextView empty = (TextView) findViewById(android.R.id.empty); empty.setText(R.string.download_error); return; } Button btnDelete = (Button) findViewById(R.id.btnDelete); if (!mInstalledData.isEmpty()) { btnDelete.setVisibility(View.VISIBLE); btnDelete.setEnabled(true); } else { btnDelete.setVisibility(View.GONE); } Button btnDownload = (Button) findViewById(R.id.btnDownload); if (!mAvailableData.isEmpty()) { btnDownload.setVisibility(View.VISIBLE); btnDownload.setEnabled(true); } else { btnDownload.setVisibility(View.GONE); } }
From source file:de.nware.app.hsDroid.provider.onlineService2Provider.java
/** * Prfen ob eine bestimmte Prfungsleistung schon eingetragen ist. * //w w w.j a v a 2s .c o m * @param examnr * Prfungsnummer * @param examdate * Prfungsdatum * @return true, wenn erfolgreich */ public boolean examExists(String examnr, String examdate) { SQLiteDatabase mDb = mOpenHelper.getReadableDatabase(); Cursor cursor = mDb.rawQuery( "select 1 from " + mOpenHelper.getTableName() + " where " + onlineService2Data.ExamsCol.EXAMNR + "=? AND " + onlineService2Data.ExamsCol.EXAMDATE + "=?", new String[] { examnr, examdate }); boolean exists = (cursor.getCount() > 0); cursor.close(); return exists; }
From source file:mp.teardrop.SongTimeline.java
/** * Run the given query and add the results to the song timeline. * * @param context A context to use.//from w ww . ja v a 2 s .com * @param query The query to be run. The mode variable must be initialized * to one of SongTimeline.MODE_*. The type and data variables may also need * to be initialized depending on the given mode. * @return The number of songs that were added. */ public int addSongs(Context context, QueryTask query) { Cursor cursor = query.runQuery(context.getContentResolver()); if (cursor == null) { return 0; } int count = cursor.getCount(); if (count == 0) { return 0; } int mode = query.mode; int type = query.type; long data = query.data; ArrayList<Song> timeline = mSongs; synchronized (this) { saveActiveSongs(); switch (mode) { case MODE_ENQUEUE: case MODE_ENQUEUE_POS_FIRST: case MODE_ENQUEUE_ID_FIRST: break; case MODE_PLAY_NEXT: timeline.subList(mCurrentPos + 1, timeline.size()).clear(); break; case MODE_PLAY: case MODE_PLAY_POS_FIRST: case MODE_PLAY_ID_FIRST: timeline.clear(); mCurrentPos = 0; break; default: throw new IllegalArgumentException("Invalid mode: " + mode); } int start = timeline.size(); Song jumpSong = null; for (int j = 0; j != count; ++j) { cursor.moveToPosition(j); Song song = new Song(-1); song.populate(cursor); timeline.add(song); if (jumpSong == null) { if ((mode == MODE_PLAY_POS_FIRST || mode == MODE_ENQUEUE_POS_FIRST) && j == data) { jumpSong = song; } else if (mode == MODE_PLAY_ID_FIRST || mode == MODE_ENQUEUE_ID_FIRST) { long id; switch (type) { /* case MediaUtils.TYPE_ARTIST: id = song.artistId; break; case MediaUtils.TYPE_ALBUM: id = song.albumId; break; case MediaUtils.TYPE_SONG: id = song.id; break; */ default: throw new IllegalArgumentException("Unsupported id type: " + type); } /* if (id == data) jumpSong = song; */ } } } if (mShuffleMode != SHUFFLE_NONE) MediaUtils.shuffle(timeline.subList(start, timeline.size()), mShuffleMode == SHUFFLE_ALBUMS); if (jumpSong != null) { int jumpPos = timeline.indexOf(jumpSong); if (jumpPos != start) { // Get the sublist twice to avoid a ConcurrentModificationException. timeline.addAll(timeline.subList(start, jumpPos)); timeline.subList(start, jumpPos).clear(); } } broadcastChangedSongs(); } changed(); return count; }