diff options
Diffstat (limited to 'src/com/android/tv/menu/MenuLayoutManager.java')
-rw-r--r-- | src/com/android/tv/menu/MenuLayoutManager.java | 540 |
1 files changed, 333 insertions, 207 deletions
diff --git a/src/com/android/tv/menu/MenuLayoutManager.java b/src/com/android/tv/menu/MenuLayoutManager.java index 173d4004..a600f704 100644 --- a/src/com/android/tv/menu/MenuLayoutManager.java +++ b/src/com/android/tv/menu/MenuLayoutManager.java @@ -34,11 +34,9 @@ import android.util.Property; import android.view.View; import android.view.ViewGroup.MarginLayoutParams; import android.widget.TextView; - import com.android.tv.R; import com.android.tv.common.SoftPreconditions; import com.android.tv.util.Utils; - import java.util.ArrayList; import java.util.Collections; import java.util.HashMap; @@ -47,9 +45,7 @@ import java.util.Map; import java.util.Map.Entry; import java.util.concurrent.TimeUnit; -/** - * A view that represents TV main menu. - */ +/** A view that represents TV main menu. */ @UiThread public class MenuLayoutManager { static final String TAG = "MenuLayoutManager"; @@ -93,24 +89,22 @@ public class MenuLayoutManager { Resources res = context.getResources(); mRowAlignFromBottom = res.getDimensionPixelOffset(R.dimen.menu_row_align_from_bottom); mRowContentsPaddingTop = res.getDimensionPixelOffset(R.dimen.menu_row_contents_padding_top); - mRowContentsPaddingBottomMax = res.getDimensionPixelOffset( - R.dimen.menu_row_contents_padding_bottom_max); - mRowTitleTextDescenderHeight = res.getDimensionPixelOffset( - R.dimen.menu_row_title_text_descender_height); + mRowContentsPaddingBottomMax = + res.getDimensionPixelOffset(R.dimen.menu_row_contents_padding_bottom_max); + mRowTitleTextDescenderHeight = + res.getDimensionPixelOffset(R.dimen.menu_row_title_text_descender_height); mMenuMarginBottomMin = res.getDimensionPixelOffset(R.dimen.menu_margin_bottom_min); mRowTitleHeight = res.getDimensionPixelSize(R.dimen.menu_row_title_height); mRowScrollUpAnimationOffset = res.getDimensionPixelOffset(R.dimen.menu_row_scroll_up_anim_offset); mRowAnimationDuration = res.getInteger(R.integer.menu_row_selection_anim_duration); - mOldContentsFadeOutDuration = res.getInteger( - R.integer.menu_previous_contents_fade_out_duration); - mCurrentContentsFadeInDuration = res.getInteger( - R.integer.menu_current_contents_fade_in_duration); + mOldContentsFadeOutDuration = + res.getInteger(R.integer.menu_previous_contents_fade_out_duration); + mCurrentContentsFadeInDuration = + res.getInteger(R.integer.menu_current_contents_fade_in_duration); } - /** - * Sets the menu rows and views. - */ + /** Sets the menu rows and views. */ public void setMenuRowsAndViews(List<MenuRow> menuRows, List<MenuRowView> menuRowViews) { mMenuRows.clear(); mMenuRows.addAll(menuRows); @@ -181,22 +175,54 @@ public class MenuLayoutManager { for (MenuRowView view : mMenuRowViews) { View title = view.getChildAt(0); View contents = view.getChildAt(1); - Log.d(TAG, prefix + " position=" + position++ - + " rowView={visiblility=" + view.getVisibility() - + ", alpha=" + view.getAlpha() - + ", translationY=" + view.getTranslationY() - + ", left=" + view.getLeft() + ", top=" + view.getTop() - + ", right=" + view.getRight() + ", bottom=" + view.getBottom() - + "}, title={visiblility=" + title.getVisibility() - + ", alpha=" + title.getAlpha() - + ", translationY=" + title.getTranslationY() - + ", left=" + title.getLeft() + ", top=" + title.getTop() - + ", right=" + title.getRight() + ", bottom=" + title.getBottom() - + "}, contents={visiblility=" + contents.getVisibility() - + ", alpha=" + contents.getAlpha() - + ", translationY=" + contents.getTranslationY() - + ", left=" + contents.getLeft() + ", top=" + contents.getTop() - + ", right=" + contents.getRight() + ", bottom=" + contents.getBottom()+ "}"); + Log.d( + TAG, + prefix + + " position=" + + position++ + + " rowView={visiblility=" + + view.getVisibility() + + ", alpha=" + + view.getAlpha() + + ", translationY=" + + view.getTranslationY() + + ", left=" + + view.getLeft() + + ", top=" + + view.getTop() + + ", right=" + + view.getRight() + + ", bottom=" + + view.getBottom() + + "}, title={visiblility=" + + title.getVisibility() + + ", alpha=" + + title.getAlpha() + + ", translationY=" + + title.getTranslationY() + + ", left=" + + title.getLeft() + + ", top=" + + title.getTop() + + ", right=" + + title.getRight() + + ", bottom=" + + title.getBottom() + + "}, contents={visiblility=" + + contents.getVisibility() + + ", alpha=" + + contents.getAlpha() + + ", translationY=" + + contents.getTranslationY() + + ", left=" + + contents.getLeft() + + ", top=" + + contents.getTop() + + ", right=" + + contents.getRight() + + ", bottom=" + + contents.getBottom() + + "}"); } } @@ -204,14 +230,14 @@ public class MenuLayoutManager { * Checks if the view will take up space for the layout not. * * @param position The index of the menu row view in the list. This is not the index of the view - * in the screen. + * in the screen. * @param view The menu row view. * @param rowsToAdd The menu row views to be added in the next layout process. * @param rowsToRemove The menu row views to be removed in the next layout process. * @return {@code true} if the view will take up space for the layout, otherwise {@code false}. */ - private boolean isVisibleInLayout(int position, MenuRowView view, List<Integer> rowsToAdd, - List<Integer> rowsToRemove) { + private boolean isVisibleInLayout( + int position, MenuRowView view, List<Integer> rowsToAdd, List<Integer> rowsToRemove) { // Checks if the view will be visible or not. return (view.getVisibility() != View.GONE && !rowsToRemove.contains(position)) || rowsToAdd.contains(position); @@ -226,8 +252,8 @@ public class MenuLayoutManager { * @param bottom The bottom coordinate of the menu view. */ private List<Rect> getViewLayouts(int left, int top, int right, int bottom) { - return getViewLayouts(left, top, right, bottom, Collections.emptyList(), - Collections.emptyList()); + return getViewLayouts( + left, top, right, bottom, Collections.emptyList(), Collections.emptyList()); } /** @@ -247,8 +273,13 @@ public class MenuLayoutManager { * @param rowsToRemove The menu row views to be removed in the next layout process. * @return the layout bounds of the menu row views. */ - private List<Rect> getViewLayouts(int left, int top, int right, int bottom, - List<Integer> rowsToAdd, List<Integer> rowsToRemove) { + private List<Rect> getViewLayouts( + int left, + int top, + int right, + int bottom, + List<Integer> rowsToAdd, + List<Integer> rowsToRemove) { // The coordinates should be relative to the parent. int relativeLeft = 0; int relateiveRight = right - left; @@ -262,18 +293,29 @@ public class MenuLayoutManager { // Calculate for the selected row first. // The distance between the bottom of the screen and the vertical center of the contents // should be kept fixed. For more information, please see the redlines. - int childTop = relativeBottom - mRowAlignFromBottom - rowContentsHeight / 2 - - mRowContentsPaddingTop - rowTitleHeight; + int childTop = + relativeBottom + - mRowAlignFromBottom + - rowContentsHeight / 2 + - mRowContentsPaddingTop + - rowTitleHeight; int childBottom = relativeBottom; int position = mSelectedPosition + 1; for (; position < count; ++position) { // Find and layout the next row to calculate the bottom line of the selected row. MenuRowView nextView = mMenuRowViews.get(position); if (isVisibleInLayout(position, nextView, rowsToAdd, rowsToRemove)) { - int nextTitleTopMax = relativeBottom - mMenuMarginBottomMin - rowTitleHeight - + mRowTitleTextDescenderHeight; - int childBottomMax = relativeBottom - mRowAlignFromBottom + rowContentsHeight / 2 - + mRowContentsPaddingBottomMax - rowTitleHeight; + int nextTitleTopMax = + relativeBottom + - mMenuMarginBottomMin + - rowTitleHeight + + mRowTitleTextDescenderHeight; + int childBottomMax = + relativeBottom + - mRowAlignFromBottom + + rowContentsHeight / 2 + + mRowContentsPaddingBottomMax + - rowTitleHeight; childBottom = Math.min(nextTitleTopMax, childBottomMax); layouts.add(new Rect(relativeLeft, childBottom, relateiveRight, relativeBottom)); break; @@ -309,19 +351,22 @@ public class MenuLayoutManager { return layouts; } - /** - * Move the current selection to the given {@code position}. - */ + /** Move the current selection to the given {@code position}. */ public void setSelectedPosition(int position) { if (DEBUG) { - Log.d(TAG, "setSelectedPosition(position=" + position + ") {previousPosition=" - + mSelectedPosition + "}"); + Log.d( + TAG, + "setSelectedPosition(position=" + + position + + ") {previousPosition=" + + mSelectedPosition + + "}"); } if (mSelectedPosition == position) { return; } boolean indexValid = Utils.isIndexValid(mMenuRowViews, position); - SoftPreconditions.checkArgument(indexValid, TAG, "position " + position); + SoftPreconditions.checkArgument(indexValid, TAG, "position %s ", position); if (!indexValid) { return; } @@ -347,13 +392,18 @@ public class MenuLayoutManager { } /** - * Move the current selection to the given {@code position} with animation. - * The animation specification is included in http://b/21069476 + * Move the current selection to the given {@code position} with animation. The animation + * specification is included in http://b/21069476 */ public void setSelectedPositionSmooth(final int position) { if (DEBUG) { - Log.d(TAG, "setSelectedPositionSmooth(position=" + position + ") {previousPosition=" - + mSelectedPosition + "}"); + Log.d( + TAG, + "setSelectedPositionSmooth(position=" + + position + + ") {previousPosition=" + + mSelectedPosition + + "}"); } if (mMenuView.getVisibility() != View.VISIBLE) { setSelectedPosition(position); @@ -363,13 +413,13 @@ public class MenuLayoutManager { return; } boolean oldIndexValid = Utils.isIndexValid(mMenuRowViews, mSelectedPosition); - SoftPreconditions - .checkState(oldIndexValid, TAG, "No previous selection: " + mSelectedPosition); + SoftPreconditions.checkState( + oldIndexValid, TAG, "No previous selection: " + mSelectedPosition); if (!oldIndexValid) { return; } boolean newIndexValid = Utils.isIndexValid(mMenuRowViews, position); - SoftPreconditions.checkArgument(newIndexValid, TAG, "position " + position); + SoftPreconditions.checkArgument(newIndexValid, TAG, "position %s", position); if (!newIndexValid) { return; } @@ -415,8 +465,7 @@ public class MenuLayoutManager { mMenuView.requestFocus(); if (mTempTitleViewForOld == null) { // Initialize here because we don't know when the views are inflated. - mTempTitleViewForOld = - (TextView) mMenuView.findViewById(R.id.temp_title_for_old); + mTempTitleViewForOld = (TextView) mMenuView.findViewById(R.id.temp_title_for_old); mTempTitleViewForCurrent = (TextView) mMenuView.findViewById(R.id.temp_title_for_current); } @@ -425,16 +474,21 @@ public class MenuLayoutManager { mPropertyValuesAfterAnimation.clear(); List<Animator> animators = new ArrayList<>(); boolean scrollDown = position > oldPosition; - List<Rect> layouts = getViewLayouts(mMenuView.getLeft(), mMenuView.getTop(), - mMenuView.getRight(), mMenuView.getBottom()); + List<Rect> layouts = + getViewLayouts( + mMenuView.getLeft(), + mMenuView.getTop(), + mMenuView.getRight(), + mMenuView.getBottom()); // Old row. MenuRow oldRow = mMenuRows.get(oldPosition); final MenuRowView oldView = mMenuRowViews.get(oldPosition); View oldContentsView = oldView.getContentsView(); // Old contents view. - animators.add(createAlphaAnimator(oldContentsView, 1.0f, 0.0f, 1.0f, mLinearOutSlowIn) - .setDuration(mOldContentsFadeOutDuration)); + animators.add( + createAlphaAnimator(oldContentsView, 1.0f, 0.0f, 1.0f, mLinearOutSlowIn) + .setDuration(mOldContentsFadeOutDuration)); final TextView oldTitleView = oldView.getTitleView(); setTempTitleView(mTempTitleViewForOld, oldTitleView); Rect oldLayoutRect = layouts.get(oldPosition); @@ -444,20 +498,36 @@ public class MenuLayoutManager { // This case is not included in the animation specification. mTempTitleViewForOld.setScaleX(1.0f); mTempTitleViewForOld.setScaleY(1.0f); - animators.add(createAlphaAnimator(mTempTitleViewForOld, 0.0f, - oldView.getTitleViewAlphaDeselected(), mFastOutLinearIn)); + animators.add( + createAlphaAnimator( + mTempTitleViewForOld, + 0.0f, + oldView.getTitleViewAlphaDeselected(), + mFastOutLinearIn)); int offset = oldLayoutRect.top - mTempTitleViewForOld.getTop(); - animators.add(createTranslationYAnimator(mTempTitleViewForOld, - offset + mRowScrollUpAnimationOffset, offset)); + animators.add( + createTranslationYAnimator( + mTempTitleViewForOld, + offset + mRowScrollUpAnimationOffset, + offset)); } else { - animators.add(createScaleXAnimator(mTempTitleViewForOld, - oldView.getTitleViewScaleSelected(), 1.0f)); - animators.add(createScaleYAnimator(mTempTitleViewForOld, - oldView.getTitleViewScaleSelected(), 1.0f)); - animators.add(createAlphaAnimator(mTempTitleViewForOld, oldTitleView.getAlpha(), - oldView.getTitleViewAlphaDeselected(), mLinearOutSlowIn)); - animators.add(createTranslationYAnimator(mTempTitleViewForOld, 0, - oldLayoutRect.top - mTempTitleViewForOld.getTop())); + animators.add( + createScaleXAnimator( + mTempTitleViewForOld, oldView.getTitleViewScaleSelected(), 1.0f)); + animators.add( + createScaleYAnimator( + mTempTitleViewForOld, oldView.getTitleViewScaleSelected(), 1.0f)); + animators.add( + createAlphaAnimator( + mTempTitleViewForOld, + oldTitleView.getAlpha(), + oldView.getTitleViewAlphaDeselected(), + mLinearOutSlowIn)); + animators.add( + createTranslationYAnimator( + mTempTitleViewForOld, + 0, + oldLayoutRect.top - mTempTitleViewForOld.getTop())); } oldTitleView.setAlpha(oldView.getTitleViewAlphaDeselected()); oldTitleView.setVisibility(View.INVISIBLE); @@ -471,23 +541,30 @@ public class MenuLayoutManager { // The maximum is to the top of the start position of mTempTitleViewForOld. int distanceCurrentTitle = currentLayoutRect.top - currentView.getTop(); int distance = Math.max(mRowScrollUpAnimationOffset, distanceCurrentTitle); - int distanceToTopOfSecondTitle = oldLayoutRect.top - mRowScrollUpAnimationOffset - - oldView.getTop(); - animators.add(createTranslationYAnimator(oldTitleView, 0.0f, - Math.min(distance, distanceToTopOfSecondTitle))); - animators.add(createAlphaAnimator(oldTitleView, 1.0f, 0.0f, 1.0f, mLinearOutSlowIn) - .setDuration(mOldContentsFadeOutDuration)); - animators.add(createScaleXAnimator(oldTitleView, - oldView.getTitleViewScaleSelected(), 1.0f)); - animators.add(createScaleYAnimator(oldTitleView, - oldView.getTitleViewScaleSelected(), 1.0f)); + int distanceToTopOfSecondTitle = + oldLayoutRect.top - mRowScrollUpAnimationOffset - oldView.getTop(); + animators.add( + createTranslationYAnimator( + oldTitleView, 0.0f, Math.min(distance, distanceToTopOfSecondTitle))); + animators.add( + createAlphaAnimator(oldTitleView, 1.0f, 0.0f, 1.0f, mLinearOutSlowIn) + .setDuration(mOldContentsFadeOutDuration)); + animators.add( + createScaleXAnimator(oldTitleView, oldView.getTitleViewScaleSelected(), 1.0f)); + animators.add( + createScaleYAnimator(oldTitleView, oldView.getTitleViewScaleSelected(), 1.0f)); mTempTitleViewForOld.setScaleX(1.0f); mTempTitleViewForOld.setScaleY(1.0f); - animators.add(createAlphaAnimator(mTempTitleViewForOld, 0.0f, - oldView.getTitleViewAlphaDeselected(), mFastOutLinearIn)); + animators.add( + createAlphaAnimator( + mTempTitleViewForOld, + 0.0f, + oldView.getTitleViewAlphaDeselected(), + mFastOutLinearIn)); int offset = oldLayoutRect.top - mTempTitleViewForOld.getTop(); - animators.add(createTranslationYAnimator(mTempTitleViewForOld, - offset - mRowScrollUpAnimationOffset, offset)); + animators.add( + createTranslationYAnimator( + mTempTitleViewForOld, offset - mRowScrollUpAnimationOffset, offset)); } // Current row. Rect currentLayoutRect = new Rect(layouts.get(position)); @@ -502,29 +579,40 @@ public class MenuLayoutManager { // The maximum is to the top of the end position of mTempTitleViewForCurrent. int distanceOldTitle = oldView.getTop() - oldLayoutRect.top; int distance = Math.max(mRowScrollUpAnimationOffset, distanceOldTitle); - int distanceTopOfSecondTitle = currentView.getTop() - mRowScrollUpAnimationOffset - - currentLayoutRect.top; - animators.add(createTranslationYAnimator(currentTitleView, - Math.min(distance, distanceTopOfSecondTitle), 0.0f)); + int distanceTopOfSecondTitle = + currentView.getTop() - mRowScrollUpAnimationOffset - currentLayoutRect.top; + animators.add( + createTranslationYAnimator( + currentTitleView, Math.min(distance, distanceTopOfSecondTitle), 0.0f)); currentView.setTop(currentLayoutRect.top); - ObjectAnimator animator = createAlphaAnimator(currentTitleView, 0.0f, 1.0f, - mFastOutLinearIn).setDuration(mCurrentContentsFadeInDuration); + ObjectAnimator animator = + createAlphaAnimator(currentTitleView, 0.0f, 1.0f, mFastOutLinearIn) + .setDuration(mCurrentContentsFadeInDuration); animator.setStartDelay(mOldContentsFadeOutDuration); currentTitleView.setAlpha(0.0f); animators.add(animator); - animators.add(createScaleXAnimator(currentTitleView, 1.0f, - currentView.getTitleViewScaleSelected())); - animators.add(createScaleYAnimator(currentTitleView, 1.0f, - currentView.getTitleViewScaleSelected())); - animators.add(createTranslationYAnimator(mTempTitleViewForCurrent, 0.0f, - -mRowScrollUpAnimationOffset)); - animators.add(createAlphaAnimator(mTempTitleViewForCurrent, - currentView.getTitleViewAlphaDeselected(), 0, mLinearOutSlowIn)); + animators.add( + createScaleXAnimator( + currentTitleView, 1.0f, currentView.getTitleViewScaleSelected())); + animators.add( + createScaleYAnimator( + currentTitleView, 1.0f, currentView.getTitleViewScaleSelected())); + animators.add( + createTranslationYAnimator( + mTempTitleViewForCurrent, 0.0f, -mRowScrollUpAnimationOffset)); + animators.add( + createAlphaAnimator( + mTempTitleViewForCurrent, + currentView.getTitleViewAlphaDeselected(), + 0, + mLinearOutSlowIn)); // Current contents view. - animators.add(createTranslationYAnimator(currentContentsView, - mRowScrollUpAnimationOffset, 0.0f)); - animator = createAlphaAnimator(currentContentsView, 0.0f, 1.0f, mFastOutLinearIn) - .setDuration(mCurrentContentsFadeInDuration); + animators.add( + createTranslationYAnimator( + currentContentsView, mRowScrollUpAnimationOffset, 0.0f)); + animator = + createAlphaAnimator(currentContentsView, 0.0f, 1.0f, mFastOutLinearIn) + .setDuration(mCurrentContentsFadeInDuration); animator.setStartDelay(mOldContentsFadeOutDuration); animators.add(animator); } else { @@ -532,17 +620,27 @@ public class MenuLayoutManager { // Current title view. int currentViewOffset = currentLayoutRect.top - currentView.getTop(); animators.add(createTranslationYAnimator(currentTitleView, 0, currentViewOffset)); - animators.add(createAlphaAnimator(currentTitleView, - currentView.getTitleViewAlphaDeselected(), 1.0f, mFastOutSlowIn)); - animators.add(createScaleXAnimator(currentTitleView, 1.0f, - currentView.getTitleViewScaleSelected())); - animators.add(createScaleYAnimator(currentTitleView, 1.0f, - currentView.getTitleViewScaleSelected())); + animators.add( + createAlphaAnimator( + currentTitleView, + currentView.getTitleViewAlphaDeselected(), + 1.0f, + mFastOutSlowIn)); + animators.add( + createScaleXAnimator( + currentTitleView, 1.0f, currentView.getTitleViewScaleSelected())); + animators.add( + createScaleYAnimator( + currentTitleView, 1.0f, currentView.getTitleViewScaleSelected())); // Current contents view. - animators.add(createTranslationYAnimator(currentContentsView, - currentViewOffset - mRowScrollUpAnimationOffset, currentViewOffset)); - ObjectAnimator animator = createAlphaAnimator(currentContentsView, 0.0f, 1.0f, - mFastOutLinearIn).setDuration(mCurrentContentsFadeInDuration); + animators.add( + createTranslationYAnimator( + currentContentsView, + currentViewOffset - mRowScrollUpAnimationOffset, + currentViewOffset)); + ObjectAnimator animator = + createAlphaAnimator(currentContentsView, 0.0f, 1.0f, mFastOutLinearIn) + .setDuration(mCurrentContentsFadeInDuration); animator.setStartDelay(mOldContentsFadeOutDuration); animators.add(animator); } @@ -553,9 +651,13 @@ public class MenuLayoutManager { if (nextPosition != INVALID_POSITION) { MenuRowView nextView = mMenuRowViews.get(nextPosition); Rect nextLayoutRect = layouts.get(nextPosition); - animators.add(createTranslationYAnimator(nextView, - nextLayoutRect.top + mRowScrollUpAnimationOffset - nextView.getTop(), - nextLayoutRect.top - nextView.getTop())); + animators.add( + createTranslationYAnimator( + nextView, + nextLayoutRect.top + + mRowScrollUpAnimationOffset + - nextView.getTop(), + nextLayoutRect.top - nextView.getTop())); animators.add(createAlphaAnimator(nextView, 0.0f, 1.0f, mFastOutLinearIn)); } } else { @@ -563,15 +665,22 @@ public class MenuLayoutManager { if (nextPosition != INVALID_POSITION) { MenuRowView nextView = mMenuRowViews.get(nextPosition); animators.add(createTranslationYAnimator(nextView, 0, mRowScrollUpAnimationOffset)); - animators.add(createAlphaAnimator(nextView, - nextView.getTitleViewAlphaDeselected(), 0.0f, 1.0f, mLinearOutSlowIn)); + animators.add( + createAlphaAnimator( + nextView, + nextView.getTitleViewAlphaDeselected(), + 0.0f, + 1.0f, + mLinearOutSlowIn)); } } // Other rows. int count = mMenuRowViews.size(); for (int i = 0; i < count; ++i) { MenuRowView view = mMenuRowViews.get(i); - if (view.getVisibility() == View.VISIBLE && i != oldPosition && i != position + if (view.getVisibility() == View.VISIBLE + && i != oldPosition + && i != position && i != nextPosition) { Rect rect = layouts.get(i); animators.add(createTranslationYAnimator(view, 0, rect.top - view.getTop())); @@ -582,51 +691,62 @@ public class MenuLayoutManager { propertyValuesAfterAnimation.addAll(mPropertyValuesAfterAnimation); mAnimatorSet = new AnimatorSet(); mAnimatorSet.playTogether(animators); - mAnimatorSet.addListener(new AnimatorListenerAdapter() { - @Override - public void onAnimationEnd(Animator animator) { - if (DEBUG) dumpChildren("onRowAnimationEndBefore"); - mAnimatorSet = null; - // The property values which are different from the end values and need to be - // changed after the animation are set here. - // e.g. setting translationY to 0, alpha of the contents view to 1. - for (ViewPropertyValueHolder holder : propertyValuesAfterAnimation) { - holder.property.set(holder.view, holder.value); - } - oldView.onDeselected(); - currentView.onSelected(true); - mTempTitleViewForOld.setVisibility(View.GONE); - mTempTitleViewForCurrent.setVisibility(View.GONE); - layout(mMenuView.getLeft(), mMenuView.getTop(), mMenuView.getRight(), - mMenuView.getBottom()); - if (DEBUG) dumpChildren("onRowAnimationEndAfter"); - - MenuRow currentRow = mMenuRows.get(position); - if (currentRow.hideTitleWhenSelected()) { - View titleView = mMenuRowViews.get(position).getTitleView(); - mTitleFadeOutAnimator = createAlphaAnimator(titleView, titleView.getAlpha(), - 0.0f, mLinearOutSlowIn); - mTitleFadeOutAnimator.setStartDelay(TITLE_SHOW_DURATION_BEFORE_HIDDEN_MS); - mTitleFadeOutAnimator.addListener(new AnimatorListenerAdapter() { - private boolean mCanceled; - - @Override - public void onAnimationCancel(Animator animator) { - mCanceled = true; + mAnimatorSet.addListener( + new AnimatorListenerAdapter() { + @Override + public void onAnimationEnd(Animator animator) { + if (DEBUG) dumpChildren("onRowAnimationEndBefore"); + mAnimatorSet = null; + // The property values which are different from the end values and need to + // be + // changed after the animation are set here. + // e.g. setting translationY to 0, alpha of the contents view to 1. + for (ViewPropertyValueHolder holder : propertyValuesAfterAnimation) { + holder.property.set(holder.view, holder.value); } - - @Override - public void onAnimationEnd(Animator animator) { - mTitleFadeOutAnimator = null; - if (!mCanceled) { - mMenuRowViews.get(position).onSelected(false); - } + oldView.onDeselected(); + currentView.onSelected(true); + mTempTitleViewForOld.setVisibility(View.GONE); + mTempTitleViewForCurrent.setVisibility(View.GONE); + layout( + mMenuView.getLeft(), + mMenuView.getTop(), + mMenuView.getRight(), + mMenuView.getBottom()); + if (DEBUG) dumpChildren("onRowAnimationEndAfter"); + + MenuRow currentRow = mMenuRows.get(position); + if (currentRow.hideTitleWhenSelected()) { + View titleView = mMenuRowViews.get(position).getTitleView(); + mTitleFadeOutAnimator = + createAlphaAnimator( + titleView, + titleView.getAlpha(), + 0.0f, + mLinearOutSlowIn); + mTitleFadeOutAnimator.setStartDelay( + TITLE_SHOW_DURATION_BEFORE_HIDDEN_MS); + mTitleFadeOutAnimator.addListener( + new AnimatorListenerAdapter() { + private boolean mCanceled; + + @Override + public void onAnimationCancel(Animator animator) { + mCanceled = true; + } + + @Override + public void onAnimationEnd(Animator animator) { + mTitleFadeOutAnimator = null; + if (!mCanceled) { + mMenuRowViews.get(position).onSelected(false); + } + } + }); + mTitleFadeOutAnimator.start(); } - }); - mTitleFadeOutAnimator.start(); - } - } - }); + } + }); mAnimatorSet.start(); if (DEBUG) dumpChildren("startedRowAnimation()"); } @@ -661,7 +781,8 @@ public class MenuLayoutManager { if (mMenuView.getVisibility() != View.VISIBLE) { int count = mMenuRowViews.size(); for (int i = 0; i < count; ++i) { - mMenuRowViews.get(i) + mMenuRowViews + .get(i) .setVisibility(mMenuRows.get(i).isVisible() ? View.VISIBLE : View.GONE); } return; @@ -674,8 +795,8 @@ public class MenuLayoutManager { for (int i = mSelectedPosition - 1; i >= 0; --i) { MenuRow row = mMenuRows.get(i); MenuRowView view = mMenuRowViews.get(i); - if (row.isVisible() && (view.getVisibility() == View.GONE - || mRemovingRowViews.contains(i))) { + if (row.isVisible() + && (view.getVisibility() == View.GONE || mRemovingRowViews.contains(i))) { // Removing rows are still VISIBLE. addedRowViews.add(i); ++added; @@ -691,8 +812,8 @@ public class MenuLayoutManager { for (int i = mSelectedPosition + 1; i < count; ++i) { MenuRow row = mMenuRows.get(i); MenuRowView view = mMenuRowViews.get(i); - if (row.isVisible() && (view.getVisibility() == View.GONE - || mRemovingRowViews.contains(i))) { + if (row.isVisible() + && (view.getVisibility() == View.GONE || mRemovingRowViews.contains(i))) { // Removing rows are still VISIBLE. addedRowViews.add(i); ++added; @@ -717,8 +838,14 @@ public class MenuLayoutManager { } mPropertyValuesAfterAnimation.clear(); List<Animator> animators = new ArrayList<>(); - List<Rect> layouts = getViewLayouts(mMenuView.getLeft(), mMenuView.getTop(), - mMenuView.getRight(), mMenuView.getBottom(), addedRowViews, removedRowViews); + List<Rect> layouts = + getViewLayouts( + mMenuView.getLeft(), + mMenuView.getTop(), + mMenuView.getRight(), + mMenuView.getBottom(), + addedRowViews, + removedRowViews); for (int position : addedRowViews) { MenuRowView view = mMenuRowViews.get(position); view.setVisibility(View.VISIBLE); @@ -728,7 +855,8 @@ public class MenuLayoutManager { view.layout(rect.left, rect.top, rect.right, rect.bottom); View titleView = view.getTitleView(); MarginLayoutParams params = (MarginLayoutParams) titleView.getLayoutParams(); - titleView.layout(view.getPaddingLeft() + params.leftMargin, + titleView.layout( + view.getPaddingLeft() + params.leftMargin, view.getPaddingTop() + params.topMargin, rect.right - rect.left - view.getPaddingRight() - params.rightMargin, rect.bottom - rect.top - view.getPaddingBottom() - params.bottomMargin); @@ -749,23 +877,28 @@ public class MenuLayoutManager { mRemovingRowViews.addAll(removedRowViews); mAnimatorSet = new AnimatorSet(); mAnimatorSet.playTogether(animators); - mAnimatorSet.addListener(new AnimatorListenerAdapter() { - @Override - public void onAnimationEnd(Animator animation) { - mAnimatorSet = null; - // The property values which are different from the end values and need to be - // changed after the animation are set here. - // e.g. setting translationY to 0, alpha of the contents view to 1. - for (ViewPropertyValueHolder holder : propertyValuesAfterAnimation) { - holder.property.set(holder.view, holder.value); - } - for (int position : mRemovingRowViews) { - mMenuRowViews.get(position).setVisibility(View.GONE); - } - layout(mMenuView.getLeft(), mMenuView.getTop(), mMenuView.getRight(), - mMenuView.getBottom()); - } - }); + mAnimatorSet.addListener( + new AnimatorListenerAdapter() { + @Override + public void onAnimationEnd(Animator animation) { + mAnimatorSet = null; + // The property values which are different from the end values and need to + // be + // changed after the animation are set here. + // e.g. setting translationY to 0, alpha of the contents view to 1. + for (ViewPropertyValueHolder holder : propertyValuesAfterAnimation) { + holder.property.set(holder.view, holder.value); + } + for (int position : mRemovingRowViews) { + mMenuRowViews.get(position).setVisibility(View.GONE); + } + layout( + mMenuView.getLeft(), + mMenuView.getTop(), + mMenuView.getRight(), + mMenuView.getBottom()); + } + }); mAnimatorSet.start(); if (DEBUG) dumpChildren("onMenuRowUpdated()"); } @@ -778,16 +911,16 @@ public class MenuLayoutManager { return animator; } - private ObjectAnimator createAlphaAnimator(View view, float from, float to, - TimeInterpolator interpolator) { + private ObjectAnimator createAlphaAnimator( + View view, float from, float to, TimeInterpolator interpolator) { ObjectAnimator animator = ObjectAnimator.ofFloat(view, View.ALPHA, from, to); animator.setDuration(mRowAnimationDuration); animator.setInterpolator(interpolator); return animator; } - private ObjectAnimator createAlphaAnimator(View view, float from, float to, float end, - TimeInterpolator interpolator) { + private ObjectAnimator createAlphaAnimator( + View view, float from, float to, float end, TimeInterpolator interpolator) { ObjectAnimator animator = ObjectAnimator.ofFloat(view, View.ALPHA, from, to); animator.setDuration(mRowAnimationDuration); animator.setInterpolator(interpolator); @@ -809,9 +942,7 @@ public class MenuLayoutManager { return animator; } - /** - * Returns the current position. - */ + /** Returns the current position. */ public int getSelectedPosition() { return mSelectedPosition; } @@ -828,15 +959,10 @@ public class MenuLayoutManager { } } - /** - * Called when the menu becomes visible. - */ - public void onMenuShow() { - } + /** Called when the menu becomes visible. */ + public void onMenuShow() {} - /** - * Called when the menu becomes hidden. - */ + /** Called when the menu becomes hidden. */ public void onMenuHide() { if (mAnimatorSet != null) { mAnimatorSet.end(); |