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