List of usage examples for android.os Bundle getIntArray
@Nullable public int[] getIntArray(@Nullable String key)
From source file:es.upv.riromu.arbre.main.MainActivity.java
@Override protected void onRestoreInstanceState(@NonNull Bundle savedInstanceState) { super.onRestoreInstanceState(savedInstanceState); if (savedInstanceState.containsKey("cropping")) { state[CROP_IMAGE] = savedInstanceState.getBoolean("cropping"); }/*from w ww . j a v a 2 s . c o m*/ if (savedInstanceState.containsKey("treated")) { state[TREAT_IMAGE] = savedInstanceState.getBoolean("treated"); } if (savedInstanceState.containsKey("image_uri")) { image_uri = Uri.parse(savedInstanceState.getString("image_uri")); } if (savedInstanceState.getBoolean("image")) { String fileName = "temp_image.jpg"; String fileURL = Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_PICTURES).getPath() + "/" + fileName; File file = new File(fileURL); try { InputStream imageStream = getContentResolver().openInputStream(Uri.fromFile(file)); image = Util.decodeScaledBitmapFromFile(file.getPath(), MAX_SIZE, MAX_SIZE); // image = BitmapFactory.decodeStream(imageStream); } catch (FileNotFoundException e) { Log.e(TAG, e.getMessage()); } } if (state[CROP_IMAGE]) { String fileName = "temp_cropped.jpg"; String fileURL = Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_PICTURES).getPath() + "/" + fileName; File file = new File(fileURL); try { InputStream imageStream = getContentResolver().openInputStream(Uri.fromFile(file)); croppedimage = BitmapFactory.decodeStream(imageStream); imageStream.close(); } catch (FileNotFoundException e) { Log.e(TAG, e.getMessage()); } catch (IOException e) { Log.e(TAG, e.getMessage()); } } if (state[TREAT_IMAGE]) { String fileName = "temp_treated.jpg"; String fileURL = Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_PICTURES).getPath() + "/" + fileName; File file = new File(fileURL); try { InputStream imageStream = getContentResolver().openInputStream(Uri.fromFile(file)); ImageView imv = (ImageView) findViewById(R.id.image_intro); imv.setImageBitmap(BitmapFactory.decodeStream(imageStream)); imageStream.close(); } catch (FileNotFoundException e) { Log.e(TAG, e.getMessage()); } catch (IOException e) { Log.e(TAG, e.getMessage()); } } ImageView imv = (ImageView) findViewById(R.id.image_intro); colours = savedInstanceState.getIntArray("colours"); if ((!state[TREAT_IMAGE]) && state[CROP_IMAGE]) imv.setImageBitmap(croppedimage); else { imv.setImageBitmap(image); } TextView imc = (TextView) findViewById(R.id.textView); imc.setBackgroundColor(Color.rgb(colours[COLOUR_R], colours[COLOUR_G], colours[COLOUR_B])); }
From source file:android.app.Activity.java
/** * Restore the state of any saved managed dialogs. * * @param savedInstanceState The bundle to restore from. *//*from w w w . java 2 s . c o m*/ private void restoreManagedDialogs(Bundle savedInstanceState) { final Bundle b = savedInstanceState.getBundle(SAVED_DIALOGS_TAG); if (b == null) { return; } final int[] ids = b.getIntArray(SAVED_DIALOG_IDS_KEY); final int numDialogs = ids.length; mManagedDialogs = new SparseArray<ManagedDialog>(numDialogs); for (int i = 0; i < numDialogs; i++) { final Integer dialogId = ids[i]; Bundle dialogState = b.getBundle(savedDialogKeyFor(dialogId)); if (dialogState != null) { // Calling onRestoreInstanceState() below will invoke dispatchOnCreate // so tell createDialog() not to do it, otherwise we get an exception final ManagedDialog md = new ManagedDialog(); md.mArgs = b.getBundle(savedDialogArgsKeyFor(dialogId)); md.mDialog = createDialog(dialogId, dialogState, md.mArgs); if (md.mDialog != null) { mManagedDialogs.put(dialogId, md); onPrepareDialog(dialogId, md.mDialog, md.mArgs); md.mDialog.onRestoreInstanceState(dialogState); } } } }