ActionBarContextView.java revision cf1ba0298c48ae56608ed556dc715eb69c54f9b9
189e0645b4157961e8c465eb9c819f965fdb453d8Adam Powell/*
289e0645b4157961e8c465eb9c819f965fdb453d8Adam Powell * Copyright (C) 2010 The Android Open Source Project
389e0645b4157961e8c465eb9c819f965fdb453d8Adam Powell *
489e0645b4157961e8c465eb9c819f965fdb453d8Adam Powell * Licensed under the Apache License, Version 2.0 (the "License");
589e0645b4157961e8c465eb9c819f965fdb453d8Adam Powell * you may not use this file except in compliance with the License.
689e0645b4157961e8c465eb9c819f965fdb453d8Adam Powell * You may obtain a copy of the License at
789e0645b4157961e8c465eb9c819f965fdb453d8Adam Powell *
889e0645b4157961e8c465eb9c819f965fdb453d8Adam Powell *      http://www.apache.org/licenses/LICENSE-2.0
989e0645b4157961e8c465eb9c819f965fdb453d8Adam Powell *
1089e0645b4157961e8c465eb9c819f965fdb453d8Adam Powell * Unless required by applicable law or agreed to in writing, software
1189e0645b4157961e8c465eb9c819f965fdb453d8Adam Powell * distributed under the License is distributed on an "AS IS" BASIS,
1289e0645b4157961e8c465eb9c819f965fdb453d8Adam Powell * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
1389e0645b4157961e8c465eb9c819f965fdb453d8Adam Powell * See the License for the specific language governing permissions and
1489e0645b4157961e8c465eb9c819f965fdb453d8Adam Powell * limitations under the License.
1589e0645b4157961e8c465eb9c819f965fdb453d8Adam Powell */
1689e0645b4157961e8c465eb9c819f965fdb453d8Adam Powellpackage com.android.internal.widget;
1789e0645b4157961e8c465eb9c819f965fdb453d8Adam Powell
189ca705e323cb737a07a667c1e86bac702f11a29cAdam Powellimport com.android.internal.R;
199ca705e323cb737a07a667c1e86bac702f11a29cAdam Powellimport com.android.internal.view.menu.ActionMenuPresenter;
209ca705e323cb737a07a667c1e86bac702f11a29cAdam Powellimport com.android.internal.view.menu.ActionMenuView;
219ca705e323cb737a07a667c1e86bac702f11a29cAdam Powellimport com.android.internal.view.menu.MenuBuilder;
229ca705e323cb737a07a667c1e86bac702f11a29cAdam Powell
23d8b3f2e8eee5f24de6653a918613674e9495f751Adam Powellimport android.animation.Animator;
24d8b3f2e8eee5f24de6653a918613674e9495f751Adam Powellimport android.animation.Animator.AnimatorListener;
25d8b3f2e8eee5f24de6653a918613674e9495f751Adam Powellimport android.animation.AnimatorSet;
26d8b3f2e8eee5f24de6653a918613674e9495f751Adam Powellimport android.animation.ObjectAnimator;
2789e0645b4157961e8c465eb9c819f965fdb453d8Adam Powellimport android.content.Context;
28bfcdfaf919cdb67897a6e24afc8f14b2c810596aAdam Powellimport android.content.res.Configuration;
2989e0645b4157961e8c465eb9c819f965fdb453d8Adam Powellimport android.content.res.TypedArray;
309ca705e323cb737a07a667c1e86bac702f11a29cAdam Powellimport android.graphics.drawable.Drawable;
31c619e74cc62678cef09b5f92e87e762a1f02aab7Gilles Debunneimport android.text.TextUtils;
3289e0645b4157961e8c465eb9c819f965fdb453d8Adam Powellimport android.util.AttributeSet;
336e34636749217654f43221885afb7a29bb5ca96aAdam Powellimport android.view.ActionMode;
3489e0645b4157961e8c465eb9c819f965fdb453d8Adam Powellimport android.view.LayoutInflater;
3589e0645b4157961e8c465eb9c819f965fdb453d8Adam Powellimport android.view.View;
369a5cc2810bbbcb0eab4579aa4131039820d92101Adam Powellimport android.view.ViewGroup;
3786ed436b83d6b71ff00d1c3db910f2952018489eAdam Powellimport android.view.accessibility.AccessibilityEvent;
38d8b3f2e8eee5f24de6653a918613674e9495f751Adam Powellimport android.view.animation.DecelerateInterpolator;
390e94b5151d817e600a888448a662208b29b5ef46Adam Powellimport android.widget.LinearLayout;
4089e0645b4157961e8c465eb9c819f965fdb453d8Adam Powellimport android.widget.TextView;
4189e0645b4157961e8c465eb9c819f965fdb453d8Adam Powell
4289e0645b4157961e8c465eb9c819f965fdb453d8Adam Powell/**
4389e0645b4157961e8c465eb9c819f965fdb453d8Adam Powell * @hide
4489e0645b4157961e8c465eb9c819f965fdb453d8Adam Powell */
45640a66eac612b850b5dabd3b93bd94f83ed2d567Adam Powellpublic class ActionBarContextView extends AbsActionBarView implements AnimatorListener {
4677769c7a9130afa48e46dbd79da8271c271ab1e9Adam Powell    private static final String TAG = "ActionBarContextView";
4777769c7a9130afa48e46dbd79da8271c271ab1e9Adam Powell
4889e0645b4157961e8c465eb9c819f965fdb453d8Adam Powell    private CharSequence mTitle;
4989e0645b4157961e8c465eb9c819f965fdb453d8Adam Powell    private CharSequence mSubtitle;
50f16888f1e849b0bc0b9c17e5f833c4e2cd54c382Adam Powell
51f16888f1e849b0bc0b9c17e5f833c4e2cd54c382Adam Powell    private View mClose;
5289e0645b4157961e8c465eb9c819f965fdb453d8Adam Powell    private View mCustomView;
530e94b5151d817e600a888448a662208b29b5ef46Adam Powell    private LinearLayout mTitleLayout;
5489e0645b4157961e8c465eb9c819f965fdb453d8Adam Powell    private TextView mTitleView;
550e94b5151d817e600a888448a662208b29b5ef46Adam Powell    private TextView mSubtitleView;
56bc234a19f4c74116454e2c77f4739290e761995aAdam Powell    private int mTitleStyleRes;
57bc234a19f4c74116454e2c77f4739290e761995aAdam Powell    private int mSubtitleStyleRes;
589ca705e323cb737a07a667c1e86bac702f11a29cAdam Powell    private Drawable mSplitBackground;
59b98a81f86ab87f1d718f329f03256111fdabd8d1Adam Powell    private boolean mTitleOptional;
60d8b3f2e8eee5f24de6653a918613674e9495f751Adam Powell
61d8b3f2e8eee5f24de6653a918613674e9495f751Adam Powell    private Animator mCurrentAnimation;
62d8b3f2e8eee5f24de6653a918613674e9495f751Adam Powell    private boolean mAnimateInOnLayout;
63d8b3f2e8eee5f24de6653a918613674e9495f751Adam Powell    private int mAnimationMode;
64d8b3f2e8eee5f24de6653a918613674e9495f751Adam Powell
65d8b3f2e8eee5f24de6653a918613674e9495f751Adam Powell    private static final int ANIMATE_IDLE = 0;
66d8b3f2e8eee5f24de6653a918613674e9495f751Adam Powell    private static final int ANIMATE_IN = 1;
67d8b3f2e8eee5f24de6653a918613674e9495f751Adam Powell    private static final int ANIMATE_OUT = 2;
6889e0645b4157961e8c465eb9c819f965fdb453d8Adam Powell
6989e0645b4157961e8c465eb9c819f965fdb453d8Adam Powell    public ActionBarContextView(Context context) {
70bc234a19f4c74116454e2c77f4739290e761995aAdam Powell        this(context, null);
7189e0645b4157961e8c465eb9c819f965fdb453d8Adam Powell    }
7289e0645b4157961e8c465eb9c819f965fdb453d8Adam Powell
7389e0645b4157961e8c465eb9c819f965fdb453d8Adam Powell    public ActionBarContextView(Context context, AttributeSet attrs) {
74bc234a19f4c74116454e2c77f4739290e761995aAdam Powell        this(context, attrs, com.android.internal.R.attr.actionModeStyle);
7589e0645b4157961e8c465eb9c819f965fdb453d8Adam Powell    }
7689e0645b4157961e8c465eb9c819f965fdb453d8Adam Powell
7789e0645b4157961e8c465eb9c819f965fdb453d8Adam Powell    public ActionBarContextView(Context context, AttributeSet attrs, int defStyle) {
7889e0645b4157961e8c465eb9c819f965fdb453d8Adam Powell        super(context, attrs, defStyle);
7989e0645b4157961e8c465eb9c819f965fdb453d8Adam Powell
80bc234a19f4c74116454e2c77f4739290e761995aAdam Powell        TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.ActionMode, defStyle, 0);
8189e0645b4157961e8c465eb9c819f965fdb453d8Adam Powell        setBackgroundDrawable(a.getDrawable(
82bc234a19f4c74116454e2c77f4739290e761995aAdam Powell                com.android.internal.R.styleable.ActionMode_background));
83bc234a19f4c74116454e2c77f4739290e761995aAdam Powell        mTitleStyleRes = a.getResourceId(
84bc234a19f4c74116454e2c77f4739290e761995aAdam Powell                com.android.internal.R.styleable.ActionMode_titleTextStyle, 0);
85bc234a19f4c74116454e2c77f4739290e761995aAdam Powell        mSubtitleStyleRes = a.getResourceId(
86bc234a19f4c74116454e2c77f4739290e761995aAdam Powell                com.android.internal.R.styleable.ActionMode_subtitleTextStyle, 0);
87dcdefbbff2bfecbfeb7b6459de130f376595c590Adam Powell
88e2194445b078932733a2d1a02fc084ea2f3c7360Adam Powell        mContentHeight = a.getLayoutDimension(
89bc234a19f4c74116454e2c77f4739290e761995aAdam Powell                com.android.internal.R.styleable.ActionMode_height, 0);
909ca705e323cb737a07a667c1e86bac702f11a29cAdam Powell
919ca705e323cb737a07a667c1e86bac702f11a29cAdam Powell        mSplitBackground = a.getDrawable(
929ca705e323cb737a07a667c1e86bac702f11a29cAdam Powell                com.android.internal.R.styleable.ActionMode_backgroundSplit);
939ca705e323cb737a07a667c1e86bac702f11a29cAdam Powell
9489e0645b4157961e8c465eb9c819f965fdb453d8Adam Powell        a.recycle();
9589e0645b4157961e8c465eb9c819f965fdb453d8Adam Powell    }
969146ac706265cd8cce66907e617bc8572152eb97Adam Powell
97a05aba9c506cd12a753c53e060c289095c3477e9Adam Powell    @Override
9897e1836e1b07d91f18de9669c46b0c941b643a72Adam Powell    public void onDetachedFromWindow() {
9997e1836e1b07d91f18de9669c46b0c941b643a72Adam Powell        super.onDetachedFromWindow();
10097e1836e1b07d91f18de9669c46b0c941b643a72Adam Powell        if (mActionMenuPresenter != null) {
10197e1836e1b07d91f18de9669c46b0c941b643a72Adam Powell            mActionMenuPresenter.hideOverflowMenu();
10297e1836e1b07d91f18de9669c46b0c941b643a72Adam Powell            mActionMenuPresenter.hideSubMenus();
10397e1836e1b07d91f18de9669c46b0c941b643a72Adam Powell        }
10497e1836e1b07d91f18de9669c46b0c941b643a72Adam Powell    }
10597e1836e1b07d91f18de9669c46b0c941b643a72Adam Powell
10697e1836e1b07d91f18de9669c46b0c941b643a72Adam Powell    @Override
107a05aba9c506cd12a753c53e060c289095c3477e9Adam Powell    public void setSplitActionBar(boolean split) {
108a05aba9c506cd12a753c53e060c289095c3477e9Adam Powell        if (mSplitActionBar != split) {
109a05aba9c506cd12a753c53e060c289095c3477e9Adam Powell            if (mActionMenuPresenter != null) {
110a05aba9c506cd12a753c53e060c289095c3477e9Adam Powell                // Mode is already active; move everything over and adjust the menu itself.
111a05aba9c506cd12a753c53e060c289095c3477e9Adam Powell                final LayoutParams layoutParams = new LayoutParams(LayoutParams.WRAP_CONTENT,
112a05aba9c506cd12a753c53e060c289095c3477e9Adam Powell                        LayoutParams.MATCH_PARENT);
113a05aba9c506cd12a753c53e060c289095c3477e9Adam Powell                if (!split) {
114a05aba9c506cd12a753c53e060c289095c3477e9Adam Powell                    mMenuView = (ActionMenuView) mActionMenuPresenter.getMenuView(this);
115a05aba9c506cd12a753c53e060c289095c3477e9Adam Powell                    mMenuView.setBackgroundDrawable(null);
116a05aba9c506cd12a753c53e060c289095c3477e9Adam Powell                    final ViewGroup oldParent = (ViewGroup) mMenuView.getParent();
117a05aba9c506cd12a753c53e060c289095c3477e9Adam Powell                    if (oldParent != null) oldParent.removeView(mMenuView);
118a05aba9c506cd12a753c53e060c289095c3477e9Adam Powell                    addView(mMenuView, layoutParams);
119a05aba9c506cd12a753c53e060c289095c3477e9Adam Powell                } else {
120a05aba9c506cd12a753c53e060c289095c3477e9Adam Powell                    // Allow full screen width in split mode.
121a05aba9c506cd12a753c53e060c289095c3477e9Adam Powell                    mActionMenuPresenter.setWidthLimit(
122a05aba9c506cd12a753c53e060c289095c3477e9Adam Powell                            getContext().getResources().getDisplayMetrics().widthPixels, true);
123a05aba9c506cd12a753c53e060c289095c3477e9Adam Powell                    // No limit to the item count; use whatever will fit.
124a05aba9c506cd12a753c53e060c289095c3477e9Adam Powell                    mActionMenuPresenter.setItemLimit(Integer.MAX_VALUE);
125a05aba9c506cd12a753c53e060c289095c3477e9Adam Powell                    // Span the whole width
126a05aba9c506cd12a753c53e060c289095c3477e9Adam Powell                    layoutParams.width = LayoutParams.MATCH_PARENT;
127a05aba9c506cd12a753c53e060c289095c3477e9Adam Powell                    layoutParams.height = mContentHeight;
128a05aba9c506cd12a753c53e060c289095c3477e9Adam Powell                    mMenuView = (ActionMenuView) mActionMenuPresenter.getMenuView(this);
129a05aba9c506cd12a753c53e060c289095c3477e9Adam Powell                    mMenuView.setBackgroundDrawable(mSplitBackground);
130a05aba9c506cd12a753c53e060c289095c3477e9Adam Powell                    final ViewGroup oldParent = (ViewGroup) mMenuView.getParent();
131a05aba9c506cd12a753c53e060c289095c3477e9Adam Powell                    if (oldParent != null) oldParent.removeView(mMenuView);
132a05aba9c506cd12a753c53e060c289095c3477e9Adam Powell                    mSplitView.addView(mMenuView, layoutParams);
133a05aba9c506cd12a753c53e060c289095c3477e9Adam Powell                }
134a05aba9c506cd12a753c53e060c289095c3477e9Adam Powell            }
135a05aba9c506cd12a753c53e060c289095c3477e9Adam Powell            super.setSplitActionBar(split);
136a05aba9c506cd12a753c53e060c289095c3477e9Adam Powell        }
137a05aba9c506cd12a753c53e060c289095c3477e9Adam Powell    }
138a05aba9c506cd12a753c53e060c289095c3477e9Adam Powell
139425689eea2f4f208f29b944b4973981bdbeda9f5Adam Powell    public void setContentHeight(int height) {
140e2194445b078932733a2d1a02fc084ea2f3c7360Adam Powell        mContentHeight = height;
141e2194445b078932733a2d1a02fc084ea2f3c7360Adam Powell    }
142e2194445b078932733a2d1a02fc084ea2f3c7360Adam Powell
14389e0645b4157961e8c465eb9c819f965fdb453d8Adam Powell    public void setCustomView(View view) {
14489e0645b4157961e8c465eb9c819f965fdb453d8Adam Powell        if (mCustomView != null) {
14589e0645b4157961e8c465eb9c819f965fdb453d8Adam Powell            removeView(mCustomView);
14689e0645b4157961e8c465eb9c819f965fdb453d8Adam Powell        }
14789e0645b4157961e8c465eb9c819f965fdb453d8Adam Powell        mCustomView = view;
1480e94b5151d817e600a888448a662208b29b5ef46Adam Powell        if (mTitleLayout != null) {
1490e94b5151d817e600a888448a662208b29b5ef46Adam Powell            removeView(mTitleLayout);
1500e94b5151d817e600a888448a662208b29b5ef46Adam Powell            mTitleLayout = null;
15189e0645b4157961e8c465eb9c819f965fdb453d8Adam Powell        }
15289e0645b4157961e8c465eb9c819f965fdb453d8Adam Powell        if (view != null) {
15389e0645b4157961e8c465eb9c819f965fdb453d8Adam Powell            addView(view);
15489e0645b4157961e8c465eb9c819f965fdb453d8Adam Powell        }
15589e0645b4157961e8c465eb9c819f965fdb453d8Adam Powell        requestLayout();
15689e0645b4157961e8c465eb9c819f965fdb453d8Adam Powell    }
1570e94b5151d817e600a888448a662208b29b5ef46Adam Powell
15889e0645b4157961e8c465eb9c819f965fdb453d8Adam Powell    public void setTitle(CharSequence title) {
15989e0645b4157961e8c465eb9c819f965fdb453d8Adam Powell        mTitle = title;
1600e94b5151d817e600a888448a662208b29b5ef46Adam Powell        initTitle();
1610e94b5151d817e600a888448a662208b29b5ef46Adam Powell    }
1620e94b5151d817e600a888448a662208b29b5ef46Adam Powell
1630e94b5151d817e600a888448a662208b29b5ef46Adam Powell    public void setSubtitle(CharSequence subtitle) {
1640e94b5151d817e600a888448a662208b29b5ef46Adam Powell        mSubtitle = subtitle;
1650e94b5151d817e600a888448a662208b29b5ef46Adam Powell        initTitle();
1660e94b5151d817e600a888448a662208b29b5ef46Adam Powell    }
1670e94b5151d817e600a888448a662208b29b5ef46Adam Powell
16829ed7575c2129974a57ad77b3531bc5995940c6cAdam Powell    public CharSequence getTitle() {
16929ed7575c2129974a57ad77b3531bc5995940c6cAdam Powell        return mTitle;
17029ed7575c2129974a57ad77b3531bc5995940c6cAdam Powell    }
17129ed7575c2129974a57ad77b3531bc5995940c6cAdam Powell
17229ed7575c2129974a57ad77b3531bc5995940c6cAdam Powell    public CharSequence getSubtitle() {
17329ed7575c2129974a57ad77b3531bc5995940c6cAdam Powell        return mSubtitle;
17429ed7575c2129974a57ad77b3531bc5995940c6cAdam Powell    }
17529ed7575c2129974a57ad77b3531bc5995940c6cAdam Powell
1760e94b5151d817e600a888448a662208b29b5ef46Adam Powell    private void initTitle() {
1770e94b5151d817e600a888448a662208b29b5ef46Adam Powell        if (mTitleLayout == null) {
17889e0645b4157961e8c465eb9c819f965fdb453d8Adam Powell            LayoutInflater inflater = LayoutInflater.from(getContext());
179f16888f1e849b0bc0b9c17e5f833c4e2cd54c382Adam Powell            inflater.inflate(R.layout.action_bar_title_item, this);
180f16888f1e849b0bc0b9c17e5f833c4e2cd54c382Adam Powell            mTitleLayout = (LinearLayout) getChildAt(getChildCount() - 1);
1810e94b5151d817e600a888448a662208b29b5ef46Adam Powell            mTitleView = (TextView) mTitleLayout.findViewById(R.id.action_bar_title);
1820e94b5151d817e600a888448a662208b29b5ef46Adam Powell            mSubtitleView = (TextView) mTitleLayout.findViewById(R.id.action_bar_subtitle);
183c619e74cc62678cef09b5f92e87e762a1f02aab7Gilles Debunne            if (mTitleStyleRes != 0) {
184c619e74cc62678cef09b5f92e87e762a1f02aab7Gilles Debunne                mTitleView.setTextAppearance(mContext, mTitleStyleRes);
18589e0645b4157961e8c465eb9c819f965fdb453d8Adam Powell            }
186c619e74cc62678cef09b5f92e87e762a1f02aab7Gilles Debunne            if (mSubtitleStyleRes != 0) {
187c619e74cc62678cef09b5f92e87e762a1f02aab7Gilles Debunne                mSubtitleView.setTextAppearance(mContext, mSubtitleStyleRes);
18889e0645b4157961e8c465eb9c819f965fdb453d8Adam Powell            }
18989e0645b4157961e8c465eb9c819f965fdb453d8Adam Powell        }
190c619e74cc62678cef09b5f92e87e762a1f02aab7Gilles Debunne
191c619e74cc62678cef09b5f92e87e762a1f02aab7Gilles Debunne        mTitleView.setText(mTitle);
192c619e74cc62678cef09b5f92e87e762a1f02aab7Gilles Debunne        mSubtitleView.setText(mSubtitle);
193c619e74cc62678cef09b5f92e87e762a1f02aab7Gilles Debunne
194c619e74cc62678cef09b5f92e87e762a1f02aab7Gilles Debunne        final boolean hasTitle = !TextUtils.isEmpty(mTitle);
195c619e74cc62678cef09b5f92e87e762a1f02aab7Gilles Debunne        final boolean hasSubtitle = !TextUtils.isEmpty(mSubtitle);
196c619e74cc62678cef09b5f92e87e762a1f02aab7Gilles Debunne        mSubtitleView.setVisibility(hasSubtitle ? VISIBLE : GONE);
197c619e74cc62678cef09b5f92e87e762a1f02aab7Gilles Debunne        mTitleLayout.setVisibility(hasTitle || hasSubtitle ? VISIBLE : GONE);
198c619e74cc62678cef09b5f92e87e762a1f02aab7Gilles Debunne        if (mTitleLayout.getParent() == null) {
199c619e74cc62678cef09b5f92e87e762a1f02aab7Gilles Debunne            addView(mTitleLayout);
200c619e74cc62678cef09b5f92e87e762a1f02aab7Gilles Debunne        }
20189e0645b4157961e8c465eb9c819f965fdb453d8Adam Powell    }
2020e94b5151d817e600a888448a662208b29b5ef46Adam Powell
2036e34636749217654f43221885afb7a29bb5ca96aAdam Powell    public void initForMode(final ActionMode mode) {
204f16888f1e849b0bc0b9c17e5f833c4e2cd54c382Adam Powell        if (mClose == null) {
205f16888f1e849b0bc0b9c17e5f833c4e2cd54c382Adam Powell            LayoutInflater inflater = LayoutInflater.from(mContext);
206d8b3f2e8eee5f24de6653a918613674e9495f751Adam Powell            mClose = inflater.inflate(R.layout.action_mode_close_item, this, false);
207d8b3f2e8eee5f24de6653a918613674e9495f751Adam Powell            addView(mClose);
20845f1e08c348ccb129bcc25e438c05421f7123f41Adam Powell        } else if (mClose.getParent() == null) {
209f16888f1e849b0bc0b9c17e5f833c4e2cd54c382Adam Powell            addView(mClose);
21089e0645b4157961e8c465eb9c819f965fdb453d8Adam Powell        }
211f16888f1e849b0bc0b9c17e5f833c4e2cd54c382Adam Powell
212f16888f1e849b0bc0b9c17e5f833c4e2cd54c382Adam Powell        View closeButton = mClose.findViewById(R.id.action_mode_close_button);
213f16888f1e849b0bc0b9c17e5f833c4e2cd54c382Adam Powell        closeButton.setOnClickListener(new OnClickListener() {
214269b8bb0cbd78969450ea9ab255232d047580210Adam Powell            public void onClick(View v) {
215269b8bb0cbd78969450ea9ab255232d047580210Adam Powell                mode.finish();
216269b8bb0cbd78969450ea9ab255232d047580210Adam Powell            }
217269b8bb0cbd78969450ea9ab255232d047580210Adam Powell        });
21889e0645b4157961e8c465eb9c819f965fdb453d8Adam Powell
2192c9c9fe806e51f29276e66b8ba40cb4b7a80c3f4Adam Powell        final MenuBuilder menu = (MenuBuilder) mode.getMenu();
220678ed0c5a32bac1ea18a5ac99b0b814421ea79b4Adam Powell        if (mActionMenuPresenter != null) {
221678ed0c5a32bac1ea18a5ac99b0b814421ea79b4Adam Powell            mActionMenuPresenter.dismissPopupMenus();
222678ed0c5a32bac1ea18a5ac99b0b814421ea79b4Adam Powell        }
223538e565c06e915b91e7e3a901f872ccdd9bccdd3Adam Powell        mActionMenuPresenter = new ActionMenuPresenter(mContext);
2241ab418a222e1834c4b1312fde355e41a1947af0dAdam Powell        mActionMenuPresenter.setReserveOverflow(true);
225640a66eac612b850b5dabd3b93bd94f83ed2d567Adam Powell
226640a66eac612b850b5dabd3b93bd94f83ed2d567Adam Powell        final LayoutParams layoutParams = new LayoutParams(LayoutParams.WRAP_CONTENT,
227640a66eac612b850b5dabd3b93bd94f83ed2d567Adam Powell                LayoutParams.MATCH_PARENT);
228a05aba9c506cd12a753c53e060c289095c3477e9Adam Powell        if (!mSplitActionBar) {
2291ab418a222e1834c4b1312fde355e41a1947af0dAdam Powell            menu.addMenuPresenter(mActionMenuPresenter);
2301ab418a222e1834c4b1312fde355e41a1947af0dAdam Powell            mMenuView = (ActionMenuView) mActionMenuPresenter.getMenuView(this);
2319ca705e323cb737a07a667c1e86bac702f11a29cAdam Powell            mMenuView.setBackgroundDrawable(null);
2321ab418a222e1834c4b1312fde355e41a1947af0dAdam Powell            addView(mMenuView, layoutParams);
233640a66eac612b850b5dabd3b93bd94f83ed2d567Adam Powell        } else {
234640a66eac612b850b5dabd3b93bd94f83ed2d567Adam Powell            // Allow full screen width in split mode.
2358d02deabac62c4a68a335a7b3141795466362b89Adam Powell            mActionMenuPresenter.setWidthLimit(
236640a66eac612b850b5dabd3b93bd94f83ed2d567Adam Powell                    getContext().getResources().getDisplayMetrics().widthPixels, true);
237640a66eac612b850b5dabd3b93bd94f83ed2d567Adam Powell            // No limit to the item count; use whatever will fit.
2388d02deabac62c4a68a335a7b3141795466362b89Adam Powell            mActionMenuPresenter.setItemLimit(Integer.MAX_VALUE);
239640a66eac612b850b5dabd3b93bd94f83ed2d567Adam Powell            // Span the whole width
240640a66eac612b850b5dabd3b93bd94f83ed2d567Adam Powell            layoutParams.width = LayoutParams.MATCH_PARENT;
2411ab418a222e1834c4b1312fde355e41a1947af0dAdam Powell            layoutParams.height = mContentHeight;
2421ab418a222e1834c4b1312fde355e41a1947af0dAdam Powell            menu.addMenuPresenter(mActionMenuPresenter);
2431ab418a222e1834c4b1312fde355e41a1947af0dAdam Powell            mMenuView = (ActionMenuView) mActionMenuPresenter.getMenuView(this);
2449ca705e323cb737a07a667c1e86bac702f11a29cAdam Powell            mMenuView.setBackgroundDrawable(mSplitBackground);
2451ab418a222e1834c4b1312fde355e41a1947af0dAdam Powell            mSplitView.addView(mMenuView, layoutParams);
246640a66eac612b850b5dabd3b93bd94f83ed2d567Adam Powell        }
247d8b3f2e8eee5f24de6653a918613674e9495f751Adam Powell
248d8b3f2e8eee5f24de6653a918613674e9495f751Adam Powell        mAnimateInOnLayout = true;
24989e0645b4157961e8c465eb9c819f965fdb453d8Adam Powell    }
2500e94b5151d817e600a888448a662208b29b5ef46Adam Powell
25189e0645b4157961e8c465eb9c819f965fdb453d8Adam Powell    public void closeMode() {
25245f1e08c348ccb129bcc25e438c05421f7123f41Adam Powell        if (mAnimationMode == ANIMATE_OUT) {
25345f1e08c348ccb129bcc25e438c05421f7123f41Adam Powell            // Called again during close; just finish what we were doing.
25445f1e08c348ccb129bcc25e438c05421f7123f41Adam Powell            return;
25545f1e08c348ccb129bcc25e438c05421f7123f41Adam Powell        }
256d8b3f2e8eee5f24de6653a918613674e9495f751Adam Powell        if (mClose == null) {
257d8b3f2e8eee5f24de6653a918613674e9495f751Adam Powell            killMode();
258d8b3f2e8eee5f24de6653a918613674e9495f751Adam Powell            return;
259d8b3f2e8eee5f24de6653a918613674e9495f751Adam Powell        }
260d8b3f2e8eee5f24de6653a918613674e9495f751Adam Powell
261d8b3f2e8eee5f24de6653a918613674e9495f751Adam Powell        finishAnimation();
262a1e6358a4c62c8b6de1f2428901e45b688bd9e9fAdam Powell        mAnimationMode = ANIMATE_OUT;
263d8b3f2e8eee5f24de6653a918613674e9495f751Adam Powell        mCurrentAnimation = makeOutAnimation();
264d8b3f2e8eee5f24de6653a918613674e9495f751Adam Powell        mCurrentAnimation.start();
265d8b3f2e8eee5f24de6653a918613674e9495f751Adam Powell    }
266d8b3f2e8eee5f24de6653a918613674e9495f751Adam Powell
267d8b3f2e8eee5f24de6653a918613674e9495f751Adam Powell    private void finishAnimation() {
26845f1e08c348ccb129bcc25e438c05421f7123f41Adam Powell        final Animator a = mCurrentAnimation;
269a1e6358a4c62c8b6de1f2428901e45b688bd9e9fAdam Powell        if (a != null) {
27045f1e08c348ccb129bcc25e438c05421f7123f41Adam Powell            mCurrentAnimation = null;
27145f1e08c348ccb129bcc25e438c05421f7123f41Adam Powell            a.end();
272d8b3f2e8eee5f24de6653a918613674e9495f751Adam Powell        }
273d8b3f2e8eee5f24de6653a918613674e9495f751Adam Powell    }
274d8b3f2e8eee5f24de6653a918613674e9495f751Adam Powell
275d8b3f2e8eee5f24de6653a918613674e9495f751Adam Powell    public void killMode() {
276d8b3f2e8eee5f24de6653a918613674e9495f751Adam Powell        finishAnimation();
27789e0645b4157961e8c465eb9c819f965fdb453d8Adam Powell        removeAllViews();
278640a66eac612b850b5dabd3b93bd94f83ed2d567Adam Powell        if (mSplitView != null) {
279640a66eac612b850b5dabd3b93bd94f83ed2d567Adam Powell            mSplitView.removeView(mMenuView);
280640a66eac612b850b5dabd3b93bd94f83ed2d567Adam Powell        }
28189e0645b4157961e8c465eb9c819f965fdb453d8Adam Powell        mCustomView = null;
2822c9c9fe806e51f29276e66b8ba40cb4b7a80c3f4Adam Powell        mMenuView = null;
28300bba682efedbe121f31c98697f91101b1c22b82Adam Powell        mAnimateInOnLayout = false;
28489e0645b4157961e8c465eb9c819f965fdb453d8Adam Powell    }
2850e94b5151d817e600a888448a662208b29b5ef46Adam Powell
286c619e74cc62678cef09b5f92e87e762a1f02aab7Gilles Debunne    @Override
287f6148c53f93978af678cc0559a4417b608a33ae1Adam Powell    public boolean showOverflowMenu() {
2888d02deabac62c4a68a335a7b3141795466362b89Adam Powell        if (mActionMenuPresenter != null) {
2898d02deabac62c4a68a335a7b3141795466362b89Adam Powell            return mActionMenuPresenter.showOverflowMenu();
290f6148c53f93978af678cc0559a4417b608a33ae1Adam Powell        }
291f6148c53f93978af678cc0559a4417b608a33ae1Adam Powell        return false;
292f6148c53f93978af678cc0559a4417b608a33ae1Adam Powell    }
293f6148c53f93978af678cc0559a4417b608a33ae1Adam Powell
294c619e74cc62678cef09b5f92e87e762a1f02aab7Gilles Debunne    @Override
295f6148c53f93978af678cc0559a4417b608a33ae1Adam Powell    public boolean hideOverflowMenu() {
2968d02deabac62c4a68a335a7b3141795466362b89Adam Powell        if (mActionMenuPresenter != null) {
2978d02deabac62c4a68a335a7b3141795466362b89Adam Powell            return mActionMenuPresenter.hideOverflowMenu();
298f6148c53f93978af678cc0559a4417b608a33ae1Adam Powell        }
299f6148c53f93978af678cc0559a4417b608a33ae1Adam Powell        return false;
300f6148c53f93978af678cc0559a4417b608a33ae1Adam Powell    }
301f6148c53f93978af678cc0559a4417b608a33ae1Adam Powell
302c619e74cc62678cef09b5f92e87e762a1f02aab7Gilles Debunne    @Override
303f6148c53f93978af678cc0559a4417b608a33ae1Adam Powell    public boolean isOverflowMenuShowing() {
3048d02deabac62c4a68a335a7b3141795466362b89Adam Powell        if (mActionMenuPresenter != null) {
3058d02deabac62c4a68a335a7b3141795466362b89Adam Powell            return mActionMenuPresenter.isOverflowMenuShowing();
306f6148c53f93978af678cc0559a4417b608a33ae1Adam Powell        }
307f6148c53f93978af678cc0559a4417b608a33ae1Adam Powell        return false;
308f6148c53f93978af678cc0559a4417b608a33ae1Adam Powell    }
309f6148c53f93978af678cc0559a4417b608a33ae1Adam Powell
31089e0645b4157961e8c465eb9c819f965fdb453d8Adam Powell    @Override
3119a5cc2810bbbcb0eab4579aa4131039820d92101Adam Powell    protected ViewGroup.LayoutParams generateDefaultLayoutParams() {
312a7db03705f53c59e63e63c2e67e2db78f8226dccAdam Powell        // Used by custom views if they don't supply layout params. Everything else
313a7db03705f53c59e63e63c2e67e2db78f8226dccAdam Powell        // added to an ActionBarContextView should have them already.
3149ca705e323cb737a07a667c1e86bac702f11a29cAdam Powell        return new MarginLayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT);
3159ca705e323cb737a07a667c1e86bac702f11a29cAdam Powell    }
3169ca705e323cb737a07a667c1e86bac702f11a29cAdam Powell
3179ca705e323cb737a07a667c1e86bac702f11a29cAdam Powell    @Override
3189a5cc2810bbbcb0eab4579aa4131039820d92101Adam Powell    public ViewGroup.LayoutParams generateLayoutParams(AttributeSet attrs) {
3199ca705e323cb737a07a667c1e86bac702f11a29cAdam Powell        return new MarginLayoutParams(getContext(), attrs);
320a7db03705f53c59e63e63c2e67e2db78f8226dccAdam Powell    }
321a7db03705f53c59e63e63c2e67e2db78f8226dccAdam Powell
322a7db03705f53c59e63e63c2e67e2db78f8226dccAdam Powell    @Override
32389e0645b4157961e8c465eb9c819f965fdb453d8Adam Powell    protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
32489e0645b4157961e8c465eb9c819f965fdb453d8Adam Powell        final int widthMode = MeasureSpec.getMode(widthMeasureSpec);
32589e0645b4157961e8c465eb9c819f965fdb453d8Adam Powell        if (widthMode != MeasureSpec.EXACTLY) {
32689e0645b4157961e8c465eb9c819f965fdb453d8Adam Powell            throw new IllegalStateException(getClass().getSimpleName() + " can only be used " +
32789e0645b4157961e8c465eb9c819f965fdb453d8Adam Powell                    "with android:layout_width=\"match_parent\" (or fill_parent)");
32889e0645b4157961e8c465eb9c819f965fdb453d8Adam Powell        }
32989e0645b4157961e8c465eb9c819f965fdb453d8Adam Powell
33089e0645b4157961e8c465eb9c819f965fdb453d8Adam Powell        final int heightMode = MeasureSpec.getMode(heightMeasureSpec);
33185446e95afa480cee2247bb96795fccc8cf812afAdam Powell        if (heightMode == MeasureSpec.UNSPECIFIED) {
33289e0645b4157961e8c465eb9c819f965fdb453d8Adam Powell            throw new IllegalStateException(getClass().getSimpleName() + " can only be used " +
33389e0645b4157961e8c465eb9c819f965fdb453d8Adam Powell                    "with android:layout_height=\"wrap_content\"");
33489e0645b4157961e8c465eb9c819f965fdb453d8Adam Powell        }
33589e0645b4157961e8c465eb9c819f965fdb453d8Adam Powell
33689e0645b4157961e8c465eb9c819f965fdb453d8Adam Powell        final int contentWidth = MeasureSpec.getSize(widthMeasureSpec);
33789e0645b4157961e8c465eb9c819f965fdb453d8Adam Powell
338e2194445b078932733a2d1a02fc084ea2f3c7360Adam Powell        int maxHeight = mContentHeight > 0 ?
339e2194445b078932733a2d1a02fc084ea2f3c7360Adam Powell                mContentHeight : MeasureSpec.getSize(heightMeasureSpec);
340e2194445b078932733a2d1a02fc084ea2f3c7360Adam Powell
341e2194445b078932733a2d1a02fc084ea2f3c7360Adam Powell        final int verticalPadding = getPaddingTop() + getPaddingBottom();
34289e0645b4157961e8c465eb9c819f965fdb453d8Adam Powell        int availableWidth = contentWidth - getPaddingLeft() - getPaddingRight();
343e2194445b078932733a2d1a02fc084ea2f3c7360Adam Powell        final int height = maxHeight - verticalPadding;
34489e0645b4157961e8c465eb9c819f965fdb453d8Adam Powell        final int childSpecHeight = MeasureSpec.makeMeasureSpec(height, MeasureSpec.AT_MOST);
34589e0645b4157961e8c465eb9c819f965fdb453d8Adam Powell
346f16888f1e849b0bc0b9c17e5f833c4e2cd54c382Adam Powell        if (mClose != null) {
347f16888f1e849b0bc0b9c17e5f833c4e2cd54c382Adam Powell            availableWidth = measureChildView(mClose, availableWidth, childSpecHeight, 0);
3489ca705e323cb737a07a667c1e86bac702f11a29cAdam Powell            MarginLayoutParams lp = (MarginLayoutParams) mClose.getLayoutParams();
3499ca705e323cb737a07a667c1e86bac702f11a29cAdam Powell            availableWidth -= lp.leftMargin + lp.rightMargin;
35089e0645b4157961e8c465eb9c819f965fdb453d8Adam Powell        }
35189e0645b4157961e8c465eb9c819f965fdb453d8Adam Powell
352f6ce6a9bacbb220c6ea7b552c481237f23e64ae7Adam Powell        if (mMenuView != null && mMenuView.getParent() == this) {
353b0ff6f995553a5deb1f22e43e44715b316d33a88Adam Powell            availableWidth = measureChildView(mMenuView, availableWidth,
354b0ff6f995553a5deb1f22e43e44715b316d33a88Adam Powell                    childSpecHeight, 0);
35589e0645b4157961e8c465eb9c819f965fdb453d8Adam Powell        }
35689e0645b4157961e8c465eb9c819f965fdb453d8Adam Powell
357b0ff6f995553a5deb1f22e43e44715b316d33a88Adam Powell        if (mTitleLayout != null && mCustomView == null) {
358b98a81f86ab87f1d718f329f03256111fdabd8d1Adam Powell            if (mTitleOptional) {
359b98a81f86ab87f1d718f329f03256111fdabd8d1Adam Powell                final int titleWidthSpec = MeasureSpec.makeMeasureSpec(0, MeasureSpec.UNSPECIFIED);
360b98a81f86ab87f1d718f329f03256111fdabd8d1Adam Powell                mTitleLayout.measure(titleWidthSpec, childSpecHeight);
361b98a81f86ab87f1d718f329f03256111fdabd8d1Adam Powell                final int titleWidth = mTitleLayout.getMeasuredWidth();
362b98a81f86ab87f1d718f329f03256111fdabd8d1Adam Powell                final boolean titleFits = titleWidth <= availableWidth;
363b98a81f86ab87f1d718f329f03256111fdabd8d1Adam Powell                if (titleFits) {
364b98a81f86ab87f1d718f329f03256111fdabd8d1Adam Powell                    availableWidth -= titleWidth;
365b98a81f86ab87f1d718f329f03256111fdabd8d1Adam Powell                }
366b98a81f86ab87f1d718f329f03256111fdabd8d1Adam Powell                mTitleLayout.setVisibility(titleFits ? VISIBLE : GONE);
367b98a81f86ab87f1d718f329f03256111fdabd8d1Adam Powell            } else {
368b98a81f86ab87f1d718f329f03256111fdabd8d1Adam Powell                availableWidth = measureChildView(mTitleLayout, availableWidth, childSpecHeight, 0);
369b98a81f86ab87f1d718f329f03256111fdabd8d1Adam Powell            }
37089e0645b4157961e8c465eb9c819f965fdb453d8Adam Powell        }
37189e0645b4157961e8c465eb9c819f965fdb453d8Adam Powell
37289e0645b4157961e8c465eb9c819f965fdb453d8Adam Powell        if (mCustomView != null) {
3739a5cc2810bbbcb0eab4579aa4131039820d92101Adam Powell            ViewGroup.LayoutParams lp = mCustomView.getLayoutParams();
374a7db03705f53c59e63e63c2e67e2db78f8226dccAdam Powell            final int customWidthMode = lp.width != LayoutParams.WRAP_CONTENT ?
375a7db03705f53c59e63e63c2e67e2db78f8226dccAdam Powell                    MeasureSpec.EXACTLY : MeasureSpec.AT_MOST;
376a7db03705f53c59e63e63c2e67e2db78f8226dccAdam Powell            final int customWidth = lp.width >= 0 ?
377a7db03705f53c59e63e63c2e67e2db78f8226dccAdam Powell                    Math.min(lp.width, availableWidth) : availableWidth;
378a7db03705f53c59e63e63c2e67e2db78f8226dccAdam Powell            final int customHeightMode = lp.height != LayoutParams.WRAP_CONTENT ?
379a7db03705f53c59e63e63c2e67e2db78f8226dccAdam Powell                    MeasureSpec.EXACTLY : MeasureSpec.AT_MOST;
380a7db03705f53c59e63e63c2e67e2db78f8226dccAdam Powell            final int customHeight = lp.height >= 0 ?
381a7db03705f53c59e63e63c2e67e2db78f8226dccAdam Powell                    Math.min(lp.height, height) : height;
382a7db03705f53c59e63e63c2e67e2db78f8226dccAdam Powell            mCustomView.measure(MeasureSpec.makeMeasureSpec(customWidth, customWidthMode),
383a7db03705f53c59e63e63c2e67e2db78f8226dccAdam Powell                    MeasureSpec.makeMeasureSpec(customHeight, customHeightMode));
38489e0645b4157961e8c465eb9c819f965fdb453d8Adam Powell        }
38589e0645b4157961e8c465eb9c819f965fdb453d8Adam Powell
386e2194445b078932733a2d1a02fc084ea2f3c7360Adam Powell        if (mContentHeight <= 0) {
387e2194445b078932733a2d1a02fc084ea2f3c7360Adam Powell            int measuredHeight = 0;
388e2194445b078932733a2d1a02fc084ea2f3c7360Adam Powell            final int count = getChildCount();
389e2194445b078932733a2d1a02fc084ea2f3c7360Adam Powell            for (int i = 0; i < count; i++) {
390e2194445b078932733a2d1a02fc084ea2f3c7360Adam Powell                View v = getChildAt(i);
391e2194445b078932733a2d1a02fc084ea2f3c7360Adam Powell                int paddedViewHeight = v.getMeasuredHeight() + verticalPadding;
392e2194445b078932733a2d1a02fc084ea2f3c7360Adam Powell                if (paddedViewHeight > measuredHeight) {
393e2194445b078932733a2d1a02fc084ea2f3c7360Adam Powell                    measuredHeight = paddedViewHeight;
394e2194445b078932733a2d1a02fc084ea2f3c7360Adam Powell                }
395e2194445b078932733a2d1a02fc084ea2f3c7360Adam Powell            }
396e2194445b078932733a2d1a02fc084ea2f3c7360Adam Powell            setMeasuredDimension(contentWidth, measuredHeight);
397e2194445b078932733a2d1a02fc084ea2f3c7360Adam Powell        } else {
398e2194445b078932733a2d1a02fc084ea2f3c7360Adam Powell            setMeasuredDimension(contentWidth, maxHeight);
399e2194445b078932733a2d1a02fc084ea2f3c7360Adam Powell        }
40089e0645b4157961e8c465eb9c819f965fdb453d8Adam Powell    }
40189e0645b4157961e8c465eb9c819f965fdb453d8Adam Powell
402d8b3f2e8eee5f24de6653a918613674e9495f751Adam Powell    private Animator makeInAnimation() {
4039ca705e323cb737a07a667c1e86bac702f11a29cAdam Powell        mClose.setTranslationX(-mClose.getWidth() -
4049ca705e323cb737a07a667c1e86bac702f11a29cAdam Powell                ((MarginLayoutParams) mClose.getLayoutParams()).leftMargin);
405d8b3f2e8eee5f24de6653a918613674e9495f751Adam Powell        ObjectAnimator buttonAnimator = ObjectAnimator.ofFloat(mClose, "translationX", 0);
406d8b3f2e8eee5f24de6653a918613674e9495f751Adam Powell        buttonAnimator.setDuration(200);
407d8b3f2e8eee5f24de6653a918613674e9495f751Adam Powell        buttonAnimator.addListener(this);
408d8b3f2e8eee5f24de6653a918613674e9495f751Adam Powell        buttonAnimator.setInterpolator(new DecelerateInterpolator());
409d8b3f2e8eee5f24de6653a918613674e9495f751Adam Powell
410d8b3f2e8eee5f24de6653a918613674e9495f751Adam Powell        AnimatorSet set = new AnimatorSet();
411d8b3f2e8eee5f24de6653a918613674e9495f751Adam Powell        AnimatorSet.Builder b = set.play(buttonAnimator);
412d8b3f2e8eee5f24de6653a918613674e9495f751Adam Powell
413d8b3f2e8eee5f24de6653a918613674e9495f751Adam Powell        if (mMenuView != null) {
414d8b3f2e8eee5f24de6653a918613674e9495f751Adam Powell            final int count = mMenuView.getChildCount();
415d8b3f2e8eee5f24de6653a918613674e9495f751Adam Powell            if (count > 0) {
416d8b3f2e8eee5f24de6653a918613674e9495f751Adam Powell                for (int i = count - 1, j = 0; i >= 0; i--, j++) {
417d8b3f2e8eee5f24de6653a918613674e9495f751Adam Powell                    View child = mMenuView.getChildAt(i);
418d8b3f2e8eee5f24de6653a918613674e9495f751Adam Powell                    child.setScaleY(0);
419d8b3f2e8eee5f24de6653a918613674e9495f751Adam Powell                    ObjectAnimator a = ObjectAnimator.ofFloat(child, "scaleY", 0, 1);
420482ae5f2388a07d60d7f3b54432120172af25eeeAdam Powell                    a.setDuration(300);
421d8b3f2e8eee5f24de6653a918613674e9495f751Adam Powell                    b.with(a);
422d8b3f2e8eee5f24de6653a918613674e9495f751Adam Powell                }
423d8b3f2e8eee5f24de6653a918613674e9495f751Adam Powell            }
424d8b3f2e8eee5f24de6653a918613674e9495f751Adam Powell        }
425d8b3f2e8eee5f24de6653a918613674e9495f751Adam Powell
426d8b3f2e8eee5f24de6653a918613674e9495f751Adam Powell        return set;
427d8b3f2e8eee5f24de6653a918613674e9495f751Adam Powell    }
428d8b3f2e8eee5f24de6653a918613674e9495f751Adam Powell
429d8b3f2e8eee5f24de6653a918613674e9495f751Adam Powell    private Animator makeOutAnimation() {
430d8b3f2e8eee5f24de6653a918613674e9495f751Adam Powell        ObjectAnimator buttonAnimator = ObjectAnimator.ofFloat(mClose, "translationX",
4319ca705e323cb737a07a667c1e86bac702f11a29cAdam Powell                -mClose.getWidth() - ((MarginLayoutParams) mClose.getLayoutParams()).leftMargin);
432d8b3f2e8eee5f24de6653a918613674e9495f751Adam Powell        buttonAnimator.setDuration(200);
433d8b3f2e8eee5f24de6653a918613674e9495f751Adam Powell        buttonAnimator.addListener(this);
434d8b3f2e8eee5f24de6653a918613674e9495f751Adam Powell        buttonAnimator.setInterpolator(new DecelerateInterpolator());
435d8b3f2e8eee5f24de6653a918613674e9495f751Adam Powell
436d8b3f2e8eee5f24de6653a918613674e9495f751Adam Powell        AnimatorSet set = new AnimatorSet();
437d8b3f2e8eee5f24de6653a918613674e9495f751Adam Powell        AnimatorSet.Builder b = set.play(buttonAnimator);
438d8b3f2e8eee5f24de6653a918613674e9495f751Adam Powell
439d8b3f2e8eee5f24de6653a918613674e9495f751Adam Powell        if (mMenuView != null) {
440d8b3f2e8eee5f24de6653a918613674e9495f751Adam Powell            final int count = mMenuView.getChildCount();
441d8b3f2e8eee5f24de6653a918613674e9495f751Adam Powell            if (count > 0) {
442d8b3f2e8eee5f24de6653a918613674e9495f751Adam Powell                for (int i = 0; i < 0; i++) {
443d8b3f2e8eee5f24de6653a918613674e9495f751Adam Powell                    View child = mMenuView.getChildAt(i);
444d8b3f2e8eee5f24de6653a918613674e9495f751Adam Powell                    child.setScaleY(0);
445640a66eac612b850b5dabd3b93bd94f83ed2d567Adam Powell                    ObjectAnimator a = ObjectAnimator.ofFloat(child, "scaleY", 0);
446482ae5f2388a07d60d7f3b54432120172af25eeeAdam Powell                    a.setDuration(300);
447d8b3f2e8eee5f24de6653a918613674e9495f751Adam Powell                    b.with(a);
448d8b3f2e8eee5f24de6653a918613674e9495f751Adam Powell                }
449d8b3f2e8eee5f24de6653a918613674e9495f751Adam Powell            }
450d8b3f2e8eee5f24de6653a918613674e9495f751Adam Powell        }
451d8b3f2e8eee5f24de6653a918613674e9495f751Adam Powell
452d8b3f2e8eee5f24de6653a918613674e9495f751Adam Powell        return set;
453d8b3f2e8eee5f24de6653a918613674e9495f751Adam Powell    }
454d8b3f2e8eee5f24de6653a918613674e9495f751Adam Powell
45589e0645b4157961e8c465eb9c819f965fdb453d8Adam Powell    @Override
45689e0645b4157961e8c465eb9c819f965fdb453d8Adam Powell    protected void onLayout(boolean changed, int l, int t, int r, int b) {
457cf1ba0298c48ae56608ed556dc715eb69c54f9b9Fabrice Di Meglio        final boolean isLayoutRtl = isLayoutRtl();
458cf1ba0298c48ae56608ed556dc715eb69c54f9b9Fabrice Di Meglio        int x = isLayoutRtl ? r - l - getPaddingRight() : getPaddingLeft();
45989e0645b4157961e8c465eb9c819f965fdb453d8Adam Powell        final int y = getPaddingTop();
46089e0645b4157961e8c465eb9c819f965fdb453d8Adam Powell        final int contentHeight = b - t - getPaddingTop() - getPaddingBottom();
46189e0645b4157961e8c465eb9c819f965fdb453d8Adam Powell
462f16888f1e849b0bc0b9c17e5f833c4e2cd54c382Adam Powell        if (mClose != null && mClose.getVisibility() != GONE) {
4639ca705e323cb737a07a667c1e86bac702f11a29cAdam Powell            MarginLayoutParams lp = (MarginLayoutParams) mClose.getLayoutParams();
464cf1ba0298c48ae56608ed556dc715eb69c54f9b9Fabrice Di Meglio            final int startMargin = (isLayoutRtl ? lp.rightMargin : lp.leftMargin);
465cf1ba0298c48ae56608ed556dc715eb69c54f9b9Fabrice Di Meglio            final int endMargin = (isLayoutRtl ? lp.leftMargin : lp.rightMargin);
466cf1ba0298c48ae56608ed556dc715eb69c54f9b9Fabrice Di Meglio            x = next(x, startMargin, isLayoutRtl);
467cf1ba0298c48ae56608ed556dc715eb69c54f9b9Fabrice Di Meglio            x += positionChild(mClose, x, y, contentHeight, isLayoutRtl);
468cf1ba0298c48ae56608ed556dc715eb69c54f9b9Fabrice Di Meglio            x = next(x, endMargin, isLayoutRtl);
469d8b3f2e8eee5f24de6653a918613674e9495f751Adam Powell
470d8b3f2e8eee5f24de6653a918613674e9495f751Adam Powell            if (mAnimateInOnLayout) {
471d8b3f2e8eee5f24de6653a918613674e9495f751Adam Powell                mAnimationMode = ANIMATE_IN;
472d8b3f2e8eee5f24de6653a918613674e9495f751Adam Powell                mCurrentAnimation = makeInAnimation();
473d8b3f2e8eee5f24de6653a918613674e9495f751Adam Powell                mCurrentAnimation.start();
474d8b3f2e8eee5f24de6653a918613674e9495f751Adam Powell                mAnimateInOnLayout = false;
475d8b3f2e8eee5f24de6653a918613674e9495f751Adam Powell            }
47689e0645b4157961e8c465eb9c819f965fdb453d8Adam Powell        }
477640a66eac612b850b5dabd3b93bd94f83ed2d567Adam Powell
478b98a81f86ab87f1d718f329f03256111fdabd8d1Adam Powell        if (mTitleLayout != null && mCustomView == null && mTitleLayout.getVisibility() != GONE) {
479cf1ba0298c48ae56608ed556dc715eb69c54f9b9Fabrice Di Meglio            x += positionChild(mTitleLayout, x, y, contentHeight, isLayoutRtl);
48089e0645b4157961e8c465eb9c819f965fdb453d8Adam Powell        }
48189e0645b4157961e8c465eb9c819f965fdb453d8Adam Powell
48289e0645b4157961e8c465eb9c819f965fdb453d8Adam Powell        if (mCustomView != null) {
483cf1ba0298c48ae56608ed556dc715eb69c54f9b9Fabrice Di Meglio            x += positionChild(mCustomView, x, y, contentHeight, isLayoutRtl);
48489e0645b4157961e8c465eb9c819f965fdb453d8Adam Powell        }
485cf1ba0298c48ae56608ed556dc715eb69c54f9b9Fabrice Di Meglio
486cf1ba0298c48ae56608ed556dc715eb69c54f9b9Fabrice Di Meglio        x = isLayoutRtl ? getPaddingLeft() : r - l - getPaddingRight();
48789e0645b4157961e8c465eb9c819f965fdb453d8Adam Powell
4882c9c9fe806e51f29276e66b8ba40cb4b7a80c3f4Adam Powell        if (mMenuView != null) {
489cf1ba0298c48ae56608ed556dc715eb69c54f9b9Fabrice Di Meglio            x += positionChild(mMenuView, x, y, contentHeight, !isLayoutRtl);
49089e0645b4157961e8c465eb9c819f965fdb453d8Adam Powell        }
49189e0645b4157961e8c465eb9c819f965fdb453d8Adam Powell    }
49289e0645b4157961e8c465eb9c819f965fdb453d8Adam Powell
493d8b3f2e8eee5f24de6653a918613674e9495f751Adam Powell    @Override
494d8b3f2e8eee5f24de6653a918613674e9495f751Adam Powell    public void onAnimationStart(Animator animation) {
495d8b3f2e8eee5f24de6653a918613674e9495f751Adam Powell    }
496d8b3f2e8eee5f24de6653a918613674e9495f751Adam Powell
497d8b3f2e8eee5f24de6653a918613674e9495f751Adam Powell    @Override
498d8b3f2e8eee5f24de6653a918613674e9495f751Adam Powell    public void onAnimationEnd(Animator animation) {
499a1e6358a4c62c8b6de1f2428901e45b688bd9e9fAdam Powell        if (mAnimationMode == ANIMATE_OUT) {
500d8b3f2e8eee5f24de6653a918613674e9495f751Adam Powell            killMode();
501d8b3f2e8eee5f24de6653a918613674e9495f751Adam Powell        }
502d8b3f2e8eee5f24de6653a918613674e9495f751Adam Powell        mAnimationMode = ANIMATE_IDLE;
503d8b3f2e8eee5f24de6653a918613674e9495f751Adam Powell    }
504d8b3f2e8eee5f24de6653a918613674e9495f751Adam Powell
505d8b3f2e8eee5f24de6653a918613674e9495f751Adam Powell    @Override
506d8b3f2e8eee5f24de6653a918613674e9495f751Adam Powell    public void onAnimationCancel(Animator animation) {
507d8b3f2e8eee5f24de6653a918613674e9495f751Adam Powell    }
508d8b3f2e8eee5f24de6653a918613674e9495f751Adam Powell
509d8b3f2e8eee5f24de6653a918613674e9495f751Adam Powell    @Override
510d8b3f2e8eee5f24de6653a918613674e9495f751Adam Powell    public void onAnimationRepeat(Animator animation) {
511d8b3f2e8eee5f24de6653a918613674e9495f751Adam Powell    }
512e0a799a2ac1ca78e30fbac9e4e12a063425c08d3Patrick Dubroy
513e0a799a2ac1ca78e30fbac9e4e12a063425c08d3Patrick Dubroy    @Override
514e0a799a2ac1ca78e30fbac9e4e12a063425c08d3Patrick Dubroy    public boolean shouldDelayChildPressedState() {
515e0a799a2ac1ca78e30fbac9e4e12a063425c08d3Patrick Dubroy        return false;
516e0a799a2ac1ca78e30fbac9e4e12a063425c08d3Patrick Dubroy    }
51786ed436b83d6b71ff00d1c3db910f2952018489eAdam Powell
51886ed436b83d6b71ff00d1c3db910f2952018489eAdam Powell    @Override
51986ed436b83d6b71ff00d1c3db910f2952018489eAdam Powell    public void onInitializeAccessibilityEvent(AccessibilityEvent event) {
52086ed436b83d6b71ff00d1c3db910f2952018489eAdam Powell        if (event.getEventType() == AccessibilityEvent.TYPE_WINDOW_STATE_CHANGED) {
52186ed436b83d6b71ff00d1c3db910f2952018489eAdam Powell            // Action mode started
52286ed436b83d6b71ff00d1c3db910f2952018489eAdam Powell            event.setSource(this);
52386ed436b83d6b71ff00d1c3db910f2952018489eAdam Powell            event.setClassName(getClass().getName());
52486ed436b83d6b71ff00d1c3db910f2952018489eAdam Powell            event.setPackageName(getContext().getPackageName());
52586ed436b83d6b71ff00d1c3db910f2952018489eAdam Powell            event.setContentDescription(mTitle);
52686ed436b83d6b71ff00d1c3db910f2952018489eAdam Powell        } else {
52786ed436b83d6b71ff00d1c3db910f2952018489eAdam Powell            super.onInitializeAccessibilityEvent(event);
52886ed436b83d6b71ff00d1c3db910f2952018489eAdam Powell        }
52986ed436b83d6b71ff00d1c3db910f2952018489eAdam Powell    }
530b98a81f86ab87f1d718f329f03256111fdabd8d1Adam Powell
531b98a81f86ab87f1d718f329f03256111fdabd8d1Adam Powell    public void setTitleOptional(boolean titleOptional) {
532b98a81f86ab87f1d718f329f03256111fdabd8d1Adam Powell        if (titleOptional != mTitleOptional) {
533b98a81f86ab87f1d718f329f03256111fdabd8d1Adam Powell            requestLayout();
534b98a81f86ab87f1d718f329f03256111fdabd8d1Adam Powell        }
535b98a81f86ab87f1d718f329f03256111fdabd8d1Adam Powell        mTitleOptional = titleOptional;
536b98a81f86ab87f1d718f329f03256111fdabd8d1Adam Powell    }
537b98a81f86ab87f1d718f329f03256111fdabd8d1Adam Powell
538b98a81f86ab87f1d718f329f03256111fdabd8d1Adam Powell    public boolean isTitleOptional() {
539b98a81f86ab87f1d718f329f03256111fdabd8d1Adam Powell        return mTitleOptional;
540b98a81f86ab87f1d718f329f03256111fdabd8d1Adam Powell    }
54189e0645b4157961e8c465eb9c819f965fdb453d8Adam Powell}
542