Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 15986f09 authored by Sid Soundararajan's avatar Sid Soundararajan Committed by Android (Google) Code Review
Browse files

Merge "Have Recents focus second task when launched, if 2 or more tasks are available" into nyc-dev

parents 1d616f0d 18cfc84f
Loading
Loading
Loading
Loading
+7 −0
Original line number Diff line number Diff line
@@ -344,6 +344,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
+4 −3
Original line number Diff line number Diff line
@@ -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) {
+32 −2
Original line number Diff line number Diff line
@@ -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),