List of usage examples for android.os Bundle putFloat
@Override public void putFloat(@Nullable String key, float value)
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); }/* 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); } 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:de.sourcestream.movieDB.controller.TVDetails.java
/** * Called to ask the fragment to save its current dynamic state, * so it can later be reconstructed in a new instance of its process is restarted. * * @param outState Bundle in which to place your saved state. *//*from ww w. j av a2 s . co m*/ @Override public void onSaveInstanceState(Bundle outState) { super.onSaveInstanceState(outState); // Used to avoid bug where we add item in the back stack // and if we change orientation twice the item from the back stack has null values if (save != null && save.getInt("timeOut") == 1) save = null; save = null; if (save != null) { if (tvDetailsCast != null) save.putInt("lastVisitedPerson", tvDetailsCast.getLastVisitedPerson()); outState.putBundle("save", save); if (addToBackStack) { activity.addTvDetailsBundle(save); addToBackStack = false; } } else { Bundle send = new Bundle(); send.putInt("currentId", currentId); if (request != null && request.getStatus() == AsyncTask.Status.RUNNING) { timeOut = 1; request.cancel(true); } send.putInt("timeOut", timeOut); send.putString("title", title); if (timeOut == 0) { // HomePage send.putInt("homeIconCheck", homeIconCheck); if (homeIconCheck == 0) send.putString("homepage", homeIconUrl); // Gallery icon send.putInt("galleryIconCheck", galleryIconCheck); if (galleryIconCheck == 0) send.putStringArrayList("galleryList", galleryList); // More icon send.putInt("moreIconCheck", moreIconCheck); // used to pass the data to the castList view send.putParcelableArrayList("seasonList", seasonList); } // TV details info begins here if (tvDetailsInfo != null) { // Backdrop path send.putInt("backDropCheck", tvDetailsInfo.getBackDropCheck()); if (tvDetailsInfo.getBackDropCheck() == 0 && tvDetailsInfo.getBackDropPath().getTag() != null) send.putString("backDropUrl", tvDetailsInfo.getBackDropPath().getTag().toString()); // Poster path url if (tvDetailsInfo.getPosterPath().getTag() != null) send.putString("posterPathURL", tvDetailsInfo.getPosterPath().getTag().toString()); // Rating send.putFloat("rating", tvDetailsInfo.getRatingBar().getRating()); send.putString("voteCount", tvDetailsInfo.getVoteCount().getText().toString()); // Title send.putString("titleText", tvDetailsInfo.getTitle().getText().toString()); // Status send.putString("status", tvDetailsInfo.getStatusText().getText().toString()); // Type send.putString("typeText", tvDetailsInfo.getTypeText().getText().toString()); // Episode runtime send.putString("episodeRuntime", tvDetailsInfo.getEpisodeRuntime().getText().toString()); // Number of episodes send.putString("numberOfEpisodesText", tvDetailsInfo.getNumberOfEpisodesText().getText().toString()); // Number of seasons send.putString("numberOfSeasonsText", tvDetailsInfo.getNumberOfSeasonsText().getText().toString()); // First air date send.putString("firstAirDateText", tvDetailsInfo.getFirstAirDateText().getText().toString()); // Last air date send.putString("lastAirDateText", tvDetailsInfo.getLastAirDateText().getText().toString()); // Genres send.putString("genres", tvDetailsInfo.getGenres().getText().toString()); // Production countries send.putString("productionCountries", tvDetailsInfo.getCountries().getText().toString()); // Production companies send.putString("productionCompanies", tvDetailsInfo.getCompanies().getText().toString()); // Similar list if (tvDetailsInfo.getSimilarList() != null && tvDetailsInfo.getSimilarList().size() > 0) send.putParcelableArrayList("similarList", tvDetailsInfo.getSimilarList()); } // TV details info ends here // TV details cast starts here if (tvDetailsCast != null) { send.putParcelableArrayList("castList", castList); send.putInt("lastVisitedPerson", tvDetailsCast.getLastVisitedPerson()); } // TV details cast ends here if (tvDetailsOverview != null) send.putString("overview", tvDetailsOverview.getOverview().getText().toString()); outState.putBundle("save", send); save = send; if (addToBackStack) { activity.addTvDetailsBundle(send); addToBackStack = false; } } }
From source file:de.sourcestream.movieDB.controller.MovieDetails.java
/** * Called to ask the fragment to save its current dynamic state, * so it can later be reconstructed in a new instance of its process is restarted. * * @param outState Bundle in which to place your saved state. *///from ww w. j av a 2s. c om @Override public void onSaveInstanceState(Bundle outState) { super.onSaveInstanceState(outState); // Used to avoid bug where we add item in the back stack // and if we change orientation twice the item from the back stack has null values if (save != null && save.getInt("timeOut") == 1) save = null; if (save != null) { if (movieDetailsCast != null) save.putInt("lastVisitedPerson", movieDetailsCast.getLastVisitedPerson()); outState.putBundle("save", save); if (addToBackStack) { activity.addMovieDetailsBundle(save); addToBackStack = false; } } else { Bundle send = new Bundle(); send.putInt("currentId", currentId); if (request != null && request.getStatus() == AsyncTask.Status.RUNNING) { timeOut = 1; request.cancel(true); } send.putInt("timeOut", timeOut); send.putString("title", title); if (timeOut == 0) { // HomePage send.putInt("homeIconCheck", homeIconCheck); if (homeIconCheck == 0) send.putString("homepage", homeIconUrl); // Gallery icon send.putInt("galleryIconCheck", galleryIconCheck); if (galleryIconCheck == 0) send.putStringArrayList("galleryList", galleryList); // Trailer icon send.putInt("trailerIconCheck", trailerIconCheck); if (trailerIconCheck == 0) send.putStringArrayList("trailerList", trailerList); // More icon send.putInt("moreIconCheck", moreIconCheck); // Movie details info begins here if (movieDetailsInfo != null) { // Backdrop path send.putInt("backDropCheck", movieDetailsInfo.getBackDropCheck()); if (movieDetailsInfo.getBackDropCheck() == 0 && movieDetailsInfo.getBackDropPath().getTag() != null) send.putString("backDropUrl", movieDetailsInfo.getBackDropPath().getTag().toString()); // Poster path url if (movieDetailsInfo.getPosterPath().getTag() != null) send.putString("posterPathURL", movieDetailsInfo.getPosterPath().getTag().toString()); // Rating send.putFloat("rating", movieDetailsInfo.getRatingBar().getRating()); send.putString("voteCount", movieDetailsInfo.getVoteCount().getText().toString()); // Title send.putString("titleText", movieDetailsInfo.getTitleText().getText().toString()); // Release date send.putString("releaseDate", movieDetailsInfo.getReleaseDate().getText().toString()); // Status send.putString("status", movieDetailsInfo.getStatusText().getText().toString()); // Tag line send.putString("tagline", movieDetailsInfo.getTagline().getText().toString()); // RunTime send.putString("runTime", movieDetailsInfo.getRuntime().getText().toString()); // Genres send.putString("genres", movieDetailsInfo.getGenres().getText().toString()); // Production countries send.putString("productionCountries", movieDetailsInfo.getCountries().getText().toString()); // Production companies send.putString("productionCompanies", movieDetailsInfo.getCompanies().getText().toString()); // Similar list if (movieDetailsInfo.getSimilarList() != null && movieDetailsInfo.getSimilarList().size() > 0) send.putParcelableArrayList("similarList", movieDetailsInfo.getSimilarList()); } // Movie details info ends here // Movie details cast starts here if (movieDetailsCast != null) { send.putParcelableArrayList("castList", castList); send.putInt("lastVisitedPerson", movieDetailsCast.getLastVisitedPerson()); } // Movie details cast ends here // Overview if (movieDetailsOverview != null) send.putString("overview", movieDetailsOverview.getOverview().getText().toString()); } outState.putBundle("save", send); save = send; if (addToBackStack) { activity.addMovieDetailsBundle(send); addToBackStack = false; } } }
From source file:android.content.pm.PackageParser.java
private Bundle parseMetaData(Resources res, XmlPullParser parser, AttributeSet attrs, Bundle data, String[] outError) throws XmlPullParserException, IOException { TypedArray sa = res.obtainAttributes(attrs, com.android.internal.R.styleable.AndroidManifestMetaData); if (data == null) { data = new Bundle(); }/*from ww w. j a v a 2 s . c o m*/ String name = sa.getNonConfigurationString(com.android.internal.R.styleable.AndroidManifestMetaData_name, 0); if (name == null) { outError[0] = "<meta-data> requires an android:name attribute"; sa.recycle(); return null; } name = name.intern(); TypedValue v = sa.peekValue(com.android.internal.R.styleable.AndroidManifestMetaData_resource); if (v != null && v.resourceId != 0) { //Slog.i(TAG, "Meta data ref " + name + ": " + v); data.putInt(name, v.resourceId); } else { v = sa.peekValue(com.android.internal.R.styleable.AndroidManifestMetaData_value); //Slog.i(TAG, "Meta data " + name + ": " + v); if (v != null) { if (v.type == TypedValue.TYPE_STRING) { CharSequence cs = v.coerceToString(); data.putString(name, cs != null ? cs.toString().intern() : null); } else if (v.type == TypedValue.TYPE_INT_BOOLEAN) { data.putBoolean(name, v.data != 0); } else if (v.type >= TypedValue.TYPE_FIRST_INT && v.type <= TypedValue.TYPE_LAST_INT) { data.putInt(name, v.data); } else if (v.type == TypedValue.TYPE_FLOAT) { data.putFloat(name, v.getFloat()); } else { if (!RIGID_PARSER) { Slog.w(TAG, "<meta-data> only supports string, integer, float, color, boolean, and resource reference types: " + parser.getName() + " at " + mArchiveSourcePath + " " + parser.getPositionDescription()); } else { outError[0] = "<meta-data> only supports string, integer, float, color, boolean, and resource reference types"; data = null; } } } else { outError[0] = "<meta-data> requires an android:value or android:resource attribute"; data = null; } } sa.recycle(); XmlUtils.skipCurrentTag(parser); return data; }