1/* 2 * Copyright (C) 2012 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 17package android.support.v7.internal.widget; 18 19import android.content.Context; 20import android.content.res.TypedArray; 21import android.graphics.Rect; 22import android.support.v7.app.ActionBar; 23import android.support.v7.appcompat.R; 24import android.util.AttributeSet; 25import android.view.View; 26import android.widget.FrameLayout; 27 28/** 29 * Special layout for the containing of an overlay action bar (and its content) to correctly handle 30 * fitting system windows when the content has request that its layout ignore them. 31 * 32 * @hide 33 */ 34public class ActionBarOverlayLayout extends FrameLayout { 35 36 private int mActionBarHeight; 37 private ActionBar mActionBar; 38 private View mContent; 39 private View mActionBarTop; 40 private ActionBarContainer mContainerView; 41 private ActionBarView mActionView; 42 private View mActionBarBottom; 43 private final Rect mZeroRect = new Rect(0, 0, 0, 0); 44 45 static final int[] mActionBarSizeAttr = new int[]{ 46 R.attr.actionBarSize 47 }; 48 49 public ActionBarOverlayLayout(Context context) { 50 super(context); 51 init(context); 52 } 53 54 public ActionBarOverlayLayout(Context context, AttributeSet attrs) { 55 super(context, attrs); 56 init(context); 57 } 58 59 private void init(Context context) { 60 TypedArray ta = getContext().getTheme().obtainStyledAttributes(mActionBarSizeAttr); 61 mActionBarHeight = ta.getDimensionPixelSize(0, 0); 62 ta.recycle(); 63 } 64 65 public void setActionBar(ActionBar impl) { 66 mActionBar = impl; 67 } 68 69 private boolean applyInsets(View view, Rect insets, boolean left, boolean top, 70 boolean bottom, boolean right) { 71 boolean changed = false; 72 FrameLayout.LayoutParams lp = (FrameLayout.LayoutParams) view.getLayoutParams(); 73 if (left && lp.leftMargin != insets.left) { 74 changed = true; 75 lp.leftMargin = insets.left; 76 } 77 if (top && lp.topMargin != insets.top) { 78 changed = true; 79 lp.topMargin = insets.top; 80 } 81 if (right && lp.rightMargin != insets.right) { 82 changed = true; 83 lp.rightMargin = insets.right; 84 } 85 if (bottom && lp.bottomMargin != insets.bottom) { 86 changed = true; 87 lp.bottomMargin = insets.bottom; 88 } 89 return changed; 90 } 91 92 void pullChildren() { 93 if (mContent == null) { 94 mContent = findViewById(R.id.action_bar_activity_content); 95 if (mContent == null) { 96 mContent = findViewById(android.R.id.content); 97 } 98 mActionBarTop = findViewById(R.id.top_action_bar); 99 mContainerView = (ActionBarContainer) findViewById(R.id.action_bar_container); 100 mActionView = (ActionBarView) findViewById(R.id.action_bar); 101 mActionBarBottom = findViewById(R.id.split_action_bar); 102 } 103 } 104} 105