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:es.usc.citius.servando.calendula.fragments.ScheduleTimetableFragment.java

private DosePickerFragment getDosePickerFragment(Medicine med, ScheduleItem item, Schedule s) {
    DosePickerFragment dpf = null;//from  www. j  ava2 s .  c  o  m
    Bundle arguments = new Bundle();

    //        if (med.presentation().equals(Presentation.SYRUP)) {
    //            dpf = new LiquidDosePickerFragment();
    //        }
    if (med.presentation().equals(Presentation.DROPS) || med.presentation().equals(Presentation.PILLS)
            || med.presentation().equals(Presentation.CAPSULES)
            || med.presentation().equals(Presentation.EFFERVESCENT)) {
        dpf = new PillDosePickerFragment();
    } else {
        dpf = new DefaultDosePickerFragment();
        arguments.putSerializable("presentation", med.presentation());
    }
    if (item != null) {
        arguments.putDouble("dose", item.dose());
    } else if (s != null) {
        arguments.putDouble("dose", s.dose());
    }

    dpf.setArguments(arguments);
    return dpf;

}

From source file:com.androzic.MapActivity.java

public boolean waypointTapped(Waypoint waypoint, int x, int y) {
    try {/*from   ww  w . j  a v  a2 s .c  o m*/
        if (application.editingRoute != null) {
            routeSelected = -1;
            waypointSelected = application.getWaypointIndex(waypoint);
            wptQuickAction.show(map, x, y);
            return true;
        } else {
            Location loc = application.getLocationAsLocation();
            FragmentManager fm = getSupportFragmentManager();
            WaypointInfo waypointInfo = (WaypointInfo) fm.findFragmentByTag("waypoint_info");
            if (waypointInfo == null)
                waypointInfo = new WaypointInfo();
            waypointInfo.setWaypoint(waypoint);
            Bundle args = new Bundle();
            args.putDouble("lat", loc.getLatitude());
            args.putDouble("lon", loc.getLongitude());
            waypointInfo.setArguments(args);
            waypointInfo.show(fm, "waypoint_info");
            return true;
        }
    } catch (Exception e) {
        return false;
    }
}

From source file:br.org.funcate.dynamicforms.FragmentDetailActivity.java

private void saveAction() throws Exception {

    FragmentDetail detailFragment = (FragmentDetail) getSupportFragmentManager()
            .findFragmentById(R.id.detailFragment);
    if (detailFragment != null) {
        detailFragment.storeFormItems(false);
    }/*w w  w  . j ava  2 s . c o m*/

    if (sectionObject == null) {
        throw new Exception(this.getString(R.string.session_object_exception));
    }

    // extract and check constraints
    List<String> availableFormNames = TagsManager.getFormNames4Section(sectionObject);
    Bundle formData = null;

    if (availableFormNames.isEmpty()) {
        throw new Exception(this.getString(R.string.session_object_exception));
    }

    for (String formNameIt : availableFormNames) {
        JSONObject formObject = TagsManager.getForm4Name(formNameIt, sectionObject);
        JSONArray formItemsArray = TagsManager.getFormItems(formObject);

        int length = formItemsArray != null ? formItemsArray.length() : 0;
        formData = new Bundle(length);
        ArrayList<String> keys = new ArrayList<String>(length);
        ArrayList<String> types = new ArrayList<String>(length);

        String key = "";
        String value = "";
        String type = "";
        boolean insertKey;// This control flag is used to ignore some types because are simply ignored or are manipulated in other time.

        for (int i = 0; i < length; i++) {
            JSONObject jsonObject = formItemsArray.getJSONObject(i);

            if (jsonObject.has(TAG_KEY))
                key = jsonObject.getString(TAG_KEY).trim();

            if (jsonObject.has(TAG_VALUE)) {
                value = jsonObject.getString(TAG_VALUE).trim();
            }

            if (jsonObject.has(TAG_TYPE)) {
                type = jsonObject.getString(TAG_TYPE).trim();
            }

            if (!key.equals("") && !value.equals("") && !type.equals("")) {

                insertKey = true;

                if (type.equals(TYPE_STRING)) {
                    formData.putString(key, value);
                } else if (type.equals(TYPE_STRINGAREA)) {
                    formData.putString(key, value);
                } else if (type.equals(TYPE_DOUBLE)) {
                    formData.putDouble(key, Double.valueOf(value));
                } else if (type.equals(TYPE_INTEGER)) {
                    formData.putInt(key, Integer.valueOf(value));
                } else if (type.equals(TYPE_DATE)) {
                    formData.putString(key, value);
                } else if (type.equals(TYPE_TIME)) {
                    formData.putString(key, value);
                } else if (type.equals(TYPE_LABEL)) {
                    insertKey = false;
                    //formData.putString(key, value);
                } else if (type.equals(TYPE_LABELWITHLINE)) {
                    insertKey = false;
                    //formData.putString(key, value);
                } else if (type.equals(TYPE_BOOLEAN)) {
                    formData.putBoolean(key, Boolean.valueOf(value));
                } else if (type.equals(TYPE_STRINGCOMBO)) {
                    formData.putString(key, value);
                } else if (type.equals(TYPE_CONNECTEDSTRINGCOMBO)) {
                    formData.putString(key, value);
                } else if (type.equals(TYPE_STRINGMULTIPLECHOICE)) {
                    insertKey = false;
                    //formData.putString(key,value);
                } else if (type.equals(TYPE_PICTURES)) {
                    insertKey = false;
                    // Using the new key to represent a list of image paths. It is manipulated on posterior time.
                    //formData.putString(key,value);
                    decodeFromJson(value, formData);
                }

                if (insertKey) {
                    keys.add(key);
                    types.add(type);
                }

            }
        }
        formData.putStringArrayList(LibraryConstants.FORM_TYPES, types);
        formData.putStringArrayList(LibraryConstants.FORM_KEYS, keys);

        if (sectionObject.has(FormUtilities.ATTR_GEOJSON_TAGS)) {
            JSONObject geojsonGeometry = sectionObject.getJSONObject(FormUtilities.ATTR_GEOJSON_TAGS);
            formData.putString(FormUtilities.ATTR_GEOJSON_TAGS, geojsonGeometry.toString());
        }

        if (pointId >= 0) {
            formData.putLong(FormUtilities.GEOM_ID, pointId);
        }

        if (existingFeatureData != null) {
            formData.putBundle(FormUtilities.ATTR_DATA_VALUES, existingFeatureData);
        }
    }

    if (formData == null) {
        throw new Exception(this.getString(R.string.session_object_exception));
    }
    Intent intent = getIntent();
    intent.putExtra(LibraryConstants.PREFS_KEY_FORM, formData);
    setResult(Activity.RESULT_OK, intent);
    finish();
}

From source file:io.jawg.osmcontributor.ui.fragments.MapFragment.java

@Override
public void onSaveInstanceState(Bundle outState) {
    super.onSaveInstanceState(outState);
    mapView.onSaveInstanceState(outState);
    outState.putParcelable(LOCATION, mapboxMap.getCameraPosition().target);
    outState.putFloat(ZOOM_LEVEL, getZoomLevel());
    outState.putInt(CREATION_MODE, mapMode.ordinal());
    outState.putLong(POI_TYPE_ID, poiTypeSelected == null ? -1 : poiTypeSelected.getId());
    outState.putDouble(LEVEL, currentLevel);
    outState.putBoolean(DISPLAY_OPEN_NOTES, displayOpenNotes);
    outState.putBoolean(DISPLAY_CLOSED_NOTES, displayClosedNotes);

    int markerType = markerSelected == null ? LocationMarkerView.MarkerType.NONE.ordinal()
            : markerSelected.getType().ordinal();
    outState.putInt(MARKER_TYPE, markerType);

    if (markerSelected != null) {
        switch (markerSelected.getType()) {
        case POI:
            markerSelectedId = ((Poi) markerSelected.getRelatedObject()).getId();
            break;
        case NODE_REF:
            markerSelectedId = ((PoiNodeRef) markerSelected.getRelatedObject()).getId();
            break;
        case NOTE:
            markerSelectedId = ((Note) markerSelected.getRelatedObject()).getId();
            break;
        }/*from w w  w .  ja  va 2  s.c om*/
    } else {
        markerSelectedId = -1L;
    }
    outState.putLong(SELECTED_MARKER_ID, markerSelectedId);

    long[] hidden = new long[poiTypeHidden.size()];
    int index = 0;

    for (Long value : poiTypeHidden) {
        hidden[index] = value;
        index++;
    }

    outState.putLongArray(HIDDEN_POI_TYPE, hidden);
}

From source file:cn.edu.zafu.corepage.base.BaseActivity.java

/**
 * ??//from   w ww. j  a v  a  2s  .  c  o m
 *
 * @param outState Bundle
 */
@Override
protected void onSaveInstanceState(Bundle outState) {
    Field[] fields = this.getClass().getDeclaredFields();
    Field.setAccessible(fields, true);
    Annotation[] ans;
    for (Field f : fields) {
        ans = f.getDeclaredAnnotations();
        for (Annotation an : ans) {
            if (an instanceof SaveWithActivity) {
                try {
                    Object o = f.get(this);
                    if (o == null) {
                        continue;
                    }
                    String fieldName = f.getName();
                    if (o instanceof Integer) {
                        outState.putInt(fieldName, f.getInt(this));
                    } else if (o instanceof String) {
                        outState.putString(fieldName, (String) f.get(this));
                    } else if (o instanceof Long) {
                        outState.putLong(fieldName, f.getLong(this));
                    } else if (o instanceof Short) {
                        outState.putShort(fieldName, f.getShort(this));
                    } else if (o instanceof Boolean) {
                        outState.putBoolean(fieldName, f.getBoolean(this));
                    } else if (o instanceof Byte) {
                        outState.putByte(fieldName, f.getByte(this));
                    } else if (o instanceof Character) {
                        outState.putChar(fieldName, f.getChar(this));
                    } else if (o instanceof CharSequence) {
                        outState.putCharSequence(fieldName, (CharSequence) f.get(this));
                    } else if (o instanceof Float) {
                        outState.putFloat(fieldName, f.getFloat(this));
                    } else if (o instanceof Double) {
                        outState.putDouble(fieldName, f.getDouble(this));
                    } else if (o instanceof String[]) {
                        outState.putStringArray(fieldName, (String[]) f.get(this));
                    } else if (o instanceof Parcelable) {
                        outState.putParcelable(fieldName, (Parcelable) f.get(this));
                    } else if (o instanceof Serializable) {
                        outState.putSerializable(fieldName, (Serializable) f.get(this));
                    } else if (o instanceof Bundle) {
                        outState.putBundle(fieldName, (Bundle) f.get(this));
                    }
                } catch (IllegalArgumentException e) {
                    e.printStackTrace();
                } catch (IllegalAccessException e) {
                    e.printStackTrace();
                }
            }
        }
    }

    super.onSaveInstanceState(outState);
}

From source file:com.amsterdam.marktbureau.makkelijkemarkt.DagvergunningFragment.java

/**
 * Save the fragment state//  w ww  .  jav  a 2s . c  o m
 * @param outState state to save to
 */
@Override
public void onSaveInstanceState(Bundle outState) {
    super.onSaveInstanceState(outState);

    // get the possibly changed values from the currently active pager fragments before saving state
    getFragmentValuesByPosition(mCurrentTab);

    // save dagvergunning state
    outState.putInt(MakkelijkeMarktProvider.Dagvergunning.COL_MARKT_ID, mMarktId);
    outState.putString(MakkelijkeMarktProvider.Dagvergunning.COL_DAG, mDag);
    outState.putInt(MakkelijkeMarktProvider.Dagvergunning.COL_ID, mId);
    outState.putString(MakkelijkeMarktProvider.Dagvergunning.COL_ERKENNINGSNUMMER_INVOER_WAARDE,
            mErkenningsnummer);
    outState.putString(MakkelijkeMarktProvider.Dagvergunning.COL_ERKENNINGSNUMMER_INVOER_METHODE,
            mErkenningsnummerInvoerMethode);
    outState.putString(MakkelijkeMarktProvider.Dagvergunning.COL_REGISTRATIE_DATUMTIJD, mRegistratieDatumtijd);
    outState.putDouble(MakkelijkeMarktProvider.Dagvergunning.COL_REGISTRATIE_GEOLOCATIE_LAT,
            mRegistratieGeolocatieLatitude);
    outState.putDouble(MakkelijkeMarktProvider.Dagvergunning.COL_REGISTRATIE_GEOLOCATIE_LONG,
            mRegistratieGeolocatieLongitude);
    outState.putInt(MakkelijkeMarktProvider.Dagvergunning.COL_TOTALE_LENGTE, mTotaleLengte);
    outState.putString(MakkelijkeMarktProvider.Dagvergunning.COL_STATUS_SOLLICITATIE, mSollicitatieStatus);
    outState.putString(MakkelijkeMarktProvider.Dagvergunning.COL_AANWEZIG, mKoopmanAanwezig);
    outState.putInt(MakkelijkeMarktProvider.Dagvergunning.COL_KOOPMAN_ID, mKoopmanId);
    outState.putString(MakkelijkeMarktProvider.Koopman.COL_VOORLETTERS, mKoopmanVoorletters);
    outState.putString(MakkelijkeMarktProvider.Koopman.COL_ACHTERNAAM, mKoopmanAchternaam);
    outState.putString(MakkelijkeMarktProvider.Koopman.COL_FOTO_URL, mKoopmanFoto);
    outState.putInt(MakkelijkeMarktProvider.Dagvergunning.COL_REGISTRATIE_ACCOUNT_ID, mRegistratieAccountId);
    outState.putString(MakkelijkeMarktProvider.Account.COL_NAAM, mRegistratieAccountNaam);
    outState.putInt(MakkelijkeMarktProvider.Dagvergunning.COL_SOLLICITATIE_ID, mSollicitatieId);
    outState.putInt(MakkelijkeMarktProvider.Sollicitatie.COL_SOLLICITATIE_NUMMER, mSollicitatieNummer);
    outState.putString(MakkelijkeMarktProvider.Dagvergunning.COL_NOTITIE, mNotitie);
    outState.putSerializable(STATE_BUNDLE_KEY_PRODUCTS, mProducten);
    outState.putSerializable(STATE_BUNDLE_KEY_PRODUCTS_VAST, mProductenVast);
    outState.putInt(MakkelijkeMarktProvider.Dagvergunning.COL_VERVANGER_ID, mVervangerId);
    outState.putString(MakkelijkeMarktProvider.Dagvergunning.COL_VERVANGER_ERKENNINGSNUMMER,
            mVervangerErkenningsnummer);

    // save viewpager state
    outState.putInt(CURRENT_TAB, mCurrentTab);
    getChildFragmentManager().putFragment(outState, KOOPMAN_FRAGMENT_TAG, mKoopmanFragment);
    getChildFragmentManager().putFragment(outState, PRODUCT_FRAGMENT_TAG, mProductFragment);
    getChildFragmentManager().putFragment(outState, OVERZICHT_FRAGMENT_TAG, mOverzichtFragment);
}

From source file:com.saulcintero.moveon.fragments.Main.java

@Override
public void onSaveInstanceState(Bundle savedInstanceState) {
    super.onSaveInstanceState(savedInstanceState);
    savedInstanceState.putLong("chronoBase", chronoBaseValue);
    savedInstanceState.putInt("stopStatus", stopStatus);
    savedInstanceState.putInt("pauseOrResumeStatus", pauseOrResumeStatus);
    savedInstanceState.putInt("activity", activity);
    savedInstanceState.putInt("activityCamera", ACTIVITY_CAMERA);
    savedInstanceState.putInt("pictureCounter", pictureCounter);
    savedInstanceState.putInt("zoom", mapView.getZoomLevel());
    savedInstanceState.putString("gpsStatus", gpsStatus);
    savedInstanceState.putString("gpsAccuracy", gpsAccuracy);
    savedInstanceState.putString("distance", mDistance);
    savedInstanceState.putString("speed", mSpeed);
    savedInstanceState.putString("maxSpeed", mMaxSpeed);
    savedInstanceState.putString("latitude", mLatitude);
    savedInstanceState.putString("longitude", mLongitude);
    savedInstanceState.putString("altitude", mAltitude);
    savedInstanceState.putString("steps", mSteps);
    savedInstanceState.putString("hr", mHeartRate);
    savedInstanceState.putString("cadence", mCadence);
    savedInstanceState.putString("path", path);
    savedInstanceState.putString("file", file);
    savedInstanceState.putBoolean("pathOverlayChangeColor", pathOverlayChangeColor);
    savedInstanceState.putBoolean("launchPractice", launchPractice);
    savedInstanceState.putBoolean("isExpanded", isExpanded);
    savedInstanceState.putBoolean("followLocation", followLocation);
    savedInstanceState.putBoolean("hasBeenResumed", hasBeenResumed);
    savedInstanceState.putBoolean("isMetric", isMetric);
    if (centerPoint != null) {
        savedInstanceState.putDouble("latCenterPoint", centerPoint.getLatitude());
        savedInstanceState.putDouble("lonCenterPoint", centerPoint.getLongitude());
    }/*ww w . jav  a2 s  .  c om*/
}

From source file:com.facebook.SharedPreferencesTokenCache.java

private void deserializeKey(String key, Bundle bundle) throws JSONException {
    String jsonString = cache.getString(key, "{}");
    JSONObject json = new JSONObject(jsonString);

    String valueType = json.getString(JSON_VALUE_TYPE);

    if (valueType.equals(TYPE_BOOLEAN)) {
        bundle.putBoolean(key, json.getBoolean(JSON_VALUE));
    } else if (valueType.equals(TYPE_BOOLEAN_ARRAY)) {
        JSONArray jsonArray = json.getJSONArray(JSON_VALUE);
        boolean[] array = new boolean[jsonArray.length()];
        for (int i = 0; i < array.length; i++) {
            array[i] = jsonArray.getBoolean(i);
        }//from w  w w. j a v a2 s.c  o  m
        bundle.putBooleanArray(key, array);
    } else if (valueType.equals(TYPE_BYTE)) {
        bundle.putByte(key, (byte) json.getInt(JSON_VALUE));
    } else if (valueType.equals(TYPE_BYTE_ARRAY)) {
        JSONArray jsonArray = json.getJSONArray(JSON_VALUE);
        byte[] array = new byte[jsonArray.length()];
        for (int i = 0; i < array.length; i++) {
            array[i] = (byte) jsonArray.getInt(i);
        }
        bundle.putByteArray(key, array);
    } else if (valueType.equals(TYPE_SHORT)) {
        bundle.putShort(key, (short) json.getInt(JSON_VALUE));
    } else if (valueType.equals(TYPE_SHORT_ARRAY)) {
        JSONArray jsonArray = json.getJSONArray(JSON_VALUE);
        short[] array = new short[jsonArray.length()];
        for (int i = 0; i < array.length; i++) {
            array[i] = (short) jsonArray.getInt(i);
        }
        bundle.putShortArray(key, array);
    } else if (valueType.equals(TYPE_INTEGER)) {
        bundle.putInt(key, json.getInt(JSON_VALUE));
    } else if (valueType.equals(TYPE_INTEGER_ARRAY)) {
        JSONArray jsonArray = json.getJSONArray(JSON_VALUE);
        int[] array = new int[jsonArray.length()];
        for (int i = 0; i < array.length; i++) {
            array[i] = jsonArray.getInt(i);
        }
        bundle.putIntArray(key, array);
    } else if (valueType.equals(TYPE_LONG)) {
        bundle.putLong(key, json.getLong(JSON_VALUE));
    } else if (valueType.equals(TYPE_LONG_ARRAY)) {
        JSONArray jsonArray = json.getJSONArray(JSON_VALUE);
        long[] array = new long[jsonArray.length()];
        for (int i = 0; i < array.length; i++) {
            array[i] = jsonArray.getLong(i);
        }
        bundle.putLongArray(key, array);
    } else if (valueType.equals(TYPE_FLOAT)) {
        bundle.putFloat(key, (float) json.getDouble(JSON_VALUE));
    } else if (valueType.equals(TYPE_FLOAT_ARRAY)) {
        JSONArray jsonArray = json.getJSONArray(JSON_VALUE);
        float[] array = new float[jsonArray.length()];
        for (int i = 0; i < array.length; i++) {
            array[i] = (float) jsonArray.getDouble(i);
        }
        bundle.putFloatArray(key, array);
    } else if (valueType.equals(TYPE_DOUBLE)) {
        bundle.putDouble(key, json.getDouble(JSON_VALUE));
    } else if (valueType.equals(TYPE_DOUBLE_ARRAY)) {
        JSONArray jsonArray = json.getJSONArray(JSON_VALUE);
        double[] array = new double[jsonArray.length()];
        for (int i = 0; i < array.length; i++) {
            array[i] = jsonArray.getDouble(i);
        }
        bundle.putDoubleArray(key, array);
    } else if (valueType.equals(TYPE_CHAR)) {
        String charString = json.getString(JSON_VALUE);
        if (charString != null && charString.length() == 1) {
            bundle.putChar(key, charString.charAt(0));
        }
    } else if (valueType.equals(TYPE_CHAR_ARRAY)) {
        JSONArray jsonArray = json.getJSONArray(JSON_VALUE);
        char[] array = new char[jsonArray.length()];
        for (int i = 0; i < array.length; i++) {
            String charString = jsonArray.getString(i);
            if (charString != null && charString.length() == 1) {
                array[i] = charString.charAt(0);
            }
        }
        bundle.putCharArray(key, array);
    } else if (valueType.equals(TYPE_STRING)) {
        bundle.putString(key, json.getString(JSON_VALUE));
    } else if (valueType.equals(TYPE_STRING_LIST)) {
        JSONArray jsonArray = json.getJSONArray(JSON_VALUE);
        int numStrings = jsonArray.length();
        ArrayList<String> stringList = new ArrayList<String>(numStrings);
        for (int i = 0; i < numStrings; i++) {
            Object jsonStringValue = jsonArray.get(i);
            stringList.add(i, jsonStringValue == JSONObject.NULL ? null : (String) jsonStringValue);
        }
        bundle.putStringArrayList(key, stringList);
    }
}

From source file:com.facebook.LegacyTokenHelper.java

private void deserializeKey(String key, Bundle bundle) throws JSONException {
    String jsonString = cache.getString(key, "{}");
    JSONObject json = new JSONObject(jsonString);

    String valueType = json.getString(JSON_VALUE_TYPE);

    if (valueType.equals(TYPE_BOOLEAN)) {
        bundle.putBoolean(key, json.getBoolean(JSON_VALUE));
    } else if (valueType.equals(TYPE_BOOLEAN_ARRAY)) {
        JSONArray jsonArray = json.getJSONArray(JSON_VALUE);
        boolean[] array = new boolean[jsonArray.length()];
        for (int i = 0; i < array.length; i++) {
            array[i] = jsonArray.getBoolean(i);
        }//from www  .  j a v  a 2s.  co m
        bundle.putBooleanArray(key, array);
    } else if (valueType.equals(TYPE_BYTE)) {
        bundle.putByte(key, (byte) json.getInt(JSON_VALUE));
    } else if (valueType.equals(TYPE_BYTE_ARRAY)) {
        JSONArray jsonArray = json.getJSONArray(JSON_VALUE);
        byte[] array = new byte[jsonArray.length()];
        for (int i = 0; i < array.length; i++) {
            array[i] = (byte) jsonArray.getInt(i);
        }
        bundle.putByteArray(key, array);
    } else if (valueType.equals(TYPE_SHORT)) {
        bundle.putShort(key, (short) json.getInt(JSON_VALUE));
    } else if (valueType.equals(TYPE_SHORT_ARRAY)) {
        JSONArray jsonArray = json.getJSONArray(JSON_VALUE);
        short[] array = new short[jsonArray.length()];
        for (int i = 0; i < array.length; i++) {
            array[i] = (short) jsonArray.getInt(i);
        }
        bundle.putShortArray(key, array);
    } else if (valueType.equals(TYPE_INTEGER)) {
        bundle.putInt(key, json.getInt(JSON_VALUE));
    } else if (valueType.equals(TYPE_INTEGER_ARRAY)) {
        JSONArray jsonArray = json.getJSONArray(JSON_VALUE);
        int[] array = new int[jsonArray.length()];
        for (int i = 0; i < array.length; i++) {
            array[i] = jsonArray.getInt(i);
        }
        bundle.putIntArray(key, array);
    } else if (valueType.equals(TYPE_LONG)) {
        bundle.putLong(key, json.getLong(JSON_VALUE));
    } else if (valueType.equals(TYPE_LONG_ARRAY)) {
        JSONArray jsonArray = json.getJSONArray(JSON_VALUE);
        long[] array = new long[jsonArray.length()];
        for (int i = 0; i < array.length; i++) {
            array[i] = jsonArray.getLong(i);
        }
        bundle.putLongArray(key, array);
    } else if (valueType.equals(TYPE_FLOAT)) {
        bundle.putFloat(key, (float) json.getDouble(JSON_VALUE));
    } else if (valueType.equals(TYPE_FLOAT_ARRAY)) {
        JSONArray jsonArray = json.getJSONArray(JSON_VALUE);
        float[] array = new float[jsonArray.length()];
        for (int i = 0; i < array.length; i++) {
            array[i] = (float) jsonArray.getDouble(i);
        }
        bundle.putFloatArray(key, array);
    } else if (valueType.equals(TYPE_DOUBLE)) {
        bundle.putDouble(key, json.getDouble(JSON_VALUE));
    } else if (valueType.equals(TYPE_DOUBLE_ARRAY)) {
        JSONArray jsonArray = json.getJSONArray(JSON_VALUE);
        double[] array = new double[jsonArray.length()];
        for (int i = 0; i < array.length; i++) {
            array[i] = jsonArray.getDouble(i);
        }
        bundle.putDoubleArray(key, array);
    } else if (valueType.equals(TYPE_CHAR)) {
        String charString = json.getString(JSON_VALUE);
        if (charString != null && charString.length() == 1) {
            bundle.putChar(key, charString.charAt(0));
        }
    } else if (valueType.equals(TYPE_CHAR_ARRAY)) {
        JSONArray jsonArray = json.getJSONArray(JSON_VALUE);
        char[] array = new char[jsonArray.length()];
        for (int i = 0; i < array.length; i++) {
            String charString = jsonArray.getString(i);
            if (charString != null && charString.length() == 1) {
                array[i] = charString.charAt(0);
            }
        }
        bundle.putCharArray(key, array);
    } else if (valueType.equals(TYPE_STRING)) {
        bundle.putString(key, json.getString(JSON_VALUE));
    } else if (valueType.equals(TYPE_STRING_LIST)) {
        JSONArray jsonArray = json.getJSONArray(JSON_VALUE);
        int numStrings = jsonArray.length();
        ArrayList<String> stringList = new ArrayList<String>(numStrings);
        for (int i = 0; i < numStrings; i++) {
            Object jsonStringValue = jsonArray.get(i);
            stringList.add(i, jsonStringValue == JSONObject.NULL ? null : (String) jsonStringValue);
        }
        bundle.putStringArrayList(key, stringList);
    } else if (valueType.equals(TYPE_ENUM)) {
        try {
            String enumType = json.getString(JSON_VALUE_ENUM_TYPE);
            @SuppressWarnings({ "unchecked", "rawtypes" })
            Class<? extends Enum> enumClass = (Class<? extends Enum>) Class.forName(enumType);
            @SuppressWarnings("unchecked")
            Enum<?> enumValue = Enum.valueOf(enumClass, json.getString(JSON_VALUE));
            bundle.putSerializable(key, enumValue);
        } catch (ClassNotFoundException e) {
        } catch (IllegalArgumentException e) {
        }
    }
}

From source file:org.opendatakit.common.android.utilities.AndroidUtils.java

public static Bundle convertToBundle(JSONObject valueMap, final MacroStringExpander expander)
        throws JSONException {
    Bundle b = new Bundle();
    @SuppressWarnings("unchecked")
    Iterator<String> cur = valueMap.keys();
    while (cur.hasNext()) {
        String key = cur.next();//from   www.j  a v  a  2 s .  c om
        if (!valueMap.isNull(key)) {
            Object o = valueMap.get(key);
            if (o instanceof JSONObject) {
                Bundle be = convertToBundle((JSONObject) o, expander);
                b.putBundle(key, be);
            } else if (o instanceof JSONArray) {
                JSONArray a = (JSONArray) o;
                // only non-empty arrays are written into the Bundle
                // first non-null element defines data type
                // for the array
                Object oe = null;
                for (int j = 0; j < a.length(); ++j) {
                    if (!a.isNull(j)) {
                        oe = a.get(j);
                        break;
                    }
                }
                if (oe != null) {
                    if (oe instanceof JSONObject) {
                        Bundle[] va = new Bundle[a.length()];
                        for (int j = 0; j < a.length(); ++j) {
                            if (a.isNull(j)) {
                                va[j] = null;
                            } else {
                                va[j] = convertToBundle((JSONObject) a.getJSONObject(j), expander);
                            }
                        }
                        b.putParcelableArray(key, va);
                    } else if (oe instanceof JSONArray) {
                        throw new JSONException("Unable to convert nested arrays");
                    } else if (oe instanceof String) {
                        String[] va = new String[a.length()];
                        for (int j = 0; j < a.length(); ++j) {
                            if (a.isNull(j)) {
                                va[j] = null;
                            } else {
                                va[j] = a.getString(j);
                            }
                        }
                        b.putStringArray(key, va);
                    } else if (oe instanceof Boolean) {
                        boolean[] va = new boolean[a.length()];
                        for (int j = 0; j < a.length(); ++j) {
                            if (a.isNull(j)) {
                                va[j] = false;
                            } else {
                                va[j] = a.getBoolean(j);
                            }
                        }
                        b.putBooleanArray(key, va);
                    } else if (oe instanceof Integer) {
                        int[] va = new int[a.length()];
                        for (int j = 0; j < a.length(); ++j) {
                            if (a.isNull(j)) {
                                va[j] = 0;
                            } else {
                                va[j] = a.getInt(j);
                            }
                        }
                        b.putIntArray(key, va);
                    } else if (oe instanceof Long) {
                        long[] va = new long[a.length()];
                        for (int j = 0; j < a.length(); ++j) {
                            if (a.isNull(j)) {
                                va[j] = 0;
                            } else {
                                va[j] = a.getLong(j);
                            }
                        }
                        b.putLongArray(key, va);
                    } else if (oe instanceof Double) {
                        double[] va = new double[a.length()];
                        for (int j = 0; j < a.length(); ++j) {
                            if (a.isNull(j)) {
                                va[j] = Double.NaN;
                            } else {
                                va[j] = a.getDouble(j);
                            }
                        }
                        b.putDoubleArray(key, va);
                    }
                }
            } else if (o instanceof String) {
                String v = valueMap.getString(key);
                if (expander != null) {
                    v = expander.expandString(v);
                }
                b.putString(key, v);
            } else if (o instanceof Boolean) {
                b.putBoolean(key, valueMap.getBoolean(key));
            } else if (o instanceof Integer) {
                b.putInt(key, valueMap.getInt(key));
            } else if (o instanceof Long) {
                b.putLong(key, valueMap.getLong(key));
            } else if (o instanceof Double) {
                b.putDouble(key, valueMap.getDouble(key));
            }
        }
    }
    return b;
}