ActionBarContainer.java revision ccd3da23c6dbdda2af5c5d746652e4b240cb4f50
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
1977b5cad3efedd20f2b7cc14d87ccce1b0261960aChris Craikimport android.annotation.NonNull;
2045f1e08c348ccb129bcc25e438c05421f7123f41Adam Powellimport android.content.Context;
2145f1e08c348ccb129bcc25e438c05421f7123f41Adam Powellimport android.content.res.TypedArray;
22a72ef62e5c329a19eab9935acba816fc1369c637Adam Powellimport android.graphics.Canvas;
237f610fed107b158c144dca1b20a44ee91eb8c934Alan Viveretteimport android.graphics.ColorFilter;
2477b5cad3efedd20f2b7cc14d87ccce1b0261960aChris Craikimport android.graphics.Outline;
25a72ef62e5c329a19eab9935acba816fc1369c637Adam Powellimport android.graphics.drawable.Drawable;
2645f1e08c348ccb129bcc25e438c05421f7123f41Adam Powellimport android.util.AttributeSet;
27640a66eac612b850b5dabd3b93bd94f83ed2d567Adam Powellimport android.view.ActionMode;
286ecf3d1690789ace1a667093ad6bbdd6cd35bda7Adam Powellimport android.view.MotionEvent;
29dae7824c4b78d02159c6ad0896f246942d7b3d8cAdam Powellimport android.view.View;
30af6b97ebe0e6a67d1691c4d7789c7bc312c1e13eAdam Powellimport android.view.ViewGroup;
3145f1e08c348ccb129bcc25e438c05421f7123f41Adam Powellimport android.widget.FrameLayout;
3245f1e08c348ccb129bcc25e438c05421f7123f41Adam Powell
3345f1e08c348ccb129bcc25e438c05421f7123f41Adam Powell/**
3445f1e08c348ccb129bcc25e438c05421f7123f41Adam Powell * This class acts as a container for the action bar view and action mode context views.
3545f1e08c348ccb129bcc25e438c05421f7123f41Adam Powell * It applies special styles as needed to help handle animated transitions between them.
3645f1e08c348ccb129bcc25e438c05421f7123f41Adam Powell * @hide
3745f1e08c348ccb129bcc25e438c05421f7123f41Adam Powell */
3845f1e08c348ccb129bcc25e438c05421f7123f41Adam Powellpublic class ActionBarContainer extends FrameLayout {
3901feaee3d9767ef1185783877e92244f14d7d4baAdam Powell    private boolean mIsTransitioning;
40dae7824c4b78d02159c6ad0896f246942d7b3d8cAdam Powell    private View mTabContainer;
41e021e6ed8931a0a8296af182fc9b0c76b64fb0c4Adam Powell    private View mActionBarView;
42ccd3da23c6dbdda2af5c5d746652e4b240cb4f50Chet Haase    private View mActionContextView;
4301feaee3d9767ef1185783877e92244f14d7d4baAdam Powell
44a72ef62e5c329a19eab9935acba816fc1369c637Adam Powell    private Drawable mBackground;
45a72ef62e5c329a19eab9935acba816fc1369c637Adam Powell    private Drawable mStackedBackground;
46a72ef62e5c329a19eab9935acba816fc1369c637Adam Powell    private Drawable mSplitBackground;
47a72ef62e5c329a19eab9935acba816fc1369c637Adam Powell    private boolean mIsSplit;
48a72ef62e5c329a19eab9935acba816fc1369c637Adam Powell    private boolean mIsStacked;
49e43340c80dc66c45edc793ecd0343774aa34d108Adam Powell    private int mHeight;
50a72ef62e5c329a19eab9935acba816fc1369c637Adam Powell
5145f1e08c348ccb129bcc25e438c05421f7123f41Adam Powell    public ActionBarContainer(Context context) {
5245f1e08c348ccb129bcc25e438c05421f7123f41Adam Powell        this(context, null);
5345f1e08c348ccb129bcc25e438c05421f7123f41Adam Powell    }
5445f1e08c348ccb129bcc25e438c05421f7123f41Adam Powell
5545f1e08c348ccb129bcc25e438c05421f7123f41Adam Powell    public ActionBarContainer(Context context, AttributeSet attrs) {
5645f1e08c348ccb129bcc25e438c05421f7123f41Adam Powell        super(context, attrs);
5745f1e08c348ccb129bcc25e438c05421f7123f41Adam Powell
587f610fed107b158c144dca1b20a44ee91eb8c934Alan Viverette        // Set a transparent background so that we project appropriately.
597f610fed107b158c144dca1b20a44ee91eb8c934Alan Viverette        setBackground(new ActionBarBackgroundDrawable());
60a72ef62e5c329a19eab9935acba816fc1369c637Adam Powell
6145f1e08c348ccb129bcc25e438c05421f7123f41Adam Powell        TypedArray a = context.obtainStyledAttributes(attrs,
6245f1e08c348ccb129bcc25e438c05421f7123f41Adam Powell                com.android.internal.R.styleable.ActionBar);
63a72ef62e5c329a19eab9935acba816fc1369c637Adam Powell        mBackground = a.getDrawable(com.android.internal.R.styleable.ActionBar_background);
64a72ef62e5c329a19eab9935acba816fc1369c637Adam Powell        mStackedBackground = a.getDrawable(
65a72ef62e5c329a19eab9935acba816fc1369c637Adam Powell                com.android.internal.R.styleable.ActionBar_backgroundStacked);
66e43340c80dc66c45edc793ecd0343774aa34d108Adam Powell        mHeight = a.getDimensionPixelSize(com.android.internal.R.styleable.ActionBar_height, -1);
67a72ef62e5c329a19eab9935acba816fc1369c637Adam Powell
68a72ef62e5c329a19eab9935acba816fc1369c637Adam Powell        if (getId() == com.android.internal.R.id.split_action_bar) {
69a72ef62e5c329a19eab9935acba816fc1369c637Adam Powell            mIsSplit = true;
70a72ef62e5c329a19eab9935acba816fc1369c637Adam Powell            mSplitBackground = a.getDrawable(
71a72ef62e5c329a19eab9935acba816fc1369c637Adam Powell                    com.android.internal.R.styleable.ActionBar_backgroundSplit);
72a72ef62e5c329a19eab9935acba816fc1369c637Adam Powell        }
7345f1e08c348ccb129bcc25e438c05421f7123f41Adam Powell        a.recycle();
74a72ef62e5c329a19eab9935acba816fc1369c637Adam Powell
75a72ef62e5c329a19eab9935acba816fc1369c637Adam Powell        setWillNotDraw(mIsSplit ? mSplitBackground == null :
76a72ef62e5c329a19eab9935acba816fc1369c637Adam Powell                mBackground == null && mStackedBackground == null);
7745f1e08c348ccb129bcc25e438c05421f7123f41Adam Powell    }
786ecf3d1690789ace1a667093ad6bbdd6cd35bda7Adam Powell
79310849abb1a0763ea9912b59187f0a4271efaa2eAdam Powell    @Override
80310849abb1a0763ea9912b59187f0a4271efaa2eAdam Powell    public void onFinishInflate() {
81310849abb1a0763ea9912b59187f0a4271efaa2eAdam Powell        super.onFinishInflate();
82e021e6ed8931a0a8296af182fc9b0c76b64fb0c4Adam Powell        mActionBarView = findViewById(com.android.internal.R.id.action_bar);
83ccd3da23c6dbdda2af5c5d746652e4b240cb4f50Chet Haase        mActionContextView = findViewById(com.android.internal.R.id.action_context_bar);
84310849abb1a0763ea9912b59187f0a4271efaa2eAdam Powell    }
85310849abb1a0763ea9912b59187f0a4271efaa2eAdam Powell
86f88b915567a37c481c4c50a6cc57e1ec0e7cf50dAdam Powell    public void setPrimaryBackground(Drawable bg) {
87a7cc06d82e45918c37429a59b14545c6a57db4e4Adam Powell        if (mBackground != null) {
88a7cc06d82e45918c37429a59b14545c6a57db4e4Adam Powell            mBackground.setCallback(null);
89a7cc06d82e45918c37429a59b14545c6a57db4e4Adam Powell            unscheduleDrawable(mBackground);
90a7cc06d82e45918c37429a59b14545c6a57db4e4Adam Powell        }
91f88b915567a37c481c4c50a6cc57e1ec0e7cf50dAdam Powell        mBackground = bg;
92a7cc06d82e45918c37429a59b14545c6a57db4e4Adam Powell        if (bg != null) {
93a7cc06d82e45918c37429a59b14545c6a57db4e4Adam Powell            bg.setCallback(this);
94e8c8ae401b6f0d894a766a1601f55f0fe567df02Adam Powell            if (mActionBarView != null) {
95e8c8ae401b6f0d894a766a1601f55f0fe567df02Adam Powell                mBackground.setBounds(mActionBarView.getLeft(), mActionBarView.getTop(),
96e8c8ae401b6f0d894a766a1601f55f0fe567df02Adam Powell                        mActionBarView.getRight(), mActionBarView.getBottom());
97e8c8ae401b6f0d894a766a1601f55f0fe567df02Adam Powell            }
98a7cc06d82e45918c37429a59b14545c6a57db4e4Adam Powell        }
99a7cc06d82e45918c37429a59b14545c6a57db4e4Adam Powell        setWillNotDraw(mIsSplit ? mSplitBackground == null :
100a7cc06d82e45918c37429a59b14545c6a57db4e4Adam Powell                mBackground == null && mStackedBackground == null);
101f88b915567a37c481c4c50a6cc57e1ec0e7cf50dAdam Powell        invalidate();
102f88b915567a37c481c4c50a6cc57e1ec0e7cf50dAdam Powell    }
103f88b915567a37c481c4c50a6cc57e1ec0e7cf50dAdam Powell
104f88b915567a37c481c4c50a6cc57e1ec0e7cf50dAdam Powell    public void setStackedBackground(Drawable bg) {
105a7cc06d82e45918c37429a59b14545c6a57db4e4Adam Powell        if (mStackedBackground != null) {
106a7cc06d82e45918c37429a59b14545c6a57db4e4Adam Powell            mStackedBackground.setCallback(null);
107a7cc06d82e45918c37429a59b14545c6a57db4e4Adam Powell            unscheduleDrawable(mStackedBackground);
108a7cc06d82e45918c37429a59b14545c6a57db4e4Adam Powell        }
109f88b915567a37c481c4c50a6cc57e1ec0e7cf50dAdam Powell        mStackedBackground = bg;
110a7cc06d82e45918c37429a59b14545c6a57db4e4Adam Powell        if (bg != null) {
111a7cc06d82e45918c37429a59b14545c6a57db4e4Adam Powell            bg.setCallback(this);
112e8c8ae401b6f0d894a766a1601f55f0fe567df02Adam Powell            if ((mIsStacked && mStackedBackground != null)) {
113e8c8ae401b6f0d894a766a1601f55f0fe567df02Adam Powell                mStackedBackground.setBounds(mTabContainer.getLeft(), mTabContainer.getTop(),
114e8c8ae401b6f0d894a766a1601f55f0fe567df02Adam Powell                        mTabContainer.getRight(), mTabContainer.getBottom());
115e8c8ae401b6f0d894a766a1601f55f0fe567df02Adam Powell            }
116a7cc06d82e45918c37429a59b14545c6a57db4e4Adam Powell        }
117a7cc06d82e45918c37429a59b14545c6a57db4e4Adam Powell        setWillNotDraw(mIsSplit ? mSplitBackground == null :
118a7cc06d82e45918c37429a59b14545c6a57db4e4Adam Powell                mBackground == null && mStackedBackground == null);
119f88b915567a37c481c4c50a6cc57e1ec0e7cf50dAdam Powell        invalidate();
120f88b915567a37c481c4c50a6cc57e1ec0e7cf50dAdam Powell    }
121f88b915567a37c481c4c50a6cc57e1ec0e7cf50dAdam Powell
122f88b915567a37c481c4c50a6cc57e1ec0e7cf50dAdam Powell    public void setSplitBackground(Drawable bg) {
123a7cc06d82e45918c37429a59b14545c6a57db4e4Adam Powell        if (mSplitBackground != null) {
124a7cc06d82e45918c37429a59b14545c6a57db4e4Adam Powell            mSplitBackground.setCallback(null);
125a7cc06d82e45918c37429a59b14545c6a57db4e4Adam Powell            unscheduleDrawable(mSplitBackground);
126a7cc06d82e45918c37429a59b14545c6a57db4e4Adam Powell        }
127f88b915567a37c481c4c50a6cc57e1ec0e7cf50dAdam Powell        mSplitBackground = bg;
128a7cc06d82e45918c37429a59b14545c6a57db4e4Adam Powell        if (bg != null) {
129a7cc06d82e45918c37429a59b14545c6a57db4e4Adam Powell            bg.setCallback(this);
130e8c8ae401b6f0d894a766a1601f55f0fe567df02Adam Powell            if (mIsSplit && mSplitBackground != null) {
131e8c8ae401b6f0d894a766a1601f55f0fe567df02Adam Powell                mSplitBackground.setBounds(0, 0, getMeasuredWidth(), getMeasuredHeight());
132e8c8ae401b6f0d894a766a1601f55f0fe567df02Adam Powell            }
133a7cc06d82e45918c37429a59b14545c6a57db4e4Adam Powell        }
134a7cc06d82e45918c37429a59b14545c6a57db4e4Adam Powell        setWillNotDraw(mIsSplit ? mSplitBackground == null :
135a7cc06d82e45918c37429a59b14545c6a57db4e4Adam Powell                mBackground == null && mStackedBackground == null);
136f88b915567a37c481c4c50a6cc57e1ec0e7cf50dAdam Powell        invalidate();
137f88b915567a37c481c4c50a6cc57e1ec0e7cf50dAdam Powell    }
138f88b915567a37c481c4c50a6cc57e1ec0e7cf50dAdam Powell
139a7cc06d82e45918c37429a59b14545c6a57db4e4Adam Powell    @Override
140a7cc06d82e45918c37429a59b14545c6a57db4e4Adam Powell    public void setVisibility(int visibility) {
141a7cc06d82e45918c37429a59b14545c6a57db4e4Adam Powell        super.setVisibility(visibility);
142a7cc06d82e45918c37429a59b14545c6a57db4e4Adam Powell        final boolean isVisible = visibility == VISIBLE;
143a7cc06d82e45918c37429a59b14545c6a57db4e4Adam Powell        if (mBackground != null) mBackground.setVisible(isVisible, false);
144a7cc06d82e45918c37429a59b14545c6a57db4e4Adam Powell        if (mStackedBackground != null) mStackedBackground.setVisible(isVisible, false);
145a7cc06d82e45918c37429a59b14545c6a57db4e4Adam Powell        if (mSplitBackground != null) mSplitBackground.setVisible(isVisible, false);
146a7cc06d82e45918c37429a59b14545c6a57db4e4Adam Powell    }
147a7cc06d82e45918c37429a59b14545c6a57db4e4Adam Powell
148a7cc06d82e45918c37429a59b14545c6a57db4e4Adam Powell    @Override
149a7cc06d82e45918c37429a59b14545c6a57db4e4Adam Powell    protected boolean verifyDrawable(Drawable who) {
150a7cc06d82e45918c37429a59b14545c6a57db4e4Adam Powell        return (who == mBackground && !mIsSplit) || (who == mStackedBackground && mIsStacked) ||
151a7cc06d82e45918c37429a59b14545c6a57db4e4Adam Powell                (who == mSplitBackground && mIsSplit) || super.verifyDrawable(who);
152a7cc06d82e45918c37429a59b14545c6a57db4e4Adam Powell    }
153a7cc06d82e45918c37429a59b14545c6a57db4e4Adam Powell
154a7cc06d82e45918c37429a59b14545c6a57db4e4Adam Powell    @Override
155a7cc06d82e45918c37429a59b14545c6a57db4e4Adam Powell    protected void drawableStateChanged() {
156a7cc06d82e45918c37429a59b14545c6a57db4e4Adam Powell        super.drawableStateChanged();
157a7cc06d82e45918c37429a59b14545c6a57db4e4Adam Powell        if (mBackground != null && mBackground.isStateful()) {
158a7cc06d82e45918c37429a59b14545c6a57db4e4Adam Powell            mBackground.setState(getDrawableState());
159a7cc06d82e45918c37429a59b14545c6a57db4e4Adam Powell        }
160a7cc06d82e45918c37429a59b14545c6a57db4e4Adam Powell        if (mStackedBackground != null && mStackedBackground.isStateful()) {
161a7cc06d82e45918c37429a59b14545c6a57db4e4Adam Powell            mStackedBackground.setState(getDrawableState());
162a7cc06d82e45918c37429a59b14545c6a57db4e4Adam Powell        }
163a7cc06d82e45918c37429a59b14545c6a57db4e4Adam Powell        if (mSplitBackground != null && mSplitBackground.isStateful()) {
164a7cc06d82e45918c37429a59b14545c6a57db4e4Adam Powell            mSplitBackground.setState(getDrawableState());
165a7cc06d82e45918c37429a59b14545c6a57db4e4Adam Powell        }
166a7cc06d82e45918c37429a59b14545c6a57db4e4Adam Powell    }
167a7cc06d82e45918c37429a59b14545c6a57db4e4Adam Powell
168a7cc06d82e45918c37429a59b14545c6a57db4e4Adam Powell    @Override
169a7cc06d82e45918c37429a59b14545c6a57db4e4Adam Powell    public void jumpDrawablesToCurrentState() {
170a7cc06d82e45918c37429a59b14545c6a57db4e4Adam Powell        super.jumpDrawablesToCurrentState();
171a7cc06d82e45918c37429a59b14545c6a57db4e4Adam Powell        if (mBackground != null) {
172a7cc06d82e45918c37429a59b14545c6a57db4e4Adam Powell            mBackground.jumpToCurrentState();
173a7cc06d82e45918c37429a59b14545c6a57db4e4Adam Powell        }
174a7cc06d82e45918c37429a59b14545c6a57db4e4Adam Powell        if (mStackedBackground != null) {
175a7cc06d82e45918c37429a59b14545c6a57db4e4Adam Powell            mStackedBackground.jumpToCurrentState();
176a7cc06d82e45918c37429a59b14545c6a57db4e4Adam Powell        }
177a7cc06d82e45918c37429a59b14545c6a57db4e4Adam Powell        if (mSplitBackground != null) {
178a7cc06d82e45918c37429a59b14545c6a57db4e4Adam Powell            mSplitBackground.jumpToCurrentState();
179a7cc06d82e45918c37429a59b14545c6a57db4e4Adam Powell        }
180a7cc06d82e45918c37429a59b14545c6a57db4e4Adam Powell    }
181a7cc06d82e45918c37429a59b14545c6a57db4e4Adam Powell
1824457e85a7090ad51726d50a4daf981d917cceeddFabrice Di Meglio    /**
1834457e85a7090ad51726d50a4daf981d917cceeddFabrice Di Meglio     * @hide
1844457e85a7090ad51726d50a4daf981d917cceeddFabrice Di Meglio     */
185a7cc06d82e45918c37429a59b14545c6a57db4e4Adam Powell    @Override
186a7cc06d82e45918c37429a59b14545c6a57db4e4Adam Powell    public void onResolveDrawables(int layoutDirection) {
187a7cc06d82e45918c37429a59b14545c6a57db4e4Adam Powell        super.onResolveDrawables(layoutDirection);
188a7cc06d82e45918c37429a59b14545c6a57db4e4Adam Powell        if (mBackground != null) {
189a7cc06d82e45918c37429a59b14545c6a57db4e4Adam Powell            mBackground.setLayoutDirection(layoutDirection);
190a7cc06d82e45918c37429a59b14545c6a57db4e4Adam Powell        }
191a7cc06d82e45918c37429a59b14545c6a57db4e4Adam Powell        if (mStackedBackground != null) {
192a7cc06d82e45918c37429a59b14545c6a57db4e4Adam Powell            mStackedBackground.setLayoutDirection(layoutDirection);
193a7cc06d82e45918c37429a59b14545c6a57db4e4Adam Powell        }
194a7cc06d82e45918c37429a59b14545c6a57db4e4Adam Powell        if (mSplitBackground != null) {
195a7cc06d82e45918c37429a59b14545c6a57db4e4Adam Powell            mSplitBackground.setLayoutDirection(layoutDirection);
196a7cc06d82e45918c37429a59b14545c6a57db4e4Adam Powell        }
197a7cc06d82e45918c37429a59b14545c6a57db4e4Adam Powell    }
198a7cc06d82e45918c37429a59b14545c6a57db4e4Adam Powell
19901feaee3d9767ef1185783877e92244f14d7d4baAdam Powell    /**
20001feaee3d9767ef1185783877e92244f14d7d4baAdam Powell     * Set the action bar into a "transitioning" state. While transitioning
20101feaee3d9767ef1185783877e92244f14d7d4baAdam Powell     * the bar will block focus and touch from all of its descendants. This
20201feaee3d9767ef1185783877e92244f14d7d4baAdam Powell     * prevents the user from interacting with the bar while it is animating
20301feaee3d9767ef1185783877e92244f14d7d4baAdam Powell     * in or out.
20401feaee3d9767ef1185783877e92244f14d7d4baAdam Powell     *
20501feaee3d9767ef1185783877e92244f14d7d4baAdam Powell     * @param isTransitioning true if the bar is currently transitioning, false otherwise.
20601feaee3d9767ef1185783877e92244f14d7d4baAdam Powell     */
20701feaee3d9767ef1185783877e92244f14d7d4baAdam Powell    public void setTransitioning(boolean isTransitioning) {
20801feaee3d9767ef1185783877e92244f14d7d4baAdam Powell        mIsTransitioning = isTransitioning;
20901feaee3d9767ef1185783877e92244f14d7d4baAdam Powell        setDescendantFocusability(isTransitioning ? FOCUS_BLOCK_DESCENDANTS
21001feaee3d9767ef1185783877e92244f14d7d4baAdam Powell                : FOCUS_AFTER_DESCENDANTS);
21101feaee3d9767ef1185783877e92244f14d7d4baAdam Powell    }
21201feaee3d9767ef1185783877e92244f14d7d4baAdam Powell
21301feaee3d9767ef1185783877e92244f14d7d4baAdam Powell    @Override
21401feaee3d9767ef1185783877e92244f14d7d4baAdam Powell    public boolean onInterceptTouchEvent(MotionEvent ev) {
21501feaee3d9767ef1185783877e92244f14d7d4baAdam Powell        return mIsTransitioning || super.onInterceptTouchEvent(ev);
21601feaee3d9767ef1185783877e92244f14d7d4baAdam Powell    }
21701feaee3d9767ef1185783877e92244f14d7d4baAdam Powell
2186ecf3d1690789ace1a667093ad6bbdd6cd35bda7Adam Powell    @Override
2196ecf3d1690789ace1a667093ad6bbdd6cd35bda7Adam Powell    public boolean onTouchEvent(MotionEvent ev) {
2206ecf3d1690789ace1a667093ad6bbdd6cd35bda7Adam Powell        super.onTouchEvent(ev);
221dae7824c4b78d02159c6ad0896f246942d7b3d8cAdam Powell
222dae7824c4b78d02159c6ad0896f246942d7b3d8cAdam Powell        // An action bar always eats touch events.
2236ecf3d1690789ace1a667093ad6bbdd6cd35bda7Adam Powell        return true;
2246ecf3d1690789ace1a667093ad6bbdd6cd35bda7Adam Powell    }
225dae7824c4b78d02159c6ad0896f246942d7b3d8cAdam Powell
2267d09f04363cdda6a3cf8b2ad1b67c9a07fa8975fAdam Powell    @Override
2277d09f04363cdda6a3cf8b2ad1b67c9a07fa8975fAdam Powell    public boolean onHoverEvent(MotionEvent ev) {
2287d09f04363cdda6a3cf8b2ad1b67c9a07fa8975fAdam Powell        super.onHoverEvent(ev);
2297d09f04363cdda6a3cf8b2ad1b67c9a07fa8975fAdam Powell
2307d09f04363cdda6a3cf8b2ad1b67c9a07fa8975fAdam Powell        // An action bar always eats hover events.
2317d09f04363cdda6a3cf8b2ad1b67c9a07fa8975fAdam Powell        return true;
2327d09f04363cdda6a3cf8b2ad1b67c9a07fa8975fAdam Powell    }
2337d09f04363cdda6a3cf8b2ad1b67c9a07fa8975fAdam Powell
234f5645cbafe7eed33452d888f16726bee8a0cd9feAdam Powell    public void setTabContainer(ScrollingTabContainerView tabView) {
235dae7824c4b78d02159c6ad0896f246942d7b3d8cAdam Powell        if (mTabContainer != null) {
236dae7824c4b78d02159c6ad0896f246942d7b3d8cAdam Powell            removeView(mTabContainer);
237dae7824c4b78d02159c6ad0896f246942d7b3d8cAdam Powell        }
238dae7824c4b78d02159c6ad0896f246942d7b3d8cAdam Powell        mTabContainer = tabView;
23925151e4792e9be8dbb892b7eba7349773b8127afAdam Powell        if (tabView != null) {
24025151e4792e9be8dbb892b7eba7349773b8127afAdam Powell            addView(tabView);
241af6b97ebe0e6a67d1691c4d7789c7bc312c1e13eAdam Powell            final ViewGroup.LayoutParams lp = tabView.getLayoutParams();
242af6b97ebe0e6a67d1691c4d7789c7bc312c1e13eAdam Powell            lp.width = LayoutParams.MATCH_PARENT;
243af6b97ebe0e6a67d1691c4d7789c7bc312c1e13eAdam Powell            lp.height = LayoutParams.WRAP_CONTENT;
244f5645cbafe7eed33452d888f16726bee8a0cd9feAdam Powell            tabView.setAllowCollapse(false);
24525151e4792e9be8dbb892b7eba7349773b8127afAdam Powell        }
246dae7824c4b78d02159c6ad0896f246942d7b3d8cAdam Powell    }
247dae7824c4b78d02159c6ad0896f246942d7b3d8cAdam Powell
248dae7824c4b78d02159c6ad0896f246942d7b3d8cAdam Powell    public View getTabContainer() {
249dae7824c4b78d02159c6ad0896f246942d7b3d8cAdam Powell        return mTabContainer;
250dae7824c4b78d02159c6ad0896f246942d7b3d8cAdam Powell    }
251dae7824c4b78d02159c6ad0896f246942d7b3d8cAdam Powell
252dae7824c4b78d02159c6ad0896f246942d7b3d8cAdam Powell    @Override
253640a66eac612b850b5dabd3b93bd94f83ed2d567Adam Powell    public ActionMode startActionModeForChild(View child, ActionMode.Callback callback) {
254640a66eac612b850b5dabd3b93bd94f83ed2d567Adam Powell        // No starting an action mode for an action bar child! (Where would it go?)
255640a66eac612b850b5dabd3b93bd94f83ed2d567Adam Powell        return null;
256640a66eac612b850b5dabd3b93bd94f83ed2d567Adam Powell    }
257640a66eac612b850b5dabd3b93bd94f83ed2d567Adam Powell
2581e610d479f091f1b09f2a7e5201711bf4d311f6fChris Craik    private static boolean isCollapsed(View view) {
259e021e6ed8931a0a8296af182fc9b0c76b64fb0c4Adam Powell        return view == null || view.getVisibility() == GONE || view.getMeasuredHeight() == 0;
260e021e6ed8931a0a8296af182fc9b0c76b64fb0c4Adam Powell    }
261e021e6ed8931a0a8296af182fc9b0c76b64fb0c4Adam Powell
262640a66eac612b850b5dabd3b93bd94f83ed2d567Adam Powell    @Override
263dae7824c4b78d02159c6ad0896f246942d7b3d8cAdam Powell    public void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
264e43340c80dc66c45edc793ecd0343774aa34d108Adam Powell        if (mActionBarView == null &&
265e43340c80dc66c45edc793ecd0343774aa34d108Adam Powell                MeasureSpec.getMode(heightMeasureSpec) == MeasureSpec.AT_MOST && mHeight >= 0) {
266e43340c80dc66c45edc793ecd0343774aa34d108Adam Powell            heightMeasureSpec = MeasureSpec.makeMeasureSpec(
267e43340c80dc66c45edc793ecd0343774aa34d108Adam Powell                    Math.min(mHeight, MeasureSpec.getSize(heightMeasureSpec)), MeasureSpec.AT_MOST);
268e43340c80dc66c45edc793ecd0343774aa34d108Adam Powell        }
269dae7824c4b78d02159c6ad0896f246942d7b3d8cAdam Powell        super.onMeasure(widthMeasureSpec, heightMeasureSpec);
270d21aa12e8eb9d46ee92bf408b4b48386c6bf062dAdam Powell
271f6ce6a9bacbb220c6ea7b552c481237f23e64ae7Adam Powell        if (mActionBarView == null) return;
272310849abb1a0763ea9912b59187f0a4271efaa2eAdam Powell
273635c21b06194cd1b426d1936e7fdf7db34b5bb98Adam Powell        int nonTabMaxHeight = 0;
274635c21b06194cd1b426d1936e7fdf7db34b5bb98Adam Powell        final int childCount = getChildCount();
275635c21b06194cd1b426d1936e7fdf7db34b5bb98Adam Powell        for (int i = 0; i < childCount; i++) {
276635c21b06194cd1b426d1936e7fdf7db34b5bb98Adam Powell            final View child = getChildAt(i);
277a12aaa75df2a7611f38050e2111a767a20a91b1bAdam Powell            if (child == mTabContainer) {
278a12aaa75df2a7611f38050e2111a767a20a91b1bAdam Powell                continue;
279a12aaa75df2a7611f38050e2111a767a20a91b1bAdam Powell            }
280635c21b06194cd1b426d1936e7fdf7db34b5bb98Adam Powell            final LayoutParams lp = (LayoutParams) child.getLayoutParams();
2812b7ff72683b71e87c327eb781dfbcc5d6fb5c9f9Adam Powell            nonTabMaxHeight = Math.max(nonTabMaxHeight, isCollapsed(child) ? 0 :
2822b7ff72683b71e87c327eb781dfbcc5d6fb5c9f9Adam Powell                    child.getMeasuredHeight() + lp.topMargin + lp.bottomMargin);
283635c21b06194cd1b426d1936e7fdf7db34b5bb98Adam Powell        }
284d21aa12e8eb9d46ee92bf408b4b48386c6bf062dAdam Powell
285dae7824c4b78d02159c6ad0896f246942d7b3d8cAdam Powell        if (mTabContainer != null && mTabContainer.getVisibility() != GONE) {
286dae7824c4b78d02159c6ad0896f246942d7b3d8cAdam Powell            final int mode = MeasureSpec.getMode(heightMeasureSpec);
287dae7824c4b78d02159c6ad0896f246942d7b3d8cAdam Powell            if (mode == MeasureSpec.AT_MOST) {
288dae7824c4b78d02159c6ad0896f246942d7b3d8cAdam Powell                final int maxHeight = MeasureSpec.getSize(heightMeasureSpec);
289dae7824c4b78d02159c6ad0896f246942d7b3d8cAdam Powell                setMeasuredDimension(getMeasuredWidth(),
290635c21b06194cd1b426d1936e7fdf7db34b5bb98Adam Powell                        Math.min(nonTabMaxHeight + mTabContainer.getMeasuredHeight(),
291f6ce6a9bacbb220c6ea7b552c481237f23e64ae7Adam Powell                                maxHeight));
292dae7824c4b78d02159c6ad0896f246942d7b3d8cAdam Powell            }
293dae7824c4b78d02159c6ad0896f246942d7b3d8cAdam Powell        }
294dae7824c4b78d02159c6ad0896f246942d7b3d8cAdam Powell    }
295dae7824c4b78d02159c6ad0896f246942d7b3d8cAdam Powell
296dae7824c4b78d02159c6ad0896f246942d7b3d8cAdam Powell    @Override
297dae7824c4b78d02159c6ad0896f246942d7b3d8cAdam Powell    public void onLayout(boolean changed, int l, int t, int r, int b) {
298dae7824c4b78d02159c6ad0896f246942d7b3d8cAdam Powell        super.onLayout(changed, l, t, r, b);
299a72ef62e5c329a19eab9935acba816fc1369c637Adam Powell
3007f610fed107b158c144dca1b20a44ee91eb8c934Alan Viverette        final View tabContainer = mTabContainer;
3017f610fed107b158c144dca1b20a44ee91eb8c934Alan Viverette        final boolean hasTabs = tabContainer != null && tabContainer.getVisibility() != GONE;
302a72ef62e5c329a19eab9935acba816fc1369c637Adam Powell
3037f610fed107b158c144dca1b20a44ee91eb8c934Alan Viverette        if (tabContainer != null && tabContainer.getVisibility() != GONE) {
304dae7824c4b78d02159c6ad0896f246942d7b3d8cAdam Powell            final int containerHeight = getMeasuredHeight();
3057f610fed107b158c144dca1b20a44ee91eb8c934Alan Viverette            final int tabHeight = tabContainer.getMeasuredHeight();
3067f610fed107b158c144dca1b20a44ee91eb8c934Alan Viverette            tabContainer.layout(l, containerHeight - tabHeight, r, containerHeight);
307dae7824c4b78d02159c6ad0896f246942d7b3d8cAdam Powell        }
308a72ef62e5c329a19eab9935acba816fc1369c637Adam Powell
309a72ef62e5c329a19eab9935acba816fc1369c637Adam Powell        boolean needsInvalidate = false;
310a72ef62e5c329a19eab9935acba816fc1369c637Adam Powell        if (mIsSplit) {
311a72ef62e5c329a19eab9935acba816fc1369c637Adam Powell            if (mSplitBackground != null) {
312a72ef62e5c329a19eab9935acba816fc1369c637Adam Powell                mSplitBackground.setBounds(0, 0, getMeasuredWidth(), getMeasuredHeight());
313a72ef62e5c329a19eab9935acba816fc1369c637Adam Powell                needsInvalidate = true;
314a72ef62e5c329a19eab9935acba816fc1369c637Adam Powell            }
315a72ef62e5c329a19eab9935acba816fc1369c637Adam Powell        } else {
316a72ef62e5c329a19eab9935acba816fc1369c637Adam Powell            if (mBackground != null) {
317ccd3da23c6dbdda2af5c5d746652e4b240cb4f50Chet Haase                if (mActionBarView.getVisibility() == View.VISIBLE) {
318ccd3da23c6dbdda2af5c5d746652e4b240cb4f50Chet Haase                    mBackground.setBounds(mActionBarView.getLeft(), mActionBarView.getTop(),
319ccd3da23c6dbdda2af5c5d746652e4b240cb4f50Chet Haase                            mActionBarView.getRight(), mActionBarView.getBottom());
320ccd3da23c6dbdda2af5c5d746652e4b240cb4f50Chet Haase                } else if (mActionContextView != null &&
321ccd3da23c6dbdda2af5c5d746652e4b240cb4f50Chet Haase                        mActionContextView.getVisibility() == View.VISIBLE) {
322ccd3da23c6dbdda2af5c5d746652e4b240cb4f50Chet Haase                    mBackground.setBounds(mActionContextView.getLeft(), mActionContextView.getTop(),
323ccd3da23c6dbdda2af5c5d746652e4b240cb4f50Chet Haase                            mActionContextView.getRight(), mActionContextView.getBottom());
324ccd3da23c6dbdda2af5c5d746652e4b240cb4f50Chet Haase                } else {
325ccd3da23c6dbdda2af5c5d746652e4b240cb4f50Chet Haase                    mBackground.setBounds(0, 0, 0, 0);
326ccd3da23c6dbdda2af5c5d746652e4b240cb4f50Chet Haase                }
327a72ef62e5c329a19eab9935acba816fc1369c637Adam Powell                needsInvalidate = true;
328a72ef62e5c329a19eab9935acba816fc1369c637Adam Powell            }
3297f610fed107b158c144dca1b20a44ee91eb8c934Alan Viverette            mIsStacked = hasTabs;
3307f610fed107b158c144dca1b20a44ee91eb8c934Alan Viverette            if (hasTabs && mStackedBackground != null) {
3317f610fed107b158c144dca1b20a44ee91eb8c934Alan Viverette                mStackedBackground.setBounds(tabContainer.getLeft(), tabContainer.getTop(),
3327f610fed107b158c144dca1b20a44ee91eb8c934Alan Viverette                        tabContainer.getRight(), tabContainer.getBottom());
333a72ef62e5c329a19eab9935acba816fc1369c637Adam Powell                needsInvalidate = true;
334a72ef62e5c329a19eab9935acba816fc1369c637Adam Powell            }
335a72ef62e5c329a19eab9935acba816fc1369c637Adam Powell        }
336a72ef62e5c329a19eab9935acba816fc1369c637Adam Powell
337a72ef62e5c329a19eab9935acba816fc1369c637Adam Powell        if (needsInvalidate) {
338a72ef62e5c329a19eab9935acba816fc1369c637Adam Powell            invalidate();
339a72ef62e5c329a19eab9935acba816fc1369c637Adam Powell        }
340dae7824c4b78d02159c6ad0896f246942d7b3d8cAdam Powell    }
3417f610fed107b158c144dca1b20a44ee91eb8c934Alan Viverette
3427f610fed107b158c144dca1b20a44ee91eb8c934Alan Viverette    /**
3437f610fed107b158c144dca1b20a44ee91eb8c934Alan Viverette     * Dummy drawable so that we don't break background display lists and
3447f610fed107b158c144dca1b20a44ee91eb8c934Alan Viverette     * projection surfaces.
3457f610fed107b158c144dca1b20a44ee91eb8c934Alan Viverette     */
3467f610fed107b158c144dca1b20a44ee91eb8c934Alan Viverette    private class ActionBarBackgroundDrawable extends Drawable {
3471e610d479f091f1b09f2a7e5201711bf4d311f6fChris Craik        @Override
3481e610d479f091f1b09f2a7e5201711bf4d311f6fChris Craik        public void draw(Canvas canvas) {
3497f610fed107b158c144dca1b20a44ee91eb8c934Alan Viverette            if (mIsSplit) {
35077b5cad3efedd20f2b7cc14d87ccce1b0261960aChris Craik                if (mSplitBackground != null) {
3511e610d479f091f1b09f2a7e5201711bf4d311f6fChris Craik                    mSplitBackground.draw(canvas);
35277b5cad3efedd20f2b7cc14d87ccce1b0261960aChris Craik                }
3537f610fed107b158c144dca1b20a44ee91eb8c934Alan Viverette            } else {
3547f610fed107b158c144dca1b20a44ee91eb8c934Alan Viverette                if (mBackground != null) {
3551e610d479f091f1b09f2a7e5201711bf4d311f6fChris Craik                    mBackground.draw(canvas);
3567f610fed107b158c144dca1b20a44ee91eb8c934Alan Viverette                }
3577f610fed107b158c144dca1b20a44ee91eb8c934Alan Viverette                if (mStackedBackground != null && mIsStacked) {
3581e610d479f091f1b09f2a7e5201711bf4d311f6fChris Craik                    mStackedBackground.draw(canvas);
3597f610fed107b158c144dca1b20a44ee91eb8c934Alan Viverette                }
3607f610fed107b158c144dca1b20a44ee91eb8c934Alan Viverette            }
36177b5cad3efedd20f2b7cc14d87ccce1b0261960aChris Craik        }
36277b5cad3efedd20f2b7cc14d87ccce1b0261960aChris Craik
36377b5cad3efedd20f2b7cc14d87ccce1b0261960aChris Craik        @Override
36477b5cad3efedd20f2b7cc14d87ccce1b0261960aChris Craik        public void getOutline(@NonNull Outline outline) {
3651e610d479f091f1b09f2a7e5201711bf4d311f6fChris Craik            if (mIsSplit) {
3661e610d479f091f1b09f2a7e5201711bf4d311f6fChris Craik                if (mSplitBackground != null) {
3671e610d479f091f1b09f2a7e5201711bf4d311f6fChris Craik                    mSplitBackground.getOutline(outline);
3681e610d479f091f1b09f2a7e5201711bf4d311f6fChris Craik                }
3691e610d479f091f1b09f2a7e5201711bf4d311f6fChris Craik            } else {
3701e610d479f091f1b09f2a7e5201711bf4d311f6fChris Craik                // ignore the stacked background for shadow casting
3711e610d479f091f1b09f2a7e5201711bf4d311f6fChris Craik                if (mBackground != null) {
3721e610d479f091f1b09f2a7e5201711bf4d311f6fChris Craik                    mBackground.getOutline(outline);
3731e610d479f091f1b09f2a7e5201711bf4d311f6fChris Craik                }
37477b5cad3efedd20f2b7cc14d87ccce1b0261960aChris Craik            }
3757f610fed107b158c144dca1b20a44ee91eb8c934Alan Viverette        }
3767f610fed107b158c144dca1b20a44ee91eb8c934Alan Viverette
3777f610fed107b158c144dca1b20a44ee91eb8c934Alan Viverette        @Override
3787f610fed107b158c144dca1b20a44ee91eb8c934Alan Viverette        public void setAlpha(int alpha) {
3797f610fed107b158c144dca1b20a44ee91eb8c934Alan Viverette        }
3807f610fed107b158c144dca1b20a44ee91eb8c934Alan Viverette
3817f610fed107b158c144dca1b20a44ee91eb8c934Alan Viverette        @Override
3827f610fed107b158c144dca1b20a44ee91eb8c934Alan Viverette        public void setColorFilter(ColorFilter cf) {
3837f610fed107b158c144dca1b20a44ee91eb8c934Alan Viverette        }
3847f610fed107b158c144dca1b20a44ee91eb8c934Alan Viverette
3857f610fed107b158c144dca1b20a44ee91eb8c934Alan Viverette        @Override
3867f610fed107b158c144dca1b20a44ee91eb8c934Alan Viverette        public int getOpacity() {
3877f610fed107b158c144dca1b20a44ee91eb8c934Alan Viverette            return 0;
3887f610fed107b158c144dca1b20a44ee91eb8c934Alan Viverette        }
3897f610fed107b158c144dca1b20a44ee91eb8c934Alan Viverette    }
39045f1e08c348ccb129bcc25e438c05421f7123f41Adam Powell}
391