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

Commit 3a06568d authored by Alex Chau's avatar Alex Chau
Browse files

Use PersistedTaskSnapshotData to calculate TaskView size

- Disabled variable width for running task, as PersistedTaskSnapshotData is not always up to date for current task after rotating the device

Bug: 174464656
Test: Test tablet overview with different comination of portrait/landscape wide/narrow thumbnails in portrait/landscape
Change-Id: Ifa01e72020ccaf422e3975b092462de85fa19efd
parent 8dd4ddc7
Loading
Loading
Loading
Loading
+2 −3
Original line number Diff line number Diff line
@@ -191,6 +191,7 @@ public class RecentTasksList extends TaskStackChangeListener {
            } else {
                task = new Task(taskKey);
            }
            task.setLastSnapshotData(rawTask);
            allTasks.add(task);
        }

@@ -200,9 +201,7 @@ public class RecentTasksList extends TaskStackChangeListener {
    private ArrayList<Task> copyOf(ArrayList<Task> tasks) {
        ArrayList<Task> newTasks = new ArrayList<>();
        for (int i = 0; i < tasks.size(); i++) {
            Task t = tasks.get(i);
            newTasks.add(new Task(t.key, t.colorPrimary, t.colorBackground, t.isDockable,
                    t.isLocked, t.taskDescription, t.topActivity));
            newTasks.add(new Task(tasks.get(i)));
        }
        return newTasks;
    }
+7 −4
Original line number Diff line number Diff line
@@ -646,9 +646,9 @@ public abstract class RecentsView<T extends StatefulActivity> extends PagedView

    public TaskView getTaskView(int taskId) {
        for (int i = 0; i < getTaskViewCount(); i++) {
            TaskView tv = getTaskViewAt(i);
            if (tv.getTask() != null && tv.getTask().key != null && tv.getTask().key.id == taskId) {
                return tv;
            TaskView taskView = getTaskViewAt(i);
            if (taskView.hasTaskId(taskId)) {
                return taskView;
            }
        }
        return null;
@@ -808,6 +808,7 @@ public abstract class RecentsView<T extends StatefulActivity> extends PagedView
            final Task task = tasks.get(i);
            final TaskView taskView = (TaskView) getChildAt(pageIndex);
            taskView.bind(task, mOrientationState);
            taskView.updateTaskSize(!taskView.hasTaskId(mRunningTaskId));
        }

        if (mNextPage == INVALID_PAGE) {
@@ -942,7 +943,8 @@ public abstract class RecentsView<T extends StatefulActivity> extends PagedView
        // Force TaskView to update size from thumbnail
        final int taskCount = getTaskViewCount();
        for (int i = 0; i < taskCount; i++) {
            getTaskViewAt(i).updateTaskSize();
            TaskView taskView = getTaskViewAt(i);
            taskView.updateTaskSize(!taskView.hasTaskId(mRunningTaskId));
        }
    }

@@ -1252,6 +1254,7 @@ public abstract class RecentsView<T extends StatefulActivity> extends PagedView
            // gesture and the task list is loaded and applied
            mTmpRunningTask = Task.from(new TaskKey(runningTaskInfo), runningTaskInfo, false);
            taskView.bind(mTmpRunningTask, mOrientationState);
            taskView.updateTaskSize(false);

            // Measure and layout immediately so that the scroll values is updated instantly
            // as the user might be quick-switching
+0 −28
Original line number Diff line number Diff line
@@ -111,9 +111,6 @@ public class TaskThumbnailView extends View implements PluginListener<OverviewSc
    private boolean mOverlayEnabled;
    private OverviewScreenshotActions mOverviewScreenshotActionsPlugin;

    // TODO(b/179466077): Remove when proper API is ready.
    private Float mThumbnailRatio = null;

    public TaskThumbnailView(Context context) {
        this(context, null);
    }
@@ -454,31 +451,6 @@ public class TaskThumbnailView extends View implements PluginListener<OverviewSc
        return mThumbnailData.isRealSnapshot;
    }

    // TODO(b/179466077): Remove when proper API is ready.
    public float getThumbnailRatio() {
        // API is ready.
        if (mThumbnailRatio != null) {
            return mThumbnailRatio;
        }

        if (mThumbnailData == null || mThumbnailData.thumbnail == null) {
            final float[] thumbnailRatios =
                    new float[]{0.8882452f, 1.2834098f, 0.5558415f, 2.15625f};
            // Use key's hash code to return a deterministic thumbnail ratio.
            mThumbnailRatio = thumbnailRatios[mTask.key.hashCode() % thumbnailRatios.length];
            return mThumbnailRatio;
        }

        float surfaceWidth = mThumbnailData.thumbnail.getWidth() / mThumbnailData.scale;
        float surfaceHeight = mThumbnailData.thumbnail.getHeight() / mThumbnailData.scale;
        float availableWidth = surfaceWidth
                - (mThumbnailData.insets.left + mThumbnailData.insets.right);
        float availableHeight = surfaceHeight
                - (mThumbnailData.insets.top + mThumbnailData.insets.bottom);
        mThumbnailRatio = availableWidth / availableHeight;
        return mThumbnailRatio;
    }

    /**
     * Utility class to position the thumbnail in the TaskView
     */
+9 −4
Original line number Diff line number Diff line
@@ -48,6 +48,7 @@ import android.app.ActivityOptions;
import android.content.Context;
import android.content.Intent;
import android.graphics.Outline;
import android.graphics.Point;
import android.graphics.Rect;
import android.graphics.RectF;
import android.graphics.drawable.Drawable;
@@ -449,7 +450,6 @@ public class TaskView extends FrameLayout implements PageCallbacks, Reusable {
        cancelPendingLoadTasks();
        mTask = task;
        mSnapshotView.bind(task);
        updateTaskSize();
        setOrientationState(orientedState);
    }

@@ -457,6 +457,10 @@ public class TaskView extends FrameLayout implements PageCallbacks, Reusable {
        return mTask;
    }

    public boolean hasTaskId(int taskId) {
        return mTask != null && mTask.key != null && mTask.key.id == taskId;
    }

    public TaskThumbnailView getThumbnail() {
        return mSnapshotView;
    }
@@ -1077,9 +1081,11 @@ public class TaskView extends FrameLayout implements PageCallbacks, Reusable {
                previewPositionHelper);
    }

    void updateTaskSize() {
    void updateTaskSize(boolean variableWidth) {
        ViewGroup.LayoutParams params = getLayoutParams();
        if (mActivity.getDeviceProfile().isTablet && FeatureFlags.ENABLE_OVERVIEW_GRID.get()) {
        float thumbnailRatio = mTask != null ? mTask.getVisibleThumbnailRatio() : 0f;
        if (variableWidth && mActivity.getDeviceProfile().isTablet
                && FeatureFlags.ENABLE_OVERVIEW_GRID.get() && thumbnailRatio != 0f) {
            final int thumbnailPadding = (int) getResources().getDimension(
                    R.dimen.task_thumbnail_top_margin);

@@ -1087,7 +1093,6 @@ public class TaskView extends FrameLayout implements PageCallbacks, Reusable {
            int taskWidth = lastComputedTaskSize.width();
            int taskHeight = lastComputedTaskSize.height();
            int boxLength = Math.max(taskWidth, taskHeight);
            float thumbnailRatio = mSnapshotView.getThumbnailRatio();

            int expectedWidth;
            int expectedHeight;