AbsActionBarView.java revision 3d0f21dab8d891b9aebdd5277348d549eeb843e6
1640a66eac612b850b5dabd3b93bd94f83ed2d567Adam Powell/*
2640a66eac612b850b5dabd3b93bd94f83ed2d567Adam Powell * Copyright (C) 2011 The Android Open Source Project
3640a66eac612b850b5dabd3b93bd94f83ed2d567Adam Powell *
4640a66eac612b850b5dabd3b93bd94f83ed2d567Adam Powell * Licensed under the Apache License, Version 2.0 (the "License");
5640a66eac612b850b5dabd3b93bd94f83ed2d567Adam Powell * you may not use this file except in compliance with the License.
6640a66eac612b850b5dabd3b93bd94f83ed2d567Adam Powell * You may obtain a copy of the License at
7640a66eac612b850b5dabd3b93bd94f83ed2d567Adam Powell *
8640a66eac612b850b5dabd3b93bd94f83ed2d567Adam Powell *      http://www.apache.org/licenses/LICENSE-2.0
9640a66eac612b850b5dabd3b93bd94f83ed2d567Adam Powell *
10640a66eac612b850b5dabd3b93bd94f83ed2d567Adam Powell * Unless required by applicable law or agreed to in writing, software
11640a66eac612b850b5dabd3b93bd94f83ed2d567Adam Powell * distributed under the License is distributed on an "AS IS" BASIS,
12640a66eac612b850b5dabd3b93bd94f83ed2d567Adam Powell * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13640a66eac612b850b5dabd3b93bd94f83ed2d567Adam Powell * See the License for the specific language governing permissions and
14640a66eac612b850b5dabd3b93bd94f83ed2d567Adam Powell * limitations under the License.
15640a66eac612b850b5dabd3b93bd94f83ed2d567Adam Powell */
16640a66eac612b850b5dabd3b93bd94f83ed2d567Adam Powellpackage com.android.internal.widget;
17640a66eac612b850b5dabd3b93bd94f83ed2d567Adam Powell
18425689eea2f4f208f29b944b4973981bdbeda9f5Adam Powellimport com.android.internal.R;
193d0f21dab8d891b9aebdd5277348d549eeb843e6Alan Viverette
203d0f21dab8d891b9aebdd5277348d549eeb843e6Alan Viveretteimport android.util.TypedValue;
213d0f21dab8d891b9aebdd5277348d549eeb843e6Alan Viveretteimport android.view.ContextThemeWrapper;
22fa18d182a3f37505940e73ae6cd76c2e939f7f7cAdam Powellimport android.widget.ActionMenuPresenter;
23fa18d182a3f37505940e73ae6cd76c2e939f7f7cAdam Powellimport android.widget.ActionMenuView;
24640a66eac612b850b5dabd3b93bd94f83ed2d567Adam Powell
25640a66eac612b850b5dabd3b93bd94f83ed2d567Adam Powellimport android.animation.Animator;
26640a66eac612b850b5dabd3b93bd94f83ed2d567Adam Powellimport android.animation.AnimatorSet;
27640a66eac612b850b5dabd3b93bd94f83ed2d567Adam Powellimport android.animation.ObjectAnimator;
28640a66eac612b850b5dabd3b93bd94f83ed2d567Adam Powellimport android.animation.TimeInterpolator;
29640a66eac612b850b5dabd3b93bd94f83ed2d567Adam Powellimport android.content.Context;
30425689eea2f4f208f29b944b4973981bdbeda9f5Adam Powellimport android.content.res.Configuration;
31425689eea2f4f208f29b944b4973981bdbeda9f5Adam Powellimport android.content.res.TypedArray;
32640a66eac612b850b5dabd3b93bd94f83ed2d567Adam Powellimport android.util.AttributeSet;
33640a66eac612b850b5dabd3b93bd94f83ed2d567Adam Powellimport android.view.View;
34640a66eac612b850b5dabd3b93bd94f83ed2d567Adam Powellimport android.view.ViewGroup;
35640a66eac612b850b5dabd3b93bd94f83ed2d567Adam Powellimport android.view.animation.DecelerateInterpolator;
36640a66eac612b850b5dabd3b93bd94f83ed2d567Adam Powell
37640a66eac612b850b5dabd3b93bd94f83ed2d567Adam Powellpublic abstract class AbsActionBarView extends ViewGroup {
383d0f21dab8d891b9aebdd5277348d549eeb843e6Alan Viverette    private static final TimeInterpolator sAlphaInterpolator = new DecelerateInterpolator();
393d0f21dab8d891b9aebdd5277348d549eeb843e6Alan Viverette
403d0f21dab8d891b9aebdd5277348d549eeb843e6Alan Viverette    private static final int FADE_DURATION = 200;
413d0f21dab8d891b9aebdd5277348d549eeb843e6Alan Viverette
423d0f21dab8d891b9aebdd5277348d549eeb843e6Alan Viverette    protected final VisibilityAnimListener mVisAnimListener = new VisibilityAnimListener();
433d0f21dab8d891b9aebdd5277348d549eeb843e6Alan Viverette
443d0f21dab8d891b9aebdd5277348d549eeb843e6Alan Viverette    /** Context against which to inflate popup menus. */
453d0f21dab8d891b9aebdd5277348d549eeb843e6Alan Viverette    protected final Context mPopupContext;
463d0f21dab8d891b9aebdd5277348d549eeb843e6Alan Viverette
47640a66eac612b850b5dabd3b93bd94f83ed2d567Adam Powell    protected ActionMenuView mMenuView;
488d02deabac62c4a68a335a7b3141795466362b89Adam Powell    protected ActionMenuPresenter mActionMenuPresenter;
49e021e6ed8931a0a8296af182fc9b0c76b64fb0c4Adam Powell    protected ViewGroup mSplitView;
50a05aba9c506cd12a753c53e060c289095c3477e9Adam Powell    protected boolean mSplitActionBar;
51a05aba9c506cd12a753c53e060c289095c3477e9Adam Powell    protected boolean mSplitWhenNarrow;
52425689eea2f4f208f29b944b4973981bdbeda9f5Adam Powell    protected int mContentHeight;
53640a66eac612b850b5dabd3b93bd94f83ed2d567Adam Powell
54640a66eac612b850b5dabd3b93bd94f83ed2d567Adam Powell    protected Animator mVisibilityAnim;
55640a66eac612b850b5dabd3b93bd94f83ed2d567Adam Powell
56640a66eac612b850b5dabd3b93bd94f83ed2d567Adam Powell    public AbsActionBarView(Context context) {
57d6479ec5eec13914f656f6be996d95fe1610fd57Alan Viverette        this(context, null);
58640a66eac612b850b5dabd3b93bd94f83ed2d567Adam Powell    }
59640a66eac612b850b5dabd3b93bd94f83ed2d567Adam Powell
60640a66eac612b850b5dabd3b93bd94f83ed2d567Adam Powell    public AbsActionBarView(Context context, AttributeSet attrs) {
61d6479ec5eec13914f656f6be996d95fe1610fd57Alan Viverette        this(context, attrs, 0);
62640a66eac612b850b5dabd3b93bd94f83ed2d567Adam Powell    }
63640a66eac612b850b5dabd3b93bd94f83ed2d567Adam Powell
64617feb99a06e7ffb3894e86a286bf30e085f321aAlan Viverette    public AbsActionBarView(Context context, AttributeSet attrs, int defStyleAttr) {
65617feb99a06e7ffb3894e86a286bf30e085f321aAlan Viverette        this(context, attrs, defStyleAttr, 0);
66617feb99a06e7ffb3894e86a286bf30e085f321aAlan Viverette    }
67617feb99a06e7ffb3894e86a286bf30e085f321aAlan Viverette
68617feb99a06e7ffb3894e86a286bf30e085f321aAlan Viverette    public AbsActionBarView(
69617feb99a06e7ffb3894e86a286bf30e085f321aAlan Viverette            Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) {
70617feb99a06e7ffb3894e86a286bf30e085f321aAlan Viverette        super(context, attrs, defStyleAttr, defStyleRes);
713d0f21dab8d891b9aebdd5277348d549eeb843e6Alan Viverette
723d0f21dab8d891b9aebdd5277348d549eeb843e6Alan Viverette        final TypedValue tv = new TypedValue();
733d0f21dab8d891b9aebdd5277348d549eeb843e6Alan Viverette        if (context.getTheme().resolveAttribute(R.attr.actionBarPopupTheme, tv, true)
743d0f21dab8d891b9aebdd5277348d549eeb843e6Alan Viverette                && tv.resourceId != 0) {
753d0f21dab8d891b9aebdd5277348d549eeb843e6Alan Viverette            mPopupContext = new ContextThemeWrapper(context, tv.resourceId);
763d0f21dab8d891b9aebdd5277348d549eeb843e6Alan Viverette        } else {
773d0f21dab8d891b9aebdd5277348d549eeb843e6Alan Viverette            mPopupContext = context;
783d0f21dab8d891b9aebdd5277348d549eeb843e6Alan Viverette        }
79640a66eac612b850b5dabd3b93bd94f83ed2d567Adam Powell    }
80640a66eac612b850b5dabd3b93bd94f83ed2d567Adam Powell
81425689eea2f4f208f29b944b4973981bdbeda9f5Adam Powell    @Override
82425689eea2f4f208f29b944b4973981bdbeda9f5Adam Powell    protected void onConfigurationChanged(Configuration newConfig) {
83425689eea2f4f208f29b944b4973981bdbeda9f5Adam Powell        super.onConfigurationChanged(newConfig);
84425689eea2f4f208f29b944b4973981bdbeda9f5Adam Powell
85425689eea2f4f208f29b944b4973981bdbeda9f5Adam Powell        // Action bar can change size on configuration changes.
86425689eea2f4f208f29b944b4973981bdbeda9f5Adam Powell        // Reread the desired height from the theme-specified style.
87425689eea2f4f208f29b944b4973981bdbeda9f5Adam Powell        TypedArray a = getContext().obtainStyledAttributes(null, R.styleable.ActionBar,
88425689eea2f4f208f29b944b4973981bdbeda9f5Adam Powell                com.android.internal.R.attr.actionBarStyle, 0);
89425689eea2f4f208f29b944b4973981bdbeda9f5Adam Powell        setContentHeight(a.getLayoutDimension(R.styleable.ActionBar_height, 0));
90425689eea2f4f208f29b944b4973981bdbeda9f5Adam Powell        a.recycle();
91a05aba9c506cd12a753c53e060c289095c3477e9Adam Powell        if (mSplitWhenNarrow) {
92e021e6ed8931a0a8296af182fc9b0c76b64fb0c4Adam Powell            setSplitToolbar(getContext().getResources().getBoolean(
93a05aba9c506cd12a753c53e060c289095c3477e9Adam Powell                    com.android.internal.R.bool.split_action_bar_is_narrow));
94a05aba9c506cd12a753c53e060c289095c3477e9Adam Powell        }
95425689eea2f4f208f29b944b4973981bdbeda9f5Adam Powell        if (mActionMenuPresenter != null) {
96425689eea2f4f208f29b944b4973981bdbeda9f5Adam Powell            mActionMenuPresenter.onConfigurationChanged(newConfig);
97425689eea2f4f208f29b944b4973981bdbeda9f5Adam Powell        }
98425689eea2f4f208f29b944b4973981bdbeda9f5Adam Powell    }
99425689eea2f4f208f29b944b4973981bdbeda9f5Adam Powell
100a05aba9c506cd12a753c53e060c289095c3477e9Adam Powell    /**
101a05aba9c506cd12a753c53e060c289095c3477e9Adam Powell     * Sets whether the bar should be split right now, no questions asked.
102a05aba9c506cd12a753c53e060c289095c3477e9Adam Powell     * @param split true if the bar should split
103a05aba9c506cd12a753c53e060c289095c3477e9Adam Powell     */
104e021e6ed8931a0a8296af182fc9b0c76b64fb0c4Adam Powell    public void setSplitToolbar(boolean split) {
105a05aba9c506cd12a753c53e060c289095c3477e9Adam Powell        mSplitActionBar = split;
106a05aba9c506cd12a753c53e060c289095c3477e9Adam Powell    }
107a05aba9c506cd12a753c53e060c289095c3477e9Adam Powell
108a05aba9c506cd12a753c53e060c289095c3477e9Adam Powell    /**
109a05aba9c506cd12a753c53e060c289095c3477e9Adam Powell     * Sets whether the bar should split if we enter a narrow screen configuration.
110a05aba9c506cd12a753c53e060c289095c3477e9Adam Powell     * @param splitWhenNarrow true if the bar should check to split after a config change
111a05aba9c506cd12a753c53e060c289095c3477e9Adam Powell     */
112a05aba9c506cd12a753c53e060c289095c3477e9Adam Powell    public void setSplitWhenNarrow(boolean splitWhenNarrow) {
113a05aba9c506cd12a753c53e060c289095c3477e9Adam Powell        mSplitWhenNarrow = splitWhenNarrow;
114a05aba9c506cd12a753c53e060c289095c3477e9Adam Powell    }
115a05aba9c506cd12a753c53e060c289095c3477e9Adam Powell
116425689eea2f4f208f29b944b4973981bdbeda9f5Adam Powell    public void setContentHeight(int height) {
117425689eea2f4f208f29b944b4973981bdbeda9f5Adam Powell        mContentHeight = height;
118425689eea2f4f208f29b944b4973981bdbeda9f5Adam Powell        requestLayout();
119425689eea2f4f208f29b944b4973981bdbeda9f5Adam Powell    }
120425689eea2f4f208f29b944b4973981bdbeda9f5Adam Powell
121425689eea2f4f208f29b944b4973981bdbeda9f5Adam Powell    public int getContentHeight() {
122425689eea2f4f208f29b944b4973981bdbeda9f5Adam Powell        return mContentHeight;
123425689eea2f4f208f29b944b4973981bdbeda9f5Adam Powell    }
124425689eea2f4f208f29b944b4973981bdbeda9f5Adam Powell
125e021e6ed8931a0a8296af182fc9b0c76b64fb0c4Adam Powell    public void setSplitView(ViewGroup splitView) {
126640a66eac612b850b5dabd3b93bd94f83ed2d567Adam Powell        mSplitView = splitView;
127640a66eac612b850b5dabd3b93bd94f83ed2d567Adam Powell    }
128640a66eac612b850b5dabd3b93bd94f83ed2d567Adam Powell
1299a5cc2810bbbcb0eab4579aa4131039820d92101Adam Powell    /**
1309a5cc2810bbbcb0eab4579aa4131039820d92101Adam Powell     * @return Current visibility or if animating, the visibility being animated to.
1319a5cc2810bbbcb0eab4579aa4131039820d92101Adam Powell     */
1329a5cc2810bbbcb0eab4579aa4131039820d92101Adam Powell    public int getAnimatedVisibility() {
1339a5cc2810bbbcb0eab4579aa4131039820d92101Adam Powell        if (mVisibilityAnim != null) {
1349a5cc2810bbbcb0eab4579aa4131039820d92101Adam Powell            return mVisAnimListener.mFinalVisibility;
1359a5cc2810bbbcb0eab4579aa4131039820d92101Adam Powell        }
1369a5cc2810bbbcb0eab4579aa4131039820d92101Adam Powell        return getVisibility();
1379a5cc2810bbbcb0eab4579aa4131039820d92101Adam Powell    }
1389a5cc2810bbbcb0eab4579aa4131039820d92101Adam Powell
139640a66eac612b850b5dabd3b93bd94f83ed2d567Adam Powell    public void animateToVisibility(int visibility) {
140640a66eac612b850b5dabd3b93bd94f83ed2d567Adam Powell        if (mVisibilityAnim != null) {
141640a66eac612b850b5dabd3b93bd94f83ed2d567Adam Powell            mVisibilityAnim.cancel();
142640a66eac612b850b5dabd3b93bd94f83ed2d567Adam Powell        }
143640a66eac612b850b5dabd3b93bd94f83ed2d567Adam Powell        if (visibility == VISIBLE) {
144640a66eac612b850b5dabd3b93bd94f83ed2d567Adam Powell            if (getVisibility() != VISIBLE) {
145640a66eac612b850b5dabd3b93bd94f83ed2d567Adam Powell                setAlpha(0);
146640a66eac612b850b5dabd3b93bd94f83ed2d567Adam Powell                if (mSplitView != null && mMenuView != null) {
147640a66eac612b850b5dabd3b93bd94f83ed2d567Adam Powell                    mMenuView.setAlpha(0);
148640a66eac612b850b5dabd3b93bd94f83ed2d567Adam Powell                }
149640a66eac612b850b5dabd3b93bd94f83ed2d567Adam Powell            }
150640a66eac612b850b5dabd3b93bd94f83ed2d567Adam Powell            ObjectAnimator anim = ObjectAnimator.ofFloat(this, "alpha", 1);
151640a66eac612b850b5dabd3b93bd94f83ed2d567Adam Powell            anim.setDuration(FADE_DURATION);
152640a66eac612b850b5dabd3b93bd94f83ed2d567Adam Powell            anim.setInterpolator(sAlphaInterpolator);
153640a66eac612b850b5dabd3b93bd94f83ed2d567Adam Powell            if (mSplitView != null && mMenuView != null) {
154640a66eac612b850b5dabd3b93bd94f83ed2d567Adam Powell                AnimatorSet set = new AnimatorSet();
155640a66eac612b850b5dabd3b93bd94f83ed2d567Adam Powell                ObjectAnimator splitAnim = ObjectAnimator.ofFloat(mMenuView, "alpha", 1);
156640a66eac612b850b5dabd3b93bd94f83ed2d567Adam Powell                splitAnim.setDuration(FADE_DURATION);
157640a66eac612b850b5dabd3b93bd94f83ed2d567Adam Powell                set.addListener(mVisAnimListener.withFinalVisibility(visibility));
158640a66eac612b850b5dabd3b93bd94f83ed2d567Adam Powell                set.play(anim).with(splitAnim);
1595c1cb19f4075b3c4ab895a30ab5f2469aff5b553Adam Powell                set.start();
160640a66eac612b850b5dabd3b93bd94f83ed2d567Adam Powell            } else {
161640a66eac612b850b5dabd3b93bd94f83ed2d567Adam Powell                anim.addListener(mVisAnimListener.withFinalVisibility(visibility));
162640a66eac612b850b5dabd3b93bd94f83ed2d567Adam Powell                anim.start();
163640a66eac612b850b5dabd3b93bd94f83ed2d567Adam Powell            }
164640a66eac612b850b5dabd3b93bd94f83ed2d567Adam Powell        } else {
165640a66eac612b850b5dabd3b93bd94f83ed2d567Adam Powell            ObjectAnimator anim = ObjectAnimator.ofFloat(this, "alpha", 0);
166640a66eac612b850b5dabd3b93bd94f83ed2d567Adam Powell            anim.setDuration(FADE_DURATION);
167640a66eac612b850b5dabd3b93bd94f83ed2d567Adam Powell            anim.setInterpolator(sAlphaInterpolator);
168640a66eac612b850b5dabd3b93bd94f83ed2d567Adam Powell            if (mSplitView != null && mMenuView != null) {
169640a66eac612b850b5dabd3b93bd94f83ed2d567Adam Powell                AnimatorSet set = new AnimatorSet();
170640a66eac612b850b5dabd3b93bd94f83ed2d567Adam Powell                ObjectAnimator splitAnim = ObjectAnimator.ofFloat(mMenuView, "alpha", 0);
171640a66eac612b850b5dabd3b93bd94f83ed2d567Adam Powell                splitAnim.setDuration(FADE_DURATION);
172640a66eac612b850b5dabd3b93bd94f83ed2d567Adam Powell                set.addListener(mVisAnimListener.withFinalVisibility(visibility));
173640a66eac612b850b5dabd3b93bd94f83ed2d567Adam Powell                set.play(anim).with(splitAnim);
1745c1cb19f4075b3c4ab895a30ab5f2469aff5b553Adam Powell                set.start();
175640a66eac612b850b5dabd3b93bd94f83ed2d567Adam Powell            } else {
176640a66eac612b850b5dabd3b93bd94f83ed2d567Adam Powell                anim.addListener(mVisAnimListener.withFinalVisibility(visibility));
177640a66eac612b850b5dabd3b93bd94f83ed2d567Adam Powell                anim.start();
178640a66eac612b850b5dabd3b93bd94f83ed2d567Adam Powell            }
179640a66eac612b850b5dabd3b93bd94f83ed2d567Adam Powell        }
180640a66eac612b850b5dabd3b93bd94f83ed2d567Adam Powell    }
181640a66eac612b850b5dabd3b93bd94f83ed2d567Adam Powell
182640a66eac612b850b5dabd3b93bd94f83ed2d567Adam Powell    @Override
183640a66eac612b850b5dabd3b93bd94f83ed2d567Adam Powell    public void setVisibility(int visibility) {
1849caeb145721238897809805f521bb5c8ef375c0fGeorge Mount        if (visibility != getVisibility()) {
1859caeb145721238897809805f521bb5c8ef375c0fGeorge Mount            if (mVisibilityAnim != null) {
1869caeb145721238897809805f521bb5c8ef375c0fGeorge Mount                mVisibilityAnim.end();
1879caeb145721238897809805f521bb5c8ef375c0fGeorge Mount            }
1889caeb145721238897809805f521bb5c8ef375c0fGeorge Mount            super.setVisibility(visibility);
189640a66eac612b850b5dabd3b93bd94f83ed2d567Adam Powell        }
190640a66eac612b850b5dabd3b93bd94f83ed2d567Adam Powell    }
191640a66eac612b850b5dabd3b93bd94f83ed2d567Adam Powell
192640a66eac612b850b5dabd3b93bd94f83ed2d567Adam Powell    public boolean showOverflowMenu() {
1938d02deabac62c4a68a335a7b3141795466362b89Adam Powell        if (mActionMenuPresenter != null) {
1948d02deabac62c4a68a335a7b3141795466362b89Adam Powell            return mActionMenuPresenter.showOverflowMenu();
195640a66eac612b850b5dabd3b93bd94f83ed2d567Adam Powell        }
196640a66eac612b850b5dabd3b93bd94f83ed2d567Adam Powell        return false;
197640a66eac612b850b5dabd3b93bd94f83ed2d567Adam Powell    }
198640a66eac612b850b5dabd3b93bd94f83ed2d567Adam Powell
199640a66eac612b850b5dabd3b93bd94f83ed2d567Adam Powell    public void postShowOverflowMenu() {
200640a66eac612b850b5dabd3b93bd94f83ed2d567Adam Powell        post(new Runnable() {
201640a66eac612b850b5dabd3b93bd94f83ed2d567Adam Powell            public void run() {
202640a66eac612b850b5dabd3b93bd94f83ed2d567Adam Powell                showOverflowMenu();
203640a66eac612b850b5dabd3b93bd94f83ed2d567Adam Powell            }
204640a66eac612b850b5dabd3b93bd94f83ed2d567Adam Powell        });
205640a66eac612b850b5dabd3b93bd94f83ed2d567Adam Powell    }
206640a66eac612b850b5dabd3b93bd94f83ed2d567Adam Powell
207640a66eac612b850b5dabd3b93bd94f83ed2d567Adam Powell    public boolean hideOverflowMenu() {
2088d02deabac62c4a68a335a7b3141795466362b89Adam Powell        if (mActionMenuPresenter != null) {
2098d02deabac62c4a68a335a7b3141795466362b89Adam Powell            return mActionMenuPresenter.hideOverflowMenu();
210640a66eac612b850b5dabd3b93bd94f83ed2d567Adam Powell        }
211640a66eac612b850b5dabd3b93bd94f83ed2d567Adam Powell        return false;
212640a66eac612b850b5dabd3b93bd94f83ed2d567Adam Powell    }
213640a66eac612b850b5dabd3b93bd94f83ed2d567Adam Powell
214640a66eac612b850b5dabd3b93bd94f83ed2d567Adam Powell    public boolean isOverflowMenuShowing() {
2158d02deabac62c4a68a335a7b3141795466362b89Adam Powell        if (mActionMenuPresenter != null) {
2168d02deabac62c4a68a335a7b3141795466362b89Adam Powell            return mActionMenuPresenter.isOverflowMenuShowing();
217640a66eac612b850b5dabd3b93bd94f83ed2d567Adam Powell        }
218640a66eac612b850b5dabd3b93bd94f83ed2d567Adam Powell        return false;
219640a66eac612b850b5dabd3b93bd94f83ed2d567Adam Powell    }
220640a66eac612b850b5dabd3b93bd94f83ed2d567Adam Powell
2215fcf5b9fd3ff6757090c6bd166b60c18eda0b3efAdam Powell    public boolean isOverflowMenuShowPending() {
2225fcf5b9fd3ff6757090c6bd166b60c18eda0b3efAdam Powell        if (mActionMenuPresenter != null) {
2235fcf5b9fd3ff6757090c6bd166b60c18eda0b3efAdam Powell            return mActionMenuPresenter.isOverflowMenuShowPending();
2245fcf5b9fd3ff6757090c6bd166b60c18eda0b3efAdam Powell        }
2255fcf5b9fd3ff6757090c6bd166b60c18eda0b3efAdam Powell        return false;
2265fcf5b9fd3ff6757090c6bd166b60c18eda0b3efAdam Powell    }
2275fcf5b9fd3ff6757090c6bd166b60c18eda0b3efAdam Powell
228640a66eac612b850b5dabd3b93bd94f83ed2d567Adam Powell    public boolean isOverflowReserved() {
2298d02deabac62c4a68a335a7b3141795466362b89Adam Powell        return mActionMenuPresenter != null && mActionMenuPresenter.isOverflowReserved();
230640a66eac612b850b5dabd3b93bd94f83ed2d567Adam Powell    }
231640a66eac612b850b5dabd3b93bd94f83ed2d567Adam Powell
232e021e6ed8931a0a8296af182fc9b0c76b64fb0c4Adam Powell    public boolean canShowOverflowMenu() {
233e021e6ed8931a0a8296af182fc9b0c76b64fb0c4Adam Powell        return isOverflowReserved() && getVisibility() == VISIBLE;
234e021e6ed8931a0a8296af182fc9b0c76b64fb0c4Adam Powell    }
235e021e6ed8931a0a8296af182fc9b0c76b64fb0c4Adam Powell
236640a66eac612b850b5dabd3b93bd94f83ed2d567Adam Powell    public void dismissPopupMenus() {
2378d02deabac62c4a68a335a7b3141795466362b89Adam Powell        if (mActionMenuPresenter != null) {
2388d02deabac62c4a68a335a7b3141795466362b89Adam Powell            mActionMenuPresenter.dismissPopupMenus();
239640a66eac612b850b5dabd3b93bd94f83ed2d567Adam Powell        }
240640a66eac612b850b5dabd3b93bd94f83ed2d567Adam Powell    }
241640a66eac612b850b5dabd3b93bd94f83ed2d567Adam Powell
242640a66eac612b850b5dabd3b93bd94f83ed2d567Adam Powell    protected int measureChildView(View child, int availableWidth, int childSpecHeight,
243640a66eac612b850b5dabd3b93bd94f83ed2d567Adam Powell            int spacing) {
244640a66eac612b850b5dabd3b93bd94f83ed2d567Adam Powell        child.measure(MeasureSpec.makeMeasureSpec(availableWidth, MeasureSpec.AT_MOST),
245640a66eac612b850b5dabd3b93bd94f83ed2d567Adam Powell                childSpecHeight);
246640a66eac612b850b5dabd3b93bd94f83ed2d567Adam Powell
247640a66eac612b850b5dabd3b93bd94f83ed2d567Adam Powell        availableWidth -= child.getMeasuredWidth();
248640a66eac612b850b5dabd3b93bd94f83ed2d567Adam Powell        availableWidth -= spacing;
249640a66eac612b850b5dabd3b93bd94f83ed2d567Adam Powell
2505d4034a37e5ac3832b91388024f6eddf343cf3f6Adam Powell        return Math.max(0, availableWidth);
251640a66eac612b850b5dabd3b93bd94f83ed2d567Adam Powell    }
252640a66eac612b850b5dabd3b93bd94f83ed2d567Adam Powell
253cf1ba0298c48ae56608ed556dc715eb69c54f9b9Fabrice Di Meglio    static protected int next(int x, int val, boolean isRtl) {
254cf1ba0298c48ae56608ed556dc715eb69c54f9b9Fabrice Di Meglio        return isRtl ? x - val : x + val;
255640a66eac612b850b5dabd3b93bd94f83ed2d567Adam Powell    }
256640a66eac612b850b5dabd3b93bd94f83ed2d567Adam Powell
257cf1ba0298c48ae56608ed556dc715eb69c54f9b9Fabrice Di Meglio    protected int positionChild(View child, int x, int y, int contentHeight, boolean reverse) {
258640a66eac612b850b5dabd3b93bd94f83ed2d567Adam Powell        int childWidth = child.getMeasuredWidth();
259640a66eac612b850b5dabd3b93bd94f83ed2d567Adam Powell        int childHeight = child.getMeasuredHeight();
260640a66eac612b850b5dabd3b93bd94f83ed2d567Adam Powell        int childTop = y + (contentHeight - childHeight) / 2;
261640a66eac612b850b5dabd3b93bd94f83ed2d567Adam Powell
262cf1ba0298c48ae56608ed556dc715eb69c54f9b9Fabrice Di Meglio        if (reverse) {
263cf1ba0298c48ae56608ed556dc715eb69c54f9b9Fabrice Di Meglio            child.layout(x - childWidth, childTop, x, childTop + childHeight);
264cf1ba0298c48ae56608ed556dc715eb69c54f9b9Fabrice Di Meglio        } else {
265cf1ba0298c48ae56608ed556dc715eb69c54f9b9Fabrice Di Meglio            child.layout(x, childTop, x + childWidth, childTop + childHeight);
266cf1ba0298c48ae56608ed556dc715eb69c54f9b9Fabrice Di Meglio        }
267640a66eac612b850b5dabd3b93bd94f83ed2d567Adam Powell
268cf1ba0298c48ae56608ed556dc715eb69c54f9b9Fabrice Di Meglio        return  (reverse ? -childWidth : childWidth);
269640a66eac612b850b5dabd3b93bd94f83ed2d567Adam Powell    }
270640a66eac612b850b5dabd3b93bd94f83ed2d567Adam Powell
271640a66eac612b850b5dabd3b93bd94f83ed2d567Adam Powell    protected class VisibilityAnimListener implements Animator.AnimatorListener {
272640a66eac612b850b5dabd3b93bd94f83ed2d567Adam Powell        private boolean mCanceled = false;
2739a5cc2810bbbcb0eab4579aa4131039820d92101Adam Powell        int mFinalVisibility;
274640a66eac612b850b5dabd3b93bd94f83ed2d567Adam Powell
275640a66eac612b850b5dabd3b93bd94f83ed2d567Adam Powell        public VisibilityAnimListener withFinalVisibility(int visibility) {
276640a66eac612b850b5dabd3b93bd94f83ed2d567Adam Powell            mFinalVisibility = visibility;
277640a66eac612b850b5dabd3b93bd94f83ed2d567Adam Powell            return this;
278640a66eac612b850b5dabd3b93bd94f83ed2d567Adam Powell        }
279640a66eac612b850b5dabd3b93bd94f83ed2d567Adam Powell
280640a66eac612b850b5dabd3b93bd94f83ed2d567Adam Powell        @Override
281640a66eac612b850b5dabd3b93bd94f83ed2d567Adam Powell        public void onAnimationStart(Animator animation) {
282640a66eac612b850b5dabd3b93bd94f83ed2d567Adam Powell            setVisibility(VISIBLE);
283640a66eac612b850b5dabd3b93bd94f83ed2d567Adam Powell            mVisibilityAnim = animation;
284640a66eac612b850b5dabd3b93bd94f83ed2d567Adam Powell            mCanceled = false;
285640a66eac612b850b5dabd3b93bd94f83ed2d567Adam Powell        }
286640a66eac612b850b5dabd3b93bd94f83ed2d567Adam Powell
287640a66eac612b850b5dabd3b93bd94f83ed2d567Adam Powell        @Override
288640a66eac612b850b5dabd3b93bd94f83ed2d567Adam Powell        public void onAnimationEnd(Animator animation) {
289640a66eac612b850b5dabd3b93bd94f83ed2d567Adam Powell            if (mCanceled) return;
290640a66eac612b850b5dabd3b93bd94f83ed2d567Adam Powell
291640a66eac612b850b5dabd3b93bd94f83ed2d567Adam Powell            mVisibilityAnim = null;
292640a66eac612b850b5dabd3b93bd94f83ed2d567Adam Powell            setVisibility(mFinalVisibility);
2939a5cc2810bbbcb0eab4579aa4131039820d92101Adam Powell            if (mSplitView != null && mMenuView != null) {
2949a5cc2810bbbcb0eab4579aa4131039820d92101Adam Powell                mMenuView.setVisibility(mFinalVisibility);
2959a5cc2810bbbcb0eab4579aa4131039820d92101Adam Powell            }
296640a66eac612b850b5dabd3b93bd94f83ed2d567Adam Powell        }
297640a66eac612b850b5dabd3b93bd94f83ed2d567Adam Powell
298640a66eac612b850b5dabd3b93bd94f83ed2d567Adam Powell        @Override
299640a66eac612b850b5dabd3b93bd94f83ed2d567Adam Powell        public void onAnimationCancel(Animator animation) {
300640a66eac612b850b5dabd3b93bd94f83ed2d567Adam Powell            mCanceled = true;
301640a66eac612b850b5dabd3b93bd94f83ed2d567Adam Powell        }
302640a66eac612b850b5dabd3b93bd94f83ed2d567Adam Powell
303640a66eac612b850b5dabd3b93bd94f83ed2d567Adam Powell        @Override
304640a66eac612b850b5dabd3b93bd94f83ed2d567Adam Powell        public void onAnimationRepeat(Animator animation) {
305640a66eac612b850b5dabd3b93bd94f83ed2d567Adam Powell        }
306640a66eac612b850b5dabd3b93bd94f83ed2d567Adam Powell    }
307640a66eac612b850b5dabd3b93bd94f83ed2d567Adam Powell}
308