Adam Powell | 45f1e08 | 2010-12-10 14:20:13 -0800 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2010 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 | |
| 17 | package com.android.internal.widget; |
| 18 | |
Chris Craik | 77b5cad | 2014-07-30 18:23:07 -0700 | [diff] [blame] | 19 | import android.annotation.NonNull; |
Adam Powell | 45f1e08 | 2010-12-10 14:20:13 -0800 | [diff] [blame] | 20 | import android.content.Context; |
| 21 | import android.content.res.TypedArray; |
Adam Powell | a72ef62 | 2011-07-06 22:53:11 -0700 | [diff] [blame] | 22 | import android.graphics.Canvas; |
Alan Viverette | 7f610fe | 2014-02-19 14:40:12 -0800 | [diff] [blame] | 23 | import android.graphics.ColorFilter; |
Chris Craik | 77b5cad | 2014-07-30 18:23:07 -0700 | [diff] [blame] | 24 | import android.graphics.Outline; |
Adam Powell | f849a5e | 2014-09-11 15:09:36 -0700 | [diff] [blame] | 25 | import android.graphics.PixelFormat; |
Adam Powell | a72ef62 | 2011-07-06 22:53:11 -0700 | [diff] [blame] | 26 | import android.graphics.drawable.Drawable; |
Adam Powell | 45f1e08 | 2010-12-10 14:20:13 -0800 | [diff] [blame] | 27 | import android.util.AttributeSet; |
Adam Powell | 640a66e | 2011-04-29 10:18:53 -0700 | [diff] [blame] | 28 | import android.view.ActionMode; |
Adam Powell | 6ecf3d1 | 2010-12-19 13:14:58 -0800 | [diff] [blame] | 29 | import android.view.MotionEvent; |
Adam Powell | dae7824 | 2011-04-25 15:23:41 -0700 | [diff] [blame] | 30 | import android.view.View; |
Adam Powell | af6b97e | 2011-08-11 17:40:57 -0700 | [diff] [blame] | 31 | import android.view.ViewGroup; |
Adam Powell | 45f1e08 | 2010-12-10 14:20:13 -0800 | [diff] [blame] | 32 | import android.widget.FrameLayout; |
| 33 | |
| 34 | /** |
| 35 | * This class acts as a container for the action bar view and action mode context views. |
| 36 | * It applies special styles as needed to help handle animated transitions between them. |
| 37 | * @hide |
| 38 | */ |
| 39 | public class ActionBarContainer extends FrameLayout { |
Adam Powell | 01feaee | 2011-02-10 15:05:05 -0800 | [diff] [blame] | 40 | private boolean mIsTransitioning; |
Adam Powell | dae7824 | 2011-04-25 15:23:41 -0700 | [diff] [blame] | 41 | private View mTabContainer; |
Adam Powell | e021e6e | 2014-05-23 17:27:24 -0700 | [diff] [blame] | 42 | private View mActionBarView; |
Chet Haase | ccd3da2 | 2014-09-12 18:03:55 -0700 | [diff] [blame] | 43 | private View mActionContextView; |
Adam Powell | 01feaee | 2011-02-10 15:05:05 -0800 | [diff] [blame] | 44 | |
Adam Powell | a72ef62 | 2011-07-06 22:53:11 -0700 | [diff] [blame] | 45 | private Drawable mBackground; |
| 46 | private Drawable mStackedBackground; |
| 47 | private Drawable mSplitBackground; |
| 48 | private boolean mIsSplit; |
| 49 | private boolean mIsStacked; |
Adam Powell | e43340c | 2014-03-17 19:10:43 -0700 | [diff] [blame] | 50 | private int mHeight; |
Adam Powell | a72ef62 | 2011-07-06 22:53:11 -0700 | [diff] [blame] | 51 | |
Adam Powell | 45f1e08 | 2010-12-10 14:20:13 -0800 | [diff] [blame] | 52 | public ActionBarContainer(Context context) { |
| 53 | this(context, null); |
| 54 | } |
| 55 | |
| 56 | public ActionBarContainer(Context context, AttributeSet attrs) { |
| 57 | super(context, attrs); |
| 58 | |
Alan Viverette | 7f610fe | 2014-02-19 14:40:12 -0800 | [diff] [blame] | 59 | // Set a transparent background so that we project appropriately. |
| 60 | setBackground(new ActionBarBackgroundDrawable()); |
Adam Powell | a72ef62 | 2011-07-06 22:53:11 -0700 | [diff] [blame] | 61 | |
Adam Powell | 45f1e08 | 2010-12-10 14:20:13 -0800 | [diff] [blame] | 62 | TypedArray a = context.obtainStyledAttributes(attrs, |
| 63 | com.android.internal.R.styleable.ActionBar); |
Adam Powell | a72ef62 | 2011-07-06 22:53:11 -0700 | [diff] [blame] | 64 | mBackground = a.getDrawable(com.android.internal.R.styleable.ActionBar_background); |
| 65 | mStackedBackground = a.getDrawable( |
| 66 | com.android.internal.R.styleable.ActionBar_backgroundStacked); |
Adam Powell | e43340c | 2014-03-17 19:10:43 -0700 | [diff] [blame] | 67 | mHeight = a.getDimensionPixelSize(com.android.internal.R.styleable.ActionBar_height, -1); |
Adam Powell | a72ef62 | 2011-07-06 22:53:11 -0700 | [diff] [blame] | 68 | |
| 69 | if (getId() == com.android.internal.R.id.split_action_bar) { |
| 70 | mIsSplit = true; |
| 71 | mSplitBackground = a.getDrawable( |
| 72 | com.android.internal.R.styleable.ActionBar_backgroundSplit); |
| 73 | } |
Adam Powell | 45f1e08 | 2010-12-10 14:20:13 -0800 | [diff] [blame] | 74 | a.recycle(); |
Adam Powell | a72ef62 | 2011-07-06 22:53:11 -0700 | [diff] [blame] | 75 | |
| 76 | setWillNotDraw(mIsSplit ? mSplitBackground == null : |
| 77 | mBackground == null && mStackedBackground == null); |
Adam Powell | 45f1e08 | 2010-12-10 14:20:13 -0800 | [diff] [blame] | 78 | } |
Adam Powell | 6ecf3d1 | 2010-12-19 13:14:58 -0800 | [diff] [blame] | 79 | |
Adam Powell | 310849a | 2011-06-08 20:07:17 -0700 | [diff] [blame] | 80 | @Override |
| 81 | public void onFinishInflate() { |
| 82 | super.onFinishInflate(); |
Adam Powell | e021e6e | 2014-05-23 17:27:24 -0700 | [diff] [blame] | 83 | mActionBarView = findViewById(com.android.internal.R.id.action_bar); |
Chet Haase | ccd3da2 | 2014-09-12 18:03:55 -0700 | [diff] [blame] | 84 | mActionContextView = findViewById(com.android.internal.R.id.action_context_bar); |
Adam Powell | 310849a | 2011-06-08 20:07:17 -0700 | [diff] [blame] | 85 | } |
| 86 | |
Adam Powell | f88b915 | 2011-09-07 14:54:32 -0700 | [diff] [blame] | 87 | public void setPrimaryBackground(Drawable bg) { |
Adam Powell | a7cc06d | 2012-08-01 16:31:23 -0700 | [diff] [blame] | 88 | if (mBackground != null) { |
| 89 | mBackground.setCallback(null); |
| 90 | unscheduleDrawable(mBackground); |
| 91 | } |
Adam Powell | f88b915 | 2011-09-07 14:54:32 -0700 | [diff] [blame] | 92 | mBackground = bg; |
Adam Powell | a7cc06d | 2012-08-01 16:31:23 -0700 | [diff] [blame] | 93 | if (bg != null) { |
| 94 | bg.setCallback(this); |
Adam Powell | e8c8ae4 | 2013-02-08 17:32:24 -0800 | [diff] [blame] | 95 | if (mActionBarView != null) { |
| 96 | mBackground.setBounds(mActionBarView.getLeft(), mActionBarView.getTop(), |
| 97 | mActionBarView.getRight(), mActionBarView.getBottom()); |
| 98 | } |
Adam Powell | a7cc06d | 2012-08-01 16:31:23 -0700 | [diff] [blame] | 99 | } |
| 100 | setWillNotDraw(mIsSplit ? mSplitBackground == null : |
| 101 | mBackground == null && mStackedBackground == null); |
Adam Powell | f88b915 | 2011-09-07 14:54:32 -0700 | [diff] [blame] | 102 | invalidate(); |
| 103 | } |
| 104 | |
| 105 | public void setStackedBackground(Drawable bg) { |
Adam Powell | a7cc06d | 2012-08-01 16:31:23 -0700 | [diff] [blame] | 106 | if (mStackedBackground != null) { |
| 107 | mStackedBackground.setCallback(null); |
| 108 | unscheduleDrawable(mStackedBackground); |
| 109 | } |
Adam Powell | f88b915 | 2011-09-07 14:54:32 -0700 | [diff] [blame] | 110 | mStackedBackground = bg; |
Adam Powell | a7cc06d | 2012-08-01 16:31:23 -0700 | [diff] [blame] | 111 | if (bg != null) { |
| 112 | bg.setCallback(this); |
Adam Powell | e8c8ae4 | 2013-02-08 17:32:24 -0800 | [diff] [blame] | 113 | if ((mIsStacked && mStackedBackground != null)) { |
| 114 | mStackedBackground.setBounds(mTabContainer.getLeft(), mTabContainer.getTop(), |
| 115 | mTabContainer.getRight(), mTabContainer.getBottom()); |
| 116 | } |
Adam Powell | a7cc06d | 2012-08-01 16:31:23 -0700 | [diff] [blame] | 117 | } |
| 118 | setWillNotDraw(mIsSplit ? mSplitBackground == null : |
| 119 | mBackground == null && mStackedBackground == null); |
Adam Powell | f88b915 | 2011-09-07 14:54:32 -0700 | [diff] [blame] | 120 | invalidate(); |
| 121 | } |
| 122 | |
| 123 | public void setSplitBackground(Drawable bg) { |
Adam Powell | a7cc06d | 2012-08-01 16:31:23 -0700 | [diff] [blame] | 124 | if (mSplitBackground != null) { |
| 125 | mSplitBackground.setCallback(null); |
| 126 | unscheduleDrawable(mSplitBackground); |
| 127 | } |
Adam Powell | f88b915 | 2011-09-07 14:54:32 -0700 | [diff] [blame] | 128 | mSplitBackground = bg; |
Adam Powell | a7cc06d | 2012-08-01 16:31:23 -0700 | [diff] [blame] | 129 | if (bg != null) { |
| 130 | bg.setCallback(this); |
Adam Powell | e8c8ae4 | 2013-02-08 17:32:24 -0800 | [diff] [blame] | 131 | if (mIsSplit && mSplitBackground != null) { |
| 132 | mSplitBackground.setBounds(0, 0, getMeasuredWidth(), getMeasuredHeight()); |
| 133 | } |
Adam Powell | a7cc06d | 2012-08-01 16:31:23 -0700 | [diff] [blame] | 134 | } |
| 135 | setWillNotDraw(mIsSplit ? mSplitBackground == null : |
| 136 | mBackground == null && mStackedBackground == null); |
Adam Powell | f88b915 | 2011-09-07 14:54:32 -0700 | [diff] [blame] | 137 | invalidate(); |
| 138 | } |
| 139 | |
Adam Powell | a7cc06d | 2012-08-01 16:31:23 -0700 | [diff] [blame] | 140 | @Override |
| 141 | public void setVisibility(int visibility) { |
| 142 | super.setVisibility(visibility); |
| 143 | final boolean isVisible = visibility == VISIBLE; |
| 144 | if (mBackground != null) mBackground.setVisible(isVisible, false); |
| 145 | if (mStackedBackground != null) mStackedBackground.setVisible(isVisible, false); |
| 146 | if (mSplitBackground != null) mSplitBackground.setVisible(isVisible, false); |
| 147 | } |
| 148 | |
| 149 | @Override |
| 150 | protected boolean verifyDrawable(Drawable who) { |
| 151 | return (who == mBackground && !mIsSplit) || (who == mStackedBackground && mIsStacked) || |
| 152 | (who == mSplitBackground && mIsSplit) || super.verifyDrawable(who); |
| 153 | } |
| 154 | |
| 155 | @Override |
| 156 | protected void drawableStateChanged() { |
| 157 | super.drawableStateChanged(); |
| 158 | if (mBackground != null && mBackground.isStateful()) { |
| 159 | mBackground.setState(getDrawableState()); |
| 160 | } |
| 161 | if (mStackedBackground != null && mStackedBackground.isStateful()) { |
| 162 | mStackedBackground.setState(getDrawableState()); |
| 163 | } |
| 164 | if (mSplitBackground != null && mSplitBackground.isStateful()) { |
| 165 | mSplitBackground.setState(getDrawableState()); |
| 166 | } |
| 167 | } |
| 168 | |
| 169 | @Override |
| 170 | public void jumpDrawablesToCurrentState() { |
| 171 | super.jumpDrawablesToCurrentState(); |
| 172 | if (mBackground != null) { |
| 173 | mBackground.jumpToCurrentState(); |
| 174 | } |
| 175 | if (mStackedBackground != null) { |
| 176 | mStackedBackground.jumpToCurrentState(); |
| 177 | } |
| 178 | if (mSplitBackground != null) { |
| 179 | mSplitBackground.jumpToCurrentState(); |
| 180 | } |
| 181 | } |
| 182 | |
Fabrice Di Meglio | 4457e85 | 2012-09-18 19:23:12 -0700 | [diff] [blame] | 183 | /** |
| 184 | * @hide |
| 185 | */ |
Adam Powell | a7cc06d | 2012-08-01 16:31:23 -0700 | [diff] [blame] | 186 | @Override |
| 187 | public void onResolveDrawables(int layoutDirection) { |
| 188 | super.onResolveDrawables(layoutDirection); |
| 189 | if (mBackground != null) { |
| 190 | mBackground.setLayoutDirection(layoutDirection); |
| 191 | } |
| 192 | if (mStackedBackground != null) { |
| 193 | mStackedBackground.setLayoutDirection(layoutDirection); |
| 194 | } |
| 195 | if (mSplitBackground != null) { |
| 196 | mSplitBackground.setLayoutDirection(layoutDirection); |
| 197 | } |
| 198 | } |
| 199 | |
Adam Powell | 01feaee | 2011-02-10 15:05:05 -0800 | [diff] [blame] | 200 | /** |
| 201 | * Set the action bar into a "transitioning" state. While transitioning |
| 202 | * the bar will block focus and touch from all of its descendants. This |
| 203 | * prevents the user from interacting with the bar while it is animating |
| 204 | * in or out. |
| 205 | * |
| 206 | * @param isTransitioning true if the bar is currently transitioning, false otherwise. |
| 207 | */ |
| 208 | public void setTransitioning(boolean isTransitioning) { |
| 209 | mIsTransitioning = isTransitioning; |
| 210 | setDescendantFocusability(isTransitioning ? FOCUS_BLOCK_DESCENDANTS |
| 211 | : FOCUS_AFTER_DESCENDANTS); |
| 212 | } |
| 213 | |
| 214 | @Override |
| 215 | public boolean onInterceptTouchEvent(MotionEvent ev) { |
| 216 | return mIsTransitioning || super.onInterceptTouchEvent(ev); |
| 217 | } |
| 218 | |
Adam Powell | 6ecf3d1 | 2010-12-19 13:14:58 -0800 | [diff] [blame] | 219 | @Override |
| 220 | public boolean onTouchEvent(MotionEvent ev) { |
| 221 | super.onTouchEvent(ev); |
Adam Powell | dae7824 | 2011-04-25 15:23:41 -0700 | [diff] [blame] | 222 | |
| 223 | // An action bar always eats touch events. |
Adam Powell | 6ecf3d1 | 2010-12-19 13:14:58 -0800 | [diff] [blame] | 224 | return true; |
| 225 | } |
Adam Powell | dae7824 | 2011-04-25 15:23:41 -0700 | [diff] [blame] | 226 | |
Adam Powell | 7d09f04 | 2011-10-10 11:15:56 -0700 | [diff] [blame] | 227 | @Override |
| 228 | public boolean onHoverEvent(MotionEvent ev) { |
| 229 | super.onHoverEvent(ev); |
| 230 | |
| 231 | // An action bar always eats hover events. |
| 232 | return true; |
| 233 | } |
| 234 | |
Adam Powell | f5645cb | 2011-08-10 22:49:02 -0700 | [diff] [blame] | 235 | public void setTabContainer(ScrollingTabContainerView tabView) { |
Adam Powell | dae7824 | 2011-04-25 15:23:41 -0700 | [diff] [blame] | 236 | if (mTabContainer != null) { |
| 237 | removeView(mTabContainer); |
| 238 | } |
| 239 | mTabContainer = tabView; |
Adam Powell | 25151e4 | 2011-05-26 15:44:59 -0700 | [diff] [blame] | 240 | if (tabView != null) { |
| 241 | addView(tabView); |
Adam Powell | af6b97e | 2011-08-11 17:40:57 -0700 | [diff] [blame] | 242 | final ViewGroup.LayoutParams lp = tabView.getLayoutParams(); |
| 243 | lp.width = LayoutParams.MATCH_PARENT; |
| 244 | lp.height = LayoutParams.WRAP_CONTENT; |
Adam Powell | f5645cb | 2011-08-10 22:49:02 -0700 | [diff] [blame] | 245 | tabView.setAllowCollapse(false); |
Adam Powell | 25151e4 | 2011-05-26 15:44:59 -0700 | [diff] [blame] | 246 | } |
Adam Powell | dae7824 | 2011-04-25 15:23:41 -0700 | [diff] [blame] | 247 | } |
| 248 | |
| 249 | public View getTabContainer() { |
| 250 | return mTabContainer; |
| 251 | } |
| 252 | |
| 253 | @Override |
Adam Powell | 640a66e | 2011-04-29 10:18:53 -0700 | [diff] [blame] | 254 | public ActionMode startActionModeForChild(View child, ActionMode.Callback callback) { |
| 255 | // No starting an action mode for an action bar child! (Where would it go?) |
| 256 | return null; |
| 257 | } |
| 258 | |
Clara Bayarri | 4423d91 | 2015-03-02 19:42:48 +0000 | [diff] [blame] | 259 | @Override |
| 260 | public ActionMode startActionModeForChild( |
| 261 | View child, ActionMode.Callback callback, int type) { |
| 262 | if (type != ActionMode.TYPE_PRIMARY) { |
| 263 | return super.startActionModeForChild(child, callback, type); |
| 264 | } |
| 265 | return null; |
| 266 | } |
| 267 | |
Chris Craik | 1e610d4 | 2014-08-13 10:37:18 -0700 | [diff] [blame] | 268 | private static boolean isCollapsed(View view) { |
Adam Powell | e021e6e | 2014-05-23 17:27:24 -0700 | [diff] [blame] | 269 | return view == null || view.getVisibility() == GONE || view.getMeasuredHeight() == 0; |
| 270 | } |
| 271 | |
Yigit Boyar | 2bbad0c | 2014-09-16 18:28:03 -0700 | [diff] [blame] | 272 | private int getMeasuredHeightWithMargins(View view) { |
| 273 | final LayoutParams lp = (LayoutParams) view.getLayoutParams(); |
| 274 | return view.getMeasuredHeight() + lp.topMargin + lp.bottomMargin; |
| 275 | } |
| 276 | |
Adam Powell | 640a66e | 2011-04-29 10:18:53 -0700 | [diff] [blame] | 277 | @Override |
Adam Powell | dae7824 | 2011-04-25 15:23:41 -0700 | [diff] [blame] | 278 | public void onMeasure(int widthMeasureSpec, int heightMeasureSpec) { |
Adam Powell | e43340c | 2014-03-17 19:10:43 -0700 | [diff] [blame] | 279 | if (mActionBarView == null && |
| 280 | MeasureSpec.getMode(heightMeasureSpec) == MeasureSpec.AT_MOST && mHeight >= 0) { |
| 281 | heightMeasureSpec = MeasureSpec.makeMeasureSpec( |
| 282 | Math.min(mHeight, MeasureSpec.getSize(heightMeasureSpec)), MeasureSpec.AT_MOST); |
| 283 | } |
Adam Powell | dae7824 | 2011-04-25 15:23:41 -0700 | [diff] [blame] | 284 | super.onMeasure(widthMeasureSpec, heightMeasureSpec); |
Adam Powell | d21aa12 | 2011-05-27 13:09:52 -0700 | [diff] [blame] | 285 | |
Adam Powell | f6ce6a9 | 2011-06-29 10:25:01 -0700 | [diff] [blame] | 286 | if (mActionBarView == null) return; |
Adam Powell | 310849a | 2011-06-08 20:07:17 -0700 | [diff] [blame] | 287 | |
Adam Powell | dae7824 | 2011-04-25 15:23:41 -0700 | [diff] [blame] | 288 | if (mTabContainer != null && mTabContainer.getVisibility() != GONE) { |
Yigit Boyar | 2bbad0c | 2014-09-16 18:28:03 -0700 | [diff] [blame] | 289 | int nonTabMaxHeight = 0; |
| 290 | final int childCount = getChildCount(); |
| 291 | for (int i = 0; i < childCount; i++) { |
| 292 | final View child = getChildAt(i); |
| 293 | if (child == mTabContainer) { |
| 294 | continue; |
| 295 | } |
| 296 | nonTabMaxHeight = Math.max(nonTabMaxHeight, isCollapsed(child) ? 0 : |
| 297 | getMeasuredHeightWithMargins(child)); |
Adam Powell | dae7824 | 2011-04-25 15:23:41 -0700 | [diff] [blame] | 298 | } |
Yigit Boyar | 2bbad0c | 2014-09-16 18:28:03 -0700 | [diff] [blame] | 299 | final int mode = MeasureSpec.getMode(heightMeasureSpec); |
| 300 | final int maxHeight = mode == MeasureSpec.AT_MOST ? |
| 301 | MeasureSpec.getSize(heightMeasureSpec) : Integer.MAX_VALUE; |
| 302 | setMeasuredDimension(getMeasuredWidth(), |
| 303 | Math.min(nonTabMaxHeight + getMeasuredHeightWithMargins(mTabContainer), |
| 304 | maxHeight)); |
Adam Powell | dae7824 | 2011-04-25 15:23:41 -0700 | [diff] [blame] | 305 | } |
| 306 | } |
| 307 | |
| 308 | @Override |
| 309 | public void onLayout(boolean changed, int l, int t, int r, int b) { |
| 310 | super.onLayout(changed, l, t, r, b); |
Adam Powell | a72ef62 | 2011-07-06 22:53:11 -0700 | [diff] [blame] | 311 | |
Alan Viverette | 7f610fe | 2014-02-19 14:40:12 -0800 | [diff] [blame] | 312 | final View tabContainer = mTabContainer; |
| 313 | final boolean hasTabs = tabContainer != null && tabContainer.getVisibility() != GONE; |
Adam Powell | a72ef62 | 2011-07-06 22:53:11 -0700 | [diff] [blame] | 314 | |
Alan Viverette | 7f610fe | 2014-02-19 14:40:12 -0800 | [diff] [blame] | 315 | if (tabContainer != null && tabContainer.getVisibility() != GONE) { |
Adam Powell | dae7824 | 2011-04-25 15:23:41 -0700 | [diff] [blame] | 316 | final int containerHeight = getMeasuredHeight(); |
Yigit Boyar | 2bbad0c | 2014-09-16 18:28:03 -0700 | [diff] [blame] | 317 | final LayoutParams lp = (LayoutParams) tabContainer.getLayoutParams(); |
Alan Viverette | 7f610fe | 2014-02-19 14:40:12 -0800 | [diff] [blame] | 318 | final int tabHeight = tabContainer.getMeasuredHeight(); |
Yigit Boyar | 2bbad0c | 2014-09-16 18:28:03 -0700 | [diff] [blame] | 319 | tabContainer.layout(l, containerHeight - tabHeight - lp.bottomMargin, r, |
| 320 | containerHeight - lp.bottomMargin); |
Adam Powell | dae7824 | 2011-04-25 15:23:41 -0700 | [diff] [blame] | 321 | } |
Adam Powell | a72ef62 | 2011-07-06 22:53:11 -0700 | [diff] [blame] | 322 | |
| 323 | boolean needsInvalidate = false; |
| 324 | if (mIsSplit) { |
| 325 | if (mSplitBackground != null) { |
| 326 | mSplitBackground.setBounds(0, 0, getMeasuredWidth(), getMeasuredHeight()); |
| 327 | needsInvalidate = true; |
| 328 | } |
| 329 | } else { |
| 330 | if (mBackground != null) { |
Chet Haase | ccd3da2 | 2014-09-12 18:03:55 -0700 | [diff] [blame] | 331 | if (mActionBarView.getVisibility() == View.VISIBLE) { |
| 332 | mBackground.setBounds(mActionBarView.getLeft(), mActionBarView.getTop(), |
| 333 | mActionBarView.getRight(), mActionBarView.getBottom()); |
| 334 | } else if (mActionContextView != null && |
| 335 | mActionContextView.getVisibility() == View.VISIBLE) { |
| 336 | mBackground.setBounds(mActionContextView.getLeft(), mActionContextView.getTop(), |
| 337 | mActionContextView.getRight(), mActionContextView.getBottom()); |
| 338 | } else { |
| 339 | mBackground.setBounds(0, 0, 0, 0); |
| 340 | } |
Adam Powell | a72ef62 | 2011-07-06 22:53:11 -0700 | [diff] [blame] | 341 | needsInvalidate = true; |
| 342 | } |
Alan Viverette | 7f610fe | 2014-02-19 14:40:12 -0800 | [diff] [blame] | 343 | mIsStacked = hasTabs; |
| 344 | if (hasTabs && mStackedBackground != null) { |
| 345 | mStackedBackground.setBounds(tabContainer.getLeft(), tabContainer.getTop(), |
| 346 | tabContainer.getRight(), tabContainer.getBottom()); |
Adam Powell | a72ef62 | 2011-07-06 22:53:11 -0700 | [diff] [blame] | 347 | needsInvalidate = true; |
| 348 | } |
| 349 | } |
| 350 | |
| 351 | if (needsInvalidate) { |
| 352 | invalidate(); |
| 353 | } |
Adam Powell | dae7824 | 2011-04-25 15:23:41 -0700 | [diff] [blame] | 354 | } |
Alan Viverette | 7f610fe | 2014-02-19 14:40:12 -0800 | [diff] [blame] | 355 | |
| 356 | /** |
| 357 | * Dummy drawable so that we don't break background display lists and |
| 358 | * projection surfaces. |
| 359 | */ |
| 360 | private class ActionBarBackgroundDrawable extends Drawable { |
Chris Craik | 1e610d4 | 2014-08-13 10:37:18 -0700 | [diff] [blame] | 361 | @Override |
| 362 | public void draw(Canvas canvas) { |
Alan Viverette | 7f610fe | 2014-02-19 14:40:12 -0800 | [diff] [blame] | 363 | if (mIsSplit) { |
Chris Craik | 77b5cad | 2014-07-30 18:23:07 -0700 | [diff] [blame] | 364 | if (mSplitBackground != null) { |
Chris Craik | 1e610d4 | 2014-08-13 10:37:18 -0700 | [diff] [blame] | 365 | mSplitBackground.draw(canvas); |
Chris Craik | 77b5cad | 2014-07-30 18:23:07 -0700 | [diff] [blame] | 366 | } |
Alan Viverette | 7f610fe | 2014-02-19 14:40:12 -0800 | [diff] [blame] | 367 | } else { |
| 368 | if (mBackground != null) { |
Chris Craik | 1e610d4 | 2014-08-13 10:37:18 -0700 | [diff] [blame] | 369 | mBackground.draw(canvas); |
Alan Viverette | 7f610fe | 2014-02-19 14:40:12 -0800 | [diff] [blame] | 370 | } |
| 371 | if (mStackedBackground != null && mIsStacked) { |
Chris Craik | 1e610d4 | 2014-08-13 10:37:18 -0700 | [diff] [blame] | 372 | mStackedBackground.draw(canvas); |
Alan Viverette | 7f610fe | 2014-02-19 14:40:12 -0800 | [diff] [blame] | 373 | } |
| 374 | } |
Chris Craik | 77b5cad | 2014-07-30 18:23:07 -0700 | [diff] [blame] | 375 | } |
| 376 | |
| 377 | @Override |
| 378 | public void getOutline(@NonNull Outline outline) { |
Chris Craik | 1e610d4 | 2014-08-13 10:37:18 -0700 | [diff] [blame] | 379 | if (mIsSplit) { |
| 380 | if (mSplitBackground != null) { |
| 381 | mSplitBackground.getOutline(outline); |
| 382 | } |
| 383 | } else { |
| 384 | // ignore the stacked background for shadow casting |
| 385 | if (mBackground != null) { |
| 386 | mBackground.getOutline(outline); |
| 387 | } |
Chris Craik | 77b5cad | 2014-07-30 18:23:07 -0700 | [diff] [blame] | 388 | } |
Alan Viverette | 7f610fe | 2014-02-19 14:40:12 -0800 | [diff] [blame] | 389 | } |
| 390 | |
| 391 | @Override |
| 392 | public void setAlpha(int alpha) { |
| 393 | } |
| 394 | |
| 395 | @Override |
Chris Craik | bd3bfc5 | 2015-03-02 10:43:29 -0800 | [diff] [blame] | 396 | public void setColorFilter(ColorFilter colorFilter) { |
Alan Viverette | 7f610fe | 2014-02-19 14:40:12 -0800 | [diff] [blame] | 397 | } |
| 398 | |
| 399 | @Override |
| 400 | public int getOpacity() { |
Adam Powell | f849a5e | 2014-09-11 15:09:36 -0700 | [diff] [blame] | 401 | if (mIsSplit) { |
| 402 | if (mSplitBackground != null |
| 403 | && mSplitBackground.getOpacity() == PixelFormat.OPAQUE) { |
| 404 | return PixelFormat.OPAQUE; |
| 405 | } |
| 406 | } else { |
| 407 | if (mIsStacked && (mStackedBackground == null |
| 408 | || mStackedBackground.getOpacity() != PixelFormat.OPAQUE)) { |
| 409 | return PixelFormat.UNKNOWN; |
| 410 | } |
| 411 | if (!isCollapsed(mActionBarView) && mBackground != null |
| 412 | && mBackground.getOpacity() == PixelFormat.OPAQUE) { |
| 413 | return PixelFormat.OPAQUE; |
| 414 | } |
| 415 | } |
| 416 | |
| 417 | return PixelFormat.UNKNOWN; |
Alan Viverette | 7f610fe | 2014-02-19 14:40:12 -0800 | [diff] [blame] | 418 | } |
| 419 | } |
Adam Powell | 45f1e08 | 2010-12-10 14:20:13 -0800 | [diff] [blame] | 420 | } |