From 061f81e7b03a7cc82157416ef53c88b70ebb5876 Mon Sep 17 00:00:00 2001 From: Sid Soundararajan Date: Wed, 4 May 2016 15:16:20 -0700 Subject: [PATCH] Reset Cards as they come into view This will ensure that they are in the correct configuration. Needed since recycler view will be re-using views. BUG:28632740 Change-Id: Icdaa48696e198cfeb8c37718fec05f7f9b195842 --- .../systemui/recents/tv/RecentsTvActivity.java | 16 +++++++++------- .../tv/animations/DismissAnimationsHolder.java | 9 ++++----- .../tv/views/TaskStackHorizontalViewAdapter.java | 12 ++++++++++++ 3 files changed, 25 insertions(+), 12 deletions(-) diff --git a/packages/SystemUI/src/com/android/systemui/recents/tv/RecentsTvActivity.java b/packages/SystemUI/src/com/android/systemui/recents/tv/RecentsTvActivity.java index 9dc9c4c19e5d3..acebf427feabc 100644 --- a/packages/SystemUI/src/com/android/systemui/recents/tv/RecentsTvActivity.java +++ b/packages/SystemUI/src/com/android/systemui/recents/tv/RecentsTvActivity.java @@ -350,13 +350,6 @@ public class RecentsTvActivity extends Activity implements OnPreDrawListener { } else { mRecentsView.getViewTreeObserver().addOnPreDrawListener(this); } - if(mTaskStackHorizontalGridView.getStack().getTaskCount() > 1 && !mLaunchedFromHome) { - // If there are 2 or more tasks, and we are not launching from home - // set the selected position to the 2nd task to allow for faster app switching - mTaskStackHorizontalGridView.setSelectedPosition(1); - } else { - mTaskStackHorizontalGridView.setSelectedPosition(0); - } // If this is a new instance from a configuration change, then we have to manually trigger // the enter animation state, or if recents was relaunched by AM, without going through @@ -382,6 +375,7 @@ public class RecentsTvActivity extends Activity implements OnPreDrawListener { if(mLaunchedFromHome) { mHomeRecentsEnterExitAnimationHolder.startEnterAnimation(mPipManager.isPipShown()); } + mTaskStackViewAdapter.setResetAddedCards(true); EventBus.getDefault().send(new EnterRecentsWindowAnimationCompletedEvent()); } @@ -389,12 +383,20 @@ public class RecentsTvActivity extends Activity implements OnPreDrawListener { public void onResume() { super.onResume(); mPipRecentsOverlayManager.onRecentsResumed(); + if(mTaskStackHorizontalGridView.getStack().getTaskCount() > 1 && !mLaunchedFromHome) { + // If there are 2 or more tasks, and we are not launching from home + // set the selected position to the 2nd task to allow for faster app switching + mTaskStackHorizontalGridView.setSelectedPosition(1); + } else { + mTaskStackHorizontalGridView.setSelectedPosition(0); + } } @Override public void onPause() { super.onPause(); mPipRecentsOverlayManager.onRecentsPaused(); + mTaskStackViewAdapter.setResetAddedCards(false); } @Override diff --git a/packages/SystemUI/src/com/android/systemui/recents/tv/animations/DismissAnimationsHolder.java b/packages/SystemUI/src/com/android/systemui/recents/tv/animations/DismissAnimationsHolder.java index 084fc874b7b96..65f5fffc5accd 100644 --- a/packages/SystemUI/src/com/android/systemui/recents/tv/animations/DismissAnimationsHolder.java +++ b/packages/SystemUI/src/com/android/systemui/recents/tv/animations/DismissAnimationsHolder.java @@ -18,7 +18,6 @@ package com.android.systemui.recents.tv.animations; import android.animation.Animator.AnimatorListener; import android.content.res.Resources; import android.graphics.drawable.TransitionDrawable; -import android.util.TypedValue; import android.view.View; import android.widget.ImageView; import android.widget.LinearLayout; @@ -39,7 +38,7 @@ public class DismissAnimationsHolder { private TransitionDrawable mDismissDrawable; private TextView mDismissText; - private float mDismissUnselectedAlpha; + private float mDismissIconNotInDismissStateAlpha; private long mShortDuration; private long mLongDuration; @@ -57,7 +56,7 @@ public class DismissAnimationsHolder { mDismissStartYDelta = mDismissEnterYDelta * 2; mShortDuration = res.getInteger(R.integer.dismiss_short_duration); mLongDuration = res.getInteger(R.integer.dismiss_long_duration); - mDismissUnselectedAlpha = res.getFloat(R.integer.dismiss_unselected_alpha); + mDismissIconNotInDismissStateAlpha = res.getFloat(R.integer.dismiss_unselected_alpha); } public void startEnterAnimation() { @@ -94,7 +93,7 @@ public class DismissAnimationsHolder { mCardDismissIcon.animate() .setDuration(mShortDuration) .setInterpolator(Interpolators.FAST_OUT_SLOW_IN) - .alpha(mDismissUnselectedAlpha) + .alpha(mDismissIconNotInDismissStateAlpha) .withEndAction(new Runnable() { @Override public void run() { @@ -157,7 +156,7 @@ public class DismissAnimationsHolder { mInfoField.animate().setListener(null); mThumbnailView.setAlpha(1.0f); mThumbnailView.setTranslationY(0); - mCardDismissIcon.setAlpha(mDismissUnselectedAlpha); + mCardDismissIcon.setAlpha(0.0f); mDismissText.setAlpha(0.0f); } } diff --git a/packages/SystemUI/src/com/android/systemui/recents/tv/views/TaskStackHorizontalViewAdapter.java b/packages/SystemUI/src/com/android/systemui/recents/tv/views/TaskStackHorizontalViewAdapter.java index eb3b02d155ebc..ed28ef173f0f6 100644 --- a/packages/SystemUI/src/com/android/systemui/recents/tv/views/TaskStackHorizontalViewAdapter.java +++ b/packages/SystemUI/src/com/android/systemui/recents/tv/views/TaskStackHorizontalViewAdapter.java @@ -42,6 +42,7 @@ public class TaskStackHorizontalViewAdapter extends private static final String TAG = "TaskStackViewAdapter"; private List mTaskList; private TaskStackHorizontalGridView mGridView; + private boolean mResetAddedCards; public class ViewHolder extends RecyclerView.ViewHolder implements View.OnClickListener{ private TaskCardView mTaskCardView; @@ -125,6 +126,13 @@ public class TaskStackHorizontalViewAdapter extends holder.init(mTaskList.get(position)); } + @Override + public void onViewAttachedToWindow(ViewHolder holder) { + if (mResetAddedCards) { + holder.mTaskCardView.reset(); + } + } + @Override public void onViewDetachedFromWindow(ViewHolder holder) { // We only want to reset on view detach if this is the last task being dismissed. @@ -171,4 +179,8 @@ public class TaskStackHorizontalViewAdapter extends mTaskList.add(position, task); notifyItemInserted(position); } + + public void setResetAddedCards(boolean reset) { + mResetAddedCards = reset; + } }