• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2014 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.pm.ApplicationInfo;
22 import android.content.pm.PackageManager.NameNotFoundException;
23 import android.content.pm.ActivityInfo;
24 import android.content.pm.PackageManager;
25 import android.content.pm.PackageInfo;
26 import android.content.pm.ResolveInfo;
27 import android.content.res.Resources;
28 import android.graphics.drawable.Drawable;
29 
30 
31 public class LauncherActivityInfoCompatV16 extends LauncherActivityInfoCompat {
32     private final ResolveInfo mResolveInfo;
33     private final ActivityInfo mActivityInfo;
34     private final ComponentName mComponentName;
35     private final PackageManager mPm;
36 
LauncherActivityInfoCompatV16(Context context, ResolveInfo info)37     LauncherActivityInfoCompatV16(Context context, ResolveInfo info) {
38         super();
39         mResolveInfo = info;
40         mActivityInfo = info.activityInfo;
41         mComponentName = new ComponentName(mActivityInfo.packageName, mActivityInfo.name);
42         mPm = context.getPackageManager();
43     }
44 
getComponentName()45     public ComponentName getComponentName() {
46         return mComponentName;
47     }
48 
getUser()49     public UserHandleCompat getUser() {
50         return UserHandleCompat.myUserHandle();
51     }
52 
getLabel()53     public CharSequence getLabel() {
54         return mResolveInfo.loadLabel(mPm);
55     }
56 
getIcon(int density)57     public Drawable getIcon(int density) {
58         int iconRes = mResolveInfo.getIconResource();
59         Resources resources = null;
60         Drawable icon = null;
61         // Get the preferred density icon from the app's resources
62         if (density != 0 && iconRes != 0) {
63             try {
64                 resources = mPm.getResourcesForApplication(mActivityInfo.applicationInfo);
65                 icon = resources.getDrawableForDensity(iconRes, density);
66             } catch (NameNotFoundException | Resources.NotFoundException exc) {
67             }
68         }
69         // Get the default density icon
70         if (icon == null) {
71             icon = mResolveInfo.loadIcon(mPm);
72         }
73         if (icon == null) {
74             resources = Resources.getSystem();
75             icon = resources.getDrawableForDensity(android.R.mipmap.sym_def_app_icon, density);
76         }
77         return icon;
78     }
79 
getApplicationInfo()80     public ApplicationInfo getApplicationInfo() {
81         return mActivityInfo.applicationInfo;
82     }
83 
getFirstInstallTime()84     public long getFirstInstallTime() {
85         try {
86             PackageInfo info = mPm.getPackageInfo(mActivityInfo.packageName, 0);
87             return info != null ? info.firstInstallTime : 0;
88         } catch (NameNotFoundException e) {
89             return 0;
90         }
91     }
92 
getName()93     public String getName() {
94         return mActivityInfo.name;
95     }
96 }
97