Example usage for android.database Cursor getInt

List of usage examples for android.database Cursor getInt

Introduction

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

Prototype

int getInt(int columnIndex);

Source Link

Document

Returns the value of the requested column as an int.

Usage

From source file:com.manning.androidhacks.hack023.adapter.TodoAdapter.java

@Override
public void bindView(View view, Context context, Cursor c) {
    final ViewHolder holder = (ViewHolder) view.getTag();
    holder.id.setText(c.getString(mInternalIdIndex));
    holder.title.setText(c.getString(mTitleIndex));

    final int status = c.getInt(mInternalStatusIndex);
    if (StatusFlag.CLEAN != status) {
        holder.title.setBackgroundColor(Color.RED);
    } else {//from  w  w w .  ja  v a 2  s  .c  o  m
        holder.title.setBackgroundColor(Color.GREEN);
    }

    final Long id = Long.valueOf(holder.id.getText().toString());
    holder.deleteButton.setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View v) {
            TodoDAO.getInstance().deleteTodo(mActivity.getContentResolver(), id);
        }
    });

}

From source file:com.almarsoft.GroundhogReader.lib.DBUtils.java

public static int getGroupIdFromName(String group, Context context) {

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

    // First get the group ID
    String query = "SELECT _ID FROM subscribed_groups WHERE name=" + esc(group);
    Cursor cur = dbread.rawQuery(query, null);

    if (cur.getCount() != 1) { // WTF?? 
        Log.w("GroundhogReader", "Trying to get id for group named " + group + " which doesnt exists on DB");
        cur.close();//from w  w  w. ja v a  2 s  .  co  m
        dbread.close();
        db.close();
        return -1;
    }

    cur.moveToFirst();
    int groupid = cur.getInt(0);
    cur.close();
    dbread.close();
    db.close();

    return groupid;
}

From source file:com.googlecode.android_scripting.facade.SmsFacade.java

@Rpc(description = "Returns a List of all message IDs.")
public List<Integer> smsGetMessageIds(@RpcParameter(name = "unreadOnly") Boolean unreadOnly,
        @RpcParameter(name = "folder") @RpcDefault("inbox") String folder) {
    Uri uri = buildFolderUri(folder);/*  www .  ja  va 2  s . c o  m*/
    List<Integer> result = new ArrayList<Integer>();
    String selection = buildSelectionClause(unreadOnly);
    String[] columns = { "_id" };
    Cursor cursor = mContentResolver.query(uri, columns, selection, null, null);
    while (cursor != null && cursor.moveToNext()) {
        result.add(cursor.getInt(0));
    }
    cursor.close();
    return result;
}

From source file:com.yozio.android.YozioDataStoreImpl.java

public int getNumEvents() {
    synchronized (this) {
        int count = -1;
        try {/*  w  w w. ja  v a  2  s.  c  o m*/
            Cursor cursor = dbHelper.getReadableDatabase()
                    .rawQuery("SELECT COUNT(*) FROM " + EVENTS_TABLE + where(), null);
            cursor.moveToFirst();
            count = cursor.getInt(0);
            cursor.close();
        } catch (SQLiteException e) {
            Log.e(LOGTAG, "getNumEvents", e);
        } finally {
            dbHelper.close();
        }
        return count;
    }
}

From source file:DictionaryDatabase.java

public long findWordID(String word) {
    long returnVal = -1;
    SQLiteDatabase db = getReadableDatabase();

    Cursor cursor = db.rawQuery("SELECT _id FROM " + TABLE_DICTIONARY + " WHERE " + FIELD_WORD + " = ?",
            new String[] { word });
    Log.i("findWordID", "getCount()=" + cursor.getCount());
    if (cursor.getCount() == 1) {
        cursor.moveToFirst();/*from   w  ww . ja va 2s.  c om*/
        returnVal = cursor.getInt(0);
    }
    return returnVal;
}

From source file:cn.code.notes.gtask.data.TaskList.java

public int getSyncAction(Cursor c) {
    try {//from  w w  w  . jav a 2 s .c  o  m
        if (c.getInt(SqlNote.LOCAL_MODIFIED_COLUMN) == 0) {
            // there is no local update
            if (c.getLong(SqlNote.SYNC_ID_COLUMN) == getLastModified()) {
                // no update both side
                return SYNC_ACTION_NONE;
            } else {
                // apply remote to local
                return SYNC_ACTION_UPDATE_LOCAL;
            }
        } else {
            // validate gtask id
            if (!c.getString(SqlNote.GTASK_ID_COLUMN).equals(getGid())) {
                Log.e(TAG, "gtask id doesn't match");
                return SYNC_ACTION_ERROR;
            }
            if (c.getLong(SqlNote.SYNC_ID_COLUMN) == getLastModified()) {
                // local modification only
                return SYNC_ACTION_UPDATE_REMOTE;
            } else {
                // for folder conflicts, just apply local modification
                return SYNC_ACTION_UPDATE_REMOTE;
            }
        }
    } catch (Exception e) {
        Log.e(TAG, e.toString());
        e.printStackTrace();
    }

    return SYNC_ACTION_ERROR;
}

From source file:com.asd.littleprincesbeauty.data.TaskList.java

@Override
public int getSyncAction(Cursor c) {
    try {/* ww  w . j a  v  a  2s  .  c  o  m*/
        if (c.getInt(SqlNote.LOCAL_MODIFIED_COLUMN) == 0) {
            // there is no local update
            if (c.getLong(SqlNote.SYNC_ID_COLUMN) == getLastModified()) {
                // no update both side
                return SYNC_ACTION_NONE;
            } else {
                // apply remote to local
                return SYNC_ACTION_UPDATE_LOCAL;
            }
        } else {
            // validate gtask id
            if (!c.getString(SqlNote.GTASK_ID_COLUMN).equals(getGid())) {
                Log.e(TAG, "gtask id doesn't match");
                return SYNC_ACTION_ERROR;
            }
            if (c.getLong(SqlNote.SYNC_ID_COLUMN) == getLastModified()) {
                // local modification only
                return SYNC_ACTION_UPDATE_REMOTE;
            } else {
                // for folder conflicts, just apply local modification
                return SYNC_ACTION_UPDATE_REMOTE;
            }
        }
    } catch (Exception e) {
        Log.e(TAG, e.toString());
        e.printStackTrace();
    }

    return SYNC_ACTION_ERROR;
}

From source file:com.clutch.ClutchStats.java

public int getCachedChoice(String name) {
    int resp = -1;
    SQLiteDatabase db = getReadableDatabase();
    String[] args = { name };//from w w w.j a  v  a  2s . c  o  m
    Cursor cur = db.rawQuery("SELECT choice FROM abcache WHERE name = ?", args);
    cur.moveToFirst();
    while (!cur.isAfterLast()) {
        resp = cur.getInt(0);
        cur.moveToNext();
    }
    db.close();
    return resp;
}

From source file:com.ubikod.urbantag.model.TagManager.java

/**
 * Convert a cursor to a tag/*w  w w .  j  a v  a  2s . c  o m*/
 * @param c
 * @return
 */
private Tag cursorToTag(Cursor c) {
    Tag t = new Tag(c.getInt(DatabaseHelper.TAG_NUM_COL_ID), c.getString(DatabaseHelper.TAG_NUM_COL_NAME),
            c.getInt(DatabaseHelper.TAG_NUM_COL_COLOR));
    t.setSelected(c.getInt(DatabaseHelper.TAG_NUM_COL_NOTIFY) == 1);
    return t;
}

From source file:export.format.FacebookCourse.java

public JSONObject export(long activityId, boolean showTrail, JSONObject runObj)
        throws IOException, JSONException {

    final String[] aColumns = { DB.ACTIVITY.NAME, DB.ACTIVITY.COMMENT, DB.ACTIVITY.START_TIME,
            DB.ACTIVITY.DISTANCE, DB.ACTIVITY.TIME, DB.ACTIVITY.SPORT };
    Cursor cursor = mDB.query(DB.ACTIVITY.TABLE, aColumns, "_id = " + activityId, null, null, null, null);
    cursor.moveToFirst();//from   w  w  w.j av a2 s . c  o  m

    if (runObj != null) {
        runObj.put("sport", cursor.getInt(5));
        runObj.put("startTime", cursor.getLong(2));
        runObj.put("endTime", cursor.getLong(2) + cursor.getLong(4));
        if (!cursor.isNull(1))
            runObj.put("comment", cursor.getString(1));
    }

    JSONObject obj = new JSONObject();
    double distance = cursor.getDouble(3);
    long duration = cursor.getLong(4);
    cursor.close();

    double unitMeters = formatter.getUnitMeters();
    if (distance < unitMeters) {
        obj.put("distance", new JSONObject().put("value", distance).put("units", "m"));
    } else {
        final int decimals = 1;
        double base = distance / unitMeters;
        double val = Formatter.round(base, decimals);
        obj.put("distance", new JSONObject().put("value", val).put("units", formatter.getUnitString()));
    }

    obj.put("duration", new JSONObject().put("value", duration).put("units", "s"));
    if (distance != 0) {
        obj.put("pace", pace(distance, duration));
    }

    if (showTrail) {
        JSONArray trail = trail(activityId);
        if (trail != null)
            obj.put("metrics", trail);
    }

    return obj;
}