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

The following are Jave code examples for showing how to use restoreHierarchyState() 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: boohee_v5.6   File: MenuBuilder.java   View Source Code Vote up 7 votes
public void restoreActionViewStates(Bundle states) {
    if (states != null) {
        SparseArray<Parcelable> viewStates = states.getSparseParcelableArray(getActionViewStatesKey());
        int itemCount = size();
        for (int i = 0; i < itemCount; i++) {
            MenuItem item = getItem(i);
            View v = MenuItemCompat.getActionView(item);
            if (!(v == null || v.getId() == -1)) {
                v.restoreHierarchyState(viewStates);
            }
            if (item.hasSubMenu()) {
                ((SubMenuBuilder) item.getSubMenu()).restoreActionViewStates(states);
            }
        }
        int expandedId = states.getInt(EXPANDED_ACTION_VIEW_ID);
        if (expandedId > 0) {
            MenuItem itemToExpand = findItem(expandedId);
            if (itemToExpand != null) {
                MenuItemCompat.expandActionView(itemToExpand);
            }
        }
    }
}
 
Example 2
Project: CSipSimple   File: MenuBuilder.java   View Source Code Vote up 6 votes
public void restoreActionViewStates(Bundle states) {
    if (states == null) {
        return;
    }

    SparseArray<Parcelable> viewStates = states.getSparseParcelableArray(
            getActionViewStatesKey());

    if (Build.VERSION.SDK_INT < Build.VERSION_CODES.HONEYCOMB && viewStates == null) {
        //Fixes Issue #652 with sdk <= 2.3.6
        return;
    }

    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) {
            v.restoreHierarchyState(viewStates);
        }
        if (item.hasSubMenu()) {
            final SubMenuBuilder subMenu = (SubMenuBuilder) item.getSubMenu();
            subMenu.restoreActionViewStates(states);
        }
    }

    final int expandedId = states.getInt(EXPANDED_ACTION_VIEW_ID);
    if (expandedId > 0) {
        MenuItem itemToExpand = findItem(expandedId);
        if (itemToExpand != null) {
            itemToExpand.expandActionView();
        }
    }
}
 
Example 3
Project: Stage   File: Scene.java   View Source Code Vote up 6 votes
private void restoreViewState(@NonNull View view) {
  if (viewState != null) {
    view.restoreHierarchyState(viewState.getSparseParcelableArray(KEY_VIEW_STATE_HIERARCHY));

    Bundle savedViewState = viewState.getBundle(KEY_VIEW_STATE_BUNDLE);
    if (savedViewState != null) {
      savedViewState.setClassLoader(getClass().getClassLoader());
      onRestoreViewState(view, savedViewState);
    }

    if (!lifecycleListeners.isEmpty()) {
      for (LifecycleListener listener : new ArrayList<>(lifecycleListeners)) {
        listener.onRestoreViewState(this, viewState);
      }
    }
  }
}
 
Example 4
Project: boohee_v5.6   File: NavigationMenuPresenter.java   View Source Code Vote up 6 votes
public void restoreInstanceState(Bundle state) {
    Iterator i$;
    int checkedItem = state.getInt(STATE_CHECKED_ITEM, 0);
    if (checkedItem != 0) {
        this.mUpdateSuspended = true;
        i$ = this.mItems.iterator();
        while (i$.hasNext()) {
            NavigationMenuItem item = (NavigationMenuItem) i$.next();
            if (item instanceof NavigationMenuTextItem) {
                MenuItemImpl menuItem = ((NavigationMenuTextItem) item).getMenuItem();
                if (menuItem != null && menuItem.getItemId() == checkedItem) {
                    setCheckedItem(menuItem);
                    break;
                }
            }
        }
        this.mUpdateSuspended = false;
        prepareMenuItems();
    }
    SparseArray<ParcelableSparseArray> actionViewStates = state.getSparseParcelableArray(STATE_ACTION_VIEWS);
    i$ = this.mItems.iterator();
    while (i$.hasNext()) {
        NavigationMenuItem navigationMenuItem = (NavigationMenuItem) i$.next();
        if (navigationMenuItem instanceof NavigationMenuTextItem) {
            MenuItemImpl item2 = ((NavigationMenuTextItem) navigationMenuItem).getMenuItem();
            View actionView = item2 != null ? item2.getActionView() : null;
            if (actionView != null) {
                actionView.restoreHierarchyState((SparseArray) actionViewStates.get(item2.getItemId()));
            }
        }
    }
}
 
Example 5
Project: ChromeLikeTabSwitcher   File: TabSwitcherDecorator.java   View Source Code Vote up 5 votes
/**
 * The method, which is invoked by a {@link TabSwitcher} to apply the decorator. 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>onShowTab(...):void</code>.
 *
 * @param context
 *         The context, the tab switcher belongs to, as an instance of the class {@link
 *         Context}. The context may not be null
 * @param tabSwitcher
 *         The tab switcher, whose tabs are visualized by the decorator, as an instance of the
 *         class {@link TabSwitcher}. The tab switcher may not be null
 * @param view
 *         The view, which is used to visualize the tab, as an instance of the class {@link
 *         View}. The view may not be null
 * @param tab
 *         The tab, which should be visualized, as an instance of the class {@link Tab}. The tab
 *         may not be null
 * @param index
 *         The index of the tab, which should be visualized, as an {@link Integer} value
 * @param savedInstanceState
 *         The bundle, which has previously been used to save the state of the view as an
 *         instance of the class {@link Bundle} or null, if no saved state is available
 */
public final void applyDecorator(@NonNull final Context context,
                                 @NonNull final TabSwitcher tabSwitcher,
                                 @NonNull final View view, @NonNull final Tab tab,
                                 final int index, @Nullable final Bundle savedInstanceState) {
    setCurrentParentView(view);
    int viewType = getViewType(tab, index);

    if (savedInstanceState != null) {
        SparseArray<Parcelable> viewStates =
                savedInstanceState.getSparseParcelableArray(VIEW_HIERARCHY_STATE_EXTRA);

        if (viewStates != null) {
            view.restoreHierarchyState(viewStates);
        }
    }

    onShowTab(context, tabSwitcher, view, tab, index, viewType, savedInstanceState);
}
 
Example 6
Project: simple-stack   File: BackstackManager.java   View Source Code Vote up 5 votes
/**
 * Restores the state of the view based on the currently stored {@link SavedState}, according to the view's key.
 *
 * @param view the view that belongs to a certain key
 */
public void restoreViewFromState(@NonNull View view) {
    if(view == null) {
        throw new IllegalArgumentException("You cannot restore state into null view!");
    }
    Object newKey = KeyContextWrapper.getKey(view.getContext());
    SavedState savedState = getSavedState(newKey);
    view.restoreHierarchyState(savedState.getViewHierarchyState());
    if(view instanceof Bundleable) {
        ((Bundleable) view).fromBundle(savedState.getBundle());
    }
}
 
Example 7
Project: NeoTerm   File: TabSwitcherDecorator.java   View Source Code Vote up 5 votes
/**
 * The method, which is invoked by a {@link TabSwitcher} to apply the decorator. 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>onShowTab(...):void</code>.
 *
 * @param context
 *         The context, the tab switcher belongs to, as an instance of the class {@link
 *         Context}. The context may not be null
 * @param tabSwitcher
 *         The tab switcher, whose tabs are visualized by the decorator, as an instance of the
 *         class {@link TabSwitcher}. The tab switcher may not be null
 * @param view
 *         The view, which is used to visualize the tab, as an instance of the class {@link
 *         View}. The view may not be null
 * @param tab
 *         The tab, which should be visualized, as an instance of the class {@link Tab}. The tab
 *         may not be null
 * @param index
 *         The index of the tab, which should be visualized, as an {@link Integer} value
 * @param savedInstanceState
 *         The bundle, which has previously been used to save the state of the view as an
 *         instance of the class {@link Bundle} or null, if no saved state is available
 */
public final void applyDecorator(@NonNull final Context context,
                                 @NonNull final TabSwitcher tabSwitcher,
                                 @NonNull final View view, @NonNull final Tab tab,
                                 final int index, @Nullable final Bundle savedInstanceState) {
    setCurrentParentView(view);
    int viewType = getViewType(tab, index);

    if (savedInstanceState != null) {
        SparseArray<Parcelable> viewStates =
                savedInstanceState.getSparseParcelableArray(VIEW_HIERARCHY_STATE_EXTRA);

        if (viewStates != null) {
            view.restoreHierarchyState(viewStates);
        }
    }

    onShowTab(context, tabSwitcher, view, tab, index, viewType, savedInstanceState);
}