List of usage examples for android.database Cursor getDouble
double getDouble(int columnIndex);
From source file:com.money.manager.ex.reports.IncomeVsExpensesAdapter.java
@Override public void bindView(View view, Context context, Cursor cursor) { TextView txtYear = (TextView) view.findViewById(R.id.textViewYear); TextView txtMonth = (TextView) view.findViewById(R.id.textViewMonth); TextView txtIncome = (TextView) view.findViewById(R.id.textViewIncome); TextView txtExpenses = (TextView) view.findViewById(R.id.textViewExpenses); TextView txtDifference = (TextView) view.findViewById(R.id.textViewDifference); // take data/*from w ww . j av a 2 s. co m*/ int year, month; year = cursor.getInt(cursor.getColumnIndex(IncomeVsExpenseReportEntity.YEAR)); month = cursor.getInt(cursor.getColumnIndex(IncomeVsExpenseReportEntity.Month)); Calendar calendar = Calendar.getInstance(); calendar.set(year, month - 1, 1); double income = 0, expenses = 0; expenses = cursor.getDouble(cursor.getColumnIndex(IncomeVsExpenseReportEntity.Expenses)); income = cursor.getDouble(cursor.getColumnIndex(IncomeVsExpenseReportEntity.Income)); // attach data txtYear.setText(Integer.toString(year)); String formatMonth = context.getResources() .getConfiguration().orientation == Configuration.ORIENTATION_PORTRAIT ? "MMM" : "MMMM"; if (month != IncomeVsExpensesActivity.SUBTOTAL_MONTH) { txtMonth.setText(new SimpleDateFormat(formatMonth).format(calendar.getTime())); } else { txtMonth.setText(null); } CurrencyService currencyService = new CurrencyService(mContext); txtIncome.setText(currencyService.getCurrencyFormatted(currencyService.getBaseCurrencyId(), MoneyFactory.fromDouble(income))); txtExpenses.setText(currencyService.getCurrencyFormatted(currencyService.getBaseCurrencyId(), MoneyFactory.fromDouble(Math.abs(expenses)))); txtDifference.setText(currencyService.getCurrencyFormatted(currencyService.getBaseCurrencyId(), MoneyFactory.fromDouble(income - Math.abs(expenses)))); UIHelper uiHelper = new UIHelper(context); if (income - Math.abs(expenses) < 0) { txtDifference.setTextColor( context.getResources().getColor(uiHelper.resolveAttribute(R.attr.holo_red_color_theme))); } else { txtDifference.setTextColor( context.getResources().getColor(uiHelper.resolveAttribute(R.attr.holo_green_color_theme))); } //view.setBackgroundColor(core.resolveColorAttribute(cursor.getPosition() % 2 == 1 ? R.attr.row_dark_theme : R.attr.row_light_theme)); // check if subtotal int typefaceStyle = month == IncomeVsExpensesActivity.SUBTOTAL_MONTH ? Typeface.BOLD : Typeface.NORMAL; txtDifference.setTypeface(null, typefaceStyle); txtExpenses.setTypeface(null, typefaceStyle); txtIncome.setTypeface(null, typefaceStyle); txtMonth.setTypeface(null, typefaceStyle); txtYear.setTypeface(null, typefaceStyle); }
From source file:com.example.xiaoma.myapplication.model.DoHttpPostJson.java
/** * Post????Json?//from w w w . j a v a2s . co m * BMS1?2 */ @Override public void bmsrealtime(final Context context, final String url) { new Thread() { @Override public void run() { final String Url = url; Context mContext = context; myDBHelper = new MyDBOpenHelper(mContext, "db_ebike", null, 1); db = myDBHelper.getWritableDatabase(); /** * ??JsonJSONArray */ String licensenumber = ""; // SN? double max_vol = 0; // String max_vol_box = ""; // ? String max_vol_position = ""; // ? double min_vol = 0; // ? String min_vol_box = ""; // ?? String min_vol_position = ""; // ?? double max_temp = 0; // String max_temp_box = ""; // ? String max_temp_position = ""; // ? double min_temp = 0; // ? String min_temp_box = ""; // ?? String min_temp_position = ""; // ?? double max_difftemp = 0; // String max_difftemp_box = ""; // ? double sys_totalvol = 0; // double soc = 0; // SOC double soh = 0; // SOH double cell_cap_left = 0; // ? int max_puttime = 0; // double current_ele = 0; // ?? double remaining_power = 0; // ? double res_positive = 0; // ? double res_negative = 0; // ? double left_dis = 0; // double cell_vol = 0; // double cell_temp = 0; // ? String uploadtime = ""; JSONArray jsonArray = new JSONArray(); Cursor cursor = db.query("tb_bmsrealtime", null, null, null, null, null, null); if (cursor.moveToFirst()) { do { //int id = cursor.getInt(cursor.getColumnIndex("id")); licensenumber = cursor.getString(cursor.getColumnIndex("licensenumber")); max_vol = cursor.getDouble(cursor.getColumnIndex("max_vol")); max_vol_box = cursor.getString(cursor.getColumnIndex("max_vol_box")); max_vol_position = cursor.getString(cursor.getColumnIndex("max_vol_position")); min_vol = cursor.getDouble(cursor.getColumnIndex("min_vol")); min_vol_box = cursor.getString(cursor.getColumnIndex("min_vol_box")); min_vol_position = cursor.getString(cursor.getColumnIndex("min_vol_position")); max_temp = cursor.getDouble(cursor.getColumnIndex("max_temp")); max_temp_box = cursor.getString(cursor.getColumnIndex("max_temp_box")); max_temp_position = cursor.getString(cursor.getColumnIndex("max_temp_position")); min_temp = cursor.getDouble(cursor.getColumnIndex("min_temp")); min_temp_box = cursor.getString(cursor.getColumnIndex("min_temp_box")); min_temp_position = cursor.getString(cursor.getColumnIndex("min_temp_position")); max_difftemp = cursor.getDouble(cursor.getColumnIndex("max_difftemp")); max_difftemp_box = cursor.getString(cursor.getColumnIndex("max_difftemp_box")); sys_totalvol = cursor.getDouble(cursor.getColumnIndex("sys_totalvol")); soc = cursor.getDouble(cursor.getColumnIndex("soc")); soh = cursor.getDouble(cursor.getColumnIndex("soh")); cell_cap_left = cursor.getDouble(cursor.getColumnIndex("cell_cap_left")); max_puttime = cursor.getInt(cursor.getColumnIndex("max_puttime")); current_ele = cursor.getDouble(cursor.getColumnIndex("current_ele")); remaining_power = cursor.getDouble(cursor.getColumnIndex("remaining_power")); res_positive = cursor.getDouble(cursor.getColumnIndex("res_positive")); res_negative = cursor.getDouble(cursor.getColumnIndex("res_negative")); left_dis = cursor.getDouble(cursor.getColumnIndex("left_dis")); cell_vol = cursor.getDouble(cursor.getColumnIndex("cell_vol")); cell_temp = cursor.getDouble(cursor.getColumnIndex("cell_temp")); try { jsonArray.put(new JSONObject().put("licensenumber", licensenumber) .put("max_vol", max_vol).put("max_vol_box", max_vol_box) .put("max_vol_position", max_vol_position).put("min_vol", min_vol) .put("min_vol_box", min_vol_box).put("min_vol_position", min_vol_position) .put("max_temp", max_temp).put("max_temp_box", max_temp_box) .put("max_temp_position", max_temp_position).put("min_temp", min_temp) .put("min_temp_box", min_temp_box).put("min_temp_position", min_temp_position) .put("max_difftemp", max_difftemp).put("max_difftemp_box", max_difftemp_box) .put("sys_totalvol", sys_totalvol).put("soc", soc).put("soh", soh) .put("cell_cap_left", cell_cap_left).put("max_puttime", max_puttime) .put("current_ele", current_ele).put("remaining_power", remaining_power) .put("res_positive", res_positive).put("res_negative", res_negative) .put("left_dis", left_dis).put("cell_vol", cell_vol).put("cell_temp", cell_temp) .put("uploadtime", uploadtime)); } catch (JSONException e) { e.printStackTrace(); } } while (cursor.moveToNext()); } cursor.close(); String jsonString = jsonArray.toString(); // Post? List<NameValuePair> nameValuePairs = new ArrayList<>(); nameValuePairs.add(new BasicNameValuePair("data", jsonString)); try { //?HTTP HttpClient httpClient = new DefaultHttpClient(); HttpPost httpPost = new HttpPost(Url); httpPost.setEntity(new UrlEncodedFormEntity(nameValuePairs)); System.out.println("executing request " + httpPost.getURI()); HttpResponse httpResponse = httpClient.execute(httpPost); try { HttpEntity httpEntity = httpResponse.getEntity(); if (httpEntity != null) { System.out.println("--------------------------------------"); System.out.println("Response content: " + EntityUtils.toString(httpEntity, "UTF-8")); System.out.println("--------------------------------------"); } } finally { System.out.println("--------------------------------------"); } } catch (UnsupportedEncodingException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (ClientProtocolException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } } }.start(); }
From source file:net.niyonkuru.koodroid.ui.DataDetailFragment.java
private XYMultipleSeriesDataset getBarDataset(Cursor cursor, int x, int maxX) { XYMultipleSeriesDataset dataset = new XYMultipleSeriesDataset(); XYSeries series = new XYSeries(null); Calendar cal = Calendar.getInstance(); CalendarUtils.trimTimestamp(cal);// w ww . j a va 2 s. c o m if (cursor.isClosed() || !cursor.moveToFirst()) return null; while (x <= maxX) { double count = 0; if (!cursor.isAfterLast()) { /* cursor has data */ Date rowDate = new Date(cal.getTimeInMillis()); Date currDate = Date.valueOf(cursor.getString(UsagesQuery.DATE)); if (rowDate.equals(currDate)) { count = cursor.getDouble(UsagesQuery.COUNT); cursor.moveToNext(); } } cal.add(Calendar.DAY_OF_YEAR, -1); series.add(x++, count); } dataset.addSeries(series); return dataset; }
From source file:utils.database.sqlite.data.AFieldData.java
/** * /*www .ja v a 2s . c o m*/ * Create the object from cursor db. * * @param t * the table. * @param cursor */ public AFieldData(ITables t, Cursor cursor) { this.tab = t; IColumns[] values = t.getColumns(); if (cursor != null) { for (IColumns c : values) { String name = ((Enum) c).name(); if (c.getType().equals(ConstantsDB.INTEGER)) { integerValue.put(c, cursor.getInt(cursor.getColumnIndex(name))); } else if (c.getType().equals(ConstantsDB.TEXT)) { stringValue.put(c, cursor.getString(cursor.getColumnIndex(name))); } else if (c.getType().equals(ConstantsDB.REAL)) { doubleValue.put(c, cursor.getDouble(cursor.getColumnIndex(name))); } } } }
From source file:com.wildplot.android.ankistats.AnswerButton.java
public boolean calculateAnswerButtons(int type) { 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;/*ww w .j a v a 2 s .c om*/ String lim = _revlogLimitWholeOnly().replaceAll("[\\[\\]]", ""); String lims = ""; //TODO when non whole collection selection is possible test this! int days = 0; if (lim.length() > 0) lims += lim + " and "; if (type == Utils.TYPE_MONTH) days = 30; else if (type == Utils.TYPE_YEAR) days = 365; else days = -1; if (days > 0) lims += "id > " + ((mCollectionData.getDayCutoff() - (days * 86400)) * 1000); if (lims.length() > 0) lim = "where " + lims; 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"; try { cur = mAnkiDb.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.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 }); // } 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] = Utils.createCumulativeInPercent(mSeriesList[1], totals[0], badNew); mCumulative[2] = Utils.createCumulativeInPercent(mSeriesList[2], totals[1], badYoung); mCumulative[3] = Utils.createCumulativeInPercent(mSeriesList[3], totals[2], badMature); mMaxElements = 15; //bars are positioned from 1 to 14 return list.size() > 0; }
From source file:com.textuality.lifesaver.Columns.java
public JSONObject cursorToJSON(Cursor cursor) { setColumns(cursor);//from www. j a va2s . co m JSONObject json = new JSONObject(); try { for (int i = 0; i < names.length; i++) { int col = columns[i]; if (cursor.isNull(col)) continue; switch (types[i]) { case STRING: json.put(names[i], cursor.getString(col)); break; case INT: json.put(names[i], cursor.getInt(col)); break; case LONG: json.put(names[i], cursor.getLong(col)); break; case FLOAT: json.put(names[i], cursor.getFloat(col)); break; case DOUBLE: json.put(names[i], cursor.getDouble(col)); break; } } } catch (JSONException e) { throw new RuntimeException(e); } return json; }
From source file:org.openbmap.activities.WifiDetailsMap.java
@Override public final void onLoadFinished(final Loader<Cursor> loader, final Cursor cursor) { if (cursor != null && cursor.getCount() > 0) { final int colLat = cursor.getColumnIndex("begin_" + Schema.COL_LATITUDE); final int colLon = cursor.getColumnIndex("begin_" + Schema.COL_LONGITUDE); final int colLevel = cursor.getColumnIndex(Schema.COL_LEVEL); while (cursor.moveToNext()) { //int intensity = (int) (cursor.getInt(colLevel) / -10); final int intensity = cursor.getInt(colLevel) / -50; points.add(new HeatLatLong(cursor.getDouble(colLat), cursor.getDouble(colLon), intensity)); }/* www.j a v a 2 s .com*/ if (points.size() > 0) { mMapView.getModel().mapViewPosition.setCenter(points.get(points.size() - 1)); } pointsLoaded = true; proceedAfterHeatmapCompleted(); } }
From source file:com.example.puter.sunshine.app.DetailFragment.java
@Override public void onLoadFinished(Loader<Cursor> loader, Cursor data) { if (data != null && data.moveToFirst()) { int weatherId = data.getInt(COL_WEATHER_CONDITION_ID); mIconView.setImageResource(Utility.getArtResourceForWeatherCondition(weatherId)); 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 . co m*/ String description = data.getString(COL_WEATHER_DESC); mDescriptionView.setText(description); mIconView.setContentDescription(description); boolean isMetric = Utility.isMetric(getActivity()); double high = data.getDouble(COL_WEATHER_MAX_TEMP); String highString = Utility.formatTemperature(getActivity(), high); mHighTempView.setText(highString); double low = data.getDouble(COL_WEATHER_MIN_TEMP); String lowString = Utility.formatTemperature(getActivity(), low); mLowTempView.setText(lowString); float humidity = data.getFloat(COL_WEATHER_HUMIDITY); mHumidityView.setText(getActivity().getString(R.string.format_humidity, humidity)); float windSpeedStr = data.getFloat(COL_WEATHER_WIND_SPEED); float windDirStr = data.getFloat(COL_WEATHER_DEGREES); mWindView.setText(Utility.getFormattedWind(getActivity(), windSpeedStr, windDirStr)); float pressure = data.getFloat(COL_WEATHER_PRESSURE); mPressureView.setText(getActivity().getString(R.string.format_pressure, pressure)); mForecast = String.format("%s - %s - %s/%s", dateText, description, high, low); if (mShareActionProvider != null) { mShareActionProvider.setShareIntent(createShareForecastIntent()); } } }
From source file:gov.wa.wsdot.android.wsdot.ui.HighwayAlertDetailsActivity.java
@SuppressLint("SetJavaScriptEnabled") @Override//from www. ja v a 2 s .co m protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); resolver = getContentResolver(); Cursor cursor = null; HighwayAlertsItem alertItem = null; title = ""; description = ""; String[] projection = { HighwayAlerts.HIGHWAY_ALERT_ID, HighwayAlerts.HIGHWAY_ALERT_LATITUDE, HighwayAlerts.HIGHWAY_ALERT_LONGITUDE, HighwayAlerts.HIGHWAY_ALERT_CATEGORY, HighwayAlerts.HIGHWAY_ALERT_HEADLINE, HighwayAlerts.HIGHWAY_ALERT_PRIORITY, HighwayAlerts.HIGHWAY_ALERT_LAST_UPDATED }; Bundle b = getIntent().getExtras(); String id = b.getString("id"); try { cursor = resolver.query(HighwayAlerts.CONTENT_URI, projection, HighwayAlerts.HIGHWAY_ALERT_ID + "=?", new String[] { id }, null); if (cursor != null && cursor.moveToFirst()) { alertItem = new HighwayAlertsItem(cursor.getDouble(1), cursor.getDouble(2), cursor.getString(3), cursor.getString(4), cursor.getString(6)); } else { alertItem = new HighwayAlertsItem(); alertItem.setEventCategory("ERROR"); alertItem.setHeadlineDescription("Whoops. Something happened trying to access the highway alert."); alertItem.setLastUpdatedTime(dateFormat.format(new Date())); } } finally { if (cursor != null) { cursor.close(); } } title = "Highway Alert - " + alertItem.getEventCategory(); description = alertItem.getHeadlineDescription(); getSupportActionBar().setDisplayHomeAsUpEnabled(true); getSupportActionBar().setTitle(title); setContentView(R.layout.fragment_webview_with_spinner); mLoadingSpinner = findViewById(R.id.loading_spinner); mLoadingSpinner.setVisibility(View.VISIBLE); webview = (WebView) findViewById(R.id.webview); webview.setWebViewClient(new myWebViewClient()); webview.getSettings().setJavaScriptEnabled(true); webview.loadDataWithBaseURL(null, buildContent(alertItem), "text/html", "utf-8", null); }
From source file:us.dustinj.locationstore.io.LocationExporter.java
private JSONArray getJSON(Cursor queryCursor) { JSONArray locations = new JSONArray(); try {// w w w.j ava 2s .com while (!queryCursor.isAfterLast()) { JSONObject location = new JSONObject(); HashMap<String, DatabaseField> databaseFields = LocationDatabase.GetColumnDefinitions(); for (int columnIndex = 0; columnIndex < queryCursor.getColumnCount(); columnIndex++) { DatabaseField currentField = databaseFields.get(queryCursor.getColumnName(columnIndex)); if (currentField.Type.equals("TEXT")) { location.put(queryCursor.getColumnName(columnIndex), queryCursor.getString(columnIndex)); } else if (currentField.Type.equals("REAL")) { location.put(queryCursor.getColumnName(columnIndex), queryCursor.getDouble(columnIndex)); } else if (currentField.Type.equals("INTEGER")) { location.put(queryCursor.getColumnName(columnIndex), queryCursor.getInt(columnIndex)); } else { Log.e(this.getClass().getSimpleName(), "Read unsupported type from the database"); } } queryCursor.moveToNext(); locations.put(location); } } catch (JSONException e) { // TODO Auto-generated catch block e.printStackTrace(); } return locations; }