List of usage examples for android.os Bundle putByteArray
@Override public void putByteArray(@Nullable String key, @Nullable byte[] value)
From source file:org.kontalk.ui.NumberValidation.java
@Override protected void onSaveInstanceState(Bundle state) { super.onSaveInstanceState(state); state.putString("name", mName); state.putString("phoneNumber", mPhoneNumber); state.putParcelable("key", mKey); state.putString("passphrase", mPassphrase); state.putByteArray("importedPrivateKey", mImportedPrivateKey); state.putByteArray("importedPublicKey", mImportedPublicKey); }
From source file:com.sentaroh.android.TextFileBrowser.MainActivity.java
private void saveViewContents(Bundle outState) { outState.putInt("SpinnerPos", mViewedFileListSpinner.getSelectedItemPosition()); outState.putInt("FAH_Size", mGlblParms.viewedFileList.size()); try {//from w w w .j av a2 s . c o m ByteArrayOutputStream bos = new ByteArrayOutputStream(1024 * 32); ObjectOutputStream oos = new ObjectOutputStream(bos); for (int i = 0; i < mGlblParms.viewedFileList.size(); i++) { ViewedFileListItem vfli = mGlblParms.viewedFileList.get(i); vfli.writeExternal(oos); } oos.flush(); byte[] buf = bos.toByteArray(); outState.putByteArray("FAH_List", buf); oos.close(); } catch (IOException e) { e.printStackTrace(); } }
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); }//w w w . j a va 2 s.c om 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.Session.java
/** * Save the Session object into the supplied Bundle. This method is intended to be called from an * Activity or Fragment's onSaveInstanceState method in order to preserve Sessions across Activity lifecycle events. * * @param session the Session to save/*from ww w .j ava2s.co m*/ * @param bundle the Bundle to save the Session to */ public static final void saveSession(Session session, Bundle bundle) { if (bundle != null && session != null && !bundle.containsKey(SESSION_BUNDLE_SAVE_KEY)) { ByteArrayOutputStream outputStream = new ByteArrayOutputStream(); try { new ObjectOutputStream(outputStream).writeObject(session); } catch (IOException e) { throw new FacebookException("Unable to save session.", e); } bundle.putByteArray(SESSION_BUNDLE_SAVE_KEY, outputStream.toByteArray()); bundle.putBundle(AUTH_BUNDLE_SAVE_KEY, session.authorizationBundle); } }
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 av a 2 s .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:com.android.calculator2.Calculator.java
@Override protected void onSaveInstanceState(@NonNull Bundle outState) { mEvaluator.cancelAll(true);// w w w. j a va2s .co m // If there's an animation in progress, cancel it first to ensure our state is up-to-date. if (mCurrentAnimator != null) { mCurrentAnimator.cancel(); } super.onSaveInstanceState(outState); outState.putInt(KEY_DISPLAY_STATE, mCurrentState.ordinal()); outState.putCharSequence(KEY_UNPROCESSED_CHARS, mUnprocessedChars); ByteArrayOutputStream byteArrayStream = new ByteArrayOutputStream(); try (ObjectOutput out = new ObjectOutputStream(byteArrayStream)) { mEvaluator.saveInstanceState(out); } catch (IOException e) { // Impossible; No IO involved. throw new AssertionError("Impossible IO exception", e); } outState.putByteArray(KEY_EVAL_STATE, byteArrayStream.toByteArray()); }
From source file:org.jnrain.mobile.accounts.kbs.KBSRegisterActivity.java
@Override protected void onSaveInstanceState(Bundle outState) { super.onSaveInstanceState(outState); /*/*ww w . j a va2 s . c o m*/ * outState.putParcelable("newUID", * editNewUID.onSaveInstanceState()); outState.putParcelable( * "newEmail", editNewEmail.onSaveInstanceState()); * outState.putParcelable( "newPass", * editNewPassword.onSaveInstanceState()); outState.putParcelable( * "repeatPass", editRetypeNewPassword.onSaveInstanceState()); * outState.putParcelable( "newNickname", * editNewNickname.onSaveInstanceState()); * outState.putParcelable("studID", * editStudID.onSaveInstanceState()); outState.putParcelable( * "realname", editRealName.onSaveInstanceState()); * outState.putParcelable("phone", editPhone.onSaveInstanceState()); * outState.putParcelable("captcha", * editCaptcha.onSaveInstanceState()); */ // captcha image ByteArrayOutputStream captchaOutStream = new ByteArrayOutputStream(); Bitmap captchaBitmap = ((BitmapDrawable) imageRegCaptcha.getDrawable()).getBitmap(); captchaBitmap.compress(CompressFormat.PNG, 100, captchaOutStream); outState.putByteArray("captchaImage", captchaOutStream.toByteArray()); }
From source file:com.TagFu.facebook.Session.java
/** * Save the Session object into the supplied Bundle. This method is intended to be called from an Activity or * Fragment's onSaveInstanceState method in order to preserve Sessions across Activity lifecycle events. * * @param session the Session to save//from w ww .j ava 2 s . c o m * @param bundle the Bundle to save the Session to */ public static final void saveSession(final Session session, final Bundle bundle) { if ((bundle != null) && (session != null) && !bundle.containsKey(SESSION_BUNDLE_SAVE_KEY)) { final ByteArrayOutputStream outputStream = new ByteArrayOutputStream(); try { new ObjectOutputStream(outputStream).writeObject(session); } catch (final IOException e) { throw new FacebookException("Unable to save session.", e); } bundle.putByteArray(SESSION_BUNDLE_SAVE_KEY, outputStream.toByteArray()); bundle.putBundle(AUTH_BUNDLE_SAVE_KEY, session.authorizationBundle); } }
From source file:com.google.blockly.android.control.BlocklyController.java
/** * Saves a snapshot of current workspace contents to a temporary cache file, and saves the * filename to the instance state bundle. * @param mSavedInstanceState//from www . jav a 2 s . co m * @return */ public boolean onSaveSnapshot(Bundle mSavedInstanceState) { Bundle blocklyState = new Bundle(); // First attempt to save the workspace to a file. ByteArrayOutputStream out = new ByteArrayOutputStream(); try { mWorkspace.serializeToXml(out); blocklyState.putByteArray(SERIALIZED_WORKSPACE_KEY, out.toByteArray()); } catch (BlocklySerializerException e) { Log.w(TAG, "Error serializing workspace.", e); return false; } finally { try { out.close(); } catch (IOException e) { // Ignore. } } // TODO(#58): Save the rest of the state. // Success! mSavedInstanceState.putBundle(SNAPSHOT_BUNDLE_KEY, blocklyState); return true; }
From source file:com.easy.facebook.android.apicall.GraphApi.java
private String uploadPhotoCall(String message, String friendIDorAlbumID, String urlPicture) throws EasyFacebookError { String postID = null;//from w w w .ja v a 2 s . co m Bundle params = new Bundle(); params.putString("format", "json"); params.putString("access_token", facebook.getAccessToken()); params.putString("message", message); if (urlPicture != null) { String pictureName = urlPicture.substring(urlPicture.lastIndexOf('/'), urlPicture.length()); params.putByteArray(pictureName, Util.loadPicture(urlPicture)); } if (friendIDorAlbumID == null) friendIDorAlbumID = "me"; try { String jsonResponse = Util.openUrl("https://graph.facebook.com/" + friendIDorAlbumID + "/photos", "POST", params); JSONObject objectJSONErrorCheck = new JSONObject(jsonResponse); if (!objectJSONErrorCheck.isNull("error")) { throw new EasyFacebookError(jsonResponse); } JSONObject json = new JSONObject(jsonResponse); if (json.has("id")) postID = json.get("id").toString(); } catch (MalformedURLException e) { throw new EasyFacebookError(e.toString(), "MalformedURLException"); } catch (IOException e) { throw new EasyFacebookError(e.toString(), "IOException"); } catch (JSONException e) { throw new EasyFacebookError(e.toString(), "JSONException"); } return postID; }