/** * Gets an array of boolean values out of the object. * @param key The key for the value. * @return The boolean values. */ @Nullable public boolean[] getBooleanArray(final String key) { return this.bundle.getBooleanArray(key); }
@Test public void booleanArray() { boolean [] arr = new boolean[] { false, true }; bundle.putBooleanArray("foo", arr); assertThat(bundle.getBooleanArray("foo")).isEqualTo(arr); assertThat(bundle.getBooleanArray("bar")).isNull(); }
when(bundle.getBooleanArray(anyString())).thenAnswer(get);
@NonNull @Override public Dialog onCreateDialog(final Bundle savedInstanceState) { selectedChoices = getArguments().getBooleanArray(ARG_SELECTED_CHOICES); ArrayList<Label> choices = getChoices(); List<String> selected = new ArrayList<>(); if (selectedChoices != null) { for (int i = 0; i < choices.size(); i++) { if (selectedChoices[i]) { selected.add(choices.get(i).name()); } } } adapter = new GroupAdapter(); for (Label label : getChoices()) { adapter.add(new LabelDialogItem(label, selected.contains(label.name()))); } adapter.setOnItemClickListener(this); return createDialogBuilder() .adapter(adapter, null) .negativeText(R.string.cancel) .neutralText(R.string.clear) .positiveText(R.string.apply) .onNeutral((dialog, which) -> { Arrays.fill(getArguments().getBooleanArray(ARG_SELECTED_CHOICES), false); onResult(RESULT_OK); }) .onPositive((dialog, which) -> onResult(RESULT_OK)) .build(); }
@Test public void getWrongType() { bundle.putFloat("foo", 5f); assertThat(bundle.getCharArray("foo")).isNull(); assertThat(bundle.getInt("foo")).isEqualTo(0); assertThat(bundle.getIntArray("foo")).isNull(); assertThat(bundle.getIntegerArrayList("foo")).isNull(); assertThat(bundle.getShort("foo")).isEqualTo((short) 0); assertThat(bundle.getShortArray("foo")).isNull(); assertThat(bundle.getBoolean("foo")).isFalse(); assertThat(bundle.getBooleanArray("foo")).isNull(); assertThat(bundle.getLong("foo")).isEqualTo(0); assertThat(bundle.getLongArray("foo")).isNull(); assertThat(bundle.getFloatArray("foo")).isNull(); assertThat(bundle.getDouble("foo")).isEqualTo(0.0); assertThat(bundle.getDoubleArray("foo")).isNull(); assertThat(bundle.getString("foo")).isNull(); assertThat(bundle.getStringArray("foo")).isNull(); assertThat(bundle.getStringArrayList("foo")).isNull(); assertThat(bundle.getBundle("foo")).isNull(); assertThat((Parcelable) bundle.getParcelable("foo")).isNull(); assertThat(bundle.getParcelableArray("foo")).isNull(); assertThat(bundle.getParcelableArrayList("foo")).isNull(); bundle.putInt("foo", 1); assertThat(bundle.getFloat("foo")).isEqualTo(0.0f); }
/** * Fetches the expandable state map from the saved instance state {@link Bundle} * and restores the expanded states of all of the list items. * <p> * Should be called from {@link Activity#onRestoreInstanceState(Bundle)} in * the {@link Activity} that hosts the RecyclerView that this * {@link ExpandableRecyclerViewAdapter} is attached to. * <p> * * @param savedInstanceState The {@code Bundle} from which the expanded * state map is loaded */ public void onRestoreInstanceState(Bundle savedInstanceState) { if (savedInstanceState == null || !savedInstanceState.containsKey(EXPAND_STATE_MAP)) { return; } expandableList.expandedGroupIndexes = savedInstanceState.getBooleanArray(EXPAND_STATE_MAP); notifyDataSetChanged(); }
assertArrayEquals(originalBundle.getBooleanArray(BOOLEAN_ARRAY_KEY), cachedBundle.getBooleanArray(BOOLEAN_ARRAY_KEY)); assertEquals(originalBundle.getByte(BYTE_KEY), cachedBundle.getByte(BYTE_KEY)); assertArrayEquals(originalBundle.getByteArray(BYTE_ARRAY_KEY), cachedBundle.getByteArray(BYTE_ARRAY_KEY));
public boolean[] getBooleanArray(Bundle state, String key) { return state.getBooleanArray(key + mBaseKey); }
/** * Retrieve extended data from the request. * * @param name The name of the desired item. * @return the value of an item that previously added with putExtra() or * null if no boolean array value was found. * @see #putExtra(String, boolean[]) */ public boolean[] getBooleanArrayExtra(String name) { return mExtras == null ? null : mExtras.getBooleanArray(name); }
@Override public void onCreate(@Nullable Bundle savedInstanceState) { super.onCreate(savedInstanceState); if ( savedInstanceState == null) return; //get your stuff from savedInstanceState //Example boolean[] array = savedInstanceState.getBooleanArray("yourkey"); }
public void onRestoreInstanceState(Bundle savedInstanceState) { if (savedInstanceState == null || !savedInstanceState.containsKey(KEY_STATES)) { return; } mExpandStates = savedInstanceState.getBooleanArray(KEY_STATES); updateIndexes(); }
@Override protected void onSaveInstanceState (Bundle outState) { super.onSaveInstanceState(outState); outState.putBooleanArray(SOME_CONSTANT_STRING,this.savedSelection); } @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); if (savedInstanceState!=null) { this.savedSelection=savedInstanceState.getBooleanArray(SOME_CONSTANT_STRING); } }
@Override @SuppressWarnings("unchecked") public void onCreate(@Nullable final Bundle savedInstanceState) { super.onCreate(savedInstanceState); if (savedInstanceState != null) { mNewValues.clear(); mNewValues.addAll((Set<String>) savedInstanceState.getSerializable(TAG + ".mNewValues")); mSelectedItems = savedInstanceState.getBooleanArray(TAG + ".mSelectedItems"); mPreferenceChanged = savedInstanceState.getBoolean(TAG + ".mPreferenceChanged"); mRestoredState = true; } } }
@Override public void setUserInput(Bundle savedInput) { if (savedInput == null) { return; } final boolean[] answers = savedInput.getBooleanArray(KEY_ANSWER); if (null == answers) { return; } for (int i = 0; i < answers.length; i++) { mListView.setItemChecked(i, answers[i]); } }
protected void onActivityResult(int requestCode, int resultCode, Intent data) { if (requestCode == 1) { Toast.makeText(this, "Productos Recibidos", Toast.LENGTH_SHORT) .show(); if (data != null) { Bundle bundle = data.getExtras(); child = bundle.getStringArrayList("child"); isChecked = bundle.getBooleanArray("selected"); // We will inflate the view with the table as a parent but not append it View newView = LayoutInflater.from(getBaseContext()) .inflate(R.layout.your_row_layout, table, false); // Refresh the data in your view // ... // Finally add it to the table table.addView(newView); // here is my problem } } }
@Override protected void onCreate(final Bundle savedInstanceState) { super.onCreate(savedInstanceState); if (savedInstanceState == null) { handleIntent(getIntent()); } else { shouldShowRequestPermissionRationale = savedInstanceState.getBooleanArray(SAVE_RATIONALE); } }
/***************************************************** * * Called when the fragment is created. * *****************************************************/ @Override public void onCreate( Bundle savedInstanceState ) { super.onCreate( savedInstanceState ); // See if we saved an "is checked" array if ( savedInstanceState != null ) { boolean[] assetIsCheckedArray = savedInstanceState.getBooleanArray( BUNDLE_KEY_ASSET_IS_CHECKED_ARRAY ); mAssetIsCheckedArrayList = BooleanUtils.arrayListFrom( assetIsCheckedArray ); } }
@Override public void setUserInput(Bundle savedInput) { if (savedInput == null) { return; } mAnswers = savedInput.getBooleanArray(KEY_ANSWERS); if (mAnswers == null) { return; } final ListAdapter adapter = mListView.getAdapter(); for (int i = 0; i < mAnswers.length; i++) { mListView.performItemClick(mListView.getChildAt(i), i, adapter.getItemId(i)); } }
@Override public void setUserInput(Bundle savedInput) { if (savedInput == null) { return; } mAnswers = savedInput.getBooleanArray(KEY_ANSWERS); if (mAnswers == null) { initAnswerSpace(); return; } ListAdapter adapter = mListView.getAdapter(); for (int i = 0; i < mAnswers.length; i++) { mListView.performItemClick(mListView.getChildAt(i), i, adapter.getItemId(i)); } }
@Override public void onActivityCreated(@Nullable Bundle savedInstanceState) { super.onActivityCreated(savedInstanceState); if (activity == null) activity = (AppCompatActivity) getActivity(); HeavyInstanceStorage storage = HeavyInstanceStorage.getInstance(getFragmentManager()); if (storage != null) { Bundle heavyInstance = storage.popData(HEAVY_STATE_TAG); if (heavyInstance != null) pieces = heavyInstance.getBooleanArray(TAG_PIECES); } if (savedInstanceState != null) { allPiecesCount = savedInstanceState.getInt(TAG_ALL_PIECES_COUNT); pieceSize = savedInstanceState.getInt(TAG_PIECE_SIZE); downloadedPieces = savedInstanceState.getInt(TAG_DOWNLOADED_PIECES); } pieceMap.setPieces(pieces); updatePieceCounter(); }