List of usage examples for android.database Cursor getInt
int getInt(int columnIndex);
From source file:com.cryart.sabbathschool.util.SSCore.java
public ArrayList<SSLesson> ssGetLessons() { SQLiteDatabase db = this.getReadableDatabase(); Cursor c = db.rawQuery("SELECT ss_quarters.serial " + "FROM ss_quarters, ss_lessons, ss_days " + "WHERE ss_days.day_date = ? AND ss_days.day_lesson_serial = ss_lessons.serial " + " AND ss_lessons.lesson_quarter_serial = ss_quarters.serial " + " AND ss_quarters.quarter_lang = ?", new String[] { this.ssTodaysDate(), LANGUAGE }); c.moveToFirst();/*from www. j a va 2 s .c o m*/ int ssQuarterSerial = c.getInt(0); c = db.rawQuery("SELECT ss_lessons.* " + "FROM ss_lessons " + "WHERE ss_lessons.lesson_quarter_serial = ?", new String[] { String.valueOf(ssQuarterSerial) }); ArrayList<SSLesson> ret = new ArrayList<SSLesson>(); if (c.moveToFirst()) { do { ret.add(new SSLesson(c.getInt(0), c.getString(2), c.getString(4))); } while (c.moveToNext()); } return ret; }
From source file:com.seneca.android.senfitbeta.DbHelper.java
public ArrayList<Exercise> getExByMuscles(int num) { Log.d("SELECT EXDB", "Getinging exercise By id"); String selectQuery = "SELECT * FROM exercises WHERE id LIKE '%" + num + "%' ORDER BY " + EXERCISE_ID + " ASC"; SQLiteDatabase db = this.getReadableDatabase(); Cursor cursor = db.rawQuery(selectQuery, null); cursor.moveToFirst();/* w w w .j a v a2 s . c o m*/ if (cursor == null) { Log.d("exiting", "NOTHING"); } if (cursor.getCount() == 0) { Log.d("NOTHING", "0 nothing"); } ArrayList<Exercise> temp = new ArrayList<Exercise>(); cursor.moveToFirst(); do { Exercise ex = new Exercise(); ex.setId(cursor.getInt(cursor.getColumnIndex(EXERCISE_ID))); ex.setLicense_author(cursor.getString(cursor.getColumnIndex(AUTHOR))); ex.setDescription(cursor.getString(cursor.getColumnIndex(DESCRIPTION))); ex.setName(cursor.getString(cursor.getColumnIndex(NAMETYPE))); ex.setName_original(cursor.getString(cursor.getColumnIndex(ORIGNALNAME))); ex.setCreation_date(cursor.getString(cursor.getColumnIndex(CREATIONDATE))); ex.setCategory(cursor.getString(cursor.getColumnIndex(CATEGORY))); temp.add(ex); } while (cursor.moveToNext()); cursor.close(); getReadableDatabase().close(); return temp; }
From source file:com.borqs.browser.combo.BookmarksPageCallbacks.java
@Override public boolean onChildClick(ExpandableListView parent, View v, int groupPosition, int childPosition, long id) { BrowserBookmarksAdapter adapter = getChildAdapter(groupPosition); Cursor cursor = adapter.getItem(childPosition); boolean isFolder = cursor.getInt(BookmarksLoader.COLUMN_INDEX_IS_FOLDER) != 0; if (onBookmarkSelected(cursor, isFolder)) { return true; }/*from w ww .j a v a2 s. co m*/ if (isFolder) { String title = cursor.getString(BookmarksLoader.COLUMN_INDEX_TITLE); Uri uri = ContentUris.withAppendedId(BrowserContract.Bookmarks.CONTENT_URI_DEFAULT_FOLDER, id); BreadCrumbView crumbs = getBreadCrumbs(groupPosition); if (crumbs != null) { // update crumbs crumbs.pushView(title, uri); crumbs.setVisibility(View.VISIBLE); } loadFolder(groupPosition, uri); } return true; }
From source file:com.rjfun.cordova.sms.SMSPlugin.java
private PluginResult listSMS(JSONObject filter, CallbackContext callbackContext) { Log.i(LOGTAG, ACTION_LIST_SMS);/*from w w w . java 2 s. c om*/ String uri_filter = filter.has(BOX) ? filter.optString(BOX) : "inbox"; int fread = filter.has(READ) ? filter.optInt(READ) : -1; int fid = filter.has("_id") ? filter.optInt("_id") : -1; String faddress = filter.optString(ADDRESS); String fcontent = filter.optString(BODY); int indexFrom = filter.has("indexFrom") ? filter.optInt("indexFrom") : 0; int maxCount = filter.has("maxCount") ? filter.optInt("maxCount") : 10; JSONArray jsons = new JSONArray(); Activity ctx = this.cordova.getActivity(); Uri uri = Uri.parse((SMS_URI_ALL + uri_filter)); Cursor cur = ctx.getContentResolver().query(uri, (String[]) null, "", (String[]) null, null); int i = 0; while (cur.moveToNext()) { JSONObject json; boolean matchFilter = false; if (fid > -1) { matchFilter = (fid == cur.getInt(cur.getColumnIndex("_id"))); } else if (fread > -1) { matchFilter = (fread == cur.getInt(cur.getColumnIndex(READ))); } else if (faddress.length() > 0) { matchFilter = faddress.equals(cur.getString(cur.getColumnIndex(ADDRESS)).trim()); } else if (fcontent.length() > 0) { matchFilter = fcontent.equals(cur.getString(cur.getColumnIndex(BODY)).trim()); } else { matchFilter = true; } if (!matchFilter) continue; if (i < indexFrom) continue; if (i >= indexFrom + maxCount) break; ++i; if ((json = this.getJsonFromCursor(cur)) == null) { callbackContext.error("failed to get json from cursor"); cur.close(); return null; } jsons.put((Object) json); } cur.close(); callbackContext.success(jsons); return null; }
From source file:com.frostwire.android.gui.Librarian.java
/** * @param fileType the file type/* w w w. j a va2 s . co m*/ * @return the number of files registered in the providers */ public int getNumFiles(Context context, byte fileType) { TableFetcher fetcher = TableFetchers.getFetcher(fileType); Cursor c = null; int numFiles = 0; try { ContentResolver cr = context.getContentResolver(); c = cr.query(fetcher.getContentUri(), new String[] { "count(" + BaseColumns._ID + ")" }, fetcher.where(), fetcher.whereArgs(), null); numFiles = c != null && c.moveToFirst() ? c.getInt(0) : 0; } catch (Throwable e) { Log.e(TAG, "Failed to get num of files", e); } finally { if (c != null) { c.close(); } } return numFiles; }
From source file:com.polyvi.xface.extension.telephony.XTelephonyExt.java
/** * Cursor?JSON// w w w . ja v a2 s .com */ private JSONObject getCallRecordFromCursor(Cursor cursor) { String callRecordId = cursor.getString(cursor.getColumnIndex(CallLog.Calls._ID)); String callRecordAddress = cursor.getString(cursor.getColumnIndex(CallLog.Calls.NUMBER)); String callRecordName = cursor.getString(cursor.getColumnIndex(CallLog.Calls.CACHED_NAME)); int callRecordTypeInt = cursor.getInt(cursor.getColumnIndex(CallLog.Calls.TYPE)); long startTime = cursor.getLong(cursor.getColumnIndex(CallLog.Calls.DATE)); long durationSeconds = cursor.getLong(cursor.getColumnIndex(CallLog.Calls.DURATION)); JSONObject callRecord = new JSONObject(); try { callRecord.put("callRecordId", callRecordId); callRecord.put("callRecordAddress", callRecordAddress); callRecord.put("callRecordName", callRecordName); callRecord.put("callRecordType", getCallRecordTypeStr(callRecordTypeInt)); callRecord.put("startTime", startTime); callRecord.put("durationSeconds", durationSeconds); } catch (JSONException e) { XLog.e(CLASS_NAME, e.toString()); } return callRecord; }
From source file:com.clearcenter.mobile_demo.mdSyncAdapter.java
public void onPerformSync(Account account, Bundle extras, String authority, ContentProviderClient provider, SyncResult syncResult) {//w w w . j a v a2s .c o m String authtoken = null; Log.i(TAG, "Starting sync operation..."); try { mdSSLUtil.DisableSecurity(); // Use the account manager to request the AuthToken we'll need // to talk to our sample server. If we don't have an AuthToken // yet, this could involve a round-trip to the server to request // an AuthToken. authtoken = account_manager.blockingGetAuthToken(account, mdConstants.AUTHTOKEN_TYPE, NOTIFY_AUTH_FAILURE); final String hostname = account_manager.getUserData(account, "hostname"); long _last_sample = -1; if (last_sample.containsKey(account.name)) _last_sample = last_sample.get(account.name); // Get sync data from server... final String data = mdRest.GetSystemInfo(hostname, authtoken, _last_sample); // Something went wrong :^( if (TextUtils.isEmpty(data)) return; if (_last_sample < 0) { int count = provider.delete(mdDeviceSamples.CONTENT_URI, mdDeviceSamples.NICKNAME + " = ?", new String[] { account.name }); Log.d(TAG, "Reset database, purged " + count + " samples."); } try { JSONObject json_data = new JSONObject(data); if (json_data.has("time")) _last_sample = Long.valueOf(json_data.getString("time")); Log.d(TAG, account.name + ": last sample time-stamp: " + _last_sample); } catch (JSONException e) { Log.e(TAG, "JSONException", e); return; } last_sample.put(account.name, _last_sample); ContentValues values = new ContentValues(); values.put(mdDeviceSamples.NICKNAME, account.name); values.put(mdDeviceSamples.DATA, data); provider.insert(mdDeviceSamples.CONTENT_URI, values); String projection[] = new String[] { mdDeviceSamples.SAMPLE_ID }; Cursor cursor = provider.query(mdDeviceSamples.CONTENT_URI, projection, mdDeviceSamples.NICKNAME + " = ?", new String[] { account.name }, mdDeviceSamples.SAMPLE_ID); int rows = cursor.getCount(); Log.d(TAG, "Rows: " + rows); if (rows <= mdConstants.MAX_SAMPLES) { cursor.close(); return; } Log.d(TAG, "Samples to purge: " + (rows - mdConstants.MAX_SAMPLES)); cursor.move(rows - mdConstants.MAX_SAMPLES); int top_id = cursor.getInt(cursor.getColumnIndex(mdDeviceSamples.SAMPLE_ID)); Log.d(TAG, "Top ID: " + top_id); cursor.close(); int count = provider.delete(mdDeviceSamples.CONTENT_URI, mdDeviceSamples.SAMPLE_ID + " <= ? AND " + mdDeviceSamples.NICKNAME + " = ?", new String[] { String.valueOf(top_id), account.name }); Log.d(TAG, "Purged " + count + " samples."); } catch (final RemoteException e) { Log.e(TAG, "RemoteException", e); syncResult.stats.numParseExceptions++; } catch (final AuthenticatorException e) { Log.e(TAG, "AuthenticatorException", e); syncResult.stats.numParseExceptions++; } catch (final OperationCanceledException e) { Log.e(TAG, "OperationCanceledExcetpion", e); } catch (final IOException e) { Log.e(TAG, "IOException", e); syncResult.stats.numIoExceptions++; } catch (final ParseException e) { Log.e(TAG, "ParseException", e); syncResult.stats.numParseExceptions++; } catch (final AuthenticationException e) { Log.e(TAG, "AuthenticationException", e); syncResult.stats.numAuthExceptions++; account_manager.invalidateAuthToken(mdConstants.AUTHTOKEN_TYPE, authtoken); } catch (GeneralSecurityException e) { Log.e(TAG, "GeneralSecurityException", e); } catch (final JSONException e) { Log.e(TAG, "JSONException", e); syncResult.stats.numParseExceptions++; } }
From source file:com.android.unit_tests.CheckinProviderTest.java
@MediumTest public void testEventReport() { long start = System.currentTimeMillis(); ContentResolver r = getContext().getContentResolver(); Checkin.logEvent(r, Checkin.Events.Tag.TEST, "Test Value"); Cursor c = r.query(Checkin.Events.CONTENT_URI, null, Checkin.Events.TAG + "=?", new String[] { Checkin.Events.Tag.TEST.toString() }, null); long id = -1; while (c.moveToNext()) { String tag = c.getString(c.getColumnIndex(Checkin.Events.TAG)); String value = c.getString(c.getColumnIndex(Checkin.Events.VALUE)); long date = c.getLong(c.getColumnIndex(Checkin.Events.DATE)); assertEquals(Checkin.Events.Tag.TEST.toString(), tag); if ("Test Value".equals(value) && date >= start) { assertTrue(id < 0);// w w w . j a va2 s .c o m id = c.getInt(c.getColumnIndex(Checkin.Events._ID)); } } assertTrue(id > 0); int rows = r.delete(ContentUris.withAppendedId(Checkin.Events.CONTENT_URI, id), null, null); assertEquals(1, rows); c.requery(); while (c.moveToNext()) { long date = c.getLong(c.getColumnIndex(Checkin.Events.DATE)); assertTrue(date < start); // Have deleted the only newer TEST. } c.close(); }
From source file:com.heneryh.aquanotes.ui.controllers.OutletsDataAdapter.java
/** {@inheritDoc} */ @Override//w w w . jav a2 s . c o m public void bindView(View view, Context context, Cursor cursor) { String outletName = cursor.getString(OutletDataViewQuery.NAME); ((TextView) view.findViewById(R.id.outlet_title)).setText(outletName); String deviceId = cursor.getString(OutletDataViewQuery.DEVICE_ID); ((TextView) view.findViewById(R.id.outlet_subtitle)).setText(deviceId); Spinner spinner = (Spinner) view.findViewById(R.id.spin); spinner.setAdapter(adapter); Integer controllerId = cursor.getInt(OutletDataViewQuery.CONTROLLER_ID); spinner.setOnItemSelectedListener(new myOnItemSelectedListener(outletName, controllerId)); // Assign track color to visible block String val = cursor.getString(OutletDataViewQuery.VALUE); final ImageView iconView = (ImageView) view.findViewById(android.R.id.icon1); Resources res = mActivity.getResources(); //// Axx = Auto-On or Auto-Off //// OFF = Manual Off //// ON = Manual On if (val.equalsIgnoreCase("AON")) { iconView.setImageDrawable(res.getDrawable(R.drawable.on)); spinner.setSelection(0); } else if (val.equalsIgnoreCase("AOF")) { iconView.setImageDrawable(res.getDrawable(R.drawable.off)); spinner.setSelection(0); } else if (val.equalsIgnoreCase("OFF")) { iconView.setImageDrawable(res.getDrawable(R.drawable.off)); spinner.setSelection(1); } else if (val.equalsIgnoreCase("ON")) { iconView.setImageDrawable(res.getDrawable(R.drawable.on)); spinner.setSelection(2); } else { iconView.setImageDrawable(new ColorDrawable(Color.BLUE)); } }
From source file:com.guess.license.plate.Task.LoadingTaskConn.java
private ServerError insOrUpDB(JSONObject jsObj, String objJS, String[] columns, String whereClause, String[] whereArgs, ContentValues values, int serverVersion) throws JSONException { ServerError result = ServerError.NO_ERROR; Cursor cursor = db.query(objJS, columns, whereClause, whereArgs, null, null, null); int count = cursor.getCount(); if (count > 0) { // Getting the version int currDBVersion = 0; while (cursor.moveToNext()) { if (cursor.isNull(0)) currDBVersion = 0;//from w w w .j a va 2s . c om else currDBVersion = cursor.getInt(0); } if (objJS.equals(WebConf.JSON_OBJECTS[0])) { if (currDBVersion == serverVersion) { return ServerError.OLD_BUILD; } db.update(objJS, values, whereClause, whereArgs); } else if (objJS.equals(WebConf.JSON_OBJECTS[1])) { // In case the plate processed is a new version update it in the DB if (currDBVersion != serverVersion) { db.update(objJS, values, whereClause, whereArgs); } } else if (objJS.equals(WebConf.JSON_OBJECTS[2])) { // In case the language processed is a new version update it in the DB if (currDBVersion != serverVersion) { db.update(objJS, values, whereClause, whereArgs); } } } else { db.insert(objJS, null, values); } return result; }