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 ActivityInfo mActivityInfo; 33 private ComponentName mComponentName; 34 private PackageManager mPm; 35 LauncherActivityInfoCompatV16(Context context, ResolveInfo info)36 LauncherActivityInfoCompatV16(Context context, ResolveInfo info) { 37 super(); 38 this.mActivityInfo = info.activityInfo; 39 mComponentName = new ComponentName(mActivityInfo.packageName, mActivityInfo.name); 40 mPm = context.getPackageManager(); 41 } 42 getComponentName()43 public ComponentName getComponentName() { 44 return mComponentName; 45 } 46 getUser()47 public UserHandleCompat getUser() { 48 return UserHandleCompat.myUserHandle(); 49 } 50 getLabel()51 public CharSequence getLabel() { 52 return mActivityInfo.loadLabel(mPm); 53 } 54 getIcon(int density)55 public Drawable getIcon(int density) { 56 Drawable d = null; 57 if (mActivityInfo.getIconResource() != 0) { 58 Resources resources; 59 try { 60 resources = mPm.getResourcesForApplication(mActivityInfo.packageName); 61 } catch (PackageManager.NameNotFoundException e) { 62 resources = null; 63 } 64 if (resources != null) { 65 try { 66 d = resources.getDrawableForDensity(mActivityInfo.getIconResource(), density); 67 } catch (Resources.NotFoundException e) { 68 // Return default icon below. 69 } 70 } 71 } 72 if (d == null) { 73 Resources resources = Resources.getSystem(); 74 d = resources.getDrawableForDensity(android.R.mipmap.sym_def_app_icon, density); 75 } 76 return d; 77 } 78 getApplicationInfo()79 public ApplicationInfo getApplicationInfo() { 80 return mActivityInfo.applicationInfo; 81 } 82 getFirstInstallTime()83 public long getFirstInstallTime() { 84 try { 85 PackageInfo info = mPm.getPackageInfo(mActivityInfo.packageName, 0); 86 return info != null ? info.firstInstallTime : 0; 87 } catch (NameNotFoundException e) { 88 return 0; 89 } 90 } 91 getName()92 public String getName() { 93 return mActivityInfo.name; 94 } 95 getBadgedIcon(int density)96 public Drawable getBadgedIcon(int density) { 97 return getIcon(density); 98 } 99 } 100