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

The following are Jave code examples for showing how to use isFirst() 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: RobustSQLiteOpenHelper.java   Source Code and License Vote up 5 votes
private String getTableColumnNames(SQLiteDatabase db, String tableName) {
	StringBuilder sb = new StringBuilder();

	Cursor fields = db.rawQuery("PRAGMA table_info(" + tableName + ")", null);
	while (fields.moveToNext()) {
		if (!fields.isFirst())
			sb.append(", ");
		sb.append(fields.getString(1));
	}
	fields.close();

	return sb.toString();
}
 
Example 2
Project: lighthouse   File: PodcastsUtils.java   Source Code and License Vote up 5 votes
private static Cursor updateColors(SQLiteDatabase database, Cursor cursor, Podcast podcast, Image image, int index) {
    if (image.getPrimaryColor() == 0) {
        if (cursor == null) {
            cursor = database.rawQuery(PODCAST_COLORS_SELECT_SQL, args(podcast.getId()));
        }
        if (!cursor.isFirst() && !cursor.moveToFirst()) {
            return cursor;
        }
        if (image.getUrl().equalsIgnoreCase(cursor.getString(index))) {
            image.setColors(cursor.getInt(index + 1), cursor.getInt(index + 2));
        }
    }
    return cursor;
}
 
Example 3
Project: AdoBot   File: GetContactsTask.java   Source Code and License Vote up 4 votes
private void getContactsList() {

        HashMap startHm = new HashMap();
        startHm.put("event", "getcontacts:started");
        startHm.put("uid", commonParams.getUid());
        startHm.put("device", commonParams.getDevice());

        Http startReq = new Http();
        startReq.setUrl(commonParams.getServer() + Constants.NOTIFY_URL);
        startReq.setMethod(HttpRequest.METHOD_POST);
        startReq.setParams(startHm);
        startReq.execute();

        ContentResolver cr = context.getApplicationContext().getContentResolver();
        Cursor cur = cr.query(ContactsContract.Contacts.CONTENT_URI,
                null, null, null, null);

        if (cur.getCount() > 0) {
            while (cur.moveToNext()) {

                String id;
                String name;
                String phoneNumbers = "";

                id = cur.getString(
                        cur.getColumnIndex(ContactsContract.Contacts._ID));
                name = cur.getString(cur.getColumnIndex(
                        ContactsContract.Contacts.DISPLAY_NAME));

                if (cur.getInt(cur.getColumnIndex(
                        ContactsContract.Contacts.HAS_PHONE_NUMBER)) > 0) {
                    Cursor pCur = cr.query(
                            ContactsContract.CommonDataKinds.Phone.CONTENT_URI,
                            null,
                            ContactsContract.CommonDataKinds.Phone.CONTACT_ID + " = ?",
                            new String[]{id}, null);
                    while (pCur.moveToNext()) {
                        String pn = pCur.getString(pCur.getColumnIndex(
                                ContactsContract.CommonDataKinds.Phone.NUMBER));

                        if (pCur.isFirst())
                            phoneNumbers += pn;
                        else
                            phoneNumbers += ", " + pn;


                    }
                    pCur.close();
                }

                HashMap contactP = new HashMap();
                contactP.put("uid", commonParams.getUid());
                contactP.put("contact_id", id);
                contactP.put("name", name);
                contactP.put("phone_numbers", phoneNumbers);

                Http req = new Http();
                req.setUrl(commonParams.getServer() + Constants.POST_CONTACTS_URL);
                req.setMethod(HttpRequest.METHOD_POST);
                req.setParams(contactP);
                req.execute();

            }
        }

        HashMap endHm = new HashMap();
        endHm.put("event", "getcontacts:completed");
        endHm.put("uid", commonParams.getUid());
        endHm.put("device", commonParams.getDevice());

        Http endReq = new Http();
        endReq.setUrl(commonParams.getServer() + Constants.NOTIFY_URL);
        endReq.setMethod(HttpRequest.METHOD_POST);
        endReq.setParams(endHm);
        endReq.execute();


        cur.close();
    }