List of usage examples for android.database Cursor getDouble
double getDouble(int columnIndex);
From source file:com.enadein.carlogbook.adapter.LogAdapter.java
@Override public void bindView(View view, Context context, Cursor cursor) { int type = cursor.getInt(cursor.getColumnIndex(ProviderDescriptor.LogView.Cols.TYPE_LOG)); int idIdx = cursor.getColumnIndex(ProviderDescriptor.LogView.Cols._ID); int odometerIdx = cursor.getColumnIndex(ProviderDescriptor.LogView.Cols.ODOMETER); int priceIdx = cursor.getColumnIndex(ProviderDescriptor.LogView.Cols.PRICE); int dateIdx = cursor.getColumnIndex(ProviderDescriptor.LogView.Cols.DATE); double price = cursor.getDouble(priceIdx); String date = CommonUtils.formatDate(new Date(cursor.getLong(dateIdx))); int odometer = cursor.getInt(odometerIdx); int id = cursor.getInt(idIdx); if (type == ProviderDescriptor.Log.Type.FUEL) { LogFuelHolder logFuelHolder = (LogFuelHolder) view.getTag(); int fuelValueIdx = cursor.getColumnIndex(ProviderDescriptor.LogView.Cols.FUEL_VOLUME); double fuelValue = cursor.getDouble(fuelValueIdx); double priceTotalDouble = fuelValue * price; int stationNameIdx = cursor.getColumnIndex(ProviderDescriptor.LogView.Cols.STATION_NAME); String stationName = cursor.getString(stationNameIdx); int fuelNameIdx = cursor.getColumnIndex(ProviderDescriptor.LogView.Cols.FUEL_NAME); String fuelName = cursor.getString(fuelNameIdx); logFuelHolder.odometerView.setText(String.valueOf(odometer)); unitFacade.appendDistUnit(logFuelHolder.odometerView, false); logFuelHolder.dateView.setText(date); logFuelHolder.fuelValueView.setText(CommonUtils.formatFuel(fuelValue, unitFacade)); unitFacade.appendFuelUnit(logFuelHolder.fuelValueView, false); logFuelHolder.priceTotal.setText(CommonUtils.formatPriceNew(priceTotalDouble, unitFacade)); unitFacade.appendCurrency(logFuelHolder.priceTotal, false, false); logFuelHolder.fuelView.setText(fuelName + "(" + stationName + ")"); logFuelHolder.imgType.setBackgroundResource(R.drawable.fuel); logFuelHolder.id = id;/*ww w .j a va2 s .c o m*/ rateLoader.calculateFuelRate(logFuelHolder.rateView, id); } else { int nameIdx = cursor.getColumnIndex(ProviderDescriptor.LogView.Cols.NAME); int typeIdx = cursor.getColumnIndex(ProviderDescriptor.LogView.Cols.TYPE_ID); String name = cursor.getString(nameIdx); int typeId = cursor.getInt(typeIdx); LogHolder logHolder = (LogHolder) view.getTag(); logHolder.dateView.setText(date); logHolder.odometerView.setText(String.valueOf(odometer)); unitFacade.appendDistUnit(logHolder.odometerView, false); logHolder.imgType.setBackgroundResource(DataInfo.images.get(typeId)); logHolder.priceTotal.setText(CommonUtils.formatPriceNew(price, unitFacade)); unitFacade.appendCurrency(logHolder.priceTotal, false, false); logHolder.nameView.setText(name); if (typeId == 0) { int fuelNameIdx = cursor.getColumnIndex(ProviderDescriptor.LogView.Cols.FUEL_NAME); String fuelName = cursor.getString(fuelNameIdx); logHolder.typeView.setText(fuelName); } else { logHolder.typeView.setText(types[typeId]); // int fuelNameIdx = cursor.getColumnIndex(ProviderDescriptor.LogView.Cols.FUEL_NAME); // String fuelName = cursor.getString(fuelNameIdx); // logHolder.typeView.setText(fuelName); } if (name == null || name.trim().equals("")) { logHolder.nameView.setText(logHolder.typeView.getText()); } logHolder.id = id; } int pos = cursor.getPosition(); CommonUtils.runAnimation(mlastPos, pos, view, UnitFacade.animSize); mlastPos = pos; }
From source file:org.jumpmind.symmetric.android.AndroidSqlTemplate.java
@SuppressWarnings("unchecked") protected <T> T get(Cursor cursor, Class<T> clazz, int columnIndex) { Object result = null;//from ww w . jav a2s . c o m if (clazz.equals(String.class)) { result = (String) cursor.getString(columnIndex); } else if (clazz.equals(Integer.class)) { result = (Integer) cursor.getInt(columnIndex); } else if (clazz.equals(Integer.class)) { result = (Double) cursor.getDouble(columnIndex); } else if (clazz.equals(Float.class)) { result = (Float) cursor.getFloat(columnIndex); } else if (clazz.equals(Long.class)) { result = (Long) cursor.getLong(columnIndex); } else if (clazz.equals(Date.class) || clazz.equals(Timestamp.class)) { String dateString = cursor.getString(columnIndex); if (dateString.contains("-")) { result = Timestamp.valueOf(dateString); } else { result = new Timestamp(Long.parseLong(dateString)); } } else if (clazz.equals(Short.class)) { result = (Short) cursor.getShort(columnIndex); } else if (clazz.equals(byte[].class)) { result = (byte[]) cursor.getBlob(columnIndex); } else { throw new IllegalArgumentException("Unsupported class: " + clazz.getName()); } return (T) result; }
From source file:com.glandorf1.joe.wsprnetviewer.app.WsprAdapter.java
@Override public void bindView(View view, Context context, Cursor cursor) { ViewHolder viewHolder = (ViewHolder) view.getTag(); // Read timestamp from cursor String timestampString = cursor.getString(WsprFragment.COL_WSPR_TIMESTAMP); // Read wspr condition ID from cursor //int viewType = getItemViewType(cursor.getPosition()); int viewType = mainDisplayFormat; // Get wspr icon viewHolder.iconView.setImageResource( Utility.getIconResourceForWsprCondition(cursor.getDouble(WsprFragment.COL_WSPR_RX_SNR))); // Find TextView and set formatted timestamp on it viewHolder.timestampView//w ww. j a v a 2 s. co m .setText(Utility.getFormattedTimestamp(timestampString, Utility.TIMESTAMP_FORMAT_HOURS_MINUTES)); // Read wspr data from cursor, then set text boxes String txgridsquare = cursor.getString(WsprFragment.COL_WSPR_TX_GRIDSQUARE); viewHolder.txgridsquareView.setText(txgridsquare); String rxgridsquare = cursor.getString(WsprFragment.COL_WSPR_RX_GRIDSQUARE); viewHolder.rxgridsquareView.setText(rxgridsquare); String txcallsign = cursor.getString(WsprFragment.COL_WSPR_TX_CALLSIGN); viewHolder.txcallsignView.setText(txcallsign); String rxcallsign = cursor.getString(WsprFragment.COL_WSPR_RX_CALLSIGN); viewHolder.rxcallsignView.setText(rxcallsign); // Read user preference for metric or English units boolean isMetric = Utility.isMetric(context); // Read frequency from cursor double frequency = cursor.getDouble(WsprFragment.COL_WSPR_TX_FREQ_MHZ); viewHolder.txfreqmhzView.setText(Utility.formatFrequency(context, frequency, true)); // Read RX SNR from cursor double rxsnr = cursor.getDouble(WsprFragment.COL_WSPR_RX_SNR); viewHolder.rxsnrView.setText(Utility.formatSnr(context, rxsnr)); // For accessibility, add a content description to the icon field // TODO: improve accessibility message for the icon viewHolder.iconView.setContentDescription(rxsnr + " dB"); // Read distance from cursor double km = cursor.getDouble(WsprFragment.COL_WSPR_DISTANCE); viewHolder.distanceView.setText(Utility.formatDistance(context, km, isMetric)); viewHolder.distanceViewUnits.setText(isMetric ? context.getString(R.string._units_metric_distance) : context.getString(R.string._units_english_distance)); switch (viewType) { case Utility.MAIN_DISPLAY_CALLSIGN: // fit everything into 2 lines of display viewHolder.txgridsquareView.setVisibility(View.GONE); viewHolder.rxgridsquareView.setVisibility(View.GONE); viewHolder.txgridsquarelabelView.setVisibility(View.GONE); viewHolder.rxgridsquarelabelView.setVisibility(View.GONE); viewHolder.txcallsignView.setVisibility(View.VISIBLE); viewHolder.rxcallsignView.setVisibility(View.VISIBLE); viewHolder.txcallsignlabelView.setVisibility(View.VISIBLE); viewHolder.rxcallsignlabelView.setVisibility(View.VISIBLE); viewHolder.distanceView.setVisibility(View.GONE); viewHolder.distanceViewUnits.setVisibility(View.GONE); break; case Utility.MAIN_DISPLAY_GRIDCALL: // fit everything into 4 lines of display viewHolder.txgridsquareView.setVisibility(View.VISIBLE); viewHolder.rxgridsquareView.setVisibility(View.VISIBLE); viewHolder.txgridsquarelabelView.setVisibility(View.VISIBLE); viewHolder.rxgridsquarelabelView.setVisibility(View.VISIBLE); viewHolder.txcallsignView.setVisibility(View.VISIBLE); viewHolder.rxcallsignView.setVisibility(View.VISIBLE); viewHolder.txcallsignlabelView.setVisibility(View.VISIBLE); viewHolder.rxcallsignlabelView.setVisibility(View.VISIBLE); viewHolder.distanceView.setVisibility(View.VISIBLE); viewHolder.distanceViewUnits.setVisibility(View.VISIBLE); break; case Utility.MAIN_DISPLAY_GRIDSQUARE: // fit everything into 2 lines of display default: viewHolder.txgridsquareView.setVisibility(View.VISIBLE); viewHolder.rxgridsquareView.setVisibility(View.VISIBLE); viewHolder.txgridsquarelabelView.setVisibility(View.VISIBLE); viewHolder.rxgridsquarelabelView.setVisibility(View.VISIBLE); viewHolder.txcallsignView.setVisibility(View.GONE); viewHolder.rxcallsignView.setVisibility(View.GONE); viewHolder.txcallsignlabelView.setVisibility(View.GONE); viewHolder.rxcallsignlabelView.setVisibility(View.GONE); viewHolder.distanceView.setVisibility(View.GONE); viewHolder.distanceViewUnits.setVisibility(View.GONE); } }
From source file:org.xbmc.kore.ui.sections.video.TVShowEpisodeInfoFragment.java
/** {@inheritDoc} */ @Override//from w w w .j a va 2s . co m public void onLoadFinished(Loader<Cursor> cursorLoader, Cursor cursor) { if (cursor != null && cursor.getCount() > 0) { switch (cursorLoader.getId()) { case LOADER_EPISODE: cursor.moveToFirst(); this.cursor = cursor; DataHolder dataHolder = getDataHolder(); dataHolder.setPosterUrl(cursor.getString(EpisodeDetailsQuery.THUMBNAIL)); dataHolder.setRating(cursor.getDouble(EpisodeDetailsQuery.RATING)); dataHolder.setMaxRating(10); String director = cursor.getString(EpisodeDetailsQuery.DIRECTOR); if (!TextUtils.isEmpty(director)) { director = getActivity().getResources().getString(R.string.directors) + " " + director; } int runtime = cursor.getInt(EpisodeDetailsQuery.RUNTIME) / 60; String durationPremiered = runtime > 0 ? String.format(getString(R.string.minutes_abbrev), String.valueOf(runtime)) + " | " + cursor.getString(EpisodeDetailsQuery.FIRSTAIRED) : cursor.getString(EpisodeDetailsQuery.FIRSTAIRED); String season = String.format(getString(R.string.season_episode), cursor.getInt(EpisodeDetailsQuery.SEASON), cursor.getInt(EpisodeDetailsQuery.EPISODE)); dataHolder.setDetails(durationPremiered + "\n" + season + "\n" + director); fileDownloadHelper = new FileDownloadHelper.TVShowInfo( cursor.getString(EpisodeDetailsQuery.SHOWTITLE), cursor.getInt(EpisodeDetailsQuery.SEASON), cursor.getInt(EpisodeDetailsQuery.EPISODE), cursor.getString(EpisodeDetailsQuery.TITLE), cursor.getString(EpisodeDetailsQuery.FILE)); setDownloadButtonState(fileDownloadHelper.downloadFileExists()); setSeenButtonState(cursor.getInt(EpisodeDetailsQuery.PLAYCOUNT) > 0); getDataHolder().setTitle(cursor.getString(EpisodeDetailsQuery.TITLE)); getDataHolder().setUndertitle(cursor.getString(EpisodeDetailsQuery.SHOWTITLE)); setExpandDescription(true); getDataHolder().setDescription(cursor.getString(EpisodeDetailsQuery.PLOT)); updateView(dataHolder); break; } } }
From source file:ch.ethz.twimight.net.tds.TDSRequestMessage.java
/** * creates JSONObject to push Statistics to the TDS * /*from w w w . j a va 2 s . c o m*/ * @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:fr.eoit.activity.fragment.mining.session.ReprocessFragment.java
@Override protected void onLoadFinishedAdapteur(Cursor cursor, SimpleCursorAdapter adapter) { MatrixCursor objectivesItemCursur = getEmptyCursor(); cursor.moveToFirst();/*from w w w . j ava 2 s. com*/ while (!cursor.isAfterLast()) { int id = cursor.getInt(cursor.getColumnIndexOrThrow(Item._ID)); String name = cursor.getString(cursor.getColumnIndexOrThrow(Item.COLUMN_NAME_NAME)); ItemBeanWithMaterials item = new ItemBeanWithMaterials(); item.id = id; item.name = name; item.quantity = minerals.get(id).quantity; item.price = PricesUtils.getPriceOrNaN(cursor); item.volume = cursor.getDouble(cursor.getColumnIndexOrThrow(Item.COLUMN_NAME_VOLUME)); totalPrice += item.quantity * item.price; totalVolume += item.quantity * item.volume; addRowToMatrixCursor(objectivesItemCursur, item); cursor.moveToNext(); } adapter.setViewBinder(new MaterialsListViewBinderWithTotalPriceAndVolume()); adapter.swapCursor(objectivesItemCursur); }
From source file:ca.mudar.parkcatcher.ui.fragments.DetailsFragment.java
private void initDetails(Cursor data) { mIsStarred = (data.getInt(PostDetailsQuery.IS_STARRED) == 1); mGeoLat = data.getDouble(PostDetailsQuery.LAT); mGeoLng = data.getDouble(PostDetailsQuery.LNG); // Start the reverse geocode address search if (ConnectionHelper.hasConnection(getActivity())) { mView.findViewById(R.id.details_progress_address).setVisibility(View.VISIBLE); final Thread thread = new Thread(this); thread.start();//from w ww . j a va2s. c o m } else { mView.findViewById(R.id.details_progress_address).setVisibility(View.GONE); } final boolean isForbidden = (data.getInt(PostDetailsQuery.IS_FORBIDDEN) == 1); final LinearLayout panelsWrapper = (LinearLayout) mView.findViewById(R.id.details_panels_wrapper); panelsWrapper.removeAllViews(); // Panels LayoutParams and Color final LayoutParams params = new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT); final float SCALE = getActivity().getResources().getDisplayMetrics().density; // Convert dips to pixels float valueDips = 16.0f; int valuePixels = (int) (valueDips * SCALE); params.setMargins(0, 0, 0, valuePixels); final int textColor = getResources().getColor(R.color.details_panel_text); do { final String desc = data.getString(PostDetailsQuery.DESCRIPTION); mShareDesc += Const.LINE_SEPARATOR + desc; panelsWrapper.addView(getPanel(desc, params, textColor)); } while (data.moveToNext()); final TextView titleUi = (TextView) mView.findViewById(R.id.details_title); if (isForbidden) { titleUi.setText(R.string.details_title_forbidden); } else { titleUi.setText(R.string.details_title_allowed); } getSherlockActivity().invalidateOptionsMenu(); }
From source file:com.google.android.apps.forscience.whistlepunk.sensordb.SensorDatabaseImpl.java
@Override public ScalarReadingList getScalarReadings(String sensorTag, TimeRange range, int resolutionTier, int maxRecords) { String[] columns = { ScalarSensorsTable.Column.TIMESTAMP_MILLIS, ScalarSensorsTable.Column.VALUE }; Pair<String, String[]> selectionAndArgs = getSelectionAndArgs(sensorTag, range, resolutionTier); String selection = selectionAndArgs.first; String[] selectionArgs = selectionAndArgs.second; String orderBy = ScalarSensorsTable.Column.TIMESTAMP_MILLIS + (range.getOrder().equals(TimeRange.ObservationOrder.OLDEST_FIRST) ? " ASC" : " DESC"); String limit = maxRecords <= 0 ? null : String.valueOf(maxRecords); Cursor cursor = mOpenHelper.getReadableDatabase().query(ScalarSensorsTable.NAME, columns, selection, selectionArgs, null, null, orderBy, limit); try {//from w w w.j a va2s. co m final int max = maxRecords <= 0 ? cursor.getCount() : maxRecords; final long[] readTimestamps = new long[max]; final double[] readValues = new double[max]; int i = 0; while (cursor.moveToNext()) { readTimestamps[i] = cursor.getLong(0); readValues[i] = cursor.getDouble(1); i++; } final int actualCount = i; return new ScalarReadingList() { @Override public void deliver(StreamConsumer c) { for (int i = 0; i < actualCount; i++) { c.addData(readTimestamps[i], readValues[i]); } } @Override public int size() { return actualCount; } @Override public List<ChartData.DataPoint> asDataPoints() { List<ChartData.DataPoint> result = new ArrayList<>(); for (int i = 0; i < actualCount; i++) { result.add(new ChartData.DataPoint(readTimestamps[i], readValues[i])); } return result; } }; } finally { cursor.close(); } }
From source file:net.benmoran.affectsampler.AffectSerializer.java
public JSONArray toJSONArray() throws JSONException { Uri samples = AffectSamples.CONTENT_URI; String[] projection = new String[] { AffectSamples.COMMENT, AffectSamples.SCHEDULED_DATE, AffectSamples.CREATED_DATE, AffectSamples.EMOTION, AffectSamples.INTENSITY }; Cursor cursor = mContentResolver.query(samples, projection, null, null, AffectSamples.CREATED_DATE + " ASC"); JSONArray arr = new JSONArray(); int emIndex = cursor.getColumnIndex(AffectSamples.EMOTION); int inIndex = cursor.getColumnIndex(AffectSamples.INTENSITY); int cdIndex = cursor.getColumnIndex(AffectSamples.CREATED_DATE); int sdIndex = cursor.getColumnIndex(AffectSamples.SCHEDULED_DATE); int coIndex = cursor.getColumnIndex(AffectSamples.COMMENT); for (cursor.moveToPosition(0); !cursor.isLast(); cursor.moveToNext()) { JSONObject o = new JSONObject(); o.put(AffectSamples.EMOTION, cursor.getDouble(emIndex)); o.put(AffectSamples.INTENSITY, cursor.getDouble(inIndex)); if (cursor.getLong(sdIndex) > 0) { o.put(AffectSamples.SCHEDULED_DATE, cursor.getLong(sdIndex)); } else {/*from w w w . java 2 s . c o m*/ o.put(AffectSamples.SCHEDULED_DATE, null); } o.put(AffectSamples.CREATED_DATE, cursor.getLong(cdIndex)); if (cursor.getString(coIndex) != null) { o.put(AffectSamples.COMMENT, cursor.getString(coIndex)); } else { o.put(AffectSamples.COMMENT, null); } arr.put(o); } cursor.close(); return arr; }
From source file:com.wildplot.android.ankistats.Intervals.java
public boolean calculateIntervals(int type) { mType = type;//ww w . java 2 s . c om double all = 0, avg = 0, max_ = 0; mType = type; mBackwards = true; mTitle = R.string.stats_review_intervals; mAxisTitles = new int[] { type, R.string.stats_cards, R.string.stats_percentage }; mValueLabels = new int[] { R.string.stats_cards_intervals }; mColors = new int[] { R.color.stats_interval }; int num = 0; String lim = ""; int chunk = 0; switch (type) { case Utils.TYPE_MONTH: num = 31; chunk = 1; lim = " and grp <= 30"; break; case Utils.TYPE_YEAR: num = 52; chunk = 7; lim = " and grp <= 52"; break; case Utils.TYPE_LIFE: num = -1; chunk = 30; lim = ""; break; } ArrayList<double[]> list = new ArrayList<double[]>(); Cursor cur = null; try { cur = mAnkiDb.getDatabase() .rawQuery("select ivl / " + chunk + " as grp, count() from cards " + "where did in " + _limitWholeOnly() + " and queue = 2 " + lim + " " + "group by grp " + "order by grp", null); while (cur.moveToNext()) { list.add(new double[] { cur.getDouble(0), cur.getDouble(1) }); } if (cur != null && !cur.isClosed()) { cur.close(); } cur = mAnkiDb.getDatabase().rawQuery("select count(), avg(ivl), max(ivl) from cards where did in " + _limitWholeOnly() + " and queue = 2", null); cur.moveToFirst(); all = cur.getDouble(0); avg = cur.getDouble(1); max_ = cur.getDouble(2); } finally { if (cur != null && !cur.isClosed()) { cur.close(); } } // 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 }); } else if (type == Utils.TYPE_LIFE && list.size() < 2) { list.add(new double[] { Math.max(12, list.get(list.size() - 1)[0] + 1), 0 }); } mSeriesList = new double[2][list.size()]; for (int i = 0; i < list.size(); i++) { double[] data = list.get(i); mSeriesList[0][i] = data[0]; // grp mSeriesList[1][i] = data[1]; // cnt if (mSeriesList[1][i] > mMaxCards) mMaxCards = (int) Math.round(data[1]); } mCumulative = Utils.createCumulative(mSeriesList); for (int i = 0; i < list.size(); i++) { mCumulative[1][i] /= all / 100; } mMaxElements = list.size() - 1; mAverage = Utils.fmtTimeSpan((int) Math.round(avg * 86400)); mLongest = Utils.fmtTimeSpan((int) Math.round(max_ * 86400)); return list.size() > 0; }