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

Commit 33d1c3c0 authored by TreeHugger Robot's avatar TreeHugger Robot Committed by Android (Google) Code Review
Browse files

Merge "Normalizing icons in recents view" into ub-launcher3-master

parents a52d2eca 338d15d2
Loading
Loading
Loading
Loading
+2.03 KiB (114 KiB)

File changed.

No diff preview for this file type.

+84 −0
Original line number Diff line number Diff line
/*
 * Copyright (C) 2018 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package com.android.quickstep;

import android.annotation.TargetApi;
import android.content.ComponentName;
import android.content.Context;
import android.content.pm.ActivityInfo;
import android.content.res.Resources;
import android.graphics.drawable.Drawable;
import android.os.Build;
import android.os.Build.VERSION_CODES;
import android.os.UserHandle;
import android.util.LruCache;
import android.util.SparseArray;

import com.android.launcher3.FastBitmapDrawable;
import com.android.launcher3.graphics.BitmapInfo;
import com.android.launcher3.graphics.LauncherIcons;
import com.android.systemui.shared.recents.model.IconLoader;
import com.android.systemui.shared.recents.model.TaskKeyLruCache;

/**
 * Extension of {@link IconLoader} with icon normalization support
 */
@TargetApi(Build.VERSION_CODES.O)
public class NormalizedIconLoader extends IconLoader {

    private final SparseArray<BitmapInfo> mDefaultIcons = new SparseArray<>();
    private LauncherIcons mLauncherIcons;

    public NormalizedIconLoader(Context context, TaskKeyLruCache<Drawable> iconCache,
            LruCache<ComponentName, ActivityInfo> activityInfoCache) {
        super(context, iconCache, activityInfoCache);
    }

    @Override
    public Drawable getDefaultIcon(int userId) {
        synchronized (mDefaultIcons) {
            BitmapInfo info = mDefaultIcons.get(userId);
            if (info == null) {
                info = getBitmapInfo(Resources.getSystem()
                        .getDrawable(android.R.drawable.sym_def_app_icon), userId);
                mDefaultIcons.put(userId, info);
            }

            return new FastBitmapDrawable(info);
        }
    }

    @Override
    protected Drawable createBadgedDrawable(Drawable drawable, int userId) {
        return new FastBitmapDrawable(getBitmapInfo(drawable, userId));
    }

    private synchronized BitmapInfo getBitmapInfo(Drawable drawable, int userId) {
        if (mLauncherIcons == null) {
            mLauncherIcons = LauncherIcons.obtain(mContext);
        }

        // User version code O, so that the icon is always wrapped in an adaptive icon container.
        return mLauncherIcons.createBadgedIconBitmap(drawable, UserHandle.of(userId),
                Build.VERSION_CODES.O);
    }

    @Override
    protected Drawable getBadgedActivityIcon(ActivityInfo activityInfo, int userId) {
        return createBadgedDrawable(
                activityInfo.loadUnbadgedIcon(mContext.getPackageManager()), userId);
    }
}
+15 −1
Original line number Diff line number Diff line
@@ -16,18 +16,24 @@
package com.android.quickstep;

import android.annotation.TargetApi;
import android.content.ComponentName;
import android.content.Context;
import android.content.pm.ActivityInfo;
import android.content.res.Resources;
import android.graphics.drawable.Drawable;
import android.os.Build;
import android.os.Looper;
import android.os.UserHandle;
import android.util.LruCache;

import com.android.launcher3.MainThreadExecutor;
import com.android.launcher3.R;
import com.android.systemui.shared.recents.ISystemUiProxy;
import com.android.systemui.shared.recents.model.IconLoader;
import com.android.systemui.shared.recents.model.RecentsTaskLoadPlan;
import com.android.systemui.shared.recents.model.RecentsTaskLoadPlan.PreloadOptions;
import com.android.systemui.shared.recents.model.RecentsTaskLoader;
import com.android.systemui.shared.recents.model.TaskKeyLruCache;
import com.android.systemui.shared.system.ActivityManagerWrapper;
import com.android.systemui.shared.system.BackgroundExecutor;
import com.android.systemui.shared.system.TaskStackChangeListener;
@@ -75,7 +81,15 @@ public class RecentsModel extends TaskStackChangeListener {
        Resources res = context.getResources();
        mRecentsTaskLoader = new RecentsTaskLoader(mContext,
                res.getInteger(R.integer.config_recentsMaxThumbnailCacheSize),
                res.getInteger(R.integer.config_recentsMaxIconCacheSize), 0);
                res.getInteger(R.integer.config_recentsMaxIconCacheSize), 0) {

            @Override
            protected IconLoader createNewIconLoader(Context context,
                    TaskKeyLruCache<Drawable> iconCache,
                    LruCache<ComponentName, ActivityInfo> activityInfoCache) {
                return new NormalizedIconLoader(context, iconCache, activityInfoCache);
            }
        };
        mRecentsTaskLoader.startLoader(mContext);

        mMainThreadExecutor = new MainThreadExecutor();
+28 −0
Original line number Diff line number Diff line
@@ -29,6 +29,8 @@ import android.graphics.PixelFormat;
import android.graphics.PorterDuff;
import android.graphics.PorterDuffColorFilter;
import android.graphics.drawable.Drawable;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.util.Property;
import android.util.SparseArray;

@@ -304,4 +306,30 @@ public class FastBitmapDrawable extends Drawable {
        }
        invalidateSelf();
    }

    @Override
    public ConstantState getConstantState() {
        return new MyConstantState(mBitmap, mIconColor);
    }

    private static class MyConstantState extends ConstantState {
        private final Bitmap mBitmap;
        private final int mIconColor;


        public MyConstantState(Bitmap bitmap, int color) {
            mBitmap = bitmap;
            mIconColor = color;
        }

        @Override
        public Drawable newDrawable() {
            return new FastBitmapDrawable(mBitmap, mIconColor);
        }

        @Override
        public int getChangingConfigurations() {
            return 0;
        }
    }
}