Example usage for android.database Cursor moveToLast

List of usage examples for android.database Cursor moveToLast

Introduction

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

Prototype

boolean moveToLast();

Source Link

Document

Move the cursor to the last row.

Usage

From source file:net.willwebberley.gowertides.utils.WeatherDatabase.java

public Cursor getWeatherInfo(Calendar dayToGet) {
    SQLiteDatabase db = this.getReadableDatabase();
    int year = dayToGet.get(Calendar.YEAR);
    int month = dayToGet.get(Calendar.MONTH) + 1;
    int day = dayToGet.get(Calendar.DAY_OF_MONTH);

    try {/*www . java 2 s .  c  om*/
        Cursor result = db.rawQuery("SELECT * FROM weather WHERE year = " + year + " AND MONTH = " + month
                + " AND DAY = " + day + " ORDER BY timestamp", null);
        result.moveToLast();
        return result;
    } catch (Exception e) {
        System.out.println(e);
        return null;
    }
}

From source file:com.yuntongxun.ecdemo.storage.IMessageSqlManager.java

/**
 * ??ID????// www  .j  ava2 s  .c o  m
 *
 * @param threadId ??ID
 * @return ?
 */
public static int getTotalCount(long threadId) {
    String sql = "SELECT COUNT(*) FROM " + DatabaseHelper.TABLES_NAME_IM_MESSAGE + " WHERE " + "sid" + "="
            + threadId;
    Cursor cursor = getInstance().sqliteDB().rawQuery(sql, null);
    int count = 0;
    if (cursor.moveToLast()) {
        count = cursor.getInt(0);
    }
    cursor.close();
    return count;
}

From source file:com.klinker.android.twitter.utils.NotificationUtils.java

private static NotificationCompat.InboxStyle getDMInboxStyle(int numberNew, int accountNumber, Context context,
        String title) {/*from w  ww  . j av  a  2  s  .c  om*/
    NotificationCompat.InboxStyle style = new NotificationCompat.InboxStyle();

    Cursor cursor = DMDataSource.getInstance(context).getCursor(accountNumber);
    if (!cursor.moveToLast()) {
        return style;
    }

    AppSettings settings = AppSettings.getInstance(context);

    if (numberNew > 5) {
        if (numberNew - 5 == 1) {
            style.setSummaryText("+" + (numberNew - 5) + " " + context.getString(R.string.new_direct_message));
        } else {
            style.setSummaryText("+" + (numberNew - 5) + " " + context.getString(R.string.new_direct_messages));
        }

        for (int i = 0; i < 5; i++) {
            String handle = cursor.getString(cursor.getColumnIndex(DMSQLiteHelper.COLUMN_SCREEN_NAME));
            String text = cursor.getString(cursor.getColumnIndex(DMSQLiteHelper.COLUMN_TEXT));
            String longText = "<b>@" + handle + "</b>: " + text;

            style.addLine(Html.fromHtml(
                    settings.addonTheme ? longText.replaceAll("FF8800", settings.accentColor) : longText));

            cursor.moveToPrevious();
        }
    } else {

        for (int i = 0; i < numberNew; i++) {
            String handle = cursor.getString(cursor.getColumnIndex(DMSQLiteHelper.COLUMN_SCREEN_NAME));
            String text = cursor.getString(cursor.getColumnIndex(DMSQLiteHelper.COLUMN_TEXT));
            String longText = "<b>@" + handle + "</b>: " + text;

            style.addLine(Html.fromHtml(
                    settings.addonTheme ? longText.replaceAll("FF8800", settings.accentColor) : longText));

            cursor.moveToPrevious();
        }
    }

    style.setBigContentTitle(title);

    return style;
}

From source file:com.klinker.android.twitter.utils.NotificationUtils.java

private static NotificationCompat.InboxStyle getMentionsInboxStyle(int numberNew, int accountNumber,
        Context context, String title) {
    NotificationCompat.InboxStyle style = new NotificationCompat.InboxStyle();

    Cursor cursor = MentionsDataSource.getInstance(context).getCursor(accountNumber);
    if (!cursor.moveToLast()) {
        return style;
    }/*from w ww.  ja  v  a2 s.  c  o  m*/

    AppSettings settings = AppSettings.getInstance(context);

    if (numberNew > 5) {
        if (numberNew - 5 == 1) {
            style.setSummaryText("+" + (numberNew - 5) + " " + context.getString(R.string.new_mention));
        } else {
            style.setSummaryText("+" + (numberNew - 5) + " " + context.getString(R.string.new_mentions));
        }

        for (int i = 0; i < 5; i++) {
            String handle = cursor.getString(cursor.getColumnIndex(MentionsSQLiteHelper.COLUMN_SCREEN_NAME));
            String text = cursor.getString(cursor.getColumnIndex(MentionsSQLiteHelper.COLUMN_TEXT));
            String longText = "<b>@" + handle + "</b>: " + text;

            style.addLine(Html.fromHtml(
                    settings.addonTheme ? longText.replaceAll("FF8800", settings.accentColor) : longText));

            cursor.moveToPrevious();
        }
    } else {

        for (int i = 0; i < numberNew; i++) {
            String handle = cursor.getString(cursor.getColumnIndex(MentionsSQLiteHelper.COLUMN_SCREEN_NAME));
            String text = cursor.getString(cursor.getColumnIndex(MentionsSQLiteHelper.COLUMN_TEXT));
            String longText = "<b>@" + handle + "</b>: " + text;

            style.addLine(Html.fromHtml(
                    settings.addonTheme ? longText.replaceAll("FF8800", settings.accentColor) : longText));

            cursor.moveToPrevious();
        }
    }

    style.setBigContentTitle(title);

    return style;
}

From source file:com.haibison.android.anhuu.BaseFileAdapter.java

/**
 * Gets the short name of this path./*from  w w  w  . j  a  v  a  2  s .  com*/
 * 
 * @return the path name, can be {@code null} if there is no data.
 */
public String getPathName() {
    Cursor cursor = getCursor();
    if (cursor == null || !cursor.moveToLast())
        return null;
    return BaseFileProviderUtils.getFileName(cursor);
}

From source file:net.mutina.uclimb.ForegroundCameraLauncher.java

/**
 * Used to find out if we are in a situation where the Camera Intent adds to images
 * to the content store. If we are using a FILE_URI and the number of images in the DB 
 * increases by 2 we have a duplicate, when using a DATA_URL the number is 1.
 */// ww w  .  j a va2s .  c o  m
private void checkForDuplicateImage() {
    int diff = 2;
    Cursor cursor = queryImgDB();
    int currentNumOfImages = cursor.getCount();

    // delete the duplicate file if the difference is 2 for file URI or 1 for Data URL
    if ((currentNumOfImages - numPics) == diff) {
        cursor.moveToLast();
        int id = Integer.valueOf(cursor.getString(cursor.getColumnIndex(MediaStore.Images.Media._ID))) - 1;
        Uri uri = Uri.parse(MediaStore.Images.Media.EXTERNAL_CONTENT_URI + "/" + id);
        this.ctx.getContentResolver().delete(uri, null, null);
    }
}

From source file:mai.whack.StickyNotesActivity.java

private void onDataWrite(Intent intent) {
    byte[] tagId = intent.getByteArrayExtra(NfcAdapter.EXTRA_ID);
    Cursor mCur = this.managedQuery(Browser.BOOKMARKS_URI, Browser.HISTORY_PROJECTION, null, null, "DATE");
    // mCur.moveToFirst();
    if (mCur.moveToLast() && mCur.getCount() > 0) {
        String url = mCur.getString(Browser.HISTORY_PROJECTION_URL_INDEX);
        mHttpPostThread = new HttpPostThread(toHex(tagId), "tabs", url);
        mHttpPostThread.start();/*  w w  w  .j  a  v  a 2 s  . c  om*/
    }
}

From source file:co.mwater.foregroundcameraplugin.ForegroundCameraLauncher.java

/**
 * Used to find out if we are in a situation where the Camera Intent adds to
 * images to the content store. If we are using a FILE_URI and the number of
 * images in the DB increases by 2 we have a duplicate, when using a
 * DATA_URL the number is 1./*from www. j  ava 2 s  .co m*/
 */
private void checkForDuplicateImage() {
    int diff = 2;
    Cursor cursor = queryImgDB();
    int currentNumOfImages = cursor.getCount();

    // delete the duplicate file if the difference is 2 for file URI or 1
    // for Data URL
    if ((currentNumOfImages - numPics) == diff) {
        cursor.moveToLast();
        int id = Integer.valueOf(cursor.getString(cursor.getColumnIndex(MediaStore.Images.Media._ID))) - 1;
        Uri uri = Uri.parse(MediaStore.Images.Media.EXTERNAL_CONTENT_URI + "/" + id);
        this.cordova.getActivity().getContentResolver().delete(uri, null, null);
    }
}

From source file:org.apache.cordova.Capture.java

/**
 * Used to find out if we are in a situation where the Camera Intent adds to images
 * to the content store.//from  w  ww. j a  v  a2s .c  om
 */
private void checkForDuplicateImage() {
    Uri contentStore = whichContentStore();
    Cursor cursor = queryImgDB(contentStore);
    int currentNumOfImages = cursor.getCount();

    // delete the duplicate file if the difference is 2
    if ((currentNumOfImages - numPics) == 2) {
        cursor.moveToLast();
        int id = Integer.valueOf(cursor.getString(cursor.getColumnIndex(MediaStore.Images.Media._ID))) - 1;
        Uri uri = Uri.parse(contentStore + "/" + id);
        this.cordova.getActivity().getContentResolver().delete(uri, null, null);
    }
}

From source file:com.nonninz.robomodel.RoboManager.java

private long getLastId() throws InstanceNotFoundException {
    final SQLiteDatabase db = mDatabaseManager.openOrCreateDatabase(getDatabaseName());

    final String columns[] = new String[] { BaseColumns._ID };
    Cursor query;
    /*//from  w  w  w . java 2  s. c  om
     * Try the query. If the Table doesn't exist, fix the DB and re-run the query.
     */
    try {
        query = db.query(getTableName(), columns, null, null, null, null, null);
    } catch (final SQLiteException e) {
        prepareTable(db);
        query = db.query(getTableName(), columns, null, null, null, null, null);
    }

    if (query.moveToLast()) {
        final int columnIndex = query.getColumnIndex(BaseColumns._ID);
        return query.getLong(columnIndex);
    } else {
        throw new InstanceNotFoundException("table " + getTableName() + " is empty");
    }
}