當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。