List of usage examples for android.database Cursor moveToPrevious
boolean moveToPrevious();
From source file:com.androzic.location.LocationService.java
public Track getTrack(long limit) { if (trackDB == null) openDatabase();/*w w w . ja v a 2s . c o m*/ Track track = new Track(); if (trackDB == null) return track; String limitStr = limit > 0 ? " LIMIT " + limit : ""; Cursor cursor = trackDB.rawQuery("SELECT * FROM track ORDER BY _id DESC" + limitStr, null); for (boolean hasItem = cursor.moveToLast(); hasItem; hasItem = cursor.moveToPrevious()) { double latitude = cursor.getDouble(cursor.getColumnIndex("latitude")); double longitude = cursor.getDouble(cursor.getColumnIndex("longitude")); double elevation = cursor.getDouble(cursor.getColumnIndex("elevation")); double speed = cursor.getDouble(cursor.getColumnIndex("speed")); double bearing = cursor.getDouble(cursor.getColumnIndex("track")); double accuracy = cursor.getDouble(cursor.getColumnIndex("accuracy")); int code = cursor.getInt(cursor.getColumnIndex("code")); long time = cursor.getLong(cursor.getColumnIndex("datetime")); track.addPoint(code == 0, latitude, longitude, elevation, speed, bearing, accuracy, time); } cursor.close(); return track; }
From source file:com.silentcircle.contacts.list.PhoneNumberListAdapter.java
@Override protected void bindView(View itemView, int partition, Cursor cursor, int position) { ContactListItemView view = (ContactListItemView) itemView; view.setHighlightedPrefix(isSearchMode() ? getUpperCaseQueryString() : null); // Look at elements before and after this position, checking if contact IDs are same. // If they have one same contact ID, it means they can be grouped. ////from w ww . j a v a2 s.c om // In one group, only the first entry will show its photo and its name, and the other // entries in the group show just their data (e.g. phone number, email address). cursor.moveToPosition(position); boolean isFirstEntry = true; boolean showBottomDivider = true; final long currentContactId = cursor.getLong(PhoneQuery.PHONE_CONTACT_ID); if (cursor.moveToPrevious() && !cursor.isBeforeFirst()) { final long previousContactId = cursor.getLong(PhoneQuery.PHONE_CONTACT_ID); if (currentContactId == previousContactId) { isFirstEntry = false; } } cursor.moveToPosition(position); if (cursor.moveToNext() && !cursor.isAfterLast()) { final long nextContactId = cursor.getLong(PhoneQuery.PHONE_CONTACT_ID); if (currentContactId == nextContactId) { // The following entry should be in the same group, which means we don't want a // divider between them. // TODO: we want a different divider than the divider between groups. Just hiding // this divider won't be enough. showBottomDivider = false; } } cursor.moveToPosition(position); bindSectionHeaderAndDivider(view, position); if (isFirstEntry) { bindName(view, cursor); if (isQuickContactEnabled()) { // No need for photo uri here, because we can not have directory results. If we // ever do, we need to add photo uri to the query bindQuickContact(view, partition, cursor, PhoneQuery.PHONE_PHOTO_ID, -1, PhoneQuery.PHONE_CONTACT_ID); } else { bindPhoto(view, cursor); } } else { unbindName(view); view.removePhotoView(true, false); } bindPhoneNumber(view, cursor); view.setDividerVisible(showBottomDivider); }
From source file:com.onegravity.contactpicker.core.ContactPickerActivity.java
private void readContacts(Cursor cursor) { mContacts.clear();//from w w w .ja v a2 s . c om mContactsByLookupKey.clear(); mNrOfSelectedContacts = 0; int count = 0; if (cursor.moveToFirst()) { cursor.moveToPrevious(); while (cursor.moveToNext()) { ContactImpl contact = ContactImpl.fromCursor(cursor); mContacts.add(contact); // LOOKUP_KEY is the one we use to retrieve the contact when the contact details are loaded String lookupKey = cursor.getString(cursor.getColumnIndex(ContactsContract.Contacts.LOOKUP_KEY)); mContactsByLookupKey.put(lookupKey, contact); boolean isChecked = mSelectedContactIds.contains(contact.getId()); contact.setChecked(isChecked, true); mNrOfSelectedContacts += isChecked ? 1 : 0; contact.addOnContactCheckedListener(mContactListener); // update the ui once some contacts have loaded if (++count >= BATCH_SIZE) { sortAndPostCopy(mContacts); count = 0; } } } if (count > 0) { sortAndPostCopy(mContacts); } updateTitle(); }
From source file:com.androzic.location.LocationService.java
public Track getTrack(long start, long end) { if (trackDB == null) openDatabase();//from w ww.java 2 s . co m Track track = new Track(); if (trackDB == null) return track; Cursor cursor = trackDB.rawQuery( "SELECT * FROM track WHERE datetime >= ? AND datetime <= ? ORDER BY _id DESC", new String[] { String.valueOf(start), String.valueOf(end) }); for (boolean hasItem = cursor.moveToLast(); hasItem; hasItem = cursor.moveToPrevious()) { double latitude = cursor.getDouble(cursor.getColumnIndex("latitude")); double longitude = cursor.getDouble(cursor.getColumnIndex("longitude")); double elevation = cursor.getDouble(cursor.getColumnIndex("elevation")); double speed = cursor.getDouble(cursor.getColumnIndex("speed")); double bearing = cursor.getDouble(cursor.getColumnIndex("track")); double accuracy = cursor.getDouble(cursor.getColumnIndex("accuracy")); int code = cursor.getInt(cursor.getColumnIndex("code")); long time = cursor.getLong(cursor.getColumnIndex("datetime")); track.addPoint(code == 0, latitude, longitude, elevation, speed, bearing, accuracy, time); } cursor.close(); return track; }
From source file:org.bombusim.lime.fragments.ChatFragment.java
private void markAllRead() { synchronized (visavis) { int unreadCount = visavis.getUnread(); visavis.setUnread(0);/* w ww . j a v a 2 s . co m*/ Cursor cursor = mCursorAdapter.getCursor(); if (cursor == null) return; if (cursor.moveToLast()) do { Message m = ChatHistoryDbAdapter.getMessageFromCursor(cursor); if (m.unread) { mChat.markRead(m.getId()); Lime.getInstance().notificationMgr().cancelChatNotification(m.getId()); unreadCount--; } } while ((unreadCount != 0) && cursor.moveToPrevious()); } }
From source file:org.voidsink.anewjkuapp.fragment.CalendarFragment.java
@Override public void onLoadFinished(Loader<Cursor> loader, Cursor data) { mAdapter.clear();//from w w w . ja v a2 s .c o m Account mAccount = AppUtils.getAccount(getContext()); if (mAccount != null) { // fetch calendar colors final SparseIntArray mColors = new SparseIntArray(); ContentResolver cr = getContext().getContentResolver(); Cursor cursor = cr.query(CalendarContractWrapper.Calendars.CONTENT_URI(), new String[] { CalendarContractWrapper.Calendars._ID(), CalendarContractWrapper.Calendars.CALENDAR_COLOR() }, null, null, null); if (cursor != null) { while (cursor.moveToNext()) { mColors.put(cursor.getInt(0), cursor.getInt(1)); } cursor.close(); } List<CalendarListEvent> mEvents = new ArrayList<>(); if (data != null) { data.moveToFirst(); data.moveToPrevious(); while (data.moveToNext()) { mEvents.add(new CalendarListEvent(getContext(), data.getLong(CalendarUtils.COLUMN_EVENT_ID), mColors.get(data.getInt(CalendarUtils.COLUMN_EVENT_CAL_ID)), data.getString(CalendarUtils.COLUMN_EVENT_TITLE), data.getString(CalendarUtils.COLUMN_EVENT_DESCRIPTION), data.getString(CalendarUtils.COLUMN_EVENT_LOCATION), data.getLong(CalendarUtils.COLUMN_EVENT_DTSTART), data.getLong(CalendarUtils.COLUMN_EVENT_DTEND), data.getInt(CalendarUtils.COLUMN_EVENT_ALL_DAY) == 1)); } } mAdapter.addAll(mEvents); } mAdapter.notifyDataSetChanged(); finishProgress(); }
From source file:com.klinker.android.twitter.utils.NotificationUtils.java
private static NotificationCompat.InboxStyle getDMInboxStyle(int numberNew, int accountNumber, Context context, String title) {/*from w w w . j a v a 2 s . com*/ NotificationCompat.InboxStyle style = new NotificationCompat.InboxStyle(); Cursor cursor = DMDataSource.getInstance(context).getCursor(accountNumber); if (!cursor.moveToLast()) { return style; } AppSettings settings = AppSettings.getInstance(context); if (numberNew > 5) { if (numberNew - 5 == 1) { style.setSummaryText("+" + (numberNew - 5) + " " + context.getString(R.string.new_direct_message)); } else { style.setSummaryText("+" + (numberNew - 5) + " " + context.getString(R.string.new_direct_messages)); } for (int i = 0; i < 5; i++) { String handle = cursor.getString(cursor.getColumnIndex(DMSQLiteHelper.COLUMN_SCREEN_NAME)); String text = cursor.getString(cursor.getColumnIndex(DMSQLiteHelper.COLUMN_TEXT)); String longText = "<b>@" + handle + "</b>: " + text; style.addLine(Html.fromHtml( settings.addonTheme ? longText.replaceAll("FF8800", settings.accentColor) : longText)); cursor.moveToPrevious(); } } else { for (int i = 0; i < numberNew; i++) { String handle = cursor.getString(cursor.getColumnIndex(DMSQLiteHelper.COLUMN_SCREEN_NAME)); String text = cursor.getString(cursor.getColumnIndex(DMSQLiteHelper.COLUMN_TEXT)); String longText = "<b>@" + handle + "</b>: " + text; style.addLine(Html.fromHtml( settings.addonTheme ? longText.replaceAll("FF8800", settings.accentColor) : longText)); cursor.moveToPrevious(); } } style.setBigContentTitle(title); return style; }
From source file:com.wso2.mobile.mdm.api.TrackCallSMS.java
/** * Returns a JSONArray of SMS objects Ex: [{number:"0772345666", date:"dd/MM/yyyy hh:mm:ss.SSS", content:"Hello"}] * //from www . jav a2 s. com * @param type * - Folder type should be passed in (1 for Inbox, 2 for Sent box) */ public JSONArray getSMS(int type) { JSONArray jsonArray = null; try { Uri uriSms = Uri.parse("content://sms"); Cursor cursor = cr.query(uriSms, new String[] { "_id", "address", "date", "body", "type", "read" }, "type=" + type, null, "date" + " COLLATE LOCALIZED ASC"); if (cursor != null) { cursor.moveToLast(); if (cursor.getCount() > 0) { jsonArray = new JSONArray(); do { JSONObject jsonObj = new JSONObject(); String date = cursor.getString(cursor.getColumnIndex("date")); Long timestamp = Long.parseLong(date); Calendar calendar = Calendar.getInstance(); calendar.setTimeInMillis(timestamp); DateFormat formatter = new SimpleDateFormat("dd/MM/yyyy hh:mm:ss.SSS"); jsonObj.put("number", cursor.getString(cursor.getColumnIndex("address"))); jsonObj.put("date", formatter.format(calendar.getTime())); /*jsonObj.put("content", cursor.getString(cursor.getColumnIndex("body")));*/ //jsonObj.put("content","Testing SMS"); jsonArray.add(jsonObj); } while (cursor.moveToPrevious()); } } } catch (Exception ex) { ex.printStackTrace(); } return jsonArray; }
From source file:com.klinker.android.twitter.utils.NotificationUtils.java
private static NotificationCompat.InboxStyle getMentionsInboxStyle(int numberNew, int accountNumber, Context context, String title) { NotificationCompat.InboxStyle style = new NotificationCompat.InboxStyle(); Cursor cursor = MentionsDataSource.getInstance(context).getCursor(accountNumber); if (!cursor.moveToLast()) { return style; }/*from w w w .j a v a2s.c om*/ AppSettings settings = AppSettings.getInstance(context); if (numberNew > 5) { if (numberNew - 5 == 1) { style.setSummaryText("+" + (numberNew - 5) + " " + context.getString(R.string.new_mention)); } else { style.setSummaryText("+" + (numberNew - 5) + " " + context.getString(R.string.new_mentions)); } for (int i = 0; i < 5; i++) { String handle = cursor.getString(cursor.getColumnIndex(MentionsSQLiteHelper.COLUMN_SCREEN_NAME)); String text = cursor.getString(cursor.getColumnIndex(MentionsSQLiteHelper.COLUMN_TEXT)); String longText = "<b>@" + handle + "</b>: " + text; style.addLine(Html.fromHtml( settings.addonTheme ? longText.replaceAll("FF8800", settings.accentColor) : longText)); cursor.moveToPrevious(); } } else { for (int i = 0; i < numberNew; i++) { String handle = cursor.getString(cursor.getColumnIndex(MentionsSQLiteHelper.COLUMN_SCREEN_NAME)); String text = cursor.getString(cursor.getColumnIndex(MentionsSQLiteHelper.COLUMN_TEXT)); String longText = "<b>@" + handle + "</b>: " + text; style.addLine(Html.fromHtml( settings.addonTheme ? longText.replaceAll("FF8800", settings.accentColor) : longText)); cursor.moveToPrevious(); } } style.setBigContentTitle(title); return style; }
From source file:cn.tangxb.imageselector.PhotoModelTaskLoader.java
@Override public ArrayList<PhotoModel> loadInBackground() { synchronized (this) { if (isLoadInBackgroundCanceled()) { throw new OperationCanceledException(); }/*from w ww .ja va 2s . c o m*/ mCancellationSignal = new CancellationSignal(); } try { Cursor cursor = ContentResolverCompat.query(getContext().getContentResolver(), MediaStore.Images.Media.EXTERNAL_CONTENT_URI, new String[] { MediaStore.Images.ImageColumns.DATA, MediaStore.Images.ImageColumns.DATE_ADDED, MediaStore.Images.ImageColumns.SIZE }, null, null, MediaStore.Images.ImageColumns.DATE_ADDED, mCancellationSignal); if (cursor != null) { try { // Ensure the cursor window is filled. cursor.getCount(); cursor.registerContentObserver(mObserver); mData = new ArrayList<>(); if (cursor == null || !cursor.moveToNext()) return mData; cursor.moveToLast(); do { if (cursor.getLong(cursor.getColumnIndex(MediaStore.Images.ImageColumns.SIZE)) > 1024 * 10) { PhotoModel photoModel = new PhotoModel(); photoModel.setOriginalPath( cursor.getString(cursor.getColumnIndex(MediaStore.Images.ImageColumns.DATA))); mData.add(photoModel); } } while (cursor.moveToPrevious()); } catch (RuntimeException ex) { cursor.close(); throw ex; } } return mData; } finally { synchronized (this) { mCancellationSignal = null; } } }