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.PackageManager; 21 import android.os.UserHandle; 22 23 import com.android.launcher3.icons.cache.CachingLogic; 24 25 public interface ComponentWithLabel { 26 getComponent()27 ComponentName getComponent(); 28 getUser()29 UserHandle getUser(); 30 getLabel(PackageManager pm)31 CharSequence getLabel(PackageManager pm); 32 33 34 class ComponentCachingLogic implements CachingLogic<ComponentWithLabel> { 35 36 private final PackageManager mPackageManager; 37 ComponentCachingLogic(Context context)38 public ComponentCachingLogic(Context context) { 39 mPackageManager = context.getPackageManager(); 40 } 41 42 @Override getComponent(ComponentWithLabel object)43 public ComponentName getComponent(ComponentWithLabel object) { 44 return object.getComponent(); 45 } 46 47 @Override getUser(ComponentWithLabel object)48 public UserHandle getUser(ComponentWithLabel object) { 49 return object.getUser(); 50 } 51 52 @Override getLabel(ComponentWithLabel object)53 public CharSequence getLabel(ComponentWithLabel object) { 54 return object.getLabel(mPackageManager); 55 } 56 57 @Override loadIcon(Context context, ComponentWithLabel object, BitmapInfo target)58 public void loadIcon(Context context, 59 ComponentWithLabel object, BitmapInfo target) { 60 // Do not load icon. 61 target.icon = BitmapInfo.LOW_RES_ICON; 62 } 63 } 64 } 65