List of usage examples for android.database Cursor getDouble
double getDouble(int columnIndex);
From source file:com.jackie.sunshine.app.ForecastAdapter.java
@Override public void bindView(View view, Context context, Cursor cursor) { ViewHolder viewHolder = (ViewHolder) view.getTag(); // Read weather icon ID from cursor int weatherId = cursor.getInt(ForecastFragment.COL_WEATHER_CONDITION_ID); // Use placeholder image for now @DrawableRes//from www. j a v a2 s . c o m int iconRes = R.drawable.art_clear; switch (getItemViewType(cursor.getPosition())) { case VIEW_TYPE_TODAY: iconRes = Utility.getArtResourceForWeatherCondition(weatherId); break; case VIEW_TYPE_FUTURE_DAY: iconRes = Utility.getIconResourceForWeatherCondition(weatherId); break; } viewHolder.iconView.setImageResource(iconRes); // Read date from cursor long dataInMillis = cursor.getLong(ForecastFragment.COL_WEATHER_DATE); // Find TextView and set formatted date on it viewHolder.dateView.setText(Utility.getFriendlyDayString(context, dataInMillis)); // Read weather forecast from cursor String description = cursor.getString(ForecastFragment.COL_WEATHER_DESC); // Find TextView and set weather forecast on it viewHolder.descriptionView.setText(description); viewHolder.iconView.setContentDescription(description); // Read user preference for metric or imperial temperature units boolean isMetric = Utility.isMetric(context); // Read high temperature from cursor double high = cursor.getDouble(ForecastFragment.COL_WEATHER_MAX_TEMP); viewHolder.highView.setText(Utility.formatTemperature(context, high)); // Read low temperature from cursor double low = cursor.getDouble(ForecastFragment.COL_WEATHER_MIN_TEMP); viewHolder.lowView.setText(Utility.formatTemperature(context, low)); }
From source file:com.example.xiaoma.myapplication.model.DoHttpPostJson.java
/** * Post????Json?// ww w .ja v a 2 s.co m * 1 */ @Override public void carrealtime(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? int speed = 0; // int drive_dis_today = 0; // int drive_dis_total = 0; // int drive_time_today = 0; // int drive_time_total = 0; // int ischarge = 0; // ? int islock = 0; // ?? String gps = ""; // GPS?? double air_quality = 0; // ? String uploadtime = ""; JSONArray jsonArray = new JSONArray(); Cursor cursor = db.query("tb_carrealtime", null, null, null, null, null, null); if (cursor.moveToFirst()) { do { //int id = cursor.getInt(cursor.getColumnIndex("id")); licensenumber = cursor.getString(cursor.getColumnIndex("licensenumber")); speed = cursor.getInt(cursor.getColumnIndex("speed")); drive_dis_today = cursor.getInt(cursor.getColumnIndex("drive_dis_today")); drive_dis_total = cursor.getInt(cursor.getColumnIndex("drive_dis_total")); drive_time_today = cursor.getInt(cursor.getColumnIndex("drive_time_today")); drive_time_total = cursor.getInt(cursor.getColumnIndex("drive_time_total")); ischarge = cursor.getInt(cursor.getColumnIndex("ischarge")); islock = cursor.getInt(cursor.getColumnIndex("islock")); gps = cursor.getString(cursor.getColumnIndex("gps")); air_quality = cursor.getDouble(cursor.getColumnIndex("air_quality")); try { jsonArray.put(new JSONObject().put("licensenumber", licensenumber).put("speed", speed) .put("drive_dis_today", drive_dis_today).put("drive_dis_total", drive_dis_total) .put("drive_time_today", drive_time_today) .put("drive_time_total", drive_time_total).put("ischarge", ischarge) .put("islock", islock).put("gps", gps).put("air_quality", air_quality) .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:com.sagar.sunshine.DetailFragment.java
@Override public void onLoadFinished(Loader<Cursor> loader, Cursor data) { if (data != null && data.moveToFirst()) { ViewParent vp = getView().getParent(); if (vp instanceof CardView) { ((View) vp).setVisibility(View.VISIBLE); }/*from w w w .j a v a2 s. c om*/ int weatherId = data.getInt(COL_WEATHER_CONDITION_ID); if (Utility.usingLocalGraphics(getActivity())) { mIconView.setImageResource(Utility.getArtResourceForWeatherCondition(weatherId)); } else { Glide.with(this).load(Utility.getArtUrlForWeatherCondition(getActivity(), weatherId)) .error(Utility.getArtResourceForWeatherCondition(weatherId)).crossFade().into(mIconView); } long date = data.getLong(COL_WEATHER_DATE); String dateText = Utility.getFullFriendlyDayString(getActivity(), date); mDateView.setText(dateText); String description = Utility.getStringForWeatherCondition(getActivity(), weatherId); mDescriptionView.setText(description); mDescriptionView.setContentDescription(getString(R.string.a11y_forecast, description)); mIconView.setContentDescription(getString(R.string.a11y_forecast_icon, description)); boolean isMetric = Utility.isMetric(getActivity()); double high = data.getDouble(COL_WEATHER_MAX_TEMP); String highString = Utility.formatTemperature(getActivity(), high); mHighTempView.setText(highString); mHighTempView.setContentDescription(getString(R.string.a11y_high_temp, highString)); double low = data.getDouble(COL_WEATHER_MIN_TEMP); String lowString = Utility.formatTemperature(getActivity(), low); mLowTempView.setText(lowString); mLowTempView.setContentDescription(getString(R.string.a11y_low_temp, lowString)); float humidity = data.getFloat(COL_WEATHER_HUMIDITY); mHumidityView.setText(getActivity().getString(R.string.format_humidity, humidity)); mHumidityView.setContentDescription(getString(R.string.a11y_humidity, mHumidityView.getText())); mHumidityLabelView.setContentDescription(mHumidityView.getContentDescription()); float windSpeedStr = data.getFloat(COL_WEATHER_WIND_SPEED); float windDirStr = data.getFloat(COL_WEATHER_DEGREES); mWindView.setText(Utility.getFormattedWind(getActivity(), windSpeedStr, windDirStr)); mWindView.setContentDescription(getString(R.string.a11y_wind, mWindView.getText())); mWindLabelView.setContentDescription(mWindView.getContentDescription()); float pressure = data.getFloat(COL_WEATHER_PRESSURE); mPressureView.setText(getString(R.string.format_pressure, pressure)); mPressureView.setContentDescription(getString(R.string.a11y_pressure, mPressureView.getText())); mPressureLabelView.setContentDescription(mPressureView.getContentDescription()); mForecast = String.format("%s - %s - %s/%s", dateText, description, high, low); } AppCompatActivity activity = (AppCompatActivity) getActivity(); Toolbar toolbarView = (Toolbar) getView().findViewById(R.id.toolbar); if (mTransitionAnimation) { activity.supportStartPostponedEnterTransition(); if (null != toolbarView) { activity.setSupportActionBar(toolbarView); activity.getSupportActionBar().setDisplayShowTitleEnabled(false); activity.getSupportActionBar().setDisplayHomeAsUpEnabled(true); } } else { if (null != toolbarView) { Menu menu = toolbarView.getMenu(); if (null != menu) menu.clear(); toolbarView.inflateMenu(R.menu.detailfragment); finishCreatingMenu(toolbarView.getMenu()); } } }
From source file:com.goliathonline.android.kegbot.ui.WhatsOnFragment.java
private void onTapQueryComplete(Cursor cursor) { if (cursor == null) return;//w ww . j a va2 s. c om else if (cursor.getCount() == 0) return; final LayoutInflater inflater = getActivity().getLayoutInflater(); final View onTapView = inflater.inflate(R.layout.whats_on_tap, mRootView, false); final TextView onTapTitleView = (TextView) onTapView.findViewById(R.id.on_tap); final TextView onTapSubTitleView = (TextView) onTapView.findViewById(R.id.whats_on_subtitle); final ProgressBar kegProgress = (ProgressBar) onTapView.findViewById(R.id.kegProgress); final ImageView tapImage = (ImageView) onTapView.findViewById(R.id.tap_image); final TextView degreesText = (TextView) onTapView.findViewById(R.id.temperature); cursor.moveToFirst(); final String tapImageUrl = cursor.getString(TapsQuery.IMAGE_URL); if (!TextUtils.isEmpty(tapImageUrl)) { BitmapUtils.fetchImage(getActivity(), tapImageUrl, null, null, new BitmapUtils.OnFetchCompleteListener() { public void onFetchComplete(Object cookie, Bitmap result) { if (result != null) { tapImage.setImageBitmap(result); } } }); } onTapTitleView.setText(cursor.getString(TapsQuery.BEER_NAME)); final Double mlRemain = cursor.getDouble(TapsQuery.VOL_REMAIN); final String pintsRemain = UnitUtils.mlToPint(Double.toString(mlRemain)); final Double mlTotal = cursor.getDouble(TapsQuery.VOL_SIZE); final Double mlPoured = mlTotal - mlRemain; final String pintsPoured = UnitUtils.mlToPint(Double.toString(mlPoured)); final Double lastTemp = cursor.getDouble(TapsQuery.LAST_TEMP); final String temperature = UnitUtils.cToF(Double.toString(lastTemp)); onTapSubTitleView.setText("Pints Poured: " + pintsPoured + " (" + pintsRemain + " remain)"); kegProgress.setProgressDrawable(getResources().getDrawable(R.drawable.progress)); kegProgress.setProgress((int) cursor.getDouble(TapsQuery.PERCENT_FULL)); degreesText.setText(temperature + DEGREES); cursor.close(); mRootView.addView(onTapView); }
From source file:com.spoiledmilk.ibikecph.util.DB.java
public ArrayList<FavoritesData> getFavorites(ArrayList<FavoritesData> ret) { if (ret == null) { ret = new ArrayList<FavoritesData>(); } else {//from w w w .ja v a 2 s . c o m ret.clear(); } SQLiteDatabase db = getReadableDatabase(); if (db == null) { return null; } String[] columns = { KEY_ID, KEY_NAME, KEY_ADDRESS, KEY_SOURCE, KEY_SUBSOURCE, KEY_LAT, KEY_LONG, KEY_API_ID }; Cursor cursor = db.query(TABLE_FAVORITES, columns, null, null, null, null, null, null); if (cursor != null && cursor.moveToFirst()) { while (cursor != null && !cursor.isAfterLast()) { int colId = cursor.getColumnIndex(KEY_ID); int colName = cursor.getColumnIndex(KEY_NAME); int colAddress = cursor.getColumnIndex(KEY_ADDRESS); int colSubSource = cursor.getColumnIndex(KEY_SUBSOURCE); int colLat = cursor.getColumnIndex(KEY_LAT); int colLong = cursor.getColumnIndex(KEY_LONG); int colApiId = cursor.getColumnIndex(KEY_API_ID); FavoritesData fd = new FavoritesData(cursor.getInt(colId), cursor.getString(colName), cursor.getString(colAddress), cursor.getString(colSubSource), cursor.getDouble(colLat), cursor.getDouble(colLong), cursor.getInt(colApiId)); ret.add(fd); cursor.moveToNext(); } } if (cursor != null) { cursor.close(); } db.close(); LOG.d("favourites count from DB = " + ret.size()); return ret; }
From source file:com.example.android.pharmacyinventory.EditorActivity.java
@Override public void onLoadFinished(Loader<Cursor> loader, final Cursor cursor) { // Bail early if the cursor is null or there is less than 1 row in the cursor if (cursor == null || cursor.getCount() < 1) { return;//from w ww . jav a 2s. c o m } // Proceed with moving to the first row of the cursor and reading data from it // (This should be the only row in the cursor) if (cursor.moveToFirst()) { // Find the columns of drug attributes that we're interested in int nameColumnIndex = cursor.getColumnIndex(DrugContract.DrugEntry.COLUMN_DRUG_NAME); int quantityColumnIndex = cursor.getColumnIndex(DrugContract.DrugEntry.COLUMN_DRUG_QUANTITY); int priceColumnIndex = cursor.getColumnIndex(DrugContract.DrugEntry.COLUMN_DRUG_PRICE); int imageColumnIndex = cursor.getColumnIndex(DrugContract.DrugEntry.COLUMN_DRUG_IMAGE); // Extract out the value from the Cursor for the given column index String name = cursor.getString(nameColumnIndex); int quantity = cursor.getInt(quantityColumnIndex); Double price = cursor.getDouble(priceColumnIndex); String picture = cursor.getString(imageColumnIndex); // Update the views on the screen with the values from the database mNameEditText.setText(name); mQuantityText.setText(Integer.toString(quantity)); mPriceEditText.setText(Double.toString(price)); mDrugImage.setImageURI(Uri.parse(picture)); } orderButton.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { // Get the Uri for the current drug int IdColumnIndex = cursor.getColumnIndex(DrugContract.DrugEntry._ID); final long itemId = cursor.getLong(IdColumnIndex); Uri mCurrentDrugUri = ContentUris.withAppendedId(DrugContract.DrugEntry.CONTENT_URI, itemId); // Find the columns of drug attributes that we're interested in int nameColumnIndex = cursor.getColumnIndex(DrugContract.DrugEntry.COLUMN_DRUG_NAME); // Read the Drug attributes from the Cursor for the current drug String name = cursor.getString(nameColumnIndex); // Read the drug name to use in subject line String subjectLine = "Need to order: " + name; Intent intent = new Intent(Intent.ACTION_SENDTO); intent.setData(Uri.parse("mailto:")); // only email apps should handle this intent.putExtra(Intent.EXTRA_EMAIL, "orders@gmail.com"); intent.putExtra(Intent.EXTRA_SUBJECT, subjectLine); if (intent.resolveActivity(getPackageManager()) != null) { startActivity(intent); } } }); }
From source file:com.spoiledmilk.ibikecph.util.DB.java
public ArrayList<SearchListItem> getFavorites2() { ArrayList<SearchListItem> ret = new ArrayList<SearchListItem>(); SQLiteDatabase db = getReadableDatabase(); if (db == null) return null; String[] columns = { KEY_ID, KEY_NAME, KEY_ADDRESS, KEY_SOURCE, KEY_SUBSOURCE, KEY_LAT, KEY_LONG, KEY_API_ID };//from w w w. ja va 2 s.c o m Cursor cursor = db.query(TABLE_FAVORITES, columns, null, null, null, null, null, null); if (cursor != null && cursor.moveToFirst()) { while (cursor != null && !cursor.isAfterLast()) { int colId = cursor.getColumnIndex(KEY_ID); int colName = cursor.getColumnIndex(KEY_NAME); int colAddress = cursor.getColumnIndex(KEY_ADDRESS); int colSubSource = cursor.getColumnIndex(KEY_SUBSOURCE); int colLat = cursor.getColumnIndex(KEY_LAT); int colLong = cursor.getColumnIndex(KEY_LONG); int colApiId = cursor.getColumnIndex(KEY_API_ID); FavoritesData fd = new FavoritesData(cursor.getInt(colId), cursor.getString(colName), cursor.getString(colAddress), cursor.getString(colSubSource), cursor.getDouble(colLat), cursor.getDouble(colLong), cursor.getInt(colApiId)); ret.add((SearchListItem) fd); cursor.moveToNext(); } } if (cursor != null) cursor.close(); db.close(); return ret; }
From source file:com.nonninz.robomodel.RoboModel.java
private void loadField(Field field, Cursor query) throws DatabaseNotUpToDateException { final Class<?> type = field.getType(); final boolean wasAccessible = field.isAccessible(); final int columnIndex = query.getColumnIndex(field.getName()); field.setAccessible(true);//from w ww . j a v a2s. co m /* * TODO: There is the potential of a problem here: * What happens if the developer changes the type of a field between releases? * * If he saves first, then the column type will be changed (In the future). * If he loads first, we don't know if an Exception will be thrown if the * types are incompatible, because it's undocumented in the Cursor documentation. */ try { if (type == String.class) { field.set(this, query.getString(columnIndex)); } else if (type == Boolean.TYPE) { final boolean value = query.getInt(columnIndex) == 1 ? true : false; field.setBoolean(this, value); } else if (type == Byte.TYPE) { field.setByte(this, (byte) query.getShort(columnIndex)); } else if (type == Double.TYPE) { field.setDouble(this, query.getDouble(columnIndex)); } else if (type == Float.TYPE) { field.setFloat(this, query.getFloat(columnIndex)); } else if (type == Integer.TYPE) { field.setInt(this, query.getInt(columnIndex)); } else if (type == Long.TYPE) { field.setLong(this, query.getLong(columnIndex)); } else if (type == Short.TYPE) { field.setShort(this, query.getShort(columnIndex)); } else if (type.isEnum()) { final String string = query.getString(columnIndex); if (string != null && string.length() > 0) { final Object[] constants = type.getEnumConstants(); final Method method = type.getMethod("valueOf", Class.class, String.class); final Object value = method.invoke(constants[0], type, string); field.set(this, value); } } else { // Try to de-json it (db column must be of type text) try { final Object value = mMapper.readValue(query.getString(columnIndex), field.getType()); field.set(this, value); } catch (final Exception e) { final String msg = String.format("Type %s is not supported for field %s", type, field.getName()); Ln.w(e, msg); throw new IllegalArgumentException(msg); } } } catch (final IllegalAccessException e) { final String msg = String.format("Field %s is not accessible", type, field.getName()); throw new IllegalArgumentException(msg); } catch (final NoSuchMethodException e) { // Should not happen throw new RuntimeException(e); } catch (final InvocationTargetException e) { // Should not happen throw new RuntimeException(e); } catch (IllegalStateException e) { // This is when there is no column in db, but there is in the model throw new DatabaseNotUpToDateException(e); } finally { field.setAccessible(wasAccessible); } }
From source file:nintao.com.android.study.sunshine.ForecastAdapter.java
@Override public void bindView(View view, Context context, Cursor cursor) { // our view is pretty simple here --- just a text view // we'll keep the UI functional with a simple (and slow!) binding. // removed when the list item is updated. // TextView tv = (TextView)view; // tv.setText(convertCursorRowToUXFormat(cursor)); //fetch the weather id from cursor // int weatherId = cursor.getInt(COL_WEATHER_ID); //get viewTag ViewHolder viewHolder = (ViewHolder) view.getTag(); //read image icon viewHolder.iconView.setImageResource(R.drawable.ic_launcher); //read date from cursor long date = cursor.getLong(COL_WEATHER_DATE); // TextView dateView = (TextView) view.findViewById(R.id.list_item_day_textview); // dateView.setText(Utility.getFriendlyDayString(context, date)); viewHolder.dateView.setText(Utility.getFriendlyDayString(context, date)); //read weather description String description = cursor.getString(COL_WEATHER_DESC); // TextView descriptionView = (TextView) view.findViewById(R.id.list_item_forecast_textview); // descriptionView.setText(description); viewHolder.descriptionView.setText(description); // Read user preference for metric or imperial temperature units boolean isMetric = Utility.isMetric(context); //read high temp double high = cursor.getDouble(COL_WEATHER_MAX_TEMP); //TextView highView = (TextView) view.findViewById(R.id.list_item_forecast_high_textview); // highVieww.setText(Utility.formatTemperature(high, isMetric)); viewHolder.highTempView.setText(Utility.formatTemperature(mContext, high, isMetric)); //read low temp double low = cursor.getDouble(COL_WEATHER_MIN_TEMP); // TextView lowView = (TextView) view.findViewById(R.id.list_item_forecast_low_textview); // lowView.setText(Utility.formatTemperature(low, isMetric)); viewHolder.lowTempView.setText(Utility.formatTemperature(mContext, low, isMetric)); }
From source file:com.robotoworks.mechanoid.db.SQuery.java
public double[] selectDoubleArray(Uri uri, String column, String orderBy) { Cursor cursor = null; try {/* ww w. j a v a 2 s . c o m*/ cursor = select(uri, new String[] { column }, orderBy, false); double[] array = new double[cursor.getCount()]; for (int i = 0; i < cursor.getCount(); i++) { cursor.moveToNext(); array[i] = cursor.getDouble(0); } return array; } finally { Closeables.closeSilently(cursor); } }