1640a66eac612b850b5dabd3b93bd94f83ed2d567Adam Powell/* 2640a66eac612b850b5dabd3b93bd94f83ed2d567Adam Powell * Copyright (C) 2011 The Android Open Source Project 3640a66eac612b850b5dabd3b93bd94f83ed2d567Adam Powell * 4640a66eac612b850b5dabd3b93bd94f83ed2d567Adam Powell * Licensed under the Apache License, Version 2.0 (the "License"); 5640a66eac612b850b5dabd3b93bd94f83ed2d567Adam Powell * you may not use this file except in compliance with the License. 6640a66eac612b850b5dabd3b93bd94f83ed2d567Adam Powell * You may obtain a copy of the License at 7640a66eac612b850b5dabd3b93bd94f83ed2d567Adam Powell * 8640a66eac612b850b5dabd3b93bd94f83ed2d567Adam Powell * http://www.apache.org/licenses/LICENSE-2.0 9640a66eac612b850b5dabd3b93bd94f83ed2d567Adam Powell * 10640a66eac612b850b5dabd3b93bd94f83ed2d567Adam Powell * Unless required by applicable law or agreed to in writing, software 11640a66eac612b850b5dabd3b93bd94f83ed2d567Adam Powell * distributed under the License is distributed on an "AS IS" BASIS, 12640a66eac612b850b5dabd3b93bd94f83ed2d567Adam Powell * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13640a66eac612b850b5dabd3b93bd94f83ed2d567Adam Powell * See the License for the specific language governing permissions and 14640a66eac612b850b5dabd3b93bd94f83ed2d567Adam Powell * limitations under the License. 15640a66eac612b850b5dabd3b93bd94f83ed2d567Adam Powell */ 16640a66eac612b850b5dabd3b93bd94f83ed2d567Adam Powellpackage com.android.internal.widget; 17640a66eac612b850b5dabd3b93bd94f83ed2d567Adam Powell 18425689eea2f4f208f29b944b4973981bdbeda9f5Adam Powellimport com.android.internal.R; 19640a66eac612b850b5dabd3b93bd94f83ed2d567Adam Powellimport com.android.internal.view.menu.ActionMenuPresenter; 20640a66eac612b850b5dabd3b93bd94f83ed2d567Adam Powellimport com.android.internal.view.menu.ActionMenuView; 21640a66eac612b850b5dabd3b93bd94f83ed2d567Adam Powell 22640a66eac612b850b5dabd3b93bd94f83ed2d567Adam Powellimport android.animation.Animator; 23640a66eac612b850b5dabd3b93bd94f83ed2d567Adam Powellimport android.animation.AnimatorSet; 24640a66eac612b850b5dabd3b93bd94f83ed2d567Adam Powellimport android.animation.ObjectAnimator; 25640a66eac612b850b5dabd3b93bd94f83ed2d567Adam Powellimport android.animation.TimeInterpolator; 26640a66eac612b850b5dabd3b93bd94f83ed2d567Adam Powellimport android.content.Context; 27425689eea2f4f208f29b944b4973981bdbeda9f5Adam Powellimport android.content.res.Configuration; 28425689eea2f4f208f29b944b4973981bdbeda9f5Adam Powellimport android.content.res.TypedArray; 29640a66eac612b850b5dabd3b93bd94f83ed2d567Adam Powellimport android.util.AttributeSet; 30640a66eac612b850b5dabd3b93bd94f83ed2d567Adam Powellimport android.view.View; 31640a66eac612b850b5dabd3b93bd94f83ed2d567Adam Powellimport android.view.ViewGroup; 32640a66eac612b850b5dabd3b93bd94f83ed2d567Adam Powellimport android.view.animation.DecelerateInterpolator; 33640a66eac612b850b5dabd3b93bd94f83ed2d567Adam Powell 34640a66eac612b850b5dabd3b93bd94f83ed2d567Adam Powellpublic abstract class AbsActionBarView extends ViewGroup { 35640a66eac612b850b5dabd3b93bd94f83ed2d567Adam Powell protected ActionMenuView mMenuView; 368d02deabac62c4a68a335a7b3141795466362b89Adam Powell protected ActionMenuPresenter mActionMenuPresenter; 37640a66eac612b850b5dabd3b93bd94f83ed2d567Adam Powell protected ActionBarContainer mSplitView; 38a05aba9c506cd12a753c53e060c289095c3477e9Adam Powell protected boolean mSplitActionBar; 39a05aba9c506cd12a753c53e060c289095c3477e9Adam Powell protected boolean mSplitWhenNarrow; 40425689eea2f4f208f29b944b4973981bdbeda9f5Adam Powell protected int mContentHeight; 41640a66eac612b850b5dabd3b93bd94f83ed2d567Adam Powell 42640a66eac612b850b5dabd3b93bd94f83ed2d567Adam Powell protected Animator mVisibilityAnim; 43640a66eac612b850b5dabd3b93bd94f83ed2d567Adam Powell protected final VisibilityAnimListener mVisAnimListener = new VisibilityAnimListener(); 44640a66eac612b850b5dabd3b93bd94f83ed2d567Adam Powell 45640a66eac612b850b5dabd3b93bd94f83ed2d567Adam Powell private static final TimeInterpolator sAlphaInterpolator = new DecelerateInterpolator(); 46640a66eac612b850b5dabd3b93bd94f83ed2d567Adam Powell 47640a66eac612b850b5dabd3b93bd94f83ed2d567Adam Powell private static final int FADE_DURATION = 200; 48640a66eac612b850b5dabd3b93bd94f83ed2d567Adam Powell 49640a66eac612b850b5dabd3b93bd94f83ed2d567Adam Powell public AbsActionBarView(Context context) { 50640a66eac612b850b5dabd3b93bd94f83ed2d567Adam Powell super(context); 51640a66eac612b850b5dabd3b93bd94f83ed2d567Adam Powell } 52640a66eac612b850b5dabd3b93bd94f83ed2d567Adam Powell 53640a66eac612b850b5dabd3b93bd94f83ed2d567Adam Powell public AbsActionBarView(Context context, AttributeSet attrs) { 54640a66eac612b850b5dabd3b93bd94f83ed2d567Adam Powell super(context, attrs); 55640a66eac612b850b5dabd3b93bd94f83ed2d567Adam Powell } 56640a66eac612b850b5dabd3b93bd94f83ed2d567Adam Powell 57640a66eac612b850b5dabd3b93bd94f83ed2d567Adam Powell public AbsActionBarView(Context context, AttributeSet attrs, int defStyle) { 58640a66eac612b850b5dabd3b93bd94f83ed2d567Adam Powell super(context, attrs, defStyle); 59640a66eac612b850b5dabd3b93bd94f83ed2d567Adam Powell } 60640a66eac612b850b5dabd3b93bd94f83ed2d567Adam Powell 61425689eea2f4f208f29b944b4973981bdbeda9f5Adam Powell @Override 62425689eea2f4f208f29b944b4973981bdbeda9f5Adam Powell protected void onConfigurationChanged(Configuration newConfig) { 63425689eea2f4f208f29b944b4973981bdbeda9f5Adam Powell super.onConfigurationChanged(newConfig); 64425689eea2f4f208f29b944b4973981bdbeda9f5Adam Powell 65425689eea2f4f208f29b944b4973981bdbeda9f5Adam Powell // Action bar can change size on configuration changes. 66425689eea2f4f208f29b944b4973981bdbeda9f5Adam Powell // Reread the desired height from the theme-specified style. 67425689eea2f4f208f29b944b4973981bdbeda9f5Adam Powell TypedArray a = getContext().obtainStyledAttributes(null, R.styleable.ActionBar, 68425689eea2f4f208f29b944b4973981bdbeda9f5Adam Powell com.android.internal.R.attr.actionBarStyle, 0); 69425689eea2f4f208f29b944b4973981bdbeda9f5Adam Powell setContentHeight(a.getLayoutDimension(R.styleable.ActionBar_height, 0)); 70425689eea2f4f208f29b944b4973981bdbeda9f5Adam Powell a.recycle(); 71a05aba9c506cd12a753c53e060c289095c3477e9Adam Powell if (mSplitWhenNarrow) { 72a05aba9c506cd12a753c53e060c289095c3477e9Adam Powell setSplitActionBar(getContext().getResources().getBoolean( 73a05aba9c506cd12a753c53e060c289095c3477e9Adam Powell com.android.internal.R.bool.split_action_bar_is_narrow)); 74a05aba9c506cd12a753c53e060c289095c3477e9Adam Powell } 75425689eea2f4f208f29b944b4973981bdbeda9f5Adam Powell if (mActionMenuPresenter != null) { 76425689eea2f4f208f29b944b4973981bdbeda9f5Adam Powell mActionMenuPresenter.onConfigurationChanged(newConfig); 77425689eea2f4f208f29b944b4973981bdbeda9f5Adam Powell } 78425689eea2f4f208f29b944b4973981bdbeda9f5Adam Powell } 79425689eea2f4f208f29b944b4973981bdbeda9f5Adam Powell 80a05aba9c506cd12a753c53e060c289095c3477e9Adam Powell /** 81a05aba9c506cd12a753c53e060c289095c3477e9Adam Powell * Sets whether the bar should be split right now, no questions asked. 82a05aba9c506cd12a753c53e060c289095c3477e9Adam Powell * @param split true if the bar should split 83a05aba9c506cd12a753c53e060c289095c3477e9Adam Powell */ 84a05aba9c506cd12a753c53e060c289095c3477e9Adam Powell public void setSplitActionBar(boolean split) { 85a05aba9c506cd12a753c53e060c289095c3477e9Adam Powell mSplitActionBar = split; 86a05aba9c506cd12a753c53e060c289095c3477e9Adam Powell } 87a05aba9c506cd12a753c53e060c289095c3477e9Adam Powell 88a05aba9c506cd12a753c53e060c289095c3477e9Adam Powell /** 89a05aba9c506cd12a753c53e060c289095c3477e9Adam Powell * Sets whether the bar should split if we enter a narrow screen configuration. 90a05aba9c506cd12a753c53e060c289095c3477e9Adam Powell * @param splitWhenNarrow true if the bar should check to split after a config change 91a05aba9c506cd12a753c53e060c289095c3477e9Adam Powell */ 92a05aba9c506cd12a753c53e060c289095c3477e9Adam Powell public void setSplitWhenNarrow(boolean splitWhenNarrow) { 93a05aba9c506cd12a753c53e060c289095c3477e9Adam Powell mSplitWhenNarrow = splitWhenNarrow; 94a05aba9c506cd12a753c53e060c289095c3477e9Adam Powell } 95a05aba9c506cd12a753c53e060c289095c3477e9Adam Powell 96425689eea2f4f208f29b944b4973981bdbeda9f5Adam Powell public void setContentHeight(int height) { 97425689eea2f4f208f29b944b4973981bdbeda9f5Adam Powell mContentHeight = height; 98d5c81db1e78e98f3e0a1a5cf206865c3056294c4Adam Powell if (mMenuView != null) { 99d5c81db1e78e98f3e0a1a5cf206865c3056294c4Adam Powell mMenuView.setMaxItemHeight(mContentHeight); 100d5c81db1e78e98f3e0a1a5cf206865c3056294c4Adam Powell } 101425689eea2f4f208f29b944b4973981bdbeda9f5Adam Powell requestLayout(); 102425689eea2f4f208f29b944b4973981bdbeda9f5Adam Powell } 103425689eea2f4f208f29b944b4973981bdbeda9f5Adam Powell 104425689eea2f4f208f29b944b4973981bdbeda9f5Adam Powell public int getContentHeight() { 105425689eea2f4f208f29b944b4973981bdbeda9f5Adam Powell return mContentHeight; 106425689eea2f4f208f29b944b4973981bdbeda9f5Adam Powell } 107425689eea2f4f208f29b944b4973981bdbeda9f5Adam Powell 108640a66eac612b850b5dabd3b93bd94f83ed2d567Adam Powell public void setSplitView(ActionBarContainer splitView) { 109640a66eac612b850b5dabd3b93bd94f83ed2d567Adam Powell mSplitView = splitView; 110640a66eac612b850b5dabd3b93bd94f83ed2d567Adam Powell } 111640a66eac612b850b5dabd3b93bd94f83ed2d567Adam Powell 1129a5cc2810bbbcb0eab4579aa4131039820d92101Adam Powell /** 1139a5cc2810bbbcb0eab4579aa4131039820d92101Adam Powell * @return Current visibility or if animating, the visibility being animated to. 1149a5cc2810bbbcb0eab4579aa4131039820d92101Adam Powell */ 1159a5cc2810bbbcb0eab4579aa4131039820d92101Adam Powell public int getAnimatedVisibility() { 1169a5cc2810bbbcb0eab4579aa4131039820d92101Adam Powell if (mVisibilityAnim != null) { 1179a5cc2810bbbcb0eab4579aa4131039820d92101Adam Powell return mVisAnimListener.mFinalVisibility; 1189a5cc2810bbbcb0eab4579aa4131039820d92101Adam Powell } 1199a5cc2810bbbcb0eab4579aa4131039820d92101Adam Powell return getVisibility(); 1209a5cc2810bbbcb0eab4579aa4131039820d92101Adam Powell } 1219a5cc2810bbbcb0eab4579aa4131039820d92101Adam Powell 122640a66eac612b850b5dabd3b93bd94f83ed2d567Adam Powell public void animateToVisibility(int visibility) { 123640a66eac612b850b5dabd3b93bd94f83ed2d567Adam Powell if (mVisibilityAnim != null) { 124640a66eac612b850b5dabd3b93bd94f83ed2d567Adam Powell mVisibilityAnim.cancel(); 125640a66eac612b850b5dabd3b93bd94f83ed2d567Adam Powell } 126640a66eac612b850b5dabd3b93bd94f83ed2d567Adam Powell if (visibility == VISIBLE) { 127640a66eac612b850b5dabd3b93bd94f83ed2d567Adam Powell if (getVisibility() != VISIBLE) { 128640a66eac612b850b5dabd3b93bd94f83ed2d567Adam Powell setAlpha(0); 129640a66eac612b850b5dabd3b93bd94f83ed2d567Adam Powell if (mSplitView != null && mMenuView != null) { 130640a66eac612b850b5dabd3b93bd94f83ed2d567Adam Powell mMenuView.setAlpha(0); 131640a66eac612b850b5dabd3b93bd94f83ed2d567Adam Powell } 132640a66eac612b850b5dabd3b93bd94f83ed2d567Adam Powell } 133640a66eac612b850b5dabd3b93bd94f83ed2d567Adam Powell ObjectAnimator anim = ObjectAnimator.ofFloat(this, "alpha", 1); 134640a66eac612b850b5dabd3b93bd94f83ed2d567Adam Powell anim.setDuration(FADE_DURATION); 135640a66eac612b850b5dabd3b93bd94f83ed2d567Adam Powell anim.setInterpolator(sAlphaInterpolator); 136640a66eac612b850b5dabd3b93bd94f83ed2d567Adam Powell if (mSplitView != null && mMenuView != null) { 137640a66eac612b850b5dabd3b93bd94f83ed2d567Adam Powell AnimatorSet set = new AnimatorSet(); 138640a66eac612b850b5dabd3b93bd94f83ed2d567Adam Powell ObjectAnimator splitAnim = ObjectAnimator.ofFloat(mMenuView, "alpha", 1); 139640a66eac612b850b5dabd3b93bd94f83ed2d567Adam Powell splitAnim.setDuration(FADE_DURATION); 140640a66eac612b850b5dabd3b93bd94f83ed2d567Adam Powell set.addListener(mVisAnimListener.withFinalVisibility(visibility)); 141640a66eac612b850b5dabd3b93bd94f83ed2d567Adam Powell set.play(anim).with(splitAnim); 1425c1cb19f4075b3c4ab895a30ab5f2469aff5b553Adam Powell set.start(); 143640a66eac612b850b5dabd3b93bd94f83ed2d567Adam Powell } else { 144640a66eac612b850b5dabd3b93bd94f83ed2d567Adam Powell anim.addListener(mVisAnimListener.withFinalVisibility(visibility)); 145640a66eac612b850b5dabd3b93bd94f83ed2d567Adam Powell anim.start(); 146640a66eac612b850b5dabd3b93bd94f83ed2d567Adam Powell } 147640a66eac612b850b5dabd3b93bd94f83ed2d567Adam Powell } else { 148640a66eac612b850b5dabd3b93bd94f83ed2d567Adam Powell ObjectAnimator anim = ObjectAnimator.ofFloat(this, "alpha", 0); 149640a66eac612b850b5dabd3b93bd94f83ed2d567Adam Powell anim.setDuration(FADE_DURATION); 150640a66eac612b850b5dabd3b93bd94f83ed2d567Adam Powell anim.setInterpolator(sAlphaInterpolator); 151640a66eac612b850b5dabd3b93bd94f83ed2d567Adam Powell if (mSplitView != null && mMenuView != null) { 152640a66eac612b850b5dabd3b93bd94f83ed2d567Adam Powell AnimatorSet set = new AnimatorSet(); 153640a66eac612b850b5dabd3b93bd94f83ed2d567Adam Powell ObjectAnimator splitAnim = ObjectAnimator.ofFloat(mMenuView, "alpha", 0); 154640a66eac612b850b5dabd3b93bd94f83ed2d567Adam Powell splitAnim.setDuration(FADE_DURATION); 155640a66eac612b850b5dabd3b93bd94f83ed2d567Adam Powell set.addListener(mVisAnimListener.withFinalVisibility(visibility)); 156640a66eac612b850b5dabd3b93bd94f83ed2d567Adam Powell set.play(anim).with(splitAnim); 1575c1cb19f4075b3c4ab895a30ab5f2469aff5b553Adam Powell set.start(); 158640a66eac612b850b5dabd3b93bd94f83ed2d567Adam Powell } else { 159640a66eac612b850b5dabd3b93bd94f83ed2d567Adam Powell anim.addListener(mVisAnimListener.withFinalVisibility(visibility)); 160640a66eac612b850b5dabd3b93bd94f83ed2d567Adam Powell anim.start(); 161640a66eac612b850b5dabd3b93bd94f83ed2d567Adam Powell } 162640a66eac612b850b5dabd3b93bd94f83ed2d567Adam Powell } 163640a66eac612b850b5dabd3b93bd94f83ed2d567Adam Powell } 164640a66eac612b850b5dabd3b93bd94f83ed2d567Adam Powell 165640a66eac612b850b5dabd3b93bd94f83ed2d567Adam Powell @Override 166640a66eac612b850b5dabd3b93bd94f83ed2d567Adam Powell public void setVisibility(int visibility) { 1679caeb145721238897809805f521bb5c8ef375c0fGeorge Mount if (visibility != getVisibility()) { 1689caeb145721238897809805f521bb5c8ef375c0fGeorge Mount if (mVisibilityAnim != null) { 1699caeb145721238897809805f521bb5c8ef375c0fGeorge Mount mVisibilityAnim.end(); 1709caeb145721238897809805f521bb5c8ef375c0fGeorge Mount } 1719caeb145721238897809805f521bb5c8ef375c0fGeorge Mount super.setVisibility(visibility); 172640a66eac612b850b5dabd3b93bd94f83ed2d567Adam Powell } 173640a66eac612b850b5dabd3b93bd94f83ed2d567Adam Powell } 174640a66eac612b850b5dabd3b93bd94f83ed2d567Adam Powell 175640a66eac612b850b5dabd3b93bd94f83ed2d567Adam Powell public boolean showOverflowMenu() { 1768d02deabac62c4a68a335a7b3141795466362b89Adam Powell if (mActionMenuPresenter != null) { 1778d02deabac62c4a68a335a7b3141795466362b89Adam Powell return mActionMenuPresenter.showOverflowMenu(); 178640a66eac612b850b5dabd3b93bd94f83ed2d567Adam Powell } 179640a66eac612b850b5dabd3b93bd94f83ed2d567Adam Powell return false; 180640a66eac612b850b5dabd3b93bd94f83ed2d567Adam Powell } 181640a66eac612b850b5dabd3b93bd94f83ed2d567Adam Powell 182640a66eac612b850b5dabd3b93bd94f83ed2d567Adam Powell public void postShowOverflowMenu() { 183640a66eac612b850b5dabd3b93bd94f83ed2d567Adam Powell post(new Runnable() { 184640a66eac612b850b5dabd3b93bd94f83ed2d567Adam Powell public void run() { 185640a66eac612b850b5dabd3b93bd94f83ed2d567Adam Powell showOverflowMenu(); 186640a66eac612b850b5dabd3b93bd94f83ed2d567Adam Powell } 187640a66eac612b850b5dabd3b93bd94f83ed2d567Adam Powell }); 188640a66eac612b850b5dabd3b93bd94f83ed2d567Adam Powell } 189640a66eac612b850b5dabd3b93bd94f83ed2d567Adam Powell 190640a66eac612b850b5dabd3b93bd94f83ed2d567Adam Powell public boolean hideOverflowMenu() { 1918d02deabac62c4a68a335a7b3141795466362b89Adam Powell if (mActionMenuPresenter != null) { 1928d02deabac62c4a68a335a7b3141795466362b89Adam Powell return mActionMenuPresenter.hideOverflowMenu(); 193640a66eac612b850b5dabd3b93bd94f83ed2d567Adam Powell } 194640a66eac612b850b5dabd3b93bd94f83ed2d567Adam Powell return false; 195640a66eac612b850b5dabd3b93bd94f83ed2d567Adam Powell } 196640a66eac612b850b5dabd3b93bd94f83ed2d567Adam Powell 197640a66eac612b850b5dabd3b93bd94f83ed2d567Adam Powell public boolean isOverflowMenuShowing() { 1988d02deabac62c4a68a335a7b3141795466362b89Adam Powell if (mActionMenuPresenter != null) { 1998d02deabac62c4a68a335a7b3141795466362b89Adam Powell return mActionMenuPresenter.isOverflowMenuShowing(); 200640a66eac612b850b5dabd3b93bd94f83ed2d567Adam Powell } 201640a66eac612b850b5dabd3b93bd94f83ed2d567Adam Powell return false; 202640a66eac612b850b5dabd3b93bd94f83ed2d567Adam Powell } 203640a66eac612b850b5dabd3b93bd94f83ed2d567Adam Powell 204640a66eac612b850b5dabd3b93bd94f83ed2d567Adam Powell public boolean isOverflowReserved() { 2058d02deabac62c4a68a335a7b3141795466362b89Adam Powell return mActionMenuPresenter != null && mActionMenuPresenter.isOverflowReserved(); 206640a66eac612b850b5dabd3b93bd94f83ed2d567Adam Powell } 207640a66eac612b850b5dabd3b93bd94f83ed2d567Adam Powell 208640a66eac612b850b5dabd3b93bd94f83ed2d567Adam Powell public void dismissPopupMenus() { 2098d02deabac62c4a68a335a7b3141795466362b89Adam Powell if (mActionMenuPresenter != null) { 2108d02deabac62c4a68a335a7b3141795466362b89Adam Powell mActionMenuPresenter.dismissPopupMenus(); 211640a66eac612b850b5dabd3b93bd94f83ed2d567Adam Powell } 212640a66eac612b850b5dabd3b93bd94f83ed2d567Adam Powell } 213640a66eac612b850b5dabd3b93bd94f83ed2d567Adam Powell 214640a66eac612b850b5dabd3b93bd94f83ed2d567Adam Powell protected int measureChildView(View child, int availableWidth, int childSpecHeight, 215640a66eac612b850b5dabd3b93bd94f83ed2d567Adam Powell int spacing) { 216640a66eac612b850b5dabd3b93bd94f83ed2d567Adam Powell child.measure(MeasureSpec.makeMeasureSpec(availableWidth, MeasureSpec.AT_MOST), 217640a66eac612b850b5dabd3b93bd94f83ed2d567Adam Powell childSpecHeight); 218640a66eac612b850b5dabd3b93bd94f83ed2d567Adam Powell 219640a66eac612b850b5dabd3b93bd94f83ed2d567Adam Powell availableWidth -= child.getMeasuredWidth(); 220640a66eac612b850b5dabd3b93bd94f83ed2d567Adam Powell availableWidth -= spacing; 221640a66eac612b850b5dabd3b93bd94f83ed2d567Adam Powell 2225d4034a37e5ac3832b91388024f6eddf343cf3f6Adam Powell return Math.max(0, availableWidth); 223640a66eac612b850b5dabd3b93bd94f83ed2d567Adam Powell } 224640a66eac612b850b5dabd3b93bd94f83ed2d567Adam Powell 225cf1ba0298c48ae56608ed556dc715eb69c54f9b9Fabrice Di Meglio static protected int next(int x, int val, boolean isRtl) { 226cf1ba0298c48ae56608ed556dc715eb69c54f9b9Fabrice Di Meglio return isRtl ? x - val : x + val; 227640a66eac612b850b5dabd3b93bd94f83ed2d567Adam Powell } 228640a66eac612b850b5dabd3b93bd94f83ed2d567Adam Powell 229cf1ba0298c48ae56608ed556dc715eb69c54f9b9Fabrice Di Meglio protected int positionChild(View child, int x, int y, int contentHeight, boolean reverse) { 230640a66eac612b850b5dabd3b93bd94f83ed2d567Adam Powell int childWidth = child.getMeasuredWidth(); 231640a66eac612b850b5dabd3b93bd94f83ed2d567Adam Powell int childHeight = child.getMeasuredHeight(); 232640a66eac612b850b5dabd3b93bd94f83ed2d567Adam Powell int childTop = y + (contentHeight - childHeight) / 2; 233640a66eac612b850b5dabd3b93bd94f83ed2d567Adam Powell 234cf1ba0298c48ae56608ed556dc715eb69c54f9b9Fabrice Di Meglio if (reverse) { 235cf1ba0298c48ae56608ed556dc715eb69c54f9b9Fabrice Di Meglio child.layout(x - childWidth, childTop, x, childTop + childHeight); 236cf1ba0298c48ae56608ed556dc715eb69c54f9b9Fabrice Di Meglio } else { 237cf1ba0298c48ae56608ed556dc715eb69c54f9b9Fabrice Di Meglio child.layout(x, childTop, x + childWidth, childTop + childHeight); 238cf1ba0298c48ae56608ed556dc715eb69c54f9b9Fabrice Di Meglio } 239640a66eac612b850b5dabd3b93bd94f83ed2d567Adam Powell 240cf1ba0298c48ae56608ed556dc715eb69c54f9b9Fabrice Di Meglio return (reverse ? -childWidth : childWidth); 241640a66eac612b850b5dabd3b93bd94f83ed2d567Adam Powell } 242640a66eac612b850b5dabd3b93bd94f83ed2d567Adam Powell 243640a66eac612b850b5dabd3b93bd94f83ed2d567Adam Powell protected class VisibilityAnimListener implements Animator.AnimatorListener { 244640a66eac612b850b5dabd3b93bd94f83ed2d567Adam Powell private boolean mCanceled = false; 2459a5cc2810bbbcb0eab4579aa4131039820d92101Adam Powell int mFinalVisibility; 246640a66eac612b850b5dabd3b93bd94f83ed2d567Adam Powell 247640a66eac612b850b5dabd3b93bd94f83ed2d567Adam Powell public VisibilityAnimListener withFinalVisibility(int visibility) { 248640a66eac612b850b5dabd3b93bd94f83ed2d567Adam Powell mFinalVisibility = visibility; 249640a66eac612b850b5dabd3b93bd94f83ed2d567Adam Powell return this; 250640a66eac612b850b5dabd3b93bd94f83ed2d567Adam Powell } 251640a66eac612b850b5dabd3b93bd94f83ed2d567Adam Powell 252640a66eac612b850b5dabd3b93bd94f83ed2d567Adam Powell @Override 253640a66eac612b850b5dabd3b93bd94f83ed2d567Adam Powell public void onAnimationStart(Animator animation) { 254640a66eac612b850b5dabd3b93bd94f83ed2d567Adam Powell setVisibility(VISIBLE); 255640a66eac612b850b5dabd3b93bd94f83ed2d567Adam Powell mVisibilityAnim = animation; 256640a66eac612b850b5dabd3b93bd94f83ed2d567Adam Powell mCanceled = false; 257640a66eac612b850b5dabd3b93bd94f83ed2d567Adam Powell } 258640a66eac612b850b5dabd3b93bd94f83ed2d567Adam Powell 259640a66eac612b850b5dabd3b93bd94f83ed2d567Adam Powell @Override 260640a66eac612b850b5dabd3b93bd94f83ed2d567Adam Powell public void onAnimationEnd(Animator animation) { 261640a66eac612b850b5dabd3b93bd94f83ed2d567Adam Powell if (mCanceled) return; 262640a66eac612b850b5dabd3b93bd94f83ed2d567Adam Powell 263640a66eac612b850b5dabd3b93bd94f83ed2d567Adam Powell mVisibilityAnim = null; 264640a66eac612b850b5dabd3b93bd94f83ed2d567Adam Powell setVisibility(mFinalVisibility); 2659a5cc2810bbbcb0eab4579aa4131039820d92101Adam Powell if (mSplitView != null && mMenuView != null) { 2669a5cc2810bbbcb0eab4579aa4131039820d92101Adam Powell mMenuView.setVisibility(mFinalVisibility); 2679a5cc2810bbbcb0eab4579aa4131039820d92101Adam Powell } 268640a66eac612b850b5dabd3b93bd94f83ed2d567Adam Powell } 269640a66eac612b850b5dabd3b93bd94f83ed2d567Adam Powell 270640a66eac612b850b5dabd3b93bd94f83ed2d567Adam Powell @Override 271640a66eac612b850b5dabd3b93bd94f83ed2d567Adam Powell public void onAnimationCancel(Animator animation) { 272640a66eac612b850b5dabd3b93bd94f83ed2d567Adam Powell mCanceled = true; 273640a66eac612b850b5dabd3b93bd94f83ed2d567Adam Powell } 274640a66eac612b850b5dabd3b93bd94f83ed2d567Adam Powell 275640a66eac612b850b5dabd3b93bd94f83ed2d567Adam Powell @Override 276640a66eac612b850b5dabd3b93bd94f83ed2d567Adam Powell public void onAnimationRepeat(Animator animation) { 277640a66eac612b850b5dabd3b93bd94f83ed2d567Adam Powell } 278640a66eac612b850b5dabd3b93bd94f83ed2d567Adam Powell } 279640a66eac612b850b5dabd3b93bd94f83ed2d567Adam Powell} 280