List of usage examples for android.database Cursor getDouble
double getDouble(int columnIndex);
From source file:com.money.manager.ex.home.DashboardFragment.java
private void showChartIncomeVsExpensesCurrentMonth(Cursor cursor) { // move to first if (!cursor.moveToFirst()) return;// w w w .j av a 2 s .c om // arrays double[] incomes = new double[3]; double[] expenses = new double[3]; String[] titles = new String[3]; // incomes and expenses incomes[1] = cursor.getDouble(cursor.getColumnIndex(IncomeVsExpenseReportEntity.Income)); expenses[1] = Math.abs(cursor.getDouble(cursor.getColumnIndex(IncomeVsExpenseReportEntity.Expenses))); // titles int year = cursor.getInt(cursor.getColumnIndex(IncomeVsExpenseReportEntity.YEAR)); int month = cursor.getInt(cursor.getColumnIndex(IncomeVsExpenseReportEntity.Month)); // format month // Calendar calendar = Calendar.getInstance(); // calendar.set(year, month - 1, 1); MmxDate dateTime = new MmxDate(year, month - 1, 1); // titles // titles[1] = Integer.toString(year) + "-" + new SimpleDateFormat("MMM").format(calendar.getTime()); titles[1] = Integer.toString(year) + "-" + dateTime.toString("MMM"); // compose bundle for arguments Bundle args = new Bundle(); args.putDoubleArray(IncomeVsExpensesChartFragment.KEY_EXPENSES_VALUES, expenses); args.putDoubleArray(IncomeVsExpensesChartFragment.KEY_INCOME_VALUES, incomes); args.putStringArray(IncomeVsExpensesChartFragment.KEY_XTITLES, titles); args.putString(IncomeVsExpensesChartFragment.KEY_TITLE, getString(R.string.income_vs_expenses_current_month)); args.putBoolean(IncomeVsExpensesChartFragment.KEY_DISPLAY_AS_UP_ENABLED, false); // get fragment manager FragmentManager fragmentManager = getChildFragmentManager(); if (fragmentManager != null) { IncomeVsExpensesChartFragment fragment; fragment = new IncomeVsExpensesChartFragment(); fragment.setChartArguments(args); if (fragment.isVisible()) fragment.onResume(); FragmentTransaction fragmentTransaction = fragmentManager.beginTransaction(); fragmentTransaction.replace(R.id.linearLayoutScreen1, fragment, IncomeVsExpensesChartFragment.class.getSimpleName()); fragmentTransaction.commit(); } }
From source file:com.rappsantiago.weighttracker.profile.ProfileFragment.java
@Override public void onLoadFinished(Loader<Cursor> loader, Cursor data) { int id = loader.getId(); switch (id) { case LOAD_PROFILE: if (null != data && (0 < data.getCount()) && data.moveToFirst()) { String name = data.getString(DbConstants.IDX_PROFILE_NAME); long birthdayInMillis = data.getLong(DbConstants.IDX_PROFILE_BIRTHDAY); String gender = data.getString(DbConstants.IDX_PROFILE_GENDER); double height = data.getDouble(DbConstants.IDX_PROFILE_HEIGHT); mLblName.setText(name);//from w w w . j av a 2 s . co m mLblBirthday.setText(DisplayUtil.getReadableDateNoYear(birthdayInMillis)); mLblGender.setText(DisplayUtil.getReadableGender(getContext(), gender)); mLblHeight.setText(DisplayUtil.getFormattedHeight(getContext(), height, null)); getLoaderManager().restartLoader(LOAD_GOAL, null, this); } break; case LOAD_GOAL: if (null != data && (0 < data.getCount()) && data.moveToFirst()) { double targetWeight = data.getDouble(DbConstants.IDX_GOAL_TARGET_WEIGHT); double targetBodyFatIndex = data.getDouble(DbConstants.IDX_GOAL_TARGET_BODY_FAT_INDEX); long dueDateInMillis = data.getLong(DbConstants.IDX_GOAL_DUE_DATE); mLblTargetWeight.setText(DisplayUtil.getFormattedWeight(getContext(), targetWeight, null)); if (0 < targetBodyFatIndex) { mLblTargetBodyFatIndex.setText(String.format("%.2f%%", targetBodyFatIndex)); mShowRemainingBfi = true; } else { mLblTargetBodyFatIndex.setText(R.string.not_applicable); } if (0 < dueDateInMillis) { mLblDueDate.setText(DisplayUtil.getReadableDate(dueDateInMillis)); } else { mLblDueDate.setText(R.string.not_applicable); } getLoaderManager().restartLoader(LOAD_WEIGHT_PROGRESS, null, this); } break; case LOAD_WEIGHT_PROGRESS: if (null != data && (0 < data.getCount()) && data.moveToFirst()) { double intialWeight = data.getDouble(WeightProgressCursorLoader.IDX_WEIGHT_PROGRESS_INITIAL_WEIGHT); double currentWeight = data .getDouble(WeightProgressCursorLoader.IDX_WEIGHT_PROGRESS_CURRENT_WEIGHT); double percentComplete = data .getDouble(WeightProgressCursorLoader.IDX_WEIGHT_PROGRESS_PERCENT_COMPLETE); double remainingWeight = data .getDouble(WeightProgressCursorLoader.IDX_WEIGHT_PROGRESS_REMAINING_WEIGHT); double weightLost = data.getDouble(WeightProgressCursorLoader.IDX_WEIGHT_PROGRESS_LOST); double initialBodyFatIndex = data .getDouble(WeightProgressCursorLoader.IDX_WEIGHT_PROGRESS_INITIAL_BODY_FAT_INDEX); double currentBodyFatIndex = data .getDouble(WeightProgressCursorLoader.IDX_WEIGHT_PROGRESS_CURRENT_BODY_FAT_INDEX); double remainingBodyFatIndex = data .getDouble(WeightProgressCursorLoader.IDX_WEIGHT_PROGRESS_REMAINING_BODY_FAT_INDEX); double currentFatMass = data .getDouble(WeightProgressCursorLoader.IDX_WEIGHT_PROGRESS_CURRENT_FAT_MASS); double currentMuscleMass = data .getDouble(WeightProgressCursorLoader.IDX_WEIGHT_PROGRESS_CURRENT_MUSCLE_MASS); mLblInitialWeight.setText(DisplayUtil.getFormattedWeight(getActivity(), intialWeight, null)); mLblCurrentWeight.setText(DisplayUtil.getFormattedWeight(getActivity(), currentWeight, null)); mLblStatus.setText(getString(R.string.percent_complete_format, percentComplete * 100.0)); mLblRemaining.setText(DisplayUtil.getFormattedWeight(getActivity(), remainingWeight, null)); mLblWeightLost.setText(DisplayUtil.getWeightString(getActivity(), weightLost, null)); mLblWeightLostWeightUnit.setText(DisplayUtil.getWeightUnitString(getActivity(), null)); mLblInitialBodyFatIndex.setText(String.format("%.2f%%", initialBodyFatIndex)); mLblCurrentBodyFatIndex.setText(String.format("%.2f%%", currentBodyFatIndex)); if (mShowRemainingBfi) { mLblRemainingBodyFatIndex.setText(String.format("%.2f%%", remainingBodyFatIndex)); } else { mLblRemainingBodyFatIndex.setText(R.string.not_applicable); } mShowRemainingBfi = false; mLblCurrentFatMass.setText(DisplayUtil.getFormattedWeight(getActivity(), currentFatMass, null)); mLblCurrentMuscleMass .setText(DisplayUtil.getFormattedWeight(getActivity(), currentMuscleMass, null)); } break; default: throw new IllegalArgumentException(); } }
From source file:org.runnerup.export.format.RunKeeper.java
private void exportPath(String name, long activityId, long startTime, JsonWriter w) throws IOException { String[] pColumns = { DB.LOCATION.TIME, DB.LOCATION.LATITUDE, DB.LOCATION.LONGITUDE, DB.LOCATION.ALTITUDE, DB.LOCATION.TYPE };/*from www.j a va 2s. c o m*/ Cursor cursor = mDB.query(DB.LOCATION.TABLE, pColumns, DB.LOCATION.ACTIVITY + " = " + activityId, null, null, null, null); if (cursor.moveToFirst()) { w.name(name); w.beginArray(); startTime = cursor.getLong(0); do { w.beginObject(); w.name("timestamp").value((cursor.getLong(0) - startTime) / 1000); w.name("latitude").value(cursor.getDouble(1)); w.name("longitude").value(cursor.getDouble(2)); if (!cursor.isNull(3)) { w.name("altitude").value(cursor.getDouble(3)); } if (cursor.getLong(4) == DB.LOCATION.TYPE_START) { w.name("type").value("start"); } else if (cursor.getLong(4) == DB.LOCATION.TYPE_END) { w.name("type").value("end"); } else if (cursor.getLong(4) == DB.LOCATION.TYPE_PAUSE) { w.name("type").value("pause"); } else if (cursor.getLong(4) == DB.LOCATION.TYPE_RESUME) { w.name("type").value("resume"); } else if (cursor.getLong(4) == DB.LOCATION.TYPE_GPS) { w.name("type").value("gps"); } else { w.name("type").value("manual"); } w.endObject(); } while (cursor.moveToNext()); w.endArray(); } cursor.close(); }
From source file:export.format.FacebookCourse.java
private JSONArray trail(long activityId) throws JSONException { final String cols[] = { DB.LOCATION.TYPE, DB.LOCATION.LATITUDE, DB.LOCATION.LONGITUDE, DB.LOCATION.TIME, DB.LOCATION.SPEED };/*from w w w . ja v a 2 s . c om*/ Cursor c = mDB.query(DB.LOCATION.TABLE, cols, DB.LOCATION.ACTIVITY + " = " + activityId, null, null, null, null); if (c.moveToFirst()) { Location prev = null, last = null; double sumDist = 0; long sumTime = 0; double accTime = 0; final double period = 30; JSONArray arr = new JSONArray(); do { switch (c.getInt(0)) { case DB.LOCATION.TYPE_START: case DB.LOCATION.TYPE_RESUME: last = new Location("Dill"); last.setLatitude(c.getDouble(1)); last.setLongitude(c.getDouble(2)); last.setTime(c.getLong(3)); accTime = period * 1000; // always emit first point // start/resume break; case DB.LOCATION.TYPE_END: accTime = period * 1000; // always emit last point case DB.LOCATION.TYPE_GPS: case DB.LOCATION.TYPE_PAUSE: Location l = new Location("Sill"); l.setLatitude(c.getDouble(1)); l.setLongitude(c.getDouble(2)); l.setTime(c.getLong(3)); if (!c.isNull(4)) l.setSpeed(c.getFloat(4)); if (last != null) { sumDist += l.distanceTo(last); sumTime += l.getTime() - last.getTime(); accTime += l.getTime() - last.getTime(); } prev = last; last = l; } if (Math.round(accTime / 1000) >= period) { arr.put(point(prev, last, sumTime, sumDist)); accTime -= period * 1000; } } while (c.moveToNext()); c.close(); return arr; } c.close(); return null; }
From source file:org.envirocar.app.storage.DbAdapterImpl.java
private Measurement buildMeasurementFromCursor(Track track, Cursor c) { double lat = c.getDouble(c.getColumnIndex(KEY_MEASUREMENT_LATITUDE)); double lon = c.getDouble(c.getColumnIndex(KEY_MEASUREMENT_LONGITUDE)); long time = c.getLong(c.getColumnIndex(KEY_MEASUREMENT_TIME)); String rawData = c.getString(c.getColumnIndex(KEY_MEASUREMENT_PROPERTIES)); Measurement measurement = new Measurement(lat, lon); measurement.setTime(time);//www .jav a 2s . c o m measurement.setTrackId(track.getTrackId()); if (rawData != null) { try { JSONObject json = new JSONObject(rawData); JSONArray names = json.names(); if (names != null) { for (int j = 0; j < names.length(); j++) { String key = names.getString(j); measurement.setProperty(PropertyKey.valueOf(key), json.getDouble(key)); } } } catch (JSONException e) { logger.severe("could not load properties", e); } } return measurement; }
From source file:edu.princeton.jrpalmer.asmlibrary.ListDataCursorAdapter.java
@Override public void bindView(View v, Context context, Cursor c) { String firstTime = Util.userDate(new Date((c.getLong(c.getColumnIndex(Fixes.KEY_TIMELONG))))); String sdTime = Util/*w w w. ja v a2 s. c o m*/ .userDate(new Date((c.getLong(c.getColumnIndex(Fixes.KEY_STATION_DEPARTURE_TIMELONG))))); TextView firstTimeText = (TextView) v.findViewById(R.id.firstTimeLong); if (firstTimeText != null) { firstTimeText.setText(firstTime); } TextView sdTimeText = (TextView) v.findViewById(R.id.sdTimeLong); if (sdTimeText != null) { sdTimeText.setText(sdTime); } TextView lat = (TextView) v.findViewById(R.id.latitude); if (lat != null) { lat.setText(String.format("%.5f", c.getDouble(c.getColumnIndex(Fixes.KEY_LATITUDE)))); } TextView lon = (TextView) v.findViewById(R.id.longitude); if (lon != null) { lon.setText(String.format("%.5f", c.getDouble(c.getColumnIndex(Fixes.KEY_LONGITUDE)))); } TextView alt = (TextView) v.findViewById(R.id.altitude); if (alt != null) { alt.setText(Double.toString(c.getDouble(c.getColumnIndex(Fixes.KEY_ALTITUDE)))); } TextView acc = (TextView) v.findViewById(R.id.accuracy); if (acc != null) { acc.setText(Double.toString(c.getDouble(c.getColumnIndex(Fixes.KEY_ACCURACY)))); } TextView prov = (TextView) v.findViewById(R.id.provider); if (prov != null) { prov.setText(c.getString(c.getColumnIndex(Fixes.KEY_PROVIDER))); } }
From source file:fr.eoit.activity.fragment.blueprint.InventionFragment.java
@Override public void onLoadFinished(Cursor data) { if (DbUtil.hasAtLeastOneRow(data)) { parentTypeId = data.getInt(data.getColumnIndexOrThrow(Blueprint.COLUMN_NAME_PARENT_TYPE_ID)); int maxProdLimit = data.getInt(data.getColumnIndexOrThrow(Blueprint.COLUMN_NAME_MAX_PRODUCTION_LIMIT)); metaLevel = data.getShort(data.getColumnIndexOrThrow(Blueprint.COLUMN_NAME_INVENTION_ITEM_META_LEVEL)); decryptorId = data.getInt(data.getColumnIndexOrThrow(Blueprint.COLUMN_NAME_DECRYPTOR_ID)); double cost = data.getDouble(data.getColumnIndexOrThrow(Blueprint.COLUMN_NAME_RESEARCH_PRICE)); if (decryptorId != 0) { currentDecryptorBonuses = DecryptorUtil.getDecryptorBonusesOrDefault(decryptorId); }/*from www .j a va 2s . c o m*/ requiredSkillInventionFragment.setParentFragment(this); requiredSkillInventionFragment.setParentTypeId(parentTypeId); requiredItemsInventionFragment.setParentFragment(this); requiredItemsInventionFragment.setDecryptorId(decryptorId); requiredItemsInventionFragment.setParentTypeId(parentTypeId); requiredItemsInventionFragment.setMaxProdLimit(maxProdLimit); requiredDecryptorFragment.setParentFragment(this); requiredDecryptorFragment.setBlueprintId(blueprintId); requiredDecryptorFragment.setProducedItemId(producedItemId); int metaGroupId = getArguments().getInt("metaGroupId", -1); Bundle blueprintBundle = BlueprintUtil.getBlueprintBundle(data, metaGroupId, true, false); int numberOfRuns = blueprintBundle.getInt("numberOfRuns", 0); int unitPerBatch = blueprintBundle.getInt("unitPerBatch", 0); double sellPrice = getArguments().getDouble("sellPrice", 0); producePrice = getArguments().getDouble("producePrice", 0); double profitOnSingleItem = sellPrice - producePrice; double blueprintProfit = profitOnSingleItem * unitPerBatch * numberOfRuns; if (!data.isNull(data.getColumnIndexOrThrow(Blueprint.COLUMN_NAME_RESEARCH_PRICE))) { BlueprintUtil.setBlueprintCost(costTextView, cost, getResources()); profitTextView.setText(PricesUtils.formatPrice(blueprintProfit, getActivity(), true)); } else { costTextView.setVisibility(View.GONE); profitTextView.setVisibility(View.GONE); } } }
From source file:com.jackie.sunshine.app.sync.SunshineSyncAdapter.java
private void notifyWeather() { Context context = getContext(); //checking the last update and notify if it' the first of the day SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context); String displayNotificationsKey = context.getString(R.string.pref_enable_notifications_key); boolean needNotification = prefs.getBoolean(displayNotificationsKey, Boolean.valueOf(context.getString(R.string.pref_enable_notifications_default))); if (needNotification) { String lastNotificationKey = context.getString(R.string.pref_last_notification); long lastSync = prefs.getLong(lastNotificationKey, 0); if (System.currentTimeMillis() - lastSync >= DAY_IN_MILLIS) { // Last sync was more than 1 day ago, let's send a notification with the weather. String locationQuery = Utility.getPreferredLocation(context); Uri weatherUri = WeatherContract.WeatherEntry.buildWeatherLocationWithDate(locationQuery, System.currentTimeMillis()); // we'll query our contentProvider, as always Cursor cursor = context.getContentResolver().query(weatherUri, NOTIFY_WEATHER_PROJECTION, null, null, null);/*from ww w . j a v a 2s . c o m*/ if (cursor.moveToFirst()) { int weatherId = cursor.getInt(INDEX_WEATHER_ID); double high = cursor.getDouble(INDEX_MAX_TEMP); double low = cursor.getDouble(INDEX_MIN_TEMP); String desc = cursor.getString(INDEX_SHORT_DESC); int iconId = Utility.getIconResourceForWeatherCondition(weatherId); String title = context.getString(R.string.app_name); // Define the text of the forecast. String contentText = String.format(context.getString(R.string.format_notification), desc, Utility.formatTemperature(context, high), Utility.formatTemperature(context, low)); //build your notification here. Intent intent = new Intent(context, MainActivity.class); TaskStackBuilder stackBuilder = TaskStackBuilder.create(context); stackBuilder.addParentStack(MainActivity.class); stackBuilder.addNextIntent(intent); PendingIntent pendingIntent = stackBuilder.getPendingIntent(0, PendingIntent.FLAG_UPDATE_CURRENT); Notification notification = new Notification.Builder(context).setSmallIcon(iconId) .setContentTitle(title).setContentText(contentText).setContentIntent(pendingIntent) .build(); NotificationManager notificationManager = (NotificationManager) context .getSystemService(Context.NOTIFICATION_SERVICE); notificationManager.notify(WEATHER_NOTIFICATION_ID, notification); //refreshing last sync SharedPreferences.Editor editor = prefs.edit(); editor.putLong(lastNotificationKey, System.currentTimeMillis()); editor.apply(); } cursor.close(); } } }
From source file:org.droidparts.persist.sql.EntityManager.java
protected Object readFromCursor(Cursor cursor, int columnIndex, Class<?> valType, Class<?> arrCollItemType) throws IllegalArgumentException { if (cursor.isNull(columnIndex)) { return null; } else if (isBoolean(valType)) { return cursor.getInt(columnIndex) == 1; } else if (isByte(valType)) { return Byte.valueOf(cursor.getString(columnIndex)); } else if (isByteArray(valType)) { return cursor.getBlob(columnIndex); } else if (isDouble(valType)) { return cursor.getDouble(columnIndex); } else if (isFloat(valType)) { return cursor.getFloat(columnIndex); } else if (isInteger(valType)) { return cursor.getInt(columnIndex); } else if (isLong(valType)) { return cursor.getLong(columnIndex); } else if (isShort(valType)) { return cursor.getShort(columnIndex); } else if (isString(valType)) { return cursor.getString(columnIndex); } else if (isUUID(valType)) { return UUID.fromString(cursor.getString(columnIndex)); } else if (isDate(valType)) { return new Date(cursor.getLong(columnIndex)); } else if (isBitmap(valType)) { byte[] arr = cursor.getBlob(columnIndex); return BitmapFactory.decodeByteArray(arr, 0, arr.length); } else if (isJsonObject(valType) || isJsonArray(valType)) { String str = cursor.getString(columnIndex); try {// ww w . j a va2 s . c o m return isJsonObject(valType) ? new JSONObject(str) : new JSONArray(str); } catch (JSONException e) { throw new IllegalArgumentException(e); } } else if (isEnum(valType)) { return instantiateEnum(valType, cursor.getString(columnIndex)); } else if (isEntity(valType)) { long id = cursor.getLong(columnIndex); @SuppressWarnings("unchecked") Entity entity = instantiate((Class<Entity>) valType); entity.id = id; return entity; } else if (isArray(valType) || isCollection(valType)) { String str = cursor.getString(columnIndex); String[] parts = (str.length() > 0) ? str.split("\\" + SEP) : new String[0]; if (isArray(valType)) { return toTypeArr(arrCollItemType, parts); } else { @SuppressWarnings("unchecked") Collection<Object> coll = (Collection<Object>) instantiate(valType); coll.addAll(toTypeColl(arrCollItemType, parts)); return coll; } } else { throw new IllegalArgumentException("Need to manually read " + valType.getName() + " from cursor."); } }
From source file:com.adkdevelopment.earthquakesurvival.ui.DetailFragment.java
@Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { View rootView = inflater.inflate(R.layout.detailed_fragment, container, false); setHasOptionsMenu(true);//from w ww . j ava 2 s. c o m mUnbinder = ButterKnife.bind(this, rootView); if (getActivity().getIntent().hasExtra(Feature.GEOFENCE)) { ArrayList<String> place = getActivity().getIntent().getStringArrayListExtra(Feature.GEOFENCE); Cursor cursor = null; if (place != null && place.size() > 1) { cursor = getActivity().getContentResolver().query(EarthquakeColumns.CONTENT_URI, null, EarthquakeColumns.URL + "= ?", new String[] { place.get(1) }, null); } if (cursor != null && cursor.getCount() > 0) { cursor.moveToFirst(); long dateMillis = cursor.getLong(cursor.getColumnIndex(EarthquakeColumns.TIME)); double latitude = cursor.getDouble(cursor.getColumnIndex(EarthquakeColumns.LATITUDE)); double longitude = cursor.getDouble(cursor.getColumnIndex(EarthquakeColumns.LONGITUDE)); LatLng latLng = new LatLng(latitude, longitude); mCameraPosition = CameraPosition.builder().target(latLng).zoom(LocationUtils.CAMERA_DEFAULT_ZOOM) .build(); mDistance = getString(R.string.earthquake_distance, LocationUtils.getDistance(latLng, LocationUtils.getLocation(getContext()))); mDate = Utilities.getRelativeDate(dateMillis); mDescription = Utilities .formatEarthquakePlace(cursor.getString(cursor.getColumnIndex(EarthquakeColumns.PLACE))); mLink = cursor.getString(cursor.getColumnIndex(EarthquakeColumns.URL)); mMagnitude = cursor.getDouble(cursor.getColumnIndex(EarthquakeColumns.MAG)); mDepth = cursor.getDouble(cursor.getColumnIndex(EarthquakeColumns.DEPTH)) / 1.6; cursor.close(); setDataToViews(); } } else if (getActivity().getIntent() != null) { Intent input = getActivity().getIntent(); mDate = input.getStringExtra(Feature.DATE); mDescription = input.getStringExtra(Feature.PLACE); mLink = input.getStringExtra(Feature.LINK); mMagnitude = input.getDoubleExtra(Feature.MAGNITUDE, 0.0); mPosition = input.getParcelableExtra(Feature.LATLNG); mDistance = input.getStringExtra(Feature.DISTANCE); mDepth = input.getDoubleExtra(Feature.DEPTH, 0.0); setDataToViews(); } if (mPosition == null) { mPosition = LocationUtils.getLocation(getContext()); } final Bundle mapViewSavedInstanceState = savedInstanceState != null ? savedInstanceState.getBundle(MAP_STATE) : null; if (Utilities.checkPlayServices(getActivity())) { mMapView.onCreate(mapViewSavedInstanceState); mMapView.getMapAsync(this); } if (savedInstanceState != null) { mCameraPosition = savedInstanceState.getParcelable(CAMERA_POSITION); } else { mCameraPosition = CameraPosition.builder().target(mPosition).zoom(LocationUtils.CAMERA_DEFAULT_ZOOM) .build(); } return rootView; }