List of usage examples for android.database Cursor moveToPosition
boolean moveToPosition(int position);
From source file:com.money.manager.ex.common.AllDataListFragment.java
private ArrayList<Integer> getTransactionIds() { final ArrayList<Integer> transIds = new ArrayList<>(); AllDataAdapter adapter = getAllDataAdapter(); if (adapter == null) return transIds; Cursor cursor = adapter.getCursor(); if (cursor != null) { // get checked items & count from the adapter, not from the list view. // List view only contains the one that was tapped, ignoring the Select All. // SparseBooleanArray positionChecked = getListView().getCheckedItemPositions(); SparseBooleanArray positionChecked = adapter.getPositionsChecked(); // int checkedItemsCount = getListView().getCheckedItemCount(); int checkedItemsCount = positionChecked.size(); for (int i = 0; i < checkedItemsCount; i++) { int position = positionChecked.keyAt(i); // This screws up the selection? // if (getListHeader() != null) // position--; if (cursor.moveToPosition(position)) { transIds.add(cursor.getInt(cursor.getColumnIndex(QueryAllData.ID))); }//from w w w . j a v a2s . c o m } } return transIds; }
From source file:mp.teardrop.LibraryActivity.java
@Override public boolean onContextItemSelected(MenuItem item) { if (item.getGroupId() == MENU_GROUP_ROUND_BUTTON) { Limiter limiter = mPagerAdapter.getCurrentLimiter(); Intent intent = null;/*from w w w . jav a 2 s . c o m*/ switch (mPagerAdapter.getCurrentType()) { case MediaUtils.TYPE_FILE: intent = new Intent(); intent.putExtra(LibraryAdapter.DATA_TYPE, MediaUtils.TYPE_FILE); intent.putExtra("file", limiter == null ? "/" : limiter.data.toString()); break; case MediaUtils.TYPE_UNIFIED: if (limiter != null && limiter.type <= 20) { intent = new Intent(); intent.putExtra(LibraryAdapter.DATA_TYPE, limiter.type); intent.putExtra(LibraryAdapter.DATA_ID, (Long) limiter.data); } //else continue with null limiter, which will play the entire MediaStore break; } mRoundPlayAllButton.setVisibility(View.GONE); pickSongs(intent, item.getItemId() == MENU_PLAY_ALL ? ACTION_PLAY_ALL : ACTION_ENQUEUE_ALL); return true; } if (item.getGroupId() != 0) { return super.onContextItemSelected(item); } final Intent intent = item.getIntent(); switch (item.getItemId()) { case MENU_EXPAND: expand(intent); if (mDefaultAction == ACTION_LAST_USED && mLastAction != ACTION_EXPAND) { mLastAction = ACTION_EXPAND; } break; case MENU_ENQUEUE: pickSongs(intent, ACTION_ENQUEUE); break; case MENU_PLAY: pickSongs(intent, ACTION_PLAY); break; case MENU_PLAY_ALL: pickSongs(intent, ACTION_PLAY_ALL); break; case MENU_ENQUEUE_ALL: pickSongs(intent, ACTION_ENQUEUE_ALL); break; case MENU_NEW_PLAYLIST: { NewPlaylistDialog dialog = new NewPlaylistDialog(this, null, R.string.create, intent); dialog.setDismissMessage(mHandler.obtainMessage(MSG_NEW_PLAYLIST, dialog)); dialog.show(); break; } case MENU_RENAME_PLAYLIST: { NewPlaylistDialog dialog = new NewPlaylistDialog(this, intent.getStringExtra("title"), R.string.rename, intent); dialog.setDismissMessage(mHandler.obtainMessage(MSG_RENAME_PLAYLIST, dialog)); dialog.show(); break; } case MENU_DELETE: String delete_message = getString(R.string.delete_item, intent.getStringExtra("title")); AlertDialog.Builder dialog = new AlertDialog.Builder(this); dialog.setTitle(R.string.delete); dialog.setMessage(delete_message) .setPositiveButton(R.string.delete, new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int id) { mHandler.sendMessage(mHandler.obtainMessage(MSG_DELETE, intent)); } }).setNegativeButton(R.string.cancel, new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int id) { } }); dialog.create().show(); break; case MENU_ADD_TO_PLAYLIST: { SubMenu playlistMenu = item.getSubMenu(); playlistMenu.add(0, MENU_NEW_PLAYLIST, 0, R.string.new_playlist).setIntent(intent); Cursor cursor = Playlist.queryPlaylists(getContentResolver()); if (cursor != null) { for (int i = 0, count = cursor.getCount(); i != count; ++i) { cursor.moveToPosition(i); long id = cursor.getLong(0); String name = cursor.getString(1); Intent copy = new Intent(intent); copy.putExtra("playlist", id); copy.putExtra("playlistName", name); playlistMenu.add(0, MENU_SELECT_PLAYLIST, 0, name).setIntent(copy); } cursor.close(); } break; } case MENU_SELECT_PLAYLIST: mHandler.sendMessage(mHandler.obtainMessage(MSG_ADD_TO_PLAYLIST, intent)); break; case MENU_MORE_FROM_ARTIST: { String selection = "_id="; selection += intent.getLongExtra(LibraryAdapter.DATA_ID, LibraryAdapter.INVALID_ID); setLimiter(-1, selection); updateLimiterViews(); break; } case MENU_MORE_FROM_ALBUM: setLimiter(-1, "_id=" + intent.getLongExtra(LibraryAdapter.DATA_ID, LibraryAdapter.INVALID_ID)); updateLimiterViews(); break; } return true; }
From source file:com.silentcircle.contacts.calllognew.CallLogAdapter.java
/** * Retrieves the call Ids represented by the current call log row. * * @param cursor Call log cursor to retrieve call Ids from. * @param groupSize Number of calls associated with the current call log row. * @return Array of call Ids.//from w w w .ja v a2 s . com */ private long[] getCallIds(final Cursor cursor, final int groupSize) { // We want to restore the position in the cursor at the end. int startingPosition = cursor.getPosition(); long[] ids = new long[groupSize]; // Copy the ids of the rows in the group. for (int index = 0; index < groupSize; ++index) { ids[index] = cursor.getLong(CallLogQuery.ID); cursor.moveToNext(); } cursor.moveToPosition(startingPosition); return ids; }
From source file:com.saarang.samples.apps.iosched.ui.SessionDetailActivity.java
private void onSpeakersQueryComplete(Cursor cursor) { mSpeakersCursor = true;//from www . ja v a 2 s .c o m final ViewGroup speakersGroup = (ViewGroup) findViewById( com.saarang.samples.apps.iosched.R.id.session_speakers_block); // Remove all existing speakers (everything but first child, which is the header) for (int i = speakersGroup.getChildCount() - 1; i >= 1; i--) { speakersGroup.removeViewAt(i); } final LayoutInflater inflater = getLayoutInflater(); boolean hasSpeakers = false; cursor.moveToPosition(-1); // move to just before first record while (cursor.moveToNext()) { final String speakerName = cursor.getString(SpeakersQuery.SPEAKER_NAME); if (TextUtils.isEmpty(speakerName)) { continue; } final String speakerImageUrl = cursor.getString(SpeakersQuery.SPEAKER_IMAGE_URL); final String speakerCompany = cursor.getString(SpeakersQuery.SPEAKER_COMPANY); final String speakerUrl = cursor.getString(SpeakersQuery.SPEAKER_URL); final String speakerAbstract = cursor.getString(SpeakersQuery.SPEAKER_ABSTRACT); String speakerHeader = speakerName; if (!TextUtils.isEmpty(speakerCompany)) { speakerHeader += ", " + speakerCompany; } final View speakerView = inflater.inflate(com.saarang.samples.apps.iosched.R.layout.speaker_detail, speakersGroup, false); final TextView speakerHeaderView = (TextView) speakerView .findViewById(com.saarang.samples.apps.iosched.R.id.speaker_header); final ImageView speakerImageView = (ImageView) speakerView .findViewById(com.saarang.samples.apps.iosched.R.id.speaker_image); final TextView speakerAbstractView = (TextView) speakerView .findViewById(com.saarang.samples.apps.iosched.R.id.speaker_abstract); if (!TextUtils.isEmpty(speakerImageUrl) && mSpeakersImageLoader != null) { mSpeakersImageLoader.loadImage(speakerImageUrl, speakerImageView); } speakerHeaderView.setText(speakerHeader); speakerImageView.setContentDescription( getString(com.saarang.samples.apps.iosched.R.string.speaker_googleplus_profile, speakerHeader)); UIUtils.setTextMaybeHtml(speakerAbstractView, speakerAbstract); if (!TextUtils.isEmpty(speakerUrl)) { speakerImageView.setEnabled(true); speakerImageView.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { String number = "tel:" + speakerUrl.trim(); Intent callIntent = new Intent(Intent.ACTION_CALL, Uri.parse(number)); startActivity(callIntent); /*Intent speakerProfileIntent = new Intent(Intent.ACTION_VIEW, Uri.parse(speakerUrl)); speakerProfileIntent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_WHEN_TASK_RESET); UIUtils.preferPackageForIntent(SessionDetailActivity.this, speakerProfileIntent, UIUtils.GOOGLE_PLUS_PACKAGE_NAME); startActivity(speakerProfileIntent);*/ } }); } else { speakerImageView.setEnabled(true); speakerImageView.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { Toast.makeText(SessionDetailActivity.this, "Sorry, No number found for this person. Call the other coordinator", Toast.LENGTH_SHORT).show(); /*Intent speakerProfileIntent = new Intent(Intent.ACTION_VIEW, Uri.parse(speakerUrl)); speakerProfileIntent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_WHEN_TASK_RESET); UIUtils.preferPackageForIntent(SessionDetailActivity.this, speakerProfileIntent, UIUtils.GOOGLE_PLUS_PACKAGE_NAME); startActivity(speakerProfileIntent);*/ } }); } speakersGroup.addView(speakerView); hasSpeakers = true; mHasSummaryContent = true; } speakersGroup.setVisibility(hasSpeakers ? View.VISIBLE : View.GONE); updateEmptyView(); }
From source file:com.elpstudio.player.EqualizerActivity.java
/** * Builds the "Load Preset" dialog. Does not call the show() method, so this * should be done manually after calling this method. * //ww w .j a v a 2 s .c o m * @return A fully built AlertDialog reference. */ private AlertDialog buildLoadPresetDialog() { AlertDialog.Builder builder = new AlertDialog.Builder(this); //Get a cursor with the list of EQ presets. final Cursor cursor = mApp.getDBAccessHelper().getAllEQPresets(); //Set the dialog title. builder.setTitle("Load Preset"); builder.setCursor(cursor, new DialogInterface.OnClickListener() { @SuppressWarnings("unchecked") @Override public void onClick(DialogInterface dialog, int which) { cursor.moveToPosition(which); //Close the dialog. dialog.dismiss(); //Pass on the equalizer values to the appropriate fragment. fiftyHertzLevel = cursor.getInt(cursor.getColumnIndex(DBAccessHelper.EQ_50_HZ)); oneThirtyHertzLevel = cursor.getInt(cursor.getColumnIndex(DBAccessHelper.EQ_130_HZ)); threeTwentyHertzLevel = cursor.getInt(cursor.getColumnIndex(DBAccessHelper.EQ_320_HZ)); eightHundredHertzLevel = cursor.getInt(cursor.getColumnIndex(DBAccessHelper.EQ_800_HZ)); twoKilohertzLevel = cursor.getInt(cursor.getColumnIndex(DBAccessHelper.EQ_2000_HZ)); fiveKilohertzLevel = cursor.getInt(cursor.getColumnIndex(DBAccessHelper.EQ_5000_HZ)); twelvePointFiveKilohertzLevel = cursor.getInt(cursor.getColumnIndex(DBAccessHelper.EQ_12500_HZ)); virtualizerLevel = cursor.getShort(cursor.getColumnIndex(DBAccessHelper.VIRTUALIZER)); bassBoostLevel = cursor.getShort(cursor.getColumnIndex(DBAccessHelper.BASS_BOOST)); reverbSetting = cursor.getShort(cursor.getColumnIndex(DBAccessHelper.REVERB)); //Save the new equalizer settings to the DB. @SuppressWarnings({ "rawtypes" }) AsyncTask task = new AsyncTask() { @Override protected Object doInBackground(Object... arg0) { setEQValuesForSong(Music.musicService.currentSong.getId() + ""); return null; } @Override public void onPostExecute(Object result) { super.onPostExecute(result); //Reinitialize the UI elements to apply the new equalizer settings. new AsyncInitSlidersTask().execute(); } }; task.execute(); if (cursor != null) cursor.close(); } }, DBAccessHelper.PRESET_NAME); return builder.create(); }
From source file:com.dsdar.thosearoundme.util.MemberAddContactsListFragment.java
@Override public void onItemClick(AdapterView<?> parent, View v, int position, long id) { // Gets the Cursor object currently bound to the ListView final Cursor cursor = mAdapter.getCursor(); Contact aContactToBeRemoved = null;//w ww. j a v a2 s. c om String aContactCursorId; String aEmailId = null; String aPhoneNumber = null; boolean isExist = false; // Moves to the Cursor row corresponding to the ListView item that was // clicked cursor.moveToPosition(position); // Creates a contact lookup Uri from contact ID and lookup_key final Uri uri = Contacts.getLookupUri(cursor.getLong(ContactsQuery.ID), cursor.getString(ContactsQuery.LOOKUP_KEY)); // Notifies the parent activity that the user selected a contact. In a // two-pane layout, the // parent activity loads a ContactDetailFragment that displays the // details for the selected // contact. In a single-pane layout, the parent activity starts a new // activity that // displays contact details in its own Fragment. // niaz checking Log.d("positionI", String.valueOf(position)); CheckedTextView aCheckedTV = (CheckedTextView) v.findViewById(android.R.id.text1); mOnContactSelectedListener.onContactSelected(uri); HashMap<Integer, Boolean> aHashMap = new HashMap<Integer, Boolean>(); aHashMap.put(position, true); final Uri aContactUri = Contacts.getLookupUri(cursor.getLong(ContactsQuery.ID), cursor.getString(ContactsQuery.LOOKUP_KEY)); String aName = cursor.getString(ContactsQuery.DISPLAY_NAME); TextView textName = (TextView) v.findViewById(R.id.phone); if (textName.getText() != null) { Log.d("FINAL", textName.getText().toString()); aPhoneNumber = textName.getText().toString(); // Toast.makeText(itsContext, "Contact Addded Successfully !", // Toast.LENGTH_LONG).show(); // Cursor aContactCursor = itsContext.getContentResolver().query( // aContactUri, null, null, null, null); // if (aContactCursor.moveToFirst()) { // int idx = cursor.getColumnIndex(ContactsContract.Contacts._ID); // aContactCursorId = cursor.getString(idx); // int aNameIdx = aContactCursor // .getColumnIndex(ContactsContract.Contacts.HAS_PHONE_NUMBER); // // // // aEmailId = cursor.getString(ContactsQuery.LOOKUP_KEY); // // aPhoneNumber = cursor.getString(ContactsQuery.ID); // // Commented by Niaz for Multiple phone number // } JSONObject aContactJSONObject; // Notifies the parent activity that the user selected a contact. In // a two-pane layout, the // parent activity loads a ContactDetailFragment that displays the // details for the selected // contact. In a single-pane layout, the parent activity starts a // new activity that // displays contact details in its own Fragment. // aEmailId = "qwe"; // aPhoneNumber = "1234"; if (checkedTvStates.contains(aHashMap)) { checkedTvStates.remove(aHashMap); aContactToBeRemoved = new Contact(); aContactToBeRemoved.setEmail(aEmailId); aContactToBeRemoved.setName(aName); aContactToBeRemoved.setPhoneNumber(aPhoneNumber); aCheckedTV.setChecked(false); } else { checkedTvStates.add(aHashMap); aCheckedTV.setChecked(true); Contact aContact = new Contact(); aContact.setName(aName); aContact.setEmail(aEmailId); aContact.setPhoneNumber(aPhoneNumber); itsContactsList.add(aContact); } if (aContactToBeRemoved != null) { itsContactsList.remove(aContactToBeRemoved); } // aCheckBox.setButtonDrawable(R.drawable.checkbox_notify); try { aContactJSONObject = new JSONObject(); aMembersArray = new JSONArray(); for (int index = 0; index < itsContactsList.size(); index++) { aContactJSONObject = new JSONObject(); aContactJSONObject.put("emailId", itsContactsList.get(index).getEmail()); aContactJSONObject.put("phone", itsContactsList.get(index).getPhoneNumber()); aContactJSONObject.put("name", itsContactsList.get(index).getName()); aMembersArray.put(aContactJSONObject); } } catch (JSONException e) { Log.e("JsonException", "Json Exception occured ", e); } catch (Exception e) { Log.e("Exception", "Exception occured ", e); } // If two-pane layout sets the selected item to checked so it // remains // highlighted. In a // single-pane layout a new activity is started so this is not // needed. if (mIsTwoPaneLayout) { getListView().setItemChecked(position, true); } } else { Toast.makeText(itsContext, "Contact Not Addded! The Contact you selected does not have a Phone Number", Toast.LENGTH_LONG).show(); } }
From source file:cm.aptoide.com.actionbarsherlock.widget.SearchView.java
/** * Query rewriting./* w w w. j a v a 2 s. com*/ */ private void rewriteQueryFromSuggestion(int position) { CharSequence oldQuery = mQueryTextView.getText(); Cursor c = mSuggestionsAdapter.getCursor(); if (c == null) { return; } if (c.moveToPosition(position)) { // Get the new query from the suggestion. CharSequence newQuery = mSuggestionsAdapter.convertToString(c); if (newQuery != null) { // The suggestion rewrites the query. // Update the text field, without getting new suggestions. setQuery(newQuery); } else { // The suggestion does not rewrite the query, restore the user's query. setQuery(oldQuery); } } else { // We got a bad position, restore the user's query. setQuery(oldQuery); } }
From source file:com.aniruddhc.acemusic.player.EqualizerActivity.EqualizerActivity.java
/** * Builds the "Load Preset" dialog. Does not call the show() method, so this * should be done manually after calling this method. * //from ww w . j a v a 2 s. co m * @return A fully built AlertDialog reference. */ private AlertDialog buildLoadPresetDialog() { AlertDialog.Builder builder = new AlertDialog.Builder(this); //Get a cursor with the list of EQ presets. final Cursor cursor = mApp.getDBAccessHelper().getAllEQPresets(); //Set the dialog title. builder.setTitle(R.string.load_preset); builder.setCursor(cursor, new DialogInterface.OnClickListener() { @SuppressWarnings("unchecked") @Override public void onClick(DialogInterface dialog, int which) { cursor.moveToPosition(which); //Close the dialog. dialog.dismiss(); //Pass on the equalizer values to the appropriate fragment. fiftyHertzLevel = cursor.getInt(cursor.getColumnIndex(DBAccessHelper.EQ_50_HZ)); oneThirtyHertzLevel = cursor.getInt(cursor.getColumnIndex(DBAccessHelper.EQ_130_HZ)); threeTwentyHertzLevel = cursor.getInt(cursor.getColumnIndex(DBAccessHelper.EQ_320_HZ)); eightHundredHertzLevel = cursor.getInt(cursor.getColumnIndex(DBAccessHelper.EQ_800_HZ)); twoKilohertzLevel = cursor.getInt(cursor.getColumnIndex(DBAccessHelper.EQ_2000_HZ)); fiveKilohertzLevel = cursor.getInt(cursor.getColumnIndex(DBAccessHelper.EQ_5000_HZ)); twelvePointFiveKilohertzLevel = cursor.getInt(cursor.getColumnIndex(DBAccessHelper.EQ_12500_HZ)); virtualizerLevel = cursor.getShort(cursor.getColumnIndex(DBAccessHelper.VIRTUALIZER)); bassBoostLevel = cursor.getShort(cursor.getColumnIndex(DBAccessHelper.BASS_BOOST)); reverbSetting = cursor.getShort(cursor.getColumnIndex(DBAccessHelper.REVERB)); //Save the new equalizer settings to the DB. @SuppressWarnings({ "rawtypes" }) AsyncTask task = new AsyncTask() { @Override protected Object doInBackground(Object... arg0) { setEQValuesForSong(mApp.getService().getCurrentSong().getId()); return null; } @Override public void onPostExecute(Object result) { super.onPostExecute(result); //Reinitialize the UI elements to apply the new equalizer settings. new AsyncInitSlidersTask().execute(); } }; task.execute(); if (cursor != null) cursor.close(); } }, DBAccessHelper.PRESET_NAME); return builder.create(); }
From source file:android.support.v7.widget.SearchView.java
/** * Query rewriting./*from w w w. j a va2s . c om*/ */ private void rewriteQueryFromSuggestion(int position) { CharSequence oldQuery = mSearchSrcTextView.getText(); Cursor c = mSuggestionsAdapter.getCursor(); if (c == null) { return; } if (c.moveToPosition(position)) { // Get the new query from the suggestion. CharSequence newQuery = mSuggestionsAdapter.convertToString(c); if (newQuery != null) { // The suggestion rewrites the query. // Update the text field, without getting new suggestions. setQuery(newQuery); } else { // The suggestion does not rewrite the query, restore the user's query. setQuery(oldQuery); } } else { // We got a bad position, restore the user's query. setQuery(oldQuery); } }
From source file:android.support.content.InMemoryCursor.java
/** * @param cursor source of data to copy. Ownership is reserved to the called, meaning * we won't ever close it. *//* w ww. ja v a 2s. c o m*/ InMemoryCursor(Cursor cursor, int offset, int length, int disposition) { checkArgument(offset < cursor.getCount()); // NOTE: The cursor could simply be saved to a field, but we choose to wrap // in a dedicated relay class to avoid hanging directly onto a reference // to the cursor...so future authors are not enticed to think there's // a live link between the delegate cursor and this cursor. mObserverRelay = new ObserverRelay(cursor); mColumnNames = cursor.getColumnNames(); mRowCount = Math.min(length, cursor.getCount() - offset); int numColumns = cursor.getColumnCount(); mExtras = ContentPager.buildExtras(cursor.getExtras(), cursor.getCount(), disposition); mColumnType = new int[numColumns]; mTypedColumnIndex = new int[NUM_TYPES][numColumns]; mColumnTypeCount = new int[NUM_TYPES]; if (!cursor.moveToFirst()) { throw new RuntimeException("Can't position cursor to first row."); } for (int col = 0; col < numColumns; col++) { int type = cursor.getType(col); mColumnType[col] = type; mTypedColumnIndex[type][col] = mColumnTypeCount[type]++; } mLongs = new long[mRowCount * mColumnTypeCount[FIELD_TYPE_INTEGER]]; mDoubles = new double[mRowCount * mColumnTypeCount[FIELD_TYPE_FLOAT]]; mBlobs = new byte[mRowCount * mColumnTypeCount[FIELD_TYPE_BLOB]][]; mStrings = new String[mRowCount * mColumnTypeCount[FIELD_TYPE_STRING]]; for (int row = 0; row < mRowCount; row++) { if (!cursor.moveToPosition(offset + row)) { throw new RuntimeException("Unable to position cursor."); } // Now copy data from the row into primitive arrays. for (int col = 0; col < mColumnType.length; col++) { int type = mColumnType[col]; int position = getCellPosition(row, col, type); switch (type) { case FIELD_TYPE_NULL: throw new UnsupportedOperationException("Not implemented."); case FIELD_TYPE_INTEGER: mLongs[position] = cursor.getLong(col); break; case FIELD_TYPE_FLOAT: mDoubles[position] = cursor.getDouble(col); break; case FIELD_TYPE_BLOB: mBlobs[position] = cursor.getBlob(col); break; case FIELD_TYPE_STRING: mStrings[position] = cursor.getString(col); break; } } } }