Search in sources :

Example 36 with Parcelable

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());
        }
    });
}
Also used : Parcelable(android.os.Parcelable) SmallTest(android.support.test.filters.SmallTest) UiThreadTest(android.support.test.annotation.UiThreadTest) Test(org.junit.Test) SmallTest(android.support.test.filters.SmallTest)

Example 37 with Parcelable

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;
}
Also used : AbsSavedState(android.support.v4.view.AbsSavedState) Parcelable(android.os.Parcelable)

Example 38 with Parcelable

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()));
}
Also used : SparseArray(android.util.SparseArray) Parcelable(android.os.Parcelable) View(android.view.View) NavigationViewActions.removeHeaderView(android.support.design.testutils.NavigationViewActions.removeHeaderView) TextView(android.widget.TextView) Espresso.onView(android.support.test.espresso.Espresso.onView) NavigationTestView(android.support.design.testapp.custom.NavigationTestView) NavigationViewActions.addHeaderView(android.support.design.testutils.NavigationViewActions.addHeaderView) NavigationViewActions.inflateHeaderView(android.support.design.testutils.NavigationViewActions.inflateHeaderView) RecyclerView(android.support.v7.widget.RecyclerView) MediumTest(android.support.test.filters.MediumTest) Test(org.junit.Test)

Example 39 with Parcelable

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()));
}
Also used : SparseArray(android.util.SparseArray) Parcelable(android.os.Parcelable) Menu(android.view.Menu) TestUtilsActions.reinflateMenu(android.support.design.testutils.TestUtilsActions.reinflateMenu) MediumTest(android.support.test.filters.MediumTest) Test(org.junit.Test)

Example 40 with Parcelable

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;
}
Also used : SparseArray(android.util.SparseArray) Bundle(android.os.Bundle) Parcelable(android.os.Parcelable) LinkedHashMap(java.util.LinkedHashMap) Map(java.util.Map)

Aggregations

Parcelable (android.os.Parcelable)826 Bundle (android.os.Bundle)99 View (android.view.View)85 Intent (android.content.Intent)58 SparseArray (android.util.SparseArray)38 Test (org.junit.Test)31 ArrayList (java.util.ArrayList)26 MenuItem (android.view.MenuItem)23 ImageView (android.widget.ImageView)23 TextView (android.widget.TextView)17 MenuItem (com.actionbarsherlock.view.MenuItem)14 SuppressLint (android.annotation.SuppressLint)13 Dialog (android.app.Dialog)13 MediumTest (android.support.test.filters.MediumTest)13 NameNotFoundException (android.content.pm.PackageManager.NameNotFoundException)12 Paint (android.graphics.Paint)12 MenuView (com.android.internal.view.menu.MenuView)12 RemoteException (android.os.RemoteException)11 Bitmap (android.graphics.Bitmap)10 ShortcutIconResource (android.content.Intent.ShortcutIconResource)9