Example usage for android.content ContentValues getAsDouble

List of usage examples for android.content ContentValues getAsDouble

Introduction

In this page you can find the example usage for android.content ContentValues getAsDouble.

Prototype

public Double getAsDouble(String key) 

Source Link

Document

Gets a value and converts it to a Double.

Usage

From source file:net.openwatch.acluaz.fragment.FormFragment.java

/**
 * Populate form given the db_id of an Incident in the database
 * This currently assumes that the database columns are equal to the view_tags (json keys)
 * @param container/*from   w  w  w  . j av  a 2s  . c  o m*/
 * @param db_id
 */
protected void fillFormFromDatabase(ViewGroup container, int db_id) {
    String TAG = "FormFragment-fillFormFromDatabase";
    Incident incident = Incident.objects(this.getActivity().getApplicationContext()).get(db_id);
    if (incident == null)
        return;
    ContentValues values = new ContentValues();
    try {
        incident.collectData(getActivity().getApplicationContext(), values, Incident.class);
    } catch (IllegalArgumentException e) {
        Log.e(TAG, "Unable to collect ContentValues from Incident");
        e.printStackTrace();
    } catch (IllegalAccessException e) {
        Log.e(TAG, "Unable to collect ContentValues from Incident");
        e.printStackTrace();
    }

    View form_input;
    for (Entry<String, ?> entry : values.valueSet()) {

        if (entry.getKey().compareTo(getString(R.string.device_lat)) == 0
                || entry.getKey().compareTo(getString(R.string.device_lon)) == 0) {
            // Combine lat and lon into a Location and tag the gps toggle
            form_input = container.findViewById(R.id.gps_toggle);
            Location loc = new Location("db");
            loc.setLatitude(values.getAsDouble(DBConstants.DEVICE_LAT));
            loc.setLongitude(values.getAsDouble(DBConstants.DEVICE_LON));
            form_input.setTag(R.id.view_tag, loc);
        } else if (entry.getKey().compareTo(getString(R.string.date_tag)) == 0) {
            form_input = container.findViewById(R.id.date_input);
            if (form_input == null || entry.getValue() == null)
                continue;
            String date = (String) entry.getValue();
            try {
                ((EditText) form_input)
                        .setText(Constants.date_formatter.format(Constants.datetime_formatter.parse(date)));
                form_input = container.findViewById(R.id.time_input);
                if (form_input == null)
                    continue;
                ((EditText) form_input)
                        .setText(Constants.time_formatter.format(Constants.datetime_formatter.parse(date)));
            } catch (ParseException e) {
                Log.e(TAG, "Error setting date time form fields from database datetime");
                e.printStackTrace();
            }

        } else {
            // If the column value is simply bound to the view
            // with tag equal to column name...
            form_input = container.findViewWithTag(entry.getKey());
            setFormFieldValue(form_input, entry);
        }
    }

}

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
 *//* w  ww  .j av  a2 s  .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);
}