本文整理汇总了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);
}
}
示例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);
}
}
}
示例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);
}
}
示例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;
}
示例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;
}