ActionBarContextView.java revision bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17f
1bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell/* 2bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell * Copyright (C) 2010 The Android Open Source Project 3bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell * 4bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell * Licensed under the Apache License, Version 2.0 (the "License"); 5bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell * you may not use this file except in compliance with the License. 6bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell * You may obtain a copy of the License at 7bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell * 8bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell * http://www.apache.org/licenses/LICENSE-2.0 9bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell * 10bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell * Unless required by applicable law or agreed to in writing, software 11bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell * distributed under the License is distributed on an "AS IS" BASIS, 12bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell * See the License for the specific language governing permissions and 14bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell * limitations under the License. 15bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell */ 16bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powellpackage android.support.appcompat.widget; 17bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell 18bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powellimport android.animation.Animator; 19bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powellimport android.animation.Animator.AnimatorListener; 20bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powellimport android.animation.AnimatorSet; 21bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powellimport android.animation.ObjectAnimator; 22bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powellimport android.content.Context; 23bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powellimport android.content.res.TypedArray; 24bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powellimport android.graphics.drawable.Drawable; 25bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powellimport android.support.appcompat.R; 26bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powellimport android.support.appcompat.view.menu.ActionMenuPresenter; 27bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powellimport android.support.appcompat.view.menu.ActionMenuView; 28bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powellimport android.support.appcompat.view.menu.MenuBuilder; 29bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powellimport android.text.TextUtils; 30bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powellimport android.util.AttributeSet; 31bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powellimport android.view.ActionMode; 32bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powellimport android.view.LayoutInflater; 33bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powellimport android.view.View; 34bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powellimport android.view.ViewGroup; 35bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powellimport android.view.accessibility.AccessibilityEvent; 36bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powellimport android.view.animation.DecelerateInterpolator; 37bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powellimport android.widget.LinearLayout; 38bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powellimport android.widget.TextView; 39bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell 40bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell/** 41bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell * @hide 42bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell */ 43bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powellpublic class ActionBarContextView extends AbsActionBarView implements AnimatorListener { 44bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell private static final String TAG = "ActionBarContextView"; 45bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell 46bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell private CharSequence mTitle; 47bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell private CharSequence mSubtitle; 48bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell 49bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell private View mClose; 50bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell private View mCustomView; 51bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell private LinearLayout mTitleLayout; 52bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell private TextView mTitleView; 53bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell private TextView mSubtitleView; 54bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell private int mTitleStyleRes; 55bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell private int mSubtitleStyleRes; 56bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell private Drawable mSplitBackground; 57bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell private boolean mTitleOptional; 58bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell 59bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell private Animator mCurrentAnimation; 60bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell private boolean mAnimateInOnLayout; 61bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell private int mAnimationMode; 62bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell 63bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell private static final int ANIMATE_IDLE = 0; 64bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell private static final int ANIMATE_IN = 1; 65bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell private static final int ANIMATE_OUT = 2; 66bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell 67bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell public ActionBarContextView(Context context) { 68bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell this(context, null); 69bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell } 70bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell 71bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell public ActionBarContextView(Context context, AttributeSet attrs) { 72bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell this(context, attrs, R.attr.actionModeStyle); 73bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell } 74bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell 75bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell public ActionBarContextView(Context context, AttributeSet attrs, int defStyle) { 76bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell super(context, attrs, defStyle); 77bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell 78bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.ActionMode, defStyle, 0); 79bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell setBackgroundDrawable(a.getDrawable( 80bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell R.styleable.ActionMode_background)); 81bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell mTitleStyleRes = a.getResourceId( 82bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell R.styleable.ActionMode_titleTextStyle, 0); 83bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell mSubtitleStyleRes = a.getResourceId( 84bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell R.styleable.ActionMode_subtitleTextStyle, 0); 85bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell 86bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell mContentHeight = a.getLayoutDimension( 87bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell R.styleable.ActionMode_height, 0); 88bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell 89bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell mSplitBackground = a.getDrawable( 90bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell R.styleable.ActionMode_backgroundSplit); 91bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell 92bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell a.recycle(); 93bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell } 94bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell 95bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell @Override 96bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell public void onDetachedFromWindow() { 97bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell super.onDetachedFromWindow(); 98bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell if (mActionMenuPresenter != null) { 99bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell mActionMenuPresenter.hideOverflowMenu(); 100bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell mActionMenuPresenter.hideSubMenus(); 101bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell } 102bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell } 103bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell 104bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell @Override 105bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell public void setSplitActionBar(boolean split) { 106bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell if (mSplitActionBar != split) { 107bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell if (mActionMenuPresenter != null) { 108bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell // Mode is already active; move everything over and adjust the menu itself. 109bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell final ViewGroup.LayoutParams layoutParams = new ViewGroup.LayoutParams( 110bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell ViewGroup.LayoutParams.WRAP_CONTENT, 111bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell ViewGroup.LayoutParams.MATCH_PARENT); 112bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell if (!split) { 113bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell mMenuView = (ActionMenuView) mActionMenuPresenter.getMenuView(this); 114bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell mMenuView.setBackgroundDrawable(null); 115bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell final ViewGroup oldParent = (ViewGroup) mMenuView.getParent(); 116bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell if (oldParent != null) oldParent.removeView(mMenuView); 117bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell addView(mMenuView, layoutParams); 118bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell } else { 119bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell // Allow full screen width in split mode. 120bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell mActionMenuPresenter.setWidthLimit( 121bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell getContext().getResources().getDisplayMetrics().widthPixels, true); 122bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell // No limit to the item count; use whatever will fit. 123bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell mActionMenuPresenter.setItemLimit(Integer.MAX_VALUE); 124bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell // Span the whole width 125bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell layoutParams.width = ViewGroup.LayoutParams.MATCH_PARENT; 126bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell layoutParams.height = mContentHeight; 127bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell mMenuView = (ActionMenuView) mActionMenuPresenter.getMenuView(this); 128bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell mMenuView.setBackgroundDrawable(mSplitBackground); 129bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell final ViewGroup oldParent = (ViewGroup) mMenuView.getParent(); 130bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell if (oldParent != null) oldParent.removeView(mMenuView); 131bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell mSplitView.addView(mMenuView, layoutParams); 132bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell } 133bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell } 134bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell super.setSplitActionBar(split); 135bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell } 136bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell } 137bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell 138bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell public void setContentHeight(int height) { 139bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell mContentHeight = height; 140bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell } 141bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell 142bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell public void setCustomView(View view) { 143bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell if (mCustomView != null) { 144bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell removeView(mCustomView); 145bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell } 146bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell mCustomView = view; 147bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell if (mTitleLayout != null) { 148bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell removeView(mTitleLayout); 149bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell mTitleLayout = null; 150bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell } 151bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell if (view != null) { 152bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell addView(view); 153bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell } 154bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell requestLayout(); 155bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell } 156bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell 157bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell public void setTitle(CharSequence title) { 158bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell mTitle = title; 159bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell initTitle(); 160bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell } 161bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell 162bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell public void setSubtitle(CharSequence subtitle) { 163bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell mSubtitle = subtitle; 164bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell initTitle(); 165bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell } 166bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell 167bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell public CharSequence getTitle() { 168bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell return mTitle; 169bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell } 170bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell 171bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell public CharSequence getSubtitle() { 172bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell return mSubtitle; 173bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell } 174bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell 175bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell private void initTitle() { 176bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell if (mTitleLayout == null) { 177bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell LayoutInflater inflater = LayoutInflater.from(getContext()); 178bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell inflater.inflate(R.layout.action_bar_title_item, this); 179bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell mTitleLayout = (LinearLayout) getChildAt(getChildCount() - 1); 180bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell mTitleView = (TextView) mTitleLayout.findViewById(R.id.action_bar_title); 181bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell mSubtitleView = (TextView) mTitleLayout.findViewById(R.id.action_bar_subtitle); 182bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell if (mTitleStyleRes != 0) { 183bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell mTitleView.setTextAppearance(getContext(), mTitleStyleRes); 184bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell } 185bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell if (mSubtitleStyleRes != 0) { 186bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell mSubtitleView.setTextAppearance(getContext(), mSubtitleStyleRes); 187bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell } 188bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell } 189bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell 190bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell mTitleView.setText(mTitle); 191bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell mSubtitleView.setText(mSubtitle); 192bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell 193bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell final boolean hasTitle = !TextUtils.isEmpty(mTitle); 194bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell final boolean hasSubtitle = !TextUtils.isEmpty(mSubtitle); 195bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell mSubtitleView.setVisibility(hasSubtitle ? VISIBLE : GONE); 196bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell mTitleLayout.setVisibility(hasTitle || hasSubtitle ? VISIBLE : GONE); 197bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell if (mTitleLayout.getParent() == null) { 198bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell addView(mTitleLayout); 199bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell } 200bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell } 201bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell 202bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell public void initForMode(final ActionMode mode) { 203bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell if (mClose == null) { 204bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell LayoutInflater inflater = LayoutInflater.from(getContext()); 205bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell mClose = inflater.inflate(R.layout.action_mode_close_item, this, false); 206bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell addView(mClose); 207bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell } else if (mClose.getParent() == null) { 208bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell addView(mClose); 209bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell } 210bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell 211bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell View closeButton = mClose.findViewById(R.id.action_mode_close_button); 212bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell closeButton.setOnClickListener(new View.OnClickListener() { 213bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell public void onClick(View v) { 214bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell mode.finish(); 215bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell } 216bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell }); 217bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell 218bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell final MenuBuilder menu = (MenuBuilder) mode.getMenu(); 219bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell if (mActionMenuPresenter != null) { 220bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell mActionMenuPresenter.dismissPopupMenus(); 221bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell } 222bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell mActionMenuPresenter = new ActionMenuPresenter(getContext()); 223bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell mActionMenuPresenter.setReserveOverflow(true); 224bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell 225bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell final ViewGroup.LayoutParams layoutParams = new ViewGroup.LayoutParams( 226bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell ViewGroup.LayoutParams.WRAP_CONTENT, 227bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell ViewGroup.LayoutParams.MATCH_PARENT); 228bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell if (!mSplitActionBar) { 229bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell // TODO(trevorjohns): Re-enable menu option 230bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell // menu.addMenuPresenter(mActionMenuPresenter); 231bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell mMenuView = (ActionMenuView) mActionMenuPresenter.getMenuView(this); 232bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell mMenuView.setBackgroundDrawable(null); 233bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell addView(mMenuView, layoutParams); 234bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell } else { 235bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell // Allow full screen width in split mode. 236bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell mActionMenuPresenter.setWidthLimit( 237bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell getContext().getResources().getDisplayMetrics().widthPixels, true); 238bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell // No limit to the item count; use whatever will fit. 239bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell mActionMenuPresenter.setItemLimit(Integer.MAX_VALUE); 240bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell // Span the whole width 241bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell layoutParams.width = ViewGroup.LayoutParams.MATCH_PARENT; 242bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell layoutParams.height = mContentHeight; 243bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell // TODO(trevorjohns): Re-enable menu option 244bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell // menu.addMenuPresenter(mActionMenuPresenter); 245bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell mMenuView = (ActionMenuView) mActionMenuPresenter.getMenuView(this); 246bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell mMenuView.setBackgroundDrawable(mSplitBackground); 247bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell mSplitView.addView(mMenuView, layoutParams); 248bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell } 249bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell 250bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell mAnimateInOnLayout = true; 251bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell } 252bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell 253bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell public void closeMode() { 254bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell if (mAnimationMode == ANIMATE_OUT) { 255bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell // Called again during close; just finish what we were doing. 256bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell return; 257bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell } 258bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell if (mClose == null) { 259bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell killMode(); 260bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell return; 261bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell } 262bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell 263bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell finishAnimation(); 264bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell mAnimationMode = ANIMATE_OUT; 265bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell mCurrentAnimation = makeOutAnimation(); 266bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell mCurrentAnimation.start(); 267bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell } 268bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell 269bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell private void finishAnimation() { 270bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell final Animator a = mCurrentAnimation; 271bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell if (a != null) { 272bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell mCurrentAnimation = null; 273bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell a.end(); 274bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell } 275bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell } 276bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell 277bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell public void killMode() { 278bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell finishAnimation(); 279bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell removeAllViews(); 280bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell if (mSplitView != null) { 281bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell mSplitView.removeView(mMenuView); 282bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell } 283bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell mCustomView = null; 284bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell mMenuView = null; 285bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell mAnimateInOnLayout = false; 286bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell } 287bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell 288bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell @Override 289bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell public boolean showOverflowMenu() { 290bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell if (mActionMenuPresenter != null) { 291bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell return mActionMenuPresenter.showOverflowMenu(); 292bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell } 293bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell return false; 294bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell } 295bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell 296bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell @Override 297bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell public boolean hideOverflowMenu() { 298bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell if (mActionMenuPresenter != null) { 299bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell return mActionMenuPresenter.hideOverflowMenu(); 300bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell } 301bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell return false; 302bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell } 303bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell 304bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell @Override 305bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell public boolean isOverflowMenuShowing() { 306bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell if (mActionMenuPresenter != null) { 307bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell return mActionMenuPresenter.isOverflowMenuShowing(); 308bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell } 309bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell return false; 310bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell } 311bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell 312bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell @Override 313bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell protected ViewGroup.LayoutParams generateDefaultLayoutParams() { 314bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell // Used by custom views if they don't supply layout params. Everything else 315bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell // added to an ActionBarContextView should have them already. 316bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell return new ViewGroup.MarginLayoutParams( 317bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT); 318bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell } 319bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell 320bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell @Override 321bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell public ViewGroup.LayoutParams generateLayoutParams(AttributeSet attrs) { 322bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell return new ViewGroup.MarginLayoutParams(getContext(), attrs); 323bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell } 324bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell 325bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell @Override 326bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) { 327bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell final int widthMode = View.MeasureSpec.getMode(widthMeasureSpec); 328bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell if (widthMode != View.MeasureSpec.EXACTLY) { 329bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell throw new IllegalStateException(getClass().getSimpleName() + " can only be used " + 330bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell "with android:layout_width=\"match_parent\" (or fill_parent)"); 331bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell } 332bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell 333bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell final int heightMode = View.MeasureSpec.getMode(heightMeasureSpec); 334bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell if (heightMode == View.MeasureSpec.UNSPECIFIED) { 335bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell throw new IllegalStateException(getClass().getSimpleName() + " can only be used " + 336bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell "with android:layout_height=\"wrap_content\""); 337bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell } 338bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell 339bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell final int contentWidth = View.MeasureSpec.getSize(widthMeasureSpec); 340bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell 341bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell int maxHeight = mContentHeight > 0 ? 342bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell mContentHeight : View.MeasureSpec.getSize(heightMeasureSpec); 343bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell 344bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell final int verticalPadding = getPaddingTop() + getPaddingBottom(); 345bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell int availableWidth = contentWidth - getPaddingLeft() - getPaddingRight(); 346bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell final int height = maxHeight - verticalPadding; 347bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell final int childSpecHeight = View.MeasureSpec 348bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell .makeMeasureSpec(height, View.MeasureSpec.AT_MOST); 349bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell 350bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell if (mClose != null) { 351bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell availableWidth = measureChildView(mClose, availableWidth, childSpecHeight, 0); 352bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell ViewGroup.MarginLayoutParams lp = (ViewGroup.MarginLayoutParams) mClose.getLayoutParams(); 353bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell availableWidth -= lp.leftMargin + lp.rightMargin; 354bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell } 355bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell 356bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell if (mMenuView != null && mMenuView.getParent() == this) { 357bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell availableWidth = measureChildView(mMenuView, availableWidth, 358bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell childSpecHeight, 0); 359bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell } 360bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell 361bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell if (mTitleLayout != null && mCustomView == null) { 362bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell if (mTitleOptional) { 363bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell final int titleWidthSpec = View.MeasureSpec 364bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell .makeMeasureSpec(0, View.MeasureSpec.UNSPECIFIED); 365bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell mTitleLayout.measure(titleWidthSpec, childSpecHeight); 366bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell final int titleWidth = mTitleLayout.getMeasuredWidth(); 367bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell final boolean titleFits = titleWidth <= availableWidth; 368bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell if (titleFits) { 369bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell availableWidth -= titleWidth; 370bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell } 371bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell mTitleLayout.setVisibility(titleFits ? VISIBLE : GONE); 372bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell } else { 373bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell availableWidth = measureChildView(mTitleLayout, availableWidth, childSpecHeight, 0); 374bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell } 375bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell } 376bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell 377bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell if (mCustomView != null) { 378bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell ViewGroup.LayoutParams lp = mCustomView.getLayoutParams(); 379bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell final int customWidthMode = lp.width != ViewGroup.LayoutParams.WRAP_CONTENT ? 380bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell View.MeasureSpec.EXACTLY : View.MeasureSpec.AT_MOST; 381bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell final int customWidth = lp.width >= 0 ? 382bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell Math.min(lp.width, availableWidth) : availableWidth; 383bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell final int customHeightMode = lp.height != ViewGroup.LayoutParams.WRAP_CONTENT ? 384bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell View.MeasureSpec.EXACTLY : View.MeasureSpec.AT_MOST; 385bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell final int customHeight = lp.height >= 0 ? 386bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell Math.min(lp.height, height) : height; 387bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell mCustomView.measure(View.MeasureSpec.makeMeasureSpec(customWidth, customWidthMode), 388bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell View.MeasureSpec.makeMeasureSpec(customHeight, customHeightMode)); 389bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell } 390bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell 391bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell if (mContentHeight <= 0) { 392bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell int measuredHeight = 0; 393bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell final int count = getChildCount(); 394bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell for (int i = 0; i < count; i++) { 395bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell View v = getChildAt(i); 396bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell int paddedViewHeight = v.getMeasuredHeight() + verticalPadding; 397bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell if (paddedViewHeight > measuredHeight) { 398bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell measuredHeight = paddedViewHeight; 399bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell } 400bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell } 401bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell setMeasuredDimension(contentWidth, measuredHeight); 402bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell } else { 403bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell setMeasuredDimension(contentWidth, maxHeight); 404bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell } 405bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell } 406bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell 407bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell private Animator makeInAnimation() { 408bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell mClose.setTranslationX(-mClose.getWidth() - 409bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell ((ViewGroup.MarginLayoutParams) mClose.getLayoutParams()).leftMargin); 410bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell ObjectAnimator buttonAnimator = ObjectAnimator.ofFloat(mClose, "translationX", 0); 411bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell buttonAnimator.setDuration(200); 412bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell buttonAnimator.addListener(this); 413bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell buttonAnimator.setInterpolator(new DecelerateInterpolator()); 414bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell 415bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell AnimatorSet set = new AnimatorSet(); 416bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell AnimatorSet.Builder b = set.play(buttonAnimator); 417bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell 418bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell if (mMenuView != null) { 419bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell final int count = mMenuView.getChildCount(); 420bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell if (count > 0) { 421bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell for (int i = count - 1, j = 0; i >= 0; i--, j++) { 422bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell View child = mMenuView.getChildAt(i); 423bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell child.setScaleY(0); 424bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell ObjectAnimator a = ObjectAnimator.ofFloat(child, "scaleY", 0, 1); 425bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell a.setDuration(300); 426bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell b.with(a); 427bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell } 428bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell } 429bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell } 430bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell 431bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell return set; 432bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell } 433bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell 434bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell private Animator makeOutAnimation() { 435bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell ObjectAnimator buttonAnimator = ObjectAnimator.ofFloat(mClose, "translationX", 436bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell -mClose.getWidth() - ((ViewGroup.MarginLayoutParams) mClose.getLayoutParams()).leftMargin); 437bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell buttonAnimator.setDuration(200); 438bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell buttonAnimator.addListener(this); 439bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell buttonAnimator.setInterpolator(new DecelerateInterpolator()); 440bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell 441bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell AnimatorSet set = new AnimatorSet(); 442bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell AnimatorSet.Builder b = set.play(buttonAnimator); 443bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell 444bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell if (mMenuView != null) { 445bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell final int count = mMenuView.getChildCount(); 446bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell if (count > 0) { 447bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell for (int i = 0; i < 0; i++) { 448bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell View child = mMenuView.getChildAt(i); 449bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell child.setScaleY(0); 450bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell ObjectAnimator a = ObjectAnimator.ofFloat(child, "scaleY", 0); 451bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell a.setDuration(300); 452bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell b.with(a); 453bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell } 454bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell } 455bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell } 456bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell 457bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell return set; 458bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell } 459bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell 460bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell @Override 461bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell protected void onLayout(boolean changed, int l, int t, int r, int b) { 462bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell int x = getPaddingLeft(); 463bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell final int y = getPaddingTop(); 464bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell final int contentHeight = b - t - getPaddingTop() - getPaddingBottom(); 465bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell 466bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell if (mClose != null && mClose.getVisibility() != GONE) { 467bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell ViewGroup.MarginLayoutParams lp = (ViewGroup.MarginLayoutParams) mClose.getLayoutParams(); 468bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell x += lp.leftMargin; 469bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell x += positionChild(mClose, x, y, contentHeight); 470bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell x += lp.rightMargin; 471bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell 472bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell if (mAnimateInOnLayout) { 473bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell mAnimationMode = ANIMATE_IN; 474bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell mCurrentAnimation = makeInAnimation(); 475bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell mCurrentAnimation.start(); 476bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell mAnimateInOnLayout = false; 477bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell } 478bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell } 479bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell 480bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell if (mTitleLayout != null && mCustomView == null && mTitleLayout.getVisibility() != GONE) { 481bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell x += positionChild(mTitleLayout, x, y, contentHeight); 482bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell } 483bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell 484bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell if (mCustomView != null) { 485bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell x += positionChild(mCustomView, x, y, contentHeight); 486bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell } 487bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell 488bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell x = r - l - getPaddingRight(); 489bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell 490bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell if (mMenuView != null) { 491bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell x -= positionChildInverse(mMenuView, x, y, contentHeight); 492bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell } 493bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell } 494bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell 495bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell @Override 496bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell public void onAnimationStart(Animator animation) { 497bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell } 498bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell 499bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell @Override 500bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell public void onAnimationEnd(Animator animation) { 501bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell if (mAnimationMode == ANIMATE_OUT) { 502bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell killMode(); 503bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell } 504bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell mAnimationMode = ANIMATE_IDLE; 505bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell } 506bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell 507bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell @Override 508bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell public void onAnimationCancel(Animator animation) { 509bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell } 510bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell 511bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell @Override 512bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell public void onAnimationRepeat(Animator animation) { 513bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell } 514bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell 515bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell @Override 516bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell public boolean shouldDelayChildPressedState() { 517bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell return false; 518bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell } 519bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell 520bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell @Override 521bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell public void onInitializeAccessibilityEvent(AccessibilityEvent event) { 522bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell if (event.getEventType() == AccessibilityEvent.TYPE_WINDOW_STATE_CHANGED) { 523bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell // Action mode started 524bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell event.setSource(this); 525bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell event.setClassName(getClass().getName()); 526bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell event.setPackageName(getContext().getPackageName()); 527bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell event.setContentDescription(mTitle); 528bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell } else { 529bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell super.onInitializeAccessibilityEvent(event); 530bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell } 531bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell } 532bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell 533bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell public void setTitleOptional(boolean titleOptional) { 534bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell if (titleOptional != mTitleOptional) { 535bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell requestLayout(); 536bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell } 537bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell mTitleOptional = titleOptional; 538bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell } 539bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell 540bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell public boolean isTitleOptional() { 541bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell return mTitleOptional; 542bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell } 543bbbb8f39d1b1d1b317c5f9237f20fe6b1d9eb17fAdam Powell} 544