List of usage examples for android.database Cursor moveToPosition
boolean moveToPosition(int position);
From source file:net.benmoran.affectsampler.AffectSerializer.java
public JSONArray toJSONArray() throws JSONException { Uri samples = AffectSamples.CONTENT_URI; String[] projection = new String[] { AffectSamples.COMMENT, AffectSamples.SCHEDULED_DATE, AffectSamples.CREATED_DATE, AffectSamples.EMOTION, AffectSamples.INTENSITY }; Cursor cursor = mContentResolver.query(samples, projection, null, null, AffectSamples.CREATED_DATE + " ASC"); JSONArray arr = new JSONArray(); int emIndex = cursor.getColumnIndex(AffectSamples.EMOTION); int inIndex = cursor.getColumnIndex(AffectSamples.INTENSITY); int cdIndex = cursor.getColumnIndex(AffectSamples.CREATED_DATE); int sdIndex = cursor.getColumnIndex(AffectSamples.SCHEDULED_DATE); int coIndex = cursor.getColumnIndex(AffectSamples.COMMENT); for (cursor.moveToPosition(0); !cursor.isLast(); cursor.moveToNext()) { JSONObject o = new JSONObject(); o.put(AffectSamples.EMOTION, cursor.getDouble(emIndex)); o.put(AffectSamples.INTENSITY, cursor.getDouble(inIndex)); if (cursor.getLong(sdIndex) > 0) { o.put(AffectSamples.SCHEDULED_DATE, cursor.getLong(sdIndex)); } else {// w ww. ja v a 2s. co m o.put(AffectSamples.SCHEDULED_DATE, null); } o.put(AffectSamples.CREATED_DATE, cursor.getLong(cdIndex)); if (cursor.getString(coIndex) != null) { o.put(AffectSamples.COMMENT, cursor.getString(coIndex)); } else { o.put(AffectSamples.COMMENT, null); } arr.put(o); } cursor.close(); return arr; }
From source file:com.github.monxalo.android.widget.SectionCursorAdapter.java
@Override public View getView(int position, View convertView, ViewGroup parent) { int viewType = getItemViewType(position); if (viewType == TYPE_NORMAL) { Cursor c = (Cursor) getItem(position); if (c == null) { if (LOGV) Log.d(TAG, "getItem(" + position + ") = null"); return mLayoutInflater.inflate(mHeaderRes, parent, false); }/*from w w w .j a v a2s. c o m*/ final int mapCursorPos = getSectionForPosition(position); c.moveToPosition(mapCursorPos); return super.getView(mapCursorPos, convertView, parent); } else { ViewHolder holder = null; if (convertView == null) { if (LOGV) Log.v(TAG, "Creating new view for section"); convertView = newHeaderView(mContext, mCursor, parent); } bindHeaderView(convertView, mContext, mCursor, position); return convertView; } }
From source file:com.money.manager.ex.fragment.HomeFragment.java
@Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { if (container == null) { return null; }/*from w w w.ja v a 2s . c o m*/ // inflate layout View view = (LinearLayout) inflater.inflate(R.layout.fragment_main, container, false); // reference view into layout linearHome = (LinearLayout) view.findViewById(R.id.linearLayoutHome); linearWelcome = (ViewGroup) view.findViewById(R.id.linearLayoutWelcome); // add account button Button btnAddAccount = (Button) view.findViewById(R.id.buttonAddAccount); if (btnAddAccount != null) { btnAddAccount.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { Intent intent = new Intent(getActivity(), AccountListEditActivity.class); intent.setAction(Constants.INTENT_ACTION_INSERT); startActivity(intent); } }); } // link to dropbox Button btnLinkDropbox = (Button) view.findViewById(R.id.buttonLinkDropbox); if (btnLinkDropbox != null) { btnLinkDropbox.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { Intent intent = new Intent(getActivity(), PreferencesActivity.class); intent.putExtra(Constants.INTENT_REQUEST_PREFERENCES_SCREEN, PreferencesConstant.PREF_DROPBOX_HOWITWORKS); startActivity(intent); } }); } txtTotalAccounts = (TextView) view.findViewById(R.id.textViewTotalAccounts); lstAccountBills = (ListView) view.findViewById(R.id.listViewAccountBills); lstAccountBills.setOnItemClickListener(new OnItemClickListener() { @Override public void onItemClick(AdapterView<?> parent, View view, int position, long id) { MainActivity activity = (MainActivity) getActivity(); //Cursor cursor = ((CursorAdapter)lstAccountBills.getAdapter()).getCursor(); HeaderViewListAdapter headerViewListAdapter = (HeaderViewListAdapter) lstAccountBills.getAdapter(); AccountBillsAdapter accountBillsAdapter = (AccountBillsAdapter) headerViewListAdapter .getWrappedAdapter(); Cursor cursor = accountBillsAdapter.getCursor(); int accountId = -1; if (cursor != null && cursor.moveToPosition(position)) { accountId = cursor.getInt(cursor.getColumnIndex(QueryAccountBills.ACCOUNTID)); } // show account clicked if (activity != null && activity instanceof MainActivity) { activity.showFragmentAccount(position, accountId); } } }); // set highlight item if (getActivity() != null && getActivity() instanceof MainActivity) { if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.ICE_CREAM_SANDWICH) lstAccountBills.setSelector(R.color.holo_blue_light); lstAccountBills.setChoiceMode(ListView.CHOICE_MODE_SINGLE); //lstAccountBills.setSelection(ListView.INVALID_POSITION); } prgAccountBills = (ProgressBar) view.findViewById(R.id.progressAccountBills); return view; }
From source file:org.mariotaku.twidere.adapter.ParcelableActivitiesAdapter.java
@Override public long getItemId(int adapterPosition) { int dataPosition = adapterPosition - getActivityStartIndex(); if (dataPosition < 0 || dataPosition >= getActivityCount()) return RecyclerView.NO_ID; if (mData instanceof ObjectCursor) { final Cursor cursor = ((ObjectCursor) mData).getCursor(); if (!cursor.moveToPosition(dataPosition)) return -1; final ParcelableActivityCursorIndices indices = (ParcelableActivityCursorIndices) ((ObjectCursor) mData) .getIndices();/*from w ww. j a v a 2 s. c om*/ final UserKey accountKey = UserKey.valueOf(cursor.getString(indices.account_key)); final long timestamp = cursor.getLong(indices.timestamp); final long maxPosition = cursor.getLong(indices.max_position); final long minPosition = cursor.getLong(indices.min_position); return ParcelableActivity.calculateHashCode(accountKey, timestamp, maxPosition, minPosition); } return mData.get(dataPosition).hashCode(); }
From source file:org.mariotaku.twidere.adapter.ParcelableActivitiesAdapter.java
@Override public boolean isGapItem(int adapterPosition) { int dataPosition = adapterPosition - getActivityStartIndex(); final int activityCount = getActivityCount(); if (dataPosition < 0 || dataPosition >= activityCount) return false; // Don't show gap if it's last item if (dataPosition == activityCount - 1) { return false; }/*from www . j av a2 s . co m*/ if (mData instanceof ObjectCursor) { final Cursor cursor = ((ObjectCursor) mData).getCursor(); if (!cursor.moveToPosition(dataPosition)) return false; final ParcelableActivityCursorIndices indices = (ParcelableActivityCursorIndices) ((ObjectCursor) mData) .getIndices(); return cursor.getShort(indices.is_gap) == 1; } return mData.get(dataPosition).is_gap; }
From source file:com.andrew.apollo.ui.activities.SearchActivity.java
/** * {@inheritDoc}//from w ww .j a va 2 s.com */ @Override public void onItemClick(final AdapterView<?> parent, final View view, final int position, final long id) { Cursor cursor = mAdapter.getCursor(); cursor.moveToPosition(position); if (cursor.isBeforeFirst() || cursor.isAfterLast()) { return; } // Get the MIME type final String mimeType = cursor.getString(cursor.getColumnIndexOrThrow(MediaStore.Audio.Media.MIME_TYPE)); // If it's an artist, open the artist profile if ("artist".equals(mimeType)) { NavUtils.openArtistProfile(this, cursor.getString(cursor.getColumnIndexOrThrow(MediaStore.Audio.Artists.ARTIST))); } else if ("album".equals(mimeType)) { // If it's an album, open the album profile NavUtils.openAlbumProfile(this, cursor.getString(cursor.getColumnIndexOrThrow(MediaStore.Audio.Albums.ALBUM)), cursor.getString(cursor.getColumnIndexOrThrow(MediaStore.Audio.Albums.ARTIST))); } else if (position >= 0 && id >= 0) { // If it's a song, play it and leave final long[] list = new long[] { id }; MusicUtils.playAll(this, list, 0, false); } // Close it up cursor.close(); cursor = null; // All done finish(); }
From source file:com.android.mail.photo.MailPhotoViewController.java
/** * Share all of the attachments in the cursor. *///w w w. j av a2s . com private void shareAllAttachments() { Cursor cursor = getCursorAtProperPosition(); if (cursor == null) { return; } ArrayList<Parcelable> uris = new ArrayList<Parcelable>(); int i = -1; while (cursor.moveToPosition(++i)) { uris.add(Utils.normalizeUri(new Attachment(cursor).contentUri)); } mActionHandler.shareAttachments(uris); }
From source file:com.enadein.carlogbook.core.BaseActivity.java
public void showSelectCars(View v) { AlertDialog.Builder builder = new AlertDialog.Builder(this); final Cursor c = getContentResolver().query(ProviderDescriptor.Car.CONTENT_URI, null, null, null, null); builder.setTitle(R.string.select_car_dialog).setCursor(c, new DialogInterface.OnClickListener() { @Override//from w w w . ja va 2s. c o m public void onClick(DialogInterface dialogInterface, int pos) { c.moveToPosition(pos); long id = c.getLong(c.getColumnIndex(ProviderDescriptor.Car.Cols._ID)); } }, ProviderDescriptor.Car.Cols.NAME); builder.create().show(); }
From source file:eu.inmite.apps.smsjizdenka.adapter.TicketsAdapter.java
/** * Tries to delete ticket either from swipe-to-dismiss or button. * * @return Pair of ticket id and previous status or null if it wasn't deleted. *//*w w w . j a v a2 s. c o m*/ public Pair<Long, Integer> archiveTicket(int position) { Cursor cursor = getCursor(); if (cursor.isClosed()) { return null; } cursor.moveToPosition(position); long id; try { id = cursor.getLong(iId); } catch (CursorIndexOutOfBoundsException e) { return null; } final Time validTo = FormatUtil.timeFrom3339(cursor.getString(iValidTo)); int status = getValidityStatus(cursor.getInt(iStatus), validTo); if (status == Tickets.STATUS_EXPIRED) { ContentValues values = new ContentValues(); values.put(TicketProvider.Tickets.STATUS, TicketProvider.Tickets.STATUS_DELETED); c.getContentResolver().update(ContentUris.withAppendedId(TicketProvider.Tickets.CONTENT_URI, id), values, null, null); // I had to call this deprecated method, because it needs to run synchronously. In asynchronous case, previous tickets blinks during swipe to dismiss. //noinspection deprecation getCursor().requery(); return new Pair<Long, Integer>(id, status); } else { return null; } }
From source file:com.android.ex.photo.PhotoViewActivity.java
/** * Utility method that will return the cursor that contains the data * at the current position so that it refers to the current image on screen. * @return the cursor at the current position or * null if no cursor exists or if the {@link PhotoViewPager} is null. *//*from www .jav a2 s. c om*/ public Cursor getCursorAtProperPosition() { if (mViewPager == null) { return null; } final int position = mViewPager.getCurrentItem(); final Cursor cursor = mAdapter.getCursor(); if (cursor == null) { return null; } cursor.moveToPosition(position); return cursor; }