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

Commit 483d2ddd authored by Kevin's avatar Kevin
Browse files

Use custom drawable for Recents Go thumbnails (2/2)

Hook up the thumbnail drawable created in the first CL to the task
thumbnail so that the drawable automatically rotates and resizes based
off the device orientation.

Bug: 114136250
Bug: 131095241
Test: Go to app in landscape, go to recents, rotate => thumbnail rotates
Change-Id: Ib58e45ab3e94aeb080e47b1d5b38c221acce5ef3
parent 6503757a
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -146,7 +146,7 @@ public final class TaskAdapter extends Adapter<ViewHolder> {
                });
                mLoader.loadTaskThumbnail(task, () -> {
                    if (Objects.equals(Optional.of(task), taskHolder.getTask())) {
                        taskHolder.getTaskItemView().setThumbnail(task.thumbnail.thumbnail);
                        taskHolder.getTaskItemView().setThumbnail(task.thumbnail);
                    }
                });
                break;
+2 −5
Original line number Diff line number Diff line
@@ -15,8 +15,6 @@
 */
package com.android.quickstep;

import android.graphics.Bitmap;

import androidx.annotation.NonNull;
import androidx.recyclerview.widget.RecyclerView.ViewHolder;

@@ -58,12 +56,11 @@ public final class TaskHolder extends ViewHolder {
     */
    public void bindTask(@NonNull Task task, boolean willAnimate) {
        mTask = task;
        Bitmap thumbnail = (task.thumbnail != null) ? task.thumbnail.thumbnail : null;
        if (willAnimate) {
            mTaskItemView.startContentAnimation(task.icon, thumbnail, task.titleDescription);
            mTaskItemView.startContentAnimation(task.icon, task.thumbnail, task.titleDescription);
        } else {
            mTaskItemView.setIcon(task.icon);
            mTaskItemView.setThumbnail(thumbnail);
            mTaskItemView.setThumbnail(task.thumbnail);
            mTaskItemView.setLabel(task.titleDescription);
        }
    }
+1 −1
Original line number Diff line number Diff line
@@ -125,7 +125,7 @@ public final class IconRecentsView extends FrameLayout {
                Task task = optTask.get();
                // Update thumbnail on the task.
                task.thumbnail = thumbnailData;
                taskView.setThumbnail(thumbnailData.thumbnail);
                taskView.setThumbnail(thumbnailData);
                return task;
            }
        }
+26 −10
Original line number Diff line number Diff line
@@ -18,9 +18,8 @@ package com.android.quickstep.views;
import static com.android.quickstep.views.TaskLayoutUtils.getTaskHeight;

import android.content.Context;
import android.content.res.Configuration;
import android.content.res.Resources;
import android.graphics.Bitmap;
import android.graphics.drawable.BitmapDrawable;
import android.graphics.drawable.Drawable;
import android.util.AttributeSet;
import android.util.FloatProperty;
@@ -33,6 +32,8 @@ import androidx.annotation.NonNull;
import androidx.annotation.Nullable;

import com.android.launcher3.R;
import com.android.quickstep.ThumbnailDrawable;
import com.android.systemui.shared.recents.model.ThumbnailData;

/**
 * View representing an individual task item with the icon + thumbnail adjacent to the task label.
@@ -132,10 +133,10 @@ public final class TaskItemView extends LinearLayout {
    /**
     * Set the task thumbnail for the task. Sets to a default thumbnail if null.
     *
     * @param thumbnail task thumbnail for the task
     * @param thumbnailData task thumbnail data for the task
     */
    public void setThumbnail(@Nullable Bitmap thumbnail) {
        mThumbnailDrawable.setCurrentDrawable(getSafeThumbnail(thumbnail));
    public void setThumbnail(@Nullable ThumbnailData thumbnailData) {
        mThumbnailDrawable.setCurrentDrawable(getSafeThumbnail(thumbnailData));
    }

    public View getThumbnailView() {
@@ -151,8 +152,8 @@ public final class TaskItemView extends LinearLayout {
     * @param endThumbnail the thumbnail to animate to
     * @param endLabel the label to animate to
     */
    public void startContentAnimation(@Nullable Drawable endIcon, @Nullable Bitmap endThumbnail,
            @Nullable String endLabel) {
    public void startContentAnimation(@Nullable Drawable endIcon,
            @Nullable ThumbnailData endThumbnail, @Nullable String endLabel) {
        mIconDrawable.startNewTransition(getSafeIcon(endIcon));
        mThumbnailDrawable.startNewTransition(getSafeThumbnail(endThumbnail));
        // TODO: Animation for label
@@ -171,12 +172,27 @@ public final class TaskItemView extends LinearLayout {
        return (icon != null) ? icon : mDefaultIcon;
    }

    private @NonNull Drawable getSafeThumbnail(@Nullable Bitmap thumbnail) {
        return (thumbnail != null) ? new BitmapDrawable(getResources(), thumbnail)
                                   : mDefaultThumbnail;
    private @NonNull Drawable getSafeThumbnail(@Nullable ThumbnailData thumbnailData) {
        if (thumbnailData == null || thumbnailData.thumbnail == null) {
            return mDefaultThumbnail;
        }
        int orientation = getResources().getConfiguration().orientation;
        return new ThumbnailDrawable(thumbnailData,  orientation /* requestedOrientation */);
    }

    private @NonNull String getSafeLabel(@Nullable String label) {
        return (label != null) ? label : DEFAULT_LABEL;
    }

    @Override
    protected void onConfigurationChanged(Configuration newConfig) {
        super.onConfigurationChanged(newConfig);
        int layerCount = mThumbnailDrawable.getNumberOfLayers();
        for (int i = 0; i < layerCount; i++) {
            Drawable drawable = mThumbnailDrawable.getDrawable(i);
            if (drawable instanceof ThumbnailDrawable) {
                ((ThumbnailDrawable) drawable).setRequestedOrientation(newConfig.orientation);
            }
        }
    }
}