当前位置: 首页>>代码示例>>Java>>正文


Java View.saveHierarchyState方法代码示例

本文整理汇总了Java中android.view.View.saveHierarchyState方法的典型用法代码示例。如果您正苦于以下问题:Java View.saveHierarchyState方法的具体用法?Java View.saveHierarchyState怎么用?Java View.saveHierarchyState使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在android.view.View的用法示例。


在下文中一共展示了View.saveHierarchyState方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: saveActionViewStates

import android.view.View; //导入方法依赖的package包/类
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);
    }
}
 
开发者ID:treasure-lau,项目名称:CSipSimple,代码行数:27,代码来源:MenuBuilder.java

示例2: saveViewState

import android.view.View; //导入方法依赖的package包/类
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);
    }
  }
}
 
开发者ID:seven332,项目名称:Stage,代码行数:18,代码来源:Scene.java

示例3: persistViewToState

import android.view.View; //导入方法依赖的package包/类
/**
 * 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);
    }
}
 
开发者ID:Zhuinden,项目名称:simple-stack,代码行数:27,代码来源:BackstackManager.java

示例4: createInstanceState

import android.view.View; //导入方法依赖的package包/类
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;
}
 
开发者ID:JackChan1999,项目名称:boohee_v5.6,代码行数:23,代码来源:NavigationMenuPresenter.java

示例5: saveInstanceState

import android.view.View; //导入方法依赖的package包/类
/**
 * 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;
}
 
开发者ID:michael-rapp,项目名称:ChromeLikeTabSwitcher,代码行数:30,代码来源:TabSwitcherDecorator.java


注:本文中的android.view.View.saveHierarchyState方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。