List of usage examples for android.database Cursor getPosition
int getPosition();
From source file:com.nonninz.robomodel.RoboManager.java
public long[] getSelectedModelIds(String selection, String[] selectionArgs, String groupBy, String having, String orderBy) {//from w ww .j a va 2s .c om final SQLiteDatabase db = mDatabaseManager.openOrCreateDatabase(getDatabaseName()); final String columns[] = new String[] { BaseColumns._ID }; Cursor query; /* * Try the query. If the Table doesn't exist, fix the DB and re-run the query. */ try { query = db.query(getTableName(), columns, selection, selectionArgs, groupBy, having, orderBy); } catch (final SQLiteException e) { prepareTable(db); query = db.query(getTableName(), columns, selection, selectionArgs, groupBy, having, orderBy); } final int columnIndex = query.getColumnIndex(BaseColumns._ID); final long result[] = new long[query.getCount()]; for (query.moveToFirst(); !query.isAfterLast(); query.moveToNext()) { result[query.getPosition()] = query.getLong(columnIndex); } return result; }
From source file:com.android.calendar.selectcalendars.SelectSyncedCalendarsMultiAccountAdapter.java
@Override protected Cursor getChildrenCursor(Cursor groupCursor) { int accountColumn = groupCursor.getColumnIndexOrThrow(Calendars.ACCOUNT_NAME); int accountTypeColumn = groupCursor.getColumnIndexOrThrow(Calendars.ACCOUNT_TYPE); String account = groupCursor.getString(accountColumn); String accountType = groupCursor.getString(accountTypeColumn); //Get all the calendars for just this account. Cursor childCursor = mChildrenCursors.get(accountType + "#" + account); new RefreshCalendars(groupCursor.getPosition(), account, accountType).run(); return childCursor; }
From source file:com.android.mms.ui.ConversationList.java
@Override public boolean onContextItemSelected(MenuItem item) { Cursor cursor = mListAdapter.getCursor(); if (cursor != null && cursor.getPosition() >= 0) { Conversation conv = Conversation.from(ConversationList.this, cursor); long threadId = conv.getThreadId(); switch (item.getItemId()) { case MENU_DELETE: { confirmDeleteThread(threadId, mQueryHandler); break; }// w w w . j a va 2s. c o m case MENU_VIEW: { openThread(threadId); break; } case MENU_VIEW_CONTACT: { Contact contact = conv.getRecipients().get(0); Intent intent = new Intent(Intent.ACTION_VIEW, contact.getUri()); intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_WHEN_TASK_RESET); startActivity(intent); break; } case MENU_ADD_TO_CONTACTS: { String address = conv.getRecipients().get(0).getNumber(); startActivity(createAddContactIntent(address)); break; } default: break; } } return super.onContextItemSelected(item); }
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 ww 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); } }
From source file:org.mariotaku.twidere.activity.AccountSelectorActivity.java
@Override public void onLoadFinished(final Loader<Cursor> loader, final Cursor cursor) { mAdapter.swapCursor(cursor);// ww w. j a v a 2 s .c o m final SparseBooleanArray checked = new SparseBooleanArray(); cursor.moveToFirst(); if (mSelectedIds.size() == 0) { if (mAllowSelectNone) return; while (!cursor.isAfterLast()) { final boolean is_activated = cursor .getInt(cursor.getColumnIndexOrThrow(Accounts.IS_ACTIVATED)) == 1; final long user_id = cursor.getLong(cursor.getColumnIndexOrThrow(Accounts.ACCOUNT_ID)); if (is_activated) { mSelectedIds.add(user_id); } mAdapter.setItemChecked(cursor.getPosition(), is_activated); cursor.moveToNext(); } } else { while (!cursor.isAfterLast()) { final long user_id = cursor.getLong(cursor.getColumnIndexOrThrow(Accounts.ACCOUNT_ID)); if (mSelectedIds.contains(user_id)) { checked.put(cursor.getPosition(), true); mAdapter.setItemChecked(cursor.getPosition(), true); } cursor.moveToNext(); } } }
From source file:com.android.mms.ui.MailBoxMessageContent.java
private void initUi() { setProgressBarIndeterminateVisibility(true); mScaleDetector = new ScaleGestureDetector(this, new MyScaleListener()); Cursor cursor = moveCursorToCurrentMsg(mCursor, mMsgId); if (cursor != null) { mPagerAdapter = new MessageDetailAdapter(this, cursor); mPagerAdapter.setScaleTextList(mSlidePaperItemTextViews); mContentPager = (ViewPager) findViewById(R.id.details_view_pager); mContentPager.setAdapter(mPagerAdapter); mContentPager.setCurrentItem(cursor.getPosition()); }//w ww . j av a2s . c o m ActionBar actionBar = getActionBar(); actionBar.setDisplayHomeAsUpEnabled(true); }
From source file:org.thialfihar.android.apg.ui.adapter.ViewKeyUserIdsAdapter.java
@Override public void bindView(View view, Context context, Cursor cursor) { TextView vRank = (TextView) view.findViewById(R.id.rank); TextView vUserId = (TextView) view.findViewById(R.id.userId); TextView vAddress = (TextView) view.findViewById(R.id.address); vRank.setText(Integer.toString(cursor.getInt(mIndexRank))); String[] userId = PgpKeyHelper.splitUserId(cursor.getString(mIndexUserId)); if (userId[0] != null) { vUserId.setText(userId[0]);//from w w w. j a v a 2s. c om } else { vUserId.setText(R.string.user_id_no_name); } vAddress.setText(userId[1]); // don't care further if checkboxes aren't shown if (mCheckStates == null) { return; } final CheckBox vCheckBox = (CheckBox) view.findViewById(R.id.checkBox); final int position = cursor.getPosition(); vCheckBox.setClickable(false); vCheckBox.setChecked(mCheckStates.get(position)); vCheckBox.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() { @Override public void onCheckedChanged(CompoundButton compoundButton, boolean b) { mCheckStates.set(position, b); } }); view.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { vCheckBox.toggle(); } }); }
From source file:org.jraf.android.hellomundo.app.pickwebcam.WebcamAdapter.java
@Override public void bindView(View view, Context context, Cursor cursor) { WebcamCursor c = (WebcamCursor) cursor; long id = c.getId(); TextView txtName = (TextView) ViewHolder.get(view, R.id.txtName); String name = c.getName();//from ww w. j av a2 s .c o m txtName.setText(name); WebcamType type = c.getType(); boolean isUserWebcam = type != null && type == WebcamType.USER; // Extend View conExtended = ViewHolder.get(view, R.id.conExtended); conExtended.setTag(id); View btnExtend = ViewHolder.get(view, R.id.btnExtend); btnExtend.setTag(conExtended); if (cursor.getPosition() == cursor.getCount() - 1) { btnExtend.setTag(R.id.lastItem, true); } else { btnExtend.setTag(R.id.lastItem, false); } btnExtend.setOnClickListener(mExtendOnClickListener); LayoutParams layoutParams = conExtended.getLayoutParams(); if (mExtendedIds.contains(id)) { layoutParams.height = mExtendedHeight; } else { layoutParams.height = 0; } // Thumbnail ImageView imgThumbnail = ViewHolder.get(view, R.id.imgThumbnail); if (isUserWebcam) { imgThumbnail.setImageResource(R.drawable.ic_thumbnail_user_defined); } else { imgThumbnail.setImageResource(0); Picasso picasso = Picasso.with(context); // picasso.setDebugging(true); picasso.load(c.getThumbUrl()) .resizeDimen(R.dimen.pickWebcam_item_imgThumbnail_widthHeight, R.dimen.pickWebcam_item_imgThumbnail_widthHeight) .centerCrop().placeholder(R.drawable.ic_thumbnail_bg).into(imgThumbnail); } // Location & time TextView txtLocationAndTime = ViewHolder.get(view, R.id.txtLocationAndTime); if (isUserWebcam) { txtLocationAndTime.setText(R.string.common_userDefined); } else { String location = c.getLocation(); String publicId = c.getPublicId(); boolean specialCam = Constants.SPECIAL_CAMS.contains(publicId); if (!specialCam) { location += " - " + getLocalTime(context, c.getTimezone()); } txtLocationAndTime.setText(location); } // Source url TextView txtSourceUrl = ViewHolder.get(view, R.id.txtSourceUrl); String sourceUrl; if (isUserWebcam) { sourceUrl = c.getUrl(); sourceUrl = sourceUrl.substring("http://".length()); int slashIdx = sourceUrl.indexOf('/'); if (slashIdx != -1) { sourceUrl = sourceUrl.substring(0, slashIdx); } } else { sourceUrl = c.getSourceUrl(); } txtSourceUrl.setText(context.getString(R.string.pickWebcam_source, sourceUrl)); txtSourceUrl.setTag(sourceUrl); txtSourceUrl.setOnClickListener(mSourceOnClickListener); // Exclude from random Boolean excludeRandom = c.getExcludeRandom(); boolean excludedFromRandom = excludeRandom != null && excludeRandom; View btnExcludeFromRandom = ViewHolder.get(view, R.id.btnExcludeFromRandom); btnExcludeFromRandom.setSelected(excludedFromRandom); btnExcludeFromRandom.setTag(id); btnExcludeFromRandom.setOnClickListener(mExcludeFromRandomOnClickListener); ImageView imgExcludedFromRandom = ViewHolder.get(view, R.id.imgExcludedFromRandom); if (excludedFromRandom) { imgExcludedFromRandom.setVisibility(View.VISIBLE); } else { imgExcludedFromRandom.setVisibility(View.GONE); } // Show on map / delete View btnShowOnMap = ViewHolder.get(view, R.id.btnShowOnMap); ImageView imgShowOnMap = ViewHolder.get(view, R.id.imgShowOnMap); TextView txtShowOnMap = ViewHolder.get(view, R.id.txtShowOnMap); if (isUserWebcam) { imgShowOnMap.setImageResource(R.drawable.ic_ext_delete); txtShowOnMap.setText(R.string.pickWebcam_delete); btnShowOnMap.setTag(id); btnShowOnMap.setOnClickListener(mDeleteOnClickListener); } else { imgShowOnMap.setImageResource(R.drawable.ic_ext_show_on_map); txtShowOnMap.setText(R.string.pickWebcam_showOnMap); String coordinates = c.getCoordinates(); if (coordinates == null) { btnShowOnMap.setEnabled(false); } else { btnShowOnMap.setEnabled(true); btnShowOnMap.setTag(R.id.coordinates, coordinates); btnShowOnMap.setTag(R.id.name, name); btnShowOnMap.setOnClickListener(mShowOnMapOnClickListener); } } View btnPreview = ViewHolder.get(view, R.id.btnPreview); btnPreview.setTag(id); btnPreview.setOnClickListener(mPreviewOnClickListener); // Current webcam View conMainItem = ViewHolder.get(view, R.id.conMainItem); conMainItem.setSelected(id == mCurrentWebcamId); }
From source file:org.sufficientlysecure.keychain.ui.widget.CertifyKeySpinner.java
@Override public void onLoadFinished(Loader<Cursor> loader, Cursor data) { super.onLoadFinished(loader, data); if (loader.getId() == LOADER_ID) { mIndexHasCertify = data.getColumnIndex(KeychainContract.KeyRings.HAS_CERTIFY); // If:/* w ww . j av a 2 s.c om*/ // - no key has been pre-selected (e.g. by SageSlinger) // - there are actually keys (not just "none" entry) // Then: // - select key that is capable of certifying, but only if there is only one key capable of it if (mPreSelectedKeyId == Constants.key.none && mAdapter.getCount() > 1) { // preselect if key can certify int selection = -1; while (data.moveToNext()) { if (!data.isNull(mIndexHasCertify)) { if (selection == -1) { selection = data.getPosition() + 1; mIsSingle = true; } else { // if selection is already set, we have more than one certify key! // get back to "none"! mIsSingle = false; selection = 0; } } } setSelection(selection); } } }
From source file:com.battlelancer.seriesguide.ui.EpisodesActivity.java
/** * Updates the episode list, using the current sorting. If a valid initial episode id is given * it will return its position in the created list. *//*from w w w . j a v a2 s . c om*/ private int updateEpisodeList(int initialEpisodeId) { Constants.EpisodeSorting sortOrder = DisplaySettings.getEpisodeSortOrder(this); Cursor episodeCursor = getContentResolver().query( Episodes.buildEpisodesOfSeasonWithShowUri(String.valueOf(mSeasonId)), new String[] { Episodes._ID, Episodes.NUMBER }, null, null, sortOrder.query()); ArrayList<Episode> episodeList = new ArrayList<>(); int startPosition = 0; if (episodeCursor != null) { while (episodeCursor.moveToNext()) { Episode ep = new Episode(); ep.episodeId = episodeCursor.getInt(0); if (ep.episodeId == initialEpisodeId) { startPosition = episodeCursor.getPosition(); } ep.episodeNumber = episodeCursor.getInt(1); ep.seasonNumber = mSeasonNumber; episodeList.add(ep); } episodeCursor.close(); } mEpisodes = episodeList; return startPosition; }