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