List of usage examples for android.os Bundle putIntArray
public void putIntArray(@Nullable String key, @Nullable int[] value)
From source file:androidx.navigation.NavController.java
/** * Saves all navigation controller state to a Bundle. * * <p>State may be restored from a bundle returned from this method by calling * {@link #restoreState(Bundle)}. Saving controller state is the responsibility * of a {@link NavHost}.</p>/*from w w w.j av a2 s . c om*/ * * @return saved state for this controller */ @Nullable public Bundle saveState() { Bundle b = null; if (mGraphId != 0) { b = new Bundle(); b.putInt(KEY_GRAPH_ID, mGraphId); } ArrayList<String> navigatorNames = new ArrayList<>(); Bundle navigatorState = new Bundle(); for (Map.Entry<String, Navigator<? extends NavDestination>> entry : mNavigatorProvider.getNavigators() .entrySet()) { String name = entry.getKey(); Bundle savedState = entry.getValue().onSaveState(); if (savedState != null) { navigatorNames.add(name); navigatorState.putBundle(name, entry.getValue().onSaveState()); } } if (!navigatorNames.isEmpty()) { if (b == null) { b = new Bundle(); } navigatorState.putStringArrayList(KEY_NAVIGATOR_STATE_NAMES, navigatorNames); b.putBundle(KEY_NAVIGATOR_STATE, navigatorState); } if (!mBackStack.isEmpty()) { if (b == null) { b = new Bundle(); } int[] backStack = new int[mBackStack.size()]; int index = 0; for (NavDestination destination : mBackStack) { backStack[index++] = destination.getId(); } b.putIntArray(KEY_BACK_STACK_IDS, backStack); } return b; }
From source file:gov.wa.wsdot.android.wsdot.ui.trafficmap.TrafficMapActivity.java
@Override public boolean onClusterClick(Cluster<CameraItem> cluster) { mTracker = ((WsdotApplication) getApplication()).getDefaultTracker(); if (isCameraGroup(cluster)) { mTracker = ((WsdotApplication) getApplication()).getDefaultTracker(); mTracker.setScreenName("/Traffic Map/Camera Group"); mTracker.send(new HitBuilders.ScreenViewBuilder().build()); Bundle b = new Bundle(); Intent intent;/*from www . j a va2 s . c o m*/ intent = new Intent(this, CameraListActivity.class); // Load camera ids into array for bundle. int cameraIds[] = new int[cluster.getSize()]; String cameraUrls[] = new String[cluster.getSize()]; int index = 0; for (CameraItem camera : cluster.getItems()) { cameraIds[index] = camera.getCameraId(); cameraUrls[index] = camera.getImageUrl(); index++; } b.putStringArray("cameraUrls", cameraUrls); b.putIntArray("cameraIds", cameraIds); intent.putExtras(b); TrafficMapActivity.this.startActivity(intent); } else { mTracker.setScreenName("/Traffic Map/Camera Cluster"); mTracker.send(new HitBuilders.ScreenViewBuilder().build()); LatLngBounds.Builder builder = LatLngBounds.builder(); for (ClusterItem item : cluster.getItems()) { builder.include(item.getPosition()); } // Get the LatLngBounds final LatLngBounds bounds = builder.build(); // Animate camera to the bounds try { mMap.animateCamera(CameraUpdateFactory.newLatLngBounds(bounds, 100)); } catch (Exception e) { e.printStackTrace(); } } return true; }
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 www . ja v a 2s . com*/ 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: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 w w w . j a v a 2s.c o m 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; }
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 a 2 s . com*/ 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:com.httrack.android.HTTrackActivity.java
/** Save instance state. **/ protected void saveInstanceState(final Bundle outState) { // Save current state. There is no guarantee than the application is going // to be killed/restored, however. // Save current pane savePaneFields();/*from w w w . j a va 2 s. c o m*/ // Save settings to bundle // Serialized session ID, used to reclain the fragment runner if any outState.putString("com.httrack.android.sessionID", sessionID); // Version ID outState.putInt("com.httrack.android.version", versionCode); // Map keys outState.putParcelable("com.httrack.android.map", mapper.serialize()); // Current pane outState.putInt("com.httrack.android.pane_id", pane_id); // Current focus id outState.putIntArray("com.httrack.android.focus_id", getCurrentFocusId()); }
From source file:es.upv.riromu.arbre.main.MainActivity.java
@Override protected void onSaveInstanceState(Bundle outState) { FileOutputStream fos;//from ww w . j a v a 2s. c o m if (image != null) { try { String fileName = "temp_image.jpg"; String fileURL = Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_PICTURES) .getPath() + "/" + fileName; fos = new FileOutputStream(fileURL); image.compress(Bitmap.CompressFormat.JPEG, compressRatio, fos); outState.putBoolean("image", true); image.recycle(); System.gc(); } catch (Exception e) { Log.e(TAG, "Error " + e.getMessage()); } } if (state[CROP_IMAGE]) { try { String fileName = "temp_cropped.jpg"; String fileURL = Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_PICTURES) .getPath() + "/" + fileName; fos = new FileOutputStream(fileURL); croppedimage.compress(Bitmap.CompressFormat.JPEG, 100, fos); outState.putBoolean("croppedimage", true); fos.close(); croppedimage.recycle(); System.gc(); } catch (Exception e) { Log.e(TAG, "Error " + e.getMessage()); } } if (state[TREAT_IMAGE]) { try { String fileName = "temp_treated.jpg"; String fileURL = Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_PICTURES) .getPath() + "/" + fileName; fos = new FileOutputStream(fileURL); ImageView imv = (ImageView) findViewById(R.id.image_intro); ((BitmapDrawable) imv.getDrawable()).getBitmap().compress(Bitmap.CompressFormat.JPEG, 100, fos); outState.putBoolean("treatedimage", true); fos.close(); } catch (Exception e) { Log.e(TAG, "Error " + e.getMessage()); } } if (image_uri != null) { outState.putString("image_uri", image_uri.getPath()); } outState.putIntArray("colours", colours); outState.putBoolean("cropping", state[CROP_IMAGE]); outState.putBoolean("treated", state[TREAT_IMAGE]); super.onSaveInstanceState(outState); }
From source file:org.de.jmg.learn.MainActivity.java
@Override protected void onSaveInstanceState(Bundle outState) { super.onSaveInstanceState(outState); try {/* w ww . j a v a 2 s . c o m*/ boolean aend = vok.aend; String filename = vok.getFileName(); Uri uri = vok.getURI(); outState.putInt("SelFragID", mPager.getCurrentItem()); outState.putString("JMGDataDirectory", JMGDataDirectory); outState.putFloat("ActionBarOriginalTextSize", ActionBarOriginalTextSize); if (vok.getGesamtzahl() > 0) { saveFilePrefs(true); if (uri != null) { lib.CheckPermissions(this, uri, false); //this.takePersistableUri(getIntent(), uri,true); } vok.SaveFile(Path.combine(getApplicationInfo().dataDir, "vok.tmp"), uri, vok.getUniCode(), true); outState.putString("vokpath", filename); outState.putInt("vokindex", vok.getIndex()); outState.putInt("vokLastIndex", vok.getLastIndex()); outState.putIntArray("Lernvokabeln", vok.getLernvokabeln()); outState.putInt("Lernindex", vok.getLernIndex()); outState.putBoolean("Unicode", vok.getUniCode()); outState.putBoolean("Cardmode", vok.getCardMode()); outState.putBoolean("aend", aend); outState.putInt("Right", vok.AnzRichtig); outState.putInt("Wrong", vok.AnzFalsch); if (uri != null) outState.putString("URI", uri.toString()); vok.aend = aend; vok.setFileName(filename); vok.setURI(uri); } handlerbackpressed.removeCallbacks(rSetBackPressedFalse); for (DialogInterface dlg : lib.OpenDialogs) { dlg.dismiss(); } lib.OpenDialogs.clear(); } catch (Exception e) { Log.e("OnSaveInstanceState", e.getMessage(), e); e.printStackTrace(); } // outState.putParcelable("vok", vok); }
From source file:android.app.Activity.java
/** * Save the state of any managed dialogs. * * @param outState place to store the saved state. *//* w w w . j av a 2 s . co m*/ private void saveManagedDialogs(Bundle outState) { if (mManagedDialogs == null) { return; } final int numDialogs = mManagedDialogs.size(); if (numDialogs == 0) { return; } Bundle dialogState = new Bundle(); int[] ids = new int[mManagedDialogs.size()]; // save each dialog's bundle, gather the ids for (int i = 0; i < numDialogs; i++) { final int key = mManagedDialogs.keyAt(i); ids[i] = key; final ManagedDialog md = mManagedDialogs.valueAt(i); dialogState.putBundle(savedDialogKeyFor(key), md.mDialog.onSaveInstanceState()); if (md.mArgs != null) { dialogState.putBundle(savedDialogArgsKeyFor(key), md.mArgs); } } dialogState.putIntArray(SAVED_DIALOG_IDS_KEY, ids); outState.putBundle(SAVED_DIALOGS_TAG, dialogState); }