android.view.View#restoreHierarchyState ( )源码实例Demo

下面列出了android.view.View#restoreHierarchyState ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。

@Override
public void onRestoreInstanceState( Parcelable state ) {
    if ( state instanceof Bundle ) {
        Bundle bundle = (Bundle) state;
        super.onRestoreInstanceState( bundle.getParcelable( "super" ) );

        ArrayList<Bundle> containers = bundle
                        .getParcelableArrayList( "containers" );
        SparseArray<View> contentViews = getAdapter().getContentViews();

        for ( Bundle contentViewBundle : containers ) {
            int id = contentViewBundle.getInt( "id" );
            SparseArray<Parcelable> container = contentViewBundle
                            .getSparseParcelableArray( "container" );

            View contentView = contentViews.get( id );
            if ( contentView != null ) {
                contentView.restoreHierarchyState( container );
            }
        }

        getAdapter().jumpTo( bundle.getInt( "focus" ) );
    } else
        super.onRestoreInstanceState( state );
}
 
源代码2 项目: TabStacker   文件: ViewData.java
static void restoreView(Bundle bundle, @NonNull View view) {

        if (bundle == null) {
            return;
        }

        SparseArray<Parcelable> savedViewHierarchy = new SparseArray<>();

        for(String bundleKey : bundle.keySet()) {
            Parcelable parcelable = bundle.getParcelable(bundleKey);
            int key = Integer.parseInt(bundleKey);
            savedViewHierarchy.put(key, parcelable);
        }

        view.restoreHierarchyState(savedViewHierarchy);
    }
 
@Override public final Object instantiateItem(ViewGroup container, int position) {
  if (detached == null) {
    detached = new SparseArray<>();
  }
  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;
}
 
源代码4 项目: flowless   文件: FlowlessPagerAdapter.java
@Override
public View instantiateItem(ViewGroup container, int position) {
    View view = getItem(position);
    if(bundles[position] != null) {
        Bundle savedState = bundles[position];
        view.restoreHierarchyState(savedState.getSparseParcelableArray("viewState"));
        if(view instanceof Bundleable) {
            ((Bundleable) view).fromBundle(savedState.getBundle("bundle"));
        }
    }
    if(view instanceof FlowLifecycles.ViewLifecycleListener) {
        ((FlowLifecycles.ViewLifecycleListener) view).onViewRestored();
    }
    container.addView(view);
    views[position] = view;
    return view;
}
 
/**
 * Restores the saved hierarchy state.
 *
 * @param container The saved hierarchy state.
 */
public static ViewAction restoreHierarchyState(final SparseArray<Parcelable> container) {
  return new ViewAction() {
    @Override
    public Matcher<View> getConstraints() {
      return isAssignableFrom(View.class);
    }

    @Override
    public String getDescription() {
      return "restore the saved state";
    }

    @Override
    public void perform(UiController uiController, View view) {
      uiController.loopMainThreadUntilIdle();
      view.restoreHierarchyState(container);
      uiController.loopMainThreadUntilIdle();
    }
  };
}
 
源代码6 项目: CSipSimple   文件: MenuBuilder.java
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();
        }
    }
}
 
源代码7 项目: simple-stack   文件: Backstack.java
/**
 * 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.getViewBundle());
    }
}
 
源代码8 项目: epoxy   文件: ViewHolderState.java
public void restore(View view) {
  int originalId = view.getId();
  setIdIfNoneExists(view);

  view.restoreHierarchyState(this);
  view.setId(originalId);
}
 
源代码9 项目: adt-leanback-support   文件: 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
 * @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);
        SparseArray<Parcelable> container = mChildStates.get(key);
        if (container != null) {
            view.restoreHierarchyState(container);
        }
    }
}
 
源代码10 项目: android-apps   文件: MenuBuilder.java
public void restoreActionViewStates(Bundle states) {
    if (states == null) {
        return;
    }

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

    final int expandedId = states.getInt(EXPANDED_ACTION_VIEW_ID);
    if (expandedId > 0) {
        MenuItem itemToExpand = findItem(expandedId);
        if (itemToExpand != null) {
            itemToExpand.expandActionView();
        }
    }
}
 
源代码11 项目: zen4android   文件: MenuBuilder.java
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();
        }
    }
}
 
源代码12 项目: zhangshangwuda   文件: MenuBuilder.java
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();
        }
    }
}
 
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();
        }
    }
}
 
/**
 * 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
 * @param inflated
 *         True, if the view has been inflated, false, if it has been reused
 */
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,
                                 final boolean inflated) {
    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);
        }
    }

    if (!inflated) {
        onRecycleView(context, tabSwitcher, view, tab, index, viewType, savedInstanceState);
    }

    onShowTab(context, tabSwitcher, view, tab, index, viewType, savedInstanceState);
}
 
源代码15 项目: Defrag   文件: ViewStack.java
void restoreState(@NonNull View view) {
	if (viewState != null) {
		view.restoreHierarchyState(viewState);
	}
}
 
源代码16 项目: flowless   文件: State.java
public void restore(@NonNull View view) {
    if(viewState != null) {
        view.restoreHierarchyState(viewState);
    }
}
 
源代码17 项目: fragnums   文件: BackstackFrame.java
public void restore(View view) {
  view.restoreHierarchyState(viewState);
}
 
源代码18 项目: Mortar-architect   文件: Presenter.java
void present(final Dispatcher.Dispatch newDispatch, final History.Entry previousEntry, final ViewTransitionDirection direction, final Dispatcher.Callback callback) {
        Preconditions.checkNotNull(view, "Container view cannot be null");
        Preconditions.checkNull(dispatchingCallback, "Previous dispatching callback not completed");

        Logger.d("Present new dispatch: %s - with direction: %s", newDispatch.entry.scopeName, direction);
        Logger.d("Previous entry: %s", previousEntry.scopeName);

        // set and track the callback from dispatcher
        // dispatcher is waiting for the onComplete call
        // either when present is done, or when presenter is desactivated
        dispatchingCallback = callback;

        if (!previousEntry.dead) {
            // save previous view state
            Logger.d("Save view state for: %s", previousEntry.scopeName);
            previousEntry.state = getCurrentViewState();
        }

        // create or reuse view
        View newView;
        boolean addNewView;
        if (!previousEntry.dead || (previousEntry.dead && !previousEntry.isModal())) {

//                direction == Dispatcher.Direction.FORWARD ||
//                (direction == Dispatcher.Direction.BACKWARD && !previousEntry.isModal())) {
            // create new view when forward and replace
            // or when backward if previous entry is not modal
            Logger.d("Create new view for %s", newDispatch.entry.scopeName);
            Context context = newDispatch.scope.createContext(view.getContext());
            newView = newDispatch.entry.path.createView(context, view);
            addNewView = true;
        } else {
            Logger.d("Reuse previous view for %s", newDispatch.entry.scopeName);
            newView = view.getChildAt(view.getChildCount() - 2);
            addNewView = false;
        }

        // find transition
        ViewTransition transition;
        if (view.hasCurrentView()) {
            transition = transitions.findTransition(view.getCurrentView(), newView, direction);
        } else {
            transition = null;
        }

        // restore state if it exists
        if (newDispatch.entry.state != null) {
            Logger.d("Restore view state for: %s", newDispatch.entry.scopeName);
            newView.restoreHierarchyState(newDispatch.entry.state);
        }

        if (newDispatch.entry.receivedResult != null) {
            if (newView instanceof HasPresenter) {
                // put result
                ViewPresenter viewPresenter = ((HasPresenter) newView).getPresenter();
                if (viewPresenter instanceof ReceivesResult) {
                    ((ReceivesResult) viewPresenter).onReceivedResult(newDispatch.entry.receivedResult);
                }
            }
            newDispatch.entry.receivedResult = null;
        }

//        boolean keepPreviousView = direction == Dispatcher.Direction.FORWARD && newDispatch.entry.isModal();
        boolean keepPreviousView = !previousEntry.dead && newDispatch.entry.isModal();
        Logger.d("Keep previous view: %b", keepPreviousView);

        view.show(new NavigatorView.Presentation(newView, addNewView, !keepPreviousView, direction, transition), new PresentationCallback() {
            @Override
            public void onPresentationFinished(int sessionId) {
                if (isCurrentSession(sessionId)) {
                    completeDispatchingCallback();
                }
            }
        });
    }
 
源代码19 项目: scoop   文件: Screen.java
public void restoreViewState(View view) {
    view.restoreHierarchyState(viewState);
}
 
源代码20 项目: flow   文件: State.java
public void restore(@NonNull View view) {
  SparseArray<Parcelable> viewState = viewStateById.get(view.getId());
  if (viewState != null) {
    view.restoreHierarchyState(viewState);
  }
}
 
 方法所在类
 同类方法