From 24cf152483c03dc446875c8d6440348174317bc5 Mon Sep 17 00:00:00 2001 From: Winson Chung Date: Thu, 29 May 2014 12:03:33 -0700 Subject: Updating task view style, fixing performance on enter-recents animation. Change-Id: I42ca9296170a93a14184ae8963abbd3f0494e503 --- packages/SystemUI/res/layout/recents_task_view.xml | 23 ++++----- packages/SystemUI/res/values/colors.xml | 2 +- packages/SystemUI/res/values/config.xml | 2 +- packages/SystemUI/res/values/dimens.xml | 2 +- .../recents/AlternateRecentsComponent.java | 20 +++++++- .../android/systemui/recents/RecentsActivity.java | 4 ++ .../android/systemui/recents/RecentsService.java | 6 +++ .../systemui/recents/views/RecentsView.java | 12 +++++ .../systemui/recents/views/TaskStackView.java | 54 ++++++++++++++++------ .../android/systemui/recents/views/TaskView.java | 15 ++++-- 10 files changed, 107 insertions(+), 33 deletions(-) (limited to 'packages') diff --git a/packages/SystemUI/res/layout/recents_task_view.xml b/packages/SystemUI/res/layout/recents_task_view.xml index 7de421c..85d2f16 100644 --- a/packages/SystemUI/res/layout/recents_task_view.xml +++ b/packages/SystemUI/res/layout/recents_task_view.xml @@ -25,36 +25,37 @@ + android:layout_marginStart="16dp" + android:layout_gravity="center_vertical|start" /> diff --git a/packages/SystemUI/res/values/colors.xml b/packages/SystemUI/res/values/colors.xml index 4e37dbb..e6fa535 100644 --- a/packages/SystemUI/res/values/colors.xml +++ b/packages/SystemUI/res/values/colors.xml @@ -67,7 +67,7 @@ #ffeeeeee - #ff222222 + #ff333333 #ffeeeeee diff --git a/packages/SystemUI/res/values/config.xml b/packages/SystemUI/res/values/config.xml index 6405ae6..3c86d45 100644 --- a/packages/SystemUI/res/values/config.xml +++ b/packages/SystemUI/res/values/config.xml @@ -113,7 +113,7 @@ 125 - 225 + 300 175 diff --git a/packages/SystemUI/res/values/dimens.xml b/packages/SystemUI/res/values/dimens.xml index 610b376..c542b7c 100644 --- a/packages/SystemUI/res/values/dimens.xml +++ b/packages/SystemUI/res/values/dimens.xml @@ -212,7 +212,7 @@ 15dip - 60dp + 32dp 60dp diff --git a/packages/SystemUI/src/com/android/systemui/recents/AlternateRecentsComponent.java b/packages/SystemUI/src/com/android/systemui/recents/AlternateRecentsComponent.java index ffd64d4..2dc97e0 100644 --- a/packages/SystemUI/src/com/android/systemui/recents/AlternateRecentsComponent.java +++ b/packages/SystemUI/src/com/android/systemui/recents/AlternateRecentsComponent.java @@ -35,6 +35,7 @@ import android.os.IBinder; import android.os.Message; import android.os.Messenger; import android.os.RemoteException; +import android.os.SystemClock; import android.os.UserHandle; import android.util.DisplayMetrics; import android.view.Display; @@ -49,7 +50,7 @@ import java.util.List; import java.util.concurrent.atomic.AtomicBoolean; /** A proxy implementation for the recents component */ -public class AlternateRecentsComponent { +public class AlternateRecentsComponent implements ActivityOptions.OnAnimationStartedListener { /** A handler for messages from the recents implementation */ class RecentsMessageHandler extends Handler { @@ -123,6 +124,7 @@ public class AlternateRecentsComponent { final public static int MSG_SHOW_RECENTS = 4; final public static int MSG_HIDE_RECENTS = 5; final public static int MSG_TOGGLE_RECENTS = 6; + final public static int MSG_START_ENTER_ANIMATION = 7; final public static String EXTRA_ANIMATING_WITH_THUMBNAIL = "recents.animatingWithThumbnail"; final public static String EXTRA_FROM_ALT_TAB = "recents.triggeredFromAltTab"; @@ -392,7 +394,7 @@ public class AlternateRecentsComponent { } return ActivityOptions.makeThumbnailScaleDownAnimation(mStatusBarView, thumbnail, - taskRect.left, taskRect.top, null); + taskRect.left, taskRect.top, this); } /** Returns whether the recents is currently running */ @@ -517,4 +519,18 @@ public class AlternateRecentsComponent { mContext.startActivityAsUser(intent, new UserHandle(UserHandle.USER_CURRENT)); } } + + + /**** OnAnimationStartedListener Implementation ****/ + + @Override + public void onAnimationStarted() { + // Notify recents to start the enter animation + try { + Message msg = Message.obtain(null, MSG_START_ENTER_ANIMATION, 0, 0); + mService.send(msg); + } catch (RemoteException re) { + re.printStackTrace(); + } + } } diff --git a/packages/SystemUI/src/com/android/systemui/recents/RecentsActivity.java b/packages/SystemUI/src/com/android/systemui/recents/RecentsActivity.java index befe8b4..df387c1 100644 --- a/packages/SystemUI/src/com/android/systemui/recents/RecentsActivity.java +++ b/packages/SystemUI/src/com/android/systemui/recents/RecentsActivity.java @@ -98,6 +98,9 @@ public class RecentsActivity extends Activity implements RecentsView.RecentsView // If there are no filtered stacks, dismiss recents and launch the first task dismissRecentsIfVisible(); } + } else if (action.equals(RecentsService.ACTION_START_ENTER_ANIMATION)) { + // Try and start the enter animation + mRecentsView.startOnEnterAnimation(); } } }; @@ -345,6 +348,7 @@ public class RecentsActivity extends Activity implements RecentsView.RecentsView IntentFilter filter = new IntentFilter(); filter.addAction(RecentsService.ACTION_HIDE_RECENTS_ACTIVITY); filter.addAction(RecentsService.ACTION_TOGGLE_RECENTS_ACTIVITY); + filter.addAction(RecentsService.ACTION_START_ENTER_ANIMATION); registerReceiver(mServiceBroadcastReceiver, filter); // Register the broadcast receiver to handle messages when the screen is turned off diff --git a/packages/SystemUI/src/com/android/systemui/recents/RecentsService.java b/packages/SystemUI/src/com/android/systemui/recents/RecentsService.java index 4bdbb20..f90e4d3 100644 --- a/packages/SystemUI/src/com/android/systemui/recents/RecentsService.java +++ b/packages/SystemUI/src/com/android/systemui/recents/RecentsService.java @@ -127,6 +127,11 @@ class SystemUIMessageHandler extends Handler { Constants.Log.App.TimeRecentsStartupKey, "receivedToggleRecents"); Console.logTraceTime(Constants.Log.App.TimeRecentsLaunchTask, Constants.Log.App.TimeRecentsLaunchKey, "receivedToggleRecents"); + } else if (msg.what == AlternateRecentsComponent.MSG_START_ENTER_ANIMATION) { + // Send a broadcast to start the enter animation + Intent intent = new Intent(RecentsService.ACTION_START_ENTER_ANIMATION); + intent.setPackage(context.getPackageName()); + context.sendBroadcast(intent); } } } @@ -135,6 +140,7 @@ class SystemUIMessageHandler extends Handler { public class RecentsService extends Service { final static String ACTION_HIDE_RECENTS_ACTIVITY = "action_hide_recents_activity"; final static String ACTION_TOGGLE_RECENTS_ACTIVITY = "action_toggle_recents_activity"; + final static String ACTION_START_ENTER_ANIMATION = "action_start_enter_animation"; final static String EXTRA_TRIGGERED_FROM_ALT_TAB = "extra_triggered_from_alt_tab"; Messenger mSystemUIMessenger = new Messenger(new SystemUIMessageHandler(this)); diff --git a/packages/SystemUI/src/com/android/systemui/recents/views/RecentsView.java b/packages/SystemUI/src/com/android/systemui/recents/views/RecentsView.java index cad9ce5..6005275 100644 --- a/packages/SystemUI/src/com/android/systemui/recents/views/RecentsView.java +++ b/packages/SystemUI/src/com/android/systemui/recents/views/RecentsView.java @@ -158,6 +158,18 @@ public class RecentsView extends FrameLayout implements TaskStackView.TaskStackV return false; } + /** Requests all task stacks to start their enter-recents animation */ + public void startOnEnterAnimation() { + int childCount = getChildCount(); + for (int i = 0; i < childCount; i++) { + View child = getChildAt(i); + if (child instanceof TaskStackView) { + TaskStackView stackView = (TaskStackView) child; + stackView.startOnEnterAnimation(); + } + } + } + /** Adds the search bar */ public void setSearchBar(View searchBar) { // Create the search bar (and hide it if we have no recent tasks) diff --git a/packages/SystemUI/src/com/android/systemui/recents/views/TaskStackView.java b/packages/SystemUI/src/com/android/systemui/recents/views/TaskStackView.java index 2b08b19..99054d5 100644 --- a/packages/SystemUI/src/com/android/systemui/recents/views/TaskStackView.java +++ b/packages/SystemUI/src/com/android/systemui/recents/views/TaskStackView.java @@ -88,6 +88,7 @@ public class TaskStackView extends FrameLayout implements TaskStack.TaskStackCal int mStackViewsAnimationDuration; boolean mStackViewsDirty = true; boolean mAwaitingFirstLayout = true; + boolean mStartEnterAnimationRequestedAfterLayout; int[] mTmpVisibleRange = new int[2]; Rect mTmpRect = new Rect(); Rect mTmpRect2 = new Rect(); @@ -703,19 +704,6 @@ public class TaskStackView extends FrameLayout implements TaskStack.TaskStackCal setStackScroll(mMaxScroll); requestSynchronizeStackViewsWithModel(); synchronizeStackViewsWithModel(); - - // Update the focused task index to be the next item to the top task - if (config.launchedFromAltTab) { - focusTask(Math.max(0, mStack.getTaskCount() - 2), false); - } - - // Animate the task bar of the first task view - if (config.launchedWithThumbnailAnimation) { - TaskView tv = (TaskView) getChildAt(getChildCount() - 1); - if (tv != null) { - tv.animateOnEnterRecents(); - } - } } // Measure each of the children @@ -758,7 +746,47 @@ public class TaskStackView extends FrameLayout implements TaskStack.TaskStackCal } if (mAwaitingFirstLayout) { + RecentsConfiguration config = RecentsConfiguration.getInstance(); + + // Update the focused task index to be the next item to the top task + if (config.launchedFromAltTab) { + focusTask(Math.max(0, mStack.getTaskCount() - 2), false); + } + + // Prepare the first view for its enter animation + if (config.launchedWithThumbnailAnimation) { + TaskView tv = (TaskView) getChildAt(getChildCount() - 1); + if (tv != null) { + tv.prepareAnimateOnEnterRecents(); + } + } + + // Mark that we have completely the first layout mAwaitingFirstLayout = false; + + // If the enter animation started already and we haven't completed a layout yet, do the + // enter animation now + if (mStartEnterAnimationRequestedAfterLayout) { + startOnEnterAnimation(); + } + } + } + + /** Requests this task stacks to start it's enter-recents animation */ + public void startOnEnterAnimation() { + RecentsConfiguration config = RecentsConfiguration.getInstance(); + if (!config.launchedWithThumbnailAnimation) return; + + // If we are still waiting to layout, then just defer until then + if (mAwaitingFirstLayout) { + mStartEnterAnimationRequestedAfterLayout = true; + return; + } + + // Animate the task bar of the first task view + TaskView tv = (TaskView) getChildAt(getChildCount() - 1); + if (tv != null) { + tv.animateOnEnterRecents(); } } diff --git a/packages/SystemUI/src/com/android/systemui/recents/views/TaskView.java b/packages/SystemUI/src/com/android/systemui/recents/views/TaskView.java index 8575661..486539f 100644 --- a/packages/SystemUI/src/com/android/systemui/recents/views/TaskView.java +++ b/packages/SystemUI/src/com/android/systemui/recents/views/TaskView.java @@ -221,13 +221,20 @@ public class TaskView extends FrameLayout implements Task.TaskCallbacks, View.On fromTransform.alpha = 0f; } + /** Prepares this task view for the enter-recents animations. This is called earlier in the + * first layout because the actual animation into recents may take a long time. */ + public void prepareAnimateOnEnterRecents() { + mBarView.setVisibility(View.INVISIBLE); + } + /** Animates this task view as it enters recents */ public void animateOnEnterRecents() { RecentsConfiguration config = RecentsConfiguration.getInstance(); - mBarView.setAlpha(0f); + mBarView.setVisibility(View.VISIBLE); + mBarView.setTranslationY(-mBarView.getMeasuredHeight()); mBarView.animate() - .alpha(1f) - .setStartDelay(300) + .translationY(0) + .setStartDelay(200) .setInterpolator(config.defaultBezierInterpolator) .setDuration(config.taskBarEnterAnimDuration) .withLayer() @@ -238,7 +245,7 @@ public class TaskView extends FrameLayout implements Task.TaskCallbacks, View.On public void animateOnLeavingRecents(final Runnable r) { RecentsConfiguration config = RecentsConfiguration.getInstance(); mBarView.animate() - .alpha(0f) + .translationY(-mBarView.getMeasuredHeight()) .setStartDelay(0) .setInterpolator(config.defaultBezierInterpolator) .setDuration(config.taskBarExitAnimDuration) -- cgit v1.1