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:com.goliathonline.android.kegbot.io.RemoteTapHandler.java

private static ContentValues queryTapDetails(Uri uri, ContentResolver resolver) {
    final ContentValues values = new ContentValues();
    final Cursor cursor = resolver.query(uri, TapsQuery.PROJECTION, null, null, null);
    try {//  ww  w .  j  ava  2s .c o  m
        if (cursor.moveToFirst()) {
            values.put(SyncColumns.UPDATED, cursor.getLong(TapsQuery.UPDATED));
        } else {
            values.put(SyncColumns.UPDATED, KegbotContract.UPDATED_NEVER);
        }
    } finally {
        cursor.close();
    }
    return values;
}

From source file:ca.mudar.parkcatcher.utils.ParserUtils.java

/**
 * Query and return the newest {@link SyncColumns#UPDATED} time for all
 * entries under the requested {@link Uri}. Expects the {@link Uri} to
 * reference a directory of several items.
 *///from  w  w w  . ja v  a2 s .  c o  m
public static long queryDirUpdated(Uri uri, ContentResolver resolver) {
    final String[] projection = { "MAX(" + SyncColumns.UPDATED + ")" };
    final Cursor cursor = resolver.query(uri, projection, null, null, null);
    try {
        cursor.moveToFirst();
        return cursor.getLong(0);
    } finally {
        cursor.close();
    }
}

From source file:com.goliathonline.android.kegbot.io.RemoteDrinksHandler.java

private static ContentValues queryDrinkDetails(Uri uri, ContentResolver resolver) {
    final ContentValues values = new ContentValues();
    final Cursor cursor = resolver.query(uri, SessionsQuery.PROJECTION, null, null, null);
    try {//from www .  j  a v  a 2  s.co  m
        if (cursor.moveToFirst()) {
            values.put(SyncColumns.UPDATED, cursor.getLong(SessionsQuery.UPDATED));
            values.put(Drinks.DRINK_STARRED, cursor.getInt(SessionsQuery.STARRED));
        } else {
            values.put(SyncColumns.UPDATED, KegbotContract.UPDATED_NEVER);
        }
    } finally {
        cursor.close();
    }
    return values;
}

From source file:ca.mudar.parkcatcher.utils.ParserUtils.java

/**
 * Query and return the {@link SyncColumns#UPDATED} time for the requested
 * {@link Uri}. Expects the {@link Uri} to reference a single item.
 *//*from   www  .  j  a v  a2 s  .c o  m*/
public static long queryItemUpdated(Uri uri, ContentResolver resolver) {
    final String[] projection = { SyncColumns.UPDATED };
    final Cursor cursor = resolver.query(uri, projection, null, null, null);
    try {
        if (cursor.moveToFirst()) {
            return cursor.getLong(0);
        } else {
            return ParkingContract.UPDATED_NEVER;
        }
    } finally {
        cursor.close();
    }
}

From source file:edu.stanford.mobisocial.dungbeetle.social.FriendRequest.java

/**
 * Returns the contact id for the contact associated with the given uri,
 * or -1 if no such contact exists./*from  w w  w. ja  va  2s.  c o m*/
 */
public static long getExistingContactId(Context context, Uri friendRequest) {
    String personId = null;
    try {
        String pubKeyStr = friendRequest.getQueryParameter("publicKey");
        PublicKey key = RSACrypto.publicKeyFromString(pubKeyStr);
        personId = Util.makePersonIdForPublicKey(key);
    } catch (Exception e) {
        return -1;
    }
    Uri uri = Uri.parse(DungBeetleContentProvider.CONTENT_URI + "/contacts");
    String[] projection = new String[] { Contact._ID };
    String selection = Contact.PERSON_ID + " = ?";
    String[] selectionArgs = new String[] { personId };
    String sortOrder = null;
    Cursor c = context.getContentResolver().query(uri, projection, selection, selectionArgs, sortOrder);
    if (!c.moveToFirst()) {
        return -1;
    }
    return c.getLong(0);
}

From source file:Main.java

protected static long findThreadId(Context context, String messageId) {
    StringBuilder sb = new StringBuilder('(');
    sb.append(Telephony.Mms.MESSAGE_ID);
    sb.append('=');
    sb.append(DatabaseUtils.sqlEscapeString(messageId));
    sb.append(" AND ");
    sb.append(Telephony.Mms.MESSAGE_TYPE);
    sb.append('=');
    sb.append(MESSAGE_TYPE_SEND_REQ);//  w  w  w .  j  a  va 2 s  .  c  o m

    // TODO ContentResolver.query() appends closing ')' to the selection argument
    // sb.append(')');

    Cursor cursor = context.getContentResolver().query(Telephony.Mms.CONTENT_URI,
            new String[] { Telephony.Mms.THREAD_ID }, sb.toString(), null, null);

    if (cursor != null) {
        try {
            if ((cursor.getCount() == 1) && cursor.moveToFirst()) {
                return cursor.getLong(0);
            }
        } finally {
            cursor.close();
        }
    }

    return -1;
}

From source file:Main.java

public static long getLastProgramEndTimeMillis(ContentResolver resolver, Uri channelUri) {
    Uri uri = TvContract.buildProgramsUriForChannel(channelUri);
    String[] projection = { Programs.COLUMN_END_TIME_UTC_MILLIS };
    Cursor cursor = null;
    try {/*from  ww w . j a va  2 s  .  c  om*/
        // TvProvider returns programs chronological order by default.
        cursor = resolver.query(uri, projection, null, null, null);
        if (cursor == null || cursor.getCount() == 0) {
            return 0;
        }
        cursor.moveToLast();
        return cursor.getLong(0);
    } catch (Exception e) {
        Log.w(TAG, "Unable to get last program end time for " + channelUri, e);
    } finally {
        if (cursor != null) {
            cursor.close();
        }
    }
    return 0;
}

From source file:com.rp.justcast.video.VideoProvider.java

public static List<MediaInfo> buildMedia() throws JSONException {

    if (null != mediaList) {
        return mediaList;
    }//  w w w  . ja  v a 2s . com

    String[] columns = { MediaStore.Video.Media._ID, MediaStore.Video.Media.DATA, MediaStore.Video.Media.TITLE,
            MediaStore.Video.Media.DURATION };
    String orderBy = MediaStore.Images.Media.DATE_TAKEN + " desc";
    Cursor videoCursor = null;
    try {
        videoCursor = JustCast.getmAppContext().getContentResolver()
                .query(MediaStore.Video.Media.EXTERNAL_CONTENT_URI, columns, null, null, orderBy);
        videoCursor.moveToFirst();
        long fileId = videoCursor.getLong(videoCursor.getColumnIndex(MediaStore.Video.Media._ID));
        Log.w(TAG, "Building Media");
        Log.w(TAG, "Video Count" + videoCursor.getCount());
        int count = videoCursor.getCount();
        Log.d(TAG, "Count of images" + count);
        mediaList = new ArrayList<MediaInfo>();
        for (int i = 0; i < count; i++) {
            videoCursor.moveToPosition(i);
            int dataColumnIndex = videoCursor.getColumnIndex(MediaStore.Video.Media.DATA);
            int titleIndex = videoCursor.getColumnIndex(MediaStore.Video.Media.TITLE);
            Log.w(TAG, "Video added" + videoCursor.getString(dataColumnIndex));
            String path = videoCursor.getString(dataColumnIndex);
            String title = videoCursor.getString(titleIndex);
            MediaMetadata movieMetadata = new MediaMetadata(MediaMetadata.MEDIA_TYPE_MOVIE);
            movieMetadata.putString("VIDEO_PATH", path);
            movieMetadata.putString(MediaMetadata.KEY_SUBTITLE, title);
            movieMetadata.putString(MediaMetadata.KEY_TITLE, title);
            movieMetadata.putString(MediaMetadata.KEY_STUDIO, title);
            path = JustCast.addJustCastServerParam(path);
            MediaInfo mediaInfo = new MediaInfo.Builder(path).setStreamType(MediaInfo.STREAM_TYPE_BUFFERED)
                    .setContentType(getMediaType()).setMetadata(movieMetadata).build();
            mediaList.add(mediaInfo);
        }
    } finally {
        videoCursor.close();
    }
    return mediaList;
}

From source file:net.sf.sprockets.database.Cursors.java

/**
 * Get all long values in the first column.
 *
 * @param close true to close the cursor or false to leave it open
 *///  w ww  .j ava2  s . co m
public static long[] allLongs(Cursor cursor, boolean close) {
    long[] l = EMPTY_LONG_ARRAY;
    if (cursor.moveToFirst()) {
        l = new long[cursor.getCount()];
        do {
            l[cursor.getPosition()] = cursor.getLong(0);
        } while (cursor.moveToNext());
    }
    close(cursor, close);
    return l;
}

From source file:com.docd.purefm.test.MediaStoreUtilsTest.java

private static boolean isFileInMediaStore(final ContentResolver resolver, final GenericFile file) {
    final Uri uri = MediaStoreUtils.getContentUri(file);
    final Pair<String, String[]> selection = MediaStoreUtils.dataSelection(file.toFile());
    final Cursor c = resolver.query(uri, new String[] { MediaStore.Files.FileColumns._ID }, selection.first,
            selection.second, null);/* ww  w. j  av a2s . c o m*/
    if (c != null) {
        try {
            if (c.moveToFirst()) {
                return c.getLong(0) != 0;
            }
        } finally {
            c.close();
        }
    }
    return false;
}