• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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<T extends ComponentWithLabel> implements CachingLogic<T> {
35 
36         private final PackageManager mPackageManager;
37         private final boolean mAddToMemCache;
38 
ComponentCachingLogic(Context context, boolean addToMemCache)39         public ComponentCachingLogic(Context context, boolean addToMemCache) {
40             mPackageManager = context.getPackageManager();
41             mAddToMemCache = addToMemCache;
42         }
43 
44         @Override
getComponent(T object)45         public ComponentName getComponent(T object) {
46             return object.getComponent();
47         }
48 
49         @Override
getUser(T object)50         public UserHandle getUser(T object) {
51             return object.getUser();
52         }
53 
54         @Override
getLabel(T object)55         public CharSequence getLabel(T object) {
56             return object.getLabel(mPackageManager);
57         }
58 
59         @Override
loadIcon(Context context, T object)60         public BitmapInfo loadIcon(Context context, T object) {
61             return BitmapInfo.LOW_RES_INFO;
62         }
63 
64         @Override
addToMemCache()65         public boolean addToMemCache() {
66             return mAddToMemCache;
67         }
68     }
69 }
70