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

Commit 14168431 authored by Sunny Goyal's avatar Sunny Goyal
Browse files

Adding support for dynamic calendar and clock icons

Change-Id: Icdba34340a27a4f6dff7310d0bf9fd29aef1330c
parent 70d7860e
Loading
Loading
Loading
Loading
+38 −18
Original line number Diff line number Diff line
@@ -40,6 +40,7 @@ import android.graphics.Matrix;
import android.graphics.Rect;
import android.graphics.RectF;
import android.graphics.drawable.Drawable;
import android.os.UserHandle;
import android.util.ArraySet;
import android.util.AttributeSet;
import android.util.FloatProperty;
@@ -66,6 +67,7 @@ import com.android.launcher3.R;
import com.android.launcher3.util.Themes;
import com.android.quickstep.ContentFillItemAnimator;
import com.android.quickstep.RecentsModel;
import com.android.quickstep.RecentsModel.TaskVisualsChangeListener;
import com.android.quickstep.RecentsToActivityHelper;
import com.android.quickstep.TaskActionController;
import com.android.quickstep.TaskAdapter;
@@ -74,6 +76,7 @@ import com.android.quickstep.TaskListLoader;
import com.android.quickstep.TaskSwipeCallback;
import com.android.quickstep.util.MultiValueUpdateListener;
import com.android.systemui.shared.recents.model.Task;
import com.android.systemui.shared.recents.model.ThumbnailData;
import com.android.systemui.shared.system.RemoteAnimationTargetCompat;
import com.android.systemui.shared.system.SyncRtSurfaceTransactionApplierCompat;
import com.android.systemui.shared.system.SyncRtSurfaceTransactionApplierCompat.SurfaceParams;
@@ -87,7 +90,8 @@ import java.util.Optional;
 * Root view for the icon recents view. Acts as the main interface to the rest of the Launcher code
 * base.
 */
public final class IconRecentsView extends FrameLayout implements Insettable {
public final class IconRecentsView extends FrameLayout
        implements Insettable, TaskVisualsChangeListener {

    public static final FloatProperty<IconRecentsView> CONTENT_ALPHA =
            new FloatProperty<IconRecentsView>("contentAlpha") {
@@ -159,22 +163,6 @@ public final class IconRecentsView extends FrameLayout implements Insettable {
    private AnimatorSet mLayoutAnimation;
    private final ArraySet<View> mLayingOutViews = new ArraySet<>();
    private Rect mInsets;
    private final RecentsModel.TaskThumbnailChangeListener listener = (taskId, thumbnailData) -> {
        ArrayList<TaskItemView> itemViews = getTaskViews();
        for (int i = 0, size = itemViews.size(); i < size; i++) {
            TaskItemView taskView = itemViews.get(i);
            TaskHolder taskHolder = (TaskHolder) mTaskRecyclerView.getChildViewHolder(taskView);
            Optional<Task> optTask = taskHolder.getTask();
            if (optTask.filter(task -> task.key.id == taskId).isPresent()) {
                Task task = optTask.get();
                // Update thumbnail on the task.
                task.thumbnail = thumbnailData;
                taskView.setThumbnail(thumbnailData);
                return task;
            }
        }
        return null;
    };

    public IconRecentsView(Context context, AttributeSet attrs) {
        super(context, attrs);
@@ -189,9 +177,29 @@ public final class IconRecentsView extends FrameLayout implements Insettable {
                mActivity.getStatsLogManager());
        mTaskAdapter.setActionController(mTaskActionController);
        mTaskLayoutManager = new LinearLayoutManager(mContext, VERTICAL, true /* reverseLayout */);
        RecentsModel.INSTANCE.get(context).addThumbnailChangeListener(listener);
    }

    @Override
    public Task onTaskThumbnailChanged(int taskId, ThumbnailData thumbnailData) {
        ArrayList<TaskItemView> itemViews = getTaskViews();
        for (int i = 0, size = itemViews.size(); i < size; i++) {
            TaskItemView taskView = itemViews.get(i);
            TaskHolder taskHolder = (TaskHolder) mTaskRecyclerView.getChildViewHolder(taskView);
            Optional<Task> optTask = taskHolder.getTask();
            if (optTask.filter(task -> task.key.id == taskId).isPresent()) {
                Task task = optTask.get();
                // Update thumbnail on the task.
                task.thumbnail = thumbnailData;
                taskView.setThumbnail(thumbnailData);
                return task;
            }
        }
        return null;
    }

    @Override
    public void onTaskIconChanged(String pkg, UserHandle user) { }

    @Override
    protected void onFinishInflate() {
        super.onFinishInflate();
@@ -274,6 +282,18 @@ public final class IconRecentsView extends FrameLayout implements Insettable {
        }
    }

    @Override
    protected void onAttachedToWindow() {
        super.onAttachedToWindow();
        RecentsModel.INSTANCE.get(getContext()).addThumbnailChangeListener(this);
    }

    @Override
    protected void onDetachedFromWindow() {
        super.onDetachedFromWindow();
        RecentsModel.INSTANCE.get(getContext()).removeThumbnailChangeListener(this);
    }

    @Override
    public void setEnabled(boolean enabled) {
        super.setEnabled(enabled);
+9 −2
Original line number Diff line number Diff line
@@ -116,7 +116,7 @@ public class BaseIconFactory implements AutoCloseable {
            icon = createIconBitmap(new BitmapDrawable(mContext.getResources(), icon), 1f);
        }

        return BitmapInfo.fromBitmap(icon, mDisableColorExtractor ? null : mColorExtractor);
        return BitmapInfo.of(icon, extractColor(icon));
    }

    public BitmapInfo createBadgedIconBitmap(Drawable icon, UserHandle user,
@@ -186,7 +186,10 @@ public class BaseIconFactory implements AutoCloseable {
        } else {
            result = bitmap;
        }
        return BitmapInfo.fromBitmap(result, mDisableColorExtractor ? null : mColorExtractor);
        int color = extractColor(result);
        return icon instanceof BitmapInfo.Extender
                ? ((BitmapInfo.Extender) icon).getExtendedInfo(result, color, this)
                : BitmapInfo.of(result, color);
    }

    public Bitmap createScaledBitmapWithoutShadow(Drawable icon, boolean shrinkNonAdaptiveIcons) {
@@ -337,6 +340,10 @@ public class BaseIconFactory implements AutoCloseable {
                iconDpi);
    }

    private int extractColor(Bitmap bitmap) {
        return mDisableColorExtractor ? 0 : mColorExtractor.findDominantColorByHue(bitmap);
    }

    /**
     * Returns the correct badge size given an icon size
     */
+19 −9
Original line number Diff line number Diff line
@@ -19,12 +19,11 @@ import android.graphics.Bitmap;
import android.graphics.Bitmap.Config;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;

public class BitmapInfo {

    public static final Bitmap LOW_RES_ICON = Bitmap.createBitmap(1, 1, Config.ALPHA_8);
    public static final BitmapInfo LOW_RES_INFO = fromBitmap(LOW_RES_ICON, null);
    public static final BitmapInfo LOW_RES_INFO = fromBitmap(LOW_RES_ICON);

    public final Bitmap icon;
    public final int color;
@@ -49,14 +48,25 @@ public class BitmapInfo {
        return of(bitmap, 0);
    }

    public static BitmapInfo fromBitmap(@NonNull Bitmap bitmap,
            @Nullable ColorExtractor dominantColorExtractor) {
        return of(bitmap, dominantColorExtractor != null
                ? dominantColorExtractor.findDominantColorByHue(bitmap)
                : 0);
    }

    public static BitmapInfo of(@NonNull Bitmap bitmap, int color) {
        return new BitmapInfo(bitmap, color);
    }

    /**
     * Interface to be implemented by drawables to provide a custom BitmapInfo
     */
    public interface Extender {

        /**
         * Called for creating a custom BitmapInfo
         */
        default BitmapInfo getExtendedInfo(Bitmap bitmap, int color, BaseIconFactory iconFactory) {
            return BitmapInfo.of(bitmap, color);
        }

        /**
         * Notifies the drawable that it will be drawn directly in the UI, without any preprocessing
         */
        default void prepareToDrawOnUi() { }
    }
}
+1 −1
Original line number Diff line number Diff line
@@ -464,7 +464,7 @@ public abstract class BaseIconCache {
        return entry;
    }

    private boolean getEntryFromDB(ComponentKey cacheKey, CacheEntry entry, boolean lowRes) {
    protected boolean getEntryFromDB(ComponentKey cacheKey, CacheEntry entry, boolean lowRes) {
        Cursor c = null;
        try {
            c = mIconDb.query(
+1 −5
Original line number Diff line number Diff line
@@ -18,8 +18,6 @@ package com.android.launcher3.appprediction;

import static com.android.quickstep.InstantAppResolverImpl.COMPONENT_CLASS_MARKER;

import android.content.Context;

import com.android.launcher3.AppInfo;
import com.android.launcher3.ItemInfoWithIcon;
import com.android.launcher3.allapps.AllAppsStore;
@@ -29,11 +27,9 @@ import com.android.launcher3.util.ComponentKey;
public class ComponentKeyMapper {

    protected final ComponentKey componentKey;
    private final Context mContext;
    private final DynamicItemCache mCache;

    public ComponentKeyMapper(Context context, ComponentKey key, DynamicItemCache cache) {
        mContext = context;
    public ComponentKeyMapper(ComponentKey key, DynamicItemCache cache) {
        componentKey = key;
        mCache = cache;
    }
Loading