• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2016 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 
17 package com.android.launcher3.compat;
18 
19 import android.content.ComponentName;
20 import android.content.Context;
21 import android.content.Intent;
22 import android.content.pm.ApplicationInfo;
23 import android.graphics.drawable.Drawable;
24 import android.util.Log;
25 
26 /**
27  * {@link LauncherActivityInfoCompat} which loads its data only when needed.
28  */
29 public class DeferredLauncherActivityInfo extends LauncherActivityInfoCompat {
30 
31     private final ComponentName mComponent;
32     private final UserHandleCompat mUser;
33     private final Context mContext;
34 
35     private LauncherActivityInfoCompat mActualInfo;
36 
DeferredLauncherActivityInfo( ComponentName component, UserHandleCompat user, Context context)37     public DeferredLauncherActivityInfo(
38             ComponentName component, UserHandleCompat user, Context context) {
39         mComponent = component;
40         mUser = user;
41         mContext = context;
42     }
43 
44     @Override
getComponentName()45     public ComponentName getComponentName() {
46         return mComponent;
47     }
48 
49     @Override
getUser()50     public UserHandleCompat getUser() {
51         return mUser;
52     }
53 
getActualInfo()54     private synchronized LauncherActivityInfoCompat getActualInfo() {
55         if (mActualInfo == null) {
56             Intent intent = new Intent(Intent.ACTION_MAIN)
57                     .addCategory(Intent.CATEGORY_LAUNCHER)
58                     .setComponent(mComponent);
59             mActualInfo = LauncherAppsCompat.getInstance(mContext).resolveActivity(intent, mUser);
60         }
61         return mActualInfo;
62     }
63 
64     @Override
getLabel()65     public CharSequence getLabel() {
66         return getActualInfo().getLabel();
67     }
68 
69     @Override
getIcon(int density)70     public Drawable getIcon(int density) {
71         return getActualInfo().getIcon(density);
72     }
73 
74     @Override
getApplicationInfo()75     public ApplicationInfo getApplicationInfo() {
76         return getActualInfo().getApplicationInfo();
77     }
78 
79     @Override
getFirstInstallTime()80     public long getFirstInstallTime() {
81         return getActualInfo().getFirstInstallTime();
82     }
83 }
84