PIP: Fix regressions

This includes following fixes
- Press back key to go to Home from Recents
- Do not show Recents when an activity is PIPed immediately after moved
  to fullscreen.

These regressions are caused by
c81082b Improve Animation Calculations to remove Jank

Bug: 28107787
Change-Id: I3078a5d8a9505c8d03cceee329e5d740efae7feb
This commit is contained in:
Jaewan Kim
2016-04-11 15:43:36 +09:00
parent b33daec8c2
commit 419c89533a
8 changed files with 58 additions and 35 deletions

View File

@@ -35,9 +35,9 @@
<!-- Placeholder view to give focus to the PIP menus. -->
<View
android:id="@+id/pip"
android:layout_width="0dp"
android:layout_height="0dp"
android:layout_width="1dp"
android:layout_height="1dp"
android:focusable="true"
android:visibility="gone" />
android:visibility="visible" />
</com.android.systemui.recents.tv.views.RecentsTvView>

View File

@@ -606,8 +606,8 @@
<dimen name="recents_layout_z_min">3dp</dimen>
<dimen name="recents_layout_z_max">24dp</dimen>
<!-- The margin between the freeform and stack. We also don't want this to change across
configurations that Recents can be opened in, so we define them statically for all
<!-- The margin between the freeform and stack. We also don't want this to change across
configurations that Recents can be opened in, so we define them statically for all
display sizes. -->
<dimen name="recents_freeform_layout_bottom_margin">16dp</dimen>
@@ -651,4 +651,7 @@
<!-- The amount to translate when animating the removal of a task. -->
<dimen name="recents_task_view_remove_anim_translation_x">100dp</dimen>
<!-- The alpha to apply to the recents row when it doesn't have focus -->
<item name="recents_recents_row_dim_alpha" format="float" type="dimen">0.5</item>
</resources>

View File

@@ -107,7 +107,9 @@ public class RecentsTvActivity extends Activity implements OnPreDrawListener {
public void onMoveToFullscreen() {
// Recents should be dismissed when PIP moves to fullscreen. If not, Recents will
// be unnecessarily shown in the scenario: PIP->Fullscreen->PIP.
dismissRecentsToLaunchTargetTaskOrHome();
// Do not show Recents close animation because PIP->Fullscreen animation will be shown
// instead.
dismissRecentsToLaunchTargetTaskOrHome(false);
}
@Override
@@ -118,7 +120,7 @@ public class RecentsTvActivity extends Activity implements OnPreDrawListener {
new PipRecentsOverlayManager.Callback() {
@Override
public void onClosed() {
dismissRecentsToLaunchTargetTaskOrHome();
dismissRecentsToLaunchTargetTaskOrHome(true);
}
@Override
@@ -211,13 +213,15 @@ public class RecentsTvActivity extends Activity implements OnPreDrawListener {
}
}
boolean dismissRecentsToLaunchTargetTaskOrHome() {
boolean dismissRecentsToLaunchTargetTaskOrHome(boolean animate) {
SystemServicesProxy ssp = Recents.getSystemServices();
if (ssp.isRecentsTopMost(ssp.getTopMostTask(), null)) {
// If we have a focused Task, launch that Task now
if (mRecentsView.launchPreviousTask()) return true;
if (mRecentsView.launchPreviousTask(animate)) {
return true;
}
// If none of the other cases apply, then just go Home
dismissRecentsToHome(true /* animateTaskViews */);
dismissRecentsToHome(animate /* animateTaskViews */);
}
return false;
}
@@ -247,7 +251,7 @@ public class RecentsTvActivity extends Activity implements OnPreDrawListener {
dismissEvent.addPostAnimationCallback(mFinishLaunchHomeRunnable);
dismissEvent.addPostAnimationCallback(closeSystemWindows);
if(mTaskStackHorizontalGridView.getChildCount() > 0 && animateTaskViews) {
if (mTaskStackHorizontalGridView.getChildCount() > 0 && animateTaskViews) {
mHomeRecentsEnterExitAnimationHolder.startExitAnimation(dismissEvent);
} else {
closeSystemWindows.run();
@@ -374,7 +378,7 @@ public class RecentsTvActivity extends Activity implements OnPreDrawListener {
public void onEnterAnimationComplete() {
super.onEnterAnimationComplete();
if(mLaunchedFromHome) {
mHomeRecentsEnterExitAnimationHolder.startEnterAnimation();
mHomeRecentsEnterExitAnimationHolder.startEnterAnimation(mPipManager.isPipShown());
}
EventBus.getDefault().send(new EnterRecentsWindowAnimationCompletedEvent());
}
@@ -463,7 +467,7 @@ public class RecentsTvActivity extends Activity implements OnPreDrawListener {
if (launchState.launchedFromHome) {
dismissRecentsToHome(true /* animateTaskViews */);
} else {
dismissRecentsToLaunchTargetTaskOrHome();
dismissRecentsToLaunchTargetTaskOrHome(true);
}
}
@@ -561,6 +565,8 @@ public class RecentsTvActivity extends Activity implements OnPreDrawListener {
// as if it's the part of the Recents UI.
mPipRecentsOverlayManager.requestFocus(
mTaskStackViewAdapter.getItemCount() > 0);
} else {
mPipRecentsOverlayManager.clearFocus();
}
}
}

View File

@@ -29,7 +29,8 @@ public class DismissAnimationsHolder {
private LinearLayout mDismissArea;
private LinearLayout mInfoField;
private View mThumbnailView;
private int mCardYDelta;
private int mDismissEnterYDelta;
private int mDismissStartYDelta;
private long mShortDuration;
private long mLongDuration;
@@ -38,7 +39,8 @@ public class DismissAnimationsHolder {
mDismissArea = (LinearLayout) taskCardView.findViewById(R.id.card_dismiss);
mThumbnailView = taskCardView.findViewById(R.id.card_view_thumbnail);
Resources res = taskCardView.getResources();
mCardYDelta = res.getDimensionPixelOffset(R.dimen.recents_tv_dismiss_shift_down);
mDismissEnterYDelta = res.getDimensionPixelOffset(R.dimen.recents_tv_dismiss_shift_down);
mDismissStartYDelta = mDismissEnterYDelta * 2;
mShortDuration = res.getInteger(R.integer.dismiss_short_duration);
mLongDuration = res.getInteger(R.integer.dismiss_long_duration);
}
@@ -52,13 +54,13 @@ public class DismissAnimationsHolder {
mInfoField.animate()
.setDuration(mShortDuration)
.setInterpolator(Interpolators.FAST_OUT_SLOW_IN)
.translationYBy(mCardYDelta)
.translationY(mDismissEnterYDelta)
.alpha(0.5f);
mThumbnailView.animate()
.setDuration(mShortDuration)
.setInterpolator(Interpolators.FAST_OUT_SLOW_IN)
.translationYBy(mCardYDelta)
.translationY(mDismissEnterYDelta)
.alpha(0.5f);
}
@@ -71,13 +73,13 @@ public class DismissAnimationsHolder {
mInfoField.animate()
.setDuration(mShortDuration)
.setInterpolator(Interpolators.FAST_OUT_SLOW_IN)
.translationYBy(-mCardYDelta)
.translationY(0)
.alpha(1.0f);
mThumbnailView.animate()
.setDuration(mShortDuration)
.setInterpolator(Interpolators.FAST_OUT_SLOW_IN)
.translationYBy(-mCardYDelta)
.translationY(0)
.alpha(1.0f);
}
@@ -90,14 +92,14 @@ public class DismissAnimationsHolder {
mInfoField.animate()
.setDuration(mLongDuration)
.setInterpolator(Interpolators.FAST_OUT_SLOW_IN)
.translationYBy(mCardYDelta)
.translationY(mDismissStartYDelta)
.alpha(0.0f)
.setListener(listener);
mThumbnailView.animate()
.setDuration(mLongDuration)
.setInterpolator(Interpolators.FAST_OUT_SLOW_IN)
.translationYBy(mCardYDelta)
.translationY(mDismissStartYDelta)
.alpha(0.0f);
}

View File

@@ -28,6 +28,7 @@ public class HomeRecentsEnterExitAnimationHolder {
private Context mContext;
private TaskStackHorizontalGridView mGridView;
private float mDimAlpha;
private long mDelay;
private int mDuration;
private int mTranslationX;
@@ -36,18 +37,19 @@ public class HomeRecentsEnterExitAnimationHolder {
TaskStackHorizontalGridView gridView) {
mContext = context;
mGridView = gridView;
mDimAlpha = mContext.getResources().getFloat(R.dimen.recents_recents_row_dim_alpha);
mTranslationX = mContext.getResources()
.getDimensionPixelSize(R.dimen.recents_tv_home_recents_shift);
mDelay = mContext.getResources().getInteger(R.integer.recents_home_delay);
mDuration = mContext.getResources().getInteger(R.integer.recents_home_duration);
}
public void startEnterAnimation() {
public void startEnterAnimation(boolean isPipShown) {
for(int i = 0; i < mGridView.getChildCount(); i++) {
TaskCardView view = (TaskCardView) mGridView.getChildAt(i);
view.setTranslationX(-mTranslationX);
view.animate()
.alpha(1.0f)
.alpha(isPipShown ? mDimAlpha : 1.0f)
.translationX(0)
.setDuration(mDuration)
.setStartDelay(mDelay * i)

View File

@@ -29,8 +29,6 @@ import com.android.systemui.recents.tv.views.TaskCardView;
* Recents row's focus animation with PIP controls.
*/
public class RecentsRowFocusAnimationHolder {
private static final float DIM_ALPHA = 0.5f;
private View mView;
private View mTitleView;
@@ -43,6 +41,7 @@ public class RecentsRowFocusAnimationHolder {
Resources res = view.getResources();
int duration = res.getInteger(R.integer.recents_tv_pip_focus_anim_duration);
float dimAlpha = res.getFloat(R.dimen.recents_recents_row_dim_alpha);
mFocusGainAnimatorSet = new AnimatorSet();
mFocusGainAnimatorSet.playTogether(
@@ -53,7 +52,7 @@ public class RecentsRowFocusAnimationHolder {
mFocusLoseAnimatorSet = new AnimatorSet();
mFocusLoseAnimatorSet.playTogether(
ObjectAnimator.ofFloat(mView, "alpha", DIM_ALPHA),
ObjectAnimator.ofFloat(mView, "alpha", dimAlpha),
ObjectAnimator.ofFloat(mTitleView, "alpha", 0f));
mFocusLoseAnimatorSet.setDuration(duration);
mFocusLoseAnimatorSet.setInterpolator(Interpolators.FAST_OUT_SLOW_IN);

View File

@@ -112,7 +112,7 @@ public class RecentsTvView extends FrameLayout {
if (mTaskStackHorizontalView != null) {
Task task = mTaskStackHorizontalView.getFocusedTask();
if (task != null) {
launchTaskFomRecents(task);
launchTaskFomRecents(task, true);
return true;
}
}
@@ -120,12 +120,12 @@ public class RecentsTvView extends FrameLayout {
}
/** Launches the task that recents was launched from if possible */
public boolean launchPreviousTask() {
public boolean launchPreviousTask(boolean animate) {
if (mTaskStackHorizontalView != null) {
TaskStack stack = mTaskStackHorizontalView.getStack();
Task task = stack.getLaunchTarget();
if (task != null) {
launchTaskFomRecents(task);
launchTaskFomRecents(task, animate);
return true;
}
}
@@ -137,18 +137,25 @@ public class RecentsTvView extends FrameLayout {
* attempt to scroll to focus the task before launching.
* @param task
*/
private void launchTaskFomRecents(final Task task) {
if(task != mTaskStackHorizontalView.getFocusedTask()) {
if(mScrollListener != null) {
private void launchTaskFomRecents(final Task task, boolean animate) {
if (!animate) {
SystemServicesProxy ssp = Recents.getSystemServices();
ssp.startActivityFromRecents(getContext(), task.key, task.title, null);
return;
}
mTaskStackHorizontalView.requestFocus();
Task focusedTask = mTaskStackHorizontalView.getFocusedTask();
if (focusedTask != null && task != focusedTask) {
if (mScrollListener != null) {
mTaskStackHorizontalView.removeOnScrollListener(mScrollListener);
}
mScrollListener = new OnScrollListener() {
@Override
public void onScrollStateChanged(RecyclerView recyclerView, int newState) {
super.onScrollStateChanged(recyclerView, newState);
if(newState == RecyclerView.SCROLL_STATE_IDLE) {
if (newState == RecyclerView.SCROLL_STATE_IDLE) {
TaskCardView cardView = mTaskStackHorizontalView.getChildViewForTask(task);
if(cardView != null) {
if (cardView != null) {
mTransitionHelper.launchTaskFromRecents(mStack, task,
mTaskStackHorizontalView, cardView, null, INVALID_STACK_ID);
} else {

View File

@@ -150,10 +150,14 @@ public class PipRecentsOverlayManager {
* is focused.
* This should be called only by {@link com.android.systemui.recents.tv.RecentsTvActivity}.
*/
private void clearFocus() {
public void clearFocus() {
if (!mIsRecentsShown || !mIsPipFocusedInRecent) {
return;
}
if (!mRecentsView.hasFocus()) {
// Let mRecentsView's focus listener handle clearFocus().
mRecentsView.requestFocus();
}
mIsPipFocusedInRecent = false;
mPipManager.resizePinnedStack(STATE_PIP_RECENTS);
mWindowManager.updateViewLayout(mOverlayView, mPipRecentsControlsViewLayoutParams);