1 /*
2  * Copyright (C) 2018 The Android Open Source Project
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 package com.android.launcher3.icons;
17 
18 import android.content.ComponentName;
19 import android.content.Context;
20 import android.content.pm.LauncherActivityInfo;
21 import android.os.UserHandle;
22 
23 import androidx.annotation.NonNull;
24 
25 import com.android.launcher3.LauncherAppState;
26 import com.android.launcher3.R;
27 import com.android.launcher3.icons.BaseIconFactory.IconOptions;
28 import com.android.launcher3.icons.cache.CachingLogic;
29 import com.android.launcher3.util.ResourceBasedOverride;
30 
31 /**
32  * Caching logic for LauncherActivityInfo.
33  */
34 public class LauncherActivityCachingLogic
35         implements CachingLogic<LauncherActivityInfo>, ResourceBasedOverride {
36 
37     /**
38      * Creates and returns a new instance
39      */
newInstance(Context context)40     public static LauncherActivityCachingLogic newInstance(Context context) {
41         return Overrides.getObject(LauncherActivityCachingLogic.class, context,
42                 R.string.launcher_activity_logic_class);
43     }
44 
45     @NonNull
46     @Override
getComponent(@onNull LauncherActivityInfo object)47     public ComponentName getComponent(@NonNull LauncherActivityInfo object) {
48         return object.getComponentName();
49     }
50 
51     @NonNull
52     @Override
getUser(@onNull LauncherActivityInfo object)53     public UserHandle getUser(@NonNull LauncherActivityInfo object) {
54         return object.getUser();
55     }
56 
57     @NonNull
58     @Override
getLabel(@onNull LauncherActivityInfo object)59     public CharSequence getLabel(@NonNull LauncherActivityInfo object) {
60         return object.getLabel();
61     }
62 
63     @NonNull
64     @Override
loadIcon(@onNull Context context, @NonNull LauncherActivityInfo object)65     public BitmapInfo loadIcon(@NonNull Context context, @NonNull LauncherActivityInfo object) {
66         try (LauncherIcons li = LauncherIcons.obtain(context)) {
67             return li.createBadgedIconBitmap(LauncherAppState.getInstance(context)
68                             .getIconProvider().getIcon(object, li.mFillResIconDpi),
69                     new IconOptions().setUser(object.getUser()));
70         }
71     }
72 }
73