List of usage examples for android.database Cursor moveToFirst
boolean moveToFirst();
From source file:biz.incomsystems.fwknop2.SendSPA.java
public int send(String nick, final Activity ourAct) { mydb = new DBHelper(ourAct); config = new Config(); config = mydb.getConfig(nick);//from w w w . j a v a 2 s . c o m Cursor CurrentIndex = mydb.getData(nick); CurrentIndex.moveToFirst(); //These variables are the ones that the jni pulls settings from. access_str = config.PORTS; passwd_str = config.KEY; hmac_str = config.HMAC; destip_str = config.SERVER_IP; destport_str = config.SERVER_PORT; fw_timeout_str = config.SERVER_TIMEOUT; allowip_str = config.ACCESS_IP; nat_ip_str = config.NAT_IP; nat_port_str = config.NAT_PORT; server_cmd_str = ""; nat_access_str = ""; if (!nat_ip_str.equalsIgnoreCase("")) { nat_access_str = nat_ip_str + "," + nat_port_str; } if (config.KEY_BASE64) { passwd_b64 = "true"; } else { passwd_b64 = "false"; } if (config.HMAC_BASE64) { hmac_b64 = "true"; } else { hmac_b64 = "false"; } final getExternalIP task = new getExternalIP(ourAct); task.execute(); return 0; }
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 ww w. j ava 2 s .c o 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.acrutiapps.browser.tasks.HistoryBookmarksExportTask.java
private String writeAsJSON(Cursor... params) { try {//from ww w .ja va 2s. c o m String fileName = mContext.getString(R.string.ApplicationName) + "-" + getNowForFileName() + ".json"; File file = new File(Environment.getExternalStorageDirectory(), fileName); FileWriter writer = new FileWriter(file); FoldersJSONArray foldersArray = new FoldersJSONArray(); BookmarksJSONArray bookmarksArray = new BookmarksJSONArray(); HistoryJSONArray historyArray = new HistoryJSONArray(); Cursor c = params[0]; if (c.moveToFirst()) { int current = 0; int total = c.getCount(); int idIndex = c.getColumnIndex(BookmarksProvider.Columns._ID); int titleIndex = c.getColumnIndex(BookmarksProvider.Columns.TITLE); int urlIndex = c.getColumnIndex(BookmarksProvider.Columns.URL); int creationDateIndex = c.getColumnIndex(BookmarksProvider.Columns.CREATION_DATE); int visitedDateIndex = c.getColumnIndex(BookmarksProvider.Columns.VISITED_DATE); int visitsIndex = c.getColumnIndex(BookmarksProvider.Columns.VISITS); int bookmarkIndex = c.getColumnIndex(BookmarksProvider.Columns.BOOKMARK); int folderIndex = c.getColumnIndex(BookmarksProvider.Columns.IS_FOLDER); int parentfolderIdIndex = c.getColumnIndex(BookmarksProvider.Columns.PARENT_FOLDER_ID); while (!c.isAfterLast()) { publishProgress(1, current, total); boolean isFolder = c.getInt(folderIndex) > 0 ? true : false; if (isFolder) { String title = c.getString(titleIndex); title = title != null ? URLEncoder.encode(title, "UTF-8") : ""; foldersArray.add(title, c.getLong(idIndex), c.getLong(parentfolderIdIndex)); } else { boolean isBookmark = c.getInt(bookmarkIndex) > 0 ? true : false; String title = c.getString(titleIndex); title = title != null ? URLEncoder.encode(title, "UTF-8") : ""; String url = c.getString(urlIndex); url = url != null ? URLEncoder.encode(url, "UTF-8") : ""; if (isBookmark) { bookmarksArray.add(c.getLong(parentfolderIdIndex), title, url, c.getLong(creationDateIndex), c.getLong(visitedDateIndex), c.getInt(visitsIndex)); } else { historyArray.add(title, url, c.getLong(visitedDateIndex), c.getInt(visitsIndex)); } } current++; c.moveToNext(); } } JSONObject output = new JSONObject(); output.put("folders", foldersArray); output.put("bookmarks", bookmarksArray); output.put("history", historyArray); writer.write(output.toString(1)); writer.flush(); writer.close(); } catch (JSONException e) { e.printStackTrace(); return e.getMessage(); } catch (IOException e) { e.printStackTrace(); return e.getMessage(); } return null; }
From source file:jp.ac.tokushima_u.is.ll.io.LanguageJsonHandler.java
public ArrayList<ContentProviderOperation> parse(ContentResolver resolver) { final ArrayList<ContentProviderOperation> batch = Lists.newArrayList(); Uri uri = Languages.CONTENT_URI; String sortOrder = SyncColumns.UPDATED + " desc"; Cursor cursor = resolver.query(uri, LanguagesQuery.PROJECTION, null, null, sortOrder); try {// w w w.j a v a2 s .c o m if (cursor.moveToFirst()) { Log.d(TAG, "Language has been inserted"); int count = cursor.getCount(); if (count > 3) { return batch; } } } finally { cursor.close(); } HttpPost httpPost = new HttpPost(this.systemUrl + this.syncServiceUrl + this.languageSearchUrl); try { DefaultHttpClient client = HttpClientFactory.createHttpClient(); MultipartEntity params = new MultipartEntity(); httpPost.setEntity(params); HttpResponse response = client.execute(httpPost); HttpEntity entity = response.getEntity(); if (entity != null) { InputStream instream = entity.getContent(); String result = convertStreamToString(instream); instream.close(); JSONObject json = new JSONObject(result); if (json != null) { JSONArray array = json.getJSONArray("languages"); if (array != null) { for (int i = 0; i < array.length(); i++) { JSONObject o = array.getJSONObject(i); String languageId = o.getString("id"); if (languageId == null || languageId.length() <= 0) continue; ContentProviderOperation.Builder builder = ContentProviderOperation .newInsert(Languages.CONTENT_URI); builder.withValue(Languages.LANGUAGE_ID, languageId); if (o.getString("code") != null && o.getString("code").length() > 0 && !"null".equals(o.getString("code"))) builder.withValue(Languages.CODE, o.getString("code")); if (o.getString("name") != null && o.getString("name").length() > 0 && !"null".equals(o.getString("name"))) builder.withValue(Languages.NAME, o.getString("name")); builder.withValue(SyncColumns.UPDATED, Calendar.getInstance().getTimeInMillis()); batch.add(builder.build()); } } } } } catch (Exception e) { Log.d(TAG, "exception occured", e); } return batch; }
From source file:com.QuarkLabs.BTCeClient.UpdateWidgetsTask.java
@Override protected JSONObject doInBackground(Void... params) { Set<String> set = new HashSet<>(); JSONObject response = null;/*from w w w . ja v a 2s .com*/ 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.clevertrail.mobile.Database_SavedTrails.java
public String getJSONString(String sName) { String[] columns = new String[] { "json" }; String selection = "name = '" + sName + "'"; Cursor cursor = sqLiteDatabase.query(MYDATABASE_TABLE, columns, selection, null, null, null, null); cursor.moveToFirst(); int index_JSON = cursor.getColumnIndex("json"); String sReturn = ""; if (!cursor.isAfterLast()) sReturn = cursor.getString(index_JSON); return sReturn; }
From source file:com.phonegap.Storage.java
/** * Process query results.// w ww . j ava 2 s.co m * * @param cur Cursor into query results * @param tx_id Transaction id */ public void processResults(Cursor cur, String tx_id) { String result = "[]"; // If query result has rows if (cur.moveToFirst()) { JSONArray fullresult = new JSONArray(); String key = ""; String value = ""; int colCount = cur.getColumnCount(); // Build up JSON result object for each row do { JSONObject row = new JSONObject(); try { for (int i = 0; i < colCount; ++i) { key = cur.getColumnName(i); value = cur.getString(i); row.put(key, value); } fullresult.put(row); } catch (JSONException e) { e.printStackTrace(); } } while (cur.moveToNext()); result = fullresult.toString(); } // Let JavaScript know that there are no more rows this.sendJavascript("droiddb.completeQuery('" + tx_id + "', " + result + ");"); }
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(); 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)); }/* ww w.ja v a 2 s . c om*/ 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; }
From source file:com.remobile.file.ContentFilesystem.java
@Override public JSONObject getFileMetadataForLocalURL(LocalFilesystemURL inputURL) throws FileNotFoundException { long size = -1; long lastModified = 0; Uri nativeUri = toNativeUri(inputURL); String mimeType = resourceApi.getMimeType(nativeUri); Cursor cursor = openCursorForURL(nativeUri); try {/*from w w w . j a v a2s. c om*/ if (cursor != null && cursor.moveToFirst()) { size = resourceSizeForCursor(cursor); lastModified = lastModifiedDateForCursor(cursor); } else { // Some content providers don't support cursors at all! CordovaResourceApi.OpenForReadResult offr = resourceApi.openForRead(nativeUri); size = offr.length; } } catch (IOException e) { throw new FileNotFoundException(); } finally { if (cursor != null) cursor.close(); } JSONObject metadata = new JSONObject(); try { metadata.put("size", size); metadata.put("type", mimeType); metadata.put("name", name); metadata.put("fullPath", inputURL.path); metadata.put("lastModifiedDate", lastModified); } catch (JSONException e) { return null; } return metadata; }
From source file:com.clevertrail.mobile.Database_SavedTrails.java
public String getJSONString() { String[] columns = new String[] { "json" }; Cursor cursor = sqLiteDatabase.query(MYDATABASE_TABLE, columns, null, null, null, null, null); cursor.moveToFirst(); int index_JSON = cursor.getColumnIndex("json"); //we will create a simple return value of the format: //"[trail1JSON, trail2JSON, ...]" String sReturn = "["; while (!cursor.isAfterLast()) { String sTrailJSON = cursor.getString(index_JSON); sReturn = sReturn.concat(sTrailJSON); cursor.moveToNext();/*from w ww. j a va 2 s. c o m*/ if (!cursor.isAfterLast()) { if (sTrailJSON.compareTo("") != 0) sReturn = sReturn.concat(","); } else { break; } } sReturn = sReturn.concat("]"); return sReturn; }