List of usage examples for android.database Cursor getFloat
float getFloat(int columnIndex);
From source file:org.ohmage.triggers.types.location.LocationTrigger.java
private JSONArray getLocations(Context context, int categId) { JSONArray jLocs = new JSONArray(); LocTrigDB db = new LocTrigDB(context); db.open();/*from w ww . j a v a 2 s . co m*/ Cursor cLocs = db.getLocations(categId); if (cLocs.moveToFirst()) { do { int lat = cLocs.getInt(cLocs.getColumnIndexOrThrow(LocTrigDB.KEY_LAT)); int lng = cLocs.getInt(cLocs.getColumnIndexOrThrow(LocTrigDB.KEY_LONG)); float radius = cLocs.getFloat(cLocs.getColumnIndexOrThrow(LocTrigDB.KEY_RADIUS)); JSONObject jLoc = new JSONObject(); try { jLoc.put(KEY_LATITUDE, (double) (lat / 1E6)); jLoc.put(KEY_LONGITUDE, (double) (lng / 1E6)); jLoc.put(KEY_RADIUS, radius); jLocs.put(jLoc); } catch (JSONException e) { Log.e(DEBUG_TAG, "LocationTrigger: Error adding locations to " + "preference JSON"); } } while (cLocs.moveToNext()); } cLocs.close(); db.close(); return jLocs; }
From source file:org.sensapp.android.sensappdroid.activities.GraphDisplayerActivity.java
private void addGraphToWrapperList(List<GraphWrapper> gwl, Cursor cursor, String title, int style, int color, long graphSensorID, float min, float max) { GraphBuffer buffer = new GraphBuffer(); for (cursor.moveToFirst(); !cursor.isAfterLast(); cursor.moveToNext()) { buffer.insertData(cursor.getFloat(cursor.getColumnIndex(SensAppContract.Measure.VALUE))); }/* ww w. j a v a2s .c o m*/ GraphWrapper wrapper = new GraphWrapper(graphSensorID, buffer); if ((min == Integer.MIN_VALUE) || (max == Integer.MAX_VALUE)) { wrapper.setGraphOptions(color, 500, style, title); if (min != Integer.MIN_VALUE) wrapper.setLowestVisible(min); if (max != Integer.MAX_VALUE) wrapper.setHighestVisible(max); } else wrapper.setGraphOptions(color, 500, style, title, min, max); wrapper.setPrinterParameters(true, false, true); gwl.add(wrapper); }
From source file:edu.auburn.ppl.cyclecolumbus.TripUploader.java
/****************************************************************************************** * Generates and uploads KCal, CO2 savings, Avg Savings from biking vs riding, and distance. ****************************************************************************************** * @param cursor Uses this to access SQLite database ******************************************************************************************/ private void setKcalCo2Savings(Cursor cursor) { // Set co2// ww w . jav a2 s . c om Double CO2 = cursor.getFloat(cursor.getColumnIndex("distance")) * 0.0006212 * 0.93; DecimalFormat df = new DecimalFormat("0.#"); co2 = df.format(CO2); // Set kcal Double calory = cursor.getFloat(cursor.getColumnIndex("distance")) * 0.0006212 * 49 - 1.69; if (calory <= 0) { kcal = "0"; } else { kcal = df.format(calory); } // Set Average Savings float savings = cursor.getFloat(cursor.getColumnIndex("distance")) * 0.0006212f; Double dSavings = savings * .592; Log.d("KENNY", "Distance: " + cursor.getFloat(cursor.getColumnIndex("distance"))); DecimalFormat df2 = new DecimalFormat("$#,###,##0.00"); avgCost = df2.format(dSavings); // Set Distance float dist = cursor.getFloat(cursor.getColumnIndex("distance")) * 0.0006212f; DecimalFormat dfDistance = new DecimalFormat("0.0#"); distance = String.valueOf(dfDistance.format(dist)); }
From source file:fr.eoit.activity.fragment.blueprint.BlueprintInfoFragment.java
@Override public void onLoadFinished(Cursor data) { if (DbUtil.hasAtLeastOneRow(data)) { int metaGroupId = getArguments().getInt("metaGroupId", -1); Bundle blueprintBundle = BlueprintUtil.getBlueprintBundle(data, metaGroupId, true, false); int ml = blueprintBundle.getInt("ml"); int pl = blueprintBundle.getInt("pl"); int numberOfRuns = blueprintBundle.getInt("numberOfRuns", 0); int unitPerBatch = blueprintBundle.getInt("unitPerBatch", 0); float baseProductionTime = data .getFloat(data.getColumnIndexOrThrow(Blueprint.COLUMN_NAME_PRODUCTION_TIME)); float productivityModifier = data .getFloat(data.getColumnIndexOrThrow(Blueprint.COLUMN_NAME_PRODUCTIVITY_MODIFIER)); int baseCopyTime = data.getInt(data.getColumnIndexOrThrow(Blueprint.COLUMN_NAME_RESEARCH_COPY_TIME)); float wasteFactor = FormulaCalculator.calculateWasteFactor(ml); double productionTime = FormulaCalculator.calculateProductionTime(baseProductionTime, productivityModifier, pl); double copyPrice = FormulaCalculator.calculateMaxRunsCopyCost(baseCopyTime, 1000, 4343, 1.5F, 0.5F); double copyTime = FormulaCalculator.calculateMaxRunsCopyTime(baseCopyTime); ((TextView) getView().findViewById(R.id.ML)).setText(Integer.toString(ml)); ((TextView) getView().findViewById(R.id.PL)).setText(Integer.toString(pl)); ((TextView) getView().findViewById(R.id.MAX_RUNS)).setText(Integer.toString(numberOfRuns)); ((TextView) getView().findViewById(R.id.UNIT_PER_BATCH)).setText(Integer.toString(unitPerBatch)); ((TextView) getView().findViewById(R.id.WASTE_FACTOR)).setText(nfPercent.format(wasteFactor)); ((TextView) getView().findViewById(R.id.PRODUCTION_TIME)).setText(Formatter.formatTime(productionTime)); ((TextView) getView().findViewById(R.id.RESEARCH_COPY_COST)) .setText(PricesUtils.formatPrice(copyPrice, getActivity(), true)); ((TextView) getView().findViewById(R.id.RESEARCH_COPY_TIME)).setText(Formatter.formatTime(copyTime)); /*/*from www. ja v a2 s. c o m*/ investFragment = (ItemInvestFragment) getFragmentManager().findFragmentById(R.id.INVEST_ITEMS_CONTAINER); investFragment.setItemId(getArguments().getInt("produceItemId")); */ } }
From source file:com.example.shutapp.DatabaseHandler.java
/** * Reads the database for a chatroom.//from w w w. j a v a 2s. com * @param name of the chatroom * @return the chatroom object */ public Chatroom getChatroom(String name) { SQLiteDatabase db = this.getReadableDatabase(); Cursor cursor = db.query(TABLE_CHATROOMS, new String[] { KEY_NAME, KEY_LATITUDE, KEY_LONGITUDE, KEY_RADIUS }, KEY_NAME + "=?", new String[] { name }, null, null, null, null); if (cursor != null) { cursor.moveToFirst(); } Chatroom chatroom = new Chatroom(cursor.getString(0), cursor.getDouble(1), cursor.getDouble(2), cursor.getFloat(StringLiterals.THREE)); // return chatroom return chatroom; }
From source file:org.akvo.flow.ui.fragment.SurveyListFragment.java
@Override public void onLoadFinished(Loader<Cursor> loader, Cursor cursor) { if (cursor == null) { Log.e(TAG, "onFinished() - Loader returned no data"); return;/*from w w w.j a va 2s . c om*/ } mAdapter.clear(); if (cursor.moveToFirst()) { do { SurveyInfo s = new SurveyInfo(); s.mId = cursor.getString(SurveyQuery.SURVEY_ID); s.mName = cursor.getString(SurveyQuery.NAME); s.mVersion = String.valueOf(cursor.getFloat(SurveyQuery.VERSION)); if (!cursor.isNull(SurveyQuery.SUBMITTED)) { s.mLastSubmission = cursor.getLong(SurveyQuery.SUBMITTED); } if (mSurveyGroup.isMonitored() && isRegistrationSurvey(s.mId)) { mAdapter.insert(s, 0);// Make sure registration survey is at the top } else { mAdapter.add(s); } } while (cursor.moveToNext()); } }
From source file:com.dabay6.android.apps.carlog.ui.statistics.fragments.AveragesFragment.java
/** * {@inheritDoc}/*w w w. jav a 2 s . c om*/ */ @Override public void onLoadFinished(final Loader<Cursor> loader, final Cursor cursor) { final DetailsAdapter adapter; final DetailsItemList items = new DetailsItemList(); if (DataUtils.hasData(cursor)) { final String[] columnNames = cursor.getColumnNames(); for (final String columnName : columnNames) { if (!columnName.equalsIgnoreCase(Columns.VEHICLE_ID.getName())) { final DetailsItem item; final int index = cursor.getColumnIndex(columnName); final String text; final float value = cursor.getFloat(index); if (columnName.equalsIgnoreCase(Columns.AVERAGE_FUEL_AMOUNT.getName()) || columnName.equalsIgnoreCase(Columns.AVERAGE_MILES_PER_GALLON.getName()) || columnName.equalsIgnoreCase(Columns.MAX_MILES_PER_GALLON.getName())) { text = String.format(getString(R.string.gallons), value); } else { final NumberFormat currency = NumberFormat.getCurrencyInstance(); text = currency.format(cursor.getFloat(index)); } item = new DetailsItem(StringUtils.splitIntoWords(columnName), text); items.add(item); } } } adapter = new DetailsAdapter(getActivity(), items, layout.list_item_statistics); setListAdapter(adapter); if (isResumed()) { setListShown(true); } else { setListShownNoAnimation(true); } }
From source file:com.dabay6.android.apps.carlog.ui.statistics.fragments.TotalsFragment.java
/** * {@inheritDoc}//from ww w. j av a 2s .c o m */ @Override public void onLoadFinished(final Loader<Cursor> cursorLoader, final Cursor cursor) { final DetailsAdapter adapter; final DetailsItemList items = new DetailsItemList(); if (DataUtils.hasData(cursor)) { final String[] columnNames = cursor.getColumnNames(); for (final String columnName : columnNames) { if (!columnName.equalsIgnoreCase(Columns.VEHICLE_ID.getName())) { final DetailsItem item; final int index = cursor.getColumnIndex(columnName); final String text; final float value = cursor.getFloat(index); if (columnName.equalsIgnoreCase(Columns.TOTAL_DISTANCE.getName())) { text = String.format(getString(R.string.fuel_history_miles), value); } else if (columnName.equalsIgnoreCase(Columns.TOTAL_FUEL.getName())) { text = String.format(getString(R.string.gallons), value); } else { final NumberFormat currency = NumberFormat.getCurrencyInstance(); text = currency.format(cursor.getFloat(index)); } item = new DetailsItem(StringUtils.splitIntoWords(columnName), text); items.add(item); } } } adapter = new DetailsAdapter(getActivity(), items, layout.list_item_statistics); setListAdapter(adapter); if (isResumed()) { setListShown(true); } else { setListShownNoAnimation(true); } }
From source file:com.dabay6.android.apps.carlog.ui.statistics.fragments.FillUpsFragment.java
/** * {@inheritDoc}// w ww. j a v a 2 s .c om */ @Override public void onLoadFinished(final Loader<Cursor> loader, final Cursor cursor) { final DetailsAdapter adapter; final DetailsItemList items = new DetailsItemList(); if (DataUtils.hasData(cursor)) { final String[] columnNames = cursor.getColumnNames(); for (final String columnName : columnNames) { if (!columnName.equalsIgnoreCase(Columns.VEHICLE_ID.getName())) { final DetailsItem item; final int index = cursor.getColumnIndex(columnName); final String text; final float value = cursor.getFloat(index); if (columnName.equalsIgnoreCase(Columns.TOTAL_FILL_UPS.getName())) { text = StringUtils.format("%.0f", value); } else if (columnName.equalsIgnoreCase(Columns.MAX_FUEL_AMOUNT.getName()) || columnName.equalsIgnoreCase(Columns.MIN_FUEL_AMOUNT.getName())) { text = StringUtils.format(getString(R.string.gallons), value); } else { final NumberFormat currency = NumberFormat.getCurrencyInstance(); text = currency.format(cursor.getFloat(index)); } item = new DetailsItem(StringUtils.splitIntoWords(columnName), text); items.add(item); } } } adapter = new DetailsAdapter(getActivity(), items, layout.list_item_statistics); setListAdapter(adapter); if (isResumed()) { setListShown(true); } else { setListShownNoAnimation(true); } }
From source file:com.ultramegasoft.flavordex2.fragment.ViewInfoFragment.java
@Override public void onLoadFinished(@NonNull Loader<Cursor> loader, Cursor data) { final int id = loader.getId(); switch (id) { case LOADER_MAIN: if (data.moveToFirst()) { mEntryCat = data.getString(data.getColumnIndex(Tables.Entries.CAT)); mTitle = data.getString(data.getColumnIndex(Tables.Entries.TITLE)); mRating = data.getFloat(data.getColumnIndex(Tables.Entries.RATING)); populateViews(data);// www .j ava 2 s . com } break; case LOADER_EXTRAS: data.moveToPosition(-1); final LinkedHashMap<String, ExtraFieldHolder> extras = new LinkedHashMap<>(); String name; String value; boolean preset; while (data.moveToNext()) { name = data.getString(data.getColumnIndex(Tables.Extras.NAME)); value = data.getString(data.getColumnIndex(Tables.EntriesExtras.VALUE)); preset = data.getInt(data.getColumnIndex(Tables.Extras.PRESET)) == 1; extras.put(name, new ExtraFieldHolder(0, name, preset, value)); } populateExtras(extras); } }