List of usage examples for android.database Cursor moveToPosition
boolean moveToPosition(int position);
From source file:org.jamienicol.episodes.EpisodeActivity.java
private int getEpisodePositionFromId(Cursor episodesData, int id) { int position; episodesData.moveToPosition(-1); while (episodesData.moveToNext()) { int idColumnIndex = episodesData.getColumnIndexOrThrow(EpisodesTable.COLUMN_ID); if (id == episodesData.getInt(idColumnIndex)) { return episodesData.getPosition(); }// w w w .ja v a2 s . c o m } return 0; }
From source file:com.DGSD.Teexter.UI.Recipient.RecipientAlternatesAdapter.java
@Override public long getItemId(int position) { Cursor c = getCursor(); if (c.moveToPosition(position)) { c.getLong(EmailQuery.DATA_ID);//from ww w. j av a 2s .c om } return -1; }
From source file:net.daverix.urlforward.LinksFragment.java
private List<LinkFilter> mapFilters(Cursor cursor) { List<LinkFilter> filters = new ArrayList<LinkFilter>(); for (int i = 0; cursor != null && cursor.moveToPosition(i); i++) { filters.add(mapper.mapFilter(cursor)); }/*from ww w. j a v a 2 s. com*/ return filters; }
From source file:ro.expectations.expenses.widget.dialog.CategoryPickerDialogFragment.java
@NonNull @Override/*w w w .j ava 2s. co m*/ public Dialog onCreateDialog(Bundle savedInstanceState) { AlertDialog.Builder builder = new AlertDialog.Builder(getActivity()); // Get the layout inflater LayoutInflater inflater = getActivity().getLayoutInflater(); View view = inflater.inflate(R.layout.dialog_fragment_recyclerview, null); final RecyclerView recyclerView = (RecyclerView) view.findViewById(R.id.recyclerview); recyclerView.setLayoutManager(new LinearLayoutManager(getActivity())); recyclerView.setHasFixedSize(true); mAdapter = new CategoryPickerAdapter(getActivity()); recyclerView.setAdapter(mAdapter); ItemClickHelper itemClickHelper = new ItemClickHelper(recyclerView); itemClickHelper.setOnItemClickListener(new ItemClickHelper.OnItemClickListener() { @Override public void onItemClick(RecyclerView parent, View view, int position) { Cursor cursor = mAdapter.getCursor(); cursor.moveToPosition(position); int categoryId = cursor.getInt(CategoryPickerAdapter.COLUMN_CATEGORY_ID); String categoryName = cursor.getString(CategoryPickerAdapter.COLUMN_CATEGORY_NAME); mCallback.onCategorySelected(getTargetRequestCode(), categoryId, categoryName); dismiss(); } }); builder.setTitle(getString(R.string.choose_category)); builder.setView(view); return builder.create(); }
From source file:com.DGSD.Teexter.UI.Recipient.RecipientAlternatesAdapter.java
@Override public View getView(int position, View convertView, ViewGroup parent) { Cursor cursor = getCursor(); cursor.moveToPosition(position); if (convertView == null) { convertView = newView();/*w w w . jav a 2 s. c o m*/ } if (cursor.getLong(EmailQuery.DATA_ID) == mCurrentId) { mCheckedItemPosition = position; if (mCheckedItemChangedListener != null) { mCheckedItemChangedListener.onCheckedItemChanged(mCheckedItemPosition); } } bindView(convertView, convertView.getContext(), cursor); return convertView; }
From source file:com.emuneee.nctrafficcams.ui.adapters.DefaultCamerasAdapter.java
@Override public ArrayList<Camera> getCameras() { Cursor cursor = getCursor(); int oldPos = cursor.getPosition(); ArrayList<Camera> cameras = CameraDBHelper.cursorToCameras(cursor); cursor.moveToPosition(oldPos); return cameras; }
From source file:com.zns.comicdroid.adapter.AggregateAdapter.java
@Override public View getView(int position, View convertView, ViewGroup parent) { Cursor cursor = getCursor(); if (cursor.moveToPosition(position)) { AggregateHolder holder;/*from w w w . j av a 2s . c o m*/ if (convertView == null) { convertView = mLayoutInflater.inflate(mLayout, null); holder = new AggregateHolder(); holder.tvTitle = (TextView) convertView.findViewById(R.id.tvTitle); holder.tvAuthor = (TextView) convertView.findViewById(R.id.tvAuthor); holder.ivImage = (ImageView) convertView.findViewById(R.id.ivImage); holder.tvCount = (TextView) convertView.findViewById(R.id.tvCount); holder.ivGroupMark = (ImageView) convertView.findViewById(R.id.ivGroupMark); holder.rlRow = (RelativeLayout) convertView.findViewById(R.id.rlRow); holder.ivGroupCompleted = (ImageView) convertView.findViewById(R.id.ivGroupCompleted); holder.ivGroupFinished = (ImageView) convertView.findViewById(R.id.ivGroupFinished); holder.ivGroupWatched = (ImageView) convertView.findViewById(R.id.ivGroupWatched); holder.rbComic = (RatingBar) convertView.findViewById(R.id.rbComicList); convertView.setTag(holder); } else { holder = (AggregateHolder) convertView.getTag(); } String title = cursor.getString(1); String subTitle = cursor.getString(2); String author = cursor.getString(3); String image = cursor.getString(4); int type = cursor.getInt(5); int count = cursor.getInt(6); boolean isBorrowed = cursor.getInt(7) == 1; int totalCount = cursor.getInt(8); boolean isFinished = cursor.getInt(9) == 1; boolean isComplete = cursor.getInt(10) == 1; boolean isWatched = cursor.getInt(11) == 1; //boolean isRead = cursor.getInt(12) == 1; int rating = cursor.getInt(13); holder.tvTitle.setText(title + (subTitle != null && !subTitle.equals("") ? " - " + subTitle : "")); holder.tvAuthor.setText(author); if (type == 2) { holder.ivGroupMark.setVisibility(View.VISIBLE); holder.tvCount.setText("(" + count + (totalCount > 0 ? "/" + totalCount : "") + ")"); holder.ivGroupFinished.setVisibility(isFinished ? View.VISIBLE : View.GONE); holder.ivGroupCompleted.setVisibility(isComplete ? View.VISIBLE : View.GONE); holder.ivGroupWatched.setVisibility(isWatched ? View.VISIBLE : View.GONE); holder.rbComic.setVisibility(View.GONE); } else { holder.ivGroupMark.setVisibility(View.GONE); holder.ivGroupCompleted.setVisibility(View.GONE); holder.ivGroupFinished.setVisibility(View.GONE); holder.ivGroupWatched.setVisibility(View.GONE); holder.tvCount.setText(""); holder.rbComic.setVisibility(rating > 0 ? View.VISIBLE : View.GONE); holder.rbComic.setRating(rating); } if (image != null && !image.equals("")) { ImageLoader.getInstance().displayImage(mImagePath.concat(image), holder.ivImage); holder.ivImage.setVisibility(View.VISIBLE); } else { holder.ivImage.setVisibility(View.GONE); } if (isBorrowed) { holder.rlRow.setBackgroundColor(mColorIsBorrowed); } else { holder.rlRow.setBackgroundColor(mColorDefault); } } return convertView; }
From source file:de.hska.iam.presentationapp.fragments.adapters.ThumbnailAdapter.java
@Override public Media getItem(final int position) { Cursor cursor = getCursor(); int oldPosition = cursor.getPosition(); cursor.moveToPosition(position); Media media = helper.getMedia(cursor); cursor.moveToPosition(oldPosition);/*w w w . j a v a 2 s.co m*/ return media; }
From source file:com.zns.comicdroid.adapter.ComicAdapter.java
public int[] getComicIds() { int[] ids = null; if (getCursor() != null) { Cursor cursor = getCursor(); ids = new int[cursor.getCount()]; int i = 0; cursor.moveToPosition(-1); while (cursor.moveToNext()) { ids[i] = cursor.getInt(0);//from w w w . ja va 2 s. co m i++; } } return ids; }
From source file:com.android.calendar.alerts.AlarmScheduler.java
/** * Queries for all the reminders of the events in the instancesCursor, and schedules * the alarm for the next upcoming reminder. *///from w w w .j av a2s .c o m private static void queryNextReminderAndSchedule(Cursor instancesCursor, Context context, ContentResolver contentResolver, AlarmManagerInterface alarmManager, int batchSize, long currentMillis) { if (AlertService.DEBUG) { int eventCount = instancesCursor.getCount(); if (eventCount == 0) { Log.d(TAG, "No events found starting within 1 week."); } else { Log.d(TAG, "Query result count for events starting within 1 week: " + eventCount); } } // Put query results of all events starting within some interval into map of event ID to // local start time. Map<Integer, List<Long>> eventMap = new HashMap<Integer, List<Long>>(); Time timeObj = new Time(); long nextAlarmTime = Long.MAX_VALUE; int nextAlarmEventId = 0; instancesCursor.moveToPosition(-1); while (!instancesCursor.isAfterLast()) { int index = 0; eventMap.clear(); StringBuilder eventIdsForQuery = new StringBuilder(); eventIdsForQuery.append('('); while (index++ < batchSize && instancesCursor.moveToNext()) { int eventId = instancesCursor.getInt(INSTANCES_INDEX_EVENTID); long begin = instancesCursor.getLong(INSTANCES_INDEX_BEGIN); boolean allday = instancesCursor.getInt(INSTANCES_INDEX_ALL_DAY) != 0; long localStartTime; if (allday) { // Adjust allday to local time. localStartTime = Utils.convertAlldayUtcToLocal(timeObj, begin, Time.getCurrentTimezone()); } else { localStartTime = begin; } List<Long> startTimes = eventMap.get(eventId); if (startTimes == null) { startTimes = new ArrayList<Long>(); eventMap.put(eventId, startTimes); eventIdsForQuery.append(eventId); eventIdsForQuery.append(","); } startTimes.add(localStartTime); // Log for debugging. if (Log.isLoggable(TAG, Log.DEBUG)) { timeObj.set(localStartTime); StringBuilder msg = new StringBuilder(); msg.append("Events cursor result -- eventId:").append(eventId); msg.append(", allDay:").append(allday); msg.append(", start:").append(localStartTime); msg.append(" (").append(timeObj.format("%a, %b %d, %Y %I:%M%P")).append(")"); Log.d(TAG, msg.toString()); } } if (eventIdsForQuery.charAt(eventIdsForQuery.length() - 1) == ',') { eventIdsForQuery.deleteCharAt(eventIdsForQuery.length() - 1); } eventIdsForQuery.append(')'); // Query the reminders table for the events found. Cursor cursor = null; try { cursor = contentResolver.query(Reminders.CONTENT_URI, REMINDERS_PROJECTION, REMINDERS_WHERE + eventIdsForQuery, null, null); // Process the reminders query results to find the next reminder time. cursor.moveToPosition(-1); while (cursor.moveToNext()) { int eventId = cursor.getInt(REMINDERS_INDEX_EVENT_ID); int reminderMinutes = cursor.getInt(REMINDERS_INDEX_MINUTES); List<Long> startTimes = eventMap.get(eventId); if (startTimes != null) { for (Long startTime : startTimes) { long alarmTime = startTime - reminderMinutes * DateUtils.MINUTE_IN_MILLIS; if (alarmTime > currentMillis && alarmTime < nextAlarmTime) { nextAlarmTime = alarmTime; nextAlarmEventId = eventId; } if (Log.isLoggable(TAG, Log.DEBUG)) { timeObj.set(alarmTime); StringBuilder msg = new StringBuilder(); msg.append("Reminders cursor result -- eventId:").append(eventId); msg.append(", startTime:").append(startTime); msg.append(", minutes:").append(reminderMinutes); msg.append(", alarmTime:").append(alarmTime); msg.append(" (").append(timeObj.format("%a, %b %d, %Y %I:%M%P")).append(")"); Log.d(TAG, msg.toString()); } } } } } finally { if (cursor != null) { cursor.close(); } } } // Schedule the alarm for the next reminder time. if (nextAlarmTime < Long.MAX_VALUE) { scheduleAlarm(context, nextAlarmEventId, nextAlarmTime, currentMillis, alarmManager); } }