ActionBarContainer.java revision 242f38763b137f4051f6098aac4aab18201935a2
1bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell/* 2bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell * Copyright (C) 2010 The Android Open Source Project 3bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell * 4bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell * Licensed under the Apache License, Version 2.0 (the "License"); 5bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell * you may not use this file except in compliance with the License. 6bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell * You may obtain a copy of the License at 7bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell * 8bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell * http://www.apache.org/licenses/LICENSE-2.0 9bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell * 10bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell * Unless required by applicable law or agreed to in writing, software 11bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell * distributed under the License is distributed on an "AS IS" BASIS, 12bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell * See the License for the specific language governing permissions and 14bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell * limitations under the License. 15bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell */ 16bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell 17ac5fe7c617c66850fff75a9fce9979c6e5674b0fAurimas Liutikaspackage androidx.appcompat.widget; 18bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell 19ac5fe7c617c66850fff75a9fce9979c6e5674b0fAurimas Liutikasimport static androidx.annotation.RestrictTo.Scope.LIBRARY_GROUP; 208e10080c914d1ad0784394fa3026b85535535847Aurimas Liutikas 21bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powellimport android.content.Context; 22bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powellimport android.content.res.TypedArray; 23bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powellimport android.graphics.drawable.Drawable; 24bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powellimport android.util.AttributeSet; 25bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powellimport android.view.MotionEvent; 26bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powellimport android.view.View; 27bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powellimport android.view.ViewGroup; 28bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powellimport android.widget.FrameLayout; 29bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell 303de8a4e8305507475d7890205184946a25cf45e7Aurimas Liutikasimport androidx.annotation.RestrictTo; 313de8a4e8305507475d7890205184946a25cf45e7Aurimas Liutikasimport androidx.appcompat.R; 323de8a4e8305507475d7890205184946a25cf45e7Aurimas Liutikasimport androidx.core.view.ViewCompat; 333de8a4e8305507475d7890205184946a25cf45e7Aurimas Liutikas 34bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell/** 3549c78900da0d43140fb602431fb93212bd7f6c70Chris Banes * This class acts as a container for the action bar view and action mode context views. 3649c78900da0d43140fb602431fb93212bd7f6c70Chris Banes * It applies special styles as needed to help handle animated transitions between them. 37bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell * @hide 38bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell */ 398e10080c914d1ad0784394fa3026b85535535847Aurimas Liutikas@RestrictTo(LIBRARY_GROUP) 40bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powellpublic class ActionBarContainer extends FrameLayout { 4120ac724a3a836bfd362c911f7dc55a61c02b4d44Trevor Johns private boolean mIsTransitioning; 4220ac724a3a836bfd362c911f7dc55a61c02b4d44Trevor Johns private View mTabContainer; 4349c78900da0d43140fb602431fb93212bd7f6c70Chris Banes private View mActionBarView; 44c5f2053af179e480ab0b0b50d1b0aade4e97fbc1Yigit Boyar private View mContextView; 4520ac724a3a836bfd362c911f7dc55a61c02b4d44Trevor Johns 46d8213c28889f37a1a2b6c05115be9f6df54a7a45Chris Banes Drawable mBackground; 47d8213c28889f37a1a2b6c05115be9f6df54a7a45Chris Banes Drawable mStackedBackground; 48d8213c28889f37a1a2b6c05115be9f6df54a7a45Chris Banes Drawable mSplitBackground; 49d8213c28889f37a1a2b6c05115be9f6df54a7a45Chris Banes boolean mIsSplit; 50d8213c28889f37a1a2b6c05115be9f6df54a7a45Chris Banes boolean mIsStacked; 5149c78900da0d43140fb602431fb93212bd7f6c70Chris Banes private int mHeight; 5220ac724a3a836bfd362c911f7dc55a61c02b4d44Trevor Johns 5320ac724a3a836bfd362c911f7dc55a61c02b4d44Trevor Johns public ActionBarContainer(Context context) { 5420ac724a3a836bfd362c911f7dc55a61c02b4d44Trevor Johns this(context, null); 5520ac724a3a836bfd362c911f7dc55a61c02b4d44Trevor Johns } 5620ac724a3a836bfd362c911f7dc55a61c02b4d44Trevor Johns 5720ac724a3a836bfd362c911f7dc55a61c02b4d44Trevor Johns public ActionBarContainer(Context context, AttributeSet attrs) { 5820ac724a3a836bfd362c911f7dc55a61c02b4d44Trevor Johns super(context, attrs); 5920ac724a3a836bfd362c911f7dc55a61c02b4d44Trevor Johns 6049c78900da0d43140fb602431fb93212bd7f6c70Chris Banes // Set a transparent background so that we project appropriately. 61242f38763b137f4051f6098aac4aab18201935a2Jake Wharton final Drawable bg = new ActionBarBackgroundDrawable(this); 6247082c30c630c34829439a9eecd1cf7e8d255a86Aurimas Liutikas ViewCompat.setBackground(this, bg); 6320ac724a3a836bfd362c911f7dc55a61c02b4d44Trevor Johns 6420ac724a3a836bfd362c911f7dc55a61c02b4d44Trevor Johns TypedArray a = context.obtainStyledAttributes(attrs, 6520ac724a3a836bfd362c911f7dc55a61c02b4d44Trevor Johns R.styleable.ActionBar); 6620ac724a3a836bfd362c911f7dc55a61c02b4d44Trevor Johns mBackground = a.getDrawable(R.styleable.ActionBar_background); 6720ac724a3a836bfd362c911f7dc55a61c02b4d44Trevor Johns mStackedBackground = a.getDrawable( 6820ac724a3a836bfd362c911f7dc55a61c02b4d44Trevor Johns R.styleable.ActionBar_backgroundStacked); 6949c78900da0d43140fb602431fb93212bd7f6c70Chris Banes mHeight = a.getDimensionPixelSize(R.styleable.ActionBar_height, -1); 7020ac724a3a836bfd362c911f7dc55a61c02b4d44Trevor Johns 7120ac724a3a836bfd362c911f7dc55a61c02b4d44Trevor Johns if (getId() == R.id.split_action_bar) { 7220ac724a3a836bfd362c911f7dc55a61c02b4d44Trevor Johns mIsSplit = true; 7349c78900da0d43140fb602431fb93212bd7f6c70Chris Banes mSplitBackground = a.getDrawable(R.styleable.ActionBar_backgroundSplit); 74bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell } 7520ac724a3a836bfd362c911f7dc55a61c02b4d44Trevor Johns a.recycle(); 7620ac724a3a836bfd362c911f7dc55a61c02b4d44Trevor Johns 7720ac724a3a836bfd362c911f7dc55a61c02b4d44Trevor Johns setWillNotDraw(mIsSplit ? mSplitBackground == null : 7820ac724a3a836bfd362c911f7dc55a61c02b4d44Trevor Johns mBackground == null && mStackedBackground == null); 7920ac724a3a836bfd362c911f7dc55a61c02b4d44Trevor Johns } 8020ac724a3a836bfd362c911f7dc55a61c02b4d44Trevor Johns 8120ac724a3a836bfd362c911f7dc55a61c02b4d44Trevor Johns @Override 8220ac724a3a836bfd362c911f7dc55a61c02b4d44Trevor Johns public void onFinishInflate() { 8320ac724a3a836bfd362c911f7dc55a61c02b4d44Trevor Johns super.onFinishInflate(); 8449c78900da0d43140fb602431fb93212bd7f6c70Chris Banes mActionBarView = findViewById(R.id.action_bar); 85c5f2053af179e480ab0b0b50d1b0aade4e97fbc1Yigit Boyar mContextView = findViewById(R.id.action_context_bar); 8620ac724a3a836bfd362c911f7dc55a61c02b4d44Trevor Johns } 8720ac724a3a836bfd362c911f7dc55a61c02b4d44Trevor Johns 8820ac724a3a836bfd362c911f7dc55a61c02b4d44Trevor Johns public void setPrimaryBackground(Drawable bg) { 89242db97d44808da5e2f8ec45076e2353a03882a0Chris Banes if (mBackground != null) { 90242db97d44808da5e2f8ec45076e2353a03882a0Chris Banes mBackground.setCallback(null); 91242db97d44808da5e2f8ec45076e2353a03882a0Chris Banes unscheduleDrawable(mBackground); 92242db97d44808da5e2f8ec45076e2353a03882a0Chris Banes } 9320ac724a3a836bfd362c911f7dc55a61c02b4d44Trevor Johns mBackground = bg; 94242db97d44808da5e2f8ec45076e2353a03882a0Chris Banes if (bg != null) { 95242db97d44808da5e2f8ec45076e2353a03882a0Chris Banes bg.setCallback(this); 9618fd7433f4123ed2e725601591470455c6b7578eChris Banes if (mActionBarView != null) { 9718fd7433f4123ed2e725601591470455c6b7578eChris Banes mBackground.setBounds(mActionBarView.getLeft(), mActionBarView.getTop(), 9818fd7433f4123ed2e725601591470455c6b7578eChris Banes mActionBarView.getRight(), mActionBarView.getBottom()); 9918fd7433f4123ed2e725601591470455c6b7578eChris Banes } 100242db97d44808da5e2f8ec45076e2353a03882a0Chris Banes } 101242db97d44808da5e2f8ec45076e2353a03882a0Chris Banes setWillNotDraw(mIsSplit ? mSplitBackground == null : 102242db97d44808da5e2f8ec45076e2353a03882a0Chris Banes mBackground == null && mStackedBackground == null); 10320ac724a3a836bfd362c911f7dc55a61c02b4d44Trevor Johns invalidate(); 10420ac724a3a836bfd362c911f7dc55a61c02b4d44Trevor Johns } 10520ac724a3a836bfd362c911f7dc55a61c02b4d44Trevor Johns 10620ac724a3a836bfd362c911f7dc55a61c02b4d44Trevor Johns public void setStackedBackground(Drawable bg) { 107242db97d44808da5e2f8ec45076e2353a03882a0Chris Banes if (mStackedBackground != null) { 108242db97d44808da5e2f8ec45076e2353a03882a0Chris Banes mStackedBackground.setCallback(null); 109242db97d44808da5e2f8ec45076e2353a03882a0Chris Banes unscheduleDrawable(mStackedBackground); 110242db97d44808da5e2f8ec45076e2353a03882a0Chris Banes } 11120ac724a3a836bfd362c911f7dc55a61c02b4d44Trevor Johns mStackedBackground = bg; 112242db97d44808da5e2f8ec45076e2353a03882a0Chris Banes if (bg != null) { 113242db97d44808da5e2f8ec45076e2353a03882a0Chris Banes bg.setCallback(this); 11418fd7433f4123ed2e725601591470455c6b7578eChris Banes if ((mIsStacked && mStackedBackground != null)) { 11518fd7433f4123ed2e725601591470455c6b7578eChris Banes mStackedBackground.setBounds(mTabContainer.getLeft(), mTabContainer.getTop(), 11618fd7433f4123ed2e725601591470455c6b7578eChris Banes mTabContainer.getRight(), mTabContainer.getBottom()); 11718fd7433f4123ed2e725601591470455c6b7578eChris Banes } 118242db97d44808da5e2f8ec45076e2353a03882a0Chris Banes } 119242db97d44808da5e2f8ec45076e2353a03882a0Chris Banes setWillNotDraw(mIsSplit ? mSplitBackground == null : 120242db97d44808da5e2f8ec45076e2353a03882a0Chris Banes mBackground == null && mStackedBackground == null); 12120ac724a3a836bfd362c911f7dc55a61c02b4d44Trevor Johns invalidate(); 12220ac724a3a836bfd362c911f7dc55a61c02b4d44Trevor Johns } 12320ac724a3a836bfd362c911f7dc55a61c02b4d44Trevor Johns 12420ac724a3a836bfd362c911f7dc55a61c02b4d44Trevor Johns public void setSplitBackground(Drawable bg) { 125242db97d44808da5e2f8ec45076e2353a03882a0Chris Banes if (mSplitBackground != null) { 126242db97d44808da5e2f8ec45076e2353a03882a0Chris Banes mSplitBackground.setCallback(null); 127242db97d44808da5e2f8ec45076e2353a03882a0Chris Banes unscheduleDrawable(mSplitBackground); 128242db97d44808da5e2f8ec45076e2353a03882a0Chris Banes } 12920ac724a3a836bfd362c911f7dc55a61c02b4d44Trevor Johns mSplitBackground = bg; 130242db97d44808da5e2f8ec45076e2353a03882a0Chris Banes if (bg != null) { 131242db97d44808da5e2f8ec45076e2353a03882a0Chris Banes bg.setCallback(this); 13218fd7433f4123ed2e725601591470455c6b7578eChris Banes if (mIsSplit && mSplitBackground != null) { 13318fd7433f4123ed2e725601591470455c6b7578eChris Banes mSplitBackground.setBounds(0, 0, getMeasuredWidth(), getMeasuredHeight()); 13418fd7433f4123ed2e725601591470455c6b7578eChris Banes } 135242db97d44808da5e2f8ec45076e2353a03882a0Chris Banes } 136242db97d44808da5e2f8ec45076e2353a03882a0Chris Banes setWillNotDraw(mIsSplit ? mSplitBackground == null : 137242db97d44808da5e2f8ec45076e2353a03882a0Chris Banes mBackground == null && mStackedBackground == null); 13820ac724a3a836bfd362c911f7dc55a61c02b4d44Trevor Johns invalidate(); 13920ac724a3a836bfd362c911f7dc55a61c02b4d44Trevor Johns } 14020ac724a3a836bfd362c911f7dc55a61c02b4d44Trevor Johns 141242db97d44808da5e2f8ec45076e2353a03882a0Chris Banes @Override 142242db97d44808da5e2f8ec45076e2353a03882a0Chris Banes public void setVisibility(int visibility) { 143242db97d44808da5e2f8ec45076e2353a03882a0Chris Banes super.setVisibility(visibility); 144242db97d44808da5e2f8ec45076e2353a03882a0Chris Banes final boolean isVisible = visibility == VISIBLE; 145242db97d44808da5e2f8ec45076e2353a03882a0Chris Banes if (mBackground != null) mBackground.setVisible(isVisible, false); 146242db97d44808da5e2f8ec45076e2353a03882a0Chris Banes if (mStackedBackground != null) mStackedBackground.setVisible(isVisible, false); 147242db97d44808da5e2f8ec45076e2353a03882a0Chris Banes if (mSplitBackground != null) mSplitBackground.setVisible(isVisible, false); 148242db97d44808da5e2f8ec45076e2353a03882a0Chris Banes } 149242db97d44808da5e2f8ec45076e2353a03882a0Chris Banes 150242db97d44808da5e2f8ec45076e2353a03882a0Chris Banes @Override 151242db97d44808da5e2f8ec45076e2353a03882a0Chris Banes protected boolean verifyDrawable(Drawable who) { 152242db97d44808da5e2f8ec45076e2353a03882a0Chris Banes return (who == mBackground && !mIsSplit) || (who == mStackedBackground && mIsStacked) || 153242db97d44808da5e2f8ec45076e2353a03882a0Chris Banes (who == mSplitBackground && mIsSplit) || super.verifyDrawable(who); 154242db97d44808da5e2f8ec45076e2353a03882a0Chris Banes } 155242db97d44808da5e2f8ec45076e2353a03882a0Chris Banes 156242db97d44808da5e2f8ec45076e2353a03882a0Chris Banes @Override 157242db97d44808da5e2f8ec45076e2353a03882a0Chris Banes protected void drawableStateChanged() { 158242db97d44808da5e2f8ec45076e2353a03882a0Chris Banes super.drawableStateChanged(); 159242db97d44808da5e2f8ec45076e2353a03882a0Chris Banes if (mBackground != null && mBackground.isStateful()) { 160242db97d44808da5e2f8ec45076e2353a03882a0Chris Banes mBackground.setState(getDrawableState()); 161242db97d44808da5e2f8ec45076e2353a03882a0Chris Banes } 162242db97d44808da5e2f8ec45076e2353a03882a0Chris Banes if (mStackedBackground != null && mStackedBackground.isStateful()) { 163242db97d44808da5e2f8ec45076e2353a03882a0Chris Banes mStackedBackground.setState(getDrawableState()); 164242db97d44808da5e2f8ec45076e2353a03882a0Chris Banes } 165242db97d44808da5e2f8ec45076e2353a03882a0Chris Banes if (mSplitBackground != null && mSplitBackground.isStateful()) { 166242db97d44808da5e2f8ec45076e2353a03882a0Chris Banes mSplitBackground.setState(getDrawableState()); 167242db97d44808da5e2f8ec45076e2353a03882a0Chris Banes } 168242db97d44808da5e2f8ec45076e2353a03882a0Chris Banes } 169242db97d44808da5e2f8ec45076e2353a03882a0Chris Banes 170e2104f4b5c8e3ad63570306a25e61502dfe4c418Aurimas Liutikas @Override 17149c78900da0d43140fb602431fb93212bd7f6c70Chris Banes public void jumpDrawablesToCurrentState() { 172034295930d0f4c507bed2a211000b8d431c99d52Kirill Grouchnikov super.jumpDrawablesToCurrentState(); 173034295930d0f4c507bed2a211000b8d431c99d52Kirill Grouchnikov if (mBackground != null) { 174034295930d0f4c507bed2a211000b8d431c99d52Kirill Grouchnikov mBackground.jumpToCurrentState(); 175034295930d0f4c507bed2a211000b8d431c99d52Kirill Grouchnikov } 176034295930d0f4c507bed2a211000b8d431c99d52Kirill Grouchnikov if (mStackedBackground != null) { 177034295930d0f4c507bed2a211000b8d431c99d52Kirill Grouchnikov mStackedBackground.jumpToCurrentState(); 178034295930d0f4c507bed2a211000b8d431c99d52Kirill Grouchnikov } 179034295930d0f4c507bed2a211000b8d431c99d52Kirill Grouchnikov if (mSplitBackground != null) { 180034295930d0f4c507bed2a211000b8d431c99d52Kirill Grouchnikov mSplitBackground.jumpToCurrentState(); 18149c78900da0d43140fb602431fb93212bd7f6c70Chris Banes } 18249c78900da0d43140fb602431fb93212bd7f6c70Chris Banes } 18349c78900da0d43140fb602431fb93212bd7f6c70Chris Banes 18420ac724a3a836bfd362c911f7dc55a61c02b4d44Trevor Johns /** 18520ac724a3a836bfd362c911f7dc55a61c02b4d44Trevor Johns * Set the action bar into a "transitioning" state. While transitioning the bar will block focus 18620ac724a3a836bfd362c911f7dc55a61c02b4d44Trevor Johns * and touch from all of its descendants. This prevents the user from interacting with the bar 18720ac724a3a836bfd362c911f7dc55a61c02b4d44Trevor Johns * while it is animating in or out. 18820ac724a3a836bfd362c911f7dc55a61c02b4d44Trevor Johns * 18920ac724a3a836bfd362c911f7dc55a61c02b4d44Trevor Johns * @param isTransitioning true if the bar is currently transitioning, false otherwise. 19020ac724a3a836bfd362c911f7dc55a61c02b4d44Trevor Johns */ 19120ac724a3a836bfd362c911f7dc55a61c02b4d44Trevor Johns public void setTransitioning(boolean isTransitioning) { 19220ac724a3a836bfd362c911f7dc55a61c02b4d44Trevor Johns mIsTransitioning = isTransitioning; 19320ac724a3a836bfd362c911f7dc55a61c02b4d44Trevor Johns setDescendantFocusability(isTransitioning ? FOCUS_BLOCK_DESCENDANTS 19420ac724a3a836bfd362c911f7dc55a61c02b4d44Trevor Johns : FOCUS_AFTER_DESCENDANTS); 19520ac724a3a836bfd362c911f7dc55a61c02b4d44Trevor Johns } 19620ac724a3a836bfd362c911f7dc55a61c02b4d44Trevor Johns 19720ac724a3a836bfd362c911f7dc55a61c02b4d44Trevor Johns @Override 19820ac724a3a836bfd362c911f7dc55a61c02b4d44Trevor Johns public boolean onInterceptTouchEvent(MotionEvent ev) { 19920ac724a3a836bfd362c911f7dc55a61c02b4d44Trevor Johns return mIsTransitioning || super.onInterceptTouchEvent(ev); 20020ac724a3a836bfd362c911f7dc55a61c02b4d44Trevor Johns } 20120ac724a3a836bfd362c911f7dc55a61c02b4d44Trevor Johns 20220ac724a3a836bfd362c911f7dc55a61c02b4d44Trevor Johns @Override 20320ac724a3a836bfd362c911f7dc55a61c02b4d44Trevor Johns public boolean onTouchEvent(MotionEvent ev) { 20420ac724a3a836bfd362c911f7dc55a61c02b4d44Trevor Johns super.onTouchEvent(ev); 20520ac724a3a836bfd362c911f7dc55a61c02b4d44Trevor Johns 20620ac724a3a836bfd362c911f7dc55a61c02b4d44Trevor Johns // An action bar always eats touch events. 20720ac724a3a836bfd362c911f7dc55a61c02b4d44Trevor Johns return true; 20820ac724a3a836bfd362c911f7dc55a61c02b4d44Trevor Johns } 20920ac724a3a836bfd362c911f7dc55a61c02b4d44Trevor Johns 2100dbe090bba314e72d65d5404c9fb15b7550a698dAndrei Stingaceanu @Override 2110dbe090bba314e72d65d5404c9fb15b7550a698dAndrei Stingaceanu public boolean onHoverEvent(MotionEvent ev) { 2120dbe090bba314e72d65d5404c9fb15b7550a698dAndrei Stingaceanu super.onHoverEvent(ev); 2130dbe090bba314e72d65d5404c9fb15b7550a698dAndrei Stingaceanu 2140dbe090bba314e72d65d5404c9fb15b7550a698dAndrei Stingaceanu // An action bar always eats hover events. 2150dbe090bba314e72d65d5404c9fb15b7550a698dAndrei Stingaceanu return true; 2160dbe090bba314e72d65d5404c9fb15b7550a698dAndrei Stingaceanu } 2170dbe090bba314e72d65d5404c9fb15b7550a698dAndrei Stingaceanu 21820ac724a3a836bfd362c911f7dc55a61c02b4d44Trevor Johns public void setTabContainer(ScrollingTabContainerView tabView) { 21920ac724a3a836bfd362c911f7dc55a61c02b4d44Trevor Johns if (mTabContainer != null) { 22020ac724a3a836bfd362c911f7dc55a61c02b4d44Trevor Johns removeView(mTabContainer); 22120ac724a3a836bfd362c911f7dc55a61c02b4d44Trevor Johns } 22220ac724a3a836bfd362c911f7dc55a61c02b4d44Trevor Johns mTabContainer = tabView; 22320ac724a3a836bfd362c911f7dc55a61c02b4d44Trevor Johns if (tabView != null) { 22420ac724a3a836bfd362c911f7dc55a61c02b4d44Trevor Johns addView(tabView); 22520ac724a3a836bfd362c911f7dc55a61c02b4d44Trevor Johns final ViewGroup.LayoutParams lp = tabView.getLayoutParams(); 22649c78900da0d43140fb602431fb93212bd7f6c70Chris Banes lp.width = LayoutParams.MATCH_PARENT; 22720ac724a3a836bfd362c911f7dc55a61c02b4d44Trevor Johns lp.height = LayoutParams.WRAP_CONTENT; 22820ac724a3a836bfd362c911f7dc55a61c02b4d44Trevor Johns tabView.setAllowCollapse(false); 22920ac724a3a836bfd362c911f7dc55a61c02b4d44Trevor Johns } 23020ac724a3a836bfd362c911f7dc55a61c02b4d44Trevor Johns } 23120ac724a3a836bfd362c911f7dc55a61c02b4d44Trevor Johns 23220ac724a3a836bfd362c911f7dc55a61c02b4d44Trevor Johns public View getTabContainer() { 23320ac724a3a836bfd362c911f7dc55a61c02b4d44Trevor Johns return mTabContainer; 23420ac724a3a836bfd362c911f7dc55a61c02b4d44Trevor Johns } 23520ac724a3a836bfd362c911f7dc55a61c02b4d44Trevor Johns 236e2104f4b5c8e3ad63570306a25e61502dfe4c418Aurimas Liutikas @Override 237d6e47228c44aaadb0d4518da6db5c3f5dffda1abChris Banes public android.view.ActionMode startActionModeForChild(View child, 238d6e47228c44aaadb0d4518da6db5c3f5dffda1abChris Banes android.view.ActionMode.Callback callback) { 23920ac724a3a836bfd362c911f7dc55a61c02b4d44Trevor Johns // No starting an action mode for an action bar child! (Where would it go?) 24020ac724a3a836bfd362c911f7dc55a61c02b4d44Trevor Johns return null; 24120ac724a3a836bfd362c911f7dc55a61c02b4d44Trevor Johns } 24220ac724a3a836bfd362c911f7dc55a61c02b4d44Trevor Johns 243e2104f4b5c8e3ad63570306a25e61502dfe4c418Aurimas Liutikas @Override 244d6e47228c44aaadb0d4518da6db5c3f5dffda1abChris Banes public android.view.ActionMode startActionModeForChild(View child, 245d6e47228c44aaadb0d4518da6db5c3f5dffda1abChris Banes android.view.ActionMode.Callback callback, int type) { 246d6e47228c44aaadb0d4518da6db5c3f5dffda1abChris Banes if (type != android.view.ActionMode.TYPE_PRIMARY) { 247d6e47228c44aaadb0d4518da6db5c3f5dffda1abChris Banes return super.startActionModeForChild(child, callback, type); 248d6e47228c44aaadb0d4518da6db5c3f5dffda1abChris Banes } 249c5cbf40d0ef5e4ba3f50adaf2af08d19fecdf55aYigit Boyar return null; 250c5cbf40d0ef5e4ba3f50adaf2af08d19fecdf55aYigit Boyar } 251c5cbf40d0ef5e4ba3f50adaf2af08d19fecdf55aYigit Boyar 25249c78900da0d43140fb602431fb93212bd7f6c70Chris Banes private boolean isCollapsed(View view) { 25349c78900da0d43140fb602431fb93212bd7f6c70Chris Banes return view == null || view.getVisibility() == GONE || view.getMeasuredHeight() == 0; 25449c78900da0d43140fb602431fb93212bd7f6c70Chris Banes } 25549c78900da0d43140fb602431fb93212bd7f6c70Chris Banes 256c5f2053af179e480ab0b0b50d1b0aade4e97fbc1Yigit Boyar private int getMeasuredHeightWithMargins(View view) { 257c5f2053af179e480ab0b0b50d1b0aade4e97fbc1Yigit Boyar final LayoutParams lp = (LayoutParams) view.getLayoutParams(); 258c5f2053af179e480ab0b0b50d1b0aade4e97fbc1Yigit Boyar return view.getMeasuredHeight() + lp.topMargin + lp.bottomMargin; 259c5f2053af179e480ab0b0b50d1b0aade4e97fbc1Yigit Boyar } 260c5f2053af179e480ab0b0b50d1b0aade4e97fbc1Yigit Boyar 26120ac724a3a836bfd362c911f7dc55a61c02b4d44Trevor Johns @Override 26220ac724a3a836bfd362c911f7dc55a61c02b4d44Trevor Johns public void onMeasure(int widthMeasureSpec, int heightMeasureSpec) { 26349c78900da0d43140fb602431fb93212bd7f6c70Chris Banes if (mActionBarView == null && 26449c78900da0d43140fb602431fb93212bd7f6c70Chris Banes MeasureSpec.getMode(heightMeasureSpec) == MeasureSpec.AT_MOST && mHeight >= 0) { 26549c78900da0d43140fb602431fb93212bd7f6c70Chris Banes heightMeasureSpec = MeasureSpec.makeMeasureSpec( 26649c78900da0d43140fb602431fb93212bd7f6c70Chris Banes Math.min(mHeight, MeasureSpec.getSize(heightMeasureSpec)), MeasureSpec.AT_MOST); 26749c78900da0d43140fb602431fb93212bd7f6c70Chris Banes } 26820ac724a3a836bfd362c911f7dc55a61c02b4d44Trevor Johns super.onMeasure(widthMeasureSpec, heightMeasureSpec); 26920ac724a3a836bfd362c911f7dc55a61c02b4d44Trevor Johns 27049c78900da0d43140fb602431fb93212bd7f6c70Chris Banes if (mActionBarView == null) return; 27120ac724a3a836bfd362c911f7dc55a61c02b4d44Trevor Johns 272c5f2053af179e480ab0b0b50d1b0aade4e97fbc1Yigit Boyar final int mode = MeasureSpec.getMode(heightMeasureSpec); 273c5f2053af179e480ab0b0b50d1b0aade4e97fbc1Yigit Boyar if (mTabContainer != null && mTabContainer.getVisibility() != GONE 274c5f2053af179e480ab0b0b50d1b0aade4e97fbc1Yigit Boyar && mode != MeasureSpec.EXACTLY) { 275c5f2053af179e480ab0b0b50d1b0aade4e97fbc1Yigit Boyar final int topMarginForTabs; 276c5f2053af179e480ab0b0b50d1b0aade4e97fbc1Yigit Boyar if (!isCollapsed(mActionBarView)) { 277c5f2053af179e480ab0b0b50d1b0aade4e97fbc1Yigit Boyar topMarginForTabs = getMeasuredHeightWithMargins(mActionBarView); 278c5f2053af179e480ab0b0b50d1b0aade4e97fbc1Yigit Boyar } else if (!isCollapsed(mContextView)) { 279c5f2053af179e480ab0b0b50d1b0aade4e97fbc1Yigit Boyar topMarginForTabs = getMeasuredHeightWithMargins(mContextView); 280c5f2053af179e480ab0b0b50d1b0aade4e97fbc1Yigit Boyar } else { 281c5f2053af179e480ab0b0b50d1b0aade4e97fbc1Yigit Boyar topMarginForTabs = 0; 28220ac724a3a836bfd362c911f7dc55a61c02b4d44Trevor Johns } 283c5f2053af179e480ab0b0b50d1b0aade4e97fbc1Yigit Boyar final int maxHeight = mode == MeasureSpec.AT_MOST ? 284c5f2053af179e480ab0b0b50d1b0aade4e97fbc1Yigit Boyar MeasureSpec.getSize(heightMeasureSpec) : Integer.MAX_VALUE; 285c5f2053af179e480ab0b0b50d1b0aade4e97fbc1Yigit Boyar setMeasuredDimension(getMeasuredWidth(), 286c5f2053af179e480ab0b0b50d1b0aade4e97fbc1Yigit Boyar Math.min(topMarginForTabs + getMeasuredHeightWithMargins(mTabContainer), 287c5f2053af179e480ab0b0b50d1b0aade4e97fbc1Yigit Boyar maxHeight)); 28820ac724a3a836bfd362c911f7dc55a61c02b4d44Trevor Johns } 28920ac724a3a836bfd362c911f7dc55a61c02b4d44Trevor Johns } 29020ac724a3a836bfd362c911f7dc55a61c02b4d44Trevor Johns 29120ac724a3a836bfd362c911f7dc55a61c02b4d44Trevor Johns @Override 29220ac724a3a836bfd362c911f7dc55a61c02b4d44Trevor Johns public void onLayout(boolean changed, int l, int t, int r, int b) { 29320ac724a3a836bfd362c911f7dc55a61c02b4d44Trevor Johns super.onLayout(changed, l, t, r, b); 29420ac724a3a836bfd362c911f7dc55a61c02b4d44Trevor Johns 29549c78900da0d43140fb602431fb93212bd7f6c70Chris Banes final View tabContainer = mTabContainer; 29649c78900da0d43140fb602431fb93212bd7f6c70Chris Banes final boolean hasTabs = tabContainer != null && tabContainer.getVisibility() != GONE; 29720ac724a3a836bfd362c911f7dc55a61c02b4d44Trevor Johns 29849c78900da0d43140fb602431fb93212bd7f6c70Chris Banes if (tabContainer != null && tabContainer.getVisibility() != GONE) { 29920ac724a3a836bfd362c911f7dc55a61c02b4d44Trevor Johns final int containerHeight = getMeasuredHeight(); 300c5f2053af179e480ab0b0b50d1b0aade4e97fbc1Yigit Boyar final LayoutParams lp = (LayoutParams) tabContainer.getLayoutParams(); 30149c78900da0d43140fb602431fb93212bd7f6c70Chris Banes final int tabHeight = tabContainer.getMeasuredHeight(); 302c5f2053af179e480ab0b0b50d1b0aade4e97fbc1Yigit Boyar tabContainer.layout(l, containerHeight - tabHeight - lp.bottomMargin, r, 303c5f2053af179e480ab0b0b50d1b0aade4e97fbc1Yigit Boyar containerHeight - lp.bottomMargin); 30420ac724a3a836bfd362c911f7dc55a61c02b4d44Trevor Johns } 30520ac724a3a836bfd362c911f7dc55a61c02b4d44Trevor Johns 30620ac724a3a836bfd362c911f7dc55a61c02b4d44Trevor Johns boolean needsInvalidate = false; 30720ac724a3a836bfd362c911f7dc55a61c02b4d44Trevor Johns if (mIsSplit) { 30820ac724a3a836bfd362c911f7dc55a61c02b4d44Trevor Johns if (mSplitBackground != null) { 30920ac724a3a836bfd362c911f7dc55a61c02b4d44Trevor Johns mSplitBackground.setBounds(0, 0, getMeasuredWidth(), getMeasuredHeight()); 31020ac724a3a836bfd362c911f7dc55a61c02b4d44Trevor Johns needsInvalidate = true; 31120ac724a3a836bfd362c911f7dc55a61c02b4d44Trevor Johns } 31220ac724a3a836bfd362c911f7dc55a61c02b4d44Trevor Johns } else { 31320ac724a3a836bfd362c911f7dc55a61c02b4d44Trevor Johns if (mBackground != null) { 3147d099302a9f49cee558d366a7c615b28cea79e0aYigit Boyar if (mActionBarView.getVisibility() == View.VISIBLE) { 3157d099302a9f49cee558d366a7c615b28cea79e0aYigit Boyar mBackground.setBounds(mActionBarView.getLeft(), mActionBarView.getTop(), 3167d099302a9f49cee558d366a7c615b28cea79e0aYigit Boyar mActionBarView.getRight(), mActionBarView.getBottom()); 3177d099302a9f49cee558d366a7c615b28cea79e0aYigit Boyar } else if (mContextView != null && 3187d099302a9f49cee558d366a7c615b28cea79e0aYigit Boyar mContextView.getVisibility() == View.VISIBLE) { 3197d099302a9f49cee558d366a7c615b28cea79e0aYigit Boyar mBackground.setBounds(mContextView.getLeft(), mContextView.getTop(), 3207d099302a9f49cee558d366a7c615b28cea79e0aYigit Boyar mContextView.getRight(), mContextView.getBottom()); 3217d099302a9f49cee558d366a7c615b28cea79e0aYigit Boyar } else { 3227d099302a9f49cee558d366a7c615b28cea79e0aYigit Boyar mBackground.setBounds(0, 0, 0, 0); 3237d099302a9f49cee558d366a7c615b28cea79e0aYigit Boyar } 32420ac724a3a836bfd362c911f7dc55a61c02b4d44Trevor Johns needsInvalidate = true; 32520ac724a3a836bfd362c911f7dc55a61c02b4d44Trevor Johns } 32649c78900da0d43140fb602431fb93212bd7f6c70Chris Banes mIsStacked = hasTabs; 32749c78900da0d43140fb602431fb93212bd7f6c70Chris Banes if (hasTabs && mStackedBackground != null) { 32849c78900da0d43140fb602431fb93212bd7f6c70Chris Banes mStackedBackground.setBounds(tabContainer.getLeft(), tabContainer.getTop(), 32949c78900da0d43140fb602431fb93212bd7f6c70Chris Banes tabContainer.getRight(), tabContainer.getBottom()); 33020ac724a3a836bfd362c911f7dc55a61c02b4d44Trevor Johns needsInvalidate = true; 33120ac724a3a836bfd362c911f7dc55a61c02b4d44Trevor Johns } 33220ac724a3a836bfd362c911f7dc55a61c02b4d44Trevor Johns } 33320ac724a3a836bfd362c911f7dc55a61c02b4d44Trevor Johns 33420ac724a3a836bfd362c911f7dc55a61c02b4d44Trevor Johns if (needsInvalidate) { 33520ac724a3a836bfd362c911f7dc55a61c02b4d44Trevor Johns invalidate(); 33620ac724a3a836bfd362c911f7dc55a61c02b4d44Trevor Johns } 33720ac724a3a836bfd362c911f7dc55a61c02b4d44Trevor Johns } 338bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell} 339