Example usage for android.database Cursor isAfterLast

List of usage examples for android.database Cursor isAfterLast

Introduction

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

Prototype

boolean isAfterLast();

Source Link

Document

Returns whether the cursor is pointing to the position after the last row.

Usage

From source file:org.getlantern.firetweet.util.Utils.java

public static String[] getAccountNames(final Context context, final long[] accountIds) {
    if (context == null)
        return new String[0];
    final String[] cols = new String[] { Accounts.NAME };
    final String where = accountIds != null
            ? Expression.in(new Column(Accounts.ACCOUNT_ID), new RawItemArray(accountIds)).getSQL()
            : null;/*  w w  w.  j av  a2  s . c  o  m*/
    final Cursor cur = ContentResolverUtils.query(context.getContentResolver(), Accounts.CONTENT_URI, cols,
            where, null, null);
    if (cur == null)
        return new String[0];
    try {
        cur.moveToFirst();
        final String[] names = new String[cur.getCount()];
        int i = 0;
        while (!cur.isAfterLast()) {
            names[i++] = cur.getString(0);
            cur.moveToNext();
        }
        return names;
    } finally {
        cur.close();
    }
}

From source file:org.getlantern.firetweet.util.Utils.java

public static String[] getAccountScreenNames(final Context context, final long[] accountIds,
        final boolean includeAtChar) {
    if (context == null)
        return new String[0];
    final String[] cols = new String[] { Accounts.SCREEN_NAME };
    final String where = accountIds != null
            ? Expression.in(new Column(Accounts.ACCOUNT_ID), new RawItemArray(accountIds)).getSQL()
            : null;//from  ww w . j  a  v a2s.c o  m
    final Cursor cur = ContentResolverUtils.query(context.getContentResolver(), Accounts.CONTENT_URI, cols,
            where, null, null);
    if (cur == null)
        return new String[0];
    try {
        cur.moveToFirst();
        final String[] screen_names = new String[cur.getCount()];
        int i = 0;
        while (!cur.isAfterLast()) {
            screen_names[i++] = cur.getString(0);
            cur.moveToNext();
        }
        return screen_names;
    } finally {
        cur.close();
    }
}

From source file:org.getlantern.firetweet.util.Utils.java

public static long[] getAllStatusesIds(final Context context, final Uri uri) {
    if (context == null)
        return new long[0];
    final ContentResolver resolver = context.getContentResolver();
    final Cursor cur = ContentResolverUtils.query(resolver, uri, new String[] { Statuses.STATUS_ID },
            buildStatusFilterWhereClause(getTableNameByUri(uri), null).getSQL(), null, null);
    if (cur == null)
        return new long[0];
    final long[] ids = new long[cur.getCount()];
    cur.moveToFirst();//w  w w  .j a  v  a2 s  .co  m
    int i = 0;
    while (!cur.isAfterLast()) {
        ids[i] = cur.getLong(0);
        cur.moveToNext();
        i++;
    }
    cur.close();
    return ids;
}

From source file:com.rener.sea.DBHelper.java

public List<User> getAllUsers() {
    SQLiteDatabase db = getReadableDatabase();
    Cursor cursor = db.query(DBSchema.TABLE_USERS, new String[] { DBSchema.USER_ID }, null, null, null, null,
            null, null);/* w w w.ja  va 2s . c om*/
    ArrayList<User> users;
    users = new ArrayList<>();
    if ((cursor != null) && (cursor.getCount() > 0)) {

        for (cursor.moveToFirst(); !cursor.isAfterLast(); cursor.moveToNext()) {
            users.add(new User(cursor.getLong(0), this));
        }

        db.close();
        cursor.close();

    }
    return users;

}

From source file:org.getlantern.firetweet.util.Utils.java

public static boolean hasAccountSignedWithOfficialKeys(final Context context) {
    if (context == null)
        return false;
    final Cursor cur = ContentResolverUtils.query(context.getContentResolver(), Accounts.CONTENT_URI,
            Accounts.COLUMNS, null, null, null);
    if (cur == null)
        return false;
    final String[] keySecrets = context.getResources()
            .getStringArray(R.array.values_official_consumer_secret_crc32);
    final ParcelableAccount.Indices indices = new ParcelableAccount.Indices(cur);
    cur.moveToFirst();/*  w  w  w .  ja  v  a 2 s.c  o m*/
    final CRC32 crc32 = new CRC32();
    try {
        while (!cur.isAfterLast()) {
            final String consumerSecret = cur.getString(indices.consumer_secret);
            if (consumerSecret != null) {
                final byte[] consumerSecretBytes = consumerSecret.getBytes(Charset.forName("UTF-8"));
                crc32.update(consumerSecretBytes, 0, consumerSecretBytes.length);
                final long value = crc32.getValue();
                crc32.reset();
                for (final String keySecret : keySecrets) {
                    if (Long.parseLong(keySecret, 16) == value)
                        return true;
                }
            }
            cur.moveToNext();
        }
    } finally {
        cur.close();
    }
    return false;
}

From source file:com.rener.sea.DBHelper.java

public List<Option> getAllOptions(long itemID) {
    SQLiteDatabase db = getReadableDatabase();
    Cursor cursor = db.query(DBSchema.TABLE_OPTION, new String[] { DBSchema.OPTION_ID },
            DBSchema.OPTION_PARENT_ID + "=?", new String[] { String.valueOf(itemID) }, null, null, null, null);
    ArrayList<Option> options = new ArrayList<>();
    if ((cursor != null) && (cursor.getCount() > 0)) {

        for (cursor.moveToFirst(); !cursor.isAfterLast(); cursor.moveToNext()) {
            options.add(new Option(cursor.getLong(0), this));
        }/*from  w w  w. jav  a  2  s  .  c  om*/

    }
    return options;
}

From source file:com.rener.sea.DBHelper.java

public List<Item> getAllItems(long flowchartID) {
    SQLiteDatabase db = getReadableDatabase();
    long id = -1;
    Cursor cursor = db.query(DBSchema.TABLE_ITEM, new String[] { DBSchema.ITEM_ID },
            DBSchema.ITEM_FLOWCHART_ID + " =? ", new String[] { String.valueOf(flowchartID) }, null, null, null,
            null);// w w w  .  ja va2  s.  co  m
    ArrayList<Item> items = new ArrayList<>();
    if ((cursor != null) && (cursor.getCount() > 0)) {

        for (cursor.moveToFirst(); !cursor.isAfterLast(); cursor.moveToNext()) {
            items.add(new Item(cursor.getLong(0), this));
        }

    }
    return items;
}

From source file:com.rener.sea.DBHelper.java

public List<Appointment> getAllAppointments() {
    SQLiteDatabase db = getReadableDatabase();
    Cursor cursor = db.query(DBSchema.TABLE_APPOINTMENTS, new String[] { DBSchema.APPOINTMENT_ID }, null, null,
            null, null, "date(" + DBSchema.APPOINTMENT_DATE + ") DESC", null);
    ArrayList<Appointment> Appointments;
    Appointments = new ArrayList<>();
    if ((cursor != null) && (cursor.getCount() > 0)) {

        for (cursor.moveToFirst(); !cursor.isAfterLast(); cursor.moveToNext()) {
            Appointments.add(new Appointment(cursor.getLong(0), this,
                    context.getResources().getString(R.string.date_format_medium)));
        }/*from   w w w  .j a  v  a  2s.co m*/

        db.close();
        cursor.close();

    }
    return Appointments;

}

From source file:com.rener.sea.DBHelper.java

private JSONArray getCategory() {

    JSONArray data;//from  w ww. j  a  v  a 2s  .co  m
    data = new JSONArray();
    SQLiteDatabase db = getReadableDatabase();
    Cursor cursor = db.query(DBSchema.TABLE_CATEGORY,
            new String[] { DBSchema.CATEGORY_ID, DBSchema.CATEGORY_NAME }, DBSchema.MODIFIED + "=?",
            new String[] { DBSchema.MODIFIED_YES }, null, null, null, null);
    if (cursor.moveToFirst()) {
        if ((cursor != null) && (cursor.getCount() > 0))
            for (cursor.moveToFirst(); !cursor.isAfterLast(); cursor.moveToNext()) {
                JSONObject map = new JSONObject();
                try {
                    if (!cursor.isNull(0))
                        map.put(DBSchema.CATEGORY_ID, cursor.getString(0));
                } catch (JSONException e) {
                    e.printStackTrace();
                }
                try {
                    if (!cursor.isNull(1))
                        map.put(DBSchema.CATEGORY_NAME, cursor.getString(1));
                } catch (JSONException e) {
                    e.printStackTrace();
                }

                data.put(map);
            }
    }
    db.close();
    cursor.close();
    return data;

}

From source file:com.rener.sea.DBHelper.java

private JSONArray getSpecialization() {

    JSONArray data;/*from   w  w w.j av a  2  s .c om*/
    data = new JSONArray();
    SQLiteDatabase db = getReadableDatabase();
    Cursor cursor = db.query(DBSchema.TABLE_SPECIALIZATION,
            new String[] { DBSchema.SPECIALIZATION_ID, DBSchema.SPECIALIZATION_NAME }, DBSchema.MODIFIED + "=?",
            new String[] { DBSchema.MODIFIED_YES }, null, null, null, null);
    if (cursor.moveToFirst()) {
        if ((cursor != null) && (cursor.getCount() > 0))
            for (cursor.moveToFirst(); !cursor.isAfterLast(); cursor.moveToNext()) {
                JSONObject map = new JSONObject();
                try {
                    if (!cursor.isNull(0))
                        map.put(DBSchema.SPECIALIZATION_ID, cursor.getString(0));
                } catch (JSONException e) {
                    e.printStackTrace();
                }
                try {
                    if (!cursor.isNull(1))
                        map.put(DBSchema.SPECIALIZATION_NAME, cursor.getString(1));
                } catch (JSONException e) {
                    e.printStackTrace();
                }

                data.put(map);
            }
    }
    db.close();
    cursor.close();
    return data;

}