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

Commit 202fabfe authored by Sunny Goyal's avatar Sunny Goyal
Browse files

Adding reusable version of IconCache and IconFactory

> Adding resource based allowing projects to control cache behavior
> Fixing missing comments from ag/5470467
> Adding support for no-immemory cache

Bug: 115891474
Change-Id: I691206805430cd93d3be78119bc249cefd79790a
parent 7b3c12f9
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -76,7 +76,7 @@ LOCAL_STATIC_ANDROID_LIBRARIES := \
    androidx.recyclerview_recyclerview \
    androidx.dynamicanimation_dynamicanimation \
    androidx.preference_preference \
    iconloader
    iconloader_base

LOCAL_STATIC_JAVA_LIBRARIES := LauncherPluginLib

+17 −1
Original line number Diff line number Diff line
@@ -13,7 +13,7 @@
// limitations under the License.

android_library {
    name: "iconloader",
    name: "iconloader_base",
    sdk_version: "28",
    min_sdk_version: "21",
    static_libs: [
@@ -26,3 +26,19 @@ android_library {
        "src/**/*.java",
    ],
}

android_library {
    name: "iconloader",
    sdk_version: "system_current",
    min_sdk_version: "21",
    static_libs: [
        "androidx.core_core",
    ],
    resource_dirs: [
        "res",
    ],
    srcs: [
        "src/**/*.java",
        "src_full_lib/**/*.java",
    ],
}
+1 −1
Original line number Diff line number Diff line
@@ -24,7 +24,7 @@ android {

    sourceSets {
        main {
            java.srcDirs = ['src']
            java.srcDirs = ['src', 'src_full_lib']
            manifest.srcFile 'AndroidManifest.xml'
            res.srcDirs = ['res']
        }
+27 −0
Original line number Diff line number Diff line
<?xml version="1.0" encoding="utf-8"?>
<!--
**
** Copyright 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.
*/
-->
<resources>

    <!-- Various configurations to control the simple cache implementation -->

    <dimen name="default_icon_bitmap_size">56dp</dimen>
    <bool name="simple_cache_enable_im_memory">false</bool>
    <string name="cache_db_name" translatable="false">app_icons.db</string>

</resources>
 No newline at end of file
+24 −8
Original line number Diff line number Diff line
package com.android.launcher3.icons;

import static android.graphics.Paint.DITHER_FLAG;
import static android.graphics.Paint.FILTER_BITMAP_FLAG;

import static com.android.launcher3.icons.ShadowGenerator.BLUR_FACTOR;

import android.content.Context;
import android.content.Intent;
import android.content.pm.PackageManager;
@@ -18,29 +23,26 @@ import android.os.Build;
import android.os.Process;
import android.os.UserHandle;

import static android.graphics.Paint.DITHER_FLAG;
import static android.graphics.Paint.FILTER_BITMAP_FLAG;
import static com.android.launcher3.icons.ShadowGenerator.BLUR_FACTOR;

/**
 * This class will be moved to androidx library. There shouldn't be any dependency outside
 * this package.
 */
public class BaseIconFactory implements AutoCloseable {

    private static final String TAG = "BaseIconFactory";
    private static final int DEFAULT_WRAPPER_BACKGROUND = Color.WHITE;
    static final boolean ATLEAST_OREO = Build.VERSION.SDK_INT >= Build.VERSION_CODES.O;
    static final boolean ATLEAST_P = Build.VERSION.SDK_INT >= Build.VERSION_CODES.P;

    private final Rect mOldBounds = new Rect();
    private final Context mContext;
    protected final Context mContext;
    private final Canvas mCanvas;
    private final PackageManager mPm;
    private final ColorExtractor mColorExtractor;
    private boolean mDisableColorExtractor;

    private int mFillResIconDpi;
    private int mIconBitmapSize;
    protected final int mFillResIconDpi;
    protected final int mIconBitmapSize;

    private IconNormalizer mNormalizer;
    private ShadowGenerator mShadowGenerator;
@@ -302,7 +304,21 @@ public class BaseIconFactory implements AutoCloseable {
    }

    @Override
    public void close() { }
    public void close() {
        clear();
    }

    public BitmapInfo makeDefaultIcon(UserHandle user) {
        return createBadgedIconBitmap(getFullResDefaultActivityIcon(mFillResIconDpi),
                user, Build.VERSION.SDK_INT);
    }

    public static Drawable getFullResDefaultActivityIcon(int iconDpi) {
        return Resources.getSystem().getDrawableForDensity(
                Build.VERSION.SDK_INT >= Build.VERSION_CODES.O
                        ? android.R.drawable.sym_def_app_icon : android.R.mipmap.sym_def_app_icon,
                iconDpi);
    }

    /**
     * An extension of {@link BitmapDrawable} which returns the bitmap pixel size as intrinsic size.
Loading