ActionBarContainer.java revision a7cc06d82e45918c37429a59b14545c6a57db4e4
145f1e08c348ccb129bcc25e438c05421f7123f41Adam Powell/* 245f1e08c348ccb129bcc25e438c05421f7123f41Adam Powell * Copyright (C) 2010 The Android Open Source Project 345f1e08c348ccb129bcc25e438c05421f7123f41Adam Powell * 445f1e08c348ccb129bcc25e438c05421f7123f41Adam Powell * Licensed under the Apache License, Version 2.0 (the "License"); 545f1e08c348ccb129bcc25e438c05421f7123f41Adam Powell * you may not use this file except in compliance with the License. 645f1e08c348ccb129bcc25e438c05421f7123f41Adam Powell * You may obtain a copy of the License at 745f1e08c348ccb129bcc25e438c05421f7123f41Adam Powell * 845f1e08c348ccb129bcc25e438c05421f7123f41Adam Powell * http://www.apache.org/licenses/LICENSE-2.0 945f1e08c348ccb129bcc25e438c05421f7123f41Adam Powell * 1045f1e08c348ccb129bcc25e438c05421f7123f41Adam Powell * Unless required by applicable law or agreed to in writing, software 1145f1e08c348ccb129bcc25e438c05421f7123f41Adam Powell * distributed under the License is distributed on an "AS IS" BASIS, 1245f1e08c348ccb129bcc25e438c05421f7123f41Adam Powell * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 1345f1e08c348ccb129bcc25e438c05421f7123f41Adam Powell * See the License for the specific language governing permissions and 1445f1e08c348ccb129bcc25e438c05421f7123f41Adam Powell * limitations under the License. 1545f1e08c348ccb129bcc25e438c05421f7123f41Adam Powell */ 1645f1e08c348ccb129bcc25e438c05421f7123f41Adam Powell 1745f1e08c348ccb129bcc25e438c05421f7123f41Adam Powellpackage com.android.internal.widget; 1845f1e08c348ccb129bcc25e438c05421f7123f41Adam Powell 19310849abb1a0763ea9912b59187f0a4271efaa2eAdam Powellimport android.app.ActionBar; 2045f1e08c348ccb129bcc25e438c05421f7123f41Adam Powellimport android.content.Context; 2145f1e08c348ccb129bcc25e438c05421f7123f41Adam Powellimport android.content.res.TypedArray; 22a72ef62e5c329a19eab9935acba816fc1369c637Adam Powellimport android.graphics.Canvas; 23a72ef62e5c329a19eab9935acba816fc1369c637Adam Powellimport android.graphics.drawable.Drawable; 2445f1e08c348ccb129bcc25e438c05421f7123f41Adam Powellimport android.util.AttributeSet; 25640a66eac612b850b5dabd3b93bd94f83ed2d567Adam Powellimport android.view.ActionMode; 266ecf3d1690789ace1a667093ad6bbdd6cd35bda7Adam Powellimport android.view.MotionEvent; 27dae7824c4b78d02159c6ad0896f246942d7b3d8cAdam Powellimport android.view.View; 28af6b97ebe0e6a67d1691c4d7789c7bc312c1e13eAdam Powellimport android.view.ViewGroup; 2945f1e08c348ccb129bcc25e438c05421f7123f41Adam Powellimport android.widget.FrameLayout; 3045f1e08c348ccb129bcc25e438c05421f7123f41Adam Powell 3145f1e08c348ccb129bcc25e438c05421f7123f41Adam Powell/** 3245f1e08c348ccb129bcc25e438c05421f7123f41Adam Powell * This class acts as a container for the action bar view and action mode context views. 3345f1e08c348ccb129bcc25e438c05421f7123f41Adam Powell * It applies special styles as needed to help handle animated transitions between them. 3445f1e08c348ccb129bcc25e438c05421f7123f41Adam Powell * @hide 3545f1e08c348ccb129bcc25e438c05421f7123f41Adam Powell */ 3645f1e08c348ccb129bcc25e438c05421f7123f41Adam Powellpublic class ActionBarContainer extends FrameLayout { 3701feaee3d9767ef1185783877e92244f14d7d4baAdam Powell private boolean mIsTransitioning; 38dae7824c4b78d02159c6ad0896f246942d7b3d8cAdam Powell private View mTabContainer; 39310849abb1a0763ea9912b59187f0a4271efaa2eAdam Powell private ActionBarView mActionBarView; 4001feaee3d9767ef1185783877e92244f14d7d4baAdam Powell 41a72ef62e5c329a19eab9935acba816fc1369c637Adam Powell private Drawable mBackground; 42a72ef62e5c329a19eab9935acba816fc1369c637Adam Powell private Drawable mStackedBackground; 43a72ef62e5c329a19eab9935acba816fc1369c637Adam Powell private Drawable mSplitBackground; 44a72ef62e5c329a19eab9935acba816fc1369c637Adam Powell private boolean mIsSplit; 45a72ef62e5c329a19eab9935acba816fc1369c637Adam Powell private boolean mIsStacked; 46a72ef62e5c329a19eab9935acba816fc1369c637Adam Powell 4745f1e08c348ccb129bcc25e438c05421f7123f41Adam Powell public ActionBarContainer(Context context) { 4845f1e08c348ccb129bcc25e438c05421f7123f41Adam Powell this(context, null); 4945f1e08c348ccb129bcc25e438c05421f7123f41Adam Powell } 5045f1e08c348ccb129bcc25e438c05421f7123f41Adam Powell 5145f1e08c348ccb129bcc25e438c05421f7123f41Adam Powell public ActionBarContainer(Context context, AttributeSet attrs) { 5245f1e08c348ccb129bcc25e438c05421f7123f41Adam Powell super(context, attrs); 5345f1e08c348ccb129bcc25e438c05421f7123f41Adam Powell 54a72ef62e5c329a19eab9935acba816fc1369c637Adam Powell setBackgroundDrawable(null); 55a72ef62e5c329a19eab9935acba816fc1369c637Adam Powell 5645f1e08c348ccb129bcc25e438c05421f7123f41Adam Powell TypedArray a = context.obtainStyledAttributes(attrs, 5745f1e08c348ccb129bcc25e438c05421f7123f41Adam Powell com.android.internal.R.styleable.ActionBar); 58a72ef62e5c329a19eab9935acba816fc1369c637Adam Powell mBackground = a.getDrawable(com.android.internal.R.styleable.ActionBar_background); 59a72ef62e5c329a19eab9935acba816fc1369c637Adam Powell mStackedBackground = a.getDrawable( 60a72ef62e5c329a19eab9935acba816fc1369c637Adam Powell com.android.internal.R.styleable.ActionBar_backgroundStacked); 61a72ef62e5c329a19eab9935acba816fc1369c637Adam Powell 62a72ef62e5c329a19eab9935acba816fc1369c637Adam Powell if (getId() == com.android.internal.R.id.split_action_bar) { 63a72ef62e5c329a19eab9935acba816fc1369c637Adam Powell mIsSplit = true; 64a72ef62e5c329a19eab9935acba816fc1369c637Adam Powell mSplitBackground = a.getDrawable( 65a72ef62e5c329a19eab9935acba816fc1369c637Adam Powell com.android.internal.R.styleable.ActionBar_backgroundSplit); 66a72ef62e5c329a19eab9935acba816fc1369c637Adam Powell } 6745f1e08c348ccb129bcc25e438c05421f7123f41Adam Powell a.recycle(); 68a72ef62e5c329a19eab9935acba816fc1369c637Adam Powell 69a72ef62e5c329a19eab9935acba816fc1369c637Adam Powell setWillNotDraw(mIsSplit ? mSplitBackground == null : 70a72ef62e5c329a19eab9935acba816fc1369c637Adam Powell mBackground == null && mStackedBackground == null); 7145f1e08c348ccb129bcc25e438c05421f7123f41Adam Powell } 726ecf3d1690789ace1a667093ad6bbdd6cd35bda7Adam Powell 73310849abb1a0763ea9912b59187f0a4271efaa2eAdam Powell @Override 74310849abb1a0763ea9912b59187f0a4271efaa2eAdam Powell public void onFinishInflate() { 75310849abb1a0763ea9912b59187f0a4271efaa2eAdam Powell super.onFinishInflate(); 76310849abb1a0763ea9912b59187f0a4271efaa2eAdam Powell mActionBarView = (ActionBarView) findViewById(com.android.internal.R.id.action_bar); 77310849abb1a0763ea9912b59187f0a4271efaa2eAdam Powell } 78310849abb1a0763ea9912b59187f0a4271efaa2eAdam Powell 79f88b915567a37c481c4c50a6cc57e1ec0e7cf50dAdam Powell public void setPrimaryBackground(Drawable bg) { 80a7cc06d82e45918c37429a59b14545c6a57db4e4Adam Powell if (mBackground != null) { 81a7cc06d82e45918c37429a59b14545c6a57db4e4Adam Powell mBackground.setCallback(null); 82a7cc06d82e45918c37429a59b14545c6a57db4e4Adam Powell unscheduleDrawable(mBackground); 83a7cc06d82e45918c37429a59b14545c6a57db4e4Adam Powell } 84f88b915567a37c481c4c50a6cc57e1ec0e7cf50dAdam Powell mBackground = bg; 85a7cc06d82e45918c37429a59b14545c6a57db4e4Adam Powell if (bg != null) { 86a7cc06d82e45918c37429a59b14545c6a57db4e4Adam Powell bg.setCallback(this); 87a7cc06d82e45918c37429a59b14545c6a57db4e4Adam Powell } 88a7cc06d82e45918c37429a59b14545c6a57db4e4Adam Powell setWillNotDraw(mIsSplit ? mSplitBackground == null : 89a7cc06d82e45918c37429a59b14545c6a57db4e4Adam Powell mBackground == null && mStackedBackground == null); 90f88b915567a37c481c4c50a6cc57e1ec0e7cf50dAdam Powell invalidate(); 91f88b915567a37c481c4c50a6cc57e1ec0e7cf50dAdam Powell } 92f88b915567a37c481c4c50a6cc57e1ec0e7cf50dAdam Powell 93f88b915567a37c481c4c50a6cc57e1ec0e7cf50dAdam Powell public void setStackedBackground(Drawable bg) { 94a7cc06d82e45918c37429a59b14545c6a57db4e4Adam Powell if (mStackedBackground != null) { 95a7cc06d82e45918c37429a59b14545c6a57db4e4Adam Powell mStackedBackground.setCallback(null); 96a7cc06d82e45918c37429a59b14545c6a57db4e4Adam Powell unscheduleDrawable(mStackedBackground); 97a7cc06d82e45918c37429a59b14545c6a57db4e4Adam Powell } 98f88b915567a37c481c4c50a6cc57e1ec0e7cf50dAdam Powell mStackedBackground = bg; 99a7cc06d82e45918c37429a59b14545c6a57db4e4Adam Powell if (bg != null) { 100a7cc06d82e45918c37429a59b14545c6a57db4e4Adam Powell bg.setCallback(this); 101a7cc06d82e45918c37429a59b14545c6a57db4e4Adam Powell } 102a7cc06d82e45918c37429a59b14545c6a57db4e4Adam Powell setWillNotDraw(mIsSplit ? mSplitBackground == null : 103a7cc06d82e45918c37429a59b14545c6a57db4e4Adam Powell mBackground == null && mStackedBackground == null); 104f88b915567a37c481c4c50a6cc57e1ec0e7cf50dAdam Powell invalidate(); 105f88b915567a37c481c4c50a6cc57e1ec0e7cf50dAdam Powell } 106f88b915567a37c481c4c50a6cc57e1ec0e7cf50dAdam Powell 107f88b915567a37c481c4c50a6cc57e1ec0e7cf50dAdam Powell public void setSplitBackground(Drawable bg) { 108a7cc06d82e45918c37429a59b14545c6a57db4e4Adam Powell if (mSplitBackground != null) { 109a7cc06d82e45918c37429a59b14545c6a57db4e4Adam Powell mSplitBackground.setCallback(null); 110a7cc06d82e45918c37429a59b14545c6a57db4e4Adam Powell unscheduleDrawable(mSplitBackground); 111a7cc06d82e45918c37429a59b14545c6a57db4e4Adam Powell } 112f88b915567a37c481c4c50a6cc57e1ec0e7cf50dAdam Powell mSplitBackground = bg; 113a7cc06d82e45918c37429a59b14545c6a57db4e4Adam Powell if (bg != null) { 114a7cc06d82e45918c37429a59b14545c6a57db4e4Adam Powell bg.setCallback(this); 115a7cc06d82e45918c37429a59b14545c6a57db4e4Adam Powell } 116a7cc06d82e45918c37429a59b14545c6a57db4e4Adam Powell setWillNotDraw(mIsSplit ? mSplitBackground == null : 117a7cc06d82e45918c37429a59b14545c6a57db4e4Adam Powell mBackground == null && mStackedBackground == null); 118f88b915567a37c481c4c50a6cc57e1ec0e7cf50dAdam Powell invalidate(); 119f88b915567a37c481c4c50a6cc57e1ec0e7cf50dAdam Powell } 120f88b915567a37c481c4c50a6cc57e1ec0e7cf50dAdam Powell 121a7cc06d82e45918c37429a59b14545c6a57db4e4Adam Powell @Override 122a7cc06d82e45918c37429a59b14545c6a57db4e4Adam Powell public void setVisibility(int visibility) { 123a7cc06d82e45918c37429a59b14545c6a57db4e4Adam Powell super.setVisibility(visibility); 124a7cc06d82e45918c37429a59b14545c6a57db4e4Adam Powell final boolean isVisible = visibility == VISIBLE; 125a7cc06d82e45918c37429a59b14545c6a57db4e4Adam Powell if (mBackground != null) mBackground.setVisible(isVisible, false); 126a7cc06d82e45918c37429a59b14545c6a57db4e4Adam Powell if (mStackedBackground != null) mStackedBackground.setVisible(isVisible, false); 127a7cc06d82e45918c37429a59b14545c6a57db4e4Adam Powell if (mSplitBackground != null) mSplitBackground.setVisible(isVisible, false); 128a7cc06d82e45918c37429a59b14545c6a57db4e4Adam Powell } 129a7cc06d82e45918c37429a59b14545c6a57db4e4Adam Powell 130a7cc06d82e45918c37429a59b14545c6a57db4e4Adam Powell @Override 131a7cc06d82e45918c37429a59b14545c6a57db4e4Adam Powell protected boolean verifyDrawable(Drawable who) { 132a7cc06d82e45918c37429a59b14545c6a57db4e4Adam Powell return (who == mBackground && !mIsSplit) || (who == mStackedBackground && mIsStacked) || 133a7cc06d82e45918c37429a59b14545c6a57db4e4Adam Powell (who == mSplitBackground && mIsSplit) || super.verifyDrawable(who); 134a7cc06d82e45918c37429a59b14545c6a57db4e4Adam Powell } 135a7cc06d82e45918c37429a59b14545c6a57db4e4Adam Powell 136a7cc06d82e45918c37429a59b14545c6a57db4e4Adam Powell @Override 137a7cc06d82e45918c37429a59b14545c6a57db4e4Adam Powell protected void drawableStateChanged() { 138a7cc06d82e45918c37429a59b14545c6a57db4e4Adam Powell super.drawableStateChanged(); 139a7cc06d82e45918c37429a59b14545c6a57db4e4Adam Powell if (mBackground != null && mBackground.isStateful()) { 140a7cc06d82e45918c37429a59b14545c6a57db4e4Adam Powell mBackground.setState(getDrawableState()); 141a7cc06d82e45918c37429a59b14545c6a57db4e4Adam Powell } 142a7cc06d82e45918c37429a59b14545c6a57db4e4Adam Powell if (mStackedBackground != null && mStackedBackground.isStateful()) { 143a7cc06d82e45918c37429a59b14545c6a57db4e4Adam Powell mStackedBackground.setState(getDrawableState()); 144a7cc06d82e45918c37429a59b14545c6a57db4e4Adam Powell } 145a7cc06d82e45918c37429a59b14545c6a57db4e4Adam Powell if (mSplitBackground != null && mSplitBackground.isStateful()) { 146a7cc06d82e45918c37429a59b14545c6a57db4e4Adam Powell mSplitBackground.setState(getDrawableState()); 147a7cc06d82e45918c37429a59b14545c6a57db4e4Adam Powell } 148a7cc06d82e45918c37429a59b14545c6a57db4e4Adam Powell } 149a7cc06d82e45918c37429a59b14545c6a57db4e4Adam Powell 150a7cc06d82e45918c37429a59b14545c6a57db4e4Adam Powell @Override 151a7cc06d82e45918c37429a59b14545c6a57db4e4Adam Powell public void jumpDrawablesToCurrentState() { 152a7cc06d82e45918c37429a59b14545c6a57db4e4Adam Powell super.jumpDrawablesToCurrentState(); 153a7cc06d82e45918c37429a59b14545c6a57db4e4Adam Powell if (mBackground != null) { 154a7cc06d82e45918c37429a59b14545c6a57db4e4Adam Powell mBackground.jumpToCurrentState(); 155a7cc06d82e45918c37429a59b14545c6a57db4e4Adam Powell } 156a7cc06d82e45918c37429a59b14545c6a57db4e4Adam Powell if (mStackedBackground != null) { 157a7cc06d82e45918c37429a59b14545c6a57db4e4Adam Powell mStackedBackground.jumpToCurrentState(); 158a7cc06d82e45918c37429a59b14545c6a57db4e4Adam Powell } 159a7cc06d82e45918c37429a59b14545c6a57db4e4Adam Powell if (mSplitBackground != null) { 160a7cc06d82e45918c37429a59b14545c6a57db4e4Adam Powell mSplitBackground.jumpToCurrentState(); 161a7cc06d82e45918c37429a59b14545c6a57db4e4Adam Powell } 162a7cc06d82e45918c37429a59b14545c6a57db4e4Adam Powell } 163a7cc06d82e45918c37429a59b14545c6a57db4e4Adam Powell 164a7cc06d82e45918c37429a59b14545c6a57db4e4Adam Powell @Override 165a7cc06d82e45918c37429a59b14545c6a57db4e4Adam Powell public void onResolveDrawables(int layoutDirection) { 166a7cc06d82e45918c37429a59b14545c6a57db4e4Adam Powell super.onResolveDrawables(layoutDirection); 167a7cc06d82e45918c37429a59b14545c6a57db4e4Adam Powell if (mBackground != null) { 168a7cc06d82e45918c37429a59b14545c6a57db4e4Adam Powell mBackground.setLayoutDirection(layoutDirection); 169a7cc06d82e45918c37429a59b14545c6a57db4e4Adam Powell } 170a7cc06d82e45918c37429a59b14545c6a57db4e4Adam Powell if (mStackedBackground != null) { 171a7cc06d82e45918c37429a59b14545c6a57db4e4Adam Powell mStackedBackground.setLayoutDirection(layoutDirection); 172a7cc06d82e45918c37429a59b14545c6a57db4e4Adam Powell } 173a7cc06d82e45918c37429a59b14545c6a57db4e4Adam Powell if (mSplitBackground != null) { 174a7cc06d82e45918c37429a59b14545c6a57db4e4Adam Powell mSplitBackground.setLayoutDirection(layoutDirection); 175a7cc06d82e45918c37429a59b14545c6a57db4e4Adam Powell } 176a7cc06d82e45918c37429a59b14545c6a57db4e4Adam Powell } 177a7cc06d82e45918c37429a59b14545c6a57db4e4Adam Powell 17801feaee3d9767ef1185783877e92244f14d7d4baAdam Powell /** 17901feaee3d9767ef1185783877e92244f14d7d4baAdam Powell * Set the action bar into a "transitioning" state. While transitioning 18001feaee3d9767ef1185783877e92244f14d7d4baAdam Powell * the bar will block focus and touch from all of its descendants. This 18101feaee3d9767ef1185783877e92244f14d7d4baAdam Powell * prevents the user from interacting with the bar while it is animating 18201feaee3d9767ef1185783877e92244f14d7d4baAdam Powell * in or out. 18301feaee3d9767ef1185783877e92244f14d7d4baAdam Powell * 18401feaee3d9767ef1185783877e92244f14d7d4baAdam Powell * @param isTransitioning true if the bar is currently transitioning, false otherwise. 18501feaee3d9767ef1185783877e92244f14d7d4baAdam Powell */ 18601feaee3d9767ef1185783877e92244f14d7d4baAdam Powell public void setTransitioning(boolean isTransitioning) { 18701feaee3d9767ef1185783877e92244f14d7d4baAdam Powell mIsTransitioning = isTransitioning; 18801feaee3d9767ef1185783877e92244f14d7d4baAdam Powell setDescendantFocusability(isTransitioning ? FOCUS_BLOCK_DESCENDANTS 18901feaee3d9767ef1185783877e92244f14d7d4baAdam Powell : FOCUS_AFTER_DESCENDANTS); 19001feaee3d9767ef1185783877e92244f14d7d4baAdam Powell } 19101feaee3d9767ef1185783877e92244f14d7d4baAdam Powell 19201feaee3d9767ef1185783877e92244f14d7d4baAdam Powell @Override 19301feaee3d9767ef1185783877e92244f14d7d4baAdam Powell public boolean onInterceptTouchEvent(MotionEvent ev) { 19401feaee3d9767ef1185783877e92244f14d7d4baAdam Powell return mIsTransitioning || super.onInterceptTouchEvent(ev); 19501feaee3d9767ef1185783877e92244f14d7d4baAdam Powell } 19601feaee3d9767ef1185783877e92244f14d7d4baAdam Powell 1976ecf3d1690789ace1a667093ad6bbdd6cd35bda7Adam Powell @Override 1986ecf3d1690789ace1a667093ad6bbdd6cd35bda7Adam Powell public boolean onTouchEvent(MotionEvent ev) { 1996ecf3d1690789ace1a667093ad6bbdd6cd35bda7Adam Powell super.onTouchEvent(ev); 200dae7824c4b78d02159c6ad0896f246942d7b3d8cAdam Powell 201dae7824c4b78d02159c6ad0896f246942d7b3d8cAdam Powell // An action bar always eats touch events. 2026ecf3d1690789ace1a667093ad6bbdd6cd35bda7Adam Powell return true; 2036ecf3d1690789ace1a667093ad6bbdd6cd35bda7Adam Powell } 204dae7824c4b78d02159c6ad0896f246942d7b3d8cAdam Powell 2057d09f04363cdda6a3cf8b2ad1b67c9a07fa8975fAdam Powell @Override 2067d09f04363cdda6a3cf8b2ad1b67c9a07fa8975fAdam Powell public boolean onHoverEvent(MotionEvent ev) { 2077d09f04363cdda6a3cf8b2ad1b67c9a07fa8975fAdam Powell super.onHoverEvent(ev); 2087d09f04363cdda6a3cf8b2ad1b67c9a07fa8975fAdam Powell 2097d09f04363cdda6a3cf8b2ad1b67c9a07fa8975fAdam Powell // An action bar always eats hover events. 2107d09f04363cdda6a3cf8b2ad1b67c9a07fa8975fAdam Powell return true; 2117d09f04363cdda6a3cf8b2ad1b67c9a07fa8975fAdam Powell } 2127d09f04363cdda6a3cf8b2ad1b67c9a07fa8975fAdam Powell 213f5645cbafe7eed33452d888f16726bee8a0cd9feAdam Powell public void setTabContainer(ScrollingTabContainerView tabView) { 214dae7824c4b78d02159c6ad0896f246942d7b3d8cAdam Powell if (mTabContainer != null) { 215dae7824c4b78d02159c6ad0896f246942d7b3d8cAdam Powell removeView(mTabContainer); 216dae7824c4b78d02159c6ad0896f246942d7b3d8cAdam Powell } 217dae7824c4b78d02159c6ad0896f246942d7b3d8cAdam Powell mTabContainer = tabView; 21825151e4792e9be8dbb892b7eba7349773b8127afAdam Powell if (tabView != null) { 21925151e4792e9be8dbb892b7eba7349773b8127afAdam Powell addView(tabView); 220af6b97ebe0e6a67d1691c4d7789c7bc312c1e13eAdam Powell final ViewGroup.LayoutParams lp = tabView.getLayoutParams(); 221af6b97ebe0e6a67d1691c4d7789c7bc312c1e13eAdam Powell lp.width = LayoutParams.MATCH_PARENT; 222af6b97ebe0e6a67d1691c4d7789c7bc312c1e13eAdam Powell lp.height = LayoutParams.WRAP_CONTENT; 223f5645cbafe7eed33452d888f16726bee8a0cd9feAdam Powell tabView.setAllowCollapse(false); 22425151e4792e9be8dbb892b7eba7349773b8127afAdam Powell } 225dae7824c4b78d02159c6ad0896f246942d7b3d8cAdam Powell } 226dae7824c4b78d02159c6ad0896f246942d7b3d8cAdam Powell 227dae7824c4b78d02159c6ad0896f246942d7b3d8cAdam Powell public View getTabContainer() { 228dae7824c4b78d02159c6ad0896f246942d7b3d8cAdam Powell return mTabContainer; 229dae7824c4b78d02159c6ad0896f246942d7b3d8cAdam Powell } 230dae7824c4b78d02159c6ad0896f246942d7b3d8cAdam Powell 231dae7824c4b78d02159c6ad0896f246942d7b3d8cAdam Powell @Override 232a72ef62e5c329a19eab9935acba816fc1369c637Adam Powell public void onDraw(Canvas canvas) { 233a72ef62e5c329a19eab9935acba816fc1369c637Adam Powell if (getWidth() == 0 || getHeight() == 0) { 234a72ef62e5c329a19eab9935acba816fc1369c637Adam Powell return; 235a72ef62e5c329a19eab9935acba816fc1369c637Adam Powell } 236a72ef62e5c329a19eab9935acba816fc1369c637Adam Powell 237a72ef62e5c329a19eab9935acba816fc1369c637Adam Powell if (mIsSplit) { 238a72ef62e5c329a19eab9935acba816fc1369c637Adam Powell if (mSplitBackground != null) mSplitBackground.draw(canvas); 239a72ef62e5c329a19eab9935acba816fc1369c637Adam Powell } else { 240a72ef62e5c329a19eab9935acba816fc1369c637Adam Powell if (mBackground != null) { 241a72ef62e5c329a19eab9935acba816fc1369c637Adam Powell mBackground.draw(canvas); 242a72ef62e5c329a19eab9935acba816fc1369c637Adam Powell } 243a72ef62e5c329a19eab9935acba816fc1369c637Adam Powell if (mStackedBackground != null && mIsStacked) { 244a72ef62e5c329a19eab9935acba816fc1369c637Adam Powell mStackedBackground.draw(canvas); 245a72ef62e5c329a19eab9935acba816fc1369c637Adam Powell } 246a72ef62e5c329a19eab9935acba816fc1369c637Adam Powell } 247a72ef62e5c329a19eab9935acba816fc1369c637Adam Powell } 248a72ef62e5c329a19eab9935acba816fc1369c637Adam Powell 249a72ef62e5c329a19eab9935acba816fc1369c637Adam Powell @Override 250640a66eac612b850b5dabd3b93bd94f83ed2d567Adam Powell public ActionMode startActionModeForChild(View child, ActionMode.Callback callback) { 251640a66eac612b850b5dabd3b93bd94f83ed2d567Adam Powell // No starting an action mode for an action bar child! (Where would it go?) 252640a66eac612b850b5dabd3b93bd94f83ed2d567Adam Powell return null; 253640a66eac612b850b5dabd3b93bd94f83ed2d567Adam Powell } 254640a66eac612b850b5dabd3b93bd94f83ed2d567Adam Powell 255640a66eac612b850b5dabd3b93bd94f83ed2d567Adam Powell @Override 256dae7824c4b78d02159c6ad0896f246942d7b3d8cAdam Powell public void onMeasure(int widthMeasureSpec, int heightMeasureSpec) { 257dae7824c4b78d02159c6ad0896f246942d7b3d8cAdam Powell super.onMeasure(widthMeasureSpec, heightMeasureSpec); 258d21aa12e8eb9d46ee92bf408b4b48386c6bf062dAdam Powell 259f6ce6a9bacbb220c6ea7b552c481237f23e64ae7Adam Powell if (mActionBarView == null) return; 260310849abb1a0763ea9912b59187f0a4271efaa2eAdam Powell 261f6ce6a9bacbb220c6ea7b552c481237f23e64ae7Adam Powell final LayoutParams lp = (LayoutParams) mActionBarView.getLayoutParams(); 262f6ce6a9bacbb220c6ea7b552c481237f23e64ae7Adam Powell final int actionBarViewHeight = mActionBarView.isCollapsed() ? 0 : 263f6ce6a9bacbb220c6ea7b552c481237f23e64ae7Adam Powell mActionBarView.getMeasuredHeight() + lp.topMargin + lp.bottomMargin; 264d21aa12e8eb9d46ee92bf408b4b48386c6bf062dAdam Powell 265dae7824c4b78d02159c6ad0896f246942d7b3d8cAdam Powell if (mTabContainer != null && mTabContainer.getVisibility() != GONE) { 266dae7824c4b78d02159c6ad0896f246942d7b3d8cAdam Powell final int mode = MeasureSpec.getMode(heightMeasureSpec); 267dae7824c4b78d02159c6ad0896f246942d7b3d8cAdam Powell if (mode == MeasureSpec.AT_MOST) { 268dae7824c4b78d02159c6ad0896f246942d7b3d8cAdam Powell final int maxHeight = MeasureSpec.getSize(heightMeasureSpec); 269dae7824c4b78d02159c6ad0896f246942d7b3d8cAdam Powell setMeasuredDimension(getMeasuredWidth(), 270f6ce6a9bacbb220c6ea7b552c481237f23e64ae7Adam Powell Math.min(actionBarViewHeight + mTabContainer.getMeasuredHeight(), 271f6ce6a9bacbb220c6ea7b552c481237f23e64ae7Adam Powell maxHeight)); 272dae7824c4b78d02159c6ad0896f246942d7b3d8cAdam Powell } 273dae7824c4b78d02159c6ad0896f246942d7b3d8cAdam Powell } 274dae7824c4b78d02159c6ad0896f246942d7b3d8cAdam Powell } 275dae7824c4b78d02159c6ad0896f246942d7b3d8cAdam Powell 276dae7824c4b78d02159c6ad0896f246942d7b3d8cAdam Powell @Override 277dae7824c4b78d02159c6ad0896f246942d7b3d8cAdam Powell public void onLayout(boolean changed, int l, int t, int r, int b) { 278dae7824c4b78d02159c6ad0896f246942d7b3d8cAdam Powell super.onLayout(changed, l, t, r, b); 279a72ef62e5c329a19eab9935acba816fc1369c637Adam Powell 280a72ef62e5c329a19eab9935acba816fc1369c637Adam Powell final boolean hasTabs = mTabContainer != null && mTabContainer.getVisibility() != GONE; 281a72ef62e5c329a19eab9935acba816fc1369c637Adam Powell 282dae7824c4b78d02159c6ad0896f246942d7b3d8cAdam Powell if (mTabContainer != null && mTabContainer.getVisibility() != GONE) { 283dae7824c4b78d02159c6ad0896f246942d7b3d8cAdam Powell final int containerHeight = getMeasuredHeight(); 284310849abb1a0763ea9912b59187f0a4271efaa2eAdam Powell final int tabHeight = mTabContainer.getMeasuredHeight(); 285310849abb1a0763ea9912b59187f0a4271efaa2eAdam Powell 286310849abb1a0763ea9912b59187f0a4271efaa2eAdam Powell if ((mActionBarView.getDisplayOptions() & ActionBar.DISPLAY_SHOW_HOME) == 0) { 287310849abb1a0763ea9912b59187f0a4271efaa2eAdam Powell // Not showing home, put tabs on top. 288310849abb1a0763ea9912b59187f0a4271efaa2eAdam Powell final int count = getChildCount(); 289f6ce6a9bacbb220c6ea7b552c481237f23e64ae7Adam Powell for (int i = 0; i < count; i++) { 290310849abb1a0763ea9912b59187f0a4271efaa2eAdam Powell final View child = getChildAt(i); 291310849abb1a0763ea9912b59187f0a4271efaa2eAdam Powell 292310849abb1a0763ea9912b59187f0a4271efaa2eAdam Powell if (child == mTabContainer) continue; 293310849abb1a0763ea9912b59187f0a4271efaa2eAdam Powell 294f6ce6a9bacbb220c6ea7b552c481237f23e64ae7Adam Powell if (!mActionBarView.isCollapsed()) { 295f6ce6a9bacbb220c6ea7b552c481237f23e64ae7Adam Powell child.offsetTopAndBottom(tabHeight); 296f6ce6a9bacbb220c6ea7b552c481237f23e64ae7Adam Powell } 297310849abb1a0763ea9912b59187f0a4271efaa2eAdam Powell } 298310849abb1a0763ea9912b59187f0a4271efaa2eAdam Powell mTabContainer.layout(l, 0, r, tabHeight); 299310849abb1a0763ea9912b59187f0a4271efaa2eAdam Powell } else { 300310849abb1a0763ea9912b59187f0a4271efaa2eAdam Powell mTabContainer.layout(l, containerHeight - tabHeight, r, containerHeight); 301310849abb1a0763ea9912b59187f0a4271efaa2eAdam Powell } 302dae7824c4b78d02159c6ad0896f246942d7b3d8cAdam Powell } 303a72ef62e5c329a19eab9935acba816fc1369c637Adam Powell 304a72ef62e5c329a19eab9935acba816fc1369c637Adam Powell boolean needsInvalidate = false; 305a72ef62e5c329a19eab9935acba816fc1369c637Adam Powell if (mIsSplit) { 306a72ef62e5c329a19eab9935acba816fc1369c637Adam Powell if (mSplitBackground != null) { 307a72ef62e5c329a19eab9935acba816fc1369c637Adam Powell mSplitBackground.setBounds(0, 0, getMeasuredWidth(), getMeasuredHeight()); 308a72ef62e5c329a19eab9935acba816fc1369c637Adam Powell needsInvalidate = true; 309a72ef62e5c329a19eab9935acba816fc1369c637Adam Powell } 310a72ef62e5c329a19eab9935acba816fc1369c637Adam Powell } else { 311a72ef62e5c329a19eab9935acba816fc1369c637Adam Powell if (mBackground != null) { 312a72ef62e5c329a19eab9935acba816fc1369c637Adam Powell mBackground.setBounds(mActionBarView.getLeft(), mActionBarView.getTop(), 313a72ef62e5c329a19eab9935acba816fc1369c637Adam Powell mActionBarView.getRight(), mActionBarView.getBottom()); 314a72ef62e5c329a19eab9935acba816fc1369c637Adam Powell needsInvalidate = true; 315a72ef62e5c329a19eab9935acba816fc1369c637Adam Powell } 316a72ef62e5c329a19eab9935acba816fc1369c637Adam Powell if ((mIsStacked = hasTabs && mStackedBackground != null)) { 317a72ef62e5c329a19eab9935acba816fc1369c637Adam Powell mStackedBackground.setBounds(mTabContainer.getLeft(), mTabContainer.getTop(), 318a72ef62e5c329a19eab9935acba816fc1369c637Adam Powell mTabContainer.getRight(), mTabContainer.getBottom()); 319a72ef62e5c329a19eab9935acba816fc1369c637Adam Powell needsInvalidate = true; 320a72ef62e5c329a19eab9935acba816fc1369c637Adam Powell } 321a72ef62e5c329a19eab9935acba816fc1369c637Adam Powell } 322a72ef62e5c329a19eab9935acba816fc1369c637Adam Powell 323a72ef62e5c329a19eab9935acba816fc1369c637Adam Powell if (needsInvalidate) { 324a72ef62e5c329a19eab9935acba816fc1369c637Adam Powell invalidate(); 325a72ef62e5c329a19eab9935acba816fc1369c637Adam Powell } 326dae7824c4b78d02159c6ad0896f246942d7b3d8cAdam Powell } 32745f1e08c348ccb129bcc25e438c05421f7123f41Adam Powell} 328