ActionBarContainer.java revision e43340c80dc66c45edc793ecd0343774aa34d108
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 1945f1e08c348ccb129bcc25e438c05421f7123f41Adam Powellimport android.content.Context; 2045f1e08c348ccb129bcc25e438c05421f7123f41Adam Powellimport android.content.res.TypedArray; 21a72ef62e5c329a19eab9935acba816fc1369c637Adam Powellimport android.graphics.Canvas; 227f610fed107b158c144dca1b20a44ee91eb8c934Alan Viveretteimport android.graphics.ColorFilter; 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; 46e43340c80dc66c45edc793ecd0343774aa34d108Adam Powell private int mHeight; 47a72ef62e5c329a19eab9935acba816fc1369c637Adam Powell 4845f1e08c348ccb129bcc25e438c05421f7123f41Adam Powell public ActionBarContainer(Context context) { 4945f1e08c348ccb129bcc25e438c05421f7123f41Adam Powell this(context, null); 5045f1e08c348ccb129bcc25e438c05421f7123f41Adam Powell } 5145f1e08c348ccb129bcc25e438c05421f7123f41Adam Powell 5245f1e08c348ccb129bcc25e438c05421f7123f41Adam Powell public ActionBarContainer(Context context, AttributeSet attrs) { 5345f1e08c348ccb129bcc25e438c05421f7123f41Adam Powell super(context, attrs); 5445f1e08c348ccb129bcc25e438c05421f7123f41Adam Powell 557f610fed107b158c144dca1b20a44ee91eb8c934Alan Viverette // Set a transparent background so that we project appropriately. 567f610fed107b158c144dca1b20a44ee91eb8c934Alan Viverette setBackground(new ActionBarBackgroundDrawable()); 57a72ef62e5c329a19eab9935acba816fc1369c637Adam Powell 5845f1e08c348ccb129bcc25e438c05421f7123f41Adam Powell TypedArray a = context.obtainStyledAttributes(attrs, 5945f1e08c348ccb129bcc25e438c05421f7123f41Adam Powell com.android.internal.R.styleable.ActionBar); 60a72ef62e5c329a19eab9935acba816fc1369c637Adam Powell mBackground = a.getDrawable(com.android.internal.R.styleable.ActionBar_background); 61a72ef62e5c329a19eab9935acba816fc1369c637Adam Powell mStackedBackground = a.getDrawable( 62a72ef62e5c329a19eab9935acba816fc1369c637Adam Powell com.android.internal.R.styleable.ActionBar_backgroundStacked); 63e43340c80dc66c45edc793ecd0343774aa34d108Adam Powell mHeight = a.getDimensionPixelSize(com.android.internal.R.styleable.ActionBar_height, -1); 64a72ef62e5c329a19eab9935acba816fc1369c637Adam Powell 65a72ef62e5c329a19eab9935acba816fc1369c637Adam Powell if (getId() == com.android.internal.R.id.split_action_bar) { 66a72ef62e5c329a19eab9935acba816fc1369c637Adam Powell mIsSplit = true; 67a72ef62e5c329a19eab9935acba816fc1369c637Adam Powell mSplitBackground = a.getDrawable( 68a72ef62e5c329a19eab9935acba816fc1369c637Adam Powell com.android.internal.R.styleable.ActionBar_backgroundSplit); 69a72ef62e5c329a19eab9935acba816fc1369c637Adam Powell } 7045f1e08c348ccb129bcc25e438c05421f7123f41Adam Powell a.recycle(); 71a72ef62e5c329a19eab9935acba816fc1369c637Adam Powell 72a72ef62e5c329a19eab9935acba816fc1369c637Adam Powell setWillNotDraw(mIsSplit ? mSplitBackground == null : 73a72ef62e5c329a19eab9935acba816fc1369c637Adam Powell mBackground == null && mStackedBackground == null); 7445f1e08c348ccb129bcc25e438c05421f7123f41Adam Powell } 756ecf3d1690789ace1a667093ad6bbdd6cd35bda7Adam Powell 76310849abb1a0763ea9912b59187f0a4271efaa2eAdam Powell @Override 77310849abb1a0763ea9912b59187f0a4271efaa2eAdam Powell public void onFinishInflate() { 78310849abb1a0763ea9912b59187f0a4271efaa2eAdam Powell super.onFinishInflate(); 79310849abb1a0763ea9912b59187f0a4271efaa2eAdam Powell mActionBarView = (ActionBarView) findViewById(com.android.internal.R.id.action_bar); 80310849abb1a0763ea9912b59187f0a4271efaa2eAdam Powell } 81310849abb1a0763ea9912b59187f0a4271efaa2eAdam Powell 82f88b915567a37c481c4c50a6cc57e1ec0e7cf50dAdam Powell public void setPrimaryBackground(Drawable bg) { 83a7cc06d82e45918c37429a59b14545c6a57db4e4Adam Powell if (mBackground != null) { 84a7cc06d82e45918c37429a59b14545c6a57db4e4Adam Powell mBackground.setCallback(null); 85a7cc06d82e45918c37429a59b14545c6a57db4e4Adam Powell unscheduleDrawable(mBackground); 86a7cc06d82e45918c37429a59b14545c6a57db4e4Adam Powell } 87f88b915567a37c481c4c50a6cc57e1ec0e7cf50dAdam Powell mBackground = bg; 88a7cc06d82e45918c37429a59b14545c6a57db4e4Adam Powell if (bg != null) { 89a7cc06d82e45918c37429a59b14545c6a57db4e4Adam Powell bg.setCallback(this); 90e8c8ae401b6f0d894a766a1601f55f0fe567df02Adam Powell if (mActionBarView != null) { 91e8c8ae401b6f0d894a766a1601f55f0fe567df02Adam Powell mBackground.setBounds(mActionBarView.getLeft(), mActionBarView.getTop(), 92e8c8ae401b6f0d894a766a1601f55f0fe567df02Adam Powell mActionBarView.getRight(), mActionBarView.getBottom()); 93e8c8ae401b6f0d894a766a1601f55f0fe567df02Adam Powell } 94a7cc06d82e45918c37429a59b14545c6a57db4e4Adam Powell } 95a7cc06d82e45918c37429a59b14545c6a57db4e4Adam Powell setWillNotDraw(mIsSplit ? mSplitBackground == null : 96a7cc06d82e45918c37429a59b14545c6a57db4e4Adam Powell mBackground == null && mStackedBackground == null); 97f88b915567a37c481c4c50a6cc57e1ec0e7cf50dAdam Powell invalidate(); 98f88b915567a37c481c4c50a6cc57e1ec0e7cf50dAdam Powell } 99f88b915567a37c481c4c50a6cc57e1ec0e7cf50dAdam Powell 100f88b915567a37c481c4c50a6cc57e1ec0e7cf50dAdam Powell public void setStackedBackground(Drawable bg) { 101a7cc06d82e45918c37429a59b14545c6a57db4e4Adam Powell if (mStackedBackground != null) { 102a7cc06d82e45918c37429a59b14545c6a57db4e4Adam Powell mStackedBackground.setCallback(null); 103a7cc06d82e45918c37429a59b14545c6a57db4e4Adam Powell unscheduleDrawable(mStackedBackground); 104a7cc06d82e45918c37429a59b14545c6a57db4e4Adam Powell } 105f88b915567a37c481c4c50a6cc57e1ec0e7cf50dAdam Powell mStackedBackground = bg; 106a7cc06d82e45918c37429a59b14545c6a57db4e4Adam Powell if (bg != null) { 107a7cc06d82e45918c37429a59b14545c6a57db4e4Adam Powell bg.setCallback(this); 108e8c8ae401b6f0d894a766a1601f55f0fe567df02Adam Powell if ((mIsStacked && mStackedBackground != null)) { 109e8c8ae401b6f0d894a766a1601f55f0fe567df02Adam Powell mStackedBackground.setBounds(mTabContainer.getLeft(), mTabContainer.getTop(), 110e8c8ae401b6f0d894a766a1601f55f0fe567df02Adam Powell mTabContainer.getRight(), mTabContainer.getBottom()); 111e8c8ae401b6f0d894a766a1601f55f0fe567df02Adam Powell } 112a7cc06d82e45918c37429a59b14545c6a57db4e4Adam Powell } 113a7cc06d82e45918c37429a59b14545c6a57db4e4Adam Powell setWillNotDraw(mIsSplit ? mSplitBackground == null : 114a7cc06d82e45918c37429a59b14545c6a57db4e4Adam Powell mBackground == null && mStackedBackground == null); 115f88b915567a37c481c4c50a6cc57e1ec0e7cf50dAdam Powell invalidate(); 116f88b915567a37c481c4c50a6cc57e1ec0e7cf50dAdam Powell } 117f88b915567a37c481c4c50a6cc57e1ec0e7cf50dAdam Powell 118f88b915567a37c481c4c50a6cc57e1ec0e7cf50dAdam Powell public void setSplitBackground(Drawable bg) { 119a7cc06d82e45918c37429a59b14545c6a57db4e4Adam Powell if (mSplitBackground != null) { 120a7cc06d82e45918c37429a59b14545c6a57db4e4Adam Powell mSplitBackground.setCallback(null); 121a7cc06d82e45918c37429a59b14545c6a57db4e4Adam Powell unscheduleDrawable(mSplitBackground); 122a7cc06d82e45918c37429a59b14545c6a57db4e4Adam Powell } 123f88b915567a37c481c4c50a6cc57e1ec0e7cf50dAdam Powell mSplitBackground = bg; 124a7cc06d82e45918c37429a59b14545c6a57db4e4Adam Powell if (bg != null) { 125a7cc06d82e45918c37429a59b14545c6a57db4e4Adam Powell bg.setCallback(this); 126e8c8ae401b6f0d894a766a1601f55f0fe567df02Adam Powell if (mIsSplit && mSplitBackground != null) { 127e8c8ae401b6f0d894a766a1601f55f0fe567df02Adam Powell mSplitBackground.setBounds(0, 0, getMeasuredWidth(), getMeasuredHeight()); 128e8c8ae401b6f0d894a766a1601f55f0fe567df02Adam Powell } 129a7cc06d82e45918c37429a59b14545c6a57db4e4Adam Powell } 130a7cc06d82e45918c37429a59b14545c6a57db4e4Adam Powell setWillNotDraw(mIsSplit ? mSplitBackground == null : 131a7cc06d82e45918c37429a59b14545c6a57db4e4Adam Powell mBackground == null && mStackedBackground == null); 132f88b915567a37c481c4c50a6cc57e1ec0e7cf50dAdam Powell invalidate(); 133f88b915567a37c481c4c50a6cc57e1ec0e7cf50dAdam Powell } 134f88b915567a37c481c4c50a6cc57e1ec0e7cf50dAdam Powell 135a7cc06d82e45918c37429a59b14545c6a57db4e4Adam Powell @Override 136a7cc06d82e45918c37429a59b14545c6a57db4e4Adam Powell public void setVisibility(int visibility) { 137a7cc06d82e45918c37429a59b14545c6a57db4e4Adam Powell super.setVisibility(visibility); 138a7cc06d82e45918c37429a59b14545c6a57db4e4Adam Powell final boolean isVisible = visibility == VISIBLE; 139a7cc06d82e45918c37429a59b14545c6a57db4e4Adam Powell if (mBackground != null) mBackground.setVisible(isVisible, false); 140a7cc06d82e45918c37429a59b14545c6a57db4e4Adam Powell if (mStackedBackground != null) mStackedBackground.setVisible(isVisible, false); 141a7cc06d82e45918c37429a59b14545c6a57db4e4Adam Powell if (mSplitBackground != null) mSplitBackground.setVisible(isVisible, false); 142a7cc06d82e45918c37429a59b14545c6a57db4e4Adam Powell } 143a7cc06d82e45918c37429a59b14545c6a57db4e4Adam Powell 144a7cc06d82e45918c37429a59b14545c6a57db4e4Adam Powell @Override 145a7cc06d82e45918c37429a59b14545c6a57db4e4Adam Powell protected boolean verifyDrawable(Drawable who) { 146a7cc06d82e45918c37429a59b14545c6a57db4e4Adam Powell return (who == mBackground && !mIsSplit) || (who == mStackedBackground && mIsStacked) || 147a7cc06d82e45918c37429a59b14545c6a57db4e4Adam Powell (who == mSplitBackground && mIsSplit) || super.verifyDrawable(who); 148a7cc06d82e45918c37429a59b14545c6a57db4e4Adam Powell } 149a7cc06d82e45918c37429a59b14545c6a57db4e4Adam Powell 150a7cc06d82e45918c37429a59b14545c6a57db4e4Adam Powell @Override 151a7cc06d82e45918c37429a59b14545c6a57db4e4Adam Powell protected void drawableStateChanged() { 152a7cc06d82e45918c37429a59b14545c6a57db4e4Adam Powell super.drawableStateChanged(); 153a7cc06d82e45918c37429a59b14545c6a57db4e4Adam Powell if (mBackground != null && mBackground.isStateful()) { 154a7cc06d82e45918c37429a59b14545c6a57db4e4Adam Powell mBackground.setState(getDrawableState()); 155a7cc06d82e45918c37429a59b14545c6a57db4e4Adam Powell } 156a7cc06d82e45918c37429a59b14545c6a57db4e4Adam Powell if (mStackedBackground != null && mStackedBackground.isStateful()) { 157a7cc06d82e45918c37429a59b14545c6a57db4e4Adam Powell mStackedBackground.setState(getDrawableState()); 158a7cc06d82e45918c37429a59b14545c6a57db4e4Adam Powell } 159a7cc06d82e45918c37429a59b14545c6a57db4e4Adam Powell if (mSplitBackground != null && mSplitBackground.isStateful()) { 160a7cc06d82e45918c37429a59b14545c6a57db4e4Adam Powell mSplitBackground.setState(getDrawableState()); 161a7cc06d82e45918c37429a59b14545c6a57db4e4Adam Powell } 162a7cc06d82e45918c37429a59b14545c6a57db4e4Adam Powell } 163a7cc06d82e45918c37429a59b14545c6a57db4e4Adam Powell 164a7cc06d82e45918c37429a59b14545c6a57db4e4Adam Powell @Override 165a7cc06d82e45918c37429a59b14545c6a57db4e4Adam Powell public void jumpDrawablesToCurrentState() { 166a7cc06d82e45918c37429a59b14545c6a57db4e4Adam Powell super.jumpDrawablesToCurrentState(); 167a7cc06d82e45918c37429a59b14545c6a57db4e4Adam Powell if (mBackground != null) { 168a7cc06d82e45918c37429a59b14545c6a57db4e4Adam Powell mBackground.jumpToCurrentState(); 169a7cc06d82e45918c37429a59b14545c6a57db4e4Adam Powell } 170a7cc06d82e45918c37429a59b14545c6a57db4e4Adam Powell if (mStackedBackground != null) { 171a7cc06d82e45918c37429a59b14545c6a57db4e4Adam Powell mStackedBackground.jumpToCurrentState(); 172a7cc06d82e45918c37429a59b14545c6a57db4e4Adam Powell } 173a7cc06d82e45918c37429a59b14545c6a57db4e4Adam Powell if (mSplitBackground != null) { 174a7cc06d82e45918c37429a59b14545c6a57db4e4Adam Powell mSplitBackground.jumpToCurrentState(); 175a7cc06d82e45918c37429a59b14545c6a57db4e4Adam Powell } 176a7cc06d82e45918c37429a59b14545c6a57db4e4Adam Powell } 177a7cc06d82e45918c37429a59b14545c6a57db4e4Adam Powell 1784457e85a7090ad51726d50a4daf981d917cceeddFabrice Di Meglio /** 1794457e85a7090ad51726d50a4daf981d917cceeddFabrice Di Meglio * @hide 1804457e85a7090ad51726d50a4daf981d917cceeddFabrice Di Meglio */ 181a7cc06d82e45918c37429a59b14545c6a57db4e4Adam Powell @Override 182a7cc06d82e45918c37429a59b14545c6a57db4e4Adam Powell public void onResolveDrawables(int layoutDirection) { 183a7cc06d82e45918c37429a59b14545c6a57db4e4Adam Powell super.onResolveDrawables(layoutDirection); 184a7cc06d82e45918c37429a59b14545c6a57db4e4Adam Powell if (mBackground != null) { 185a7cc06d82e45918c37429a59b14545c6a57db4e4Adam Powell mBackground.setLayoutDirection(layoutDirection); 186a7cc06d82e45918c37429a59b14545c6a57db4e4Adam Powell } 187a7cc06d82e45918c37429a59b14545c6a57db4e4Adam Powell if (mStackedBackground != null) { 188a7cc06d82e45918c37429a59b14545c6a57db4e4Adam Powell mStackedBackground.setLayoutDirection(layoutDirection); 189a7cc06d82e45918c37429a59b14545c6a57db4e4Adam Powell } 190a7cc06d82e45918c37429a59b14545c6a57db4e4Adam Powell if (mSplitBackground != null) { 191a7cc06d82e45918c37429a59b14545c6a57db4e4Adam Powell mSplitBackground.setLayoutDirection(layoutDirection); 192a7cc06d82e45918c37429a59b14545c6a57db4e4Adam Powell } 193a7cc06d82e45918c37429a59b14545c6a57db4e4Adam Powell } 194a7cc06d82e45918c37429a59b14545c6a57db4e4Adam Powell 19501feaee3d9767ef1185783877e92244f14d7d4baAdam Powell /** 19601feaee3d9767ef1185783877e92244f14d7d4baAdam Powell * Set the action bar into a "transitioning" state. While transitioning 19701feaee3d9767ef1185783877e92244f14d7d4baAdam Powell * the bar will block focus and touch from all of its descendants. This 19801feaee3d9767ef1185783877e92244f14d7d4baAdam Powell * prevents the user from interacting with the bar while it is animating 19901feaee3d9767ef1185783877e92244f14d7d4baAdam Powell * in or out. 20001feaee3d9767ef1185783877e92244f14d7d4baAdam Powell * 20101feaee3d9767ef1185783877e92244f14d7d4baAdam Powell * @param isTransitioning true if the bar is currently transitioning, false otherwise. 20201feaee3d9767ef1185783877e92244f14d7d4baAdam Powell */ 20301feaee3d9767ef1185783877e92244f14d7d4baAdam Powell public void setTransitioning(boolean isTransitioning) { 20401feaee3d9767ef1185783877e92244f14d7d4baAdam Powell mIsTransitioning = isTransitioning; 20501feaee3d9767ef1185783877e92244f14d7d4baAdam Powell setDescendantFocusability(isTransitioning ? FOCUS_BLOCK_DESCENDANTS 20601feaee3d9767ef1185783877e92244f14d7d4baAdam Powell : FOCUS_AFTER_DESCENDANTS); 20701feaee3d9767ef1185783877e92244f14d7d4baAdam Powell } 20801feaee3d9767ef1185783877e92244f14d7d4baAdam Powell 20901feaee3d9767ef1185783877e92244f14d7d4baAdam Powell @Override 21001feaee3d9767ef1185783877e92244f14d7d4baAdam Powell public boolean onInterceptTouchEvent(MotionEvent ev) { 21101feaee3d9767ef1185783877e92244f14d7d4baAdam Powell return mIsTransitioning || super.onInterceptTouchEvent(ev); 21201feaee3d9767ef1185783877e92244f14d7d4baAdam Powell } 21301feaee3d9767ef1185783877e92244f14d7d4baAdam Powell 2146ecf3d1690789ace1a667093ad6bbdd6cd35bda7Adam Powell @Override 2156ecf3d1690789ace1a667093ad6bbdd6cd35bda7Adam Powell public boolean onTouchEvent(MotionEvent ev) { 2166ecf3d1690789ace1a667093ad6bbdd6cd35bda7Adam Powell super.onTouchEvent(ev); 217dae7824c4b78d02159c6ad0896f246942d7b3d8cAdam Powell 218dae7824c4b78d02159c6ad0896f246942d7b3d8cAdam Powell // An action bar always eats touch events. 2196ecf3d1690789ace1a667093ad6bbdd6cd35bda7Adam Powell return true; 2206ecf3d1690789ace1a667093ad6bbdd6cd35bda7Adam Powell } 221dae7824c4b78d02159c6ad0896f246942d7b3d8cAdam Powell 2227d09f04363cdda6a3cf8b2ad1b67c9a07fa8975fAdam Powell @Override 2237d09f04363cdda6a3cf8b2ad1b67c9a07fa8975fAdam Powell public boolean onHoverEvent(MotionEvent ev) { 2247d09f04363cdda6a3cf8b2ad1b67c9a07fa8975fAdam Powell super.onHoverEvent(ev); 2257d09f04363cdda6a3cf8b2ad1b67c9a07fa8975fAdam Powell 2267d09f04363cdda6a3cf8b2ad1b67c9a07fa8975fAdam Powell // An action bar always eats hover events. 2277d09f04363cdda6a3cf8b2ad1b67c9a07fa8975fAdam Powell return true; 2287d09f04363cdda6a3cf8b2ad1b67c9a07fa8975fAdam Powell } 2297d09f04363cdda6a3cf8b2ad1b67c9a07fa8975fAdam Powell 230f5645cbafe7eed33452d888f16726bee8a0cd9feAdam Powell public void setTabContainer(ScrollingTabContainerView tabView) { 231dae7824c4b78d02159c6ad0896f246942d7b3d8cAdam Powell if (mTabContainer != null) { 232dae7824c4b78d02159c6ad0896f246942d7b3d8cAdam Powell removeView(mTabContainer); 233dae7824c4b78d02159c6ad0896f246942d7b3d8cAdam Powell } 234dae7824c4b78d02159c6ad0896f246942d7b3d8cAdam Powell mTabContainer = tabView; 23525151e4792e9be8dbb892b7eba7349773b8127afAdam Powell if (tabView != null) { 23625151e4792e9be8dbb892b7eba7349773b8127afAdam Powell addView(tabView); 237af6b97ebe0e6a67d1691c4d7789c7bc312c1e13eAdam Powell final ViewGroup.LayoutParams lp = tabView.getLayoutParams(); 238af6b97ebe0e6a67d1691c4d7789c7bc312c1e13eAdam Powell lp.width = LayoutParams.MATCH_PARENT; 239af6b97ebe0e6a67d1691c4d7789c7bc312c1e13eAdam Powell lp.height = LayoutParams.WRAP_CONTENT; 240f5645cbafe7eed33452d888f16726bee8a0cd9feAdam Powell tabView.setAllowCollapse(false); 24125151e4792e9be8dbb892b7eba7349773b8127afAdam Powell } 242dae7824c4b78d02159c6ad0896f246942d7b3d8cAdam Powell } 243dae7824c4b78d02159c6ad0896f246942d7b3d8cAdam Powell 244dae7824c4b78d02159c6ad0896f246942d7b3d8cAdam Powell public View getTabContainer() { 245dae7824c4b78d02159c6ad0896f246942d7b3d8cAdam Powell return mTabContainer; 246dae7824c4b78d02159c6ad0896f246942d7b3d8cAdam Powell } 247dae7824c4b78d02159c6ad0896f246942d7b3d8cAdam Powell 248dae7824c4b78d02159c6ad0896f246942d7b3d8cAdam Powell @Override 249640a66eac612b850b5dabd3b93bd94f83ed2d567Adam Powell public ActionMode startActionModeForChild(View child, ActionMode.Callback callback) { 250640a66eac612b850b5dabd3b93bd94f83ed2d567Adam Powell // No starting an action mode for an action bar child! (Where would it go?) 251640a66eac612b850b5dabd3b93bd94f83ed2d567Adam Powell return null; 252640a66eac612b850b5dabd3b93bd94f83ed2d567Adam Powell } 253640a66eac612b850b5dabd3b93bd94f83ed2d567Adam Powell 254640a66eac612b850b5dabd3b93bd94f83ed2d567Adam Powell @Override 255dae7824c4b78d02159c6ad0896f246942d7b3d8cAdam Powell public void onMeasure(int widthMeasureSpec, int heightMeasureSpec) { 256e43340c80dc66c45edc793ecd0343774aa34d108Adam Powell if (mActionBarView == null && 257e43340c80dc66c45edc793ecd0343774aa34d108Adam Powell MeasureSpec.getMode(heightMeasureSpec) == MeasureSpec.AT_MOST && mHeight >= 0) { 258e43340c80dc66c45edc793ecd0343774aa34d108Adam Powell heightMeasureSpec = MeasureSpec.makeMeasureSpec( 259e43340c80dc66c45edc793ecd0343774aa34d108Adam Powell Math.min(mHeight, MeasureSpec.getSize(heightMeasureSpec)), MeasureSpec.AT_MOST); 260e43340c80dc66c45edc793ecd0343774aa34d108Adam Powell } 261dae7824c4b78d02159c6ad0896f246942d7b3d8cAdam Powell super.onMeasure(widthMeasureSpec, heightMeasureSpec); 262d21aa12e8eb9d46ee92bf408b4b48386c6bf062dAdam Powell 263f6ce6a9bacbb220c6ea7b552c481237f23e64ae7Adam Powell if (mActionBarView == null) return; 264310849abb1a0763ea9912b59187f0a4271efaa2eAdam Powell 265f6ce6a9bacbb220c6ea7b552c481237f23e64ae7Adam Powell final LayoutParams lp = (LayoutParams) mActionBarView.getLayoutParams(); 266f6ce6a9bacbb220c6ea7b552c481237f23e64ae7Adam Powell final int actionBarViewHeight = mActionBarView.isCollapsed() ? 0 : 267f6ce6a9bacbb220c6ea7b552c481237f23e64ae7Adam Powell mActionBarView.getMeasuredHeight() + lp.topMargin + lp.bottomMargin; 268d21aa12e8eb9d46ee92bf408b4b48386c6bf062dAdam Powell 269dae7824c4b78d02159c6ad0896f246942d7b3d8cAdam Powell if (mTabContainer != null && mTabContainer.getVisibility() != GONE) { 270dae7824c4b78d02159c6ad0896f246942d7b3d8cAdam Powell final int mode = MeasureSpec.getMode(heightMeasureSpec); 271dae7824c4b78d02159c6ad0896f246942d7b3d8cAdam Powell if (mode == MeasureSpec.AT_MOST) { 272dae7824c4b78d02159c6ad0896f246942d7b3d8cAdam Powell final int maxHeight = MeasureSpec.getSize(heightMeasureSpec); 273dae7824c4b78d02159c6ad0896f246942d7b3d8cAdam Powell setMeasuredDimension(getMeasuredWidth(), 274f6ce6a9bacbb220c6ea7b552c481237f23e64ae7Adam Powell Math.min(actionBarViewHeight + mTabContainer.getMeasuredHeight(), 275f6ce6a9bacbb220c6ea7b552c481237f23e64ae7Adam Powell maxHeight)); 276dae7824c4b78d02159c6ad0896f246942d7b3d8cAdam Powell } 277dae7824c4b78d02159c6ad0896f246942d7b3d8cAdam Powell } 278dae7824c4b78d02159c6ad0896f246942d7b3d8cAdam Powell } 279dae7824c4b78d02159c6ad0896f246942d7b3d8cAdam Powell 280dae7824c4b78d02159c6ad0896f246942d7b3d8cAdam Powell @Override 281dae7824c4b78d02159c6ad0896f246942d7b3d8cAdam Powell public void onLayout(boolean changed, int l, int t, int r, int b) { 282dae7824c4b78d02159c6ad0896f246942d7b3d8cAdam Powell super.onLayout(changed, l, t, r, b); 283a72ef62e5c329a19eab9935acba816fc1369c637Adam Powell 2847f610fed107b158c144dca1b20a44ee91eb8c934Alan Viverette final View tabContainer = mTabContainer; 2857f610fed107b158c144dca1b20a44ee91eb8c934Alan Viverette final boolean hasTabs = tabContainer != null && tabContainer.getVisibility() != GONE; 286a72ef62e5c329a19eab9935acba816fc1369c637Adam Powell 2877f610fed107b158c144dca1b20a44ee91eb8c934Alan Viverette if (tabContainer != null && tabContainer.getVisibility() != GONE) { 288dae7824c4b78d02159c6ad0896f246942d7b3d8cAdam Powell final int containerHeight = getMeasuredHeight(); 2897f610fed107b158c144dca1b20a44ee91eb8c934Alan Viverette final int tabHeight = tabContainer.getMeasuredHeight(); 2907f610fed107b158c144dca1b20a44ee91eb8c934Alan Viverette tabContainer.layout(l, containerHeight - tabHeight, r, containerHeight); 291dae7824c4b78d02159c6ad0896f246942d7b3d8cAdam Powell } 292a72ef62e5c329a19eab9935acba816fc1369c637Adam Powell 293a72ef62e5c329a19eab9935acba816fc1369c637Adam Powell boolean needsInvalidate = false; 294a72ef62e5c329a19eab9935acba816fc1369c637Adam Powell if (mIsSplit) { 295a72ef62e5c329a19eab9935acba816fc1369c637Adam Powell if (mSplitBackground != null) { 296a72ef62e5c329a19eab9935acba816fc1369c637Adam Powell mSplitBackground.setBounds(0, 0, getMeasuredWidth(), getMeasuredHeight()); 297a72ef62e5c329a19eab9935acba816fc1369c637Adam Powell needsInvalidate = true; 298a72ef62e5c329a19eab9935acba816fc1369c637Adam Powell } 299a72ef62e5c329a19eab9935acba816fc1369c637Adam Powell } else { 300a72ef62e5c329a19eab9935acba816fc1369c637Adam Powell if (mBackground != null) { 3017f610fed107b158c144dca1b20a44ee91eb8c934Alan Viverette final ActionBarView actionBarView = mActionBarView; 3027f610fed107b158c144dca1b20a44ee91eb8c934Alan Viverette mBackground.setBounds(actionBarView.getLeft(), actionBarView.getTop(), 3037f610fed107b158c144dca1b20a44ee91eb8c934Alan Viverette actionBarView.getRight(), actionBarView.getBottom()); 304a72ef62e5c329a19eab9935acba816fc1369c637Adam Powell needsInvalidate = true; 305a72ef62e5c329a19eab9935acba816fc1369c637Adam Powell } 3067f610fed107b158c144dca1b20a44ee91eb8c934Alan Viverette mIsStacked = hasTabs; 3077f610fed107b158c144dca1b20a44ee91eb8c934Alan Viverette if (hasTabs && mStackedBackground != null) { 3087f610fed107b158c144dca1b20a44ee91eb8c934Alan Viverette mStackedBackground.setBounds(tabContainer.getLeft(), tabContainer.getTop(), 3097f610fed107b158c144dca1b20a44ee91eb8c934Alan Viverette tabContainer.getRight(), tabContainer.getBottom()); 310a72ef62e5c329a19eab9935acba816fc1369c637Adam Powell needsInvalidate = true; 311a72ef62e5c329a19eab9935acba816fc1369c637Adam Powell } 312a72ef62e5c329a19eab9935acba816fc1369c637Adam Powell } 313a72ef62e5c329a19eab9935acba816fc1369c637Adam Powell 314a72ef62e5c329a19eab9935acba816fc1369c637Adam Powell if (needsInvalidate) { 315a72ef62e5c329a19eab9935acba816fc1369c637Adam Powell invalidate(); 316a72ef62e5c329a19eab9935acba816fc1369c637Adam Powell } 317dae7824c4b78d02159c6ad0896f246942d7b3d8cAdam Powell } 3187f610fed107b158c144dca1b20a44ee91eb8c934Alan Viverette 3197f610fed107b158c144dca1b20a44ee91eb8c934Alan Viverette /** 3207f610fed107b158c144dca1b20a44ee91eb8c934Alan Viverette * Dummy drawable so that we don't break background display lists and 3217f610fed107b158c144dca1b20a44ee91eb8c934Alan Viverette * projection surfaces. 3227f610fed107b158c144dca1b20a44ee91eb8c934Alan Viverette */ 3237f610fed107b158c144dca1b20a44ee91eb8c934Alan Viverette private class ActionBarBackgroundDrawable extends Drawable { 3247f610fed107b158c144dca1b20a44ee91eb8c934Alan Viverette @Override 3257f610fed107b158c144dca1b20a44ee91eb8c934Alan Viverette public void draw(Canvas canvas) { 3267f610fed107b158c144dca1b20a44ee91eb8c934Alan Viverette if (mIsSplit) { 3277f610fed107b158c144dca1b20a44ee91eb8c934Alan Viverette if (mSplitBackground != null) mSplitBackground.draw(canvas); 3287f610fed107b158c144dca1b20a44ee91eb8c934Alan Viverette } else { 3297f610fed107b158c144dca1b20a44ee91eb8c934Alan Viverette if (mBackground != null) { 3307f610fed107b158c144dca1b20a44ee91eb8c934Alan Viverette mBackground.draw(canvas); 3317f610fed107b158c144dca1b20a44ee91eb8c934Alan Viverette } 3327f610fed107b158c144dca1b20a44ee91eb8c934Alan Viverette if (mStackedBackground != null && mIsStacked) { 3337f610fed107b158c144dca1b20a44ee91eb8c934Alan Viverette mStackedBackground.draw(canvas); 3347f610fed107b158c144dca1b20a44ee91eb8c934Alan Viverette } 3357f610fed107b158c144dca1b20a44ee91eb8c934Alan Viverette } 3367f610fed107b158c144dca1b20a44ee91eb8c934Alan Viverette } 3377f610fed107b158c144dca1b20a44ee91eb8c934Alan Viverette 3387f610fed107b158c144dca1b20a44ee91eb8c934Alan Viverette @Override 3397f610fed107b158c144dca1b20a44ee91eb8c934Alan Viverette public void setAlpha(int alpha) { 3407f610fed107b158c144dca1b20a44ee91eb8c934Alan Viverette } 3417f610fed107b158c144dca1b20a44ee91eb8c934Alan Viverette 3427f610fed107b158c144dca1b20a44ee91eb8c934Alan Viverette @Override 3437f610fed107b158c144dca1b20a44ee91eb8c934Alan Viverette public void setColorFilter(ColorFilter cf) { 3447f610fed107b158c144dca1b20a44ee91eb8c934Alan Viverette } 3457f610fed107b158c144dca1b20a44ee91eb8c934Alan Viverette 3467f610fed107b158c144dca1b20a44ee91eb8c934Alan Viverette @Override 3477f610fed107b158c144dca1b20a44ee91eb8c934Alan Viverette public int getOpacity() { 3487f610fed107b158c144dca1b20a44ee91eb8c934Alan Viverette return 0; 3497f610fed107b158c144dca1b20a44ee91eb8c934Alan Viverette } 3507f610fed107b158c144dca1b20a44ee91eb8c934Alan Viverette } 35145f1e08c348ccb129bcc25e438c05421f7123f41Adam Powell} 352