List of usage examples for android.database Cursor getDouble
double getDouble(int columnIndex);
From source file:ru.gkpromtech.exhibition.db.Table.java
private void fillFieldValue(int type, Field field, Object entity, Cursor cursor, int i) throws IllegalAccessException { if (cursor.isNull(i)) { field.set(entity, null);/*from www . jav a2 s . c o m*/ return; } switch (type) { case INTEGER: field.set(entity, cursor.getInt(i)); break; case SHORT: field.set(entity, cursor.getShort(i)); break; case LONG: field.set(entity, cursor.getLong(i)); break; case FLOAT: field.set(entity, cursor.getFloat(i)); break; case DOUBLE: field.set(entity, cursor.getDouble(i)); break; case STRING: field.set(entity, cursor.getString(i)); break; case BYTE_ARRAY: field.set(entity, cursor.getBlob(i)); break; case DATE: field.set(entity, new Date(cursor.getLong(i))); break; case BOOLEAN: field.set(entity, cursor.getInt(i) != 0); break; } }
From source file:com.runnable.weather.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)); // 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 ww .j a va 2 s .c o m // Read description from cursor and update view String description = data.getString(COL_WEATHER_DESC); mDescriptionView.setText(WeatherDescriptionMap.getInstance().getDescription(description)); // For accessibility, add a content description to the icon field mIconView.setContentDescription(description); 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)); } }
From source file:com.money.manager.ex.reports.CategoriesReportFragment.java
public void showChart() { CategoriesReportAdapter adapter = (CategoriesReportAdapter) getListAdapter(); if (adapter == null) return;/*from w w w.ja va2s. co m*/ Cursor cursor = adapter.getCursor(); if (cursor == null) return; if (cursor.getCount() <= 0) return; ArrayList<ValuePieEntry> arrayList = new ArrayList<>(); CurrencyService currencyService = new CurrencyService(getActivity().getApplicationContext()); // Reset cursor to initial position. cursor.moveToPosition(-1); // process cursor while (cursor.moveToNext()) { ValuePieEntry item = new ValuePieEntry(); String category = cursor.getString(cursor.getColumnIndex(ViewMobileData.Category)); if (!TextUtils.isEmpty(cursor.getString(cursor.getColumnIndex(ViewMobileData.Subcategory)))) { category += " : " + cursor.getString(cursor.getColumnIndex(ViewMobileData.Subcategory)); } // total double total = Math.abs(cursor.getDouble(cursor.getColumnIndex("TOTAL"))); // check if category is empty if (TextUtils.isEmpty(category)) { category = getString(R.string.empty_category); } item.setText(category); item.setValue(total); item.setValueFormatted(currencyService.getCurrencyFormatted(currencyService.getBaseCurrencyId(), MoneyFactory.fromDouble(total))); // add element arrayList.add(item); } Bundle args = new Bundle(); args.putSerializable(PieChartFragment.KEY_CATEGORIES_VALUES, arrayList); //get fragment manager FragmentManager fragmentManager = getActivity().getSupportFragmentManager(); if (fragmentManager != null) { PieChartFragment fragment; fragment = (PieChartFragment) fragmentManager .findFragmentByTag(IncomeVsExpensesChartFragment.class.getSimpleName()); if (fragment == null) { fragment = new PieChartFragment(); } fragment.setChartArguments(args); fragment.setDisplayHomeAsUpEnabled(true); if (fragment.isVisible()) fragment.onResume(); FragmentTransaction fragmentTransaction = fragmentManager.beginTransaction(); if (((CategoriesReportActivity) getActivity()).mIsDualPanel) { fragmentTransaction.replace(R.id.fragmentChart, fragment, PieChartFragment.class.getSimpleName()); } else { fragmentTransaction.replace(R.id.fragmentMain, fragment, PieChartFragment.class.getSimpleName()); fragmentTransaction.addToBackStack(null); } fragmentTransaction.commit(); } }
From source file:com.syncedsynapse.kore2.ui.TVShowOverviewFragment.java
/** * Display the tv show details/*from ww w . j av a 2 s . co m*/ * * @param cursor Cursor with the data */ private void displayTVShowDetails(Cursor cursor) { cursor.moveToFirst(); String tvshowTitle = cursor.getString(TVShowDetailsQuery.TITLE); mediaTitle.setText(tvshowTitle); int numEpisodes = cursor.getInt(TVShowDetailsQuery.EPISODE), watchedEpisodes = cursor.getInt(TVShowDetailsQuery.WATCHEDEPISODES); String episodes = String.format(getString(R.string.num_episodes), numEpisodes, numEpisodes - watchedEpisodes); mediaUndertitle.setText(episodes); String premiered = String.format(getString(R.string.premiered), cursor.getString(TVShowDetailsQuery.PREMIERED)) + " | " + cursor.getString(TVShowDetailsQuery.STUDIO); mediaPremiered.setText(premiered); mediaGenres.setText(cursor.getString(TVShowDetailsQuery.GENRES)); double rating = cursor.getDouble(TVShowDetailsQuery.RATING); if (rating > 0) { mediaRating.setVisibility(View.VISIBLE); mediaMaxRating.setVisibility(View.VISIBLE); mediaRating.setText(String.format("%01.01f", rating)); mediaMaxRating.setText(getString(R.string.max_rating_video)); } else { mediaRating.setVisibility(View.INVISIBLE); mediaMaxRating.setVisibility(View.INVISIBLE); } mediaDescription.setText(cursor.getString(TVShowDetailsQuery.PLOT)); // // IMDB button // imdbButton.setTag(cursor.getString(TVShowDetailsQuery.IMDBNUMBER)); // Images Resources resources = getActivity().getResources(); DisplayMetrics displayMetrics = new DisplayMetrics(); getActivity().getWindowManager().getDefaultDisplay().getMetrics(displayMetrics); int posterWidth = resources.getDimensionPixelOffset(R.dimen.now_playing_poster_width); int posterHeight = resources.getDimensionPixelOffset(R.dimen.now_playing_poster_height); UIUtils.loadImageWithCharacterAvatar(getActivity(), hostManager, cursor.getString(TVShowDetailsQuery.THUMBNAIL), tvshowTitle, mediaPoster, posterWidth, posterHeight); int artHeight = resources.getDimensionPixelOffset(R.dimen.now_playing_art_height); UIUtils.loadImageIntoImageview(hostManager, cursor.getString(TVShowDetailsQuery.FANART), mediaArt, displayMetrics.widthPixels, artHeight); }
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./* ww w . j av a 2 s . c om*/ * @param c Cursor to track points. * @throws IOException */ private void writeTrackpoints(final int session, final String trackName, final BufferedWriter bw) throws IOException { Log.i(TAG, "Writing trackpoints"); Cursor c = mDbHelper.getReadableDatabase().rawQuery(TRACKPOINT_SQL_QUERY1, 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); bw.write("\t<trk>"); bw.write("\t\t<name>"); bw.write(trackName); bw.write("</name>\n"); bw.write("\t\t<trkseg>\n"); long outer = 0; while (!c.isAfterLast()) { c.moveToFirst(); //StringBuffer out = new StringBuffer(32 * 1024); while (!c.isAfterLast()) { bw.write("\t\t\t<trkpt 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("</trkpt>\n"); c.moveToNext(); } //bw.write(out.toString()); //out = null; // fetch next CURSOR_SIZE records outer += CURSOR_SIZE; c.close(); c = mDbHelper.getReadableDatabase().rawQuery(TRACKPOINT_SQL_QUERY1, new String[] { String.valueOf(mSession), String.valueOf(outer) }); } c.close(); bw.write("\t\t</trkseg>\n"); bw.write("\t</trk>\n"); System.gc(); }
From source file:com.kobi.metalsexchange.app.DetailFragment.java
@Override public void onLoadFinished(Loader<Cursor> loader, Cursor data) { if (data != null && data.moveToFirst()) { // Read metal ID from cursor String metalId = data.getString(COL_RATE_METAL_ID); // Use currency art image mIconView.setImageResource(Utility.getArtResourceForMetal(metalId)); // Read date from cursor and update views for day of week and date mDate = data.getLong(COL_RATE_DATE); String friendlyDateText = Utility.getFriendlyDayString(getActivity(), mDate); mFriendlyDateView.setText(friendlyDateText); // // For accessibility, add a content description to the icon field // mIconView.setContentDescription(description); String preferredCurrency = Utility.getPreferredCurrency(getActivity()); String rate = getRateForCurrency(data, preferredCurrency); mRateView.setText(rate);/*from w w w .j a v a 2 s . c o m*/ mRawRate = data.getDouble(Utility.getPreferredCurrencyColumnId(preferredCurrency)); mRateUnitView.setText("(" + Utility.getWeightName(getActivity()) + ")"); oneGramPrice = data.getDouble(Utility.getPreferredCurrencyColumnId(preferredCurrency)); List<String> otherCurrencies = Utility.getOtherCurrencies(getActivity()); otherCurrencies.remove(preferredCurrency); String otherRate1 = null; String otherRate2 = null; String otherRate3 = null; if (otherCurrencies.size() > 0) { otherRate1 = getRateForCurrency(data, otherCurrencies.get(0)); mCurrency1View.setText(otherRate1); } if (otherCurrencies.size() > 1) { otherRate2 = getRateForCurrency(data, otherCurrencies.get(1)); mCurrency2View.setText(otherRate2); } if (otherCurrencies.size() > 2) { otherRate3 = getRateForCurrency(data, otherCurrencies.get(2)); mCurrency3View.setText(otherRate3); } String metalName = Utility.getMetalName(metalId, getActivity()); mExchangeRate = getActivity().getString(R.string.app_name) + "(" + friendlyDateText + " [" + Utility.getWeightName(getActivity()) + "])" + ":\n" + "------" + metalName + "----" + "\n" + rate + "\n" + (otherRate1 != null ? otherRate1 + "\n" : "") + (otherRate2 != null ? otherRate2 + "\n" : "") + (otherRate3 != null ? otherRate1 : ""); // If onCreateOptionsMenu has already happened, we need to update the share intent now. if (mShareActionProvider != null) { mShareActionProvider.setShareIntent(createShareExchangeRatesIntent()); } String showJewishCustomsCurrencyKey = getActivity().getString(R.string.pref_show_jewish_customs_key); SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(getActivity()); boolean showJewishCustomsCurrency = prefs.getBoolean(showJewishCustomsCurrencyKey, Boolean.parseBoolean(getActivity().getString(R.string.pref_show_jewish_customs_default))); if (Utility.getCurrentMetalId(getActivity()).equals(Utility.SILVER) && showJewishCustomsCurrency) { mShekelButtonView.setVisibility(View.VISIBLE); mPidionButtonView.setVisibility(View.VISIBLE); } else { mShekelButtonView.setVisibility(View.GONE); mPidionButtonView.setVisibility(View.GONE); } } }
From source file:edu.pdx.cecs.orcycle.TripUploader.java
@SuppressLint("SimpleDateFormat") private JSONArray getPausesJSON(long tripId) throws JSONException { SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); mDb.openReadOnly();//from w w w.j a va2s .c o m Cursor pausesCursor = mDb.fetchPauses(tripId); // Build the map between JSON fieldname and phone db fieldname: Map<String, Integer> fieldMap = new HashMap<String, Integer>(); fieldMap.put(PAUSE_START, pausesCursor.getColumnIndex(DbAdapter.K_PAUSE_START_TIME)); fieldMap.put(PAUSE_END, pausesCursor.getColumnIndex(DbAdapter.K_PAUSE_END_TIME)); // Build JSON objects for each coordinate: JSONArray jsonPauses = new JSONArray(); while (!pausesCursor.isAfterLast()) { JSONObject json = new JSONObject(); try { json.put(PAUSE_START, df.format(pausesCursor.getDouble(fieldMap.get(PAUSE_START)))); json.put(PAUSE_END, df.format(pausesCursor.getDouble(fieldMap.get(PAUSE_END)))); jsonPauses.put(json); } catch (Exception ex) { Log.e(MODULE_TAG, ex.getMessage()); } pausesCursor.moveToNext(); } pausesCursor.close(); mDb.close(); return jsonPauses; }
From source file:com.example.asadkhan.sunshine.ForecastAdapter.java
@Override public void bindView(View view, Context context, Cursor cursor) { ViewHolder viewHolder = (ViewHolder) view.getTag(); int viewType = getItemViewType(cursor.getPosition()); switch (viewType) { case VIEW_TYPE_TODAY: { viewHolder.iconView.setImageResource(Utility.getArtResourceForWeatherCondition( cursor.getInt(MainForecastFragment.COL_WEATHER_CONDITION_ID))); break;/*from ww w. jav a2 s. c o m*/ } case VIEW_TYPE_FUTURE_DAY: { viewHolder.iconView.setImageResource(Utility.getIconResourceForWeatherCondition( cursor.getInt(MainForecastFragment.COL_WEATHER_CONDITION_ID))); break; } } Long dateInMillis = cursor.getLong(MainForecastFragment.COL_WEATHER_DATE); viewHolder.dateView.setText(Utility.getFriendlyDayString(context, dateInMillis)); String description = cursor.getString(MainForecastFragment.COL_WEATHER_DESC); viewHolder.descriptionView.setText(description); // Read user preference for metric or imperial temperature units boolean isMetric = Utility.isMetric(context); double high = cursor.getDouble(MainForecastFragment.COL_WEATHER_MAX_TEMP); viewHolder.highTempView.setText(Utility.formatTemperature(context, high, isMetric)); double low = cursor.getDouble(MainForecastFragment.COL_WEATHER_MIN_TEMP); viewHolder.lowTempView.setText(Utility.formatTemperature(context, low, isMetric)); // Log.e(LOG_TAG, "High val : " + high); // Log.e(LOG_TAG, "Low val : " + low); }
From source file:com.money.manager.ex.reports.IncomeVsExpensesListFragment.java
private void showChartInternal() { // take a adapter and cursor IncomeVsExpensesAdapter adapter = ((IncomeVsExpensesAdapter) getListAdapter()); if (adapter == null) return;/*from ww w . jav a2 s .com*/ Cursor cursor = adapter.getCursor(); if (cursor == null) return; // Move to the first record. if (cursor.getCount() <= 0) return; // arrays ArrayList<Double> incomes = new ArrayList<>(); ArrayList<Double> expenses = new ArrayList<>(); ArrayList<String> titles = new ArrayList<>(); // Reset cursor to initial position. cursor.moveToPosition(-1); // cycle cursor while (cursor.moveToNext()) { int month = cursor.getInt(cursor.getColumnIndex(IncomeVsExpenseReportEntity.Month)); // check if not subtotal if (month != IncomeVsExpensesActivity.SUBTOTAL_MONTH) { // incomes and expenses incomes.add(cursor.getDouble(cursor.getColumnIndex(IncomeVsExpenseReportEntity.Income))); expenses.add( Math.abs(cursor.getDouble(cursor.getColumnIndex(IncomeVsExpenseReportEntity.Expenses)))); // titles int year = cursor.getInt(cursor.getColumnIndex(IncomeVsExpenseReportEntity.YEAR)); // format month Calendar calendar = Calendar.getInstance(); calendar.set(year, month - 1, 1); // titles titles.add(Integer.toString(year) + "-" + new SimpleDateFormat("MMM").format(calendar.getTime())); } } //compose bundle for arguments Bundle args = new Bundle(); args.putDoubleArray(IncomeVsExpensesChartFragment.KEY_EXPENSES_VALUES, ArrayUtils.toPrimitive(expenses.toArray(new Double[0]))); args.putDoubleArray(IncomeVsExpensesChartFragment.KEY_INCOME_VALUES, ArrayUtils.toPrimitive(incomes.toArray(new Double[0]))); args.putStringArray(IncomeVsExpensesChartFragment.KEY_XTITLES, titles.toArray(new String[titles.size()])); //get fragment manager FragmentManager fragmentManager = getActivity().getSupportFragmentManager(); if (fragmentManager != null) { IncomeVsExpensesChartFragment fragment; fragment = (IncomeVsExpensesChartFragment) fragmentManager .findFragmentByTag(IncomeVsExpensesChartFragment.class.getSimpleName()); if (fragment == null) { fragment = new IncomeVsExpensesChartFragment(); } fragment.setChartArguments(args); fragment.setDisplayHomeAsUpEnabled(true); if (fragment.isVisible()) fragment.onResume(); FragmentTransaction fragmentTransaction = fragmentManager.beginTransaction(); if (((IncomeVsExpensesActivity) getActivity()).mIsDualPanel) { fragmentTransaction.replace(R.id.fragmentChart, fragment, IncomeVsExpensesChartFragment.class.getSimpleName()); } else { fragmentTransaction.replace(R.id.fragmentMain, fragment, IncomeVsExpensesChartFragment.class.getSimpleName()); fragmentTransaction.addToBackStack(null); } fragmentTransaction.commit(); } }
From source file:cz.maresmar.sfm.view.portal.PortalDetailFragment.java
@Override public void onLoadFinished(@NonNull Loader<Cursor> loader, Cursor cursor) { switch (loader.getId()) { case PORTAL_LOADER_ID: Timber.d("Portal data loaded"); cursor.moveToFirst();// ww w .j a v a 2 s . com if (BuildConfig.DEBUG) { Assert.isOne(cursor.getCount()); } // Portal name mNameText.setText(cursor.getString(0)); // Portal reference mRefText.setText(cursor.getString(1)); // Security spinner setConnectionSecurity(cursor.getInt(3)); // Location LatLng location = new LatLng(cursor.getDouble(4), cursor.getDouble(5)); if (location.latitude == 0 && location.longitude == 0) removeLocation(); else setLocation(location); // Extra setExtraData(cursor.getString(6)); // Plugin String plugin = cursor.getString(2); AsyncTask.execute(() -> { try { blockingLoaders.await(); } catch (InterruptedException e) { Timber.e(e); } getActivity().runOnUiThread(() -> { setPlugin(plugin); mPluginSpinner.setOnItemSelectedListener(mPluginChangeListen); }); }); // New menu notification @ProviderContract.PortalFlags int flags = cursor.getInt(7); mNewMenuNotificationCheckBox.setChecked(!((flags & ProviderContract.PORTAL_FLAG_DISABLE_NEW_MENU_NOTIFICATION) == ProviderContract.PORTAL_FLAG_DISABLE_NEW_MENU_NOTIFICATION)); break; default: throw new UnsupportedOperationException("Unknown loader id: " + loader.getId()); } }