List of usage examples for android.database Cursor moveToNext
boolean moveToNext();
From source file:io.selendroid.server.ServerInstrumentation.java
public List<CallLogEntry> readCallLog() throws PermissionDeniedException { if (getTargetContext().checkCallingOrSelfPermission( Manifest.permission.READ_CALL_LOG) == PackageManager.PERMISSION_GRANTED) { List<CallLogEntry> logs = new ArrayList<CallLogEntry>(); Cursor managedCursor = getTargetContext().getContentResolver().query(CallLog.Calls.CONTENT_URI, null, null, null, null);//from ww w. j a v a 2 s .co m int number = managedCursor.getColumnIndex(CallLog.Calls.NUMBER); int type = managedCursor.getColumnIndex(CallLog.Calls.TYPE); int date = managedCursor.getColumnIndex(CallLog.Calls.DATE); int duration = managedCursor.getColumnIndex(CallLog.Calls.DURATION); while (managedCursor.moveToNext()) { String phNumber = managedCursor.getString(number); String callType = managedCursor.getString(type); String callDate = managedCursor.getString(date); Date callDayTime = new Date(Long.valueOf(callDate)); String callDuration = managedCursor.getString(duration); logs.add(new CallLogEntry(phNumber, Integer.parseInt(callDuration), callDayTime, Integer.parseInt(callType))); } managedCursor.close(); return logs; } else { throw new PermissionDeniedException( "Application under test does not have required READ_CALL_LOG permission for this feature."); } }
From source file:se.lu.nateko.edca.svc.GetMap.java
/** * Method that fetches the names of the layers set to be displayed in the local * SQLite database and returns them in a single String, with the names separated * by commas.// w w w. ja va 2s . c om * @return A String with the names of the layers to be included in a GetMap request. */ public String fetchLayerNames() { // Log.d(TAG, "fetchLayerNames() called."); Cursor layers = mService.getSQLhelper().fetchData(LocalSQLDBhelper.TABLE_LAYER, LocalSQLDBhelper.KEY_LAYER_COLUMNS, LocalSQLDBhelper.ALL_RECORDS, null, false); mService.getActiveActivity().startManagingCursor(layers); String layerString = ""; if (layers.moveToFirst()) { int layerCount = 0; if (layers.getInt(2) % LocalSQLDBhelper.LAYER_MODE_DISPLAY == 0) { // If the layer is set to "display", then; layerString = layerString + layers.getString(1); // Add the first name to the String. layerCount++; } while (layers.moveToNext()) { // As long as there's another row: if (layers.getInt(2) % LocalSQLDBhelper.LAYER_MODE_DISPLAY == 0) {// If the layer is set to "display", then; if (layerCount > 0) layerString = layerString + ","; // Add a comma separator to the String. layerString = layerString + layers.getString(1); // Add the next name to the String. layerCount++; } } Log.v(TAG, String.valueOf(layerCount) + " layers are to be included in the GetMap request."); } Log.v(TAG, "layerString: " + layerString); return layerString; }
From source file:heartware.com.heartware_master.DBAdapter.java
public ArrayList<HashMap<String, String>> getAllMeetups() { ArrayList<HashMap<String, String>> workoutList; workoutList = new ArrayList<HashMap<String, String>>(); String selectQuery = "SELECT * FROM " + MEETUPS_TABLE + " ORDER BY " + USER_ID + " ASC"; SQLiteDatabase database = this.getWritableDatabase(); Cursor cursor = database.rawQuery(selectQuery, null); if (cursor.moveToFirst()) { do {//from ww w . j av a2s. c om HashMap<String, String> workoutMap = new HashMap<String, String>(); workoutMap.put(USER_ID, cursor.getString(0)); workoutMap.put(NOTE, cursor.getString(1)); workoutMap.put(EXERCISE, cursor.getString(2)); workoutMap.put(LOCATION, cursor.getString(3)); workoutMap.put(DATE, cursor.getString(4)); workoutMap.put(PEOPLE, cursor.getString(5)); workoutList.add(workoutMap); } while (cursor.moveToNext()); } return workoutList; }
From source file:heartware.com.heartware_master.DBAdapter.java
public ArrayList<HashMap<String, String>> getAllMeetups(final String userId) { ArrayList<HashMap<String, String>> workoutList; workoutList = new ArrayList<HashMap<String, String>>(); String selectQuery = "SELECT * FROM " + MEETUPS_TABLE + " WHERE " + USER_ID + " ='" + userId + "' ORDER BY " + USER_ID + " ASC"; SQLiteDatabase database = this.getWritableDatabase(); Cursor cursor = database.rawQuery(selectQuery, null); if (cursor.moveToFirst()) { do {//w w w . ja v a 2 s . co m HashMap<String, String> workoutMap = new HashMap<String, String>(); workoutMap.put(USER_ID, cursor.getString(0)); workoutMap.put(NOTE, cursor.getString(1)); workoutMap.put(EXERCISE, cursor.getString(2)); workoutMap.put(LOCATION, cursor.getString(3)); workoutMap.put(DATE, cursor.getString(4)); workoutMap.put(PEOPLE, cursor.getString(5)); workoutList.add(workoutMap); } while (cursor.moveToNext()); } return workoutList; }
From source file:com.amazonaws.mobileconnectors.s3.transferutility.TransferDBUtil.java
/** * Queries the transfer record specified by main upload id. * * @param mainUploadId The mainUploadId of a multipart upload task * @return The bytes already uploaded for this multipart upload task *///from w w w .ja va 2s . c o m public long queryBytesTransferredByMainUploadId(int mainUploadId) { Cursor c = null; long bytesTotal = 0; try { c = transferDBBase.query(getPartUri(mainUploadId), null, null, null, null); while (c.moveToNext()) { final String state = c.getString(c.getColumnIndexOrThrow(TransferTable.COLUMN_STATE)); if (TransferState.PART_COMPLETED.equals(TransferState.getState(state))) { bytesTotal += c.getLong(c.getColumnIndexOrThrow(TransferTable.COLUMN_BYTES_TOTAL)); } } } finally { if (c != null) { c.close(); } } return bytesTotal; }
From source file:com.phonegap.ContactAccessorSdk3_4.java
/** * Create a ContactField JSONArray/*from www .j a v a 2 s .co m*/ * @param cr database access object * @param contactId the ID to search the database for * @return a JSONArray representing a set of ContactFields */ private JSONArray imQuery(ContentResolver cr, String contactId) { String imWhere = ContactMethods.PERSON_ID + " = ? AND " + ContactMethods.KIND + " = ?"; String[] imWhereParams = new String[] { contactId, ContactMethods.CONTENT_IM_ITEM_TYPE }; Cursor cursor = cr.query(ContactMethods.CONTENT_URI, null, imWhere, imWhereParams, null); JSONArray ims = new JSONArray(); JSONObject im; while (cursor.moveToNext()) { im = new JSONObject(); try { im.put("id", cursor.getString(cursor.getColumnIndex(ContactMethods._ID))); im.put("perf", false); im.put("value", cursor.getString(cursor.getColumnIndex(ContactMethodsColumns.DATA))); im.put("type", getContactType(cursor.getInt(cursor.getColumnIndex(ContactMethodsColumns.TYPE)))); ims.put(im); } catch (JSONException e) { Log.e(LOG_TAG, e.getMessage(), e); } } cursor.close(); return null; }
From source file:com.example.asaldanha.sunshine.app.FetchWeatherTask.java
/** * Take the String representing the complete forecast in JSON Format and * pull out the data we need to construct the Strings needed for the wireframes. * * Fortunately parsing is easy: constructor takes the JSON string and converts it * into an Object hierarchy for us.//from ww w .ja v a 2 s.c om */ // private String[] getWeatherDataFromJson(String forecastJsonStr, private void getWeatherDataFromJson(String forecastJsonStr, String locationSetting) throws JSONException { // Now we have a String representing the complete forecast in JSON Format. // Fortunately parsing is easy: constructor takes the JSON string and converts it // into an Object hierarchy for us. // These are the names of the JSON objects that need to be extracted. // Location information final String OWM_CITY = "city"; final String OWM_CITY_NAME = "name"; final String OWM_COORD = "coord"; // Location coordinate final String OWM_LATITUDE = "lat"; final String OWM_LONGITUDE = "lon"; // Weather information. Each day's forecast info is an element of the "list" array. final String OWM_LIST = "list"; final String OWM_PRESSURE = "pressure"; final String OWM_HUMIDITY = "humidity"; final String OWM_WINDSPEED = "speed"; final String OWM_WIND_DIRECTION = "deg"; // All temperatures are children of the "temp" object. final String OWM_TEMPERATURE = "temp"; final String OWM_MAX = "max"; final String OWM_MIN = "min"; final String OWM_WEATHER = "weather"; final String OWM_DESCRIPTION = "main"; final String OWM_WEATHER_ID = "id"; try { JSONObject forecastJson = new JSONObject(forecastJsonStr); JSONArray weatherArray = forecastJson.getJSONArray(OWM_LIST); JSONObject cityJson = forecastJson.getJSONObject(OWM_CITY); String cityName = cityJson.getString(OWM_CITY_NAME); JSONObject cityCoord = cityJson.getJSONObject(OWM_COORD); double cityLatitude = cityCoord.getDouble(OWM_LATITUDE); double cityLongitude = cityCoord.getDouble(OWM_LONGITUDE); long locationId = addLocation(locationSetting, cityName, cityLatitude, cityLongitude); // Insert the new weather information into the database Vector<ContentValues> cVVector = new Vector<ContentValues>(weatherArray.length()); // OWM returns daily forecasts based upon the local time of the city that is being // asked for, which means that we need to know the GMT offset to translate this data // properly. // Since this data is also sent in-order and the first day is always the // current day, we're going to take advantage of that to get a nice // normalized UTC date for all of our weather. Time dayTime = new Time(); dayTime.setToNow(); // we start at the day returned by local time. Otherwise this is a mess. int julianStartDay = Time.getJulianDay(System.currentTimeMillis(), dayTime.gmtoff); // now we work exclusively in UTC dayTime = new Time(); for (int i = 0; i < weatherArray.length(); i++) { // These are the values that will be collected. long dateTime; double pressure; int humidity; double windSpeed; double windDirection; double high; double low; String description; int weatherId; // Get the JSON object representing the day JSONObject dayForecast = weatherArray.getJSONObject(i); // Cheating to convert this to UTC time, which is what we want anyhow dateTime = dayTime.setJulianDay(julianStartDay + i); pressure = dayForecast.getDouble(OWM_PRESSURE); humidity = dayForecast.getInt(OWM_HUMIDITY); windSpeed = dayForecast.getDouble(OWM_WINDSPEED); windDirection = dayForecast.getDouble(OWM_WIND_DIRECTION); // Description is in a child array called "weather", which is 1 element long. // That element also contains a weather code. JSONObject weatherObject = dayForecast.getJSONArray(OWM_WEATHER).getJSONObject(0); description = weatherObject.getString(OWM_DESCRIPTION); weatherId = weatherObject.getInt(OWM_WEATHER_ID); // Temperatures are in a child object called "temp". Try not to name variables // "temp" when working with temperature. It confuses everybody. JSONObject temperatureObject = dayForecast.getJSONObject(OWM_TEMPERATURE); high = temperatureObject.getDouble(OWM_MAX); low = temperatureObject.getDouble(OWM_MIN); ContentValues weatherValues = new ContentValues(); weatherValues.put(WeatherEntry.COLUMN_LOC_KEY, locationId); weatherValues.put(WeatherEntry.COLUMN_DATE, dateTime); weatherValues.put(WeatherEntry.COLUMN_HUMIDITY, humidity); weatherValues.put(WeatherEntry.COLUMN_PRESSURE, pressure); weatherValues.put(WeatherEntry.COLUMN_WIND_SPEED, windSpeed); weatherValues.put(WeatherEntry.COLUMN_DEGREES, windDirection); weatherValues.put(WeatherEntry.COLUMN_MAX_TEMP, high); weatherValues.put(WeatherEntry.COLUMN_MIN_TEMP, low); weatherValues.put(WeatherEntry.COLUMN_SHORT_DESC, description); weatherValues.put(WeatherEntry.COLUMN_WEATHER_ID, weatherId); cVVector.add(weatherValues); } // add to database if (cVVector.size() > 0) { // Student: call bulkInsert to add the weatherEntries to the database here ContentValues[] cvArray = new ContentValues[cVVector.size()]; cVVector.toArray(cvArray); mContext.getContentResolver().bulkInsert(WeatherEntry.CONTENT_URI, cvArray); } // Sort order: Ascending, by date. String sortOrder = WeatherEntry.COLUMN_DATE + " ASC"; Uri weatherForLocationUri = WeatherEntry.buildWeatherLocationWithStartDate(locationSetting, System.currentTimeMillis()); // Students: Uncomment the next lines to display what what you stored in the bulkInsert Cursor cur = mContext.getContentResolver().query(weatherForLocationUri, null, null, null, sortOrder); cVVector = new Vector<ContentValues>(cur.getCount()); if (cur.moveToFirst()) { do { ContentValues cv = new ContentValues(); DatabaseUtils.cursorRowToContentValues(cur, cv); cVVector.add(cv); } while (cur.moveToNext()); } Log.d(LOG_TAG, "FetchWeatherTask Complete. " + cVVector.size() + " Inserted"); //String[] resultStrs = convertContentValuesToUXFormat(cVVector); //return resultStrs; } catch (JSONException e) { Log.e(LOG_TAG, e.getMessage(), e); e.printStackTrace(); } //return null; }
From source file:myblog.richard.vewe.launcher3.LauncherApplication.java
public boolean applistChanged() { Cursor cursor = getContentResolver().query(UsersContract.TableApplist.DIGA_URI, UsersContract.TableApplist.BASIC_COLUMNS, null, null, null); if (cursor == null || cursor.getCount() < 1) { if (mApplist.size() == 0) return false; else/*from w ww .j a v a2 s . com*/ return true; } else { if (mApplist.size() != cursor.getCount()) return true; while (cursor.moveToNext()) { App app = new App(cursor); boolean match = false; for (App cmp : mApplist) { if (app.getPkgName().contentEquals(cmp.getPkgName())) //same package { match = true; if (app.getPkgType() != cmp.getPkgType()) { return true; } break; } } if (match == false) { return true; } } cursor.close(); } return false; }
From source file:com.hichinaschool.flashcards.libanki.Stats.java
/** * Due and cumulative due//from ww w. j a va 2s.co m * *********************************************************************************************** */ public 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 }; int end = 0; int chunk = 0; switch (type) { case TYPE_MONTH: end = 31; chunk = 1; break; case TYPE_YEAR: end = 52; chunk = 7; break; case 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 { cur = mCol.getDb().getDatabase() .rawQuery("SELECT (due - " + mCol.getSched().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 " + _limit() + " AND queue IN (2,3)" + lim + " GROUP BY day ORDER BY day", 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 != TYPE_LIFE && dues.get(dues.size() - 1)[0] < end) { dues.add(new int[] { end, 0, 0 }); } else if (type == 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); mSeriesList[0][i] = data[0]; mSeriesList[1][i] = data[1]; mSeriesList[2][i] = data[2]; } return dues.size() > 0; }
From source file:org.smap.smapTask.android.tasks.DownloadTasksTask.java
private Outcome submitCompletedForms() { String selection = InstanceColumns.SOURCE + "=? and (" + InstanceColumns.STATUS + "=? or " + InstanceColumns.STATUS + "=?)"; String selectionArgs[] = { Utilities.getSource(), InstanceProviderAPI.STATUS_COMPLETE, InstanceProviderAPI.STATUS_SUBMISSION_FAILED }; ArrayList<Long> toUpload = new ArrayList<Long>(); Cursor c = null; try {//from ww w . j a v a2s .co m c = Collect.getInstance().getContentResolver().query(InstanceColumns.CONTENT_URI, null, selection, selectionArgs, null); if (c != null && c.getCount() > 0) { c.move(-1); while (c.moveToNext()) { Long l = c.getLong(c.getColumnIndex(InstanceColumns._ID)); toUpload.add(Long.valueOf(l)); } } } catch (Exception e) { e.printStackTrace(); } finally { if (c != null) { c.close(); } } InstanceUploaderTask instanceUploaderTask = new InstanceUploaderTask(); publishProgress("Submitting " + toUpload.size() + " finalised surveys"); instanceUploaderTask.setUploaderListener((InstanceUploaderListener) mStateListener); Long[] toSendArray = new Long[toUpload.size()]; toUpload.toArray(toSendArray); Log.i(getClass().getSimpleName(), "Submitting " + toUpload.size() + " finalised surveys"); if (toUpload.size() > 0) { return instanceUploaderTask.doInBackground(toSendArray); // Already running a background task so call direct } else { return null; } }