use of android.os.Parcelable in project material-components-android by material-components.
the class BottomNavigationViewTest method testSavedState.
@Test
@SmallTest
public void testSavedState() throws Throwable {
// Select an item other than the first
onView(allOf(withText(mMenuStringContent.get(R.id.destination_profile)), isDescendantOfA(withId(R.id.bottom_navigation)), isDisplayed())).perform(click());
assertTrue(mBottomNavigation.getMenu().findItem(R.id.destination_profile).isChecked());
// Save the state
final Parcelable state = mBottomNavigation.onSaveInstanceState();
// Restore the state into a fresh BottomNavigationView
activityTestRule.runOnUiThread(new Runnable() {
@Override
public void run() {
BottomNavigationView testView = new BottomNavigationView(activityTestRule.getActivity());
testView.inflateMenu(R.menu.bottom_navigation_view_content);
testView.onRestoreInstanceState(state);
assertTrue(testView.getMenu().findItem(R.id.destination_profile).isChecked());
}
});
}
use of android.os.Parcelable in project material-components-android by material-components.
the class TextInputLayout method onSaveInstanceState.
@Override
public Parcelable onSaveInstanceState() {
Parcelable superState = super.onSaveInstanceState();
SavedState ss = new SavedState(superState);
if (mErrorShown) {
ss.error = getError();
}
return ss;
}
use of android.os.Parcelable in project material-components-android by material-components.
the class NavigationViewTest method testHeaderState.
@Test
public void testHeaderState() {
// Open our drawer
onView(withId(R.id.drawer_layout)).perform(openDrawer(GravityCompat.START));
// Inflate a header with a toggle switch and check that it's there in the navigation view
onView(withId(R.id.start_drawer)).perform(inflateHeaderView(R.layout.design_navigation_view_header_switch));
verifyHeaders(R.id.header_frame);
onView(withId(R.id.header_toggle)).check(matches(isNotChecked())).perform(click()).check(matches(isChecked()));
// Save the current state
SparseArray<Parcelable> container = new SparseArray<>();
mNavigationView.saveHierarchyState(container);
// Remove the header
final View header = mNavigationView.findViewById(R.id.header_frame);
onView(withId(R.id.start_drawer)).perform(removeHeaderView(header));
verifyHeaders();
// Inflate the header again
onView(withId(R.id.start_drawer)).perform(inflateHeaderView(R.layout.design_navigation_view_header_switch));
verifyHeaders(R.id.header_frame);
// Restore the saved state
onView(withId(R.id.start_drawer)).perform(restoreHierarchyState(container));
// Confirm that the state was restored
onView(withId(R.id.header_toggle)).check(matches(isChecked()));
}
use of android.os.Parcelable in project material-components-android by material-components.
the class NavigationViewTest method testActionViewState.
@Test
public void testActionViewState() {
// Open our drawer
onView(withId(R.id.drawer_layout)).perform(openDrawer(GravityCompat.START));
final Menu menu = mNavigationView.getMenu();
onView(isActionViewOf(menu, R.id.destination_people)).check(// Not checked by default
matches(isNotChecked())).perform(// Check it
click()).check(matches(isChecked()));
// Remove the other action view to simulate the case where it is not yet inflated
onView(isActionViewOf(menu, R.id.destination_custom)).check(matches(isDisplayed()));
onView(withId(R.id.start_drawer)).perform(removeMenuItem(R.id.destination_custom));
// Save the current state
SparseArray<Parcelable> container = new SparseArray<>();
mNavigationView.saveHierarchyState(container);
// Restore the saved state
onView(withId(R.id.start_drawer)).perform(reinflateMenu(R.menu.navigation_view_content)).perform(restoreHierarchyState(container));
// Checked state should be restored
onView(isActionViewOf(menu, R.id.destination_people)).check(matches(isChecked()));
}
use of android.os.Parcelable in project flow by square.
the class State method toBundle.
Bundle toBundle(KeyParceler parceler) {
Bundle outState = new Bundle();
outState.putParcelable(KEY, parceler.toParcelable(getKey()));
int[] viewIds = new int[viewStateById.size()];
int c = 0;
for (Map.Entry<Integer, SparseArray<Parcelable>> entry : viewStateById.entrySet()) {
Integer viewId = entry.getKey();
viewIds[c++] = viewId;
SparseArray<Parcelable> viewState = entry.getValue();
if (viewState.size() > 0) {
outState.putSparseParcelableArray(VIEW_STATE_PREFIX + viewId, viewState);
}
}
outState.putIntArray(VIEW_STATE_IDS, viewIds);
if (bundle != null && !bundle.isEmpty()) {
outState.putBundle(BUNDLE, bundle);
}
return outState;
}
Aggregations