ActionBarContainer.java revision bd3bfc5285dcacff0a69fecf3baeeeb90d887a58
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;
25f849a5e16d016fb6ae081a4575ce67f4ce688e3aAdam Powellimport android.graphics.PixelFormat;
2641fceb462b6eefbaa3a4d4e56b962fdb2910a6f5Svetoslavimport android.graphics.RectF;
27a72ef62e5c329a19eab9935acba816fc1369c637Adam Powellimport android.graphics.drawable.Drawable;
2845f1e08c348ccb129bcc25e438c05421f7123f41Adam Powellimport android.util.AttributeSet;
29640a66eac612b850b5dabd3b93bd94f83ed2d567Adam Powellimport android.view.ActionMode;
306ecf3d1690789ace1a667093ad6bbdd6cd35bda7Adam Powellimport android.view.MotionEvent;
31dae7824c4b78d02159c6ad0896f246942d7b3d8cAdam Powellimport android.view.View;
32af6b97ebe0e6a67d1691c4d7789c7bc312c1e13eAdam Powellimport android.view.ViewGroup;
3345f1e08c348ccb129bcc25e438c05421f7123f41Adam Powellimport android.widget.FrameLayout;
3445f1e08c348ccb129bcc25e438c05421f7123f41Adam Powell
3541fceb462b6eefbaa3a4d4e56b962fdb2910a6f5Svetoslavimport java.util.List;
3641fceb462b6eefbaa3a4d4e56b962fdb2910a6f5Svetoslav
3745f1e08c348ccb129bcc25e438c05421f7123f41Adam Powell/**
3845f1e08c348ccb129bcc25e438c05421f7123f41Adam Powell * This class acts as a container for the action bar view and action mode context views.
3945f1e08c348ccb129bcc25e438c05421f7123f41Adam Powell * It applies special styles as needed to help handle animated transitions between them.
4045f1e08c348ccb129bcc25e438c05421f7123f41Adam Powell * @hide
4145f1e08c348ccb129bcc25e438c05421f7123f41Adam Powell */
4245f1e08c348ccb129bcc25e438c05421f7123f41Adam Powellpublic class ActionBarContainer extends FrameLayout {
4301feaee3d9767ef1185783877e92244f14d7d4baAdam Powell    private boolean mIsTransitioning;
44dae7824c4b78d02159c6ad0896f246942d7b3d8cAdam Powell    private View mTabContainer;
45e021e6ed8931a0a8296af182fc9b0c76b64fb0c4Adam Powell    private View mActionBarView;
46ccd3da23c6dbdda2af5c5d746652e4b240cb4f50Chet Haase    private View mActionContextView;
4701feaee3d9767ef1185783877e92244f14d7d4baAdam Powell
48a72ef62e5c329a19eab9935acba816fc1369c637Adam Powell    private Drawable mBackground;
49a72ef62e5c329a19eab9935acba816fc1369c637Adam Powell    private Drawable mStackedBackground;
50a72ef62e5c329a19eab9935acba816fc1369c637Adam Powell    private Drawable mSplitBackground;
51a72ef62e5c329a19eab9935acba816fc1369c637Adam Powell    private boolean mIsSplit;
52a72ef62e5c329a19eab9935acba816fc1369c637Adam Powell    private boolean mIsStacked;
53e43340c80dc66c45edc793ecd0343774aa34d108Adam Powell    private int mHeight;
54a72ef62e5c329a19eab9935acba816fc1369c637Adam Powell
5545f1e08c348ccb129bcc25e438c05421f7123f41Adam Powell    public ActionBarContainer(Context context) {
5645f1e08c348ccb129bcc25e438c05421f7123f41Adam Powell        this(context, null);
5745f1e08c348ccb129bcc25e438c05421f7123f41Adam Powell    }
5845f1e08c348ccb129bcc25e438c05421f7123f41Adam Powell
5945f1e08c348ccb129bcc25e438c05421f7123f41Adam Powell    public ActionBarContainer(Context context, AttributeSet attrs) {
6045f1e08c348ccb129bcc25e438c05421f7123f41Adam Powell        super(context, attrs);
6145f1e08c348ccb129bcc25e438c05421f7123f41Adam Powell
627f610fed107b158c144dca1b20a44ee91eb8c934Alan Viverette        // Set a transparent background so that we project appropriately.
637f610fed107b158c144dca1b20a44ee91eb8c934Alan Viverette        setBackground(new ActionBarBackgroundDrawable());
64a72ef62e5c329a19eab9935acba816fc1369c637Adam Powell
6545f1e08c348ccb129bcc25e438c05421f7123f41Adam Powell        TypedArray a = context.obtainStyledAttributes(attrs,
6645f1e08c348ccb129bcc25e438c05421f7123f41Adam Powell                com.android.internal.R.styleable.ActionBar);
67a72ef62e5c329a19eab9935acba816fc1369c637Adam Powell        mBackground = a.getDrawable(com.android.internal.R.styleable.ActionBar_background);
68a72ef62e5c329a19eab9935acba816fc1369c637Adam Powell        mStackedBackground = a.getDrawable(
69a72ef62e5c329a19eab9935acba816fc1369c637Adam Powell                com.android.internal.R.styleable.ActionBar_backgroundStacked);
70e43340c80dc66c45edc793ecd0343774aa34d108Adam Powell        mHeight = a.getDimensionPixelSize(com.android.internal.R.styleable.ActionBar_height, -1);
71a72ef62e5c329a19eab9935acba816fc1369c637Adam Powell
72a72ef62e5c329a19eab9935acba816fc1369c637Adam Powell        if (getId() == com.android.internal.R.id.split_action_bar) {
73a72ef62e5c329a19eab9935acba816fc1369c637Adam Powell            mIsSplit = true;
74a72ef62e5c329a19eab9935acba816fc1369c637Adam Powell            mSplitBackground = a.getDrawable(
75a72ef62e5c329a19eab9935acba816fc1369c637Adam Powell                    com.android.internal.R.styleable.ActionBar_backgroundSplit);
76a72ef62e5c329a19eab9935acba816fc1369c637Adam Powell        }
7745f1e08c348ccb129bcc25e438c05421f7123f41Adam Powell        a.recycle();
78a72ef62e5c329a19eab9935acba816fc1369c637Adam Powell
79a72ef62e5c329a19eab9935acba816fc1369c637Adam Powell        setWillNotDraw(mIsSplit ? mSplitBackground == null :
80a72ef62e5c329a19eab9935acba816fc1369c637Adam Powell                mBackground == null && mStackedBackground == null);
8145f1e08c348ccb129bcc25e438c05421f7123f41Adam Powell    }
826ecf3d1690789ace1a667093ad6bbdd6cd35bda7Adam Powell
83310849abb1a0763ea9912b59187f0a4271efaa2eAdam Powell    @Override
84310849abb1a0763ea9912b59187f0a4271efaa2eAdam Powell    public void onFinishInflate() {
85310849abb1a0763ea9912b59187f0a4271efaa2eAdam Powell        super.onFinishInflate();
86e021e6ed8931a0a8296af182fc9b0c76b64fb0c4Adam Powell        mActionBarView = findViewById(com.android.internal.R.id.action_bar);
87ccd3da23c6dbdda2af5c5d746652e4b240cb4f50Chet Haase        mActionContextView = findViewById(com.android.internal.R.id.action_context_bar);
88310849abb1a0763ea9912b59187f0a4271efaa2eAdam Powell    }
89310849abb1a0763ea9912b59187f0a4271efaa2eAdam Powell
90f88b915567a37c481c4c50a6cc57e1ec0e7cf50dAdam Powell    public void setPrimaryBackground(Drawable bg) {
91a7cc06d82e45918c37429a59b14545c6a57db4e4Adam Powell        if (mBackground != null) {
92a7cc06d82e45918c37429a59b14545c6a57db4e4Adam Powell            mBackground.setCallback(null);
93a7cc06d82e45918c37429a59b14545c6a57db4e4Adam Powell            unscheduleDrawable(mBackground);
94a7cc06d82e45918c37429a59b14545c6a57db4e4Adam Powell        }
95f88b915567a37c481c4c50a6cc57e1ec0e7cf50dAdam Powell        mBackground = bg;
96a7cc06d82e45918c37429a59b14545c6a57db4e4Adam Powell        if (bg != null) {
97a7cc06d82e45918c37429a59b14545c6a57db4e4Adam Powell            bg.setCallback(this);
98e8c8ae401b6f0d894a766a1601f55f0fe567df02Adam Powell            if (mActionBarView != null) {
99e8c8ae401b6f0d894a766a1601f55f0fe567df02Adam Powell                mBackground.setBounds(mActionBarView.getLeft(), mActionBarView.getTop(),
100e8c8ae401b6f0d894a766a1601f55f0fe567df02Adam Powell                        mActionBarView.getRight(), mActionBarView.getBottom());
101e8c8ae401b6f0d894a766a1601f55f0fe567df02Adam Powell            }
102a7cc06d82e45918c37429a59b14545c6a57db4e4Adam Powell        }
103a7cc06d82e45918c37429a59b14545c6a57db4e4Adam Powell        setWillNotDraw(mIsSplit ? mSplitBackground == null :
104a7cc06d82e45918c37429a59b14545c6a57db4e4Adam Powell                mBackground == null && mStackedBackground == null);
105f88b915567a37c481c4c50a6cc57e1ec0e7cf50dAdam Powell        invalidate();
106f88b915567a37c481c4c50a6cc57e1ec0e7cf50dAdam Powell    }
107f88b915567a37c481c4c50a6cc57e1ec0e7cf50dAdam Powell
108f88b915567a37c481c4c50a6cc57e1ec0e7cf50dAdam Powell    public void setStackedBackground(Drawable bg) {
109a7cc06d82e45918c37429a59b14545c6a57db4e4Adam Powell        if (mStackedBackground != null) {
110a7cc06d82e45918c37429a59b14545c6a57db4e4Adam Powell            mStackedBackground.setCallback(null);
111a7cc06d82e45918c37429a59b14545c6a57db4e4Adam Powell            unscheduleDrawable(mStackedBackground);
112a7cc06d82e45918c37429a59b14545c6a57db4e4Adam Powell        }
113f88b915567a37c481c4c50a6cc57e1ec0e7cf50dAdam Powell        mStackedBackground = bg;
114a7cc06d82e45918c37429a59b14545c6a57db4e4Adam Powell        if (bg != null) {
115a7cc06d82e45918c37429a59b14545c6a57db4e4Adam Powell            bg.setCallback(this);
116e8c8ae401b6f0d894a766a1601f55f0fe567df02Adam Powell            if ((mIsStacked && mStackedBackground != null)) {
117e8c8ae401b6f0d894a766a1601f55f0fe567df02Adam Powell                mStackedBackground.setBounds(mTabContainer.getLeft(), mTabContainer.getTop(),
118e8c8ae401b6f0d894a766a1601f55f0fe567df02Adam Powell                        mTabContainer.getRight(), mTabContainer.getBottom());
119e8c8ae401b6f0d894a766a1601f55f0fe567df02Adam Powell            }
120a7cc06d82e45918c37429a59b14545c6a57db4e4Adam Powell        }
121a7cc06d82e45918c37429a59b14545c6a57db4e4Adam Powell        setWillNotDraw(mIsSplit ? mSplitBackground == null :
122a7cc06d82e45918c37429a59b14545c6a57db4e4Adam Powell                mBackground == null && mStackedBackground == null);
123f88b915567a37c481c4c50a6cc57e1ec0e7cf50dAdam Powell        invalidate();
124f88b915567a37c481c4c50a6cc57e1ec0e7cf50dAdam Powell    }
125f88b915567a37c481c4c50a6cc57e1ec0e7cf50dAdam Powell
126f88b915567a37c481c4c50a6cc57e1ec0e7cf50dAdam Powell    public void setSplitBackground(Drawable bg) {
127a7cc06d82e45918c37429a59b14545c6a57db4e4Adam Powell        if (mSplitBackground != null) {
128a7cc06d82e45918c37429a59b14545c6a57db4e4Adam Powell            mSplitBackground.setCallback(null);
129a7cc06d82e45918c37429a59b14545c6a57db4e4Adam Powell            unscheduleDrawable(mSplitBackground);
130a7cc06d82e45918c37429a59b14545c6a57db4e4Adam Powell        }
131f88b915567a37c481c4c50a6cc57e1ec0e7cf50dAdam Powell        mSplitBackground = bg;
132a7cc06d82e45918c37429a59b14545c6a57db4e4Adam Powell        if (bg != null) {
133a7cc06d82e45918c37429a59b14545c6a57db4e4Adam Powell            bg.setCallback(this);
134e8c8ae401b6f0d894a766a1601f55f0fe567df02Adam Powell            if (mIsSplit && mSplitBackground != null) {
135e8c8ae401b6f0d894a766a1601f55f0fe567df02Adam Powell                mSplitBackground.setBounds(0, 0, getMeasuredWidth(), getMeasuredHeight());
136e8c8ae401b6f0d894a766a1601f55f0fe567df02Adam Powell            }
137a7cc06d82e45918c37429a59b14545c6a57db4e4Adam Powell        }
138a7cc06d82e45918c37429a59b14545c6a57db4e4Adam Powell        setWillNotDraw(mIsSplit ? mSplitBackground == null :
139a7cc06d82e45918c37429a59b14545c6a57db4e4Adam Powell                mBackground == null && mStackedBackground == null);
140f88b915567a37c481c4c50a6cc57e1ec0e7cf50dAdam Powell        invalidate();
141f88b915567a37c481c4c50a6cc57e1ec0e7cf50dAdam Powell    }
142f88b915567a37c481c4c50a6cc57e1ec0e7cf50dAdam Powell
143a7cc06d82e45918c37429a59b14545c6a57db4e4Adam Powell    @Override
144a7cc06d82e45918c37429a59b14545c6a57db4e4Adam Powell    public void setVisibility(int visibility) {
145a7cc06d82e45918c37429a59b14545c6a57db4e4Adam Powell        super.setVisibility(visibility);
146a7cc06d82e45918c37429a59b14545c6a57db4e4Adam Powell        final boolean isVisible = visibility == VISIBLE;
147a7cc06d82e45918c37429a59b14545c6a57db4e4Adam Powell        if (mBackground != null) mBackground.setVisible(isVisible, false);
148a7cc06d82e45918c37429a59b14545c6a57db4e4Adam Powell        if (mStackedBackground != null) mStackedBackground.setVisible(isVisible, false);
149a7cc06d82e45918c37429a59b14545c6a57db4e4Adam Powell        if (mSplitBackground != null) mSplitBackground.setVisible(isVisible, false);
150a7cc06d82e45918c37429a59b14545c6a57db4e4Adam Powell    }
151a7cc06d82e45918c37429a59b14545c6a57db4e4Adam Powell
152a7cc06d82e45918c37429a59b14545c6a57db4e4Adam Powell    @Override
153a7cc06d82e45918c37429a59b14545c6a57db4e4Adam Powell    protected boolean verifyDrawable(Drawable who) {
154a7cc06d82e45918c37429a59b14545c6a57db4e4Adam Powell        return (who == mBackground && !mIsSplit) || (who == mStackedBackground && mIsStacked) ||
155a7cc06d82e45918c37429a59b14545c6a57db4e4Adam Powell                (who == mSplitBackground && mIsSplit) || super.verifyDrawable(who);
156a7cc06d82e45918c37429a59b14545c6a57db4e4Adam Powell    }
157a7cc06d82e45918c37429a59b14545c6a57db4e4Adam Powell
158a7cc06d82e45918c37429a59b14545c6a57db4e4Adam Powell    @Override
159a7cc06d82e45918c37429a59b14545c6a57db4e4Adam Powell    protected void drawableStateChanged() {
160a7cc06d82e45918c37429a59b14545c6a57db4e4Adam Powell        super.drawableStateChanged();
161a7cc06d82e45918c37429a59b14545c6a57db4e4Adam Powell        if (mBackground != null && mBackground.isStateful()) {
162a7cc06d82e45918c37429a59b14545c6a57db4e4Adam Powell            mBackground.setState(getDrawableState());
163a7cc06d82e45918c37429a59b14545c6a57db4e4Adam Powell        }
164a7cc06d82e45918c37429a59b14545c6a57db4e4Adam Powell        if (mStackedBackground != null && mStackedBackground.isStateful()) {
165a7cc06d82e45918c37429a59b14545c6a57db4e4Adam Powell            mStackedBackground.setState(getDrawableState());
166a7cc06d82e45918c37429a59b14545c6a57db4e4Adam Powell        }
167a7cc06d82e45918c37429a59b14545c6a57db4e4Adam Powell        if (mSplitBackground != null && mSplitBackground.isStateful()) {
168a7cc06d82e45918c37429a59b14545c6a57db4e4Adam Powell            mSplitBackground.setState(getDrawableState());
169a7cc06d82e45918c37429a59b14545c6a57db4e4Adam Powell        }
170a7cc06d82e45918c37429a59b14545c6a57db4e4Adam Powell    }
171a7cc06d82e45918c37429a59b14545c6a57db4e4Adam Powell
172a7cc06d82e45918c37429a59b14545c6a57db4e4Adam Powell    @Override
173a7cc06d82e45918c37429a59b14545c6a57db4e4Adam Powell    public void jumpDrawablesToCurrentState() {
174a7cc06d82e45918c37429a59b14545c6a57db4e4Adam Powell        super.jumpDrawablesToCurrentState();
175a7cc06d82e45918c37429a59b14545c6a57db4e4Adam Powell        if (mBackground != null) {
176a7cc06d82e45918c37429a59b14545c6a57db4e4Adam Powell            mBackground.jumpToCurrentState();
177a7cc06d82e45918c37429a59b14545c6a57db4e4Adam Powell        }
178a7cc06d82e45918c37429a59b14545c6a57db4e4Adam Powell        if (mStackedBackground != null) {
179a7cc06d82e45918c37429a59b14545c6a57db4e4Adam Powell            mStackedBackground.jumpToCurrentState();
180a7cc06d82e45918c37429a59b14545c6a57db4e4Adam Powell        }
181a7cc06d82e45918c37429a59b14545c6a57db4e4Adam Powell        if (mSplitBackground != null) {
182a7cc06d82e45918c37429a59b14545c6a57db4e4Adam Powell            mSplitBackground.jumpToCurrentState();
183a7cc06d82e45918c37429a59b14545c6a57db4e4Adam Powell        }
184a7cc06d82e45918c37429a59b14545c6a57db4e4Adam Powell    }
185a7cc06d82e45918c37429a59b14545c6a57db4e4Adam Powell
1864457e85a7090ad51726d50a4daf981d917cceeddFabrice Di Meglio    /**
1874457e85a7090ad51726d50a4daf981d917cceeddFabrice Di Meglio     * @hide
1884457e85a7090ad51726d50a4daf981d917cceeddFabrice Di Meglio     */
189a7cc06d82e45918c37429a59b14545c6a57db4e4Adam Powell    @Override
190a7cc06d82e45918c37429a59b14545c6a57db4e4Adam Powell    public void onResolveDrawables(int layoutDirection) {
191a7cc06d82e45918c37429a59b14545c6a57db4e4Adam Powell        super.onResolveDrawables(layoutDirection);
192a7cc06d82e45918c37429a59b14545c6a57db4e4Adam Powell        if (mBackground != null) {
193a7cc06d82e45918c37429a59b14545c6a57db4e4Adam Powell            mBackground.setLayoutDirection(layoutDirection);
194a7cc06d82e45918c37429a59b14545c6a57db4e4Adam Powell        }
195a7cc06d82e45918c37429a59b14545c6a57db4e4Adam Powell        if (mStackedBackground != null) {
196a7cc06d82e45918c37429a59b14545c6a57db4e4Adam Powell            mStackedBackground.setLayoutDirection(layoutDirection);
197a7cc06d82e45918c37429a59b14545c6a57db4e4Adam Powell        }
198a7cc06d82e45918c37429a59b14545c6a57db4e4Adam Powell        if (mSplitBackground != null) {
199a7cc06d82e45918c37429a59b14545c6a57db4e4Adam Powell            mSplitBackground.setLayoutDirection(layoutDirection);
200a7cc06d82e45918c37429a59b14545c6a57db4e4Adam Powell        }
201a7cc06d82e45918c37429a59b14545c6a57db4e4Adam Powell    }
202a7cc06d82e45918c37429a59b14545c6a57db4e4Adam Powell
20301feaee3d9767ef1185783877e92244f14d7d4baAdam Powell    /**
20401feaee3d9767ef1185783877e92244f14d7d4baAdam Powell     * Set the action bar into a "transitioning" state. While transitioning
20501feaee3d9767ef1185783877e92244f14d7d4baAdam Powell     * the bar will block focus and touch from all of its descendants. This
20601feaee3d9767ef1185783877e92244f14d7d4baAdam Powell     * prevents the user from interacting with the bar while it is animating
20701feaee3d9767ef1185783877e92244f14d7d4baAdam Powell     * in or out.
20801feaee3d9767ef1185783877e92244f14d7d4baAdam Powell     *
20901feaee3d9767ef1185783877e92244f14d7d4baAdam Powell     * @param isTransitioning true if the bar is currently transitioning, false otherwise.
21001feaee3d9767ef1185783877e92244f14d7d4baAdam Powell     */
21101feaee3d9767ef1185783877e92244f14d7d4baAdam Powell    public void setTransitioning(boolean isTransitioning) {
21201feaee3d9767ef1185783877e92244f14d7d4baAdam Powell        mIsTransitioning = isTransitioning;
21301feaee3d9767ef1185783877e92244f14d7d4baAdam Powell        setDescendantFocusability(isTransitioning ? FOCUS_BLOCK_DESCENDANTS
21401feaee3d9767ef1185783877e92244f14d7d4baAdam Powell                : FOCUS_AFTER_DESCENDANTS);
21501feaee3d9767ef1185783877e92244f14d7d4baAdam Powell    }
21601feaee3d9767ef1185783877e92244f14d7d4baAdam Powell
21701feaee3d9767ef1185783877e92244f14d7d4baAdam Powell    @Override
21801feaee3d9767ef1185783877e92244f14d7d4baAdam Powell    public boolean onInterceptTouchEvent(MotionEvent ev) {
21901feaee3d9767ef1185783877e92244f14d7d4baAdam Powell        return mIsTransitioning || super.onInterceptTouchEvent(ev);
22001feaee3d9767ef1185783877e92244f14d7d4baAdam Powell    }
22101feaee3d9767ef1185783877e92244f14d7d4baAdam Powell
2226ecf3d1690789ace1a667093ad6bbdd6cd35bda7Adam Powell    @Override
2236ecf3d1690789ace1a667093ad6bbdd6cd35bda7Adam Powell    public boolean onTouchEvent(MotionEvent ev) {
2246ecf3d1690789ace1a667093ad6bbdd6cd35bda7Adam Powell        super.onTouchEvent(ev);
225dae7824c4b78d02159c6ad0896f246942d7b3d8cAdam Powell
226dae7824c4b78d02159c6ad0896f246942d7b3d8cAdam Powell        // An action bar always eats touch events.
2276ecf3d1690789ace1a667093ad6bbdd6cd35bda7Adam Powell        return true;
2286ecf3d1690789ace1a667093ad6bbdd6cd35bda7Adam Powell    }
229dae7824c4b78d02159c6ad0896f246942d7b3d8cAdam Powell
2307d09f04363cdda6a3cf8b2ad1b67c9a07fa8975fAdam Powell    @Override
2317d09f04363cdda6a3cf8b2ad1b67c9a07fa8975fAdam Powell    public boolean onHoverEvent(MotionEvent ev) {
2327d09f04363cdda6a3cf8b2ad1b67c9a07fa8975fAdam Powell        super.onHoverEvent(ev);
2337d09f04363cdda6a3cf8b2ad1b67c9a07fa8975fAdam Powell
2347d09f04363cdda6a3cf8b2ad1b67c9a07fa8975fAdam Powell        // An action bar always eats hover events.
2357d09f04363cdda6a3cf8b2ad1b67c9a07fa8975fAdam Powell        return true;
2367d09f04363cdda6a3cf8b2ad1b67c9a07fa8975fAdam Powell    }
2377d09f04363cdda6a3cf8b2ad1b67c9a07fa8975fAdam Powell
238f5645cbafe7eed33452d888f16726bee8a0cd9feAdam Powell    public void setTabContainer(ScrollingTabContainerView tabView) {
239dae7824c4b78d02159c6ad0896f246942d7b3d8cAdam Powell        if (mTabContainer != null) {
240dae7824c4b78d02159c6ad0896f246942d7b3d8cAdam Powell            removeView(mTabContainer);
241dae7824c4b78d02159c6ad0896f246942d7b3d8cAdam Powell        }
242dae7824c4b78d02159c6ad0896f246942d7b3d8cAdam Powell        mTabContainer = tabView;
24325151e4792e9be8dbb892b7eba7349773b8127afAdam Powell        if (tabView != null) {
24425151e4792e9be8dbb892b7eba7349773b8127afAdam Powell            addView(tabView);
245af6b97ebe0e6a67d1691c4d7789c7bc312c1e13eAdam Powell            final ViewGroup.LayoutParams lp = tabView.getLayoutParams();
246af6b97ebe0e6a67d1691c4d7789c7bc312c1e13eAdam Powell            lp.width = LayoutParams.MATCH_PARENT;
247af6b97ebe0e6a67d1691c4d7789c7bc312c1e13eAdam Powell            lp.height = LayoutParams.WRAP_CONTENT;
248f5645cbafe7eed33452d888f16726bee8a0cd9feAdam Powell            tabView.setAllowCollapse(false);
24925151e4792e9be8dbb892b7eba7349773b8127afAdam Powell        }
250dae7824c4b78d02159c6ad0896f246942d7b3d8cAdam Powell    }
251dae7824c4b78d02159c6ad0896f246942d7b3d8cAdam Powell
252dae7824c4b78d02159c6ad0896f246942d7b3d8cAdam Powell    public View getTabContainer() {
253dae7824c4b78d02159c6ad0896f246942d7b3d8cAdam Powell        return mTabContainer;
254dae7824c4b78d02159c6ad0896f246942d7b3d8cAdam Powell    }
255dae7824c4b78d02159c6ad0896f246942d7b3d8cAdam Powell
256dae7824c4b78d02159c6ad0896f246942d7b3d8cAdam Powell    @Override
257640a66eac612b850b5dabd3b93bd94f83ed2d567Adam Powell    public ActionMode startActionModeForChild(View child, ActionMode.Callback callback) {
258640a66eac612b850b5dabd3b93bd94f83ed2d567Adam Powell        // No starting an action mode for an action bar child! (Where would it go?)
259640a66eac612b850b5dabd3b93bd94f83ed2d567Adam Powell        return null;
260640a66eac612b850b5dabd3b93bd94f83ed2d567Adam Powell    }
261640a66eac612b850b5dabd3b93bd94f83ed2d567Adam Powell
2621e610d479f091f1b09f2a7e5201711bf4d311f6fChris Craik    private static boolean isCollapsed(View view) {
263e021e6ed8931a0a8296af182fc9b0c76b64fb0c4Adam Powell        return view == null || view.getVisibility() == GONE || view.getMeasuredHeight() == 0;
264e021e6ed8931a0a8296af182fc9b0c76b64fb0c4Adam Powell    }
265e021e6ed8931a0a8296af182fc9b0c76b64fb0c4Adam Powell
2662bbad0cddce213ffd3d1e0909f2dc74dd0038ba7Yigit Boyar    private int getMeasuredHeightWithMargins(View view) {
2672bbad0cddce213ffd3d1e0909f2dc74dd0038ba7Yigit Boyar        final LayoutParams lp = (LayoutParams) view.getLayoutParams();
2682bbad0cddce213ffd3d1e0909f2dc74dd0038ba7Yigit Boyar        return view.getMeasuredHeight() + lp.topMargin + lp.bottomMargin;
2692bbad0cddce213ffd3d1e0909f2dc74dd0038ba7Yigit Boyar    }
2702bbad0cddce213ffd3d1e0909f2dc74dd0038ba7Yigit Boyar
271640a66eac612b850b5dabd3b93bd94f83ed2d567Adam Powell    @Override
272dae7824c4b78d02159c6ad0896f246942d7b3d8cAdam Powell    public void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
273e43340c80dc66c45edc793ecd0343774aa34d108Adam Powell        if (mActionBarView == null &&
274e43340c80dc66c45edc793ecd0343774aa34d108Adam Powell                MeasureSpec.getMode(heightMeasureSpec) == MeasureSpec.AT_MOST && mHeight >= 0) {
275e43340c80dc66c45edc793ecd0343774aa34d108Adam Powell            heightMeasureSpec = MeasureSpec.makeMeasureSpec(
276e43340c80dc66c45edc793ecd0343774aa34d108Adam Powell                    Math.min(mHeight, MeasureSpec.getSize(heightMeasureSpec)), MeasureSpec.AT_MOST);
277e43340c80dc66c45edc793ecd0343774aa34d108Adam Powell        }
278dae7824c4b78d02159c6ad0896f246942d7b3d8cAdam Powell        super.onMeasure(widthMeasureSpec, heightMeasureSpec);
279d21aa12e8eb9d46ee92bf408b4b48386c6bf062dAdam Powell
280f6ce6a9bacbb220c6ea7b552c481237f23e64ae7Adam Powell        if (mActionBarView == null) return;
281310849abb1a0763ea9912b59187f0a4271efaa2eAdam Powell
282dae7824c4b78d02159c6ad0896f246942d7b3d8cAdam Powell        if (mTabContainer != null && mTabContainer.getVisibility() != GONE) {
2832bbad0cddce213ffd3d1e0909f2dc74dd0038ba7Yigit Boyar            int nonTabMaxHeight = 0;
2842bbad0cddce213ffd3d1e0909f2dc74dd0038ba7Yigit Boyar            final int childCount = getChildCount();
2852bbad0cddce213ffd3d1e0909f2dc74dd0038ba7Yigit Boyar            for (int i = 0; i < childCount; i++) {
2862bbad0cddce213ffd3d1e0909f2dc74dd0038ba7Yigit Boyar                final View child = getChildAt(i);
2872bbad0cddce213ffd3d1e0909f2dc74dd0038ba7Yigit Boyar                if (child == mTabContainer) {
2882bbad0cddce213ffd3d1e0909f2dc74dd0038ba7Yigit Boyar                    continue;
2892bbad0cddce213ffd3d1e0909f2dc74dd0038ba7Yigit Boyar                }
2902bbad0cddce213ffd3d1e0909f2dc74dd0038ba7Yigit Boyar                nonTabMaxHeight = Math.max(nonTabMaxHeight, isCollapsed(child) ? 0 :
2912bbad0cddce213ffd3d1e0909f2dc74dd0038ba7Yigit Boyar                        getMeasuredHeightWithMargins(child));
292dae7824c4b78d02159c6ad0896f246942d7b3d8cAdam Powell            }
2932bbad0cddce213ffd3d1e0909f2dc74dd0038ba7Yigit Boyar            final int mode = MeasureSpec.getMode(heightMeasureSpec);
2942bbad0cddce213ffd3d1e0909f2dc74dd0038ba7Yigit Boyar            final int maxHeight = mode == MeasureSpec.AT_MOST ?
2952bbad0cddce213ffd3d1e0909f2dc74dd0038ba7Yigit Boyar                    MeasureSpec.getSize(heightMeasureSpec) : Integer.MAX_VALUE;
2962bbad0cddce213ffd3d1e0909f2dc74dd0038ba7Yigit Boyar            setMeasuredDimension(getMeasuredWidth(),
2972bbad0cddce213ffd3d1e0909f2dc74dd0038ba7Yigit Boyar                    Math.min(nonTabMaxHeight + getMeasuredHeightWithMargins(mTabContainer),
2982bbad0cddce213ffd3d1e0909f2dc74dd0038ba7Yigit Boyar                            maxHeight));
299dae7824c4b78d02159c6ad0896f246942d7b3d8cAdam Powell        }
300dae7824c4b78d02159c6ad0896f246942d7b3d8cAdam Powell    }
301dae7824c4b78d02159c6ad0896f246942d7b3d8cAdam Powell
302dae7824c4b78d02159c6ad0896f246942d7b3d8cAdam Powell    @Override
303dae7824c4b78d02159c6ad0896f246942d7b3d8cAdam Powell    public void onLayout(boolean changed, int l, int t, int r, int b) {
304dae7824c4b78d02159c6ad0896f246942d7b3d8cAdam Powell        super.onLayout(changed, l, t, r, b);
305a72ef62e5c329a19eab9935acba816fc1369c637Adam Powell
3067f610fed107b158c144dca1b20a44ee91eb8c934Alan Viverette        final View tabContainer = mTabContainer;
3077f610fed107b158c144dca1b20a44ee91eb8c934Alan Viverette        final boolean hasTabs = tabContainer != null && tabContainer.getVisibility() != GONE;
308a72ef62e5c329a19eab9935acba816fc1369c637Adam Powell
3097f610fed107b158c144dca1b20a44ee91eb8c934Alan Viverette        if (tabContainer != null && tabContainer.getVisibility() != GONE) {
310dae7824c4b78d02159c6ad0896f246942d7b3d8cAdam Powell            final int containerHeight = getMeasuredHeight();
3112bbad0cddce213ffd3d1e0909f2dc74dd0038ba7Yigit Boyar            final LayoutParams lp = (LayoutParams) tabContainer.getLayoutParams();
3127f610fed107b158c144dca1b20a44ee91eb8c934Alan Viverette            final int tabHeight = tabContainer.getMeasuredHeight();
3132bbad0cddce213ffd3d1e0909f2dc74dd0038ba7Yigit Boyar            tabContainer.layout(l, containerHeight - tabHeight - lp.bottomMargin, r,
3142bbad0cddce213ffd3d1e0909f2dc74dd0038ba7Yigit Boyar                    containerHeight - lp.bottomMargin);
315dae7824c4b78d02159c6ad0896f246942d7b3d8cAdam Powell        }
316a72ef62e5c329a19eab9935acba816fc1369c637Adam Powell
317a72ef62e5c329a19eab9935acba816fc1369c637Adam Powell        boolean needsInvalidate = false;
318a72ef62e5c329a19eab9935acba816fc1369c637Adam Powell        if (mIsSplit) {
319a72ef62e5c329a19eab9935acba816fc1369c637Adam Powell            if (mSplitBackground != null) {
320a72ef62e5c329a19eab9935acba816fc1369c637Adam Powell                mSplitBackground.setBounds(0, 0, getMeasuredWidth(), getMeasuredHeight());
321a72ef62e5c329a19eab9935acba816fc1369c637Adam Powell                needsInvalidate = true;
322a72ef62e5c329a19eab9935acba816fc1369c637Adam Powell            }
323a72ef62e5c329a19eab9935acba816fc1369c637Adam Powell        } else {
324a72ef62e5c329a19eab9935acba816fc1369c637Adam Powell            if (mBackground != null) {
325ccd3da23c6dbdda2af5c5d746652e4b240cb4f50Chet Haase                if (mActionBarView.getVisibility() == View.VISIBLE) {
326ccd3da23c6dbdda2af5c5d746652e4b240cb4f50Chet Haase                    mBackground.setBounds(mActionBarView.getLeft(), mActionBarView.getTop(),
327ccd3da23c6dbdda2af5c5d746652e4b240cb4f50Chet Haase                            mActionBarView.getRight(), mActionBarView.getBottom());
328ccd3da23c6dbdda2af5c5d746652e4b240cb4f50Chet Haase                } else if (mActionContextView != null &&
329ccd3da23c6dbdda2af5c5d746652e4b240cb4f50Chet Haase                        mActionContextView.getVisibility() == View.VISIBLE) {
330ccd3da23c6dbdda2af5c5d746652e4b240cb4f50Chet Haase                    mBackground.setBounds(mActionContextView.getLeft(), mActionContextView.getTop(),
331ccd3da23c6dbdda2af5c5d746652e4b240cb4f50Chet Haase                            mActionContextView.getRight(), mActionContextView.getBottom());
332ccd3da23c6dbdda2af5c5d746652e4b240cb4f50Chet Haase                } else {
333ccd3da23c6dbdda2af5c5d746652e4b240cb4f50Chet Haase                    mBackground.setBounds(0, 0, 0, 0);
334ccd3da23c6dbdda2af5c5d746652e4b240cb4f50Chet Haase                }
335a72ef62e5c329a19eab9935acba816fc1369c637Adam Powell                needsInvalidate = true;
336a72ef62e5c329a19eab9935acba816fc1369c637Adam Powell            }
3377f610fed107b158c144dca1b20a44ee91eb8c934Alan Viverette            mIsStacked = hasTabs;
3387f610fed107b158c144dca1b20a44ee91eb8c934Alan Viverette            if (hasTabs && mStackedBackground != null) {
3397f610fed107b158c144dca1b20a44ee91eb8c934Alan Viverette                mStackedBackground.setBounds(tabContainer.getLeft(), tabContainer.getTop(),
3407f610fed107b158c144dca1b20a44ee91eb8c934Alan Viverette                        tabContainer.getRight(), tabContainer.getBottom());
341a72ef62e5c329a19eab9935acba816fc1369c637Adam Powell                needsInvalidate = true;
342a72ef62e5c329a19eab9935acba816fc1369c637Adam Powell            }
343a72ef62e5c329a19eab9935acba816fc1369c637Adam Powell        }
344a72ef62e5c329a19eab9935acba816fc1369c637Adam Powell
345a72ef62e5c329a19eab9935acba816fc1369c637Adam Powell        if (needsInvalidate) {
346a72ef62e5c329a19eab9935acba816fc1369c637Adam Powell            invalidate();
347a72ef62e5c329a19eab9935acba816fc1369c637Adam Powell        }
348dae7824c4b78d02159c6ad0896f246942d7b3d8cAdam Powell    }
3497f610fed107b158c144dca1b20a44ee91eb8c934Alan Viverette
3507f610fed107b158c144dca1b20a44ee91eb8c934Alan Viverette    /**
3517f610fed107b158c144dca1b20a44ee91eb8c934Alan Viverette     * Dummy drawable so that we don't break background display lists and
3527f610fed107b158c144dca1b20a44ee91eb8c934Alan Viverette     * projection surfaces.
3537f610fed107b158c144dca1b20a44ee91eb8c934Alan Viverette     */
3547f610fed107b158c144dca1b20a44ee91eb8c934Alan Viverette    private class ActionBarBackgroundDrawable extends Drawable {
3551e610d479f091f1b09f2a7e5201711bf4d311f6fChris Craik        @Override
3561e610d479f091f1b09f2a7e5201711bf4d311f6fChris Craik        public void draw(Canvas canvas) {
3577f610fed107b158c144dca1b20a44ee91eb8c934Alan Viverette            if (mIsSplit) {
35877b5cad3efedd20f2b7cc14d87ccce1b0261960aChris Craik                if (mSplitBackground != null) {
3591e610d479f091f1b09f2a7e5201711bf4d311f6fChris Craik                    mSplitBackground.draw(canvas);
36077b5cad3efedd20f2b7cc14d87ccce1b0261960aChris Craik                }
3617f610fed107b158c144dca1b20a44ee91eb8c934Alan Viverette            } else {
3627f610fed107b158c144dca1b20a44ee91eb8c934Alan Viverette                if (mBackground != null) {
3631e610d479f091f1b09f2a7e5201711bf4d311f6fChris Craik                    mBackground.draw(canvas);
3647f610fed107b158c144dca1b20a44ee91eb8c934Alan Viverette                }
3657f610fed107b158c144dca1b20a44ee91eb8c934Alan Viverette                if (mStackedBackground != null && mIsStacked) {
3661e610d479f091f1b09f2a7e5201711bf4d311f6fChris Craik                    mStackedBackground.draw(canvas);
3677f610fed107b158c144dca1b20a44ee91eb8c934Alan Viverette                }
3687f610fed107b158c144dca1b20a44ee91eb8c934Alan Viverette            }
36977b5cad3efedd20f2b7cc14d87ccce1b0261960aChris Craik        }
37077b5cad3efedd20f2b7cc14d87ccce1b0261960aChris Craik
37177b5cad3efedd20f2b7cc14d87ccce1b0261960aChris Craik        @Override
37277b5cad3efedd20f2b7cc14d87ccce1b0261960aChris Craik        public void getOutline(@NonNull Outline outline) {
3731e610d479f091f1b09f2a7e5201711bf4d311f6fChris Craik            if (mIsSplit) {
3741e610d479f091f1b09f2a7e5201711bf4d311f6fChris Craik                if (mSplitBackground != null) {
3751e610d479f091f1b09f2a7e5201711bf4d311f6fChris Craik                    mSplitBackground.getOutline(outline);
3761e610d479f091f1b09f2a7e5201711bf4d311f6fChris Craik                }
3771e610d479f091f1b09f2a7e5201711bf4d311f6fChris Craik            } else {
3781e610d479f091f1b09f2a7e5201711bf4d311f6fChris Craik                // ignore the stacked background for shadow casting
3791e610d479f091f1b09f2a7e5201711bf4d311f6fChris Craik                if (mBackground != null) {
3801e610d479f091f1b09f2a7e5201711bf4d311f6fChris Craik                    mBackground.getOutline(outline);
3811e610d479f091f1b09f2a7e5201711bf4d311f6fChris Craik                }
38277b5cad3efedd20f2b7cc14d87ccce1b0261960aChris Craik            }
3837f610fed107b158c144dca1b20a44ee91eb8c934Alan Viverette        }
3847f610fed107b158c144dca1b20a44ee91eb8c934Alan Viverette
3857f610fed107b158c144dca1b20a44ee91eb8c934Alan Viverette        @Override
3867f610fed107b158c144dca1b20a44ee91eb8c934Alan Viverette        public void setAlpha(int alpha) {
3877f610fed107b158c144dca1b20a44ee91eb8c934Alan Viverette        }
3887f610fed107b158c144dca1b20a44ee91eb8c934Alan Viverette
3897f610fed107b158c144dca1b20a44ee91eb8c934Alan Viverette        @Override
390bd3bfc5285dcacff0a69fecf3baeeeb90d887a58Chris Craik        public void setColorFilter(ColorFilter colorFilter) {
3917f610fed107b158c144dca1b20a44ee91eb8c934Alan Viverette        }
3927f610fed107b158c144dca1b20a44ee91eb8c934Alan Viverette
3937f610fed107b158c144dca1b20a44ee91eb8c934Alan Viverette        @Override
3947f610fed107b158c144dca1b20a44ee91eb8c934Alan Viverette        public int getOpacity() {
395f849a5e16d016fb6ae081a4575ce67f4ce688e3aAdam Powell            if (mIsSplit) {
396f849a5e16d016fb6ae081a4575ce67f4ce688e3aAdam Powell                if (mSplitBackground != null
397f849a5e16d016fb6ae081a4575ce67f4ce688e3aAdam Powell                        && mSplitBackground.getOpacity() == PixelFormat.OPAQUE) {
398f849a5e16d016fb6ae081a4575ce67f4ce688e3aAdam Powell                    return PixelFormat.OPAQUE;
399f849a5e16d016fb6ae081a4575ce67f4ce688e3aAdam Powell                }
400f849a5e16d016fb6ae081a4575ce67f4ce688e3aAdam Powell            } else {
401f849a5e16d016fb6ae081a4575ce67f4ce688e3aAdam Powell                if (mIsStacked && (mStackedBackground == null
402f849a5e16d016fb6ae081a4575ce67f4ce688e3aAdam Powell                        || mStackedBackground.getOpacity() != PixelFormat.OPAQUE)) {
403f849a5e16d016fb6ae081a4575ce67f4ce688e3aAdam Powell                    return PixelFormat.UNKNOWN;
404f849a5e16d016fb6ae081a4575ce67f4ce688e3aAdam Powell                }
405f849a5e16d016fb6ae081a4575ce67f4ce688e3aAdam Powell                if (!isCollapsed(mActionBarView) && mBackground != null
406f849a5e16d016fb6ae081a4575ce67f4ce688e3aAdam Powell                        && mBackground.getOpacity() == PixelFormat.OPAQUE) {
407f849a5e16d016fb6ae081a4575ce67f4ce688e3aAdam Powell                    return PixelFormat.OPAQUE;
408f849a5e16d016fb6ae081a4575ce67f4ce688e3aAdam Powell                }
409f849a5e16d016fb6ae081a4575ce67f4ce688e3aAdam Powell            }
410f849a5e16d016fb6ae081a4575ce67f4ce688e3aAdam Powell
411f849a5e16d016fb6ae081a4575ce67f4ce688e3aAdam Powell            return PixelFormat.UNKNOWN;
4127f610fed107b158c144dca1b20a44ee91eb8c934Alan Viverette        }
4137f610fed107b158c144dca1b20a44ee91eb8c934Alan Viverette    }
41445f1e08c348ccb129bcc25e438c05421f7123f41Adam Powell}
415