Example usage for android.view View restoreHierarchyState

List of usage examples for android.view View restoreHierarchyState

Introduction

In this page you can find the example usage for android.view View restoreHierarchyState.

Prototype

public void restoreHierarchyState(SparseArray<Parcelable> container) 

Source Link

Document

Restore this view hierarchy's frozen state from the given container.

Usage

From source file:com.nightlynexus.viewstatepageradapter.ViewStatePagerAdapter.java

@Override
public final Object instantiateItem(ViewGroup container, int position) {
    if (detached == null) {
        detached = new SparseArray<>();
    }/*from  w  ww.j  av a2s. c o m*/
    View view = createView(container, position);
    if (view == null) {
        throw new NullPointerException("createView must not return null. (position: " + position + ")");
    }
    SparseArray<Parcelable> viewState = detached.get(position);
    if (viewState != null) {
        view.restoreHierarchyState(viewState);
    }
    container.addView(view);
    attached.put(position, view);
    return view;
}

From source file:android.support.v17.leanback.widget.ViewsStateBundle.java

/**
 * Load view from states, it's none operation if the there is no state associated with the id.
 *
 * @param view view where loads into//from  w w  w .  j a v  a  2 s .  com
 * @param id unique id for the view within this ViewsStateBundle
 */
public final void loadView(View view, int id) {
    if (mChildStates != null) {
        String key = getSaveStatesKey(id);
        // Once loaded the state, do not keep the state of child. The child state will
        // be saved again either when child is offscreen or when the parent is saved.
        SparseArray<Parcelable> container = mChildStates.remove(key);
        if (container != null) {
            view.restoreHierarchyState(container);
        }
    }
}

From source file:com.actionbarsherlock.internal.view.menu.MenuBuilder.java

public void restoreActionViewStates(Bundle states) {
    if (states == null) {
        return;/*from  w  ww .j  a  v  a 2  s  .  c  o m*/
    }

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

    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);
        }
    }
}

From source file:android.support.v7.internal.view.menu.MenuBuilder.java

public void restoreActionViewStates(Bundle states) {
    if (states == null) {
        return;/*from ww  w.j  a v  a  2  s.co  m*/
    }

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

    final int itemCount = size();
    for (int i = 0; i < itemCount; i++) {
        final MenuItem item = getItem(i);
        final View v = MenuItemCompat.getActionView(item);
        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) {
            MenuItemCompat.expandActionView(itemToExpand);
        }
    }
}