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:curso.android.DAO.RespostaDAO.java

public static List<Resposta> readAll() {
    Cursor cursor = null;
    try {/*  ww  w  .  jav a2s  .  c om*/
        List<Resposta> all = new ArrayList<Resposta>();

        cursor = Const.db.rawQuery("SELECT * FROM resposta", null);

        if (cursor.getCount() > 0) {
            int idIndex = cursor.getColumnIndex("asw_id");
            int askIndex = cursor.getColumnIndex("ask_id");
            int userIndex = cursor.getColumnIndex("user_id");
            int respostaIndex = cursor.getColumnIndex("asw_resposta");
            int nameIndex = cursor.getColumnIndex("user_name");
            cursor.moveToFirst();
            do {
                Long id = Long.valueOf(cursor.getInt(idIndex));
                Long ask = Long.valueOf(cursor.getString(askIndex));
                Long user = Long.valueOf(cursor.getString(userIndex));
                String pergunta = cursor.getString(respostaIndex);
                String user_name = cursor.getString(nameIndex);

                Resposta asw = new Resposta();
                asw.setAsw_id(id);
                asw.setAsk_id(ask);
                asw.setUser_id(user);
                asw.setAsw_resposta(pergunta);
                asw.setUser_name(user_name);

                all.add(asw);

                cursor.moveToNext();
            } while (!cursor.isAfterLast());
        }

        return all;
    } finally {
        if (cursor != null) {
            cursor.close();
        }
    }
}

From source file:edu.mit.mobile.android.demomode.Preferences.java

private String toConfigString() {

    final String password = mPrefs.getString(KEY_PASSWORD, null);

    final ArrayList<BasicNameValuePair> nvp = new ArrayList<BasicNameValuePair>();

    int ver;/*from   w w w .  j  av  a 2s .c  om*/
    try {
        ver = getPackageManager().getPackageInfo(getPackageName(), 0).versionCode;

    } catch (final NameNotFoundException e) {
        // this should never happen
        ver = 0;
        e.printStackTrace();
    }
    nvp.add(new BasicNameValuePair(CFG_K_VER, String.valueOf(ver)));
    nvp.add(new BasicNameValuePair(CFG_K_SECRETKEY, password));
    final Cursor c = getContentResolver().query(LauncherItem.CONTENT_URI, null, null, null, null);

    try {
        final int pkgCol = c.getColumnIndex(LauncherItem.PACKAGE_NAME);
        final int actCol = c.getColumnIndex(LauncherItem.ACTIVITY_NAME);

        for (c.moveToFirst(); !c.isAfterLast(); c.moveToNext()) {
            nvp.add(new BasicNameValuePair(CFG_K_APPS,
                    c.getString(pkgCol) + CFG_PKG_SEP + c.getString(actCol)));
        }

        return "data:" + CFG_MIME_TYPE + "," + URLEncodedUtils.format(nvp, "utf-8");

    } finally {
        c.close();
    }

}

From source file:com.intel.xdk.contacts.Contacts.java

@SuppressWarnings("deprecation")
public void contactsAdderActivityResult(int requestCode, int resultCode, Intent intent) {

    //Contact Added
    if (resultCode == Activity.RESULT_OK) {
        Cursor cursor = activity.managedQuery(intent.getData(), null, null, null, null);
        cursor.moveToNext();
        String contactId = cursor.getString(cursor.getColumnIndex(ContactsContract.Contacts.LOOKUP_KEY));

        getAllContacts();/*from   ww w.ja  v a 2s.c om*/
        String js = String.format(
                "var e = document.createEvent('Events');e.initEvent('intel.xdk.contacts.add',true,true);e.success=true;e.contactid='%s';document.dispatchEvent(e);",
                contactId);

        injectJS("javascript:" + js);
        busy = false;
    }
    //Contact not Added
    else {
        String js = "javascript: var e = document.createEvent('Events');e.initEvent('intel.xdk.contacts.add',true,true);e.success=false;e.cancelled=true;document.dispatchEvent(e);";
        injectJS(js);
        busy = false;
    }

}

From source file:com.android.providers.contacts.ContactsSyncAdapter.java

private static void addGroupMembershipToContactEntry(String account, ContentResolver cr, long personId,
        ContactEntry entry) throws ParseException {
    Cursor c = cr.query(GroupMembership.RAW_CONTENT_URI, null, "person=" + personId, null, null);
    try {/*from  ww w.  ja  v a2  s.  c o m*/
        int serverIdIndex = c.getColumnIndexOrThrow(GroupMembership.GROUP_SYNC_ID);
        int localIdIndex = c.getColumnIndexOrThrow(GroupMembership.GROUP_ID);
        while (c.moveToNext()) {
            String serverId = c.getString(serverIdIndex);
            if (serverId == null) {
                final Uri groupUri = ContentUris.withAppendedId(Groups.CONTENT_URI, c.getLong(localIdIndex));
                Cursor groupCursor = cr.query(groupUri, new String[] { Groups._SYNC_ID }, null, null, null);
                try {
                    if (groupCursor.moveToNext()) {
                        serverId = groupCursor.getString(0);
                    }
                } finally {
                    groupCursor.close();
                }
            }
            if (serverId == null) {
                // the group hasn't been synced yet, we can't complete this operation since
                // we don't know what server id to use for the group
                throw new ParseException("unable to construct GroupMembershipInfo since the "
                        + "group _sync_id isn't known yet, will retry later");
            }
            GroupMembershipInfo groupMembershipInfo = new GroupMembershipInfo();
            String groupId = getCanonicalGroupsFeedForAccount(account) + "/" + serverId;
            groupMembershipInfo.setGroup(groupId);
            groupMembershipInfo.setDeleted(false);
            entry.addGroup(groupMembershipInfo);
        }
    } finally {
        if (c != null)
            c.close();
    }
}

From source file:com.QuarkLabs.BTCeClient.UpdateWidgetsTask.java

@Override
protected JSONObject doInBackground(Void... params) {
    Set<String> set = new HashSet<>();
    JSONObject response = null;/*  w  ww  .j  a  va 2s .c  om*/
    for (int x : mMap.keySet()) {
        set.add(mMap.get(x));
    }
    try {
        response = App.getPairInfo(set.toArray(new String[set.size()]));
        response = response == null ? new JSONObject() : response;
        Context context = mContext.get();
        if (context == null) {
            return null;
        }
        DBWorker dbWorker = DBWorker.getInstance(context);
        String[] columns = { "pair", "last" };
        Cursor cursor = dbWorker.pullWidgetData(columns);
        Map<String, Double> values = new HashMap<>();
        if (cursor.moveToFirst()) {
            while (!cursor.isAfterLast()) {
                values.put(cursor.getString(cursor.getColumnIndex(columns[0])),
                        cursor.getDouble(cursor.getColumnIndex(columns[1])));
                cursor.moveToNext();
            }
        }
        cursor.close();
        for (@SuppressWarnings("unchecked")
        Iterator<String> x = response.keys(); x.hasNext();) {
            String pair = x.next();
            String pairInDB = pair.replace("_", "/").toUpperCase(Locale.US);
            ContentValues cv = new ContentValues(4);
            double last = response.getJSONObject(pair).getDouble("last");
            double sell = response.getJSONObject(pair).getDouble("sell");
            double buy = response.getJSONObject(pair).getDouble("buy");
            cv.put("last", last);
            cv.put("buy", buy);
            cv.put("sell", sell);
            if (values.containsKey(pairInDB)) {
                if (last >= values.get(pairInDB)) {
                    response.getJSONObject(pair).put("color", "green");
                } else {
                    response.getJSONObject(pair).put("color", "red");
                }
            } else {
                response.getJSONObject(pair).put("color", "green");
            }

            int result = dbWorker.updateWidgetData(cv, pair.replace("_", "/").toUpperCase(Locale.US));
            if (result == 0) {
                cv.put("pair", pair.replace("_", "/").toUpperCase(Locale.US));
                dbWorker.insertToWidgetData(cv);
            }
        }

    } catch (JSONException e) {
        e.printStackTrace();
    }
    return response;
}

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

/**
 * ?/*from ww w  . ja v  a 2 s.c  o m*/
 *
 * @param session
 * @return
 */
public static List<String> getImageMessageIdSession(long session) {
    String sql = "select msgid from " + DatabaseHelper.TABLES_NAME_IM_MESSAGE + " where "
            + IMessageColumn.OWN_THREAD_ID + " = " + session + " and msgType=" + ECMessage.Type.IMAGE.ordinal();
    Cursor cursor = getInstance().sqliteDB().rawQuery(sql, null);
    List<String> msgids = null;
    if (cursor != null && cursor.getCount() > 0) {
        msgids = new ArrayList<String>();
        while (cursor.moveToNext()) {
            msgids.add(cursor.getString(0));
        }
        cursor.close();
    }
    return msgids;
}

From source file:com.prey.json.actions.ContactsList.java

@TargetApi(Build.VERSION_CODES.ECLAIR)
public HttpDataService run(Context ctx, List<ActionResult> lista, JSONObject parameters) {
    HttpDataService data = new HttpDataService("contacts_list");
    HashMap<String, String> parametersMap = new HashMap<String, String>();
    Cursor cursor = null;
    try {/*from w  w w.j  a v  a2  s  .  c  om*/
        final String[] projection = null;
        final String selection = null;
        final String[] selectionArgs = null;
        final String sortOrder = null;
        Uri uri = ContactsContract.CommonDataKinds.Phone.CONTENT_URI;
        cursor = ctx.getContentResolver().query(uri, projection, selection, selectionArgs, sortOrder);
        int i = 0;
        if (cursor != null) {
            while (cursor.moveToNext()) {
                String phone = "";
                String name = cursor.getString(cursor.getColumnIndex(ContactsContract.Contacts.DISPLAY_NAME));
                try {
                    phone = cursor
                            .getString(cursor.getColumnIndex(ContactsContract.CommonDataKinds.Phone.NUMBER));
                } catch (Exception e) {

                }
                if (!"".equals(phone)) {
                    parametersMap.put(i + "][phone", phone);
                    parametersMap.put(i + "][name", name);
                    i++;
                }

            }
        }
    } catch (Exception ex) {
        PreyLogger.e("Error:" + ex.getMessage(), ex);
        PreyWebServices.getInstance().sendNotifyActionResultPreyHttp(ctx,
                UtilJson.makeMapParam("get", "contacts_list", "failed", ex.getMessage()));
    } finally {
        cursor.close();
    }
    data.setList(true);
    data.addDataListAll(parametersMap);
    return data;
}

From source file:com.bellman.bible.service.db.mynote.MyNoteDBAdapter.java

public List<MyNoteDto> getAllMyNotes() {
    Log.d(TAG, "about to getAllMyNotes");
    List<MyNoteDto> allMyNotes = new ArrayList<MyNoteDto>();
    Cursor c = db.query(MyNoteQuery.TABLE, MyNoteQuery.COLUMNS, null, null, null, null, null);
    try {/*from  w  ww  . j  av a  2 s.  c o  m*/
        if (c.moveToFirst()) {
            while (!c.isAfterLast()) {
                MyNoteDto mynote = getMyNoteDto(c);
                allMyNotes.add(mynote);
                c.moveToNext();
            }
        }
    } finally {
        c.close();
    }

    Log.d(TAG, "allMyNotes set to " + allMyNotes.size() + " item long list");
    return allMyNotes;
}

From source file:com.miz.service.TraktMoviesSyncService.java

private void loadMovieLibrary() {
    // Get movies
    mMovieDatabase = MizuuApplication.getMovieAdapter();
    Cursor cursor = mMovieDatabase.fetchAllMovies(DbAdapterMovies.KEY_TITLE + " ASC");
    ColumnIndexCache cache = new ColumnIndexCache();

    try {/*from  w ww.java  2  s. c  o m*/
        while (cursor.moveToNext()) {
            mTmdbIds.add(cursor.getString(cache.getColumnIndex(cursor, DbAdapterMovies.KEY_TMDB_ID)));

            // Full movies
            mMovies.add(new Movie(this,
                    cursor.getString(cache.getColumnIndex(cursor, DbAdapterMovies.KEY_TITLE)),
                    cursor.getString(cache.getColumnIndex(cursor, DbAdapterMovies.KEY_PLOT)),
                    cursor.getString(cache.getColumnIndex(cursor, DbAdapterMovies.KEY_TAGLINE)),
                    cursor.getString(cache.getColumnIndex(cursor, DbAdapterMovies.KEY_TMDB_ID)),
                    cursor.getString(cache.getColumnIndex(cursor, DbAdapterMovies.KEY_IMDB_ID)),
                    cursor.getString(cache.getColumnIndex(cursor, DbAdapterMovies.KEY_RATING)),
                    cursor.getString(cache.getColumnIndex(cursor, DbAdapterMovies.KEY_RELEASEDATE)),
                    cursor.getString(cache.getColumnIndex(cursor, DbAdapterMovies.KEY_CERTIFICATION)),
                    cursor.getString(cache.getColumnIndex(cursor, DbAdapterMovies.KEY_RUNTIME)),
                    cursor.getString(cache.getColumnIndex(cursor, DbAdapterMovies.KEY_TRAILER)),
                    cursor.getString(cache.getColumnIndex(cursor, DbAdapterMovies.KEY_GENRES)),
                    cursor.getString(cache.getColumnIndex(cursor, DbAdapterMovies.KEY_FAVOURITE)),
                    cursor.getString(cache.getColumnIndex(cursor, DbAdapterMovies.KEY_ACTORS)),
                    MizuuApplication.getCollectionsAdapter().getCollection(
                            cursor.getString(cache.getColumnIndex(cursor, DbAdapterMovies.KEY_COLLECTION_ID))),
                    cursor.getString(cache.getColumnIndex(cursor, DbAdapterMovies.KEY_COLLECTION_ID)),
                    cursor.getString(cache.getColumnIndex(cursor, DbAdapterMovies.KEY_TO_WATCH)),
                    cursor.getString(cache.getColumnIndex(cursor, DbAdapterMovies.KEY_HAS_WATCHED)),
                    cursor.getString(cache.getColumnIndex(cursor, DbAdapterMovies.KEY_DATE_ADDED)), false));
        }
    } catch (Exception e) {
    } finally {
        cursor.close();
        cache.clear();
    }
}