| 1 | /* |
| 2 | * Copyright (C) 2011 The Android Open Source Project |
| 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
| 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. |
| 15 | */ |
| 16 | |
| 17 | package android.support.v2.app; |
| 18 | |
| 19 | import android.content.Context; |
| 20 | import android.os.Parcelable; |
| 21 | import android.util.SparseArray; |
| 22 | import android.view.View; |
| 23 | import android.view.ViewGroup; |
| 24 | import android.widget.FrameLayout; |
| 25 | |
| 26 | /** |
| 27 | * Pre-Honeycomb versions of the platform don't have View.setSaveFromParentEnabled(), |
| 28 | * so instead we insert this between the view and its parent. |
| 29 | */ |
| 30 | public class NoSaveStateFrameLayout extends FrameLayout { |
| 31 | static ViewGroup wrap(View child) { |
| 32 | NoSaveStateFrameLayout wrapper = new NoSaveStateFrameLayout(child.getContext()); |
| 33 | ViewGroup.LayoutParams childParams = child.getLayoutParams(); |
| 34 | if (childParams != null) { |
| 35 | wrapper.setLayoutParams(childParams); |
| 36 | } |
| 37 | NoSaveStateFrameLayout.LayoutParams lp = new NoSaveStateFrameLayout.LayoutParams( |
| 38 | ViewGroup.LayoutParams.FILL_PARENT, ViewGroup.LayoutParams.FILL_PARENT); |
| 39 | child.setLayoutParams(lp); |
| 40 | wrapper.addView(child); |
| 41 | return wrapper; |
| 42 | } |
| 43 | |
| 44 | public NoSaveStateFrameLayout(Context context) { |
| 45 | super(context); |
| 46 | } |
| 47 | |
| 48 | /** |
| 49 | * Override to prevent freezing of any child views. |
| 50 | */ |
| 51 | @Override |
| 52 | protected void dispatchSaveInstanceState(SparseArray<Parcelable> container) { |
| 53 | dispatchFreezeSelfOnly(container); |
| 54 | } |
| 55 | |
| 56 | /** |
| 57 | * Override to prevent thawing of any child views. |
| 58 | */ |
| 59 | @Override |
| 60 | protected void dispatchRestoreInstanceState(SparseArray<Parcelable> container) { |
| 61 | dispatchThawSelfOnly(container); |
| 62 | } |
| 63 | } |