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:com.wheelly.fragments.LocationsListFragment.java

private void startGeocode(ContentValues location) {
    new GeocoderTask(location).execute(location.getAsDouble("latitude"), location.getAsDouble("longitude"));
}

From source file:com.wheelly.fragments.LocationsMapFragment.java

@Subscribe
public void onSelectionChanged(final LocationSelectedEvent event) {
    if (this != event.sender) {
        final ContentValues c = new LocationBroker(getActivity()).loadOrCreate(event.id);
        final LatLng selected = new LatLng(c.getAsDouble("latitude"), c.getAsDouble("longitude"));
        googleMap.animateCamera(CameraUpdateFactory.newLatLngZoom(selected, 17));
    }/*  w  w  w.ja  va2  s  .  c om*/
}

From source file:app.com.example.wungmathing.sunshine.FetchWeatherTask.java

String[] convertContentValuesToUXFormat(Vector<ContentValues> cvv) {
    // return strings to keep UI functional for now
    String[] resultStrs = new String[cvv.size()];
    for (int i = 0; i < cvv.size(); i++) {
        ContentValues weatherValues = cvv.elementAt(i);
        String highAndLow = formatHighLows(weatherValues.getAsDouble(WeatherEntry.COLUMN_MAX_TEMP),
                weatherValues.getAsDouble(WeatherEntry.COLUMN_MIN_TEMP));
        resultStrs[i] = getReadableDateString(weatherValues.getAsLong(WeatherEntry.COLUMN_DATE)) + " - "
                + weatherValues.getAsString(WeatherEntry.COLUMN_SHORT_DESC) + " - " + highAndLow;
    }// ww  w. j a  v a 2  s. c  o m
    return resultStrs;
}

From source file:com.example.android.sunshine.data.FetchWeatherTask.java

String[] convertContentValuesToUXFormat(Vector<ContentValues> cvv) {
    // return strings to keep UI functional for now
    String[] resultStrs = new String[cvv.size()];
    for (int i = 0; i < cvv.size(); i++) {
        ContentValues weatherValues = cvv.elementAt(i);
        String highAndLow = formatHighLows(
                weatherValues.getAsDouble(WeatherContract.WeatherEntry.COLUMN_MAX_TEMP),
                weatherValues.getAsDouble(WeatherContract.WeatherEntry.COLUMN_MIN_TEMP));
        resultStrs[i] = getReadableDateString(weatherValues.getAsLong(WeatherContract.WeatherEntry.COLUMN_DATE))
                + " - " + weatherValues.getAsString(WeatherContract.WeatherEntry.COLUMN_SHORT_DESC) + " - "
                + highAndLow;//  w  w  w  .ja va  2  s .  co m
    }
    return resultStrs;
}

From source file:br.com.scalasoft.alvaro.weather.FetchWeatherTask.java

String[] convertContentValuesToUXFormat(Vector<ContentValues> cvv) {
    // return strings to keep UI functional for now
    String[] resultStrs = new String[cvv.size()];
    for (int i = 0; i < cvv.size(); i++) {
        ContentValues weatherValues = cvv.elementAt(i);
        String highAndLow = formatHighLows(weatherValues.getAsDouble(WeatherEntry.COLUMN_MAX_TEMP),
                weatherValues.getAsDouble(WeatherEntry.COLUMN_MIN_TEMP));
        resultStrs[i] = getReadableDateString(weatherValues.getAsLong(WeatherEntry.COLUMN_DATE)) + " - "
                + weatherValues.getAsString(WeatherContract.WeatherEntry.COLUMN_SHORT_DESC) + " - "
                + highAndLow;/*from ww w  .ja va  2  s.  c o  m*/
    }
    return resultStrs;
}

From source file:org.tigase.mobile.roster.RosterFragment.java

@Override
public void onCreateContextMenu(ContextMenu menu, View v, ContextMenuInfo menuInfo) {
    super.onCreateContextMenu(menu, v, menuInfo);

    final Long id = extractId(menuInfo);

    if (id != null && id != -1) {
        RosterItem r = getJid(id);// www. ja v  a  2s  .  c  om
        final boolean sessionEstablished = r != null && isSessionEstablished(r.getSessionObject());

        MenuInflater m = new MenuInflater(getActivity());
        try {
            Presence p = r.getSessionObject().getPresence().getBestPresence(r.getJid());
            if (p != null && p.getType() == null) {
                SubMenu sm = menu.addSubMenu(R.id.contactsOnlineGroup, Menu.NONE, Menu.NONE, "Chat with");
                prepareResources(sm, id);
            }
        } catch (Exception e) {
        }
        m.inflate(R.menu.roster_context_menu, menu);

        JaxmppCore jaxmpp = this.getMulti().get(r.getSessionObject());
        if (jaxmpp != null && sessionEstablished) {
            GeolocationModule module = jaxmpp.getModule(GeolocationModule.class);
            if (module != null) {
                ContentValues location = module.getLocationForJid(r.getJid());
                if (location != null) {
                    Double lat = location.getAsDouble(GeolocationTableMetaData.FIELD_LAT);
                    Double lon = location.getAsDouble(GeolocationTableMetaData.FIELD_LON);
                    String uriStr = null;
                    if (lon == null || lat == null) {
                        String str = "";
                        String val = location.getAsString(GeolocationTableMetaData.FIELD_STREET);
                        Log.v(TAG, "Street = " + String.valueOf(val));
                        if (val != null) {
                            str += val;
                        }
                        val = location.getAsString(GeolocationTableMetaData.FIELD_LOCALITY);
                        Log.v(TAG, "Locality = " + String.valueOf(val));
                        if (val != null) {
                            if (!isEmpty(str)) {
                                str += " ";
                            }
                            str += val;
                        }
                        val = location.getAsString(GeolocationTableMetaData.FIELD_COUNTRY);
                        Log.v(TAG, "Country = " + String.valueOf(val));
                        if (val != null) {
                            if (!isEmpty(str)) {
                                str += " ";
                            }
                            str += val;
                        }

                        if (!isEmpty(str)) {
                            str = str.replace(' ', '+');
                            uriStr = "geo:0,0?q=" + str;
                        }
                    } else {
                        Log.v(TAG, "latitude = " + String.valueOf(lat));
                        Log.v(TAG, "longitude = " + String.valueOf(lon));
                        uriStr = "geo:" + String.valueOf(lat) + "," + String.valueOf(lon) + "?z=14";
                    }
                    if (uriStr != null) {
                        uriStr += "(" + RosterDisplayTools.getDisplayName(r) + ")";
                        Log.v(TAG, "created geolocation uri = " + uriStr);
                        Uri uri = Uri.parse(uriStr);
                        MenuItem item = menu.add(R.string.geolocation_show);
                        Intent intent = new Intent(Intent.ACTION_VIEW, uri);
                        item.setIntent(intent);
                    }
                }
            }
        }

        menu.setGroupVisible(R.id.contactsOnlineGroup, sessionEstablished);
    }
}

From source file:com.csipsimple.utils.Columns.java

public JSONObject contentValueToJSON(ContentValues cv) {
    JSONObject json = new JSONObject();
    try {//from   www. j a  va  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:org.wheelmap.android.fragment.POIsOsmdroidFragment.java

@Override
public void markItem(ContentValues values, boolean centerToItem) {
    Log.d(TAG, "markItem " + values);
    GeoPoint point = new GeoPoint(values.getAsDouble(POIs.LATITUDE), values.getAsDouble(POIs.LONGITUDE));
    markItemIntern(point, centerToItem);
    WheelmapApp app = (WheelmapApp) this.getActivity().getApplication();
    boolean b = app.isNoItemToSelect();
    app.setNoItemToSelect(false);/*from ww  w  . j a v  a2s. c o m*/
    if (!b) {

        if (mListener != null) {
            mListener.onShowDetail(this, values);
        }
    }
}

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;
        }/*w  ww.j  a  va  2 s  . co  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:com.adkdevelopment.earthquakesurvival.data.syncadapter.SyncAdapter.java

/**
 * Raises a notification with a biggest earthquake with each sync
 *
 * @param notifyValues data with the biggest recent earthquake
 *///w  ww .ja v a2s. c o  m
private void sendNotification(ContentValues notifyValues) {

    Context context = getContext();

    if (Utilities.getNotificationsPrefs(context) && !Utilities.checkForeground(context)) {

        //checking the last update and notify if it' the first of the day
        SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context);
        String lastNotificationKey = context.getString(R.string.sharedprefs_key_lastnotification);
        long lastSync = prefs.getLong(lastNotificationKey, 0);

        if (System.currentTimeMillis() - lastSync >= DateUtils.DAY_IN_MILLIS) {
            Intent intent = new Intent(context, DetailActivity.class);

            double latitude = notifyValues.getAsDouble(EarthquakeColumns.LATITUDE);
            double longitude = notifyValues.getAsDouble(EarthquakeColumns.LONGITUDE);
            LatLng latLng = new LatLng(latitude, longitude);

            String distance = context.getString(R.string.earthquake_distance,
                    LocationUtils.getDistance(latLng, LocationUtils.getLocation(context)));

            String magnitude = context.getString(R.string.earthquake_magnitude,
                    notifyValues.getAsDouble(EarthquakeColumns.MAG));
            String date = Utilities.getRelativeDate(notifyValues.getAsLong(EarthquakeColumns.TIME));

            double depth = notifyValues.getAsDouble(EarthquakeColumns.DEPTH);

            intent.putExtra(Feature.MAGNITUDE, notifyValues.getAsDouble(EarthquakeColumns.MAG));
            intent.putExtra(Feature.PLACE, notifyValues.getAsString(EarthquakeColumns.PLACE));
            intent.putExtra(Feature.DATE, date);
            intent.putExtra(Feature.LINK, notifyValues.getAsString(EarthquakeColumns.URL));
            intent.putExtra(Feature.LATLNG, latLng);
            intent.putExtra(Feature.DISTANCE, distance);
            intent.putExtra(Feature.DEPTH, depth);
            intent.setFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP);

            PendingIntent pendingIntent = PendingIntent.getActivity(context, EarthquakeObject.NOTIFICATION_ID_1,
                    intent, PendingIntent.FLAG_UPDATE_CURRENT);

            NotificationCompat.Builder builder = new NotificationCompat.Builder(context);

            Bitmap largeIcon = BitmapFactory.decodeResource(context.getResources(), R.mipmap.ic_launcher);

            builder.setDefaults(Notification.DEFAULT_ALL).setAutoCancel(true)
                    .setContentTitle(context.getString(R.string.earthquake_statistics_largest))
                    .setContentText(context.getString(R.string.earthquake_magnitude,
                            notifyValues.get(EarthquakeColumns.MAG)))
                    .setContentIntent(pendingIntent).setSmallIcon(R.drawable.ic_info_black_24dp)
                    .setLargeIcon(largeIcon).setTicker(context.getString(R.string.app_name))
                    .setStyle(new NotificationCompat.BigTextStyle()
                            .bigText(notifyValues.get(EarthquakeColumns.PLACE).toString() + "\n" + magnitude
                                    + "\n" + context.getString(R.string.earthquake_depth, depth) + "\n"
                                    + distance + "\n" + date))
                    .setGroup(EarthquakeObject.NOTIFICATION_GROUP).setGroupSummary(true);

            NotificationManagerCompat managerCompat = NotificationManagerCompat.from(context);
            managerCompat.notify(EarthquakeObject.NOTIFICATION_ID_1, builder.build());

            //refreshing last sync
            boolean success = prefs.edit().putLong(lastNotificationKey, System.currentTimeMillis()).commit();
        }
    }
}