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 androidx.annotation.NonNull; 24 25 import com.android.launcher3.icons.cache.CachingLogic; 26 27 public interface ComponentWithLabel { 28 getComponent()29 ComponentName getComponent(); 30 getUser()31 UserHandle getUser(); 32 getLabel(PackageManager pm)33 CharSequence getLabel(PackageManager pm); 34 35 36 class ComponentCachingLogic<T extends ComponentWithLabel> implements CachingLogic<T> { 37 38 private final PackageManager mPackageManager; 39 private final boolean mAddToMemCache; 40 ComponentCachingLogic(Context context, boolean addToMemCache)41 public ComponentCachingLogic(Context context, boolean addToMemCache) { 42 mPackageManager = context.getPackageManager(); 43 mAddToMemCache = addToMemCache; 44 } 45 46 @Override 47 @NonNull getComponent(@onNull T object)48 public ComponentName getComponent(@NonNull T object) { 49 return object.getComponent(); 50 } 51 52 @NonNull 53 @Override getUser(@onNull T object)54 public UserHandle getUser(@NonNull T object) { 55 return object.getUser(); 56 } 57 58 @NonNull 59 @Override getLabel(@onNull T object)60 public CharSequence getLabel(@NonNull T object) { 61 return object.getLabel(mPackageManager); 62 } 63 64 @NonNull 65 @Override loadIcon(@onNull Context context, @NonNull T object)66 public BitmapInfo loadIcon(@NonNull Context context, @NonNull T object) { 67 return BitmapInfo.LOW_RES_INFO; 68 } 69 70 @Override addToMemCache()71 public boolean addToMemCache() { 72 return mAddToMemCache; 73 } 74 } 75 } 76