Java Code Examples for android.view.View.saveHierarchyState()

The following are Jave code examples for showing how to use saveHierarchyState() of the android.view.View class. You can vote up the examples you like. Your votes will be used in our system to get more good examples.
+ Save this method
Example 1
Project: CSipSimple   File: MenuBuilder.java   View Source Code Vote up 7 votes
public void saveActionViewStates(Bundle outStates) {
    SparseArray<Parcelable> viewStates = null;

    final int itemCount = size();
    for (int i = 0; i < itemCount; i++) {
        final MenuItem item = getItem(i);
        final View v = item.getActionView();
        if (v != null && v.getId() != View.NO_ID) {
            if (viewStates == null) {
                viewStates = new SparseArray<Parcelable>();
            }
            v.saveHierarchyState(viewStates);
            if (item.isActionViewExpanded()) {
                outStates.putInt(EXPANDED_ACTION_VIEW_ID, item.getItemId());
            }
        }
        if (item.hasSubMenu()) {
            final SubMenuBuilder subMenu = (SubMenuBuilder) item.getSubMenu();
            subMenu.saveActionViewStates(outStates);
        }
    }

    if (viewStates != null) {
        outStates.putSparseParcelableArray(getActionViewStatesKey(), viewStates);
    }
}
 
Example 2
Project: Stage   File: Scene.java   View Source Code Vote up 6 votes
private void saveViewState(@NonNull View view) {
  viewState = new Bundle(getClass().getClassLoader());

  SparseArray<Parcelable> hierarchyState = new SparseArray<>();
  view.saveHierarchyState(hierarchyState);
  viewState.putSparseParcelableArray(KEY_VIEW_STATE_HIERARCHY, hierarchyState);

  Bundle stateBundle = new Bundle(getClass().getClassLoader());
  onSaveViewState(view, stateBundle);
  viewState.putBundle(KEY_VIEW_STATE_BUNDLE, stateBundle);

  if (!lifecycleListeners.isEmpty()) {
    for (LifecycleListener listener : new ArrayList<>(lifecycleListeners)) {
      listener.onSaveViewState(this, viewState);
    }
  }
}
 
Example 3
Project: simple-stack   File: BackstackManager.java   View Source Code Vote up 6 votes
/**
 * Provides the means to save the provided view's hierarchy state
 * and its optional StateBundle via {@link Bundleable} into a {@link SavedState}.
 *
 * @param view the view that belongs to a certain key
 */
public void persistViewToState(@Nullable View view) {
    if(view != null) {
        Object key = KeyContextWrapper.getKey(view.getContext());
        if(key == null) {
            throw new IllegalArgumentException("The view [" + view + "] contained no key in its context hierarchy. The view or its parent hierarchy should be inflated by a layout inflater from `stateChange.createContext(baseContext, key)`, or a KeyContextWrapper.");
        }
        SparseArray<Parcelable> viewHierarchyState = new SparseArray<>();
        view.saveHierarchyState(viewHierarchyState);
        StateBundle bundle = null;
        if(view instanceof Bundleable) {
            bundle = ((Bundleable) view).toBundle();
        }
        SavedState previousSavedState = SavedState.builder() //
                .setKey(key) //
                .setViewHierarchyState(viewHierarchyState) //
                .setBundle(bundle) //
                .build();
        keyStateMap.put(key, previousSavedState);
    }
}
 
Example 4
Project: boohee_v5.6   File: NavigationMenuPresenter.java   View Source Code Vote up 6 votes
public Bundle createInstanceState() {
    Bundle state = new Bundle();
    if (this.mCheckedItem != null) {
        state.putInt(STATE_CHECKED_ITEM, this.mCheckedItem.getItemId());
    }
    SparseArray<ParcelableSparseArray> actionViewStates = new SparseArray();
    Iterator i$ = this.mItems.iterator();
    while (i$.hasNext()) {
        NavigationMenuItem navigationMenuItem = (NavigationMenuItem) i$.next();
        if (navigationMenuItem instanceof NavigationMenuTextItem) {
            MenuItemImpl item = ((NavigationMenuTextItem) navigationMenuItem).getMenuItem();
            View actionView = item != null ? item.getActionView() : null;
            if (actionView != null) {
                ParcelableSparseArray container = new ParcelableSparseArray();
                actionView.saveHierarchyState(container);
                actionViewStates.put(item.getItemId(), container);
            }
        }
    }
    state.putSparseParcelableArray(STATE_ACTION_VIEWS, actionViewStates);
    return state;
}
 
Example 5
Project: ChromeLikeTabSwitcher   File: TabSwitcherDecorator.java   View Source Code Vote up 3 votes
/**
 * The method, which is invoked by a {@link TabSwitcher} to save the current state of a tab. It
 * initializes the view holder pattern, which is provided by the decorator and then delegates
 * the method call to the decorator's custom implementation of the method
 * <code>onSaveInstanceState(...):void</code>.
 *
 * @param view
 *         The view, which is used to visualize the tab, as an instance of the class {@link
 *         View}
 * @param tab
 *         The tab, whose state should be saved, as an instance of the class {@link Tab}. The
 *         tab may not be null
 * @param index
 *         The index of the tab, whose state should be saved, as an {@link Integer} value
 * @return The bundle, which has been used to save the state, as an instance of the class {@link
 * Bundle}. The bundle may not be null
 */
@NonNull
public final Bundle saveInstanceState(@NonNull final View view, @NonNull final Tab tab,
                                      final int index) {
    setCurrentParentView(view);
    int viewType = getViewType(tab, index);
    Bundle outState = new Bundle();
    SparseArray<Parcelable> viewStates = new SparseArray<>();
    view.saveHierarchyState(viewStates);
    outState.putSparseParcelableArray(VIEW_HIERARCHY_STATE_EXTRA, viewStates);
    onSaveInstanceState(view, tab, index, viewType, outState);
    return outState;
}
 
Example 6
Project: NeoTerm   File: TabSwitcherDecorator.java   View Source Code Vote up 3 votes
/**
 * The method, which is invoked by a {@link TabSwitcher} to save the current state of a tab. It
 * initializes the view holder pattern, which is provided by the decorator and then delegates
 * the method call to the decorator's custom implementation of the method
 * <code>onSaveInstanceState(...):void</code>.
 *
 * @param view
 *         The view, which is used to visualize the tab, as an instance of the class {@link
 *         View}
 * @param tab
 *         The tab, whose state should be saved, as an instance of the class {@link Tab}. The
 *         tab may not be null
 * @param index
 *         The index of the tab, whose state should be saved, as an {@link Integer} value
 * @return The bundle, which has been used to save the state, as an instance of the class {@link
 * Bundle}. The bundle may not be null
 */
@NonNull
public final Bundle saveInstanceState(@NonNull final View view, @NonNull final Tab tab,
                                      final int index) {
    setCurrentParentView(view);
    int viewType = getViewType(tab, index);
    Bundle outState = new Bundle();
    SparseArray<Parcelable> viewStates = new SparseArray<>();
    view.saveHierarchyState(viewStates);
    outState.putSparseParcelableArray(VIEW_HIERARCHY_STATE_EXTRA, viewStates);
    onSaveInstanceState(view, tab, index, viewType, outState);
    return outState;
}