List of usage examples for android.database Cursor getDouble
double getDouble(int columnIndex);
From source file:org.openbmap.soapclient.GpxExporter.java
/** * Iterates on track points and write them. * @param trackName Name of the track (metadata). * @param bw Writer to the target file./*from w w w.j a v a2s . co m*/ * @param c Cursor to track points. * @throws IOException */ private void writeWaypoints(final int session, final BufferedWriter bw) throws IOException { Log.i(TAG, "Writing trackpoints"); Cursor c = mDbHelper.getReadableDatabase().rawQuery(WAYPOINT_SQL_QUERY, new String[] { String.valueOf(mSession), String.valueOf(0) }); final int colLatitude = c.getColumnIndex(Schema.COL_LATITUDE); final int colLongitude = c.getColumnIndex(Schema.COL_LONGITUDE); final int colAltitude = c.getColumnIndex(Schema.COL_ALTITUDE); final int colTimestamp = c.getColumnIndex(Schema.COL_TIMESTAMP); long outer = 0; while (!c.isAfterLast()) { c.moveToFirst(); //StringBuffer out = new StringBuffer(32 * 1024); while (!c.isAfterLast()) { bw.write("\t\t\t<wpt lat=\""); bw.write(String.valueOf(c.getDouble(colLatitude))); bw.write("\" "); bw.write("lon=\""); bw.write(String.valueOf(c.getDouble(colLongitude))); bw.write("\">"); bw.write("<ele>"); bw.write(String.valueOf(c.getDouble(colAltitude))); bw.write("</ele>"); bw.write("<time>"); // time stamp conversion to ISO 8601 bw.write(getGpxDate(c.getLong(colTimestamp))); bw.write("</time>"); bw.write("</wpt>\n"); c.moveToNext(); } //bw.write(out.toString()); //out = null; // fetch next CURSOR_SIZE records outer += CURSOR_SIZE; c.close(); c = mDbHelper.getReadableDatabase().rawQuery(WAYPOINT_SQL_QUERY, new String[] { String.valueOf(mSession), String.valueOf(outer) }); } c.close(); System.gc(); }
From source file:com.wildplot.android.ankistats.HourlyBreakdown.java
public boolean calculateBreakdown(int type) { mTitle = R.string.stats_breakdown;//from w ww .j a v a 2 s .com mAxisTitles = new int[] { R.string.stats_time_of_day, R.string.stats_percentage_correct, R.string.stats_reviews }; mValueLabels = new int[] { R.string.stats_percentage_correct, R.string.stats_answers }; mColors = new int[] { R.color.stats_counts, R.color.stats_hours }; mType = type; String lim = _revlogLimitWholeOnly().replaceAll("[\\[\\]]", ""); if (lim.length() > 0) { lim = " and " + lim; } Calendar sd = GregorianCalendar.getInstance(); sd.setTimeInMillis(mCollectionData.getCrt() * 1000); Calendar cal = Calendar.getInstance(); TimeZone tz = TimeZone.getDefault(); /* date formatter in local timezone */ SimpleDateFormat sdf = new SimpleDateFormat("dd/MM/yyyy HH:mm:ss"); sdf.setTimeZone(tz); /* print your timestamp and double check it's the date you expect */ String localTime = sdf.format(new Date(mCollectionData.getCrt() * 1000)); // I assume your timestamp is in seconds and you're converting to milliseconds? int pd = _periodDays(); if (pd > 0) { lim += " and id > " + ((mCollectionData.getDayCutoff() - (86400 * pd)) * 1000); } int hourOfDay = sd.get(GregorianCalendar.HOUR_OF_DAY); long cutoff = mCollectionData.getDayCutoff(); long cut = cutoff - sd.get(Calendar.HOUR_OF_DAY) * 3600; ArrayList<double[]> list = new ArrayList<double[]>(); Cursor cur = null; String query = "select " + "23 - ((cast((" + cut + " - id/1000) / 3600.0 as int)) % 24) as hour, " + "sum(case when ease = 1 then 0 else 1 end) / " + "cast(count() as float) * 100, " + "count() " + "from revlog where type in (0,1,2) " + lim + " " + "group by hour having count() > 30 order by hour"; Log.d(AnkiStatsApplication.TAG, sd.get(Calendar.HOUR_OF_DAY) + " : " + cutoff + " breakdown query: " + query); try { cur = mAnkiDb.getDatabase().rawQuery(query, null); while (cur.moveToNext()) { list.add(new double[] { cur.getDouble(0), cur.getDouble(1), cur.getDouble(2) }); } } finally { if (cur != null && !cur.isClosed()) { cur.close(); } } //TODO adjust for breakdown, for now only copied from intervals // small adjustment for a proper chartbuilding with achartengine // if (list.size() == 0 || list.get(0)[0] > 0) { // list.add(0, new double[] { 0, 0, 0 }); // } // if (num == -1 && list.size() < 2) { // num = 31; // } // if (type != Utils.TYPE_LIFE && list.get(list.size() - 1)[0] < num) { // list.add(new double[] { num, 0, 0 }); // } else if (type == Utils.TYPE_LIFE && list.size() < 2) { // list.add(new double[] { Math.max(12, list.get(list.size() - 1)[0] + 1), 0, 0 }); // } for (int i = 0; i < list.size(); i++) { double[] data = list.get(i); int intHour = (int) data[0]; int hour = (intHour - 4) % 24; if (hour < 0) hour += 24; data[0] = hour; list.set(i, data); } Collections.sort(list, new Comparator<double[]>() { @Override public int compare(double[] s1, double[] s2) { if (s1[0] < s2[0]) return -1; if (s1[0] > s2[0]) return 1; return 0; } }); mSeriesList = new double[4][list.size()]; mPeak = 0.0; mMcount = 0.0; double minHour = Double.MAX_VALUE; double maxHour = 0; for (int i = 0; i < list.size(); i++) { double[] data = list.get(i); int hour = (int) data[0]; //double hour = data[0]; if (hour < minHour) minHour = hour; if (hour > maxHour) maxHour = hour; double pct = data[1]; if (pct > mPeak) mPeak = pct; mSeriesList[0][i] = hour; mSeriesList[1][i] = pct; mSeriesList[2][i] = data[2]; if (i == 0) { mSeriesList[3][i] = pct; } else { double prev = mSeriesList[3][i - 1]; double diff = pct - prev; diff /= 3.0; diff = Math.round(diff * 10.0) / 10.0; mSeriesList[3][i] = prev + diff; } if (data[2] > mMcount) mMcount = data[2]; if (mSeriesList[1][i] > mMaxCards) mMaxCards = (int) mSeriesList[1][i]; } mMaxElements = (int) (maxHour - minHour); return list.size() > 0; }
From source file:net.niyonkuru.koodroid.ui.AccountFragment.java
@Override public void onLoadFinished(Loader<Cursor> loader, Cursor data) { int id = loader.getId(); switch (id) { case PLAN_TOKEN: { if (!data.moveToFirst()) return; mPlanCost.setText(formatMoney(data.getString(PlansQuery.COST))); mPlanName.setText(data.getString(PlansQuery.NAME)); mPlanUpdateTime.setTag(Timestamp.valueOf(data.getString(PlansQuery.UPDATED))); break;//from ww w . j a va2s . c o m } case ADDONS_TOKEN: { mAddonsList.removeAllViews(); double total_cost = 0.0; while (data.moveToNext()) { View addon = mLayoutInflater.inflate(R.layout.addon_list_item, null); final TextView addonName = (TextView) addon.findViewById(R.id.addon_name); addonName.setText(data.getString(AddonsQuery.NAME)); double cost = data.getDouble(AddonsQuery.COST); total_cost += cost; final TextView addonCost = (TextView) addon.findViewById(R.id.addon_cost); addonCost.setText(formatMoney(cost)); mAddonsList.addView(addon); } View addonsTitle = getView().findViewById(R.id.addons_content); if (mAddonsList.getChildCount() > 0) { mAddonsCost.setText(formatMoney(total_cost)); addonsTitle.setVisibility(View.VISIBLE); } else { /* make the list visible when there's at least one addon */ addonsTitle.setVisibility(View.GONE); } break; } } updateTimestamps(); }
From source file:cl.gisred.android.RepartoActivity.java
public void readData() { SQLiteDatabase db = sqlReparto.getReadableDatabase(); String[] sValues = { "id", "codigo", "x", "y" }; Cursor cData = db.query("repartos", sValues, null, null, null, null, null, null); arrayDatos = new ArrayList<>(); if (cData != null && cData.getCount() > 0) { iContRep = cData.getCount();//from w w w .j av a 2 s . co m cData.moveToFirst(); do { RepartoClass oRep = new RepartoClass(cData.getInt(0), cData.getString(1), cData.getDouble(2), cData.getDouble(3)); arrayDatos.add(oRep); } while (cData.moveToNext()); cData.close(); } db.close(); }
From source file:com.hangulo.powercontact.ErrorContactsListFragment.java
@Override public void onLoadFinished(Loader<Cursor> loader, Cursor data) { //Log.v(LOG_TAG, "LOADER:MainActivity/onLoaderFinished : cursor num " + cursor.getCount()); // if (cursor==null) return; mErrorContactList.clear(); // first clear! if (data.moveToFirst()) { do {//from ww w .ja v a 2 s. co m long contact_id = data.getLong(INDEX_COL_CONTACT_ID); long data_id = data.getLong(INDEX_COL_DATA_ID); String lookup_key = data.getString(INDEX_COL_LOOKUP_KEY); String name = data.getString(INDEX_COL_NAME); String addr = data.getString(INDEX_COL_ADDR); int type = data.getInt(INDEX_COL_TYPE); String label = data.getString(INDEX_COL_LABEL); double lat = data.getDouble(INDEX_COL_LAT); double lng = data.getDouble(INDEX_COL_LNG); //double dist = cursor.getDouble(INDEX_COL_DISTANCE); // distance String photo = data.getString(INDEX_COL_PHOTO); // photo mErrorContactList.add(new PowerContactAddress(contact_id, data_id, lookup_key, name, addr, type, label, photo, lat, lng, 0)); } while (data.moveToNext()); } mAdapter.swapCursor(data); // }
From source file:org.xbmc.kore.ui.sections.audio.AlbumDetailsFragment.java
/** * Display the album details//from ww w . ja va2 s . c om * * @param cursor Cursor with the data */ private void displayAlbumDetails(Cursor cursor) { final Resources resources = getActivity().getResources(); cursor.moveToFirst(); albumTitle = cursor.getString(AlbumDetailsQuery.TITLE); albumDisplayArtist = cursor.getString(AlbumDetailsQuery.DISPLAYARTIST); mediaTitle.setText(albumTitle); mediaUndertitle.setText(albumDisplayArtist); setMediaYear(cursor.getString(AlbumDetailsQuery.GENRE), cursor.getInt(AlbumDetailsQuery.YEAR)); double rating = cursor.getDouble(AlbumDetailsQuery.RATING); if (rating > 0) { mediaRating.setVisibility(View.VISIBLE); mediaMaxRating.setVisibility(View.VISIBLE); setMediaRating(rating); } else { mediaRating.setVisibility(View.GONE); mediaMaxRating.setVisibility(View.GONE); } String description = cursor.getString(AlbumDetailsQuery.DESCRIPTION); if (!TextUtils.isEmpty(description)) { mediaDescription.setVisibility(View.VISIBLE); mediaDescription.setText(description); Resources.Theme theme = getActivity().getTheme(); TypedArray styledAttributes = theme .obtainStyledAttributes(new int[] { R.attr.iconExpand, R.attr.iconCollapse }); final int iconCollapseResId = styledAttributes.getResourceId(styledAttributes.getIndex(0), R.drawable.ic_expand_less_white_24dp); final int iconExpandResId = styledAttributes.getResourceId(styledAttributes.getIndex(1), R.drawable.ic_expand_more_white_24dp); styledAttributes.recycle(); mediaDescriptionContainer.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { mediaDescription.toggle(); mediaShowAll .setImageResource(mediaDescription.isExpanded() ? iconCollapseResId : iconExpandResId); } }); } else { mediaDescriptionContainer.setVisibility(View.GONE); } // Images DisplayMetrics displayMetrics = new DisplayMetrics(); getActivity().getWindowManager().getDefaultDisplay().getMetrics(displayMetrics); String fanart = cursor.getString(AlbumDetailsQuery.FANART), poster = cursor.getString(AlbumDetailsQuery.THUMBNAIL); int artHeight = resources.getDimensionPixelOffset(R.dimen.now_playing_art_height), artWidth = displayMetrics.widthPixels; int posterWidth = resources.getDimensionPixelOffset(R.dimen.albumdetail_poster_width); int posterHeight = resources.getDimensionPixelOffset(R.dimen.albumdetail_poster_heigth); UIUtils.loadImageWithCharacterAvatar(getActivity(), hostManager, poster, albumTitle, mediaPoster, posterWidth, posterHeight); UIUtils.loadImageIntoImageview(hostManager, TextUtils.isEmpty(fanart) ? poster : fanart, mediaArt, artWidth, artHeight); }
From source file:com.androzic.location.LocationService.java
public Track getTrack(long limit) { if (trackDB == null) openDatabase();/*from www.jav a2 s. c o m*/ Track track = new Track(); if (trackDB == null) return track; String limitStr = limit > 0 ? " LIMIT " + limit : ""; Cursor cursor = trackDB.rawQuery("SELECT * FROM track ORDER BY _id DESC" + limitStr, null); for (boolean hasItem = cursor.moveToLast(); hasItem; hasItem = cursor.moveToPrevious()) { double latitude = cursor.getDouble(cursor.getColumnIndex("latitude")); double longitude = cursor.getDouble(cursor.getColumnIndex("longitude")); double elevation = cursor.getDouble(cursor.getColumnIndex("elevation")); double speed = cursor.getDouble(cursor.getColumnIndex("speed")); double bearing = cursor.getDouble(cursor.getColumnIndex("track")); double accuracy = cursor.getDouble(cursor.getColumnIndex("accuracy")); int code = cursor.getInt(cursor.getColumnIndex("code")); long time = cursor.getLong(cursor.getColumnIndex("datetime")); track.addPoint(code == 0, latitude, longitude, elevation, speed, bearing, accuracy, time); } cursor.close(); return track; }
From source file:org.openbmap.soapclient.GpxExporter.java
/** * Iterates on way points and write them. * @param bw Writer to the target file./*from ww w.j av a2s. c om*/ * @param c Cursor to way points. * @throws IOException */ private void writeCells(final BufferedWriter bw) throws IOException { Log.i(TAG, "Writing cell waypoints"); Cursor c = mDbHelper.getReadableDatabase().rawQuery(CELL_POINTS_SQL_QUERY, new String[] { String.valueOf(mSession), String.valueOf(0) }); final int colLatitude = c.getColumnIndex(Schema.COL_LATITUDE); final int colLongitude = c.getColumnIndex(Schema.COL_LONGITUDE); final int colAltitude = c.getColumnIndex(Schema.COL_ALTITUDE); final int colTimestamp = c.getColumnIndex(Schema.COL_TIMESTAMP); final int colName = c.getColumnIndex("name"); long outer = 0; while (!c.isAfterLast()) { c.moveToFirst(); //StringBuffer out = new StringBuffer(); while (!c.isAfterLast()) { bw.write("\t<wpt lat=\""); bw.write(String.valueOf(c.getDouble(colLatitude))); bw.write("\" "); bw.write("lon=\""); bw.write(String.valueOf(c.getDouble(colLongitude))); bw.write("\">\n"); bw.write("\t\t<ele>"); bw.write(String.valueOf(c.getDouble(colAltitude))); bw.write("</ele>\n"); bw.write("\t\t<time>"); // time stamp conversion to ISO 8601 bw.write(getGpxDate(c.getLong(colTimestamp))); bw.write("</time>\n"); bw.write("\t\t<name>"); bw.write(StringEscapeUtils.escapeXml(c.getString(colName))); bw.write("</name>\n"); bw.write("\t</wpt>\n"); c.moveToNext(); } //bw.write(out.toString()); //out = null; // fetch next CURSOR_SIZE records outer += CURSOR_SIZE; c.close(); c = mDbHelper.getReadableDatabase().rawQuery(CELL_POINTS_SQL_QUERY, new String[] { String.valueOf(mSession), String.valueOf(outer) }); } c.close(); System.gc(); }
From source file:com.samknows.measurement.storage.DBHelper.java
private JSONObject cursorTestResultToJSONObject(Cursor c) { JSONObject ret = new JSONObject(); try {//from ww w .j av a2 s .c om ret.put(SKSQLiteHelper.TR_COLUMN_ID, c.getLong(0)); ret.put(SKSQLiteHelper.TR_COLUMN_TYPE, c.getString(1)); ret.put(SKSQLiteHelper.TR_COLUMN_DTIME, c.getLong(2)); ret.put(SKSQLiteHelper.TR_COLUMN_LOCATION, c.getString(3)); ret.put(SKSQLiteHelper.TR_COLUMN_SUCCESS, c.getInt(4)); ret.put(SKSQLiteHelper.TR_COLUMN_RESULT, c.getDouble(5)); ret.put(SKSQLiteHelper.TR_COLUMN_BATCH_ID, c.getLong(6)); } catch (JSONException je) { } return ret; }
From source file:uk.org.rivernile.edinburghbustracker.android.fragments.general.BusStopDetailsFragment.java
/** * This is called when the Loader has finished. It moves the data out of the * Cursor and in to local fields.//w ww . j a va 2 s . co m * * @param c The returned Cursor. */ private void populateData(final Cursor c) { if (c == null) { showLoadFailedError(); return; } if (c.moveToNext()) { stopName = c.getString(2); latitude = c.getDouble(3); longitude = c.getDouble(4); orientation = c.getInt(5); locality = c.getString(6); c.close(); populateView(); } else { c.close(); showLoadFailedError(); } }