List of usage examples for android.database Cursor getInt
int getInt(int columnIndex);
From source file:com.logilite.vision.camera.CameraLauncher.java
private int getImageOrientation(Uri uri) { int rotate = 0; String[] cols = { MediaStore.Images.Media.ORIENTATION }; try {//from ww w. j ava 2s .c o m Cursor cursor = cordova.getActivity().getContentResolver().query(uri, cols, null, null, null); if (cursor != null) { cursor.moveToPosition(0); rotate = cursor.getInt(0); cursor.close(); } } catch (Exception e) { // You can get an IllegalArgumentException if ContentProvider doesn't support querying for orientation. } return rotate; }
From source file:com.dileepindia.cordova.sms.SMSPlugin.java
private PluginResult listSMS(JSONObject filter, CallbackContext callbackContext) { Log.e("SMSPlugin", "listSMS"); String uri_filter = filter.optString("box"); int fread = filter.optInt("read"); int fid = filter.optInt("_id"); String faddress = filter.optString("address"); String fcontent = filter.optString("body"); long fdate1 = filter.optLong("date"); int indexFrom = filter.has("indexFrom") ? filter.optInt("indexFrom") : 0; int maxCount = filter.has("maxCount") ? filter.optInt("maxCount") : 100; JSONArray jsons = new JSONArray(); Context ctx = this.cordova.getActivity(); Uri uri = Uri.parse("content://sms/" + uri_filter); Cursor cur = ctx.getContentResolver().query(uri, null, "", null, null); int i = 0;/*from w ww .ja v a 2 s .c om*/ while (cur.moveToNext()) if (i >= indexFrom) { i++; if (i >= indexFrom + maxCount) break; boolean matchFilter = false; if (fid > -1) { int _id = cur.getInt(cur.getColumnIndex("_id")); matchFilter = fid == _id; } else if (fread > -1) { int read = cur.getInt(cur.getColumnIndex("read")); matchFilter = fread == read; } else if (faddress.length() > 0) { String address = cur.getString(cur.getColumnIndex("address")).trim(); matchFilter = address.contains(faddress); } else if (fdate1 > 0) { System.out.println(fdate1); long dateInMillis = cur.getLong(cur.getColumnIndex("date")); matchFilter = fdate1 <= dateInMillis; } else if (fcontent.length() > 0) { String body = cur.getString(cur.getColumnIndex("body")).trim(); matchFilter = body.equals(fcontent); } else { matchFilter = true; } if (matchFilter) { JSONObject json = getJsonFromCursor(cur); if (json == null) { callbackContext.error("failed to get json from cursor"); cur.close(); return null; } jsons.put(json); } } cur.close(); callbackContext.success(jsons); return null; }
From source file:com.mk4droid.IMC_Services.DatabaseHandler.java
/** * Getting all categories//from w ww . j a v a 2 s.c om * @return */ public ArrayList<Category> getAllCategories() { ArrayList<Category> mCategL = new ArrayList<Category>(); // Select All Query String selectQuery = "SELECT * FROM " + TABLE_Categories; if (!db.isOpen()) db = this.getWritableDatabase(); Cursor cursor = db.rawQuery(selectQuery, null); if (cursor.moveToFirst()) { do { Category mCategory = new Category(cursor.getInt(0), cursor.getString(1), cursor.getBlob(2), cursor.getInt(3), cursor.getInt(4), cursor.getInt(5)); mCategL.add(mCategory); } while (cursor.moveToNext()); } cursor.close(); return mCategL; }
From source file:io.n7.calendar.caldav.CalDAVService.java
private void doSyncCalendar(Account acc, long calid) throws Exception { // Get a list of local events String[] evproj1 = new String[] { Events._ID, Events._SYNC_ID, Events.DELETED, Events._SYNC_DIRTY }; HashMap<String, Long> localevs = new HashMap<String, Long>(); HashMap<String, Long> removedevs = new HashMap<String, Long>(); HashMap<String, Long> dirtyevs = new HashMap<String, Long>(); HashMap<String, Long> newdevevs = new HashMap<String, Long>(); Cursor c = mCR.query(EVENTS_URI, evproj1, Events.CALENDAR_ID + "=" + calid, null, null); long tid;// w ww. ja v a2 s. co m String tuid = null; if (c.moveToFirst()) { do { tid = c.getLong(0); tuid = c.getString(1); if (c.getInt(2) != 0) removedevs.put(tuid, tid); else if (tuid == null) { // generate a UUID tuid = UUID.randomUUID().toString(); newdevevs.put(tuid, tid); } else if (c.getInt(3) != 0) dirtyevs.put(tuid, tid); else localevs.put(tuid, tid); } while (c.moveToNext()); c.close(); } CalDAV4jIf caldavif = new CalDAV4jIf(getAssets()); caldavif.setCredentials(new CaldavCredential(acc.getProtocol(), acc.getHost(), acc.getPort(), acc.getHome(), acc.getCollection(), acc.getUser(), acc.getPassword())); //add new device events to server for (String uid : newdevevs.keySet()) addEventOnServer(uid, newdevevs.get(uid), caldavif); //delete the locally removed events on server for (String uid : removedevs.keySet()) { removeEventOnServer(uid, caldavif); // clean up provider DB? removeLocalEvent(removedevs.get(uid)); } //update the dirty events on server for (String uid : dirtyevs.keySet()) updateEventOnServer(uid, dirtyevs.get(uid), caldavif); // Get events from server VEvent[] evs = caldavif.getEvents(); // add/update to provider DB String[] evproj = new String[] { Events._ID }; ContentValues cv = new ContentValues(); String temp, durstr = null; for (VEvent v : evs) { cv.clear(); durstr = null; String uid = ICalendarUtils.getUIDValue(v); // XXX Some times the server seem to return the deleted event if we do get events immediately // after removing.. // So ignore the possibility of deleted event on server was modified on server, for now. if (removedevs.containsKey(uid)) continue; //TODO: put etag here cv.put(Events._SYNC_ID, uid); //UUID cv.put(Events._SYNC_DATA, uid); cv.put(Events.CALENDAR_ID, calid); cv.put(Events.TITLE, ICalendarUtils.getSummaryValue(v)); cv.put(Events.DESCRIPTION, ICalendarUtils.getPropertyValue(v, Property.DESCRIPTION)); cv.put(Events.EVENT_LOCATION, ICalendarUtils.getPropertyValue(v, Property.LOCATION)); String tzid = ICalendarUtils.getPropertyValue(v, Property.TZID); if (tzid == null) tzid = Time.getCurrentTimezone(); cv.put(Events.EVENT_TIMEZONE, tzid); long dtstart = parseDateTimeToMillis(ICalendarUtils.getPropertyValue(v, Property.DTSTART), tzid); cv.put(Events.DTSTART, dtstart); temp = ICalendarUtils.getPropertyValue(v, Property.DTEND); if (temp != null) cv.put(Events.DTEND, parseDateTimeToMillis(temp, tzid)); else { temp = ICalendarUtils.getPropertyValue(v, Property.DURATION); durstr = temp; if (temp != null) { cv.put(Events.DURATION, durstr); // We still need to calculate and enter DTEND. Otherwise, the Android is not displaying // the event properly Duration dur = new Duration(); dur.parse(temp); cv.put(Events.DTEND, dtstart + dur.getMillis()); } } //TODO add more fields //if the event is already present, update it otherwise insert it // TODO find if something changed on server using etag Uri euri; if (localevs.containsKey(uid) || dirtyevs.containsKey(uid)) { if (localevs.containsKey(uid)) { tid = localevs.get(uid); localevs.remove(uid); } else { tid = dirtyevs.get(uid); dirtyevs.remove(uid); } mCR.update(ContentUris.withAppendedId(EVENTS_URI, tid), cv, null, null); //clear sync dirty flag cv.clear(); cv.put(Events._SYNC_DIRTY, 0); mCR.update(ContentUris.withAppendedId(EVENTS_URI, tid), cv, null, null); Log.d(TAG, "Updated " + uid); } else if (!newdevevs.containsKey(uid)) { euri = mCR.insert(EVENTS_URI, cv); Log.d(TAG, "Inserted " + uid); } } // the remaining events in local and dirty event list are no longer on the server. So remove them. for (String uid : localevs.keySet()) removeLocalEvent(localevs.get(uid)); //XXX Is this possible? /* for (String uid: dirtyevs.keySet ()) removeLocalEvent (dirtyevs[uid]); */ }
From source file:com.xorcode.andtweet.TweetListActivity.java
@Override public void onCreateContextMenu(ContextMenu menu, View view, ContextMenuInfo menuInfo) { super.onCreateContextMenu(menu, view, menuInfo); // Get the adapter context menu information AdapterView.AdapterContextMenuInfo info; try {/*ww w . j a v a 2 s . c om*/ info = (AdapterView.AdapterContextMenuInfo) menuInfo; } catch (ClassCastException e) { Log.e(TAG, "bad menuInfo", e); return; } int m = 0; // Add menu items menu.add(0, CONTEXT_MENU_ITEM_REPLY, m++, R.string.menu_item_reply); menu.add(0, CONTEXT_MENU_ITEM_RETWEET, m++, R.string.menu_item_retweet); menu.add(0, CONTEXT_MENU_ITEM_SHARE, m++, R.string.menu_item_share); // menu.add(0, CONTEXT_MENU_ITEM_DIRECT_MESSAGE, m++, // R.string.menu_item_direct_message); // menu.add(0, CONTEXT_MENU_ITEM_UNFOLLOW, m++, // R.string.menu_item_unfollow); // menu.add(0, CONTEXT_MENU_ITEM_BLOCK, m++, R.string.menu_item_block); // menu.add(0, CONTEXT_MENU_ITEM_PROFILE, m++, // R.string.menu_item_view_profile); // Get the record for the currently selected item Uri uri = ContentUris.withAppendedId(Tweets.CONTENT_URI, info.id); Cursor c = getContentResolver().query(uri, new String[] { Tweets._ID, Tweets.MESSAGE, Tweets.AUTHOR_ID, Tweets.FAVORITED }, null, null, null); try { c.moveToFirst(); menu.setHeaderTitle(c.getString(c.getColumnIndex(Tweets.MESSAGE))); if (c.getInt(c.getColumnIndex(Tweets.FAVORITED)) == 1) { menu.add(0, CONTEXT_MENU_ITEM_DESTROY_FAVORITE, m++, R.string.menu_item_destroy_favorite); } else { menu.add(0, CONTEXT_MENU_ITEM_FAVORITE, m++, R.string.menu_item_favorite); } if (MyPreferences.getDefaultSharedPreferences().getString(MyPreferences.KEY_TWITTER_USERNAME, null) .equals(c.getString(c.getColumnIndex(Tweets.AUTHOR_ID)))) { menu.add(0, CONTEXT_MENU_ITEM_DESTROY_STATUS, m++, R.string.menu_item_destroy_status); } } catch (Exception e) { Log.e(TAG, "onCreateContextMenu: " + e.toString()); } finally { if (c != null && !c.isClosed()) c.close(); } }
From source file:com.triarc.sync.SyncAdapter.java
@SuppressLint("UseValueOf") private Object getModelValueFor(Cursor query, String fieldName, FieldType fieldType) throws JSONException { int columnIndex = query.getColumnIndex(fieldName); if (query.isNull(columnIndex)) { return null; }// ww w .j a va 2s .com switch (fieldType) { case Boolean: return new Boolean(query.getInt(columnIndex) != 0); case Date: return format.format(new Date(query.getLong(columnIndex))); case Numeric: return new Long(query.getLong(columnIndex)); case Text: return query.getString(columnIndex); case JsonObject: String json = query.getString(columnIndex); return new JSONObject(json); case JsonArray: json = query.getString(columnIndex); return new JSONArray(json); default: return null; } }
From source file:com.wildplot.android.ankistats.Forecast.java
/** * Due and cumulative due/*from w w w.jav a 2s. c om*/ * *********************************************************************************************** */ private boolean calculateDue(int type) { mType = type; mBackwards = false; mTitle = R.string.stats_forecast; mValueLabels = new int[] { R.string.statistics_young, R.string.statistics_mature }; mColors = new int[] { R.color.stats_young, R.color.stats_mature }; mAxisTitles = new int[] { type, R.string.stats_cards, R.string.stats_cumulative_cards }; int end = 0; int chunk = 0; switch (type) { case Utils.TYPE_MONTH: end = 31; chunk = 1; break; case Utils.TYPE_YEAR: end = 52; chunk = 7; break; case Utils.TYPE_LIFE: end = -1; chunk = 30; break; } String lim = "";// AND due - " + mCol.getSched().getToday() + " >= " + start; // leave this out in order to show // card too which were due the days before if (end != -1) { lim += " AND day <= " + end; } ArrayList<int[]> dues = new ArrayList<int[]>(); Cursor cur = null; try { String query; query = "SELECT (due - " + mCollectionData.getToday() + ")/" + chunk + " AS day, " // day + "count(), " // all cards + "sum(CASE WHEN ivl >= 21 THEN 1 ELSE 0 END) " // mature cards + "FROM cards WHERE did IN " + _limitWholeOnly() + " AND queue IN (2,3)" + lim + " GROUP BY day ORDER BY day"; //TODO remove: System.out.println("forecast query: " + query); cur = mAnkiDb.getDatabase().rawQuery(query, null); while (cur.moveToNext()) { dues.add(new int[] { cur.getInt(0), cur.getInt(1), cur.getInt(2) }); } } finally { if (cur != null && !cur.isClosed()) { cur.close(); } } // small adjustment for a proper chartbuilding with achartengine if (dues.size() == 0 || dues.get(0)[0] > 0) { dues.add(0, new int[] { 0, 0, 0 }); } if (end == -1 && dues.size() < 2) { end = 31; } if (type != Utils.TYPE_LIFE && dues.get(dues.size() - 1)[0] < end) { dues.add(new int[] { end, 0, 0 }); } else if (type == Utils.TYPE_LIFE && dues.size() < 2) { dues.add(new int[] { Math.max(12, dues.get(dues.size() - 1)[0] + 1), 0, 0 }); } mSeriesList = new double[3][dues.size()]; for (int i = 0; i < dues.size(); i++) { int[] data = dues.get(i); if (data[1] > mMaxCards) mMaxCards = data[1]; mSeriesList[0][i] = data[0]; mSeriesList[1][i] = data[1]; mSeriesList[2][i] = data[2]; if (data[0] > mLastElement) mLastElement = data[0]; if (data[0] == 0) { mZeroIndex = i; } } mMaxElements = dues.size() - 1; return dues.size() > 0; }
From source file:com.spoiledmilk.ibikecph.util.DB.java
public int getApiId(int id) { int ret = -1; SQLiteDatabase db = getWritableDatabase(); if (db == null) return -1; String strFilter = "_id= ?"; Cursor cur = db.query(TABLE_FAVORITES, new String[] { KEY_API_ID }, strFilter, new String[] { id + "" }, null, null, null);/* www . j a va 2 s. c o m*/ if (cur != null && cur.moveToFirst()) { if (cur != null && !cur.isAfterLast()) { ret = cur.getInt(cur.getColumnIndex(KEY_API_ID)); } } db.close(); return ret; }
From source file:ch.ethz.twimight.net.tds.TDSRequestMessage.java
/** * creates JSONObject to push Statistics to the TDS * /*from w ww .j a v a 2 s . c om*/ * @param * @return JSON Object * @throws JSONException */ public void createStatisticObject(Cursor stats, long follCount) throws JSONException { if (stats != null) { statisticObject = new JSONObject(); JSONArray statisticArray = new JSONArray(); while (!stats.isAfterLast()) { JSONObject row = new JSONObject(); row.put("latitude", Double .toString(stats.getDouble(stats.getColumnIndex(StatisticsDBHelper.KEY_LOCATION_LAT)))); row.put("longitude", Double .toString(stats.getDouble(stats.getColumnIndex(StatisticsDBHelper.KEY_LOCATION_LNG)))); row.put("accuracy", Integer .toString(stats.getInt(stats.getColumnIndex(StatisticsDBHelper.KEY_LOCATION_ACCURACY)))); row.put("provider", stats.getString(stats.getColumnIndex(StatisticsDBHelper.KEY_LOCATION_PROVIDER))); row.put("timestamp", Long.toString(stats.getLong(stats.getColumnIndex(StatisticsDBHelper.KEY_TIMESTAMP)))); row.put("network", stats.getString(stats.getColumnIndex(StatisticsDBHelper.KEY_NETWORK))); row.put("event", stats.getString(stats.getColumnIndex(StatisticsDBHelper.KEY_EVENT))); row.put("link", stats.getString(stats.getColumnIndex(StatisticsDBHelper.KEY_LINK))); row.put("isDisaster", Integer.toString(stats.getInt(stats.getColumnIndex(StatisticsDBHelper.KEY_ISDISASTER)))); row.put("followers_count", follCount); SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context); row.put("dis_mode_used", Preferences.getBoolean(context, R.string.pref_key_disastermode_has_been_used, false)); statisticArray.put(row); stats.moveToNext(); } stats.close(); statisticObject.put("content", statisticArray); } }
From source file:com.tuxpan.foregroundcameragalleryplugin.ForegroundCameraLauncher.java
private int getImageOrientation(Uri uri) { String[] cols = { MediaStore.Images.Media.ORIENTATION }; Cursor cursor = cordova.getActivity().getContentResolver().query(uri, cols, null, null, null); int rotate = 0; if (cursor != null) { cursor.moveToPosition(0);//from w ww. jav a 2 s . com rotate = cursor.getInt(0); cursor.close(); } return rotate; }