List of usage examples for android.database Cursor getPosition
int getPosition();
From source file:com.cyanogenmod.eleven.provider.LocalizedStore.java
/** * Gets the list of saved ids and labels for the itemType in localized sorted order * @param itemType the type of item we're querying for (artists, albums, songs) * @param sortType the type we want to sort by (eg songs sorted by artists, * albums sorted by artists). Note some combinations don't make sense and * will fallback to the basic sort, for example Artists sorted by songs * doesn't make sense//w ww.j a v a 2 s . co m * @param descending Whether we want to sort ascending or descending. This will only apply to * the basic searches (ie when sortType == itemType), * otherwise ascending is always assumed * @return sorted list of ids and bucket labels for the itemType */ public SortData getSortOrder(SortParameter itemType, SortParameter sortType, boolean descending) { SortData sortData = new SortData(); String tableName = ""; String joinClause = ""; String selectParams = ""; String postfixOrder = ""; String prefixOrder = ""; switch (itemType) { case Song: selectParams = SongSortColumns.CONCRETE_ID + ","; postfixOrder = SongSortColumns.getOrderBy(descending); tableName = SongSortColumns.TABLE_NAME; if (sortType == SortParameter.Artist) { selectParams += ArtistSortColumns.NAME_LABEL; prefixOrder = ArtistSortColumns.getOrderBy(false) + ","; joinClause = createJoin(ArtistSortColumns.TABLE_NAME, SongSortColumns.ARTIST_ID, ArtistSortColumns.CONCRETE_ID); } else if (sortType == SortParameter.Album) { selectParams += AlbumSortColumns.NAME_LABEL; prefixOrder = AlbumSortColumns.getOrderBy(false) + ","; joinClause = createJoin(AlbumSortColumns.TABLE_NAME, SongSortColumns.ALBUM_ID, AlbumSortColumns.CONCRETE_ID); } else { selectParams += SongSortColumns.NAME_LABEL; } break; case Artist: selectParams = ArtistSortColumns.CONCRETE_ID + "," + ArtistSortColumns.NAME_LABEL; postfixOrder = ArtistSortColumns.getOrderBy(descending); tableName = ArtistSortColumns.TABLE_NAME; break; case Album: selectParams = AlbumSortColumns.CONCRETE_ID + ","; postfixOrder = AlbumSortColumns.getOrderBy(descending); tableName = AlbumSortColumns.TABLE_NAME; if (sortType == SortParameter.Artist) { selectParams += AlbumSortColumns.NAME_LABEL; prefixOrder = ArtistSortColumns.getOrderBy(false) + ","; joinClause = createJoin(ArtistSortColumns.TABLE_NAME, AlbumSortColumns.ARTIST_ID, ArtistSortColumns.CONCRETE_ID); } else { selectParams += AlbumSortColumns.NAME_LABEL; } break; } final String selection = "SELECT " + selectParams + " FROM " + tableName + joinClause + " ORDER BY " + prefixOrder + postfixOrder; if (DEBUG) { Log.d(TAG, "Running selection: " + selection); } Cursor c = null; try { c = mMusicDatabase.getReadableDatabase().rawQuery(selection, null); if (c != null && c.moveToFirst()) { sortData.ids = new long[c.getCount()]; sortData.bucketLabels = new ArrayList<String>(c.getCount()); do { sortData.ids[c.getPosition()] = c.getLong(0); sortData.bucketLabels.add(c.getString(1)); } while (c.moveToNext()); } } finally { if (c != null) { c.close(); } } return sortData; }
From source file:com.android.mail.utils.NotificationUtils.java
/** * Seeks the cursor to the position of the most recent unread conversation. If no unread * conversation is found, the position of the cursor will be restored, and false will be * returned./*w ww . java 2s .co m*/ */ private static boolean seekToLatestUnreadConversation(final Cursor cursor) { final int initialPosition = cursor.getPosition(); do { final Conversation conversation = new Conversation(cursor); if (!conversation.read) { return true; } } while (cursor.moveToNext()); // Didn't find an unread conversation, reset the position. cursor.moveToPosition(initialPosition); return false; }
From source file:de.elanev.studip.android.app.frontend.courses.CoursesFragment.java
@Override public void onLoadFinished(Loader<Cursor> loader, Cursor cursor) { if (getActivity() == null) { return;/*from w w w . j ava 2s .com*/ } cursor.moveToFirst(); if (!cursor.isAfterLast()) { ArrayList<SectionedCursorAdapter.Section> sections = new ArrayList<SectionedCursorAdapter.Section>(); String prevSemesterId = ""; String currSemesterId = ""; int semesterIdIdx = cursor.getColumnIndex(SEMESTER_ID); int semesterTitleIdx = cursor.getColumnIndex(SEMESTER_TITLE); while (!cursor.isAfterLast()) { currSemesterId = cursor.getString(semesterIdIdx); if (!TextUtils.equals(prevSemesterId, currSemesterId)) { sections.add(new SectionedCursorAdapter.Section(cursor.getPosition(), cursor.getString(semesterTitleIdx))); } prevSemesterId = currSemesterId; cursor.moveToNext(); } mAdapter.setSections(sections); } mAdapter.swapCursor(cursor); mSwipeRefreshLayoutListView.setRefreshing(false); }
From source file:com.granita.tasks.QuickAddDialogFragment.java
@Override public void onLoadFinished(Loader<Cursor> loader, Cursor cursor) { mTaskListAdapter.changeCursor(cursor); if (cursor != null) { if (mSelectedListId == -1) { mSelectedListId = mListId;/*from ww w . j a v a 2 s. c om*/ } // set the list that was used the last time the user created an event // iterate over all lists and select the one that matches the given id cursor.moveToFirst(); while (!cursor.isAfterLast()) { long listId = cursor.getLong(TASK_LIST_PROJECTION_VALUES.id); if (listId == mSelectedListId) { mListSpinner.setSelection(cursor.getPosition()); break; } cursor.moveToNext(); } } }
From source file:com.money.manager.ex.common.AllDataListFragment.java
private Money getTotalFromCursor(Cursor cursor) { Money total = MoneyFactory.fromString("0"); int originalPosition = cursor.getPosition(); AllDataAdapter adapter = getAllDataAdapter(); CurrencyService currencyService = new CurrencyService(getContext()); int baseCurrencyId = currencyService.getBaseCurrencyId(); ContentValues values = new ContentValues(); int currencyId; Money amount;//from w w w . j av a 2 s. c om Money converted; String transType; TransactionTypes transactionType; cursor.moveToPosition(Constants.NOT_SET); while (cursor.moveToNext()) { values.clear(); // Read needed data. DatabaseUtils.cursorStringToContentValues(cursor, adapter.TRANSACTIONTYPE, values); DatabaseUtils.cursorIntToContentValues(cursor, adapter.CURRENCYID, values); DatabaseUtils.cursorIntToContentValues(cursor, adapter.TOCURRENCYID, values); DatabaseUtils.cursorDoubleToCursorValues(cursor, adapter.AMOUNT, values); DatabaseUtils.cursorDoubleToCursorValues(cursor, adapter.TOAMOUNT, values); transType = values.getAsString(adapter.TRANSACTIONTYPE); transactionType = TransactionTypes.valueOf(transType); if (transactionType.equals(TransactionTypes.Transfer)) { currencyId = values.getAsInteger(adapter.TOCURRENCYID); amount = MoneyFactory.fromString(values.getAsString(adapter.TOAMOUNT)); } else { currencyId = values.getAsInteger(adapter.CURRENCYID); amount = MoneyFactory.fromString(values.getAsString(adapter.AMOUNT)); } converted = currencyService.doCurrencyExchange(baseCurrencyId, amount, currencyId); total = total.add(converted); } cursor.moveToPosition(originalPosition); return total; }
From source file:com.enadein.carlogbook.adapter.NotificationAdapter.java
@Override public void bindView(View view, Context context, Cursor cursor) { int nameIdx = cursor.getColumnIndex(ProviderDescriptor.Notify.Cols.NAME); int trigerIdx = cursor.getColumnIndex(ProviderDescriptor.Notify.Cols.TRIGGER_VALUE); int typeIdx = cursor.getColumnIndex(ProviderDescriptor.Notify.Cols.TYPE); String name = cursor.getString(nameIdx); long trigerValue = cursor.getLong(trigerIdx); int type = cursor.getInt(typeIdx); ImageView imageView = (ImageView) view.findViewById(R.id.logo); TextView trigerView = (TextView) view.findViewById(R.id.value); TextView nameView = (TextView) view.findViewById(R.id.name); nameView.setText(name);//w ww . ja va2s . co m if (type == ProviderDescriptor.Notify.Type.DATE) { imageView.setImageResource(R.drawable.date); trigerView.setText(CommonUtils.formatDate(new Date(trigerValue))); } else { imageView.setImageResource(R.drawable.odometer); trigerView.setText(String.valueOf(trigerValue)); } int pos = cursor.getPosition(); CommonUtils.runAnimation(mlastPos, pos, view, UnitFacade.animSize); mlastPos = pos; }
From source file:com.example.amit.tellymoviebuzzz.PopularSeriesFragment.java
public boolean[] values() { boolean[] arr; String sSeriesID = MovieContract.SeriesNumberEntry.TABLE_NAME + "." + MovieContract.SeriesNumberEntry.COLUMN_SERIES_CATEGORY + " = ? "; Cursor locationCursor1 = mContext.getContentResolver().query(MovieContract.SeriesNumberEntry.CONTENT_URI, new String[] { MovieContract.SeriesNumberEntry.COLUMN_SERIES_FOLLOWING }, sSeriesID, new String[] { "popular" }, null); int count = locationCursor1.getCount(); arr = new boolean[count]; // this.checkBoxState = new boolean[count]; if (locationCursor1.moveToFirst()) { while (locationCursor1.isAfterLast() == false) { String following = locationCursor1.getString( locationCursor1.getColumnIndex(MovieContract.SeriesNumberEntry.COLUMN_SERIES_FOLLOWING)); if (following == "yes") arr[locationCursor1.getPosition()] = true; else/*w w w . j av a 2 s .co m*/ arr[locationCursor1.getPosition()] = false; } locationCursor1.moveToNext(); } return arr; }
From source file:com.nadmm.airports.afd.AirportDetailsFragment.java
protected void showAwosDetails(Cursor[] result) { LinearLayout layout = (LinearLayout) findViewById(R.id.detail_awos_layout); Cursor awos1 = result[7]; if (awos1.moveToFirst()) { do {//from ww w .j ava 2 s . com if (awos1.getPosition() == MAX_WX_STATIONS) { break; } String icaoCode = awos1.getString(awos1.getColumnIndex(Wxs.STATION_ID)); String sensorId = awos1.getString(awos1.getColumnIndex(Awos1.WX_SENSOR_IDENT)); if (icaoCode == null || icaoCode.isEmpty()) { icaoCode = "K" + sensorId; } String type = awos1.getString(awos1.getColumnIndex(Awos1.WX_SENSOR_TYPE)); String freq = awos1.getString(awos1.getColumnIndex(Awos1.STATION_FREQUENCY)); if (freq == null || freq.isEmpty()) { freq = awos1.getString(awos1.getColumnIndex(Awos1.SECOND_STATION_FREQUENCY)); } String phone = awos1.getString(awos1.getColumnIndex(Awos1.STATION_PHONE_NUMBER)); String name = awos1.getString(awos1.getColumnIndex(Wxs.STATION_NAME)); float distance = awos1.getFloat(awos1.getColumnIndex("DISTANCE")); float bearing = awos1.getFloat(awos1.getColumnIndex("BEARING")); final Bundle extras = new Bundle(); extras.putString(NoaaService.STATION_ID, icaoCode); extras.putString(Awos1.WX_SENSOR_IDENT, sensorId); Runnable runnable = new Runnable() { @Override public void run() { cacheMetars(); Intent intent = new Intent(getActivity(), WxDetailActivity.class); intent.putExtras(extras); startActivity(intent); } }; addAwosRow(layout, icaoCode, name, type, freq, phone, distance, bearing, runnable); } while (awos1.moveToNext()); if (!awos1.isAfterLast()) { Intent intent = new Intent(getActivity(), NearbyWxActivity.class); intent.putExtra(LocationColumns.LOCATION, mLocation); intent.putExtra(LocationColumns.RADIUS, mRadius); addClickableRow(layout, "More...", intent); } } else { addRow(layout, "No Wx stations found nearby."); } }
From source file:com.example.amit.tellymoviebuzzz.UpcomingMoviesForecast.java
@Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { // The CursorAdapter will take data from our cursor and populate the ListView. mForecastAdapter = new ForecastAdapter(getActivity(), null, 0); View rootView = inflater.inflate(R.layout.upcomingmovies_main, container, false); // Get a reference to the ListView, and attach this adapter to it. ListView listView = (ListView) rootView.findViewById(R.id.listview_upcoming_movies); listView.setAdapter(mForecastAdapter); // We'll call our MainActivity listView.setOnItemClickListener(new AdapterView.OnItemClickListener() { @Override// w w w.ja va 2s .co m public void onItemClick(AdapterView<?> adapterView, View view, int position, long l) { // CursorAdapter returns a cursor at the correct position for getItem(), or null // if it cannot seek to that position. Cursor cursor = (Cursor) adapterView.getItemAtPosition(position); if (cursor != null) { // String locationSetting = Utility.getPreferredLocation(getActivity()); String movieSetting = "upcoming"; Log.v("MovieSetting", movieSetting); Log.v("MovieSetting", movieSetting); Log.v("MovieSetting", movieSetting); Log.v("MovieSetting", movieSetting); Log.v("MovieSetting", movieSetting); Log.v("MovieSetting", movieSetting); Log.v("MovieSetting", movieSetting); Log.v("MovieSetting", movieSetting); Log.v("MovieSetting", movieSetting); Log.v("cursor position", String.valueOf(cursor.getPosition())); Log.v("cursor position", String.valueOf(cursor.getPosition())); Log.v("cursor position", String.valueOf(cursor.getPosition())); Log.v("cursor position", String.valueOf(cursor.getPosition())); Log.v("cursor position", String.valueOf(cursor.getPosition())); Log.v("cursor position", String.valueOf(cursor.getPosition())); Log.v("cursor position", String.valueOf(cursor.getPosition())); Log.v("cursor position", String.valueOf(cursor.getPosition())); // Intent intent = new Intent(getActivity(), DetailActivity.class) // .setData(WeatherContract.WeatherEntry.buildWeatherLocationWithDate( // locationSetting, cursor.getLong(COL_WEATHER_DATE) // )); Intent intent = new Intent(getActivity(), DetailActivity.class).setData( MovieContract.MovieNumberEntry.buildMovieTypeWithMovieId(movieSetting, "87101")); startActivity(intent); } } }); return rootView; }
From source file:net.potterpcs.recipebook.RecipeData.java
public String[] getRecipeTagStrings(long rid) { Cursor c = getRecipeTags(rid); String[] tags = new String[c.getCount()]; c.moveToFirst();/*from w w w.j av a 2 s . c om*/ while (!c.isAfterLast()) { tags[c.getPosition()] = c.getString(c.getColumnIndex(TT_TAG)); c.moveToNext(); } c.close(); return tags; }