List of usage examples for android.database Cursor getDouble
double getDouble(int columnIndex);
From source file:com.battlelancer.seriesguide.ui.OverviewFragment.java
private void onLoadEpisodeDetails(final Cursor episode) { final int seasonNumber = episode.getInt(EpisodeQuery.SEASON); final int episodeNumber = episode.getInt(EpisodeQuery.NUMBER); final String episodeTitle = episode.getString(EpisodeQuery.TITLE); // Description, DVD episode number, guest stars, absolute number ((TextView) getView().findViewById(R.id.TextViewEpisodeDescription)) .setText(episode.getString(EpisodeQuery.OVERVIEW)); boolean isShowingMeta; isShowingMeta = Utils.setLabelValueOrHide(getView().findViewById(R.id.labelDvd), (TextView) getView().findViewById(R.id.textViewEpisodeDVDnumber), episode.getDouble(EpisodeQuery.DVDNUMBER)); isShowingMeta |= Utils.setLabelValueOrHide(getView().findViewById(R.id.labelGuestStars), (TextView) getView().findViewById(R.id.TextViewEpisodeGuestStars), Utils.splitAndKitTVDBStrings(episode.getString(EpisodeQuery.GUESTSTARS))); // hide divider if no meta is visible getView().findViewById(R.id.dividerHorizontalOverviewEpisodeMeta) .setVisibility(isShowingMeta ? View.VISIBLE : View.GONE); // TVDb rating final String ratingText = episode.getString(EpisodeQuery.RATING); if (ratingText != null && ratingText.length() != 0) { ((TextView) getView().findViewById(R.id.textViewRatingsTvdbValue)).setText(ratingText); }/* w w w .j a v a 2 s . co m*/ // IMDb button String imdbId = episode.getString(EpisodeQuery.IMDBID); if (TextUtils.isEmpty(imdbId) && mShowCursor != null) { // fall back to show IMDb id imdbId = mShowCursor.getString(ShowQuery.SHOW_IMDBID); } ServiceUtils.setUpImdbButton(imdbId, getView().findViewById(R.id.buttonShowInfoIMDB), TAG, getActivity()); // TVDb button final int episodeTvdbId = episode.getInt(EpisodeQuery._ID); final int seasonTvdbId = episode.getInt(EpisodeQuery.REF_SEASON_ID); ServiceUtils.setUpTvdbButton(getShowId(), seasonTvdbId, episodeTvdbId, getView().findViewById(R.id.buttonTVDB), TAG); // trakt button ServiceUtils.setUpTraktButton(getShowId(), seasonNumber, episodeNumber, getView().findViewById(R.id.buttonTrakt), TAG); // Web search button getView().findViewById(R.id.buttonWebSearch).setVisibility(View.GONE); // trakt shouts button getView().findViewById(R.id.buttonShouts).setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { if (mCurrentEpisodeCursor != null && mCurrentEpisodeCursor.moveToFirst()) { Intent i = new Intent(getActivity(), TraktShoutsActivity.class); i.putExtras(TraktShoutsActivity.createInitBundleEpisode(getShowId(), seasonNumber, episodeNumber, episodeTitle)); ActivityCompat.startActivity(getActivity(), i, ActivityOptionsCompat .makeScaleUpAnimation(v, 0, 0, v.getWidth(), v.getHeight()).toBundle()); fireTrackerEvent("Comments"); } } }); // trakt ratings onLoadTraktRatings(true); }
From source file:com.robotoworks.mechanoid.db.SQuery.java
public double firstDouble(SQLiteDatabase db, String table, String column, String orderBy) { Cursor cursor = null; double value = 0; try {//from www .j av a 2 s . c om cursor = query(db, table, new String[] { column }, orderBy); if (cursor.moveToFirst()) { value = cursor.getDouble(0); } } finally { Closeables.closeSilently(cursor); } return value; }
From source file:com.robotoworks.mechanoid.db.SQuery.java
public double firstDouble(Uri uri, String column, String orderBy) { Cursor cursor = null; double value = 0; try {//from ww w . j ava 2 s . c o m cursor = select(uri, new String[] { column }, orderBy, false); if (cursor.moveToFirst()) { value = cursor.getDouble(0); } } finally { Closeables.closeSilently(cursor); } return value; }
From source file:org.mozilla.mozstumbler.service.sync.UploadReports.java
private BatchRequestStats getRequestBody(Cursor cursor) { int wifiCount = 0; int cellCount = 0; JSONArray items = new JSONArray(); int columnId = cursor.getColumnIndex(DatabaseContract.Reports._ID); int columnTime = cursor.getColumnIndex(DatabaseContract.Reports.TIME); int columnLat = cursor.getColumnIndex(DatabaseContract.Reports.LAT); int columnLon = cursor.getColumnIndex(DatabaseContract.Reports.LON); int columnAltitude = cursor.getColumnIndex(DatabaseContract.Reports.ALTITUDE); int columnAccuracy = cursor.getColumnIndex(DatabaseContract.Reports.ACCURACY); int columnRadio = cursor.getColumnIndex(DatabaseContract.Reports.RADIO); int columnCell = cursor.getColumnIndex(DatabaseContract.Reports.CELL); int columnWifi = cursor.getColumnIndex(DatabaseContract.Reports.WIFI); int columnCellCount = cursor.getColumnIndex(DatabaseContract.Reports.CELL_COUNT); int columnWifiCount = cursor.getColumnIndex(DatabaseContract.Reports.WIFI_COUNT); cursor.moveToPosition(-1);/*from ww w . j a v a 2 s. c om*/ try { while (cursor.moveToNext()) { JSONObject item = new JSONObject(); item.put("time", DateTimeUtils.formatTime(DateTimeUtils.removeDay(cursor.getLong(columnTime)))); item.put("lat", cursor.getDouble(columnLat)); item.put("lon", cursor.getDouble(columnLon)); if (!cursor.isNull(columnAltitude)) { item.put("altitude", cursor.getInt(columnAltitude)); } if (!cursor.isNull(columnAccuracy)) { item.put("accuracy", cursor.getInt(columnAccuracy)); } item.put("radio", cursor.getString(columnRadio)); item.put("cell", new JSONArray(cursor.getString(columnCell))); item.put("wifi", new JSONArray(cursor.getString(columnWifi))); items.put(item); cellCount += cursor.getInt(columnCellCount); wifiCount += cursor.getInt(columnWifiCount); } } catch (JSONException jsonex) { Log.e(LOGTAG, "JSONException", jsonex); } if (items.length() == 0) { return null; } long minId, maxId; cursor.moveToFirst(); minId = cursor.getLong(columnId); cursor.moveToLast(); maxId = cursor.getLong(columnId); JSONObject wrapper = new JSONObject(Collections.singletonMap("items", items)); return new BatchRequestStats(wrapper.toString().getBytes(), wifiCount, cellCount, items.length(), minId, maxId); }
From source file:com.example.android.spotifystreamer.app.DetailFragment.java
@Override public void onLoadFinished(Loader<Cursor> loader, Cursor data) { if (data != null && data.moveToFirst()) { // Read weather condition ID from cursor int weatherId = data.getInt(COL_WEATHER_CONDITION_ID); // Use weather art image //mIconView.setImageResource(Utility.getArtResourceForWeatherCondition(weatherId)); // Picasso.with(context).load("https://i.scdn.co/image/264d935b124541a0755b6c4723a08ca51f036e21").into(mIconView); // Read date from cursor and update views for day of week and date long date = data.getLong(COL_WEATHER_DATE); String friendlyDateText = Utility.getDayName(getActivity(), date); String dateText = Utility.getFormattedMonthDay(getActivity(), date); mFriendlyDateView.setText(friendlyDateText); mDateView.setText(dateText);//from w w w . ja v a 2s.c o m // Read description from cursor and update view String description = data.getString(COL_WEATHER_DESC); mDescriptionView.setText(description); // // For accessibility, add a content description to the icon field // mIconView.setContentDescription(description); // Read high temperature from cursor and update view boolean isMetric = Utility.isMetric(getActivity()); double high = data.getDouble(COL_WEATHER_MAX_TEMP); String highString = Utility.formatTemperature(getActivity(), high); mHighTempView.setText(highString); // Read low temperature from cursor and update view double low = data.getDouble(COL_WEATHER_MIN_TEMP); String lowString = Utility.formatTemperature(getActivity(), low); mLowTempView.setText(lowString); // Read humidity from cursor and update view float humidity = data.getFloat(COL_WEATHER_HUMIDITY); mHumidityView.setText(getActivity().getString(R.string.format_humidity, humidity)); // Read wind speed and direction from cursor and update view float windSpeedStr = data.getFloat(COL_WEATHER_WIND_SPEED); float windDirStr = data.getFloat(COL_WEATHER_DEGREES); mWindView.setText(Utility.getFormattedWind(getActivity(), windSpeedStr, windDirStr)); // // Read pressure from cursor and update view // float pressure = data.getFloat(COL_WEATHER_PRESSURE); // mPressureView.setText(getActivity().getString(R.string.format_pressure, pressure)); // We still need this for the share intent mForecast = String.format("%s - %s - %s/%s", dateText, description, high, low); // If onCreateOptionsMenu has already happened, we need to update the share intent now. if (mShareActionProvider != null) { mShareActionProvider.setShareIntent(createShareForecastIntent()); } } }
From source file:com.money.manager.ex.home.HomeFragment.java
@Override public void onLoadFinished(Loader<Cursor> loader, Cursor data) { switch (loader.getId()) { case LOADER_ACCOUNT_BILLS: try {/*from ww w . j a va2 s . com*/ renderAccountsList(data); } catch (Exception e) { Timber.e(e, "rendering account list"); } // set total for accounts in the main Drawer. EventBus.getDefault().post(new AccountsTotalLoadedEvent(txtTotalAccounts.getText().toString())); break; case LOADER_INCOME_EXPENSES: double income = 0, expenses = 0; if (data != null) { while (data.moveToNext()) { expenses = data.getDouble(data.getColumnIndex(IncomeVsExpenseReportEntity.Expenses)); income = data.getDouble(data.getColumnIndex(IncomeVsExpenseReportEntity.Income)); } } TextView txtIncome = (TextView) getActivity().findViewById(R.id.textViewIncome); TextView txtExpenses = (TextView) getActivity().findViewById(R.id.textViewExpenses); TextView txtDifference = (TextView) getActivity().findViewById(R.id.textViewDifference); // set value if (txtIncome != null) txtIncome.setText(mCurrencyService.getCurrencyFormatted(mCurrencyService.getBaseCurrencyId(), MoneyFactory.fromDouble(income))); if (txtExpenses != null) txtExpenses.setText(mCurrencyService.getCurrencyFormatted(mCurrencyService.getBaseCurrencyId(), MoneyFactory.fromDouble(Math.abs(expenses)))); if (txtDifference != null) txtDifference.setText(mCurrencyService.getCurrencyFormatted(mCurrencyService.getBaseCurrencyId(), MoneyFactory.fromDouble(income - Math.abs(expenses)))); // manage progressbar final ProgressBar barIncome = (ProgressBar) getActivity().findViewById(R.id.progressBarIncome); final ProgressBar barExpenses = (ProgressBar) getActivity().findViewById(R.id.progressBarExpenses); if (barIncome != null && barExpenses != null) { barIncome.setMax((int) (Math.abs(income) + Math.abs(expenses))); barExpenses.setMax((int) (Math.abs(income) + Math.abs(expenses))); if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.HONEYCOMB) { ObjectAnimator animationIncome = ObjectAnimator.ofInt(barIncome, "progress", (int) Math.abs(income)); animationIncome.setDuration(1000); // 0.5 second animationIncome.setInterpolator(new DecelerateInterpolator()); animationIncome.start(); ObjectAnimator animationExpenses = ObjectAnimator.ofInt(barExpenses, "progress", (int) Math.abs(expenses)); animationExpenses.setDuration(1000); // 0.5 second animationExpenses.setInterpolator(new DecelerateInterpolator()); animationExpenses.start(); } else { barIncome.setProgress((int) Math.abs(income)); barExpenses.setProgress((int) Math.abs(expenses)); } } break; } // Close the cursor. MmxDatabaseUtils.closeCursor(data); }
From source file:com.bai.android.ui.OtherActivity.java
public void displayMapContent() { map.clear();/* w w w .j av a 2 s .c o m*/ TypedArray defaultAvatars = getResources().obtainTypedArray(R.array.map_markers); MapDataAdapter mapAdapter = new MapDataAdapter(getApplicationContext()); mapAdapter.open(); Cursor mapCursor = mapAdapter.getLocations(); int titleColIndex = mapCursor.getColumnIndex("title"); int descrColIndex = mapCursor.getColumnIndex("descr"); int typeColIndex = mapCursor.getColumnIndex("type"); int latColIndex = mapCursor.getColumnIndex("lat"); int lonColIndex = mapCursor.getColumnIndex("lon"); while (mapCursor.moveToNext()) { MarkerOptions marker = new MarkerOptions(); marker.title(mapCursor.getString(titleColIndex)); marker.snippet(mapCursor.getString(descrColIndex)); LatLng position = new LatLng(mapCursor.getDouble(latColIndex), mapCursor.getDouble(lonColIndex)); marker.position(position); int imgMarkerType = mapCursor.getInt(typeColIndex); int imgResource = defaultAvatars.getResourceId(imgMarkerType, R.drawable.ic_map_undefined); marker.icon(BitmapDescriptorFactory.fromResource(imgResource)); map.addMarker(marker); } mapAdapter.close(); }
From source file:com.nearnotes.NoteEdit.java
@SuppressWarnings("deprecation") private void populateFields() { if (mRowId != null) { int settingsResult = mDbHelper.fetchSetting(); if (settingsResult == mRowId) { mCheckBox.setChecked(true);// w w w . j av a2s . c om } else mCheckBox.setChecked(false); Cursor note = mDbHelper.fetchNote(mRowId); getActivity().startManagingCursor(note); mTitleText.setText(note.getString(note.getColumnIndexOrThrow(NotesDbAdapter.KEY_TITLE))); mBodyText.setText(note.getString(note.getColumnIndexOrThrow(NotesDbAdapter.KEY_BODY)), TextView.BufferType.SPANNABLE); autoCompView.setAdapter(null); autoCompView.setText(note.getString(note.getColumnIndexOrThrow(NotesDbAdapter.KEY_LOCATION))); autoCompView.setAdapter(new PlacesAutoCompleteAdapter(getActivity(), R.layout.list_item)); location = note.getString(note.getColumnIndexOrThrow(NotesDbAdapter.KEY_LOCATION)); longitude = note.getDouble(note.getColumnIndexOrThrow(NotesDbAdapter.KEY_LNG)); latitude = note.getDouble(note.getColumnIndexOrThrow(NotesDbAdapter.KEY_LAT)); checkString = note.getString(note.getColumnIndexOrThrow(NotesDbAdapter.KEY_CHECK)); mChecklist = Boolean.parseBoolean(checkString); } else { autoCompView.requestFocus(); InputMethodManager imm = (InputMethodManager) getActivity() .getSystemService(Context.INPUT_METHOD_SERVICE); imm.showSoftInput(autoCompView, InputMethodManager.SHOW_IMPLICIT); } }
From source file:com.ichi2.libanki.Stats.java
/** * Intervals *********************************************************************************************** *//*from ww w .ja va2 s. c om*/ public boolean calculateIntervals(Context context, int type) { mDynamicAxis = true; mType = type; double all = 0, avg = 0, max_ = 0; mBackwards = false; 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 TYPE_MONTH: num = 31; chunk = 1; lim = " and grp <= 30"; break; case TYPE_YEAR: num = 52; chunk = 7; lim = " and grp <= 52"; break; case TYPE_LIFE: num = -1; chunk = 30; lim = ""; break; } ArrayList<double[]> list = new ArrayList<double[]>(); Cursor cur = null; try { cur = mCol.getDb().getDatabase().rawQuery("select ivl / " + chunk + " as grp, count() from cards " + "where did in " + _limit() + " 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 = mCol.getDb().getDatabase().rawQuery( "select count(), avg(ivl), max(ivl) from cards where did in " + _limit() + " 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 != TYPE_LIFE && list.get(list.size() - 1)[0] < num) { list.add(new double[] { num, 0 }); } else if (type == TYPE_LIFE && list.size() < 2) { list.add(new double[] { Math.max(12, list.get(list.size() - 1)[0] + 1), 0 }); } mLastElement = 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]); if (data[0] > mLastElement) mLastElement = data[0]; } mCumulative = createCumulative(mSeriesList); for (int i = 0; i < list.size(); i++) { mCumulative[1][i] /= all / 100; } mMcount = 100; switch (mType) { case TYPE_MONTH: mLastElement = 31; break; case TYPE_YEAR: mLastElement = 52; break; default: } mFirstElement = 0; mMaxElements = list.size() - 1; mAverage = Utils.timeSpan(context, (int) Math.round(avg * 86400)); mLongest = Utils.timeSpan(context, (int) Math.round(max_ * 86400)); //some adjustments to not crash the chartbuilding with emtpy data if (mMaxElements == 0) { mMaxElements = 10; } if (mMcount == 0) { mMcount = 10; } if (mFirstElement == mLastElement) { mFirstElement = 0; mLastElement = 6; } if (mMaxCards == 0) mMaxCards = 10; return list.size() > 0; }
From source file:edu.gatech.ppl.cycleatlanta.TripUploader.java
private JSONObject getCoordsJSON(long tripId) throws JSONException { SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); mDb.openReadOnly();/* w ww .j av a 2s . c om*/ Cursor tripCoordsCursor = mDb.fetchAllCoordsForTrip(tripId); // Build the map between JSON fieldname and phone db fieldname: Map<String, Integer> fieldMap = new HashMap<String, Integer>(); fieldMap.put(TRIP_COORDS_TIME, tripCoordsCursor.getColumnIndex(DbAdapter.K_POINT_TIME)); fieldMap.put(TRIP_COORDS_LAT, tripCoordsCursor.getColumnIndex(DbAdapter.K_POINT_LAT)); fieldMap.put(TRIP_COORDS_LON, tripCoordsCursor.getColumnIndex(DbAdapter.K_POINT_LGT)); fieldMap.put(TRIP_COORDS_ALT, tripCoordsCursor.getColumnIndex(DbAdapter.K_POINT_ALT)); fieldMap.put(TRIP_COORDS_SPEED, tripCoordsCursor.getColumnIndex(DbAdapter.K_POINT_SPEED)); fieldMap.put(TRIP_COORDS_HACCURACY, tripCoordsCursor.getColumnIndex(DbAdapter.K_POINT_ACC)); fieldMap.put(TRIP_COORDS_VACCURACY, tripCoordsCursor.getColumnIndex(DbAdapter.K_POINT_ACC)); // Build JSON objects for each coordinate: JSONObject tripCoords = new JSONObject(); while (!tripCoordsCursor.isAfterLast()) { JSONObject coord = new JSONObject(); coord.put(TRIP_COORDS_TIME, df.format(tripCoordsCursor.getDouble(fieldMap.get(TRIP_COORDS_TIME)))); coord.put(TRIP_COORDS_LAT, tripCoordsCursor.getDouble(fieldMap.get(TRIP_COORDS_LAT)) / 1E6); coord.put(TRIP_COORDS_LON, tripCoordsCursor.getDouble(fieldMap.get(TRIP_COORDS_LON)) / 1E6); coord.put(TRIP_COORDS_ALT, tripCoordsCursor.getDouble(fieldMap.get(TRIP_COORDS_ALT))); coord.put(TRIP_COORDS_SPEED, tripCoordsCursor.getDouble(fieldMap.get(TRIP_COORDS_SPEED))); coord.put(TRIP_COORDS_HACCURACY, tripCoordsCursor.getDouble(fieldMap.get(TRIP_COORDS_HACCURACY))); coord.put(TRIP_COORDS_VACCURACY, tripCoordsCursor.getDouble(fieldMap.get(TRIP_COORDS_VACCURACY))); tripCoords.put(coord.getString("r"), coord); tripCoordsCursor.moveToNext(); } tripCoordsCursor.close(); mDb.close(); return tripCoords; }