List of usage examples for android.database Cursor getDouble
double getDouble(int columnIndex);
From source file:edu.auburn.ppl.cyclecolumbus.TripUploader.java
/****************************************************************************************** * Gets each coordinate that was set during a trip and the info that goes along with it. ****************************************************************************************** * @param tripId Unique trip ID//from w w w.j a v a 2 s .c o m * @return JSONObject representing all of the points set during trip * @throws JSONException ******************************************************************************************/ private JSONObject getCoordsJSON(long tripId) throws JSONException { SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); mDb.openReadOnly(); 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; }
From source file:com.dileepindia.cordova.sms.SMSPlugin.java
private JSONObject getJsonFromCursor(Cursor cur) { JSONObject json = new JSONObject(); int nCol = cur.getColumnCount(); String[] keys = cur.getColumnNames(); try {//from ww w . j a v a 2 s.co m for (int j = 0; j < nCol; j++) { switch (cur.getType(j)) { /*case 0: json.put(keys[j], null); break; case 1: json.put(keys[j], cur.getInt(j)); break; case 2: json.put(keys[j], cur.getLong(j)); break; case 3: json.put(keys[j], cur.getFloat(j)); break; case 4: json.put(keys[j], cur.getString(j)); break; case 5: json.put(keys[j], cur.getBlob(j)); */ case Cursor.FIELD_TYPE_BLOB: json.put(keys[j], cur.getBlob(j).toString()); break; case Cursor.FIELD_TYPE_FLOAT: json.put(keys[j], cur.getDouble(j)); break; case Cursor.FIELD_TYPE_INTEGER: json.put(keys[j], cur.getLong(j)); break; case Cursor.FIELD_TYPE_NULL: json.put(keys[j], cur); break; case Cursor.FIELD_TYPE_STRING: json.put(keys[j], cur.getString(j)); break; } } } catch (Exception e) { e.printStackTrace(); return null; } return json; }
From source file:org.cowboycoders.cyclismo.CourseListActivity.java
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.course_list); sharedPreferences = getSharedPreferences(Constants.SETTINGS_NAME, Context.MODE_PRIVATE); listView = (ListView) findViewById(R.id.course_list); listView.setEmptyView(findViewById(R.id.course_list_empty_view)); listView.setOnItemClickListener(new OnItemClickListener() { @Override//from w w w.jav a 2s . c o m public void onItemClick(AdapterView<?> parent, View view, int position, long id) { updateTrackIdSharedPreference(id); //Editor editor = sharedPreferences.edit(); //editor.putLong(PreferencesUtils.getKey(CourseListActivity.this,R.string.course_track_id), id); //editor.apply(); doFinish(); } }); resourceCursorAdapter = new ResourceCursorAdapter(this, R.layout.list_item, null, 0) { @Override public void bindView(View view, Context context, Cursor cursor) { int idIndex = cursor.getColumnIndex(CourseTracksColumns._ID); int iconIndex = cursor.getColumnIndex(CourseTracksColumns.ICON); int nameIndex = cursor.getColumnIndex(CourseTracksColumns.NAME); int categoryIndex = cursor.getColumnIndex(CourseTracksColumns.CATEGORY); int totalTimeIndex = cursor.getColumnIndexOrThrow(CourseTracksColumns.TOTALTIME); int totalDistanceIndex = cursor.getColumnIndexOrThrow(CourseTracksColumns.TOTALDISTANCE); int startTimeIndex = cursor.getColumnIndexOrThrow(CourseTracksColumns.STARTTIME); int descriptionIndex = cursor.getColumnIndex(CourseTracksColumns.DESCRIPTION); int iconId = TrackIconUtils.getIconDrawable(cursor.getString(iconIndex)); String name = cursor.getString(nameIndex); String totalTime = StringUtils.formatElapsedTime(cursor.getLong(totalTimeIndex)); String totalDistance = StringUtils.formatDistance(CourseListActivity.this, cursor.getDouble(totalDistanceIndex), metricUnits); long startTime = cursor.getLong(startTimeIndex); String startTimeDisplay = StringUtils.formatDateTime(context, startTime).equals(name) ? null : StringUtils.formatRelativeDateTime(context, startTime); Log.d(TAG, "resourceCursorAdapter.bindview : ListItemUtils.setListItem"); ListItemUtils.setListItem(CourseListActivity.this, view, false, false, iconId, R.string.icon_track, name, cursor.getString(categoryIndex), totalTime, totalDistance, startTimeDisplay, cursor.getString(descriptionIndex)); Log.d(TAG, "resourceCursorAdapter.bindview : ListItemUtils.setListItem finished"); } }; listView.setAdapter(resourceCursorAdapter); ApiAdapterFactory.getApiAdapter().configureListViewContextualMenu(this, listView, contextualActionModeCallback); getSupportLoaderManager().initLoader(0, null, new LoaderCallbacks<Cursor>() { @Override public Loader<Cursor> onCreateLoader(int arg0, Bundle arg1) { Log.d(TAG, "onCreateLoader"); CursorLoader rtn = new CursorLoader(CourseListActivity.this, CourseTracksColumns.CONTENT_URI, PROJECTION, null, null, CourseTracksColumns._ID + " DESC"); Log.d(TAG, "onCreateLoader returning"); return rtn; } @Override public void onLoadFinished(Loader<Cursor> loader, Cursor cursor) { Log.d(TAG, "onLoadFinished"); resourceCursorAdapter.swapCursor(cursor); Log.d(TAG, "onLoadFinished returning"); } @Override public void onLoaderReset(Loader<Cursor> loader) { Log.d(TAG, "onLoaderReset"); resourceCursorAdapter.swapCursor(null); Log.d(TAG, "onLoaderReset returning"); } }); importButton = (Button) this.findViewById(R.id.course_import_button); importButton.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { showChooser(); } }); cancelButton = (Button) this.findViewById(R.id.course_cancel_button); cancelButton.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { cancel(); } }); showStartupDialogs(); }
From source file:edu.cens.loci.provider.LociDbUtils.java
/** * /*from w w w.j av a 2 s. c o m*/ * @param start * @param end * @param filter * @return */ public ArrayList<LociLocation> getTrack(long start, long end, int filter) { String[] columns = new String[] { Tracks._ID, Tracks.TIME, Tracks.LATITUDE, Tracks.LONGITUDE, Tracks.ALTITUDE, Tracks.SPEED, Tracks.BEARING, Tracks.ACCURACY }; String selection = Tracks.TIME + ">=" + start + " AND " + Tracks.TIME + " <= " + end; final SQLiteDatabase db = mDbHelper.getWritableDatabase(); Cursor cursor = db.query(Tables.TRACKS, columns, selection, null, null, null, null); ArrayList<LociLocation> track = new ArrayList<LociLocation>(); if (cursor.moveToFirst()) { do { LociLocation loc = new LociLocation(LocationManager.GPS_PROVIDER); loc.setTime(cursor.getLong(cursor.getColumnIndex(Tracks.TIME))); loc.setLatitude(cursor.getDouble(cursor.getColumnIndex(Tracks.LATITUDE))); loc.setLongitude(cursor.getDouble(cursor.getColumnIndex(Tracks.LONGITUDE))); loc.setAltitude(cursor.getDouble(cursor.getColumnIndex(Tracks.ALTITUDE))); loc.setSpeed(cursor.getFloat(cursor.getColumnIndex(Tracks.SPEED))); loc.setBearing(cursor.getFloat(cursor.getColumnIndex(Tracks.BEARING))); loc.setAccuracy(cursor.getFloat(cursor.getColumnIndex(Tracks.ACCURACY))); track.add(loc); } while (cursor.moveToNext()); } cursor.close(); return track; }
From source file:org.cowboycoders.cyclisimo.CourseListActivity.java
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.course_list); sharedPreferences = getSharedPreferences(Constants.SETTINGS_NAME, Context.MODE_PRIVATE); listView = (ListView) findViewById(R.id.course_list); listView.setEmptyView(findViewById(R.id.course_list_empty_view)); listView.setOnItemClickListener(new OnItemClickListener() { @Override/*w ww. ja v a2s .com*/ public void onItemClick(AdapterView<?> parent, View view, int position, long id) { updateTrackIdSharedPreference(id); //Editor editor = sharedPreferences.edit(); //editor.putLong(PreferencesUtils.getKey(CourseListActivity.this,R.string.course_track_id), id); //editor.apply(); doFinish(); } }); resourceCursorAdapter = new ResourceCursorAdapter(this, R.layout.list_item, null, 0) { @Override public void bindView(View view, Context context, Cursor cursor) { int idIndex = cursor.getColumnIndex(CourseTracksColumns._ID); int iconIndex = cursor.getColumnIndex(CourseTracksColumns.ICON); int nameIndex = cursor.getColumnIndex(CourseTracksColumns.NAME); int categoryIndex = cursor.getColumnIndex(CourseTracksColumns.CATEGORY); int totalTimeIndex = cursor.getColumnIndexOrThrow(CourseTracksColumns.TOTALTIME); int totalDistanceIndex = cursor.getColumnIndexOrThrow(CourseTracksColumns.TOTALDISTANCE); int startTimeIndex = cursor.getColumnIndexOrThrow(CourseTracksColumns.STARTTIME); int descriptionIndex = cursor.getColumnIndex(CourseTracksColumns.DESCRIPTION); int iconId = TrackIconUtils.getIconDrawable(cursor.getString(iconIndex)); String name = cursor.getString(nameIndex); String totalTime = StringUtils.formatElapsedTime(cursor.getLong(totalTimeIndex)); String totalDistance = StringUtils.formatDistance(CourseListActivity.this, cursor.getDouble(totalDistanceIndex), metricUnits); long startTime = cursor.getLong(startTimeIndex); String startTimeDisplay = StringUtils.formatDateTime(context, startTime).equals(name) ? null : StringUtils.formatRelativeDateTime(context, startTime); Log.d(TAG, "resourceCursorAdapter.bindview : ListItemUtils.setListItem"); ListItemUtils.setListItem(CourseListActivity.this, view, false, false, iconId, R.string.icon_track, name, cursor.getString(categoryIndex), totalTime, totalDistance, startTimeDisplay, cursor.getString(descriptionIndex)); Log.d(TAG, "resourceCursorAdapter.bindview : ListItemUtils.setListItem finsihed"); } }; listView.setAdapter(resourceCursorAdapter); ApiAdapterFactory.getApiAdapter().configureListViewContextualMenu(this, listView, contextualActionModeCallback); getSupportLoaderManager().initLoader(0, null, new LoaderCallbacks<Cursor>() { @Override public Loader<Cursor> onCreateLoader(int arg0, Bundle arg1) { Log.d(TAG, "onCreateLoader"); CursorLoader rtn = new CursorLoader(CourseListActivity.this, CourseTracksColumns.CONTENT_URI, PROJECTION, null, null, CourseTracksColumns._ID + " DESC"); Log.d(TAG, "onCreateLoader returning"); return rtn; } @Override public void onLoadFinished(Loader<Cursor> loader, Cursor cursor) { Log.d(TAG, "onLoadFinished"); resourceCursorAdapter.swapCursor(cursor); Log.d(TAG, "onLoadFinished returning"); } @Override public void onLoaderReset(Loader<Cursor> loader) { Log.d(TAG, "onLoaderReset"); resourceCursorAdapter.swapCursor(null); Log.d(TAG, "onLoaderReset returning"); } }); importButton = (Button) this.findViewById(R.id.course_import_button); importButton.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { showChooser(); } }); cancelButton = (Button) this.findViewById(R.id.course_cancel_button); cancelButton.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { cancel(); } }); showStartupDialogs(); }
From source file:com.nadmm.airports.afd.AirportDetailsFragment.java
protected void showHomeDistance(Cursor[] result) { LinearLayout layout = (LinearLayout) findViewById(R.id.detail_home_layout); Cursor home = result[14]; if (home == null) { Runnable runnable = new Runnable() { @Override/* w ww . j a v a 2 s .c o m*/ public void run() { Intent prefs = new Intent(getActivity(), PreferencesActivity.class); startActivity(prefs); getActivity().finish(); } }; addClickableRow(layout, "Tap here to set home airport", runnable); } else if (home.moveToFirst()) { String siteNumber = home.getString(home.getColumnIndex(Airports.SITE_NUMBER)); if (siteNumber.equals(mSiteNumber)) { addRow(layout, mHome + " is your home airport"); } else { double lat = home.getDouble(home.getColumnIndex(Airports.REF_LATTITUDE_DEGREES)); double lon = home.getDouble(home.getColumnIndex(Airports.REF_LONGITUDE_DEGREES)); float[] results = new float[3]; Location.distanceBetween(lat, lon, mLocation.getLatitude(), mLocation.getLongitude(), results); float distance = results[0] / GeoUtils.METERS_PER_NAUTICAL_MILE; if (distance >= 100) { distance = Math.round(distance); } int initialBearing = Math.round((results[1] + mDeclination + 360) % 360); int finalBearing = Math.round((results[2] + mDeclination + 360) % 360); addRow(layout, "Distance from " + mHome, String.format(Locale.US, "%s %s", FormatUtils.formatNauticalMiles(distance), GeoUtils.getCardinalDirection(initialBearing))); addRow(layout, "Initial bearing", FormatUtils.formatDegrees(initialBearing) + " M"); if (Math.abs(finalBearing - initialBearing) >= 10) { addRow(layout, "Final bearing", FormatUtils.formatDegrees(finalBearing) + " M"); } } } else { addRow(layout, "Home airport '" + mHome + "' not found"); } }
From source file:com.ichi2.libanki.Stats.java
/** * Cards Types/*w ww .ja va 2s .c o m*/ */ public boolean calculateCardsTypes(int type) { mTitle = R.string.stats_cards_types; mIsPieChart = true; mAxisTitles = new int[] { R.string.stats_answer_type, R.string.stats_answers, R.string.stats_cumulative_correct_percentage }; mValueLabels = new int[] { R.string.statistics_mature, R.string.statistics_young_and_learn, R.string.statistics_unlearned, R.string.statistics_suspended }; mColors = new int[] { R.color.stats_mature, R.color.stats_young, R.color.stats_unseen, R.color.stats_suspended }; mType = type; ArrayList<double[]> list = new ArrayList<double[]>(); double[] pieData; Cursor cur = null; String query = "select " + "sum(case when queue=2 and ivl >= 21 then 1 else 0 end), -- mtr\n" + "sum(case when queue in (1,3) or (queue=2 and ivl < 21) then 1 else 0 end), -- yng/lrn\n" + "sum(case when queue=0 then 1 else 0 end), -- new\n" + "sum(case when queue<0 then 1 else 0 end) -- susp\n" + "from cards where did in " + _limit(); Timber.d("CardsTypes query: %s", query); try { cur = mCol.getDb().getDatabase().rawQuery(query, null); cur.moveToFirst(); pieData = new double[] { cur.getDouble(0), cur.getDouble(1), cur.getDouble(2), cur.getDouble(3) }; } finally { if (cur != null && !cur.isClosed()) { cur.close(); } } //TODO adjust for CardsTypes, 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 }); // } mSeriesList = new double[1][4]; mSeriesList[0] = pieData; mFirstElement = 0.5; mLastElement = 9.5; mMcount = 100; mMaxElements = 10; //bars are positioned from 1 to 14 if (mMaxCards == 0) mMaxCards = 10; return list.size() > 0; }
From source file:com.money.manager.ex.home.DashboardFragment.java
private View showTableLayoutTopPayees(Cursor cursor) { LayoutInflater inflater = (LayoutInflater) getActivity().getSystemService(Context.LAYOUT_INFLATER_SERVICE); LinearLayout layout = (LinearLayout) inflater.inflate(R.layout.dashboard_summary_layout, null); CurrencyService currencyService = new CurrencyService(getActivity().getApplicationContext()); // Textview Title TextView title = (TextView) layout.findViewById(R.id.textViewTitle); title.setText(R.string.top_payees_last_30_days); // Table//from ww w. j a va 2s. c om TableLayout tableLayout = (TableLayout) layout.findViewById(R.id.tableLayoutSummary); // Create Title tableLayout.addView(createTableRow( new String[] { "<small><b>" + getString(R.string.payee) + "</b></small>", "<small><b>" + getString(R.string.quantity) + "</b></small>", "<small><b>" + getString(R.string.summary) + "</b></small>" }, new Float[] { 1f, null, null }, new Integer[] { null, Gravity.RIGHT, Gravity.RIGHT }, new Integer[][] { null, { 0, 0, padding_in_px, 0 }, null })); // add rows while (cursor.moveToNext()) { // load values String payee = cursor.getString(cursor.getColumnIndex(ViewMobileData.PAYEE)); double total = cursor.getDouble(cursor.getColumnIndex("TOTAL")); int num = cursor.getInt(cursor.getColumnIndex("NUM")); // Add Row tableLayout.addView(createTableRow( new String[] { "<small>" + payee + "</small>", "<small><i>" + Integer.toString(num) + "</i></small>", "<small>" + currencyService.getCurrencyFormatted(currencyService.getBaseCurrencyId(), MoneyFactory.fromDouble(total)) + "</small>" }, new Float[] { 1f, null, null }, new Integer[] { null, Gravity.RIGHT, Gravity.RIGHT }, new Integer[][] { null, { 0, 0, padding_in_px, 0 }, null })); } // return Layout return layout; }
From source file:co.carlosjimenez.android.currencyalerts.app.DetailActivityFragment.java
@Override public void onLoadFinished(Loader<Cursor> loader, Cursor data) { if (data == null) { Log.d(LOG_TAG, "Detail Forex Loader Finished: No data returned"); return;/*from ww w. ja v a 2 s.c om*/ } if (!data.moveToFirst()) { Log.d(LOG_TAG, "Detail Forex Loader Finished: No data returned"); data.close(); return; } long lDate = 0; String sDate = ""; String sCurrency = ""; int i = 0; double dRateAverage = 0; double dVal = 0; double dMinVal = 0; double dMaxVal = 0; data.moveToPosition(0); mCurrencyFromId = data.getString(COL_CURRENCY_FROM_ID); String currencyFromName = data.getString(COL_CURRENCY_FROM_NAME); String currencyFromSymbol = data.getString(COL_CURRENCY_FROM_SYMBOL); String countryFromName = data.getString(COL_COUNTRY_FROM_NAME); double currencyFromRate = ForexContract.RateEntry.getRateFromUri(mUri); mCurrencyToId = data.getString(COL_CURRENCY_TO_ID); String currencyToName = data.getString(COL_CURRENCY_TO_NAME); String currencyToSymbol = data.getString(COL_CURRENCY_TO_SYMBOL); String countryToName = data.getString(COL_COUNTRY_TO_NAME); double currencyToRate = ForexContract.RateEntry.getRateFromUri(mUri) * data.getDouble(COL_RATE_VAL); Glide.with(getActivity()).load(data.getString(COL_COUNTRY_FROM_FLAG)).error(R.drawable.globe).crossFade() .into(mIvFlagFrom); mIvFlagFrom.setContentDescription(Utility.formatCountryFlagName(mContext, countryFromName)); Glide.with(getActivity()).load(data.getString(COL_COUNTRY_TO_FLAG)).error(R.drawable.globe).crossFade() .into(mIvFlagTo); mIvFlagFrom.setContentDescription(Utility.formatCountryFlagName(mContext, countryToName)); mTvCurrencyFromDesc.setText(currencyFromName); mTvCurrencyFromDesc.setContentDescription(currencyFromName); mTvCurrencyFromRate .setText(Utility.formatCurrencyRate(getActivity(), currencyFromSymbol, currencyFromRate)); mTvCurrencyFromRate.setContentDescription(String.valueOf(currencyFromRate) + " " + currencyFromName); mTvCurrencyToDesc.setText(currencyToName); mTvCurrencyToDesc.setContentDescription(currencyToName); mTvCurrencyToRate.setText(Utility.formatCurrencyRate(getActivity(), currencyToSymbol, currencyToRate)); mTvCurrencyToRate.setContentDescription(String.valueOf(currencyToRate) + " " + currencyToName); Time dayTime = new Time(); dayTime.setToNow(); int julianDate = Time.getJulianDay(System.currentTimeMillis(), dayTime.gmtoff); dayTime = new Time(); long lMinDate = dayTime.setJulianDay(julianDate - DEFAULT_DAYS_FOREX_AVERAGE); sDate = Utility.getDateString(getActivity(), data.getLong(COL_RATE_DATE)); for (i = 0; i < data.getCount() && i < DEFAULT_DAYS_FOREX_AVERAGE; i++) { data.moveToPosition(i); lDate = data.getLong(COL_RATE_DATE); if (lDate < lMinDate) { break; } sCurrency = data.getString(COL_CURRENCY_TO_ID); sDate = Utility.getDateString(getActivity(), lDate); dVal = data.getDouble(COL_RATE_VAL); dRateAverage += dVal; if (i == 0) { dMinVal = dVal; dMaxVal = dVal; } else { dMinVal = dMinVal < dVal ? dMinVal : dVal; dMaxVal = dMaxVal > dVal ? dMaxVal : dVal; } } dRateAverage = dRateAverage / i; if (data.getCount() > 1) mTvPeriod.setText(data.getCount() + " days"); else mTvPeriod.setText(data.getCount() + " day"); mTvMaxRate.setContentDescription(mTvPeriod.getText()); mTvMaxRate.setText( Utility.formatCurrencyRate(getActivity(), data.getString(COL_CURRENCY_TO_SYMBOL), dMaxVal)); mTvMaxRate.setContentDescription(mTvMaxRate.getText()); mTvMinRate.setText( Utility.formatCurrencyRate(getActivity(), data.getString(COL_CURRENCY_TO_SYMBOL), dMinVal)); mTvMinRate.setContentDescription(mTvMinRate.getText()); mTvAverageRate.setText( Utility.formatCurrencyRate(getActivity(), data.getString(COL_CURRENCY_TO_SYMBOL), dRateAverage)); mTvAverageRate.setContentDescription(mTvAverageRate.getText()); // String text to share if user clicks on share menu icon mDisplayedRate = String.format("%s - %s %s = %s %s", sDate, currencyFromRate, mCurrencyFromId, currencyToRate, mCurrencyToId); mDisplayedCurrencyIds = mCurrencyFromId + "-" + mCurrencyToId; mDisplayedCurrencyNames = currencyToName; mContext.supportStartPostponedEnterTransition(); if (null != mToolbar) { Menu menu = mToolbar.getMenu(); if (null != menu) menu.clear(); mToolbar.inflateMenu(R.menu.detailfragment); finishCreatingMenu(mToolbar.getMenu()); } }
From source file:com.ichi2.libanki.Stats.java
/** * Answer Buttons// w ww . j av a 2s. c o m */ public boolean calculateAnswerButtons(int type) { mHasColoredCumulative = true; mTitle = R.string.stats_answer_buttons; mAxisTitles = new int[] { R.string.stats_answer_type, R.string.stats_answers, R.string.stats_cumulative_correct_percentage }; mValueLabels = new int[] { R.string.statistics_learn, R.string.statistics_young, R.string.statistics_mature }; mColors = new int[] { R.color.stats_learn, R.color.stats_young, R.color.stats_mature }; mType = type; String lim = _revlogLimit().replaceAll("[\\[\\]]", ""); Vector<String> lims = new Vector<String>(); int days = 0; if (lim.length() > 0) lims.add(lim); if (type == TYPE_MONTH) days = 30; else if (type == TYPE_YEAR) days = 365; else days = -1; if (days > 0) lims.add("id > " + ((mCol.getSched().getDayCutoff() - (days * 86400)) * 1000)); if (lims.size() > 0) { lim = "where " + lims.get(0); for (int i = 1; i < lims.size(); i++) lim += " and " + lims.get(i); } else lim = ""; ArrayList<double[]> list = new ArrayList<double[]>(); Cursor cur = null; String query = "select (case " + " when type in (0,2) then 0 " + " when lastIvl < 21 then 1 " + " else 2 end) as thetype, " + " (case when type in (0,2) and ease = 4 then 3 else ease end), count() from revlog " + lim + " " + " group by thetype, ease " + " order by thetype, ease"; Timber.d("AnswerButtons query: %s", query); try { cur = mCol.getDb().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 AnswerButton, for now only copied from intervals // small adjustment for a proper chartbuilding with achartengine if (list.size() == 0) { list.add(0, new double[] { 0, 1, 0 }); } double[] totals = new double[3]; for (int i = 0; i < list.size(); i++) { double[] data = list.get(i); int currentType = (int) data[0]; double ease = data[1]; double cnt = data[2]; totals[currentType] += cnt; } int badNew = 0; int badYoung = 0; int badMature = 0; mSeriesList = new double[4][list.size() + 1]; for (int i = 0; i < list.size(); i++) { double[] data = list.get(i); int currentType = (int) data[0]; double ease = data[1]; double cnt = data[2]; if (currentType == 1) ease += 5; else if (currentType == 2) ease += 10; if ((int) ease == 1) { badNew = i; } if ((int) ease == 6) { badYoung = i; } if ((int) ease == 11) { badMature = i; } mSeriesList[0][i] = ease; mSeriesList[1 + currentType][i] = cnt; if (cnt > mMaxCards) mMaxCards = (int) cnt; } mSeriesList[0][list.size()] = 15; mCumulative = new double[4][]; mCumulative[0] = mSeriesList[0]; mCumulative[1] = createCumulativeInPercent(mSeriesList[1], totals[0], badNew); mCumulative[2] = createCumulativeInPercent(mSeriesList[2], totals[1], badYoung); mCumulative[3] = createCumulativeInPercent(mSeriesList[3], totals[2], badMature); mFirstElement = 0.5; mLastElement = 14.5; mMcount = 100; mMaxElements = 15; //bars are positioned from 1 to 14 if (mMaxCards == 0) mMaxCards = 10; return list.size() > 0; }