Example usage for android.database Cursor moveToFirst

List of usage examples for android.database Cursor moveToFirst

Introduction

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

Prototype

boolean moveToFirst();

Source Link

Document

Move the cursor to the first row.

Usage

From source file:net.nordist.lloydproof.CorrectionStorage.java

public int count() {
    openReadDB();/*from   w  w  w  .  j  a  v  a 2s.  c om*/
    Cursor cursor = readDB.query(TABLE_NAME, new String[] { "COUNT(1)" }, null, null, null, null, null);
    if (cursor.getCount() > 0) {
        cursor.moveToFirst();
        return cursor.getInt(0);
    } else {
        return 0;
    }
}

From source file:com.google.android.apps.iosched.ui.VendorDetailActivity.java

/** {@inheritDoc} */
public void onQueryComplete(int token, Object cookie, Cursor cursor) {
    try {/* w w w  .  j  a  va  2  s  .  c om*/
        if (!cursor.moveToFirst())
            return;

        mName.setText(cursor.getString(VendorsQuery.NAME));
        mLocation.setText(cursor.getString(VendorsQuery.LOCATION));

        // Unregister around setting checked state to avoid triggering
        // listener since change isn't user generated.
        mStarred.setOnCheckedChangeListener(null);
        mStarred.setChecked(cursor.getInt(VendorsQuery.STARRED) != 0);
        mStarred.setOnCheckedChangeListener(this);

        // Start background fetch to load vendor logo
        final String logoUrl = cursor.getString(VendorsQuery.LOGO_URL);
        new VendorLogoTask().execute(logoUrl);

        mUrl.setText(cursor.getString(VendorsQuery.URL));
        mDesc.setText(cursor.getString(VendorsQuery.DESC));
        mProductDesc.setText(cursor.getString(VendorsQuery.PRODUCT_DESC));

        mTrackId = cursor.getString(VendorsQuery.TRACK_ID);

        // Assign track details when found
        // TODO: handle vendors not attached to track
        ((TextView) findViewById(R.id.title_text)).setText(cursor.getString(VendorsQuery.TRACK_NAME));
        UIUtils.setTitleBarColor(findViewById(R.id.title_container), cursor.getInt(VendorsQuery.TRACK_COLOR));

    } finally {
        cursor.close();
    }
}

From source file:com.samuelcastro.cordova.InstagramSharePlugin.java

public String getRealImagePathFromURI(Uri contentUri) {
    String res = null;/*ww  w.  j a va 2  s. co m*/
    String[] proj = { MediaStore.Images.Media.DATA };
    Cursor cursor = cordova.getActivity().getContentResolver().query(contentUri, proj, null, null, null);
    if (cursor.moveToFirst()) {
        ;
        int column_index = cursor.getColumnIndexOrThrow(MediaStore.Images.Media.DATA);
        res = cursor.getString(column_index);
    }
    cursor.close();
    return res;
}

From source file:it.ms.theing.loquitur.functions.Storage.java

public Vector<Pair<String[], String>> loadCache(String name) {
    Cursor cursor = dataBase.rawQuery("select * from alias where genre=?", new String[] { name });
    cursor.moveToFirst();
    Vector<Pair<String[], String>> ja = new Vector<Pair<String[], String>>();
    while (!cursor.isAfterLast()) {
        String[] sv = cursor.getString(1).split("\'| ");
        String s = cursor.getString(2);
        Pair<String[], String> p = Pair.create(sv, s);
        ja.add(p);//from   w ww .  ja  v a  2 s.  co m
        cursor.moveToNext();
    }
    return ja;
}

From source file:net.eledge.android.toolkit.db.abstracts.Dao.java

private List<E> mapToEntities(Cursor cursor) {
    List<E> list = new ArrayList<>();
    if (cursor != null) {
        if (cursor.moveToFirst()) {
            do {//ww  w .j ava  2  s  . c  om
                try {
                    E instance = clazz.newInstance();
                    for (Field field : clazz.getFields()) {
                        if (field.isAnnotationPresent(Column.class)) {
                            int columnIndex = cursor.getColumnIndex(SQLBuilder.getFieldName(field));
                            if (!cursor.isNull(columnIndex)) {
                                FieldType fieldType = FieldType.getType(field.getType());
                                fieldType.convertToField(instance, field, cursor, columnIndex);
                            }
                        }
                    }
                    list.add(instance);
                } catch (IllegalArgumentException | IllegalAccessException | InstantiationException e) {
                    Log.e(this.getClass().getName(), e.getMessage(), e);
                }
            } while (cursor.moveToNext());
        }
        cursor.close();
    }
    return list;
}

From source file:com.kynetx.api.java

public void setApp(Cursor apps) {
    appId = "";/*from ww  w. j av a2 s  . c om*/
    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.almarsoft.GroundhogReader.lib.DBUtils.java

public static String getGroupNameFromId(int groupid, Context context) {

    DBHelper db = new DBHelper(context);
    SQLiteDatabase dbread = db.getReadableDatabase();

    String query = "SELECT name FROM subscribed_groups WHERE _id=" + groupid;
    Cursor cur = dbread.rawQuery(query, null);

    if (cur.getCount() != 1) {
        Log.w("GroundhogReader", "Trying to get name for groupid " + groupid + " which doesnt exists on DB");
        cur.close();//from  w  w w  .  j av a  2  s  .  co  m
        dbread.close();
        db.close();
        return null;
    }

    cur.moveToFirst();
    String groupname = cur.getString(0);
    cur.close();
    dbread.close();
    db.close();

    return groupname;
}

From source file:com.phicomm.account.operator.UploadContactOperation.java

@Override
public Bundle execute(Context context, Request request) {
    //read upload table
    //xml//from   w  ww .  j  a v  a 2  s  .  c o  m
    //upload to service   -- ok

    String ssession_id = null;
    String user_key = null;
    String user_name = null;
    String xmlDoc = null;
    String sync_time = null;
    Bundle resultData = new Bundle();
    Cursor persionCursor = context.getContentResolver().query(Provider.PersonColumns.CONTENT_URI, null, null,
            null, null);
    if (persionCursor != null) {
        if (persionCursor.moveToFirst()) {
            ssession_id = persionCursor
                    .getString(persionCursor.getColumnIndex(Provider.PersonColumns.JSSESSIONID));
            user_key = persionCursor.getString(persionCursor.getColumnIndex(Provider.PersonColumns.USER_KEY));
            user_name = persionCursor.getString(persionCursor.getColumnIndex(Provider.PersonColumns.NAME));
            sync_time = persionCursor.getString(persionCursor.getColumnIndex(Provider.PersonColumns.SYNC_TIME));
        }
        persionCursor.close();
    }
    //mode xmlDoc.
    ContactUpload upload = new ContactUpload();
    UploadDataOperate uploadOperate = new UploadDataOperate(context);
    Log.i("ss", "_____upload :" + uploadOperate.judgeUploadDataExist());
    if (uploadOperate.judgeUploadDataExist()) {
        ArrayList<Contact> updataValues = upload.getUploadContactList(context);
        xmlDoc = NetworkUtilities.modContactToXml(updataValues, user_name, user_key, sync_time);
    }
    String url = WSConfig.WS_SYNC_CONTACT_URL + ssession_id;
    NetworkConnection networkConnection1 = new NetworkConnection(context, url);
    ArrayList<BasicNameValuePair> parameterList = new ArrayList<BasicNameValuePair>();
    BasicNameValuePair value = new BasicNameValuePair("XML", xmlDoc);
    parameterList.add(value);
    networkConnection1.setParameters(parameterList);
    try {
        ConnectionResult result = networkConnection1.execute();
        resultData.putString("result", result.body);
        Log.i("ss", "________________________________result.body:" + result.body);
    } catch (ConnectionException e) {
        e.printStackTrace();
    }
    Log.i("ss", "_______________________________________OK");
    return resultData;
}

From source file:com.jaspersoft.android.jaspermobile.util.SavedItemHelper.java

private File getFile(Uri recordUri) {
    Cursor cursor = context.getContentResolver().query(recordUri, null, null, null, null);
    if (cursor == null || !cursor.moveToFirst())
        return null;

    File file = new File(cursor.getString(cursor.getColumnIndex(SavedItemsTable.FILE_PATH)));
    cursor.close();//from w  w  w.  j  a v  a  2 s  .c  o m
    return file;
}

From source file:com.jaspersoft.android.jaspermobile.util.SavedItemHelper.java

private String getExtension(Uri recordUri) {
    Cursor cursor = context.getContentResolver().query(recordUri, null, null, null, null);
    if (cursor == null || !cursor.moveToFirst())
        return null;

    String extension = cursor.getString(cursor.getColumnIndex(SavedItemsTable.FILE_FORMAT));
    cursor.close();/*w ww. j a  va  2s.c  om*/
    return extension;
}