Example usage for android.database Cursor getLong

List of usage examples for android.database Cursor getLong

Introduction

In this page you can find the example usage for android.database Cursor getLong.

Prototype

long getLong(int columnIndex);

Source Link

Document

Returns the value of the requested column as a long.

Usage

From source file:ro.weednet.contactssync.platform.ContactManager.java

public static long ensureGroupExists(Context context, Account account) {
    final ContentResolver resolver = context.getContentResolver();

    // Lookup the group
    long groupId = 0;
    final Cursor cursor = resolver.query(Groups.CONTENT_URI, new String[] { Groups._ID },
            Groups.ACCOUNT_NAME + "=? AND " + Groups.ACCOUNT_TYPE + "=? AND " + Groups.TITLE + "=?",
            new String[] { account.name, account.type, GROUP_NAME }, null);
    if (cursor != null) {
        try {/*  w w w .  j a  v  a 2 s  .  c  o  m*/
            if (cursor.moveToFirst()) {
                groupId = cursor.getLong(0);
            }
        } finally {
            cursor.close();
        }
    }

    if (groupId == 0) {
        // Group doesn't exist yet, so create it
        final ContentValues contentValues = new ContentValues();
        contentValues.put(Groups.ACCOUNT_NAME, account.name);
        contentValues.put(Groups.ACCOUNT_TYPE, account.type);
        contentValues.put(Groups.TITLE, GROUP_NAME);
        //   contentValues.put(Groups.GROUP_IS_READ_ONLY, true);
        contentValues.put(Groups.GROUP_VISIBLE, true);

        final Uri newGroupUri = resolver.insert(Groups.CONTENT_URI, contentValues);
        groupId = ContentUris.parseId(newGroupUri);
    }
    return groupId;
}

From source file:com.android.dialer.calllog.ContactInfoHelper.java

/**
 * Returns the contact information stored in an entry of the call log.
 *
 * @param c A cursor pointing to an entry in the call log.
 *//*from   ww  w.j a v a  2s  . c  o  m*/
public static ContactInfo getContactInfo(Cursor c) {
    ContactInfo info = new ContactInfo();

    info.lookupUri = UriUtils.parseUriOrNull(c.getString(CallLogQuery.CACHED_LOOKUP_URI));
    info.name = c.getString(CallLogQuery.CACHED_NAME);
    info.type = c.getInt(CallLogQuery.CACHED_NUMBER_TYPE);
    info.label = c.getString(CallLogQuery.CACHED_NUMBER_LABEL);
    String matchedNumber = c.getString(CallLogQuery.CACHED_MATCHED_NUMBER);
    info.number = matchedNumber == null ? c.getString(CallLogQuery.NUMBER) : matchedNumber;
    info.normalizedNumber = c.getString(CallLogQuery.CACHED_NORMALIZED_NUMBER);
    info.photoId = c.getLong(CallLogQuery.CACHED_PHOTO_ID);
    info.photoUri = UriUtils
            .nullForNonContactsUri(UriUtils.parseUriOrNull(c.getString(CallLogQuery.CACHED_PHOTO_URI)));
    info.formattedNumber = c.getString(CallLogQuery.CACHED_FORMATTED_NUMBER);

    return info;
}

From source file:edu.mit.mobile.android.locast.data.JsonSyncableItem.java

/**
 * Given a public Uri fragment, finds the local item representing it. If there isn't any such item, null is returned.
 *
 * @param context//from   w  ww.j a v  a  2  s.  co m
 * @param dirUri the base local URI to search.
 * @param pubUri A public URI fragment that represents the given item. This must match the result from the API.
 * @return a local URI matching the item or null if none were found.
 */
public static Uri getItemByPubIUri(Context context, Uri dirUri, String pubUri) {
    Uri uri = null;
    final ContentResolver cr = context.getContentResolver();

    final String[] selectionArgs = { pubUri };
    final Cursor c = cr.query(dirUri, PUB_URI_PROJECTION, _PUBLIC_URI + "=?", selectionArgs, null);
    if (c.moveToFirst()) {
        uri = ContentUris.withAppendedId(dirUri, c.getLong(c.getColumnIndex(_ID)));
    }

    c.close();
    return uri;
}

From source file:org.c99.SyncProviderDemo.ContactsSyncAdapterService.java

private static void updateContactStatus(ArrayList<ContentProviderOperation> operationList, long rawContactId,
        String status) {//from  w w w . j ava 2s. c o  m
    Uri rawContactUri = ContentUris.withAppendedId(RawContacts.CONTENT_URI, rawContactId);
    Uri entityUri = Uri.withAppendedPath(rawContactUri, Entity.CONTENT_DIRECTORY);
    Cursor c = mContentResolver.query(entityUri,
            new String[] { RawContacts.SOURCE_ID, Entity.DATA_ID, Entity.MIMETYPE, Entity.DATA1 }, null, null,
            null);
    try {
        while (c.moveToNext()) {
            if (!c.isNull(1)) {
                String mimeType = c.getString(2);

                if (mimeType.equals("vnd.android.cursor.item/vnd.org.c99.SyncProviderDemo.profile")) {
                    ContentProviderOperation.Builder builder = ContentProviderOperation
                            .newInsert(ContactsContract.StatusUpdates.CONTENT_URI);
                    builder.withValue(ContactsContract.StatusUpdates.DATA_ID, c.getLong(1));
                    builder.withValue(ContactsContract.StatusUpdates.STATUS, status);
                    builder.withValue(ContactsContract.StatusUpdates.STATUS_RES_PACKAGE,
                            "org.c99.SyncProviderDemo");
                    builder.withValue(ContactsContract.StatusUpdates.STATUS_LABEL, R.string.app_name);
                    builder.withValue(ContactsContract.StatusUpdates.STATUS_ICON, R.drawable.logo);
                    builder.withValue(ContactsContract.StatusUpdates.STATUS_TIMESTAMP,
                            System.currentTimeMillis());
                    operationList.add(builder.build());

                    //Only change the text of our custom entry to the status message pre-Honeycomb, as the newer contacts app shows
                    //statuses elsewhere
                    if (Integer.decode(Build.VERSION.SDK) < 11) {
                        builder = ContentProviderOperation.newUpdate(ContactsContract.Data.CONTENT_URI);
                        builder.withSelection(BaseColumns._ID + " = '" + c.getLong(1) + "'", null);
                        builder.withValue(ContactsContract.Data.DATA3, status);
                        operationList.add(builder.build());
                    }
                }
            }
        }
    } finally {
        c.close();
    }
}

From source file:ro.weednet.contactssync.platform.ContactManager.java

public static void updateContactPhotoHd(Context context, ContentResolver resolver, long rawContactId,
        ContactPhoto photo, BatchOperation batchOperation) {
    final Cursor c = resolver.query(DataQuery.CONTENT_URI, DataQuery.PROJECTION,
            Data.RAW_CONTACT_ID + "=? AND " + Data.MIMETYPE + "=?",
            new String[] { String.valueOf(rawContactId), Photo.CONTENT_ITEM_TYPE }, null);
    final ContactOperations contactOp = ContactOperations.updateExistingContact(context, rawContactId, true,
            batchOperation);/*from   w ww.  j a v  a  2 s  . c  om*/

    if ((c != null) && c.moveToFirst()) {
        final long id = c.getLong(DataQuery.COLUMN_ID);
        final Uri uri = ContentUris.withAppendedId(Data.CONTENT_URI, id);
        contactOp.updateAvatar(c.getString(DataQuery.COLUMN_DATA1), photo.getPhotoUrl(), uri);
        c.close();
    } else {
        Log.i(TAG, "creating row, count: " + c.getCount());
        contactOp.addAvatar(photo.getPhotoUrl());
    }
    Log.d(TAG, "updating check timestamp");
    final Uri uri = ContentUris.withAppendedId(RawContacts.CONTENT_URI, rawContactId);
    contactOp.updateSyncTimestamp1(System.currentTimeMillis(), uri);
}

From source file:com.liferay.alerts.model.User.java

public User(Cursor cursor) {
    _id = cursor.getLong(cursor.getColumnIndex(ID));
    _uuid = cursor.getString(cursor.getColumnIndex(UUID));
    _fullName = cursor.getString(cursor.getColumnIndex(FULL_NAME));
    _portraitId = cursor.getLong(cursor.getColumnIndex(PORTRAIT_ID));
}

From source file:com.almarsoft.GroundhogReader.lib.DBUtils.java

public static Vector<Object> isHeaderInDatabase(Long number, String group, Context context) {
    int groupid = getGroupIdFromName(group, context);

    DBHelper db = new DBHelper(context);
    SQLiteDatabase dbread = db.getReadableDatabase();
    Vector<Object> retVal = null;

    String q = "SELECT _id, server_article_id FROM headers WHERE subscribed_group_id=" + groupid
            + " AND server_article_number=" + number;
    Cursor c = dbread.rawQuery(q, null);
    int count = c.getCount();

    if (count > 0) {
        c.moveToFirst();//ww  w.  j av  a 2  s .c o  m
        retVal = new Vector<Object>(2);
        retVal.add(c.getLong(0));
        retVal.add(c.getString(1));
    }

    c.close();
    dbread.close();
    db.close();

    return retVal;
}

From source file:com.almarsoft.GroundhogReader.lib.DBUtils.java

public static Vector<Long> getUnreadNoncatchedArticleList(String group, Context context) {
    int groupid = getGroupIdFromName(group, context);

    Vector<Long> artList = null;
    DBHelper db = new DBHelper(context);
    SQLiteDatabase dbread = db.getReadableDatabase();

    String q = "SELECT server_article_number FROM headers WHERE subscribed_group_id=" + groupid
            + " AND read=0 AND catched=0";
    Cursor c = dbread.rawQuery(q, null);

    int count = c.getCount();
    artList = new Vector<Long>(count);

    c.moveToFirst();//w  w w.ja v  a2  s  .c  o m

    for (int i = 0; i < count; i++) {
        artList.add(c.getLong(0));
        c.moveToNext();
    }

    c.close();
    dbread.close();
    db.close();
    return artList;
}

From source file:cn.code.notes.gtask.data.SqlData.java

private void loadFromCursor(Cursor c) {
    mDataId = c.getLong(DATA_ID_COLUMN);
    mDataMimeType = c.getString(DATA_MIME_TYPE_COLUMN);
    mDataContent = c.getString(DATA_CONTENT_COLUMN);
    mDataContentData1 = c.getLong(DATA_CONTENT_DATA_1_COLUMN);
    mDataContentData3 = c.getString(DATA_CONTENT_DATA_3_COLUMN);
}

From source file:cn.code.notes.gtask.data.SqlConn.java

private void loadFromCursor(Cursor c) {
    mGuid = c.getString(GUID_COLUMN);
    mId = c.getLong(ID_COLUMN);
    mDataMD5 = c.getString(MD5_COLUMN);

}