ActionBarContextView.java revision e0a799a2ac1ca78e30fbac9e4e12a063425c08d3
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 1889e0645b4157961e8c465eb9c819f965fdb453d8Adam Powellimport com.android.internal.R; 19696cba573e651b0e4f18a4718627c8ccecb3bda0Adam Powellimport com.android.internal.view.menu.ActionMenuPresenter; 202c9c9fe806e51f29276e66b8ba40cb4b7a80c3f4Adam Powellimport com.android.internal.view.menu.ActionMenuView; 212c9c9fe806e51f29276e66b8ba40cb4b7a80c3f4Adam Powellimport com.android.internal.view.menu.MenuBuilder; 2289e0645b4157961e8c465eb9c819f965fdb453d8Adam 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; 2889e0645b4157961e8c465eb9c819f965fdb453d8Adam Powellimport android.content.res.TypedArray; 2989e0645b4157961e8c465eb9c819f965fdb453d8Adam Powellimport android.util.AttributeSet; 306e34636749217654f43221885afb7a29bb5ca96aAdam Powellimport android.view.ActionMode; 3189e0645b4157961e8c465eb9c819f965fdb453d8Adam Powellimport android.view.LayoutInflater; 3289e0645b4157961e8c465eb9c819f965fdb453d8Adam Powellimport android.view.View; 3389e0645b4157961e8c465eb9c819f965fdb453d8Adam Powellimport android.view.ViewGroup; 34d8b3f2e8eee5f24de6653a918613674e9495f751Adam Powellimport android.view.animation.DecelerateInterpolator; 350e94b5151d817e600a888448a662208b29b5ef46Adam Powellimport android.widget.LinearLayout; 3689e0645b4157961e8c465eb9c819f965fdb453d8Adam Powellimport android.widget.TextView; 3789e0645b4157961e8c465eb9c819f965fdb453d8Adam Powell 3889e0645b4157961e8c465eb9c819f965fdb453d8Adam Powell/** 3989e0645b4157961e8c465eb9c819f965fdb453d8Adam Powell * @hide 4089e0645b4157961e8c465eb9c819f965fdb453d8Adam Powell */ 41d8b3f2e8eee5f24de6653a918613674e9495f751Adam Powellpublic class ActionBarContextView extends ViewGroup implements AnimatorListener { 4277769c7a9130afa48e46dbd79da8271c271ab1e9Adam Powell private static final String TAG = "ActionBarContextView"; 4377769c7a9130afa48e46dbd79da8271c271ab1e9Adam Powell 4489e0645b4157961e8c465eb9c819f965fdb453d8Adam Powell private int mContentHeight; 4589e0645b4157961e8c465eb9c819f965fdb453d8Adam Powell 4689e0645b4157961e8c465eb9c819f965fdb453d8Adam Powell private CharSequence mTitle; 4789e0645b4157961e8c465eb9c819f965fdb453d8Adam Powell private CharSequence mSubtitle; 48f16888f1e849b0bc0b9c17e5f833c4e2cd54c382Adam Powell 49f16888f1e849b0bc0b9c17e5f833c4e2cd54c382Adam Powell private View mClose; 5089e0645b4157961e8c465eb9c819f965fdb453d8Adam Powell private View mCustomView; 510e94b5151d817e600a888448a662208b29b5ef46Adam Powell private LinearLayout mTitleLayout; 5289e0645b4157961e8c465eb9c819f965fdb453d8Adam Powell private TextView mTitleView; 530e94b5151d817e600a888448a662208b29b5ef46Adam Powell private TextView mSubtitleView; 54bc234a19f4c74116454e2c77f4739290e761995aAdam Powell private int mTitleStyleRes; 55bc234a19f4c74116454e2c77f4739290e761995aAdam Powell private int mSubtitleStyleRes; 56b366bbae2b5a3009893ef64246e3430cea4b7736Adam Powell private ActionMenuView mMenuView; 57696cba573e651b0e4f18a4718627c8ccecb3bda0Adam Powell private ActionMenuPresenter mPresenter; 58d8b3f2e8eee5f24de6653a918613674e9495f751Adam Powell 59d8b3f2e8eee5f24de6653a918613674e9495f751Adam Powell private Animator mCurrentAnimation; 60d8b3f2e8eee5f24de6653a918613674e9495f751Adam Powell private boolean mAnimateInOnLayout; 61d8b3f2e8eee5f24de6653a918613674e9495f751Adam Powell private int mAnimationMode; 62d8b3f2e8eee5f24de6653a918613674e9495f751Adam Powell 63d8b3f2e8eee5f24de6653a918613674e9495f751Adam Powell private static final int ANIMATE_IDLE = 0; 64d8b3f2e8eee5f24de6653a918613674e9495f751Adam Powell private static final int ANIMATE_IN = 1; 65d8b3f2e8eee5f24de6653a918613674e9495f751Adam Powell private static final int ANIMATE_OUT = 2; 6689e0645b4157961e8c465eb9c819f965fdb453d8Adam Powell 6789e0645b4157961e8c465eb9c819f965fdb453d8Adam Powell public ActionBarContextView(Context context) { 68bc234a19f4c74116454e2c77f4739290e761995aAdam Powell this(context, null); 6989e0645b4157961e8c465eb9c819f965fdb453d8Adam Powell } 7089e0645b4157961e8c465eb9c819f965fdb453d8Adam Powell 7189e0645b4157961e8c465eb9c819f965fdb453d8Adam Powell public ActionBarContextView(Context context, AttributeSet attrs) { 72bc234a19f4c74116454e2c77f4739290e761995aAdam Powell this(context, attrs, com.android.internal.R.attr.actionModeStyle); 7389e0645b4157961e8c465eb9c819f965fdb453d8Adam Powell } 7489e0645b4157961e8c465eb9c819f965fdb453d8Adam Powell 7589e0645b4157961e8c465eb9c819f965fdb453d8Adam Powell public ActionBarContextView(Context context, AttributeSet attrs, int defStyle) { 7689e0645b4157961e8c465eb9c819f965fdb453d8Adam Powell super(context, attrs, defStyle); 7789e0645b4157961e8c465eb9c819f965fdb453d8Adam Powell 78bc234a19f4c74116454e2c77f4739290e761995aAdam Powell TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.ActionMode, defStyle, 0); 7989e0645b4157961e8c465eb9c819f965fdb453d8Adam Powell setBackgroundDrawable(a.getDrawable( 80bc234a19f4c74116454e2c77f4739290e761995aAdam Powell com.android.internal.R.styleable.ActionMode_background)); 81bc234a19f4c74116454e2c77f4739290e761995aAdam Powell mTitleStyleRes = a.getResourceId( 82bc234a19f4c74116454e2c77f4739290e761995aAdam Powell com.android.internal.R.styleable.ActionMode_titleTextStyle, 0); 83bc234a19f4c74116454e2c77f4739290e761995aAdam Powell mSubtitleStyleRes = a.getResourceId( 84bc234a19f4c74116454e2c77f4739290e761995aAdam Powell com.android.internal.R.styleable.ActionMode_subtitleTextStyle, 0); 85dcdefbbff2bfecbfeb7b6459de130f376595c590Adam Powell 86e2194445b078932733a2d1a02fc084ea2f3c7360Adam Powell mContentHeight = a.getLayoutDimension( 87bc234a19f4c74116454e2c77f4739290e761995aAdam Powell com.android.internal.R.styleable.ActionMode_height, 0); 8889e0645b4157961e8c465eb9c819f965fdb453d8Adam Powell a.recycle(); 8989e0645b4157961e8c465eb9c819f965fdb453d8Adam Powell } 9089e0645b4157961e8c465eb9c819f965fdb453d8Adam Powell 919146ac706265cd8cce66907e617bc8572152eb97Adam Powell @Override 929146ac706265cd8cce66907e617bc8572152eb97Adam Powell public ActionMode startActionModeForChild(View child, ActionMode.Callback callback) { 939146ac706265cd8cce66907e617bc8572152eb97Adam Powell // No starting an action mode for an existing action mode UI child! (Where would it go?) 949146ac706265cd8cce66907e617bc8572152eb97Adam Powell return null; 959146ac706265cd8cce66907e617bc8572152eb97Adam Powell } 969146ac706265cd8cce66907e617bc8572152eb97Adam Powell 97e2194445b078932733a2d1a02fc084ea2f3c7360Adam Powell public void setHeight(int height) { 98e2194445b078932733a2d1a02fc084ea2f3c7360Adam Powell mContentHeight = height; 99e2194445b078932733a2d1a02fc084ea2f3c7360Adam Powell } 100e2194445b078932733a2d1a02fc084ea2f3c7360Adam Powell 10189e0645b4157961e8c465eb9c819f965fdb453d8Adam Powell public void setCustomView(View view) { 10289e0645b4157961e8c465eb9c819f965fdb453d8Adam Powell if (mCustomView != null) { 10389e0645b4157961e8c465eb9c819f965fdb453d8Adam Powell removeView(mCustomView); 10489e0645b4157961e8c465eb9c819f965fdb453d8Adam Powell } 10589e0645b4157961e8c465eb9c819f965fdb453d8Adam Powell mCustomView = view; 1060e94b5151d817e600a888448a662208b29b5ef46Adam Powell if (mTitleLayout != null) { 1070e94b5151d817e600a888448a662208b29b5ef46Adam Powell removeView(mTitleLayout); 1080e94b5151d817e600a888448a662208b29b5ef46Adam Powell mTitleLayout = null; 10989e0645b4157961e8c465eb9c819f965fdb453d8Adam Powell } 11089e0645b4157961e8c465eb9c819f965fdb453d8Adam Powell if (view != null) { 11189e0645b4157961e8c465eb9c819f965fdb453d8Adam Powell addView(view); 11289e0645b4157961e8c465eb9c819f965fdb453d8Adam Powell } 11389e0645b4157961e8c465eb9c819f965fdb453d8Adam Powell requestLayout(); 11489e0645b4157961e8c465eb9c819f965fdb453d8Adam Powell } 1150e94b5151d817e600a888448a662208b29b5ef46Adam Powell 11689e0645b4157961e8c465eb9c819f965fdb453d8Adam Powell public void setTitle(CharSequence title) { 11789e0645b4157961e8c465eb9c819f965fdb453d8Adam Powell mTitle = title; 1180e94b5151d817e600a888448a662208b29b5ef46Adam Powell initTitle(); 1190e94b5151d817e600a888448a662208b29b5ef46Adam Powell } 1200e94b5151d817e600a888448a662208b29b5ef46Adam Powell 1210e94b5151d817e600a888448a662208b29b5ef46Adam Powell public void setSubtitle(CharSequence subtitle) { 1220e94b5151d817e600a888448a662208b29b5ef46Adam Powell mSubtitle = subtitle; 1230e94b5151d817e600a888448a662208b29b5ef46Adam Powell initTitle(); 1240e94b5151d817e600a888448a662208b29b5ef46Adam Powell } 1250e94b5151d817e600a888448a662208b29b5ef46Adam Powell 12629ed7575c2129974a57ad77b3531bc5995940c6cAdam Powell public CharSequence getTitle() { 12729ed7575c2129974a57ad77b3531bc5995940c6cAdam Powell return mTitle; 12829ed7575c2129974a57ad77b3531bc5995940c6cAdam Powell } 12929ed7575c2129974a57ad77b3531bc5995940c6cAdam Powell 13029ed7575c2129974a57ad77b3531bc5995940c6cAdam Powell public CharSequence getSubtitle() { 13129ed7575c2129974a57ad77b3531bc5995940c6cAdam Powell return mSubtitle; 13229ed7575c2129974a57ad77b3531bc5995940c6cAdam Powell } 13329ed7575c2129974a57ad77b3531bc5995940c6cAdam Powell 1340e94b5151d817e600a888448a662208b29b5ef46Adam Powell private void initTitle() { 1350e94b5151d817e600a888448a662208b29b5ef46Adam Powell if (mTitleLayout == null) { 13689e0645b4157961e8c465eb9c819f965fdb453d8Adam Powell LayoutInflater inflater = LayoutInflater.from(getContext()); 137f16888f1e849b0bc0b9c17e5f833c4e2cd54c382Adam Powell inflater.inflate(R.layout.action_bar_title_item, this); 138f16888f1e849b0bc0b9c17e5f833c4e2cd54c382Adam Powell mTitleLayout = (LinearLayout) getChildAt(getChildCount() - 1); 1390e94b5151d817e600a888448a662208b29b5ef46Adam Powell mTitleView = (TextView) mTitleLayout.findViewById(R.id.action_bar_title); 1400e94b5151d817e600a888448a662208b29b5ef46Adam Powell mSubtitleView = (TextView) mTitleLayout.findViewById(R.id.action_bar_subtitle); 1410e94b5151d817e600a888448a662208b29b5ef46Adam Powell if (mTitle != null) { 1420e94b5151d817e600a888448a662208b29b5ef46Adam Powell mTitleView.setText(mTitle); 143bc234a19f4c74116454e2c77f4739290e761995aAdam Powell if (mTitleStyleRes != 0) { 144bc234a19f4c74116454e2c77f4739290e761995aAdam Powell mTitleView.setTextAppearance(mContext, mTitleStyleRes); 145bc234a19f4c74116454e2c77f4739290e761995aAdam Powell } 1460e94b5151d817e600a888448a662208b29b5ef46Adam Powell } 1470e94b5151d817e600a888448a662208b29b5ef46Adam Powell if (mSubtitle != null) { 1480e94b5151d817e600a888448a662208b29b5ef46Adam Powell mSubtitleView.setText(mSubtitle); 149bc234a19f4c74116454e2c77f4739290e761995aAdam Powell if (mSubtitleStyleRes != 0) { 150bc234a19f4c74116454e2c77f4739290e761995aAdam Powell mSubtitleView.setTextAppearance(mContext, mSubtitleStyleRes); 151bc234a19f4c74116454e2c77f4739290e761995aAdam Powell } 1528350f7dbc3a62211b2891f35911e4073d24c4cc5Adam Powell mSubtitleView.setVisibility(VISIBLE); 15389e0645b4157961e8c465eb9c819f965fdb453d8Adam Powell } 15489e0645b4157961e8c465eb9c819f965fdb453d8Adam Powell } else { 1550e94b5151d817e600a888448a662208b29b5ef46Adam Powell mTitleView.setText(mTitle); 1560e94b5151d817e600a888448a662208b29b5ef46Adam Powell mSubtitleView.setText(mSubtitle); 1578350f7dbc3a62211b2891f35911e4073d24c4cc5Adam Powell mSubtitleView.setVisibility(mSubtitle != null ? VISIBLE : GONE); 1580e94b5151d817e600a888448a662208b29b5ef46Adam Powell if (mTitleLayout.getParent() == null) { 1590e94b5151d817e600a888448a662208b29b5ef46Adam Powell addView(mTitleLayout); 16089e0645b4157961e8c465eb9c819f965fdb453d8Adam Powell } 16189e0645b4157961e8c465eb9c819f965fdb453d8Adam Powell } 16289e0645b4157961e8c465eb9c819f965fdb453d8Adam Powell } 1630e94b5151d817e600a888448a662208b29b5ef46Adam Powell 1646e34636749217654f43221885afb7a29bb5ca96aAdam Powell public void initForMode(final ActionMode mode) { 165f16888f1e849b0bc0b9c17e5f833c4e2cd54c382Adam Powell if (mClose == null) { 166f16888f1e849b0bc0b9c17e5f833c4e2cd54c382Adam Powell LayoutInflater inflater = LayoutInflater.from(mContext); 167d8b3f2e8eee5f24de6653a918613674e9495f751Adam Powell mClose = inflater.inflate(R.layout.action_mode_close_item, this, false); 168d8b3f2e8eee5f24de6653a918613674e9495f751Adam Powell addView(mClose); 16945f1e08c348ccb129bcc25e438c05421f7123f41Adam Powell } else if (mClose.getParent() == null) { 170f16888f1e849b0bc0b9c17e5f833c4e2cd54c382Adam Powell addView(mClose); 17189e0645b4157961e8c465eb9c819f965fdb453d8Adam Powell } 172f16888f1e849b0bc0b9c17e5f833c4e2cd54c382Adam Powell 173f16888f1e849b0bc0b9c17e5f833c4e2cd54c382Adam Powell View closeButton = mClose.findViewById(R.id.action_mode_close_button); 174f16888f1e849b0bc0b9c17e5f833c4e2cd54c382Adam Powell closeButton.setOnClickListener(new OnClickListener() { 175269b8bb0cbd78969450ea9ab255232d047580210Adam Powell public void onClick(View v) { 176269b8bb0cbd78969450ea9ab255232d047580210Adam Powell mode.finish(); 177269b8bb0cbd78969450ea9ab255232d047580210Adam Powell } 178269b8bb0cbd78969450ea9ab255232d047580210Adam Powell }); 17989e0645b4157961e8c465eb9c819f965fdb453d8Adam Powell 1802c9c9fe806e51f29276e66b8ba40cb4b7a80c3f4Adam Powell final MenuBuilder menu = (MenuBuilder) mode.getMenu(); 181696cba573e651b0e4f18a4718627c8ccecb3bda0Adam Powell mPresenter = new ActionMenuPresenter(); 182696cba573e651b0e4f18a4718627c8ccecb3bda0Adam Powell menu.addMenuPresenter(mPresenter); 183696cba573e651b0e4f18a4718627c8ccecb3bda0Adam Powell mMenuView = (ActionMenuView) mPresenter.getMenuView(this); 1842c9c9fe806e51f29276e66b8ba40cb4b7a80c3f4Adam Powell addView(mMenuView); 185d8b3f2e8eee5f24de6653a918613674e9495f751Adam Powell 186d8b3f2e8eee5f24de6653a918613674e9495f751Adam Powell mAnimateInOnLayout = true; 18789e0645b4157961e8c465eb9c819f965fdb453d8Adam Powell } 1880e94b5151d817e600a888448a662208b29b5ef46Adam Powell 18989e0645b4157961e8c465eb9c819f965fdb453d8Adam Powell public void closeMode() { 19045f1e08c348ccb129bcc25e438c05421f7123f41Adam Powell if (mAnimationMode == ANIMATE_OUT) { 19145f1e08c348ccb129bcc25e438c05421f7123f41Adam Powell // Called again during close; just finish what we were doing. 19245f1e08c348ccb129bcc25e438c05421f7123f41Adam Powell return; 19345f1e08c348ccb129bcc25e438c05421f7123f41Adam Powell } 194d8b3f2e8eee5f24de6653a918613674e9495f751Adam Powell if (mClose == null) { 195d8b3f2e8eee5f24de6653a918613674e9495f751Adam Powell killMode(); 196d8b3f2e8eee5f24de6653a918613674e9495f751Adam Powell return; 197d8b3f2e8eee5f24de6653a918613674e9495f751Adam Powell } 198d8b3f2e8eee5f24de6653a918613674e9495f751Adam Powell 199d8b3f2e8eee5f24de6653a918613674e9495f751Adam Powell finishAnimation(); 200a1e6358a4c62c8b6de1f2428901e45b688bd9e9fAdam Powell mAnimationMode = ANIMATE_OUT; 201d8b3f2e8eee5f24de6653a918613674e9495f751Adam Powell mCurrentAnimation = makeOutAnimation(); 202d8b3f2e8eee5f24de6653a918613674e9495f751Adam Powell mCurrentAnimation.start(); 203d8b3f2e8eee5f24de6653a918613674e9495f751Adam Powell } 204d8b3f2e8eee5f24de6653a918613674e9495f751Adam Powell 205d8b3f2e8eee5f24de6653a918613674e9495f751Adam Powell private void finishAnimation() { 20645f1e08c348ccb129bcc25e438c05421f7123f41Adam Powell final Animator a = mCurrentAnimation; 207a1e6358a4c62c8b6de1f2428901e45b688bd9e9fAdam Powell if (a != null) { 20845f1e08c348ccb129bcc25e438c05421f7123f41Adam Powell mCurrentAnimation = null; 20945f1e08c348ccb129bcc25e438c05421f7123f41Adam Powell a.end(); 210d8b3f2e8eee5f24de6653a918613674e9495f751Adam Powell } 211d8b3f2e8eee5f24de6653a918613674e9495f751Adam Powell } 212d8b3f2e8eee5f24de6653a918613674e9495f751Adam Powell 213d8b3f2e8eee5f24de6653a918613674e9495f751Adam Powell public void killMode() { 214d8b3f2e8eee5f24de6653a918613674e9495f751Adam Powell finishAnimation(); 21589e0645b4157961e8c465eb9c819f965fdb453d8Adam Powell removeAllViews(); 21689e0645b4157961e8c465eb9c819f965fdb453d8Adam Powell mCustomView = null; 2172c9c9fe806e51f29276e66b8ba40cb4b7a80c3f4Adam Powell mMenuView = null; 21800bba682efedbe121f31c98697f91101b1c22b82Adam Powell mAnimateInOnLayout = false; 21989e0645b4157961e8c465eb9c819f965fdb453d8Adam Powell } 2200e94b5151d817e600a888448a662208b29b5ef46Adam Powell 221f6148c53f93978af678cc0559a4417b608a33ae1Adam Powell public boolean showOverflowMenu() { 222696cba573e651b0e4f18a4718627c8ccecb3bda0Adam Powell if (mPresenter != null) { 223696cba573e651b0e4f18a4718627c8ccecb3bda0Adam Powell return mPresenter.showOverflowMenu(); 224f6148c53f93978af678cc0559a4417b608a33ae1Adam Powell } 225f6148c53f93978af678cc0559a4417b608a33ae1Adam Powell return false; 226f6148c53f93978af678cc0559a4417b608a33ae1Adam Powell } 227f6148c53f93978af678cc0559a4417b608a33ae1Adam Powell 228f6148c53f93978af678cc0559a4417b608a33ae1Adam Powell public boolean hideOverflowMenu() { 229696cba573e651b0e4f18a4718627c8ccecb3bda0Adam Powell if (mPresenter != null) { 230696cba573e651b0e4f18a4718627c8ccecb3bda0Adam Powell return mPresenter.hideOverflowMenu(); 231f6148c53f93978af678cc0559a4417b608a33ae1Adam Powell } 232f6148c53f93978af678cc0559a4417b608a33ae1Adam Powell return false; 233f6148c53f93978af678cc0559a4417b608a33ae1Adam Powell } 234f6148c53f93978af678cc0559a4417b608a33ae1Adam Powell 235f6148c53f93978af678cc0559a4417b608a33ae1Adam Powell public boolean isOverflowMenuShowing() { 236696cba573e651b0e4f18a4718627c8ccecb3bda0Adam Powell if (mPresenter != null) { 237696cba573e651b0e4f18a4718627c8ccecb3bda0Adam Powell return mPresenter.isOverflowMenuShowing(); 238f6148c53f93978af678cc0559a4417b608a33ae1Adam Powell } 239f6148c53f93978af678cc0559a4417b608a33ae1Adam Powell return false; 240f6148c53f93978af678cc0559a4417b608a33ae1Adam Powell } 241f6148c53f93978af678cc0559a4417b608a33ae1Adam Powell 24289e0645b4157961e8c465eb9c819f965fdb453d8Adam Powell @Override 243a7db03705f53c59e63e63c2e67e2db78f8226dccAdam Powell protected LayoutParams generateDefaultLayoutParams() { 244a7db03705f53c59e63e63c2e67e2db78f8226dccAdam Powell // Used by custom views if they don't supply layout params. Everything else 245a7db03705f53c59e63e63c2e67e2db78f8226dccAdam Powell // added to an ActionBarContextView should have them already. 246a7db03705f53c59e63e63c2e67e2db78f8226dccAdam Powell return new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT); 247a7db03705f53c59e63e63c2e67e2db78f8226dccAdam Powell } 248a7db03705f53c59e63e63c2e67e2db78f8226dccAdam Powell 249a7db03705f53c59e63e63c2e67e2db78f8226dccAdam Powell @Override 25089e0645b4157961e8c465eb9c819f965fdb453d8Adam Powell protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) { 25189e0645b4157961e8c465eb9c819f965fdb453d8Adam Powell final int widthMode = MeasureSpec.getMode(widthMeasureSpec); 25289e0645b4157961e8c465eb9c819f965fdb453d8Adam Powell if (widthMode != MeasureSpec.EXACTLY) { 25389e0645b4157961e8c465eb9c819f965fdb453d8Adam Powell throw new IllegalStateException(getClass().getSimpleName() + " can only be used " + 25489e0645b4157961e8c465eb9c819f965fdb453d8Adam Powell "with android:layout_width=\"match_parent\" (or fill_parent)"); 25589e0645b4157961e8c465eb9c819f965fdb453d8Adam Powell } 25689e0645b4157961e8c465eb9c819f965fdb453d8Adam Powell 25789e0645b4157961e8c465eb9c819f965fdb453d8Adam Powell final int heightMode = MeasureSpec.getMode(heightMeasureSpec); 25885446e95afa480cee2247bb96795fccc8cf812afAdam Powell if (heightMode == MeasureSpec.UNSPECIFIED) { 25989e0645b4157961e8c465eb9c819f965fdb453d8Adam Powell throw new IllegalStateException(getClass().getSimpleName() + " can only be used " + 26089e0645b4157961e8c465eb9c819f965fdb453d8Adam Powell "with android:layout_height=\"wrap_content\""); 26189e0645b4157961e8c465eb9c819f965fdb453d8Adam Powell } 26289e0645b4157961e8c465eb9c819f965fdb453d8Adam Powell 26389e0645b4157961e8c465eb9c819f965fdb453d8Adam Powell final int contentWidth = MeasureSpec.getSize(widthMeasureSpec); 26489e0645b4157961e8c465eb9c819f965fdb453d8Adam Powell 265e2194445b078932733a2d1a02fc084ea2f3c7360Adam Powell int maxHeight = mContentHeight > 0 ? 266e2194445b078932733a2d1a02fc084ea2f3c7360Adam Powell mContentHeight : MeasureSpec.getSize(heightMeasureSpec); 267e2194445b078932733a2d1a02fc084ea2f3c7360Adam Powell 268e2194445b078932733a2d1a02fc084ea2f3c7360Adam Powell final int verticalPadding = getPaddingTop() + getPaddingBottom(); 26989e0645b4157961e8c465eb9c819f965fdb453d8Adam Powell int availableWidth = contentWidth - getPaddingLeft() - getPaddingRight(); 270e2194445b078932733a2d1a02fc084ea2f3c7360Adam Powell final int height = maxHeight - verticalPadding; 27189e0645b4157961e8c465eb9c819f965fdb453d8Adam Powell final int childSpecHeight = MeasureSpec.makeMeasureSpec(height, MeasureSpec.AT_MOST); 27289e0645b4157961e8c465eb9c819f965fdb453d8Adam Powell 273f16888f1e849b0bc0b9c17e5f833c4e2cd54c382Adam Powell if (mClose != null) { 274f16888f1e849b0bc0b9c17e5f833c4e2cd54c382Adam Powell availableWidth = measureChildView(mClose, availableWidth, childSpecHeight, 0); 27589e0645b4157961e8c465eb9c819f965fdb453d8Adam Powell } 27689e0645b4157961e8c465eb9c819f965fdb453d8Adam Powell 277b0ff6f995553a5deb1f22e43e44715b316d33a88Adam Powell if (mMenuView != null) { 278b0ff6f995553a5deb1f22e43e44715b316d33a88Adam Powell availableWidth = measureChildView(mMenuView, availableWidth, 279b0ff6f995553a5deb1f22e43e44715b316d33a88Adam Powell childSpecHeight, 0); 28089e0645b4157961e8c465eb9c819f965fdb453d8Adam Powell } 28189e0645b4157961e8c465eb9c819f965fdb453d8Adam Powell 282b0ff6f995553a5deb1f22e43e44715b316d33a88Adam Powell if (mTitleLayout != null && mCustomView == null) { 283b0ff6f995553a5deb1f22e43e44715b316d33a88Adam Powell availableWidth = measureChildView(mTitleLayout, availableWidth, childSpecHeight, 0); 28489e0645b4157961e8c465eb9c819f965fdb453d8Adam Powell } 28589e0645b4157961e8c465eb9c819f965fdb453d8Adam Powell 28689e0645b4157961e8c465eb9c819f965fdb453d8Adam Powell if (mCustomView != null) { 287a7db03705f53c59e63e63c2e67e2db78f8226dccAdam Powell LayoutParams lp = mCustomView.getLayoutParams(); 288a7db03705f53c59e63e63c2e67e2db78f8226dccAdam Powell final int customWidthMode = lp.width != LayoutParams.WRAP_CONTENT ? 289a7db03705f53c59e63e63c2e67e2db78f8226dccAdam Powell MeasureSpec.EXACTLY : MeasureSpec.AT_MOST; 290a7db03705f53c59e63e63c2e67e2db78f8226dccAdam Powell final int customWidth = lp.width >= 0 ? 291a7db03705f53c59e63e63c2e67e2db78f8226dccAdam Powell Math.min(lp.width, availableWidth) : availableWidth; 292a7db03705f53c59e63e63c2e67e2db78f8226dccAdam Powell final int customHeightMode = lp.height != LayoutParams.WRAP_CONTENT ? 293a7db03705f53c59e63e63c2e67e2db78f8226dccAdam Powell MeasureSpec.EXACTLY : MeasureSpec.AT_MOST; 294a7db03705f53c59e63e63c2e67e2db78f8226dccAdam Powell final int customHeight = lp.height >= 0 ? 295a7db03705f53c59e63e63c2e67e2db78f8226dccAdam Powell Math.min(lp.height, height) : height; 296a7db03705f53c59e63e63c2e67e2db78f8226dccAdam Powell mCustomView.measure(MeasureSpec.makeMeasureSpec(customWidth, customWidthMode), 297a7db03705f53c59e63e63c2e67e2db78f8226dccAdam Powell MeasureSpec.makeMeasureSpec(customHeight, customHeightMode)); 29889e0645b4157961e8c465eb9c819f965fdb453d8Adam Powell } 29989e0645b4157961e8c465eb9c819f965fdb453d8Adam Powell 300e2194445b078932733a2d1a02fc084ea2f3c7360Adam Powell if (mContentHeight <= 0) { 301e2194445b078932733a2d1a02fc084ea2f3c7360Adam Powell int measuredHeight = 0; 302e2194445b078932733a2d1a02fc084ea2f3c7360Adam Powell final int count = getChildCount(); 303e2194445b078932733a2d1a02fc084ea2f3c7360Adam Powell for (int i = 0; i < count; i++) { 304e2194445b078932733a2d1a02fc084ea2f3c7360Adam Powell View v = getChildAt(i); 305e2194445b078932733a2d1a02fc084ea2f3c7360Adam Powell int paddedViewHeight = v.getMeasuredHeight() + verticalPadding; 306e2194445b078932733a2d1a02fc084ea2f3c7360Adam Powell if (paddedViewHeight > measuredHeight) { 307e2194445b078932733a2d1a02fc084ea2f3c7360Adam Powell measuredHeight = paddedViewHeight; 308e2194445b078932733a2d1a02fc084ea2f3c7360Adam Powell } 309e2194445b078932733a2d1a02fc084ea2f3c7360Adam Powell } 310e2194445b078932733a2d1a02fc084ea2f3c7360Adam Powell setMeasuredDimension(contentWidth, measuredHeight); 311e2194445b078932733a2d1a02fc084ea2f3c7360Adam Powell } else { 312e2194445b078932733a2d1a02fc084ea2f3c7360Adam Powell setMeasuredDimension(contentWidth, maxHeight); 313e2194445b078932733a2d1a02fc084ea2f3c7360Adam Powell } 31489e0645b4157961e8c465eb9c819f965fdb453d8Adam Powell } 31589e0645b4157961e8c465eb9c819f965fdb453d8Adam Powell 316d8b3f2e8eee5f24de6653a918613674e9495f751Adam Powell private Animator makeInAnimation() { 317d8b3f2e8eee5f24de6653a918613674e9495f751Adam Powell mClose.setTranslationX(-mClose.getWidth()); 318d8b3f2e8eee5f24de6653a918613674e9495f751Adam Powell ObjectAnimator buttonAnimator = ObjectAnimator.ofFloat(mClose, "translationX", 0); 319d8b3f2e8eee5f24de6653a918613674e9495f751Adam Powell buttonAnimator.setDuration(200); 320d8b3f2e8eee5f24de6653a918613674e9495f751Adam Powell buttonAnimator.addListener(this); 321d8b3f2e8eee5f24de6653a918613674e9495f751Adam Powell buttonAnimator.setInterpolator(new DecelerateInterpolator()); 322d8b3f2e8eee5f24de6653a918613674e9495f751Adam Powell 323d8b3f2e8eee5f24de6653a918613674e9495f751Adam Powell AnimatorSet set = new AnimatorSet(); 324d8b3f2e8eee5f24de6653a918613674e9495f751Adam Powell AnimatorSet.Builder b = set.play(buttonAnimator); 325d8b3f2e8eee5f24de6653a918613674e9495f751Adam Powell 326d8b3f2e8eee5f24de6653a918613674e9495f751Adam Powell if (mMenuView != null) { 327d8b3f2e8eee5f24de6653a918613674e9495f751Adam Powell final int count = mMenuView.getChildCount(); 328d8b3f2e8eee5f24de6653a918613674e9495f751Adam Powell if (count > 0) { 329d8b3f2e8eee5f24de6653a918613674e9495f751Adam Powell for (int i = count - 1, j = 0; i >= 0; i--, j++) { 330d8b3f2e8eee5f24de6653a918613674e9495f751Adam Powell View child = mMenuView.getChildAt(i); 331d8b3f2e8eee5f24de6653a918613674e9495f751Adam Powell child.setScaleY(0); 332d8b3f2e8eee5f24de6653a918613674e9495f751Adam Powell ObjectAnimator a = ObjectAnimator.ofFloat(child, "scaleY", 0, 1); 333d8b3f2e8eee5f24de6653a918613674e9495f751Adam Powell a.setDuration(100); 334d8b3f2e8eee5f24de6653a918613674e9495f751Adam Powell a.setStartDelay(j * 70); 335d8b3f2e8eee5f24de6653a918613674e9495f751Adam Powell b.with(a); 336d8b3f2e8eee5f24de6653a918613674e9495f751Adam Powell } 337d8b3f2e8eee5f24de6653a918613674e9495f751Adam Powell } 338d8b3f2e8eee5f24de6653a918613674e9495f751Adam Powell } 339d8b3f2e8eee5f24de6653a918613674e9495f751Adam Powell 340d8b3f2e8eee5f24de6653a918613674e9495f751Adam Powell return set; 341d8b3f2e8eee5f24de6653a918613674e9495f751Adam Powell } 342d8b3f2e8eee5f24de6653a918613674e9495f751Adam Powell 343d8b3f2e8eee5f24de6653a918613674e9495f751Adam Powell private Animator makeOutAnimation() { 344d8b3f2e8eee5f24de6653a918613674e9495f751Adam Powell ObjectAnimator buttonAnimator = ObjectAnimator.ofFloat(mClose, "translationX", 345d8b3f2e8eee5f24de6653a918613674e9495f751Adam Powell 0, -mClose.getWidth()); 346d8b3f2e8eee5f24de6653a918613674e9495f751Adam Powell buttonAnimator.setDuration(200); 347d8b3f2e8eee5f24de6653a918613674e9495f751Adam Powell buttonAnimator.addListener(this); 348d8b3f2e8eee5f24de6653a918613674e9495f751Adam Powell buttonAnimator.setInterpolator(new DecelerateInterpolator()); 349d8b3f2e8eee5f24de6653a918613674e9495f751Adam Powell 350d8b3f2e8eee5f24de6653a918613674e9495f751Adam Powell AnimatorSet set = new AnimatorSet(); 351d8b3f2e8eee5f24de6653a918613674e9495f751Adam Powell AnimatorSet.Builder b = set.play(buttonAnimator); 352d8b3f2e8eee5f24de6653a918613674e9495f751Adam Powell 353d8b3f2e8eee5f24de6653a918613674e9495f751Adam Powell if (mMenuView != null) { 354d8b3f2e8eee5f24de6653a918613674e9495f751Adam Powell final int count = mMenuView.getChildCount(); 355d8b3f2e8eee5f24de6653a918613674e9495f751Adam Powell if (count > 0) { 356d8b3f2e8eee5f24de6653a918613674e9495f751Adam Powell for (int i = 0; i < 0; i++) { 357d8b3f2e8eee5f24de6653a918613674e9495f751Adam Powell View child = mMenuView.getChildAt(i); 358d8b3f2e8eee5f24de6653a918613674e9495f751Adam Powell child.setScaleY(0); 359d8b3f2e8eee5f24de6653a918613674e9495f751Adam Powell ObjectAnimator a = ObjectAnimator.ofFloat(child, "scaleY", 1, 0); 360d8b3f2e8eee5f24de6653a918613674e9495f751Adam Powell a.setDuration(100); 361d8b3f2e8eee5f24de6653a918613674e9495f751Adam Powell a.setStartDelay(i * 70); 362d8b3f2e8eee5f24de6653a918613674e9495f751Adam Powell b.with(a); 363d8b3f2e8eee5f24de6653a918613674e9495f751Adam Powell } 364d8b3f2e8eee5f24de6653a918613674e9495f751Adam Powell } 365d8b3f2e8eee5f24de6653a918613674e9495f751Adam Powell } 366d8b3f2e8eee5f24de6653a918613674e9495f751Adam Powell 367d8b3f2e8eee5f24de6653a918613674e9495f751Adam Powell return set; 368d8b3f2e8eee5f24de6653a918613674e9495f751Adam Powell } 369d8b3f2e8eee5f24de6653a918613674e9495f751Adam Powell 37089e0645b4157961e8c465eb9c819f965fdb453d8Adam Powell @Override 37189e0645b4157961e8c465eb9c819f965fdb453d8Adam Powell protected void onLayout(boolean changed, int l, int t, int r, int b) { 37289e0645b4157961e8c465eb9c819f965fdb453d8Adam Powell int x = getPaddingLeft(); 37389e0645b4157961e8c465eb9c819f965fdb453d8Adam Powell final int y = getPaddingTop(); 37489e0645b4157961e8c465eb9c819f965fdb453d8Adam Powell final int contentHeight = b - t - getPaddingTop() - getPaddingBottom(); 37589e0645b4157961e8c465eb9c819f965fdb453d8Adam Powell 376f16888f1e849b0bc0b9c17e5f833c4e2cd54c382Adam Powell if (mClose != null && mClose.getVisibility() != GONE) { 377f16888f1e849b0bc0b9c17e5f833c4e2cd54c382Adam Powell x += positionChild(mClose, x, y, contentHeight); 378d8b3f2e8eee5f24de6653a918613674e9495f751Adam Powell 379d8b3f2e8eee5f24de6653a918613674e9495f751Adam Powell if (mAnimateInOnLayout) { 380d8b3f2e8eee5f24de6653a918613674e9495f751Adam Powell mAnimationMode = ANIMATE_IN; 381d8b3f2e8eee5f24de6653a918613674e9495f751Adam Powell mCurrentAnimation = makeInAnimation(); 382d8b3f2e8eee5f24de6653a918613674e9495f751Adam Powell mCurrentAnimation.start(); 383d8b3f2e8eee5f24de6653a918613674e9495f751Adam Powell mAnimateInOnLayout = false; 384d8b3f2e8eee5f24de6653a918613674e9495f751Adam Powell } 38589e0645b4157961e8c465eb9c819f965fdb453d8Adam Powell } 38689e0645b4157961e8c465eb9c819f965fdb453d8Adam Powell 3870e94b5151d817e600a888448a662208b29b5ef46Adam Powell if (mTitleLayout != null && mCustomView == null) { 388be4d68e7b238b8ee879de0481e39c40d3f1683b6Adam Powell x += positionChild(mTitleLayout, x, y, contentHeight); 38989e0645b4157961e8c465eb9c819f965fdb453d8Adam Powell } 39089e0645b4157961e8c465eb9c819f965fdb453d8Adam Powell 39189e0645b4157961e8c465eb9c819f965fdb453d8Adam Powell if (mCustomView != null) { 392be4d68e7b238b8ee879de0481e39c40d3f1683b6Adam Powell x += positionChild(mCustomView, x, y, contentHeight); 39389e0645b4157961e8c465eb9c819f965fdb453d8Adam Powell } 39489e0645b4157961e8c465eb9c819f965fdb453d8Adam Powell 39589e0645b4157961e8c465eb9c819f965fdb453d8Adam Powell x = r - l - getPaddingRight(); 39689e0645b4157961e8c465eb9c819f965fdb453d8Adam Powell 3972c9c9fe806e51f29276e66b8ba40cb4b7a80c3f4Adam Powell if (mMenuView != null) { 398be4d68e7b238b8ee879de0481e39c40d3f1683b6Adam Powell x -= positionChildInverse(mMenuView, x, y, contentHeight); 39989e0645b4157961e8c465eb9c819f965fdb453d8Adam Powell } 40089e0645b4157961e8c465eb9c819f965fdb453d8Adam Powell } 40189e0645b4157961e8c465eb9c819f965fdb453d8Adam Powell 40289e0645b4157961e8c465eb9c819f965fdb453d8Adam Powell private int measureChildView(View child, int availableWidth, int childSpecHeight, int spacing) { 40389e0645b4157961e8c465eb9c819f965fdb453d8Adam Powell child.measure(MeasureSpec.makeMeasureSpec(availableWidth, MeasureSpec.AT_MOST), 40489e0645b4157961e8c465eb9c819f965fdb453d8Adam Powell childSpecHeight); 40589e0645b4157961e8c465eb9c819f965fdb453d8Adam Powell 40689e0645b4157961e8c465eb9c819f965fdb453d8Adam Powell availableWidth -= child.getMeasuredWidth(); 40789e0645b4157961e8c465eb9c819f965fdb453d8Adam Powell availableWidth -= spacing; 40889e0645b4157961e8c465eb9c819f965fdb453d8Adam Powell 40989e0645b4157961e8c465eb9c819f965fdb453d8Adam Powell return availableWidth; 41089e0645b4157961e8c465eb9c819f965fdb453d8Adam Powell } 41189e0645b4157961e8c465eb9c819f965fdb453d8Adam Powell 41289e0645b4157961e8c465eb9c819f965fdb453d8Adam Powell private int positionChild(View child, int x, int y, int contentHeight) { 41389e0645b4157961e8c465eb9c819f965fdb453d8Adam Powell int childWidth = child.getMeasuredWidth(); 41489e0645b4157961e8c465eb9c819f965fdb453d8Adam Powell int childHeight = child.getMeasuredHeight(); 41589e0645b4157961e8c465eb9c819f965fdb453d8Adam Powell int childTop = y + (contentHeight - childHeight) / 2; 41689e0645b4157961e8c465eb9c819f965fdb453d8Adam Powell 41789e0645b4157961e8c465eb9c819f965fdb453d8Adam Powell child.layout(x, childTop, x + childWidth, childTop + childHeight); 41889e0645b4157961e8c465eb9c819f965fdb453d8Adam Powell 41989e0645b4157961e8c465eb9c819f965fdb453d8Adam Powell return childWidth; 42089e0645b4157961e8c465eb9c819f965fdb453d8Adam Powell } 42189e0645b4157961e8c465eb9c819f965fdb453d8Adam Powell 42289e0645b4157961e8c465eb9c819f965fdb453d8Adam Powell private int positionChildInverse(View child, int x, int y, int contentHeight) { 42389e0645b4157961e8c465eb9c819f965fdb453d8Adam Powell int childWidth = child.getMeasuredWidth(); 42489e0645b4157961e8c465eb9c819f965fdb453d8Adam Powell int childHeight = child.getMeasuredHeight(); 42589e0645b4157961e8c465eb9c819f965fdb453d8Adam Powell int childTop = y + (contentHeight - childHeight) / 2; 42689e0645b4157961e8c465eb9c819f965fdb453d8Adam Powell 42789e0645b4157961e8c465eb9c819f965fdb453d8Adam Powell child.layout(x - childWidth, childTop, x, childTop + childHeight); 42889e0645b4157961e8c465eb9c819f965fdb453d8Adam Powell 42989e0645b4157961e8c465eb9c819f965fdb453d8Adam Powell return childWidth; 43089e0645b4157961e8c465eb9c819f965fdb453d8Adam Powell } 431d8b3f2e8eee5f24de6653a918613674e9495f751Adam Powell 432d8b3f2e8eee5f24de6653a918613674e9495f751Adam Powell @Override 433d8b3f2e8eee5f24de6653a918613674e9495f751Adam Powell public void onAnimationStart(Animator animation) { 434d8b3f2e8eee5f24de6653a918613674e9495f751Adam Powell } 435d8b3f2e8eee5f24de6653a918613674e9495f751Adam Powell 436d8b3f2e8eee5f24de6653a918613674e9495f751Adam Powell @Override 437d8b3f2e8eee5f24de6653a918613674e9495f751Adam Powell public void onAnimationEnd(Animator animation) { 438a1e6358a4c62c8b6de1f2428901e45b688bd9e9fAdam Powell if (mAnimationMode == ANIMATE_OUT) { 439d8b3f2e8eee5f24de6653a918613674e9495f751Adam Powell killMode(); 440d8b3f2e8eee5f24de6653a918613674e9495f751Adam Powell } 441d8b3f2e8eee5f24de6653a918613674e9495f751Adam Powell mAnimationMode = ANIMATE_IDLE; 442d8b3f2e8eee5f24de6653a918613674e9495f751Adam Powell } 443d8b3f2e8eee5f24de6653a918613674e9495f751Adam Powell 444d8b3f2e8eee5f24de6653a918613674e9495f751Adam Powell @Override 445d8b3f2e8eee5f24de6653a918613674e9495f751Adam Powell public void onAnimationCancel(Animator animation) { 446d8b3f2e8eee5f24de6653a918613674e9495f751Adam Powell } 447d8b3f2e8eee5f24de6653a918613674e9495f751Adam Powell 448d8b3f2e8eee5f24de6653a918613674e9495f751Adam Powell @Override 449d8b3f2e8eee5f24de6653a918613674e9495f751Adam Powell public void onAnimationRepeat(Animator animation) { 450d8b3f2e8eee5f24de6653a918613674e9495f751Adam Powell } 451e0a799a2ac1ca78e30fbac9e4e12a063425c08d3Patrick Dubroy 452e0a799a2ac1ca78e30fbac9e4e12a063425c08d3Patrick Dubroy @Override 453e0a799a2ac1ca78e30fbac9e4e12a063425c08d3Patrick Dubroy public boolean shouldDelayChildPressedState() { 454e0a799a2ac1ca78e30fbac9e4e12a063425c08d3Patrick Dubroy return false; 455e0a799a2ac1ca78e30fbac9e4e12a063425c08d3Patrick Dubroy } 45689e0645b4157961e8c465eb9c819f965fdb453d8Adam Powell} 457