List of usage examples for android.database Cursor isAfterLast
boolean isAfterLast();
From source file:org.musicmod.android.dialog.PlaylistDialog.java
private int idForplaylist(String name) { Cursor cursor = MusicUtils.query(this, MediaStore.Audio.Playlists.EXTERNAL_CONTENT_URI, new String[] { MediaStore.Audio.Playlists._ID }, MediaStore.Audio.Playlists.NAME + "=?", new String[] { name }, MediaStore.Audio.Playlists.NAME); int id = -1;/* ww w.j a v a 2s . c om*/ if (cursor != null) { cursor.moveToFirst(); if (!cursor.isAfterLast()) { id = cursor.getInt(0); } cursor.close(); } return id; }
From source file:org.androidtitlan.estoesgoogle.ui.tablet.TracksDropdownFragment.java
/** {@inheritDoc} */ public void onQueryComplete(int token, Object cookie, Cursor cursor) { if (getActivity() == null || cursor == null) { return;/* w w w . jav a 2s . c o m*/ } mCursor = cursor; getActivity().startManagingCursor(mCursor); // If there was a last-opened track, load it. Otherwise load the first track. cursor.moveToFirst(); String lastTrackID = UIUtils.getLastUsedTrackID(getActivity()); if (lastTrackID != null) { while (!cursor.isAfterLast()) { if (lastTrackID.equals(cursor.getString(TracksAdapter.TracksQuery.TRACK_ID))) { break; } cursor.moveToNext(); } if (cursor.isAfterLast()) { loadTrack(null, mAutoloadTarget); } else { loadTrack(cursor, mAutoloadTarget); } } else { loadTrack(null, mAutoloadTarget); } mAdapter.setHasAllItem(true); mAdapter.setIsSessions(true); mAdapter.changeCursor(mCursor); }
From source file:de.elanev.studip.android.app.frontend.messages.MessageComposeFragment.java
public void onLoadFinished(Loader<Cursor> laoder, Cursor cursor) { ArrayList<UserItem> items = new ArrayList<UserItem>(); cursor.moveToFirst();/* w w w. java 2s. com*/ while (!cursor.isAfterLast()) { items.add(getNewUserItem(cursor)); cursor.moveToNext(); } mAdapter = new UserAdapter(mContext, R.layout.list_item_single_text, items); mAutoCompleteTextView.setAdapter(mAdapter); mAdapter.notifyDataSetChanged(); }
From source file:com.goliathonline.android.kegbot.ui.tablet.TracksDropdownFragment.java
/** {@inheritDoc} */ public void onQueryComplete(int token, Object cookie, Cursor cursor) { if (getActivity() == null || cursor == null) { return;/*from ww w. j ava 2 s . c o m*/ } mCursor = cursor; getActivity().startManagingCursor(mCursor); // If there was a last-opened track, load it. Otherwise load the first track. cursor.moveToFirst(); String lastTrackID = UIUtils.getLastUsedTrackID(getActivity()); if (lastTrackID != null) { while (!cursor.isAfterLast()) { if (lastTrackID.equals(cursor.getString(TracksAdapter.TracksQuery.KEG_ID))) { break; } cursor.moveToNext(); } if (cursor.isAfterLast()) { loadTrack(null, mAutoloadTarget); } else { loadTrack(cursor, mAutoloadTarget); } } else { loadTrack(null, mAutoloadTarget); } mAdapter.setHasAllItem(true); mAdapter.setIsSessions(NEXT_TYPE_SESSIONS.equals(mNextType)); mAdapter.changeCursor(mCursor); }
From source file:com.sferadev.etic.tasks.DownloadTasksTask.java
private void cleanupTasks(FileDbAdapter fda, String source) throws Exception { Cursor taskListCursor = fda.fetchTasksForSource(source, false); taskListCursor.moveToFirst();/*from w ww . j av a 2 s .com*/ while (!taskListCursor.isAfterLast()) { if (isCancelled()) { return; } ; // Return if the user cancels String status = taskListCursor.getString(taskListCursor.getColumnIndex(FileDbAdapter.KEY_T_STATUS)); long id = taskListCursor.getLong(taskListCursor.getColumnIndex(FileDbAdapter.KEY_T_ID)); Log.i("cleanupTasks", "taskid:" + id + " -- status:" + status); if (status.equals(FileDbAdapter.STATUS_T_MISSED) || status.equals(FileDbAdapter.STATUS_T_CANCELLED)) { fda.deleteTask(id); } taskListCursor.moveToNext(); } taskListCursor.close(); }
From source file:com.stoyanr.feeder.activity.ChannelsActivity.java
private long[] getChannelIds() { Cursor cursor = adapter.getCursor(); assert (cursor != null); long[] result = new long[cursor.getCount()]; int i = 0;/* w w w . j a va 2s. co m*/ for (cursor.moveToFirst(); !cursor.isAfterLast(); cursor.moveToNext()) { result[i++] = (ContentManager.getChannelId(cursor)); } return result; }
From source file:com.entertailion.android.launcher.Dialogs.java
/** * Utility method to load the list of browser bookmarks. *///from w w w .ja v a 2 s .c o m private static ArrayList<BookmarkInfo> loadBookmarks(Launcher context) { ArrayList<BookmarkInfo> bookmarks = new ArrayList<BookmarkInfo>(); Cursor cursor = context.managedQuery(Browser.BOOKMARKS_URI, Browser.HISTORY_PROJECTION, null, null, null); if (cursor != null) { cursor.moveToFirst(); if (cursor.moveToFirst() && cursor.getCount() > 0) { while (cursor.isAfterLast() == false) { String bookmarkIndex = cursor.getString(Browser.HISTORY_PROJECTION_BOOKMARK_INDEX); if (bookmarkIndex != null && bookmarkIndex.equals("1")) { BookmarkInfo bookmark = new BookmarkInfo(); String title = cursor.getString(Browser.HISTORY_PROJECTION_TITLE_INDEX); bookmark.setTitle(title); String url = cursor.getString(Browser.HISTORY_PROJECTION_URL_INDEX); bookmark.setUrl(url); // for some reason the favicons aren't good looking // images // byte[] data = // cursor.getBlob(Browser.HISTORY_PROJECTION_FAVICON_INDEX); // if (data != null) { // try { // Bitmap bitmap = BitmapFactory.decodeByteArray(data, // 0, data.length); // bookmark.setDrawable(new FastBitmapDrawable(bitmap)); // } catch (Exception e) { // Log.e(LOG_TAG, "bookmark icon", e); // } // } bookmarks.add(bookmark); } cursor.moveToNext(); } } } return bookmarks; }
From source file:com.andrew.apollo.utils.MusicUtils.java
/** * Creates a sub menu used to add items to a new playlist or an existing * one.//from w w w . jav a2 s.c o m * * @param context The {@link Context} to use. * @param groupId The group Id of the menu. * @param subMenu The {@link SubMenu} to add to. * @param showFavorites True if we should show the option to add to the * Favorites cache. */ public static void makePlaylistMenu(final Context context, final int groupId, final SubMenu subMenu, final boolean showFavorites) { // subMenu.clear(); subMenu.clearHeader(); if (showFavorites) { subMenu.add(groupId, FragmentMenuItems.ADD_TO_FAVORITES, Menu.NONE, R.string.add_to_favorites); } subMenu.add(groupId, FragmentMenuItems.NEW_PLAYLIST, Menu.NONE, R.string.new_empty_playlist); Cursor cursor = PlaylistLoader.makePlaylistCursor(context); if (cursor != null && cursor.getCount() > 0 && cursor.moveToFirst()) { while (!cursor.isAfterLast()) { final Intent intent = new Intent(); String name = cursor.getString(1); //LOG.info("makePlaylistMenu - add ["+name+"]"); if (name != null) { intent.putExtra("playlist", getIdForPlaylist(context, name)); subMenu.add(groupId, FragmentMenuItems.PLAYLIST_SELECTED, Menu.NONE, name).setIntent(intent); } cursor.moveToNext(); } } if (cursor != null) { cursor.close(); } }
From source file:curso.android.DAO.PerguntaDAO.java
public static List<Pergunta> readAll() { Cursor cursor = null; try {/*w w w.j a v a 2s. c o m*/ List<Pergunta> all = new ArrayList<Pergunta>(); cursor = Const.db.rawQuery("SELECT * FROM pergunta WHERE user_id <> " + Const.config.idUser, null); if (cursor.getCount() > 0) { int idIndex = cursor.getColumnIndex("ask_id"); int userIndex = cursor.getColumnIndex("user_id"); int perguntaIndex = cursor.getColumnIndex("ask_pergunta"); int nomeIndex = cursor.getColumnIndex("user_name"); int statusIndex = cursor.getColumnIndex("status"); cursor.moveToFirst(); do { Long id = Long.valueOf(cursor.getInt(idIndex)); Long user = Long.valueOf(cursor.getString(userIndex)); String pergunta = cursor.getString(perguntaIndex); String user_name = cursor.getString(nomeIndex); String status = cursor.getString(statusIndex); Pergunta ask = new Pergunta(); ask.setAsk_id(id); ask.setUser_id(user); ask.setAsk_pergunta(pergunta); ask.setUser_name(user_name); ask.setStatus(Integer.valueOf(status) == 1); all.add(ask); cursor.moveToNext(); } while (!cursor.isAfterLast()); } return all; } finally { if (cursor != null) { cursor.close(); } } }
From source file:com.example.android.gcncouponalert.app.CouponsFragment.java
@Override public void onLoadFinished(Loader<Cursor> loader, Cursor data) { Log.d(LOG_TAG, "onLoadFinished: " + data.getCount()); mCouponsAdapter.swapCursor(data);//from w w w .j a v a2s . c o m //Bundle extras = getActivity().getIntent().getExtras(); Bundle extras = this.getArguments(); if (extras != null) { if (extras.containsKey("coupon_id")) { long coupon_id = extras.getLong("coupon_id"); Log.d(LOG_TAG, "Intent! coupon_id: " + coupon_id); if (null != mCouponsAdapter) { //Log.d(LOG_TAG,"Intent! mCouponsAdapter OK"); Cursor c = mCouponsAdapter.getCursor(); if (null != c) { //Log.d(LOG_TAG,"Intent! Cursor c OK"); if (c.moveToFirst()) { //Log.d(LOG_TAG,"Intent! Cursor c has data OK"); while (!c.isAfterLast()) { //Log.d(LOG_TAG,"Intent! is "+c.getLong(COL_COUPON_ID)+" == "+coupon_id+" ?"); if (c.getLong(COL_COUPON_ID) == coupon_id) { mPosition = c.getPosition(); break; } c.moveToNext(); } } } } //getActivity().getIntent().removeExtra("coupon_id"); extras.remove("coupon_id"); } } //Log.d(LOG_TAG,"Intent! mPosition: "+mPosition); if (mPosition != ListView.INVALID_POSITION) { // If we don't need to restart the loader, and there's a desired position to restore // to, do so now. int offset = 0; //mListView.smoothScrollToPositionFromTop(mPosition, offset, 100); mListView.setSelection(mPosition); } }