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

Commit 337e10d2 authored by Alex Chau's avatar Alex Chau
Browse files

Add helper API in Task to avoid direct usage of lastSnapshotData in Launcher

Bug: 174464656
Test: Test tablet overview with different comination of portrait/landscape wide/narrow thumbnails in portrait/landscape
Change-Id: I4ac7217357c38baeb9aca0fb789dd48824dcd59b
parent 814951f2
Loading
Loading
Loading
Loading
+20 −0
Original line number Diff line number Diff line
@@ -254,6 +254,7 @@ public class Task {
    public Task(Task other) {
        this(other.key, other.colorPrimary, other.colorBackground, other.isDockable,
                other.isLocked, other.taskDescription, other.topActivity);
        lastSnapshotData.set(other.lastSnapshotData);
    }

    /**
@@ -281,6 +282,25 @@ public class Task {
                : key.baseIntent.getComponent();
    }

    public void setLastSnapshotData(ActivityManager.RecentTaskInfo rawTask) {
        lastSnapshotData.set(rawTask.lastSnapshotData);
    }

    /**
     * Returns the visible width to height ratio. Returns 0f if snapshot data is not available.
     */
    public float getVisibleThumbnailRatio() {
        if (lastSnapshotData.taskSize == null || lastSnapshotData.contentInsets == null) {
            return 0f;
        }

        float availableWidth = lastSnapshotData.taskSize.x - (lastSnapshotData.contentInsets.left
                + lastSnapshotData.contentInsets.right);
        float availableHeight = lastSnapshotData.taskSize.y - (lastSnapshotData.contentInsets.top
                + lastSnapshotData.contentInsets.bottom);
        return availableWidth / availableHeight;
    }

    @Override
    public boolean equals(Object o) {
        // Check that the id matches