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:fr.eoit.parameter.Mining.java

@Override
public void onLoadFinished(Loader<Cursor> loader, Cursor cursor) {
    if (DbUtil.hasAtLeastOneRow(cursor) && loader.getId() == LOADER_ID) {

        Log.d(LOG_TAG, "Reading cursor...");

        while (!cursor.isAfterLast()) {
            AsteroidItemBean item = getItem(cursor);
            ItemBeanWithMaterials mineral = new ItemBeanWithMaterials();
            mineral.id = cursor//from www .ja  va  2  s.  c o m
                    .getInt(cursor.getColumnIndexOrThrow(ItemMaterials.COLUMN_NAME_MATERIAL_ITEM_ID));
            mineral.quantity = cursor.getInt(cursor.getColumnIndexOrThrow(ItemMaterials.COLUMN_NAME_QUANTITY));

            if (asteroids.containsKey(item.id)) {
                ((AsteroidItemBean) asteroids.get(item.id)).addMineral(mineral);
            } else {
                asteroids.append(item);
                item.addMineral(mineral);
            }

            cursor.moveToNext();
        }

        asteroidMap = new SparseArray<TreeSet<ItemBeanWithMaterials>>();
        asteroidMap.append(EOITConst.Items.TRITANIUM,
                new TreeSet<ItemBeanWithMaterials>(new AsteroidMineralComparator(EOITConst.Items.TRITANIUM)));
        asteroidMap.append(EOITConst.Items.PYERITE,
                new TreeSet<ItemBeanWithMaterials>(new AsteroidMineralComparator(EOITConst.Items.PYERITE)));
        asteroidMap.append(EOITConst.Items.MEXALLON,
                new TreeSet<ItemBeanWithMaterials>(new AsteroidMineralComparator(EOITConst.Items.MEXALLON)));
        asteroidMap.append(EOITConst.Items.ISOGEN,
                new TreeSet<ItemBeanWithMaterials>(new AsteroidMineralComparator(EOITConst.Items.ISOGEN)));
        asteroidMap.append(EOITConst.Items.NOCXIUM,
                new TreeSet<ItemBeanWithMaterials>(new AsteroidMineralComparator(EOITConst.Items.NOCXIUM)));
        asteroidMap.append(EOITConst.Items.ZYDRINE,
                new TreeSet<ItemBeanWithMaterials>(new AsteroidMineralComparator(EOITConst.Items.ZYDRINE)));
        asteroidMap.append(EOITConst.Items.MEGACYTE,
                new TreeSet<ItemBeanWithMaterials>(new AsteroidMineralComparator(EOITConst.Items.MEGACYTE)));
        asteroidMap.append(EOITConst.Items.MORPHITE,
                new TreeSet<ItemBeanWithMaterials>(new AsteroidMineralComparator(EOITConst.Items.MORPHITE)));

        asteroids.populateSet(asteroidMap.get(EOITConst.Items.TRITANIUM));
        asteroids.populateSet(asteroidMap.get(EOITConst.Items.PYERITE));
        asteroids.populateSet(asteroidMap.get(EOITConst.Items.MEXALLON));
        asteroids.populateSet(asteroidMap.get(EOITConst.Items.ISOGEN));
        asteroids.populateSet(asteroidMap.get(EOITConst.Items.NOCXIUM));
        asteroids.populateSet(asteroidMap.get(EOITConst.Items.ZYDRINE));
        asteroids.populateSet(asteroidMap.get(EOITConst.Items.MEGACYTE));
        asteroids.populateSet(asteroidMap.get(EOITConst.Items.MORPHITE));

        Log.d(LOG_TAG, "Finish reading cursor...");
    }
}

From source file:com.bellman.bible.service.db.bookmark.BookmarkDBAdapter.java

public List<BookmarkDto> getUnlabelledBookmarks() {
    String sql = "SELECT " + SQLHelper.getColumnsForQuery(BookmarkQuery.TABLE, BookmarkQuery.COLUMNS)
            + " FROM bookmark "
            + " WHERE NOT EXISTS (SELECT * FROM bookmark_label WHERE bookmark._id = bookmark_label.bookmark_id)";

    List<BookmarkDto> bookmarks = new ArrayList<BookmarkDto>();
    Cursor c = db.rawQuery(sql, null);
    try {//from w ww.j  ava 2s  .  co  m
        if (c.moveToFirst()) {
            while (!c.isAfterLast()) {
                BookmarkDto bookmark = getBookmarkDto(c);
                bookmarks.add(bookmark);
                c.moveToNext();
            }
        }
    } finally {
        c.close();
    }

    return bookmarks;
}

From source file:com.anysoftkeyboard.dictionaries.content.ContactsDictionary.java

@Override
protected void readWordsFromActualStorage(WordReadListener listener) {
    //we required Contacts permission
    Intent contactsRequired = PermissionsFragmentChauffeurActivity.createIntentToPermissionsRequest(mContext,
            MainSettingsActivity.class, PermissionsRequestCodes.CONTACTS.getRequestCode(),
            Manifest.permission.READ_CONTACTS);
    if (contactsRequired != null) {
        //we are running OUTSIDE an Activity
        contactsRequired.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
        //showing a notification, so the user's flow will not be interrupted.
        showNotificationWithIntent(contactsRequired);
        //and failing. So it will try to read contacts again
        throw new RuntimeException("We do not have permission to read contacts!");
    } else {/*from  w w  w. j a  v a2 s  .  co m*/
        Cursor cursor = mContext.getContentResolver().query(Contacts.CONTENT_URI, PROJECTION,
                Contacts.IN_VISIBLE_GROUP + "=?", new String[] { "1" }, null);
        if (cursor != null && cursor.moveToFirst()) {
            while (!cursor.isAfterLast()) {
                final String fullname = cursor.getString(INDEX_NAME);
                final int freq;
                //in contacts, the frequency is a bit tricky:
                //stared contacts are really high
                final boolean isStarred = cursor.getInt(INDEX_STARRED) > 0;
                if (isStarred) {
                    freq = MAX_WORD_FREQUENCY;// WOW! important!
                } else {
                    //times contacted will be our frequency
                    final int frequencyContacted = cursor.getInt(INDEX_TIMES);
                    //A contact is a valid word in a language, and it usually very frequent.
                    final int minimumAdjustedFrequencyContacted = Math.max(MINIMUM_CONTACT_WORD_FREQUENCY,
                            frequencyContacted);
                    //but no more than the max allowed
                    freq = Math.min(minimumAdjustedFrequencyContacted, MAX_WORD_FREQUENCY);
                }
                if (!listener.onWordRead(fullname, freq))
                    break;
                cursor.moveToNext();
            }
        }
        if (cursor != null)
            cursor.close();
    }
}

From source file:com.bellman.bible.service.db.bookmark.BookmarkDBAdapter.java

public List<BookmarkDto> getBookmarksWithLabel(LabelDto label) {
    String sql = "SELECT " + SQLHelper.getColumnsForQuery(BookmarkQuery.TABLE, BookmarkQuery.COLUMNS)
            + " FROM bookmark " + "JOIN bookmark_label ON (bookmark._id = bookmark_label.bookmark_id) "
            + "JOIN label ON (bookmark_label.label_id = label._id) " + "WHERE label._id = ? ";

    List<BookmarkDto> allBookmarks = new ArrayList<BookmarkDto>();
    String[] args = new String[] { label.getId().toString() };
    Cursor c = db.rawQuery(sql, args);
    try {/* w ww  .  j a  va  2  s .c  o m*/
        if (c.moveToFirst()) {
            while (!c.isAfterLast()) {
                BookmarkDto bookmark = getBookmarkDto(c);
                allBookmarks.add(bookmark);
                c.moveToNext();
            }
        }
    } finally {
        c.close();
    }

    return allBookmarks;
}

From source file:com.bellman.bible.service.db.bookmark.BookmarkDBAdapter.java

public List<LabelDto> getBookmarkLabels(BookmarkDto bookmark) {
    String sql = "SELECT label._id, label.name " + "FROM label "
            + "JOIN bookmark_label ON (label._id = bookmark_label.label_id) "
            + "JOIN bookmark ON (bookmark_label.bookmark_id = bookmark._id) " + "WHERE bookmark._id = ?";

    List<LabelDto> labels = new ArrayList<LabelDto>();
    String[] args = new String[] { bookmark.getId().toString() };
    Cursor c = db.rawQuery(sql, args);
    try {//  w w w  .ja v a 2 s.com
        if (c.moveToFirst()) {
            while (!c.isAfterLast()) {
                LabelDto label = getLabelDto(c);
                labels.add(label);
                c.moveToNext();
            }
        }
    } finally {
        c.close();
    }

    return labels;
}

From source file:com.taobao.weex.devtools.inspector.protocol.module.Database.java

/**
 * Flatten all columns and all rows of a cursor to a single array.  The array cannot be
 * interpreted meaningfully without the number of columns.
 *
 * @param cursor/*from   www.  j a  v a  2 s . c  o  m*/
 * @param limit Maximum number of rows to process.
 * @return List of Java primitives matching the value type of each column, converted to
 *      strings.
 */
private static ArrayList<String> flattenRows(Cursor cursor, int limit) {
    Util.throwIfNot(limit >= 0);
    ArrayList<String> flatList = new ArrayList<>();
    final int numColumns = cursor.getColumnCount();
    for (int row = 0; row < limit && cursor.moveToNext(); row++) {
        for (int column = 0; column < numColumns; column++) {
            switch (cursor.getType(column)) {
            case Cursor.FIELD_TYPE_NULL:
                flatList.add(null);
                break;
            case Cursor.FIELD_TYPE_INTEGER:
                flatList.add(String.valueOf(cursor.getLong(column)));
                break;
            case Cursor.FIELD_TYPE_FLOAT:
                flatList.add(String.valueOf(cursor.getDouble(column)));
                break;
            case Cursor.FIELD_TYPE_BLOB:
                flatList.add(blobToString(cursor.getBlob(column)));
                break;
            case Cursor.FIELD_TYPE_STRING:
            default:
                flatList.add(cursor.getString(column));
                break;
            }
        }
    }
    if (!cursor.isAfterLast()) {
        for (int column = 0; column < numColumns; column++) {
            flatList.add("{truncated}");
        }
    }
    return flatList;
}

From source file:com.yek.keyboard.dictionaries.content.ContactsDictionary.java

@Override
protected void readWordsFromActualStorage(WordReadListener listener) {
    //we required Contacts permission
    if (true)//  w  w w  .  j  av  a 2  s  . c o  m
        return;
    Intent contactsRequired = PermissionsFragmentChauffeurActivity.createIntentToPermissionsRequest(mContext,
            MainSettingsActivity.class, PermissionsRequestCodes.CONTACTS.getRequestCode(),
            Manifest.permission.READ_CONTACTS);
    if (contactsRequired != null) {
        //we are running OUTSIDE an Activity
        contactsRequired.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
        //showing a notification, so the user's flow will not be interrupted.
        showNotificationWithIntent(contactsRequired);
        //and failing. So it will try to read contacts again
        throw new RuntimeException("We do not have permission to read contacts!");
    } else {
        Cursor cursor = mContext.getContentResolver().query(Contacts.CONTENT_URI, PROJECTION,
                Contacts.IN_VISIBLE_GROUP + "=?", new String[] { "1" }, null);
        if (cursor != null && cursor.moveToFirst()) {
            while (!cursor.isAfterLast()) {
                final String fullname = cursor.getString(INDEX_NAME);
                final int freq;
                //in contacts, the frequency is a bit tricky:
                //stared contacts are really high
                final boolean isStarred = cursor.getInt(INDEX_STARRED) > 0;
                if (isStarred) {
                    freq = MAX_WORD_FREQUENCY;// WOW! important!
                } else {
                    //times contacted will be our frequency
                    final int frequencyContacted = cursor.getInt(INDEX_TIMES);
                    //A contact is a valid word in a language, and it usually very frequent.
                    final int minimumAdjustedFrequencyContacted = Math.max(MINIMUM_CONTACT_WORD_FREQUENCY,
                            frequencyContacted);
                    //but no more than the max allowed
                    freq = Math.min(minimumAdjustedFrequencyContacted, MAX_WORD_FREQUENCY);
                }
                if (!listener.onWordRead(fullname, freq))
                    break;
                cursor.moveToNext();
            }
        }
        if (cursor != null)
            cursor.close();
    }
}

From source file:de.elanev.studip.android.app.frontend.contacts.ContactsGroupsFragment.java

@Override
public void onLoadFinished(Loader<Cursor> loader, Cursor cursor) {
    if (getActivity() == null) {
        return;/*  w  ww .  j a  va  2s .co  m*/
    }

    List<SectionedCursorAdapter.Section> sections = new ArrayList<SectionedCursorAdapter.Section>();
    cursor.moveToFirst();
    String prevGroup = null;
    String currGroup = null;

    while (!cursor.isAfterLast()) {
        currGroup = cursor.getString(cursor.getColumnIndex(ContactsContract.Columns.ContactGroups.GROUP_NAME));
        if (!TextUtils.equals(currGroup, prevGroup)) {
            sections.add(new SectionedCursorAdapter.Section(cursor.getPosition(), currGroup));
        }

        prevGroup = currGroup;

        cursor.moveToNext();
    }

    mUserAdapter.setSections(sections);
    mUserAdapter.swapCursor(cursor);

    setLoadingViewVisible(false);
}

From source file:com.snu.msl.sensys.SyncAdapter.SyncAdapter.java

@Override
public void onPerformSync(Account account, Bundle bundle, String s, ContentProviderClient contentProviderClient,
        SyncResult syncResult) {/*  ww w . j a  va 2  s . com*/
    Log.d("UPUP", "Reached here");
    try {
        Cursor cursor = contentProviderClient.query(
                Uri.parse("content://com.snu.msl.sensys.provider/datacollected"), null, null, null, null);
        cursor.moveToFirst();
        StringBuilder res = new StringBuilder();
        while (!cursor.isAfterLast()) {
            String timestamp = cursor.getString(cursor.getColumnIndex("timestamp"));
            String firstTime = cursor.getString(cursor.getColumnIndex("firsttime"));
            String gpsLatitude = cursor.getString(cursor.getColumnIndex("gpslatitude"));
            String gpsLongitude = cursor.getString(cursor.getColumnIndex("gpslongitude"));
            String sensordroneMAC = cursor.getString(cursor.getColumnIndex("sensordronemac"));
            String sensordroneTemperature = cursor.getString(cursor.getColumnIndex("sensordronetemperature"));
            String sensordroneHumidity = cursor.getString(cursor.getColumnIndex("sensordronehumidity"));
            String sensordronePressure = cursor.getString(cursor.getColumnIndex("sensordronepressure"));
            String sensordroneIRTemperature = cursor
                    .getString(cursor.getColumnIndex("sensordroneirtemperature"));
            String sensordroneIlluminance = cursor.getString(cursor.getColumnIndex("sensordroneilluminance"));
            String sensordronePrecisionGas = cursor.getString(cursor.getColumnIndex("sensordroneprecisiongas"));
            String sensordroneCapacitance = cursor.getString(cursor.getColumnIndex("sensordronecapacitance"));
            String sensordroneExternalVoltage = cursor
                    .getString(cursor.getColumnIndex("sensordroneexternalvoltage"));
            String sensordroneBatteryVoltage = cursor
                    .getString(cursor.getColumnIndex("sensordronebatteryvoltage"));
            String sensordroneOxidizingGas = cursor.getString(cursor.getColumnIndex("sensordroneoxidizinggas"));
            String sensordroneReducingGas = cursor.getString(cursor.getColumnIndex("sensordronereducinggas"));
            String gpsAltitude = cursor.getString(cursor.getColumnIndex("gpsaltitude"));
            String sensordroneCO2 = cursor.getString(cursor.getColumnIndex("sensordroneco2"));

            String responseString = "";
            HttpClient httpclient = new DefaultHttpClient();
            HttpPost httppost = new HttpPost(
                    "http://mobisense.webapps.snu.edu.in/ITRAWebsite/upload/sensordroneupload.php");
            try {
                List<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>(2);
                nameValuePairs.add(new BasicNameValuePair("user", account.name));
                nameValuePairs.add(new BasicNameValuePair("timestamp", timestamp));
                nameValuePairs.add(new BasicNameValuePair("firsttime", firstTime));
                nameValuePairs.add(new BasicNameValuePair("gpslatitude", gpsLatitude));
                nameValuePairs.add(new BasicNameValuePair("gpslongitude", gpsLongitude));
                nameValuePairs.add(new BasicNameValuePair("sensordronemac", sensordroneMAC));
                nameValuePairs.add(new BasicNameValuePair("sensordronetemperature", sensordroneTemperature));
                nameValuePairs.add(new BasicNameValuePair("sensordronehumidity", sensordroneHumidity));
                nameValuePairs.add(new BasicNameValuePair("sensordronepressure", sensordronePressure));
                nameValuePairs
                        .add(new BasicNameValuePair("sensordroneirtemperature", sensordroneIRTemperature));
                nameValuePairs.add(new BasicNameValuePair("sensordroneilluminance", sensordroneIlluminance));
                nameValuePairs.add(new BasicNameValuePair("sensordroneprecisiongas", sensordronePrecisionGas));
                nameValuePairs.add(new BasicNameValuePair("sensordronecapacitance", sensordroneCapacitance));
                nameValuePairs
                        .add(new BasicNameValuePair("sensordroneexternalvoltage", sensordroneExternalVoltage));
                nameValuePairs
                        .add(new BasicNameValuePair("sensordronebatteryvoltage", sensordroneBatteryVoltage));
                nameValuePairs.add(new BasicNameValuePair("sensordroneoxidizinggas", sensordroneOxidizingGas));
                nameValuePairs.add(new BasicNameValuePair("sensordronereducinggas", sensordroneReducingGas));
                nameValuePairs.add(new BasicNameValuePair("sensordroneco2", sensordroneCO2));
                nameValuePairs.add(new BasicNameValuePair("gpsaltitude", gpsAltitude));

                Log.d("TAG", sensordroneOxidizingGas + ", " + sensordroneReducingGas + ", "
                        + sensordroneTemperature);

                httppost.setEntity(new UrlEncodedFormEntity(nameValuePairs));
                HttpResponse response = httpclient.execute(httppost);
                HttpEntity entity = response.getEntity();
                responseString = EntityUtils.toString(entity, "UTF-8");
                Log.d("TAGFFFF", responseString);
            } catch (ClientProtocolException e) {
                // TODO Auto-generated catch block
            } catch (IOException e) {
                // TODO Auto-generated catch block
            }
            if (responseString.equalsIgnoreCase("Success"))
                contentProviderClient.delete(Uri.parse("content://com.snu.msl.sensys.provider/datacollected"),
                        "timestamp=?", new String[] { timestamp });

            cursor = contentProviderClient.query(
                    Uri.parse("content://com.snu.msl.sensys.provider/datacollected"), null, null, null, null);
            cursor.moveToFirst();

        }
    } catch (RemoteException e) {
        syncResult.hasHardError();
        e.printStackTrace();
    }

}

From source file:com.google.android.apps.santatracker.data.DestinationDbHelper.java

public long getLastArrival() {
    SQLiteDatabase db = getReadableDatabase();
    Cursor c = db.rawQuery("SELECT " + COLUMN_NAME_ARRIVAL + " FROM " + TABLE_NAME + " ORDER BY "
            + COLUMN_NAME_ARRIVAL + " DESC LIMIT 1", null);
    c.moveToFirst();// w  w w. ja  v a  2s  . co  m
    long l;
    if (c.isAfterLast()) {
        l = -1;
    } else {
        l = c.getLong(c.getColumnIndex(COLUMN_NAME_ARRIVAL));
    }
    c.close();
    return l;
}