Example usage for android.database Cursor moveToNext

List of usage examples for android.database Cursor moveToNext

Introduction

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

Prototype

boolean moveToNext();

Source Link

Document

Move the cursor to the next row.

Usage

From source file:de.stadtrallye.rallyesoft.model.pictures.PictureManager.java

private void reload() {
    unconfirmed = null;/*from w  w  w . j  a  v a2 s. co  m*/
    queue.clear();

    Cursor c = getDb().query(Pictures.TABLE,
            new String[] { Pictures.KEY_ID, Pictures.KEY_STATE, Pictures.KEY_FILE, Pictures.KEY_SOURCE_HINT },
            Pictures.KEY_STATE + "<=?", new String[] { Integer.toString(STATE_UPLOADED) }, null, null, null);
    while (c.moveToNext()) {
        SourceHint sourceHint = null;
        try {
            String s = c.getString(3);
            if (s != null)
                sourceHint = Serialization.getJsonInstance().readValue(s, SourceHint.class);
        } catch (IOException e) {
            Log.e(THIS, "Could not read SourceHint", e);
        }
        Picture picture = new Picture(c.getInt(0), c.getString(2), c.getInt(1), sourceHint);
        if (picture.isUnconfirmed()) {
            unconfirmed = picture;
            if (unconfirmed != null) {
                Log.w(THIS, "Multiple unconfirmed Pictures, discarding: " + unconfirmed);
                unconfirmed.discard();
            }
            queuedUnconfirmed = autoUpload;
            if (autoUpload) {
                queue.add(picture);
            }
        } else {
            queue.add(picture);
        }
    }
    c.close();
    Log.d(THIS, "Loaded " + queue.size() + " Pictures into the queue");
    if (!queue.isEmpty())
        notifyUploader();
}

From source file:org.noorganization.instalistsynch.controller.synch.impl.CategorySynch.java

@Override
public void indexLocal(int _groupId, Date _lastIndexTime) {
    String lastIndexTime = ISO8601Utils.format(_lastIndexTime, false, TimeZone.getTimeZone("GMT+0000"));//.concat("+0000");
    boolean isLocal = false;
    GroupAuth groupAuth = mGroupAuthDbController.getLocalGroup();
    if (groupAuth != null) {
        isLocal = groupAuth.getGroupId() == _groupId;
    }// ww w.  ja va 2 s. com
    Cursor categoryLogCursor = mClientLogDbController.getLogsSince(lastIndexTime, mModelType);
    if (categoryLogCursor.getCount() == 0) {
        categoryLogCursor.close();
        return;
    }

    try {
        while (categoryLogCursor.moveToNext()) {
            // fetch the action type
            int actionId = categoryLogCursor.getInt(categoryLogCursor.getColumnIndex(LogInfo.COLUMN.ACTION));
            eActionType actionType = eActionType.getTypeById(actionId);

            List<ModelMapping> modelMappingList = mCategoryModelMappingController.get(
                    ModelMapping.COLUMN.GROUP_ID + " = ? AND " + ModelMapping.COLUMN.CLIENT_SIDE_UUID
                            + " LIKE ?",
                    new String[] { String.valueOf(_groupId), categoryLogCursor
                            .getString(categoryLogCursor.getColumnIndex(LogInfo.COLUMN.ITEM_UUID)) });
            ModelMapping modelMapping = modelMappingList.size() == 0 ? null : modelMappingList.get(0);

            switch (actionType) {
            case INSERT:
                // skip insertion because this should be decided by the user if the non local groups should have access to the category
                // and also skip if a mapping for this case already exists!
                if (!isLocal || modelMapping != null) {
                    continue;
                }

                String clientUuid = categoryLogCursor
                        .getString(categoryLogCursor.getColumnIndex(LogInfo.COLUMN.ITEM_UUID));
                Date clientDate = ISO8601Utils.parse(
                        categoryLogCursor
                                .getString(categoryLogCursor.getColumnIndex(LogInfo.COLUMN.ACTION_DATE)),
                        new ParsePosition(0));
                modelMapping = new ModelMapping(null, groupAuth.getGroupId(), null, clientUuid,
                        new Date(Constants.INITIAL_DATE), clientDate, false);
                mCategoryModelMappingController.insert(modelMapping);
                break;
            case UPDATE:
                if (modelMapping == null) {
                    Log.i(TAG, "indexLocal: the model is null but shouldn't be");
                    continue;
                }
                String timeString = categoryLogCursor
                        .getString(categoryLogCursor.getColumnIndex(LogInfo.COLUMN.ACTION_DATE));
                clientDate = ISO8601Utils.parse(timeString, new ParsePosition(0));
                modelMapping.setLastClientChange(clientDate);
                mCategoryModelMappingController.update(modelMapping);
                break;
            case DELETE:
                if (modelMapping == null) {
                    Log.i(TAG, "indexLocal: the model is null but shouldn't be");
                    continue;
                }
                modelMapping.setDeleted(true);
                timeString = categoryLogCursor
                        .getString(categoryLogCursor.getColumnIndex(LogInfo.COLUMN.ACTION_DATE));
                clientDate = ISO8601Utils.parse(timeString, new ParsePosition(0));
                modelMapping.setLastClientChange(clientDate);
                mCategoryModelMappingController.update(modelMapping);
                break;
            default:
            }

        }
    } catch (Exception e) {
        categoryLogCursor.close();
    }
}

From source file:com.kynetx.api.java

public void setApp(Cursor apps) {
    appId = "";/*from  w ww  . j  a  v a  2  s .c o  m*/
    appVersions = "";

    apps.moveToFirst();

    while (apps.isAfterLast() == false) {
        if (!apps.getString(apps.getColumnIndex(KynetxSQLHelper.KEY_VERSION)).equals("none")) {
            appId += apps.getString(apps.getColumnIndex(KynetxSQLHelper.KEY_APPID));
            appVersions += appId + ":kynetx_app_version="
                    + apps.getString(apps.getColumnIndex(KynetxSQLHelper.KEY_VERSION)) + "&";
            if (!apps.isLast()) {
                appId += ";";
            }
        }
        apps.moveToNext();
    }
    apps.close();
}

From source file:com.phonegap.ContactAccessorSdk3_4.java

/**
 * A convenience method so we don't duplicate code in doQuery
 * @param searchTerm//from w  w w .  j  av a  2  s  . com
 * @param contactIds
 * @param uri
 * @param projection
 * @param selection
 * @param selectionArgs
 */
private void doQuery(String searchTerm, Set<String> contactIds, Uri uri, String projection, String selection,
        String[] selectionArgs) {
    ContentResolver cr = mApp.getContentResolver();

    Cursor cursor = cr.query(uri, null, selection, selectionArgs, null);

    while (cursor.moveToNext()) {
        contactIds.add(cursor.getString(cursor.getColumnIndex(projection)));
    }
    cursor.close();
}

From source file:it.gmariotti.android.examples.googleaccount.SmsBackupGDriveActivity.java

private JSONObject readSmsInbox() throws JSONException {
    Cursor cursor = getSmsInboxCursor();
    // StringBuilder messages = new StringBuilder();
    JSONArray messages = new JSONArray();

    String and = "";

    if (cursor != null) {
        final String[] columns = cursor.getColumnNames();
        while (cursor.moveToNext()) {
            // messages.append(and);
            JSONObject msg = new JSONObject();
            // long id = cursor.getLong(SmsQuery._ID);
            long contactId = cursor.getLong(SmsQuery.PERSON);
            String address = cursor.getString(SmsQuery.ADDRESS);
            // long threadId = cursor.getLong(SmsQuery.THREAD_ID);
            // final long date = cursor.getLong(SmsQuery.DATE);

            final Map<String, String> msgMap = new HashMap<String, String>(columns.length);

            for (int i = 0; i < columns.length; i++) {
                String value = cursor.getString(i);
                msgMap.put(columns[i], cursor.getString(i));
                /*//from w ww . j  a  v  a2s. c om
                 * messages.append(columns[i]); messages.append("=");
                 * messages.append(value); messages.append(";;");
                 */
                msg.put(columns[i], value);

            }
            // and = "\n";

            /**
             * Retrieve display name
             * 
             */
            String displayName = address;

            if (contactId > 0) {
                // Retrieve from Contacts with contact id
                Cursor contactCursor = tryOpenContactsCursorById(contactId);
                if (contactCursor != null) {
                    if (contactCursor.moveToFirst()) {
                        displayName = contactCursor.getString(RawContactsQuery.DISPLAY_NAME);
                    } else {
                        contactId = 0;
                    }
                    contactCursor.close();
                }
            } else {
                if (contactId <= 0) {
                    // Retrieve with address
                    Cursor contactCursor = tryOpenContactsCursorByAddress(address);
                    if (contactCursor != null) {
                        if (contactCursor.moveToFirst()) {
                            displayName = contactCursor.getString(ContactsQuery.DISPLAY_NAME);
                        }
                        contactCursor.close();
                    }
                }
            }
            /*
             * messages.append("displayName"); messages.append("=");
             * messages.append(displayName); messages.append(";;");
             * messages.append("||");
             */
            msg.put("displayName", displayName);

            messages.put(msg);

        }
    }

    JSONObject fileBackupTest = new JSONObject();
    fileBackupTest.put("messages", messages);
    return fileBackupTest;
}

From source file:com.android.browser.BookmarksPageCallbacks.java

@Override
public void onLoadFinished(Loader<Cursor> loader, Cursor cursor) {
    if (loader.getId() == LOADER_ACCOUNTS) {
        LoaderManager lm = getLoaderManager();
        int id = LOADER_BOOKMARKS;
        while (cursor.moveToNext()) {
            String accountName = cursor.getString(0);
            String accountType = cursor.getString(1);
            Bundle args = new Bundle();
            args.putString(ACCOUNT_NAME, accountName);
            args.putString(ACCOUNT_TYPE, accountType);
            BrowserBookmarksAdapter adapter = new BrowserBookmarksAdapter(getActivity());
            mBookmarkAdapters.put(id, adapter);
            boolean expand = true;
            try {
                expand = mState.getBoolean(
                        accountName != null ? accountName : BookmarkExpandableView.LOCAL_ACCOUNT_NAME);
            } catch (JSONException e) {
            } // no state for accountName
            mGrid.addAccount(accountName, adapter, expand);
            lm.restartLoader(id, args, this);
            id++;//from www  .  ja  v a  2  s  .  c  om
        }
        // TODO: Figure out what a reload of these means
        // Currently, a reload is triggered whenever bookmarks change
        // This is less than ideal
        // It also causes UI flickering as a new adapter is created
        // instead of re-using an existing one when the account_name is the
        // same.
        // For now, this is a one-shot load
        getLoaderManager().destroyLoader(LOADER_ACCOUNTS);
    } else if (loader.getId() >= LOADER_BOOKMARKS) {
        BrowserBookmarksAdapter adapter = mBookmarkAdapters.get(loader.getId());
        adapter.changeCursor(cursor);
    }
}

From source file:org.noorganization.instalistsynch.controller.synch.impl.ListSynch.java

@Override
public void indexLocal(int _groupId, Date _lastIndexTime) {
    String lastIndexTime = ISO8601Utils.format(_lastIndexTime, false, TimeZone.getTimeZone("GMT+0000"));//.concat("+0000");
    boolean isLocal = false;
    GroupAuth groupAuth = mGroupAuthDbController.getLocalGroup();
    if (groupAuth != null) {
        isLocal = groupAuth.getGroupId() == _groupId;
    }/*  w  w  w. ja v  a2 s.co m*/
    Cursor logCursor = mClientLogDbController.getLogsSince(lastIndexTime, mModelType);
    if (logCursor.getCount() == 0) {
        logCursor.close();
        return;
    }

    try {
        while (logCursor.moveToNext()) {
            // fetch the action type
            int actionId = logCursor.getInt(logCursor.getColumnIndex(LogInfo.COLUMN.ACTION));
            eActionType actionType = eActionType.getTypeById(actionId);

            List<ModelMapping> modelMappingList = mListModelMappingController.get(
                    ModelMapping.COLUMN.GROUP_ID + " = ? AND " + ModelMapping.COLUMN.CLIENT_SIDE_UUID
                            + " LIKE ?",
                    new String[] { String.valueOf(_groupId),
                            logCursor.getString(logCursor.getColumnIndex(LogInfo.COLUMN.ITEM_UUID)) });
            ModelMapping modelMapping = modelMappingList.size() == 0 ? null : modelMappingList.get(0);

            switch (actionType) {
            case INSERT:
                // skip insertion because this should be decided by the user if the non local groups should have access to the category
                // and also skip if a mapping for this case already exists!
                if (!isLocal || modelMapping != null) {
                    continue;
                }

                String clientUuid = logCursor.getString(logCursor.getColumnIndex(LogInfo.COLUMN.ITEM_UUID));
                Date clientDate = ISO8601Utils.parse(
                        logCursor.getString(logCursor.getColumnIndex(LogInfo.COLUMN.ACTION_DATE)),
                        new ParsePosition(0));
                modelMapping = new ModelMapping(null, groupAuth.getGroupId(), null, clientUuid,
                        new Date(Constants.INITIAL_DATE), clientDate, false);
                mListModelMappingController.insert(modelMapping);
                break;
            case UPDATE:
                if (modelMapping == null) {
                    Log.i(TAG, "indexLocal: the model is null but shouldn't be");
                    continue;
                }
                String timeString = logCursor.getString(logCursor.getColumnIndex(LogInfo.COLUMN.ACTION_DATE));
                clientDate = ISO8601Utils.parse(timeString, new ParsePosition(0));
                modelMapping.setLastClientChange(clientDate);
                mListModelMappingController.update(modelMapping);
                break;
            case DELETE:
                if (modelMapping == null) {
                    Log.i(TAG, "indexLocal: the model is null but shouldn't be");
                    continue;
                }
                modelMapping.setDeleted(true);
                timeString = logCursor.getString(logCursor.getColumnIndex(LogInfo.COLUMN.ACTION_DATE));
                clientDate = ISO8601Utils.parse(timeString, new ParsePosition(0));
                modelMapping.setLastClientChange(clientDate);
                mListModelMappingController.update(modelMapping);
                break;
            default:
            }

        }
    } catch (Exception e) {
        logCursor.close();
    }
}

From source file:edu.auburn.ppl.cyclecolumbus.TripUploader.java

@Override
protected Boolean doInBackground(Long... tripid) {
    // First, send the trip user asked for:
    Boolean result = true;//from  w  ww .  j  a va  2 s  . c  o m
    if (tripid.length != 0) {
        result = uploadOneTrip(tripid[0]);
    }

    // Then, automatically try and send previously-completed trips
    // that were not sent successfully.
    Vector<Long> unsentTrips = new Vector<Long>();

    mDb.openReadOnly();
    Cursor cur = mDb.fetchUnsentTrips();
    if (cur != null && cur.getCount() > 0) {
        // Reades all unsent trips
        while (!cur.isAfterLast()) {
            unsentTrips.add(Long.valueOf(cur.getLong(0)));
            cur.moveToNext();
        }
        cur.close();
    }
    mDb.close();

    for (Long trip : unsentTrips) {
        result &= uploadOneTrip(trip);
    }
    return result;
}

From source file:org.opensmc.mytracks.cyclesmc.TripUploader.java

@Override
protected Boolean doInBackground(Long... tripid) {
    // First, send the trip user asked for:
    Boolean result = uploadOneTrip(tripid[0]);

    // TODO: not always working?
    //Log.d("uploading trip", tripid[0].toString());
    //////////////////////////////////////////////

    // Then, automatically try and send previously-completed trips
    // that were not sent successfully.
    Vector<Long> unsentTrips = new Vector<Long>();

    mDb.openReadOnly();/*from   w  w w.  j av  a 2  s  .co  m*/
    Cursor cur = mDb.fetchUnsentTrips();
    if (cur != null && cur.getCount() > 0) {
        //pd.setMessage("Sent. You have previously unsent trips; submitting those now.");

        ////////////
        //Log.d("previously unsent count", cur.getCount() + " previously unsent trips");
        ////////////

        while (!cur.isAfterLast()) {
            unsentTrips.add(Long.valueOf(cur.getLong(0)));
            cur.moveToNext();
        }
        cur.close();
    }
    mDb.close();

    for (Long trip : unsentTrips) {
        result &= uploadOneTrip(trip);
        ///////////////
        //Log.d("uploading unsent trip", trip.toString());
        ///////////////

    }
    return result;
}

From source file:at.bitfire.davdroid.resource.LocalCollection.java

/**
 * Finds deleted resources (resources which have been marked for deletion).
 * Deleted resources have the "deleted" flag set.
 * Only records matching sqlFilter will be returned.
 * //from w w  w .  ja v  a2 s  .c  om
 * @return IDs of deleted resources
 * @throws LocalStorageException when the content provider couldn't be queried
 */
public long[] findDeleted() throws LocalStorageException {
    String where = entryColumnDeleted() + "=1";
    if (entryColumnParentID() != null)
        where += " AND " + entryColumnParentID() + "=" + String.valueOf(getId());
    if (sqlFilter != null)
        where += " AND (" + sqlFilter + ")";
    try {
        @Cleanup
        Cursor cursor = providerClient.query(entriesURI(),
                new String[] { entryColumnID(), entryColumnRemoteName(), entryColumnETag() }, where, null,
                null);
        if (cursor == null)
            throw new LocalStorageException("Couldn't query dirty records");

        long deleted[] = new long[cursor.getCount()];
        for (int idx = 0; cursor.moveToNext(); idx++)
            deleted[idx] = cursor.getLong(0);
        return deleted;
    } catch (RemoteException ex) {
        throw new LocalStorageException(ex);
    }
}