List of usage examples for android.database Cursor getPosition
int getPosition();
From source file:com.kaliturin.blacklist.adapters.SMSConversationsListCursorAdapter.java
@Override public void bindView(View view, Context context, Cursor cursor) { // try to get a model from the cache long itemId = getItemId(cursor.getPosition()); SMSConversation model = smsConversationCache.get(itemId); if (model == null) { // get cursor wrapper SMSConversationWrapper cursorWrapper = (SMSConversationWrapper) cursor; // get model model = cursorWrapper.getConversation(context); // put it to the cache smsConversationCache.put(itemId, model); }//from w w w . j a v a 2 s . co m // get view holder from the row ViewHolder viewHolder = (ViewHolder) view.getTag(); // update the view holder with new model viewHolder.setModel(model); }
From source file:de.fahrgemeinschaft.util.SpinningZebraListFragment.java
@Override public void onViewCreated(View layout, Bundle state) { super.onViewCreated(layout, state); layout.setOnClickListener(null);/*from ww w .j av a2 s. co m*/ setListAdapter(new CursorAdapter(getActivity(), null, 0) { @Override public int getCount() { if (spinningEnabled) return super.getCount() + 1; else return super.getCount(); } @Override public int getViewTypeCount() { if (spinningEnabled) return 2; else return 1; } @Override public int getItemViewType(int position) { if (!spinningEnabled || position < getCount() - 1) return 0; else return 1; } @Override public View getView(int position, View v, ViewGroup parent) { if (!spinningEnabled || position < getCount() - 1) v = super.getView(position, v, parent); else { if (v == null) { v = getLayoutInflater(null).inflate(R.layout.view_spinning_wheel, parent, false); } ((TextView) v.findViewById(R.id.small)).setText(smallText); ((TextView) v.findViewById(R.id.large)).setText(largeText); if (spinning && onScreen) { v.findViewById(R.id.progress).startAnimation(rotate); } else if (onScreen) { v.findViewById(R.id.progress).clearAnimation(); } } if (position % 2 == 0) { v.setBackgroundColor(getResources().getColor(R.color.medium_green)); } else { v.setBackgroundColor(getResources().getColor(R.color.almost_medium_green)); } return v; } @Override public View newView(Context ctx, Cursor rides, ViewGroup parent) { return getLayoutInflater(null).inflate(R.layout.view_ride_list_entry, parent, false); } @Override public void bindView(View view, Context ctx, Cursor ride) { if (ride.getPosition() == ride.getCount()) return; bindListItemView(view, ride); } }); registerForContextMenu(getListView()); rotate = new RotateAnimation(0f, 360f, Animation.RELATIVE_TO_SELF, 0.5f, Animation.RELATIVE_TO_SELF, 0.5f); rotate.setDuration(600); rotate.setRepeatMode(Animation.RESTART); rotate.setRepeatCount(Animation.INFINITE); stopSpinning(getString(R.string.search_continue)); if (state != null) { code = state.getInt(ID); setSpinningEnabled(state.getBoolean(SPIN)); uri = (Uri) (state.getParcelable(URI)); getActivity().getSupportLoaderManager().initLoader(code, state, this); } else if (uri != null) { getActivity().getSupportLoaderManager().restartLoader(code, state, this); } getListView().requestFocus(); }
From source file:org.sufficientlysecure.keychain.ui.adapter.PhotoAttributesAdapter.java
/** "Bind an existing view to the data pointed to by cursor. * view Existing view, returned earlier by newView. * cursor The cursor from which to get the data, already moved to the correct position." (from doc) * This method is the bridge between newView() and getItem(). *//*from www . j a v a 2 s . c o m*/ @Override public void bindView(View view, Context context, Cursor cursor) { PhotoAttViewHolder holder = (PhotoAttViewHolder) view.getTag(); PhotoAttribute photo = getItem(cursor.getPosition()); holder.setData(photo, context); }
From source file:com.ubuntuone.android.files.fragment.AutoUploadCustomizeFragment.java
private void bindView(View view, Context context, Cursor cursor) { final int checked = cursor.getInt(cursor.getColumnIndex(WatchedFolders.AUTO_UPLOAD)); mFolderList.setItemChecked(cursor.getPosition(), checked == 1); final int isNew = cursor.getInt(cursor.getColumnIndex(WatchedFolders.IS_NEW)); if (isNew == 1) { view.setBackgroundResource(R.color.soft_orange); } else {// w w w . j a va 2 s .co m view.setBackgroundResource(android.R.color.background_light); } }
From source file:com.dabay6.android.apps.carlog.adapters.FuelHistoryCursorAdapter.java
/** * @param context The {@link Context} used to retrieve string resources. * @param history The current {@link FuelHistoryDTO} record. * @param cursor All history records./*from ww w .ja va 2s. co m*/ */ private Pair<Float, String> calculateMilesPerGallon(final Context context, final FuelHistoryDTO history, final Cursor cursor) { final Pair<Long, String> returnValue; final int count = cursor.getCount() - 1; final int currentPosition = cursor.getPosition(); final int next = cursor.getPosition() + 1; final float mileage; final float mpg; if (next <= count) { final FuelHistoryDTO previous; cursor.moveToPosition(next); previous = FuelHistoryDTO.newInstance(cursor); mileage = history.getOdometerReading() - previous.getOdometerReading(); mpg = mileage / history.getFuelAmount(); cursor.moveToPosition(currentPosition); } else { mpg = history.getOdometerReading() / history.getFuelAmount(); } return new Pair<Float, String>(mpg, String.format(context.getString(R.string.miles_per_gallon), mpg)); }
From source file:com.kaliturin.blacklist.adapters.ContactsCursorAdapter.java
public List<Contact> extractCheckedContacts() { List<Contact> list = new LinkedList<>(); Cursor cursor = getCursor(); if (cursor != null) { int position = cursor.getPosition(); cursor.moveToFirst();//from w w w . j ava2s.c o m do { Contact contact = ((ContactSource) cursor).getContact(); if (checkedItems.contains((int) contact.id)) { list.add(contact); } } while (cursor.moveToNext()); cursor.moveToPosition(position); } return list; }
From source file:li.barter.adapters.ChatDetailAdapter.java
@Override public void bindView(final View view, final Context context, final Cursor cursor) { ((TextView) view.getTag(R.id.text_chat_message)) .setText(cursor.getString(cursor.getColumnIndex(DatabaseColumns.MESSAGE))); final int itemViewType = getItemViewType(cursor.getPosition()); final String timestamp = cursor.getString(cursor.getColumnIndex(DatabaseColumns.TIMESTAMP_HUMAN)); view.setTag(R.string.tag_resend_on_click, false); if (itemViewType == INCOMING_MESSAGE) { ((TextView) view.getTag(R.id.chat_ack)).setText(timestamp); } else if (itemViewType == OUTGOING_MESSAGE) { final int chatStatus = cursor.getInt(cursor.getColumnIndex(DatabaseColumns.CHAT_STATUS)); final TextView chatStatusTextView = ((TextView) view.getTag(R.id.chat_ack)); switch (chatStatus) { case ChatStatus.SENDING: { chatStatusTextView.setText(mSendingString); break; }/*from w w w . j a v a 2s .co m*/ case ChatStatus.SENT: { chatStatusTextView.setText(timestamp); break; } case ChatStatus.FAILED: { chatStatusTextView.setText(mFailedString); view.setTag(R.string.tag_resend_on_click, true); break; } } } }
From source file:com.spokenpic.ViewMain.java
@Override protected void onPause() { super.onPause(); Cursor cursor = mGalleryAdapter.getCursor(); if (cursor != null) { mCursorPosition = cursor.getPosition(); cursor.close();/*from ww w . j a v a 2 s . c o m*/ mGalleryAdapter.changeCursor(null); } }
From source file:com.zhaojian.jolly.adapter.UserPhotosViewPagerAdapter.java
@Override public View newView(Context context, Cursor cursor, ViewGroup parent) { final PhotoUpload upload = MediaStoreCursorHelper .photosCursorToSelection(MediaStoreCursorHelper.MEDIA_STORE_CONTENT_URI, cursor); PhotoTagItemLayout view = new PhotoTagItemLayout(mContext, mController, upload); view.setPosition(cursor.getPosition()); if (null != upload) { MultiTouchImageView imageView = view.getImageView(); imageView.requestFullSize(upload, true, null); }/*from ww w .j a v a 2s . c om*/ return view; }
From source file:me.jreilly.JamesTweet.Adapters.TweetDataHelper.java
public Callback<List<Tweet>> callBackMaker(final int mMaxItems, final RecyclerView mRecyclerView, final Cursor mCursor, final SQLiteDatabase mTimelineDB, final TweetDataHelper mHelper, final SwipeRefreshLayout mSwipeRefreshLayout) { final int position = mCursor.getPosition(); return new Callback<List<Tweet>>() { @Override/*from w w w .j a va2 s. com*/ public void success(Result<List<Tweet>> listResult) { long numEntries = DatabaseUtils.queryNumEntries(mTimelineDB, "home"); List<Tweet> list = listResult.data.subList(0, listResult.data.size()); for (Tweet t : list) { try { ContentValues tweetValues = mHelper.getValues(t); mTimelineDB.insertOrThrow("home", null, tweetValues); Log.v("NEW CONTEXT", "Added Tweet Tweets!"); } catch (Exception te) { Log.e("NEW CONTEXT", "Exception: " + te); } } int rowLimit = 50; if (DatabaseUtils.queryNumEntries(mTimelineDB, "home") > rowLimit) { String deleteQuery = "DELETE FROM home WHERE " + BaseColumns._ID + " NOT IN " + "(SELECT " + BaseColumns._ID + " FROM home ORDER BY " + "update_time DESC " + "limit " + rowLimit + ")"; mTimelineDB.execSQL(deleteQuery); Log.v("NEW CONTEXT", "Deleteing Tweets!"); } mRecyclerView.getAdapter().notifyDataSetChanged(); if (mSwipeRefreshLayout != null) { mSwipeRefreshLayout.setRefreshing(false); } else { mRecyclerView.smoothScrollToPosition(position); } Log.v("NEW CONTEXT", "All done!"); } @Override public void failure(TwitterException e) { Log.e("NEW CONTEXT", "Exception " + e); } }; }