List of usage examples for android.database Cursor getPosition
int getPosition();
From source file:io.github.carlorodriguez.alarmon.MediaListView.java
protected void query(Uri contentUri, String nameColumn, String selection, int rowResId, String[] displayColumns, int[] resIDs) { this.nameColumn = nameColumn; final ArrayList<String> queryColumns = new ArrayList<>(displayColumns.length + 1); queryColumns.addAll(Arrays.asList(displayColumns)); // The ID column is required for the SimpleCursorAdapter. Make sure to // add it if it's not already there. if (!queryColumns.contains(BaseColumns._ID)) { queryColumns.add(BaseColumns._ID); }//from w ww.java2 s. c o m Cursor dbCursor; if (ContextCompat.checkSelfPermission(getContext(), Manifest.permission.READ_EXTERNAL_STORAGE) == PackageManager.PERMISSION_GRANTED) { dbCursor = getContext().getContentResolver().query(contentUri, queryColumns.toArray(new String[queryColumns.size()]), selection, null, sortOrder); } else { dbCursor = new MatrixCursor(queryColumns.toArray(new String[queryColumns.size()])); } if (staticCursor != null) { Cursor[] cursors = new Cursor[] { staticCursor, dbCursor }; cursor = new MergeCursor(cursors); } else { cursor = dbCursor; } manageCursor(cursor); this.contentUri = contentUri; final SimpleCursorAdapter adapter = new SimpleCursorAdapter(getContext(), rowResId, cursor, displayColumns, resIDs, 1); // Use a custom binder to highlight the selected element. adapter.setViewBinder(new ViewBinder() { @Override public boolean setViewValue(View view, Cursor cursor, int columnIndex) { if (view.getVisibility() == View.VISIBLE && view instanceof TextView) { TextView text = (TextView) view; if (isItemChecked(cursor.getPosition())) { text.setTypeface(Typeface.DEFAULT_BOLD); } else { text.setTypeface(Typeface.DEFAULT); } } // Let the default binder do the real work. return false; } }); setAdapter(adapter); setOnItemClickListener(this); }
From source file:com.udacity.movietimes.adapter.MovieDetailAdapter.java
@Override public void bindView(View view, final Context context, final Cursor cursor) { int viewType = getItemViewType(cursor.getPosition()); switch (viewType) { case VIEW_TYPE_MOVIE_BODY: { final MovieViewHolder viewHolder = (MovieViewHolder) view.getTag(); // Set the poster of the movie StringBuilder imagePath = new StringBuilder(MovieUrl.MOVIE_IMAGE_BASE_URL) .append(cursor.getString(COL_POSTER)); Picasso.with(context).load(imagePath.toString()).into(viewHolder.poster, new Callback.EmptyCallback() { @Override// w w w . j a v a2 s . c o m public void onError() { viewHolder.poster.setImageResource(R.drawable.no_poster); } }); // Set the title of the movie viewHolder.title.setText(cursor.getString(COL_TITLE)); // Set the favorite button ON/OFF updateFavoriteButton(viewHolder, context, cursor); // Set the Release date of the movie String date = MovieUtility.formatDate(cursor.getString(COL_RELEASE_DATE)); if (date != null) { viewHolder.releaseDate.setText(date); } // Set the Rating of the Movie viewHolder.rating.setRating((float) (Float.valueOf(cursor.getString(COL_RATING)) / 2.0)); // Set the Overview of the Movie viewHolder.overview.setText(cursor.getString(COL_OVERVIEW)); break; } case VIEW_TYPE_MOVIE_REVIEW: { ReviewVeiwHolder viewHolder = (ReviewVeiwHolder) view.getTag(); viewHolder.author.setText(cursor.getString(COL_AUTHOR_NAME)); viewHolder.review.setText(cursor.getString(COL_REVIEW_CONTENT)); break; } case VIEW_TYPE_MOVIE_TRAILER: { final TrailerVeiwHolder viewHolder = (TrailerVeiwHolder) view.getTag(); // Set the Trailer Image final String trailerKey = cursor.getString(COL_TRAILER_KEY); Uri.Builder mVedioUrl = Uri.parse(MovieUrl.MOVIE_VEDIO_BASE_URL).buildUpon().appendPath(trailerKey) .appendPath(MovieUrl.VEDIO_TN_SIZE); Picasso.with(mContext).load(mVedioUrl.toString()).into(viewHolder.trailerPic, new Callback.EmptyCallback() { @Override public void onSuccess() { viewHolder.trailerPic.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { try { Intent intent = YouTubeStandalonePlayer.createVideoIntent(activity, MovieConfig.GOOGLE_API_KEY, trailerKey); context.startActivity(intent); } catch (ActivityNotFoundException e) { Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse("http://www.youtube.com/watch?v=" + trailerKey)); context.startActivity(intent); } } }); } @Override public void onError() { super.onError(); viewHolder.trailerMsg.setText(R.string.noTrailer); } }); break; } } }
From source file:fr.eoit.activity.util.ItemListViewBinder.java
@Override public boolean setViewValue(View view, Cursor cursor, int columnIndex) { int viewId = view.getId(); numberOfElements = cursor.getCount(); currentPosition = cursor.getPosition(); switch (viewId) { case R.id.item_name: case R.id.ITEM_NAME: String value = cursor.getString(columnIndex); initName(view, value);/* ww w. j a v a2 s . c o m*/ break; case R.id.item_icon: case R.id.ITEM_ICON: id = cursor.getLong(columnIndex); initIcon(view, id); break; case R.id.item_quantity: case R.id.ITEM_QUANTITY: quantity = cursor.getLong(columnIndex); int ml = 0; int groupId = 0; if (cursor.getColumnIndex(Blueprint.COLUMN_NAME_ML) != -1) { ml = cursor.getInt(cursor.getColumnIndexOrThrow(Blueprint.COLUMN_NAME_ML)); } if (cursor.getColumnIndex(Item.COLUMN_NAME_GROUP_ID) != -1) { groupId = cursor.getInt(cursor.getColumnIndexOrThrow(Item.COLUMN_NAME_GROUP_ID)); } if (cursor.getColumnIndex(Prices.COLUMN_NAME_PRODUCE_PRICE) != -1) { price = cursor.getDouble(cursor.getColumnIndexOrThrow(Prices.COLUMN_NAME_PRODUCE_PRICE)); } initQuantity(id, view, quantity, ml, groupId, price); break; case R.id.ITEM_DMG_PER_JOB: float damagePerJob = cursor.getFloat(columnIndex); initDamagePerJob(view, damagePerJob); break; case R.id.warn_icon: case R.id.WARN_ICON: price = PricesUtils.getPriceOrNaN(cursor); initWarnIcon(view, price); break; case R.id.item_price: case R.id.ITEM_PRICE: addToTotalPrice(id, price, quantity); break; case R.id.item_volume: case R.id.ITEM_VOLUME: double volume = cursor.getDouble(columnIndex); addToTotalVolume(id, volume, quantity); break; default: throw new IllegalArgumentException("viewId : " + viewId); } return true; }
From source file:org.jamienicol.episodes.EpisodeActivity.java
private int getEpisodePositionFromId(Cursor episodesData, int id) { int position; episodesData.moveToPosition(-1);/*from w w w .ja v a 2 s.c o m*/ while (episodesData.moveToNext()) { int idColumnIndex = episodesData.getColumnIndexOrThrow(EpisodesTable.COLUMN_ID); if (id == episodesData.getInt(idColumnIndex)) { return episodesData.getPosition(); } } return 0; }
From source file:org.adaway.util.RedirectionCursorAdapter.java
/** * Bind cursor to view using the checkboxes *///from www. j a v a 2 s . c om @Override public void bindView(View v, Context context, Cursor cursor) { CheckBox cBox = (CheckBox) v.findViewById(R.id.checkbox_list_two_checkbox); TextView hostnameTextView = (TextView) v.findViewById(R.id.checkbox_list_two_text); TextView ipTextView = (TextView) v.findViewById(R.id.checkbox_list_two_subtext); if (cBox != null) { // bind cursor position to tag of list item int cursorPosition = cursor.getPosition(); cBox.setTag("checkbox_" + cursorPosition); hostnameTextView.setTag("hostname_" + cursorPosition); ipTextView.setTag("ip_" + cursorPosition); int enabledCol = cursor.getColumnIndexOrThrow(RedirectionList.ENABLED); String enabled = cursor.getString(enabledCol); if (Integer.parseInt(enabled) == 1) { cBox.setChecked(true); } else { cBox.setChecked(false); } // set hostname int hostnameCol = cursor.getColumnIndexOrThrow(RedirectionList.HOSTNAME); String hostname = cursor.getString(hostnameCol); hostnameTextView.setText(hostname); // set ip int ipCol = cursor.getColumnIndexOrThrow(RedirectionList.IP); String ip = cursor.getString(ipCol); ipTextView.setText(ip); } }
From source file:com.enadein.carlogbook.adapter.DataValueAdapter.java
@Override public void bindView(View view, Context context, Cursor cursor) { DataValueHolder setsHolder = (DataValueHolder) view.getTag(); int idIdx = cursor.getColumnIndex(ProviderDescriptor.DataValue.Cols._ID); int nameIdx = cursor.getColumnIndex(ProviderDescriptor.DataValue.Cols.NAME); String name = cursor.getString(nameIdx); int id = cursor.getInt(idIdx); setsHolder.nameView.setText(name);//from w w w . j av a2s . co m setsHolder.id = id; int pos = cursor.getPosition(); CommonUtils.runAnimation(mlastPos, pos, view, UnitFacade.animSize); mlastPos = pos; }
From source file:com.example.xyzreader.ui.articledetail.ArticleDetailActivity.java
@Override public void onLoadFinished(Loader<Cursor> loader, Cursor data) { Log.d(LOG_TAG, "onLoadFinished, data = " + data.toString()); mCursor = data;// w w w . ja va 2 s .com mSectionsPagerAdapter.notifyDataSetChanged(); for (data.moveToFirst(); !data.isAfterLast(); data.moveToNext()) { if (data.getLong(ArticleLoader.Query._ID) == mStartId) { final int position = data.getPosition(); mViewPager.setCurrentItem(position, false); break; } } }
From source file:cm.confide.ex.chips.RecipientAlternatesAdapter.java
@Override public void bindView(View view, Context context, Cursor cursor) { int position = cursor.getPosition(); TextView display = (TextView) view.findViewById(android.R.id.title); ImageView imageView = (ImageView) view.findViewById(android.R.id.icon); RecipientEntry entry = getRecipientEntry(position); if (position == 0) { display.setText(cursor.getString(Queries.Query.NAME)); display.setVisibility(View.VISIBLE); // TODO: see if this needs to be done outside the main thread // as it may be too slow to get immediately. imageView.setImageURI(entry.getPhotoThumbnailUri()); imageView.setVisibility(View.VISIBLE); } else {//from w ww . ja va2 s .c o m display.setVisibility(View.GONE); imageView.setVisibility(View.GONE); } TextView destination = (TextView) view.findViewById(android.R.id.text1); destination.setText(cursor.getString(Queries.Query.DESTINATION)); TextView destinationType = (TextView) view.findViewById(android.R.id.text2); if (destinationType != null) { destinationType.setText( mQuery.getTypeLabel(context.getResources(), cursor.getInt(Queries.Query.DESTINATION_TYPE), cursor.getString(Queries.Query.DESTINATION_LABEL)).toString().toUpperCase()); } }
From source file:org.adaway.util.HostsSourcesCursorAdapter.java
/** * Bind cursor to view using the checkboxes *//*from w ww .j av a 2 s. com*/ @Override public void bindView(View v, Context context, Cursor cursor) { CheckBox cBox = (CheckBox) v.findViewById(R.id.checkbox_list_two_checkbox); TextView hostnameTextView = (TextView) v.findViewById(R.id.checkbox_list_two_text); TextView lastModifiedTextView = (TextView) v.findViewById(R.id.checkbox_list_two_subtext); if (cBox != null) { // bind cursor position to tag of list item int cursorPosition = cursor.getPosition(); cBox.setTag("checkbox_" + cursorPosition); hostnameTextView.setTag("url_" + cursorPosition); lastModifiedTextView.setTag("last_modified_" + cursorPosition); int enabledCol = cursor.getColumnIndexOrThrow(HostsSources.ENABLED); String enabled = cursor.getString(enabledCol); if (Integer.parseInt(enabled) == 1) { cBox.setChecked(true); } else { cBox.setChecked(false); } // set hostname int urlCol = cursor.getColumnIndex(HostsSources.URL); String url = cursor.getString(urlCol); hostnameTextView.setText(url); // set last modified int lastModifiedLocalCol = cursor.getColumnIndexOrThrow(HostsSources.LAST_MODIFIED_LOCAL); long lastModifiedLocal = cursor.getLong(lastModifiedLocalCol); int lastModifiedOnlineCol = cursor.getColumnIndexOrThrow(HostsSources.LAST_MODIFIED_ONLINE); long lastModifiedOnline = cursor.getLong(lastModifiedOnlineCol); lastModifiedTextView.setText(context.getString(R.string.hosts_last_modified_local) + " " + DateUtils.longToDateString(context, lastModifiedLocal) + ", " + context.getString(R.string.hosts_last_modified_online) + " " + DateUtils.longToDateString(context, lastModifiedOnline)); } }
From source file:p1.nd.khan.jubair.mohammadd.popularmovies.adapter.MovieDetailsAdapter.java
@Override public void bindView(View view, Context context, Cursor data) { int viewType = getItemViewType(data.getPosition()); switch (viewType) { case MOVIE://from w w w . j a v a2 s. c om DrawMovieDetails(context, data, (MovieHolder) view.getTag()); break; case TRAILER: DrawTrailerDetails(context, data, (TrailerHolder) view.getTag()); break; case REVIEW: DrawReviewDetails(data, (ReviewHolder) view.getTag()); break; } }