From 18cfc84f4814f87d660d04bad4f9941e6d503125 Mon Sep 17 00:00:00 2001 From: Sid Soundararajan Date: Thu, 7 Apr 2016 17:03:09 -0700 Subject: [PATCH] Have Recents focus second task when launched, if 2 or more tasks are available This should kill 2 bugs. b/27952292 b/27876144 Change-Id: I49521fc4b7fc52b9b34ce71b108cbe795e40104f --- .../recents/tv/RecentsTvActivity.java | 7 ++++ .../systemui/recents/tv/RecentsTvImpl.java | 7 ++-- .../recents/tv/views/TaskCardView.java | 34 +++++++++++++++++-- 3 files changed, 43 insertions(+), 5 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 13e1a14ead63c..bdc142644c70c 100644 --- a/packages/SystemUI/src/com/android/systemui/recents/tv/RecentsTvActivity.java +++ b/packages/SystemUI/src/com/android/systemui/recents/tv/RecentsTvActivity.java @@ -343,6 +343,13 @@ 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 diff --git a/packages/SystemUI/src/com/android/systemui/recents/tv/RecentsTvImpl.java b/packages/SystemUI/src/com/android/systemui/recents/tv/RecentsTvImpl.java index fd31872055657..dc0d1f1fe465d 100644 --- a/packages/SystemUI/src/com/android/systemui/recents/tv/RecentsTvImpl.java +++ b/packages/SystemUI/src/com/android/systemui/recents/tv/RecentsTvImpl.java @@ -75,7 +75,8 @@ public class RecentsTvImpl extends RecentsImpl{ if (useThumbnailTransition) { // Try starting with a thumbnail transition - ActivityOptions opts = getThumbnailTransitionActivityOptionsForTV(topTask); + ActivityOptions opts = getThumbnailTransitionActivityOptionsForTV(topTask, + stack.getTaskCount()); if (opts != null) { startRecentsActivity(topTask, opts, false /* fromHome */, true /* fromThumbnail */); } else { @@ -118,8 +119,8 @@ public class RecentsTvImpl extends RecentsImpl{ * Creates the activity options for an app->recents transition on TV. */ private ActivityOptions getThumbnailTransitionActivityOptionsForTV( - ActivityManager.RunningTaskInfo topTask) { - Rect rect = TaskCardView.getStartingCardThumbnailRect(mContext); + ActivityManager.RunningTaskInfo topTask, int numTasks) { + Rect rect = TaskCardView.getStartingCardThumbnailRect(mContext, numTasks); SystemServicesProxy ssp = Recents.getSystemServices(); ThumbnailData thumbnailData = ssp.getTaskThumbnail(topTask.id); if (thumbnailData.thumbnail != null) { diff --git a/packages/SystemUI/src/com/android/systemui/recents/tv/views/TaskCardView.java b/packages/SystemUI/src/com/android/systemui/recents/tv/views/TaskCardView.java index 99d478b2e8d17..08d5cb0feb023 100644 --- a/packages/SystemUI/src/com/android/systemui/recents/tv/views/TaskCardView.java +++ b/packages/SystemUI/src/com/android/systemui/recents/tv/views/TaskCardView.java @@ -95,7 +95,38 @@ public class TaskCardView extends LinearLayout { return r; } - public static Rect getStartingCardThumbnailRect(Context context) { + public static Rect getStartingCardThumbnailRect(Context context, int numberOfTasks) { + if(numberOfTasks > 1) { + return getStartingCardThumbnailRectForStartPosition(context); + } else { + return getStartingCardThumbnailRectForFocusedPosition(context); + } + } + + private static Rect getStartingCardThumbnailRectForStartPosition(Context context) { + Resources res = context.getResources(); + + int width = res.getDimensionPixelOffset(R.dimen.recents_tv_card_width); + int totalSpacing = res.getDimensionPixelOffset(R.dimen.recents_tv_gird_card_spacing) * 2 + + res.getDimensionPixelOffset(R.dimen.recents_tv_gird_focused_card_delta); + int height = res.getDimensionPixelOffset(R.dimen.recents_tv_screenshot_height); + int topMargin = res.getDimensionPixelOffset(R.dimen.recents_tv_gird_row_top_margin); + int headerHeight = res.getDimensionPixelOffset(R.dimen.recents_tv_card_extra_badge_size) + + res.getDimensionPixelOffset(R.dimen.recents_tv_icon_padding_bottom); + + WindowManager wm = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE); + Display display = wm.getDefaultDisplay(); + Point size = new Point(); + display.getSize(size); + int screenWidth = size.x; + + return new Rect(screenWidth / 2 + width / 2 + totalSpacing, + topMargin + headerHeight, + screenWidth / 2 + width / 2 + totalSpacing + width, + topMargin + headerHeight + height); + } + + private static Rect getStartingCardThumbnailRectForFocusedPosition(Context context) { Resources res = context.getResources(); TypedValue out = new TypedValue(); @@ -127,7 +158,6 @@ public class TaskCardView extends LinearLayout { Point size = new Point(); display.getSize(size); int screenWidth = size.x; - int screenHeight = size.y; return new Rect(screenWidth / 2 - width / 2 - widthDelta / 2, topMargin - totalHeightDelta / 2 + (int) (headerHeight * scale),