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 com.android.launcher3.R;
24 import com.android.launcher3.icons.cache.CachingLogic;
25 import com.android.launcher3.util.ResourceBasedOverride;
26 
27 /**
28  * Caching logic for LauncherActivityInfo.
29  */
30 public class LauncherActivityCachingLogic
31         implements CachingLogic<LauncherActivityInfo>, ResourceBasedOverride {
32 
33     /**
34      * Creates and returns a new instance
35      */
newInstance(Context context)36     public static LauncherActivityCachingLogic newInstance(Context context) {
37         return Overrides.getObject(LauncherActivityCachingLogic.class, context,
38                 R.string.launcher_activity_logic_class);
39     }
40 
41     @Override
getComponent(LauncherActivityInfo object)42     public ComponentName getComponent(LauncherActivityInfo object) {
43         return object.getComponentName();
44     }
45 
46     @Override
getUser(LauncherActivityInfo object)47     public UserHandle getUser(LauncherActivityInfo object) {
48         return object.getUser();
49     }
50 
51     @Override
getLabel(LauncherActivityInfo object)52     public CharSequence getLabel(LauncherActivityInfo object) {
53         return object.getLabel();
54     }
55 
56     @Override
loadIcon(Context context, LauncherActivityInfo object)57     public BitmapInfo loadIcon(Context context, LauncherActivityInfo object) {
58         try (LauncherIcons li = LauncherIcons.obtain(context)) {
59             return li.createBadgedIconBitmap(new IconProvider(context)
60                             .getIcon(object, li.mFillResIconDpi),
61                     object.getUser(), object.getApplicationInfo().targetSdkVersion);
62         }
63     }
64 }
65