Example usage for android.os Bundle putDouble

List of usage examples for android.os Bundle putDouble

Introduction

In this page you can find the example usage for android.os Bundle putDouble.

Prototype

public void putDouble(@Nullable String key, double value) 

Source Link

Document

Inserts a double value into the mapping of this Bundle, replacing any existing value for the given key.

Usage

From source file:com.lvfq.rabbit.fragment.SettingFragment.java

private void onUpdate(JSONObject jsonObject) {
    try {//from  www  .  ja  v  a  2 s.  c  om
        if (jsonObject != null) {
            Double serverVersion = jsonObject.getDouble("version");
            if (serverVersion > Double
                    .parseDouble(((MainApplication) getActivity().getApplication()).getVersion_name())) {
                UpdateDialog updateDialog = new UpdateDialog();
                Bundle args = new Bundle();
                args.putDouble("version", serverVersion);
                args.putString("url", jsonObject.getString("url"));
                args.putString("info", jsonObject.getString("info"));
                updateDialog.setArguments(args);
                updateDialog.show(getActivity().getSupportFragmentManager(), "update");
            } else {
                Toast.makeText(getActivity(), getString(R.string.noupdate), Toast.LENGTH_SHORT).show();
            }
        }
    } catch (JSONException e) {
        Log.e(TAG, "JSONException");
    } finally {
        synchronized (canCheckUpdate) {
            canCheckUpdate = true;
        }
    }
}

From source file:com.esri.android.ecologicalmarineunitexplorer.map.MapFragment.java

public void onSaveInstanceState(Bundle outState) {
    if (mSelectedPoint != null) {
        outState.putDouble("X", mSelectedPoint.getX());
        outState.putDouble("Y", mSelectedPoint.getY());
        if (mSelectedPoint.getSpatialReference() != null) {
            outState.putString("SR", mSelectedPoint.getSpatialReference().getWKText());
        }/*  w  w w  .  j a v  a2s  . c o  m*/
        Log.i("MapFragment", "Saving instance state");
    }
}

From source file:com.facebook.internal.BundleJSONConverterTests.java

@SmallTest
public void testSimpleValues() throws JSONException {
    ArrayList<String> arrayList = new ArrayList<String>();
    arrayList.add("1st");
    arrayList.add("2nd");
    arrayList.add("third");

    Bundle innerBundle1 = new Bundle();
    innerBundle1.putInt("inner", 1);

    Bundle innerBundle2 = new Bundle();
    innerBundle2.putString("inner", "2");
    innerBundle2.putStringArray("deep list", new String[] { "7", "8" });

    innerBundle1.putBundle("nested bundle", innerBundle2);

    Bundle b = new Bundle();
    b.putBoolean("boolValue", true);
    b.putInt("intValue", 7);
    b.putLong("longValue", 5000000000l);
    b.putDouble("doubleValue", 3.14);
    b.putString("stringValue", "hello world");
    b.putStringArray("stringArrayValue", new String[] { "first", "second" });
    b.putStringArrayList("stringArrayListValue", arrayList);
    b.putBundle("nested", innerBundle1);

    JSONObject json = BundleJSONConverter.convertToJSON(b);
    assertNotNull(json);/*ww  w. j ava 2 s .com*/

    assertEquals(true, json.getBoolean("boolValue"));
    assertEquals(7, json.getInt("intValue"));
    assertEquals(5000000000l, json.getLong("longValue"));
    assertEquals(3.14, json.getDouble("doubleValue"));
    assertEquals("hello world", json.getString("stringValue"));

    JSONArray jsonArray = json.getJSONArray("stringArrayValue");
    assertEquals(2, jsonArray.length());
    assertEquals("first", jsonArray.getString(0));
    assertEquals("second", jsonArray.getString(1));

    jsonArray = json.getJSONArray("stringArrayListValue");
    assertEquals(3, jsonArray.length());
    assertEquals("1st", jsonArray.getString(0));
    assertEquals("2nd", jsonArray.getString(1));
    assertEquals("third", jsonArray.getString(2));

    JSONObject innerJson = json.getJSONObject("nested");
    assertEquals(1, innerJson.getInt("inner"));
    innerJson = innerJson.getJSONObject("nested bundle");
    assertEquals("2", innerJson.getString("inner"));

    jsonArray = innerJson.getJSONArray("deep list");
    assertEquals(2, jsonArray.length());
    assertEquals("7", jsonArray.getString(0));
    assertEquals("8", jsonArray.getString(1));

    Bundle finalBundle = BundleJSONConverter.convertToBundle(json);
    assertNotNull(finalBundle);

    assertEquals(true, finalBundle.getBoolean("boolValue"));
    assertEquals(7, finalBundle.getInt("intValue"));
    assertEquals(5000000000l, finalBundle.getLong("longValue"));
    assertEquals(3.14, finalBundle.getDouble("doubleValue"));
    assertEquals("hello world", finalBundle.getString("stringValue"));

    List<String> stringList = finalBundle.getStringArrayList("stringArrayValue");
    assertEquals(2, stringList.size());
    assertEquals("first", stringList.get(0));
    assertEquals("second", stringList.get(1));

    stringList = finalBundle.getStringArrayList("stringArrayListValue");
    assertEquals(3, stringList.size());
    assertEquals("1st", stringList.get(0));
    assertEquals("2nd", stringList.get(1));
    assertEquals("third", stringList.get(2));

    Bundle finalInnerBundle = finalBundle.getBundle("nested");
    assertEquals(1, finalInnerBundle.getInt("inner"));
    finalBundle = finalInnerBundle.getBundle("nested bundle");
    assertEquals("2", finalBundle.getString("inner"));

    stringList = finalBundle.getStringArrayList("deep list");
    assertEquals(2, stringList.size());
    assertEquals("7", stringList.get(0));
    assertEquals("8", stringList.get(1));
}

From source file:gov.wa.wsdot.android.wsdot.service.MyFirebaseMessagingService.java

private void startHighwayAlertDetailsActivity(int id, String title, String message, Map data) {

    // Create an Intent for the activity you want to start
    Intent resultIntent = new Intent(this, HighwayAlertDetailsActivity.class);
    // Create the TaskStackBuilder and add the intent, which inflates the back stack
    TaskStackBuilder stackBuilder = TaskStackBuilder.create(this);

    Bundle b1 = new Bundle();
    b1.putInt("id", Integer.valueOf(data.get("alert_id").toString()));
    b1.putBoolean("refresh", true);
    b1.putBoolean("from_notification", true);
    resultIntent.putExtras(b1);//from ww w  .  j a  v a  2 s.  c o m
    resultIntent.setAction("actionstring" + System.currentTimeMillis());
    stackBuilder.addNextIntentWithParentStack(resultIntent);

    Bundle b2 = new Bundle();

    if ((data.get("lat") != null && data.get("long") != null)) {

        b2.putDouble("lat", Double.valueOf(data.get("lat").toString()));
        b2.putDouble("long", Double.valueOf(data.get("long").toString()));
        b2.putInt("zoom", 15);

    } else {
        Log.i(TAG, "no data for bundle");
    }

    // set extras for the FerriesRouteAlertsBulletinsFragment
    stackBuilder.editIntentAt(stackBuilder.getIntentCount() - 2).putExtras(b2);

    // Get the PendingIntent containing the entire back stack
    PendingIntent resultPendingIntent = stackBuilder.getPendingIntent(0, PendingIntent.FLAG_UPDATE_CURRENT);
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
        NotificationCompat.Builder builder = new NotificationCompat.Builder(this, ALERT_CHANNEL_ID)
                .setSmallIcon(R.drawable.ic_list_wsdot).setContentTitle(title).setContentText(message)
                .setChannelId(ALERT_CHANNEL_ID).setStyle(new NotificationCompat.BigTextStyle().bigText(message))
                .setContentIntent(resultPendingIntent)
                .setColor(ContextCompat.getColor(this, R.color.primary_default)).setAutoCancel(true)
                .setGroup(String.valueOf(System.currentTimeMillis())).setDefaults(Notification.DEFAULT_LIGHTS);
        NotificationManagerCompat notificationManager = NotificationManagerCompat.from(this);
        notificationManager.notify(id, builder.build());
    } else {
        NotificationCompat.Builder builder = new NotificationCompat.Builder(this)
                .setSmallIcon(R.drawable.ic_list_wsdot).setContentTitle(title).setContentText(message)
                .setStyle(new NotificationCompat.BigTextStyle().bigText(message))
                .setContentIntent(resultPendingIntent).setAutoCancel(true).setWhen(0)
                .setDefaults(Notification.DEFAULT_LIGHTS);
        NotificationManagerCompat notificationManager = NotificationManagerCompat.from(this);
        notificationManager.notify(id, builder.build());
    }
}

From source file:com.facebook.internal.BundleJSONConverterTest.java

@Test
public void testSimpleValues() throws JSONException {
    ArrayList<String> arrayList = new ArrayList<String>();
    arrayList.add("1st");
    arrayList.add("2nd");
    arrayList.add("third");

    Bundle innerBundle1 = new Bundle();
    innerBundle1.putInt("inner", 1);

    Bundle innerBundle2 = new Bundle();
    innerBundle2.putString("inner", "2");
    innerBundle2.putStringArray("deep list", new String[] { "7", "8" });

    innerBundle1.putBundle("nested bundle", innerBundle2);

    Bundle b = new Bundle();
    b.putBoolean("boolValue", true);
    b.putInt("intValue", 7);
    b.putLong("longValue", 5000000000l);
    b.putDouble("doubleValue", 3.14);
    b.putString("stringValue", "hello world");
    b.putStringArray("stringArrayValue", new String[] { "first", "second" });
    b.putStringArrayList("stringArrayListValue", arrayList);
    b.putBundle("nested", innerBundle1);

    JSONObject json = BundleJSONConverter.convertToJSON(b);
    assertNotNull(json);/*  ww  w.  j  a v a  2s  . co m*/

    assertEquals(true, json.getBoolean("boolValue"));
    assertEquals(7, json.getInt("intValue"));
    assertEquals(5000000000l, json.getLong("longValue"));
    assertEquals(3.14, json.getDouble("doubleValue"), TestUtils.DOUBLE_EQUALS_DELTA);
    assertEquals("hello world", json.getString("stringValue"));

    JSONArray jsonArray = json.getJSONArray("stringArrayValue");
    assertEquals(2, jsonArray.length());
    assertEquals("first", jsonArray.getString(0));
    assertEquals("second", jsonArray.getString(1));

    jsonArray = json.getJSONArray("stringArrayListValue");
    assertEquals(3, jsonArray.length());
    assertEquals("1st", jsonArray.getString(0));
    assertEquals("2nd", jsonArray.getString(1));
    assertEquals("third", jsonArray.getString(2));

    JSONObject innerJson = json.getJSONObject("nested");
    assertEquals(1, innerJson.getInt("inner"));
    innerJson = innerJson.getJSONObject("nested bundle");
    assertEquals("2", innerJson.getString("inner"));

    jsonArray = innerJson.getJSONArray("deep list");
    assertEquals(2, jsonArray.length());
    assertEquals("7", jsonArray.getString(0));
    assertEquals("8", jsonArray.getString(1));

    Bundle finalBundle = BundleJSONConverter.convertToBundle(json);
    assertNotNull(finalBundle);

    assertEquals(true, finalBundle.getBoolean("boolValue"));
    assertEquals(7, finalBundle.getInt("intValue"));
    assertEquals(5000000000l, finalBundle.getLong("longValue"));
    assertEquals(3.14, finalBundle.getDouble("doubleValue"), TestUtils.DOUBLE_EQUALS_DELTA);
    assertEquals("hello world", finalBundle.getString("stringValue"));

    List<String> stringList = finalBundle.getStringArrayList("stringArrayValue");
    assertEquals(2, stringList.size());
    assertEquals("first", stringList.get(0));
    assertEquals("second", stringList.get(1));

    stringList = finalBundle.getStringArrayList("stringArrayListValue");
    assertEquals(3, stringList.size());
    assertEquals("1st", stringList.get(0));
    assertEquals("2nd", stringList.get(1));
    assertEquals("third", stringList.get(2));

    Bundle finalInnerBundle = finalBundle.getBundle("nested");
    assertEquals(1, finalInnerBundle.getInt("inner"));
    finalBundle = finalInnerBundle.getBundle("nested bundle");
    assertEquals("2", finalBundle.getString("inner"));

    stringList = finalBundle.getStringArrayList("deep list");
    assertEquals(2, stringList.size());
    assertEquals("7", stringList.get(0));
    assertEquals("8", stringList.get(1));
}

From source file:com.reliqartz.firsttipcalc.gui.SplitterFragment.java

@Override
public void onSaveInstanceState(Bundle outState) {
    super.onSaveInstanceState(outState);
    outState.putDouble(FINAL_BILL, mFinalBill);
}

From source file:com.zachrohde.gpsautodash.MainActivity.java

@Override
public void onSaveInstanceState(Bundle outState) {
    super.onSaveInstanceState(outState);

    // When the activity is ended, save the current theme and distance traveled.
    outState.putInt("theme", mThemeId);
    outState.putDouble("distance", GPSService.mDistanceTraveled);
}

From source file:org.wheelmap.android.fragment.EditPositionFragment.java

@Override
public void onSaveInstanceState(Bundle outState) {
    outState.putDouble(Extra.LATITUDE, mCrrLatitude);
    outState.putDouble(Extra.LONGITUDE, mCrrLongitude);

    super.onSaveInstanceState(outState);
}

From source file:com.googlecode.android_scripting.facade.AndroidFacade.java

private static void putNestedJSONObject(JSONObject jsonObject, Bundle bundle) throws JSONException {
    JSONArray names = jsonObject.names();
    for (int i = 0; i < names.length(); i++) {
        String name = names.getString(i);
        Object data = jsonObject.get(name);
        if (data == null) {
            continue;
        }//w  w  w.  jav  a 2  s.  c om
        if (data instanceof Integer) {
            bundle.putInt(name, ((Integer) data).intValue());
        }
        if (data instanceof Float) {
            bundle.putFloat(name, ((Float) data).floatValue());
        }
        if (data instanceof Double) {
            bundle.putDouble(name, ((Double) data).doubleValue());
        }
        if (data instanceof Long) {
            bundle.putLong(name, ((Long) data).longValue());
        }
        if (data instanceof String) {
            bundle.putString(name, (String) data);
        }
        if (data instanceof Boolean) {
            bundle.putBoolean(name, ((Boolean) data).booleanValue());
        }
        // Nested JSONObject
        if (data instanceof JSONObject) {
            Bundle nestedBundle = new Bundle();
            bundle.putBundle(name, nestedBundle);
            putNestedJSONObject((JSONObject) data, nestedBundle);
        }
        // Nested JSONArray. Doesn't support mixed types in single array
        if (data instanceof JSONArray) {
            // Empty array. No way to tell what type of data to pass on, so skipping
            if (((JSONArray) data).length() == 0) {
                Log.e("Empty array not supported in nested JSONObject, skipping");
                continue;
            }
            // Integer
            if (((JSONArray) data).get(0) instanceof Integer) {
                int[] integerArrayData = new int[((JSONArray) data).length()];
                for (int j = 0; j < ((JSONArray) data).length(); ++j) {
                    integerArrayData[j] = ((JSONArray) data).getInt(j);
                }
                bundle.putIntArray(name, integerArrayData);
            }
            // Double
            if (((JSONArray) data).get(0) instanceof Double) {
                double[] doubleArrayData = new double[((JSONArray) data).length()];
                for (int j = 0; j < ((JSONArray) data).length(); ++j) {
                    doubleArrayData[j] = ((JSONArray) data).getDouble(j);
                }
                bundle.putDoubleArray(name, doubleArrayData);
            }
            // Long
            if (((JSONArray) data).get(0) instanceof Long) {
                long[] longArrayData = new long[((JSONArray) data).length()];
                for (int j = 0; j < ((JSONArray) data).length(); ++j) {
                    longArrayData[j] = ((JSONArray) data).getLong(j);
                }
                bundle.putLongArray(name, longArrayData);
            }
            // String
            if (((JSONArray) data).get(0) instanceof String) {
                String[] stringArrayData = new String[((JSONArray) data).length()];
                for (int j = 0; j < ((JSONArray) data).length(); ++j) {
                    stringArrayData[j] = ((JSONArray) data).getString(j);
                }
                bundle.putStringArray(name, stringArrayData);
            }
            // Boolean
            if (((JSONArray) data).get(0) instanceof Boolean) {
                boolean[] booleanArrayData = new boolean[((JSONArray) data).length()];
                for (int j = 0; j < ((JSONArray) data).length(); ++j) {
                    booleanArrayData[j] = ((JSONArray) data).getBoolean(j);
                }
                bundle.putBooleanArray(name, booleanArrayData);
            }
        }
    }
}

From source file:org.wheelmap.android.fragment.EditPositionFragment.java

public void save() {
    Bundle b = new Bundle();
    b.putDouble(Extra.LATITUDE, mCrrLatitude);
    b.putDouble(Extra.LONGITUDE, mCrrLongitude);
    Intent intent = getActivity().getIntent().putExtras(b);
    getActivity().setResult(Activity.RESULT_OK, intent);
    getActivity().finish();//from w w  w . j a v a  2s  .  c  o  m
}