Java Code Examples for android.database.Cursor.moveToPrevious()

The following are Jave code examples for showing how to use moveToPrevious() of the android.database.Cursor class. You can vote up the examples you like. Your votes will be used in our system to get more good examples.
Example 1
Project: GitHub   File: TasksManagerDemoActivity.java   Source Code and License Vote up 6 votes
public List<TasksManagerModel> getAllTasks() {
    final Cursor c = db.rawQuery("SELECT * FROM " + TABLE_NAME, null);

    final List<TasksManagerModel> list = new ArrayList<>();
    try {
        if (!c.moveToLast()) {
            return list;
        }

        do {
            TasksManagerModel model = new TasksManagerModel();
            model.setId(c.getInt(c.getColumnIndex(TasksManagerModel.ID)));
            model.setName(c.getString(c.getColumnIndex(TasksManagerModel.NAME)));
            model.setUrl(c.getString(c.getColumnIndex(TasksManagerModel.URL)));
            model.setPath(c.getString(c.getColumnIndex(TasksManagerModel.PATH)));
            list.add(model);
        } while (c.moveToPrevious());
    } finally {
        if (c != null) {
            c.close();
        }
    }

    return list;
}
 
Example 2
Project: SOS-The-Healthcare-Companion   File: ContactPickerActivity.java   Source Code and License Vote up 6 votes
private void readContactDetails(Cursor cursor) {
    if (cursor != null && cursor.moveToFirst()) {
        cursor.moveToPrevious();
        while (cursor.moveToNext()) {
            String lookupKey = cursor.getString(cursor.getColumnIndex(ContactsContract.Data.LOOKUP_KEY));
            ContactImpl contact = mContactsByLookupKey.get(lookupKey);

            if (contact != null) {
                readContactDetails(cursor, contact);
            }
        }
    }

    sortAndPostCopy(mContacts);
    joinContactsAndGroups(mContacts);
}
 
Example 3
Project: IslamicLibraryAndroid   File: BooksInformationDbHelper.java   Source Code and License Vote up 6 votes
/**
 * @param c           cursor moved byond its last position
 * @param columnIndex the index for enqueId in the Cursor
 */
public void cancelMultipleDownloads(Cursor c, int columnIndex) {
    SQLiteDatabase db = this.getWritableDatabase();
    db.beginTransaction();
    try {
        while (c.moveToPrevious()) {
            long enquId = c.getLong(columnIndex);
            db.delete(BooksInformationDBContract.StoredBooks.TABLE_NAME,
                    BooksInformationDBContract.StoredBooks.COLUMN_NAME_ENQID + "=?",
                    new String[]{Long.toString(enquId)});
        }
        db.setTransactionSuccessful();
    } finally {
        db.endTransaction();
    }
}
 
Example 4
Project: FileDownloader-master   File: TasksManagerDBController.java   Source Code and License Vote up 6 votes
public List<TasksManagerModel> getAllTasks() {
    final Cursor c = db.rawQuery("SELECT * FROM " + TABLE_NAME, null);

    final List<TasksManagerModel> list = new ArrayList<>();
    try {
        if (!c.moveToLast()) {
            return list;
        }

        do {
            TasksManagerModel model = new TasksManagerModel();
            model.setId(c.getInt(c.getColumnIndex(TasksManagerModel.ID)));
            model.setName(c.getString(c.getColumnIndex(TasksManagerModel.NAME)));
            model.setUrl(c.getString(c.getColumnIndex(TasksManagerModel.URL)));
            model.setPath(c.getString(c.getColumnIndex(TasksManagerModel.PATH)));
            list.add(model);
        } while (c.moveToPrevious());
    } finally {
        if (c != null) {
            c.close();
        }
    }

    return list;
}
 
Example 5
Project: q-mail   File: EmailProviderCacheCursor.java   Source Code and License Vote up 5 votes
public EmailProviderCacheCursor(String accountUuid, Cursor cursor, Context context) {
    super(cursor);

    mCache = EmailProviderCache.getCache(accountUuid, context);

    mMessageIdColumn = cursor.getColumnIndex(MessageColumns.ID);
    mFolderIdColumn = cursor.getColumnIndex(MessageColumns.FOLDER_ID);
    mThreadRootColumn = cursor.getColumnIndex(ThreadColumns.ROOT);

    if (mMessageIdColumn == -1 || mFolderIdColumn == -1 || mThreadRootColumn == -1) {
        throw new IllegalArgumentException("The supplied cursor needs to contain the " +
                "following columns: " + MessageColumns.ID + ", " + MessageColumns.FOLDER_ID +
                ", " + ThreadColumns.ROOT);
    }

    while (cursor.moveToNext()) {
        long messageId = cursor.getLong(mMessageIdColumn);
        long folderId = cursor.getLong(mFolderIdColumn);
        if (mCache.isMessageHidden(messageId, folderId)) {
            mHiddenRows.add(cursor.getPosition());
        }
    }

    // Reset the cursor position
    cursor.moveToFirst();
    cursor.moveToPrevious();
}
 
Example 6
Project: SOS-The-Healthcare-Companion   File: ContactPickerActivity.java   Source Code and License Vote up 5 votes
private void readContacts(Cursor cursor) {
    mContacts.clear();
    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();
}
 
Example 7
Project: CSipSimple   File: FavAdapter.java   Source Code and License Vote up 5 votes
@Override
public void onClick(View view) {
    ContactInfo ci = (ContactInfo) view.getTag();
    List<String> phones = ContactsWrapper.getInstance().getCSipPhonesContact(mContext, ci.contactId);
    boolean useCSip = true;
    String toCall = null;
    if(phones != null && phones.size() > 0) {
        toCall = phones.get(0);
    }else {
        List<Phone> cPhones = ContactsWrapper.getInstance().getPhoneNumbers(mContext, ci.contactId, ContactsWrapper.URI_ALLS);
        if(cPhones != null && cPhones.size() > 0) {
            toCall = cPhones.get(0).getNumber();
            useCSip = false;
        }
    }
    
    if(!TextUtils.isEmpty(toCall) ) {
        Cursor c = (Cursor) getItem((Integer) ci.userData);
        Long profileId = null;
        while(c.moveToPrevious()) {
            int cTypeIdx = c.getColumnIndex(ContactsWrapper.FIELD_TYPE);
            int cAccIdx = c.getColumnIndex(BaseColumns._ID);
            if(cTypeIdx >= 0 && cAccIdx >= 0) {
                if(c.getInt(cTypeIdx) == ContactsWrapper.TYPE_GROUP) {
                    profileId = c.getLong(cAccIdx);
                    break;
                }
            }
        }
        
        Intent it = new Intent(Intent.ACTION_CALL);
        it.setData(SipUri.forgeSipUri(useCSip ? SipManager.PROTOCOL_CSIP : SipManager.PROTOCOL_SIP, toCall));
        it.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
        if(profileId != null) {
            it.putExtra(SipProfile.FIELD_ACC_ID, profileId);
        }
        mContext.startActivity(it);
    }
}
 
Example 8
Project: oma-riista-android   File: DiaryDataSource.java   Source Code and License Vote up 5 votes
/**
 * Iterates sqlite cursor and builds complete GameHarvest objects
 *
 * @param cursor           sqlite cursor
 * @param getDeletedImages
 * @return List of GameHarvest objects
 */
private List<GameHarvest> aggregateEvents(Cursor cursor, boolean getDeletedImages) {
    cursor.moveToFirst();
    List<LogImage> logImages = new ArrayList<LogImage>();
    boolean first = true;
    int lastId = 0;
    List<GameHarvest> logEvents = new ArrayList<GameHarvest>();
    while (!cursor.isAfterLast()) {
        int eventId = cursor.getInt(cursor.getColumnIndex(DiaryHelper.COLUMN_LOCALID));
        if (!first && eventId != lastId) {
            cursor.moveToPrevious();
            logEvents.add(createEvent(cursor, logImages));
            logImages = new ArrayList<LogImage>();
            cursor.moveToNext();
        }
        LogImage image = logImageFromCursor(cursor, getDeletedImages);
        if (image != null)
            logImages.add(image);
        lastId = eventId;
        cursor.moveToNext();
        first = false;
    }
    if (cursor.getCount() > 0) {
        cursor.moveToLast();
        logEvents.add(createEvent(cursor, logImages));
    }
    return logEvents;
}
 
Example 9
Project: StopApp   File: AppInfoDBController.java   Source Code and License Vote up 5 votes
/**
 * 获取主页停用列表apps
 *
 * @param tableName
 * @return
 */
public List<AppInfo> getDisableApps(String tableName) {
    final Cursor cursor = mSQLiteDatabase.rawQuery("SELECT * FROM " + tableName, null);

    final List<AppInfo> list = new ArrayList<>();
    try {
        if (!cursor.moveToLast()) {
            return list;
        }
        do {
            AppInfo appInfo = new AppInfo();
            appInfo.setAppPackageName(cursor.getString(cursor.getColumnIndex(AppInfo.APP_PACKAGE_NAME)));
            appInfo.setAppName(cursor.getString(cursor.getColumnIndex(AppInfo.APP_NAME)));
            MyLogger.e(cursor.getString(cursor.getColumnIndex(AppInfo.APP_NAME)));
            appInfo.setAppIcon(CommonUtil.getImage(cursor.getBlob(cursor.getColumnIndex(AppInfo.APP_ICON))));
            appInfo.setEnable(cursor.getInt(cursor.getColumnIndex(AppInfo.IS_ENABLE)));
            appInfo.setSystemApp(cursor.getInt(cursor.getColumnIndex(AppInfo.IS_SYSTEM_APP)));
            list.add(appInfo);
        } while (cursor.moveToPrevious());
    } finally {
        if (cursor != null && !cursor.isClosed()) {
            cursor.close();
        }
    }

    return list;
}
 
Example 10
Project: q-mail   File: MergeCursor.java   Source Code and License Vote up 4 votes
@Override
public boolean moveToNext() {
    int count = getCount();
    if (mPosition == count) {
        return false;
    }

    if (mPosition == count - 1) {
        mActiveCursor.moveToNext();
        mPosition++;
        return false;
    }

    int smallest = -1;
    for (int i = 0, len = mCursors.length; i < len; i++) {
        if (mCursors[i] == null || mCursors[i].getCount() == 0 || mCursors[i].isLast()) {
            continue;
        }

        if (smallest == -1) {
            smallest = i;
            mCursors[smallest].moveToNext();
            continue;
        }

        Cursor left = mCursors[smallest];
        Cursor right = mCursors[i];

        right.moveToNext();

        int result = mComparator.compare(left, right);
        if (result > 0) {
            smallest = i;
            left.moveToPrevious();
        } else {
            right.moveToPrevious();
        }
    }

    mPosition++;
    if (smallest != -1) {
        mActiveCursorIndex = smallest;
        mActiveCursor = mCursors[mActiveCursorIndex];
    }

    return true;
}
 
Example 11
Project: remotedroid   File: SMSUtils.java   Source Code and License Vote up 4 votes
private List<HashMap<String,String>> getMessages(String where, String[] whereArgs, int limitStart, int limitEnd){
    Uri uri = Uri.parse("content://sms");

    Cursor c = mContext.getContentResolver().query(uri,
            null,
            where,
            whereArgs,
            "date desc LIMIT "+String.valueOf(limitStart)+", "+String.valueOf(limitEnd)
    );
    List<HashMap<String,String>> ret = new ArrayList<HashMap<String, String>>();
    if (c.getCount() > 0){
        c.moveToLast();
        for (int i = 0; i < c.getCount(); i++) {
            String msgId = c.getString(c.getColumnIndex("_id"));
            String address = c.getString(c.getColumnIndex("address")); // phone #
            String date = c.getString(c.getColumnIndex("date"));
            String body = c.getString(c.getColumnIndex("body"));
            //String seen = c.getString(c.getColumnIndex("read"));
            String type = c.getString(c.getColumnIndex("type"));
            int thread = c.getInt(c.getColumnIndexOrThrow("thread_id"));

            ContactsUtil mContacts = new ContactsUtil(mContext);
            String contactId = mContacts.getContactId(address);

            String name = address;
            if (!(contactId == null)) {
                HashMap<String, String> contact = mContacts.getContactById(Integer.parseInt(contactId));
                name = contact.get("name");
            }

            HashMap<String,String> currMsg = new HashMap<>();
            currMsg.put("address",address);
            currMsg.put("name",name);
            currMsg.put("date",date); //timestamp
            currMsg.put("content",body);
            currMsg.put("contact_id",contactId);
            currMsg.put("type",type);
            currMsg.put("msg_id", msgId);
            currMsg.put("thread_id", String.valueOf(thread));

            ret.add(currMsg);
            c.moveToPrevious();
        }
    }
    return ret;
}