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:org.zoumbox.mh_dla_notifier.sp.PublicScriptsProxy.java

public static List<MhSpRequest> listLatestRequests(Context context, String trollId, int count) {
    List<MhSpRequest> result = new ArrayList<MhSpRequest>();

    String query = String.format(SQL_LIST_REQUESTS, count);

    MhDlaSQLHelper helper = new MhDlaSQLHelper(context);
    SQLiteDatabase database = helper.getReadableDatabase();

    Calendar calendar = Calendar.getInstance();

    Cursor cursor = database.rawQuery(query, new String[] { trollId });
    while (cursor.moveToNext()) {
        long startTimeMillis = cursor.getLong(0);
        long endTimeMillis = cursor.getLong(1);
        String scriptName = cursor.getString(2);
        String status = cursor.getString(3);

        calendar.setTimeInMillis(startTimeMillis);
        Date date = calendar.getTime();
        PublicScript script = PublicScript.valueOf(scriptName);

        long duration = 0;
        if (endTimeMillis > 0) {
            duration = endTimeMillis - startTimeMillis;
        }//from  ww  w.  ja  va  2s. c  om
        MhSpRequest request = new MhSpRequest(date, duration, script, status);
        result.add(request);
    }

    cursor.close();
    database.close();

    return result;
}

From source file:com.nbos.phonebook.sync.platform.ContactManager.java

/**
 * Returns the Data id for a sample SyncAdapter contact's profile row, or 0
 * if the sample SyncAdapter user isn't found.
 * //from ww w.  j a  va2s. co  m
 * @param resolver a content resolver
 * @param userId the sample SyncAdapter user ID to lookup
 * @return the profile Data row id, or 0 if not found
 */
private static long lookupProfile(ContentResolver resolver, long userId) {
    long profileId = 0;
    final Cursor c = resolver.query(Data.CONTENT_URI, ProfileQuery.PROJECTION, ProfileQuery.SELECTION,
            new String[] { String.valueOf(userId) }, null);
    try {
        if (c != null && c.moveToFirst()) {
            profileId = c.getLong(ProfileQuery.COLUMN_ID);
        }
    } finally {
        if (c != null) {
            c.close();
        }
    }
    return profileId;
}

From source file:com.deliciousdroid.platform.ContactManager.java

/**
 * Returns the Data id for a sample SyncAdapter contact's profile row, or 0
 * if the sample SyncAdapter user isn't found.
 * // w  w w.  ja v a  2  s .c  om
 * @param resolver a content resolver
 * @param userId the sample SyncAdapter user ID to lookup
 * @return the profile Data row id, or 0 if not found
 */
private static long lookupProfile(ContentResolver resolver, String userName) {
    long profileId = 0;
    final Cursor c = resolver.query(Data.CONTENT_URI, ProfileQuery.PROJECTION, ProfileQuery.SELECTION,
            new String[] { userName }, null);
    try {
        if (c != null && c.moveToFirst()) {
            profileId = c.getLong(ProfileQuery.COLUMN_ID);
            Log.d("ProfileLookup", Long.toString(c.getLong(ProfileQuery.COLUMN_ID)));
        }
    } finally {
        if (c != null) {
            c.close();
        }
    }
    return profileId;
}

From source file:com.cyanogenmod.filemanager.util.MediaHelper.java

/**
 * Method that converts a file reference to a content uri reference
 *
 * @param cr A content resolver/*w w  w  . ja v  a 2  s  .  c  om*/
 * @param path The path to search
 * @param volume The volume
 * @return Uri The content uri or null if file not exists in the media database
 */
private static Uri fileToContentUri(ContentResolver cr, String path, String volume) {
    final String[] projection = { BaseColumns._ID, MediaStore.Files.FileColumns.MEDIA_TYPE };
    final String where = MediaColumns.DATA + " = ?";
    Uri baseUri = MediaStore.Files.getContentUri(volume);
    Cursor c = cr.query(baseUri, projection, where, new String[] { path }, null);
    try {
        if (c != null && c.moveToNext()) {
            int type = c.getInt(c.getColumnIndexOrThrow(MediaStore.Files.FileColumns.MEDIA_TYPE));
            if (type != 0) {
                // Do not force to use content uri for no media files
                long id = c.getLong(c.getColumnIndexOrThrow(BaseColumns._ID));
                return Uri.withAppendedPath(baseUri, String.valueOf(id));
            }
        }
    } finally {
        IOUtils.closeQuietly(c);
    }
    return null;
}

From source file:com.deliciousdroid.platform.ContactManager.java

private static long lookupHighWatermark(ContentResolver resolver, long id) {
    long result = 0;
    final Cursor c = resolver.query(RawContacts.CONTENT_URI, HighWatermarkQuery.PROJECTION,
            HighWatermarkQuery.SELECTION, new String[] { Long.toString(id) }, null);
    try {/* w  ww .j  av a2 s. c  om*/
        while (c.moveToNext()) {
            result = c.getLong(HighWatermarkQuery.COLUMN_ID);
        }
    } finally {
        if (c != null) {
            c.close();
        }
    }
    return result;
}

From source file:com.android.emailcommon.utility.AttachmentUtilities.java

/**
 * In support of deleting a mailbox, find all messages and delete their attachments.
 *
 * @param context/*from w ww . jav a  2s. c o m*/
 * @param accountId the account for the mailbox
 * @param mailboxId the mailbox for the messages
 */
public static void deleteAllMailboxAttachmentFiles(Context context, long accountId, long mailboxId) {
    Cursor c = context.getContentResolver().query(Message.CONTENT_URI, Message.ID_COLUMN_PROJECTION,
            MessageColumns.MAILBOX_KEY + "=?", new String[] { Long.toString(mailboxId) }, null);
    try {
        while (c.moveToNext()) {
            long messageId = c.getLong(Message.ID_PROJECTION_COLUMN);
            deleteAllAttachmentFiles(context, accountId, messageId);
        }
    } finally {
        c.close();
    }
}

From source file:org.zoumbox.mh_dla_notifier.sp.PublicScriptsProxy.java

public static List<MhSpRequest> listLatestRequestsSince(Context context, String trollId, int dayCount) {
    List<MhSpRequest> result = new ArrayList<MhSpRequest>();

    Calendar instance = Calendar.getInstance();
    instance.add(Calendar.HOUR_OF_DAY, dayCount * -24);
    Date sinceDate = instance.getTime();

    MhDlaSQLHelper helper = new MhDlaSQLHelper(context);
    SQLiteDatabase database = helper.getReadableDatabase();

    Calendar calendar = Calendar.getInstance();

    Cursor cursor = database.rawQuery(SQL_LIST_REQUESTS_SINCE,
            new String[] { trollId, "" + sinceDate.getTime() });
    while (cursor.moveToNext()) {
        long startTimeMillis = cursor.getLong(0);
        long endTimeMillis = cursor.getLong(1);
        String scriptName = cursor.getString(2);
        String status = cursor.getString(3);

        calendar.setTimeInMillis(startTimeMillis);
        Date date = calendar.getTime();
        PublicScript script = PublicScript.valueOf(scriptName);

        long duration = 0;
        if (endTimeMillis > 0) {
            duration = endTimeMillis - startTimeMillis;
        }//from w w w  .  j  a  va  2s. co m
        MhSpRequest request = new MhSpRequest(date, duration, script, status);
        result.add(request);
    }

    cursor.close();
    database.close();

    return result;
}

From source file:com.coinomi.wallet.ExchangeRatesProvider.java

public static ExchangeRate getExchangeRate(@Nonnull final Cursor cursor) {
    final String codeId = getCurrencyCodeId(cursor);
    final CoinType type = CoinID.typeFromSymbol(
            cursor.getString(cursor.getColumnIndexOrThrow(ExchangeRatesProvider.KEY_RATE_COIN_CODE)));
    final Value rateCoin = Value.valueOf(type,
            cursor.getLong(cursor.getColumnIndexOrThrow(ExchangeRatesProvider.KEY_RATE_COIN)));
    final String fiatCode = cursor
            .getString(cursor.getColumnIndexOrThrow(ExchangeRatesProvider.KEY_RATE_FIAT_CODE));
    final Value rateFiat = FiatValue.valueOf(fiatCode,
            cursor.getLong(cursor.getColumnIndexOrThrow(ExchangeRatesProvider.KEY_RATE_FIAT)));
    final String source = cursor.getString(cursor.getColumnIndexOrThrow(ExchangeRatesProvider.KEY_SOURCE));

    ExchangeRateBase rate = new ExchangeRateBase(rateCoin, rateFiat);
    return new ExchangeRate(rate, codeId, source);
}

From source file:edu.stanford.mobisocial.dungbeetle.ImageGalleryActivity.java

private static int binarySearch(Cursor c, long id, int colId) {
    long test;// ww w  .  j av a2 s  .  c  o m
    int first = 0;
    int max = c.getCount();
    while (first < max) {
        int mid = (first + max) / 2;
        c.moveToPosition(mid);
        test = c.getLong(colId);
        if (id > test) {
            max = mid;
        } else if (id < test) {
            first = mid + 1;
        } else {
            return mid;
        }
    }
    return 0;
}

From source file:org.zoumbox.mh_dla_notifier.sp.PublicScriptsProxy.java

public static Date geLastRequest(Context context, PublicScript script, String trollId) {

    MhDlaSQLHelper helper = new MhDlaSQLHelper(context);
    SQLiteDatabase database = helper.getReadableDatabase();

    Cursor cursor = database.rawQuery(SQL_LAST_REQUEST, new String[] { trollId, script.name() });
    Date result = null;/*from   w  w  w .  j a v a2  s. co  m*/
    if (cursor.getCount() > 0) {
        cursor.moveToFirst();
        long resultTimestamp = cursor.getLong(0);
        result = new Date(resultTimestamp);
    }

    cursor.close();
    database.close();

    String format = "Last request for category %s (script=%s) and troll=%s is: '%s'";
    String message = String.format(format, script.category, script, trollId, result);
    Log.d(TAG, message);

    return result;
}