List of usage examples for android.content ContentValues getAsFloat
public Float getAsFloat(String key)
From source file:th.in.ffc.person.visit.VisitDefaultActivity.java
private boolean doSave() { if (TextUtils.isEmpty(mVisitNo)) return false; EditTransaction et = beginTransaction(); boolean weight = et.retrieveData(Visit.WEIGHT, mWeight, false, 0.0f, 300.0f, "weight, out of range"); boolean height = et.retrieveData(Visit.HEIGHT, mHeight, false, 0.0f, 300.0f, "height, out of range"); et.retrieveData(Visit.ASS, mAss, true, 0.0f, 300.0f, "Ass, out of range"); et.retrieveData(Visit.WAIST, mWaist, true, 0.0f, 300.0f, "Waist out of range"); et.retrieveData(Visit.PRESSURE, mPressure, true, "\\d{1,3}/{0,1}\\d{0,2}\\b", "invalid format"); et.retrieveData(Visit.PRESSURE_2, mPressure2, true, "\\d{1,3}/{0,1}\\d{0,2}\\b", "invalid format"); et.retrieveData(Visit.PULSE, mPulse, true, 0, 250, "Pulse out of rage"); et.retrieveData(Visit.TEMPERATURE, mTemp, true, 30.0f, 45.0f, "Is he/her already dead"); if (weight && height) { ContentValues cv = et.getContentValues(); int bmi = BMILevel.calculateBMILevel(cv.getAsFloat(Visit.WEIGHT), cv.getAsFloat(Visit.HEIGHT)); cv.put(Visit.BMI, bmi);/*from w w w . j a va 2 s . c o m*/ } et.retrieveData(Visit.SYMPTOMS, mSymtom, true, null, null); et.retrieveData(Visit.VITAL, mVitalCheck, true, null, null); et.retrieveData(Visit.HEALTH_SUGGEST_1, mHealthSuggest, true, null, null); ContentValues value = et.getContentValues(); value.put(Visit.SERVICE_TYPE, mServiceType.isChecked() ? 1 : 2); value.put(Visit.TIME_SERIVICE, mServiceTime.isChecked() ? 1 : 2); value.put(Visit.INCUP, mInCup.isChecked() ? 1 : 2); if (getIntent().getAction().equals(Action.INSERT)) { if (et.canCommit()) { value.put(Visit.PCUCODE, getPcuCode()); value.put(Visit.PCUCODE_PERSON, getPcuCode()); value.put(Visit.PID, mPid); value.put(Visit.NO, mVisitNo); value.put(Visit.DATE, DateTime.getCurrentDate()); value.put(Visit.UPDATE, DateTime.getCurrentDateTime()); value.put(Visit.USERNAME, getUser()); value.put(Visit.TIME_START, mTimeStart); getSupportLoaderManager().initLoader(LOAD_PERSONRIGHT, null, this); } } else { value.put(Visit.UPDATE, DateTime.getCurrentDateTime()); Uri visit = Uri.withAppendedPath(Visit.CONTENT_URI, mVisitNo); int update = et.commit(visit, null, null); if (update > 0) { setResult(RESULT_OK, new Intent(Action.EDIT, visit)); finish(); } else { setResult(RESULT_CANCELED); Log.d(TAG, "update failre"); } } return true; }
From source file:com.csipsimple.utils.Columns.java
public JSONObject contentValueToJSON(ContentValues cv) { JSONObject json = new JSONObject(); try {// w w w .j a v a 2 s . c o m for (int i = 0; i < names.length; i++) { if (!cv.containsKey(names[i])) { continue; } switch (types[i]) { case STRING: json.put(names[i], cv.getAsString(names[i])); break; case INT: json.put(names[i], cv.getAsInteger(names[i])); break; case LONG: json.put(names[i], cv.getAsLong(names[i])); break; case FLOAT: json.put(names[i], cv.getAsFloat(names[i])); break; case DOUBLE: json.put(names[i], cv.getAsDouble(names[i])); break; case BOOLEAN: json.put(names[i], cv.getAsBoolean(names[i])); break; } } } catch (JSONException e) { throw new RuntimeException(e); } return json; }
From source file:com.csipsimple.backup.Columns.java
public JSONObject contentValueToJSON(ContentValues cv) { JSONObject json = new JSONObject(); for (int i = 0; i < names.size(); i++) { if (!cv.containsKey(names.get(i))) { continue; }/*from w ww . j ava 2s .c o m*/ try { String name = names.get(i); switch (types.get(i)) { case STRING: json.put(name, cv.getAsString(name)); break; case INT: json.put(name, cv.getAsInteger(name)); break; case LONG: json.put(name, cv.getAsLong(name)); break; case FLOAT: json.put(name, cv.getAsFloat(name)); break; case DOUBLE: json.put(name, cv.getAsDouble(name)); break; case BOOLEAN: json.put(name, cv.getAsBoolean(name)); break; default: Log.w("Col", "Invalid type, can't unserialize " + types.get(i)); } } catch (JSONException e) { Log.e("Col", "Invalid type, can't unserialize ", e); } } return json; }
From source file:org.runnerup.view.DetailActivity.java
void fillHeaderData() { // Fields from the database (projection) // Must include the _id column for the adapter to work String[] from = new String[] { DB.ACTIVITY.START_TIME, DB.ACTIVITY.DISTANCE, DB.ACTIVITY.TIME, DB.ACTIVITY.COMMENT, DB.ACTIVITY.SPORT }; Cursor c = mDB.query(DB.ACTIVITY.TABLE, from, "_id == " + mID, null, null, null, null, null); c.moveToFirst();/*from w w w .jav a 2 s . co m*/ ContentValues tmp = DBHelper.get(c); c.close(); long st = 0; if (tmp.containsKey(DB.ACTIVITY.START_TIME)) { st = tmp.getAsLong(DB.ACTIVITY.START_TIME); setTitle("RunnerUp - " + formatter.formatDateTime(Formatter.TXT_LONG, st)); } float d = 0; if (tmp.containsKey(DB.ACTIVITY.DISTANCE)) { d = tmp.getAsFloat(DB.ACTIVITY.DISTANCE); activityDistance.setText(formatter.formatDistance(Formatter.TXT_LONG, (long) d)); } else { activityDistance.setText(""); } float t = 0; if (tmp.containsKey(DB.ACTIVITY.TIME)) { t = tmp.getAsFloat(DB.ACTIVITY.TIME); activityTime.setText(formatter.formatElapsedTime(Formatter.TXT_SHORT, (long) t)); } else { activityTime.setText(""); } if (d != 0 && t != 0) { activityPace.setText(formatter.formatPace(Formatter.TXT_LONG, t / d)); } else { activityPace.setText(""); } if (tmp.containsKey(DB.ACTIVITY.COMMENT)) { notes.setText(tmp.getAsString(DB.ACTIVITY.COMMENT)); } if (tmp.containsKey(DB.ACTIVITY.SPORT)) { sport.setValue(tmp.getAsInteger(DB.ACTIVITY.SPORT)); } }
From source file:edu.cens.loci.ui.PlaceViewActivity.java
/** * Build up the entries to display on the screen. * * @param personCursor the URI for the contact being displayed */// www . ja v a2s . c o m private final void buildEntries() { final Context context = this; final Sources sources = Sources.getInstance(context); ArrayList<ViewEntry> items = new ArrayList<ViewEntry>(); int typeIcon = R.drawable.icon_question; String typeString = "Unknown"; if (mPlace.type == Places.TYPE_GPS) { typeIcon = R.drawable.icon_satellite; typeString = "GPS"; } else if (mPlace.type == Places.TYPE_WIFI) { typeIcon = R.drawable.icon_wifi; typeString = "Wi-Fi"; } // detection type items.add(new ViewEntry(LIST_ACTION_NO_ACTION, typeIcon, "Dectection Sensor", typeString, null)); // recent visit time String recentVisitTime = getRecentVisitSubstring(); //"May 4, 3:00pm, 1hr"; items.add(new ViewEntry(LIST_ACTION_VIEW_VISITS, R.drawable.ic_clock_strip_desk_clock, "View recent visits", recentVisitTime, null)); for (Entity entity : mEntities) { final ContentValues entValues = entity.getEntityValues(); final String accountType = entValues.getAsString(Places.ACCOUNT_TYPE); final long placeId = entValues.getAsLong(Places._ID); for (NamedContentValues subValue : entity.getSubValues()) { final ContentValues entryValues = subValue.values; entryValues.put(Places.Data.PLACE_ID, placeId); final long dataId = entryValues.getAsLong(Data._ID); final String mimeType = entryValues.getAsString(Data.MIMETYPE); if (mimeType == null) continue; final DataKind kind = sources.getKindOrFallback(accountType, mimeType, this, PlacesSource.LEVEL_MIMETYPES); if (kind == null) continue; //Log.e(TAG, "buildEntries: dataId=" + dataId + ", mimeType=" + mimeType); // public ViewEntry(int action, int icon, String text, String subtext, Intent intent) { if (WifiFingerprint.CONTENT_ITEM_TYPE.equals(mimeType)) { String fingerprint = entryValues.getAsString(WifiFingerprint.FINGERPRINT); long timestamp = entryValues.getAsLong(WifiFingerprint.TIMESTAMP); String subtext = "Captured at " + MyDateUtils.getAbrv_MMM_d_h_m(timestamp); //Log.d(TAG, fingerprint); //String apsAbstract = getWifiInfoSubstring(5, fingerprint); ViewEntry item = new ViewEntry(LIST_ACTION_VIEW_WIFIS, R.drawable.ic_settings_wireless, "View Wi-Fi APs", subtext, null); item.extra_string = fingerprint; mWifiEntries.add(item); } else if (GpsCircleArea.CONTENT_ITEM_TYPE.equals(mimeType)) { double lat = entryValues.getAsDouble(GpsCircleArea.LATITUDE); double lon = entryValues.getAsDouble(GpsCircleArea.LONGITUDE); float rad = entryValues.getAsFloat(GpsCircleArea.RADIUS); //Log.d(TAG, "lat=" + lat + ",lon=" + lon + ",rad=" + rad); ViewEntry item = new ViewEntry(-1, -1, null, null, null); item.extra_double1 = lat; item.extra_double2 = lon; item.extra_float1 = rad; mGpsEntries.add(item); } else if (StructuredPostal.CONTENT_ITEM_TYPE.equals(mimeType)) { ViewEntry item = ViewEntry.fromValues(context, mimeType, kind, placeId, dataId, entryValues); String uri = "geo:0,0?q=" + TextUtils.htmlEncode(item.data); item.intent = new Intent(Intent.ACTION_VIEW, Uri.parse(uri)); item.action = LIST_ACTION_POSTAL; item.text = item.label; item.subtext = item.data; mPostalEntries.add(item); } else if (Keyword.CONTENT_ITEM_TYPE.equals(mimeType)) { ViewEntry item = ViewEntry.fromValues(context, mimeType, kind, placeId, dataId, entryValues); item.text = item.data; item.subtext = null; mTagEntries.add(item); } else if (Note.CONTENT_ITEM_TYPE.equals(mimeType)) { ViewEntry item = ViewEntry.fromValues(context, mimeType, kind, placeId, dataId, entryValues); item.text = item.label; item.subtext = item.data; mOtherEntries.add(item); } else if (Website.CONTENT_ITEM_TYPE.equals(mimeType)) { ViewEntry item = ViewEntry.fromValues(context, mimeType, kind, placeId, dataId, entryValues); item.uri = null; item.action = LIST_ACTION_WEBSITE; item.text = item.label; item.subtext = item.data; item.intent = new Intent(Intent.ACTION_VIEW, Uri.parse(item.data)); mWebsiteEntries.add(item); } } } for (ViewEntry item : mWifiEntries) { items.add(item); } mWifiEntries.clear(); for (ViewEntry item : mPostalEntries) { items.add(item); } mPostalEntries.clear(); for (ViewEntry item : mTagEntries) { items.add(item); } mTagEntries.clear(); for (ViewEntry item : mWebsiteEntries) { items.add(item); } mWebsiteEntries.clear(); for (ViewEntry item : mOtherEntries) { items.add(item); } mOtherEntries.clear(); // Log.d(TAG, "size of items = " + items.size()); ViewEntryAdapter adapter = new ViewEntryAdapter(this, R.layout.place_view_list_item, items); mListView.setAdapter(adapter); }