ShortcutInfo.java revision 10923b30a22b4ec8d10cf8536bddf3f176e6c26f
10589f0f66ce498512c6ee47482c649d88294c9d0Joe Onorato/* 20589f0f66ce498512c6ee47482c649d88294c9d0Joe Onorato * Copyright (C) 2008 The Android Open Source Project 30589f0f66ce498512c6ee47482c649d88294c9d0Joe Onorato * 40589f0f66ce498512c6ee47482c649d88294c9d0Joe Onorato * Licensed under the Apache License, Version 2.0 (the "License"); 50589f0f66ce498512c6ee47482c649d88294c9d0Joe Onorato * you may not use this file except in compliance with the License. 60589f0f66ce498512c6ee47482c649d88294c9d0Joe Onorato * You may obtain a copy of the License at 70589f0f66ce498512c6ee47482c649d88294c9d0Joe Onorato * 80589f0f66ce498512c6ee47482c649d88294c9d0Joe Onorato * http://www.apache.org/licenses/LICENSE-2.0 90589f0f66ce498512c6ee47482c649d88294c9d0Joe Onorato * 100589f0f66ce498512c6ee47482c649d88294c9d0Joe Onorato * Unless required by applicable law or agreed to in writing, software 110589f0f66ce498512c6ee47482c649d88294c9d0Joe Onorato * distributed under the License is distributed on an "AS IS" BASIS, 120589f0f66ce498512c6ee47482c649d88294c9d0Joe Onorato * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 130589f0f66ce498512c6ee47482c649d88294c9d0Joe Onorato * See the License for the specific language governing permissions and 140589f0f66ce498512c6ee47482c649d88294c9d0Joe Onorato * limitations under the License. 150589f0f66ce498512c6ee47482c649d88294c9d0Joe Onorato */ 160589f0f66ce498512c6ee47482c649d88294c9d0Joe Onorato 17325dc23624160689e59fbac708cf6f222b20d025Daniel Sandlerpackage com.android.launcher3; 180589f0f66ce498512c6ee47482c649d88294c9d0Joe Onorato 19bfbf7f9f4a0b300613f0ff27a4eb592d88c08325Tony Wickhamimport android.annotation.TargetApi; 20349426234e8c5a0e5bcf2c8d94dbb9844b5f724aSunny Goyalimport android.content.ComponentName; 210589f0f66ce498512c6ee47482c649d88294c9d0Joe Onoratoimport android.content.ContentValues; 221e2f465f46ded990ea30516cdb7f0fcf3280411fMichael Jurkaimport android.content.Context; 230589f0f66ce498512c6ee47482c649d88294c9d0Joe Onoratoimport android.content.Intent; 240589f0f66ce498512c6ee47482c649d88294c9d0Joe Onoratoimport android.graphics.Bitmap; 25bfbf7f9f4a0b300613f0ff27a4eb592d88c08325Tony Wickhamimport android.graphics.drawable.Drawable; 26bfbf7f9f4a0b300613f0ff27a4eb592d88c08325Tony Wickhamimport android.os.Build; 27bfbf7f9f4a0b300613f0ff27a4eb592d88c08325Tony Wickhamimport android.text.TextUtils; 280589f0f66ce498512c6ee47482c649d88294c9d0Joe Onorato 294fbc3828c5ae1e8c5789ede974447fa365f3c5a1Sunny Goyalimport com.android.launcher3.LauncherSettings.Favorites; 3018bf8e2ffde3444d53aaa9654da02cdedd0b7cd1Sunny Goyalimport com.android.launcher3.compat.LauncherActivityInfoCompat; 31bfbf7f9f4a0b300613f0ff27a4eb592d88c08325Tony Wickhamimport com.android.launcher3.compat.LauncherAppsCompat; 32ed13187a745866483139e2878037e1f8427ce567Kenny Guyimport com.android.launcher3.compat.UserHandleCompat; 3318bf8e2ffde3444d53aaa9654da02cdedd0b7cd1Sunny Goyalimport com.android.launcher3.compat.UserManagerCompat; 34261194387beebaa7927ec4e310274218b651494dSunny Goyalimport com.android.launcher3.folder.FolderIcon; 35bfbf7f9f4a0b300613f0ff27a4eb592d88c08325Tony Wickhamimport com.android.launcher3.shortcuts.ShortcutInfoCompat; 361e2f465f46ded990ea30516cdb7f0fcf3280411fMichael Jurka 370589f0f66ce498512c6ee47482c649d88294c9d0Joe Onorato/** 380589f0f66ce498512c6ee47482c649d88294c9d0Joe Onorato * Represents a launchable icon on the workspaces and in folders. 390589f0f66ce498512c6ee47482c649d88294c9d0Joe Onorato */ 407b168a1bb94044d9ae11004bae18beba9eed46fdAnjali Koppalpublic class ShortcutInfo extends ItemInfo { 410589f0f66ce498512c6ee47482c649d88294c9d0Joe Onorato 42349426234e8c5a0e5bcf2c8d94dbb9844b5f724aSunny Goyal public static final int DEFAULT = 0; 43aeff7ea43409d817490fbb8c22b8d4b9725bb54fChris Wren 44349426234e8c5a0e5bcf2c8d94dbb9844b5f724aSunny Goyal /** 45349426234e8c5a0e5bcf2c8d94dbb9844b5f724aSunny Goyal * The shortcut was restored from a backup and it not ready to be used. This is automatically 46349426234e8c5a0e5bcf2c8d94dbb9844b5f724aSunny Goyal * set during backup/restore 47349426234e8c5a0e5bcf2c8d94dbb9844b5f724aSunny Goyal */ 48349426234e8c5a0e5bcf2c8d94dbb9844b5f724aSunny Goyal public static final int FLAG_RESTORED_ICON = 1; 49aeff7ea43409d817490fbb8c22b8d4b9725bb54fChris Wren 50349426234e8c5a0e5bcf2c8d94dbb9844b5f724aSunny Goyal /** 51349426234e8c5a0e5bcf2c8d94dbb9844b5f724aSunny Goyal * The icon was added as an auto-install app, and is not ready to be used. This flag can't 52349426234e8c5a0e5bcf2c8d94dbb9844b5f724aSunny Goyal * be present along with {@link #FLAG_RESTORED_ICON}, and is set during default layout 53349426234e8c5a0e5bcf2c8d94dbb9844b5f724aSunny Goyal * parsing. 54349426234e8c5a0e5bcf2c8d94dbb9844b5f724aSunny Goyal */ 55bb3b02f562bef4de063099c085d3199a77d06cfdSunny Goyal public static final int FLAG_AUTOINTALL_ICON = 2; //0B10; 56aeff7ea43409d817490fbb8c22b8d4b9725bb54fChris Wren 57349426234e8c5a0e5bcf2c8d94dbb9844b5f724aSunny Goyal /** 580c2f0700a55080318a4c21457408abb8af26740dSunny Goyal * The icon is being installed. If {@link #FLAG_RESTORED_ICON} or {@link #FLAG_AUTOINTALL_ICON} 59349426234e8c5a0e5bcf2c8d94dbb9844b5f724aSunny Goyal * is set, then the icon is either being installed or is in a broken state. 60349426234e8c5a0e5bcf2c8d94dbb9844b5f724aSunny Goyal */ 61bb3b02f562bef4de063099c085d3199a77d06cfdSunny Goyal public static final int FLAG_INSTALL_SESSION_ACTIVE = 4; // 0B100; 62aeff7ea43409d817490fbb8c22b8d4b9725bb54fChris Wren 630589f0f66ce498512c6ee47482c649d88294c9d0Joe Onorato /** 649448536b113afa6ceefce26604a1b44618d1d4f2Sunny Goyal * Indicates that the widget restore has started. 659448536b113afa6ceefce26604a1b44618d1d4f2Sunny Goyal */ 66bb3b02f562bef4de063099c085d3199a77d06cfdSunny Goyal public static final int FLAG_RESTORE_STARTED = 8; //0B1000; 67bb3b02f562bef4de063099c085d3199a77d06cfdSunny Goyal 68bb3b02f562bef4de063099c085d3199a77d06cfdSunny Goyal /** 69bb3b02f562bef4de063099c085d3199a77d06cfdSunny Goyal * Indicates if it represents a common type mentioned in {@link CommonAppTypeParser}. 70bb3b02f562bef4de063099c085d3199a77d06cfdSunny Goyal * Upto 15 different types supported. 71bb3b02f562bef4de063099c085d3199a77d06cfdSunny Goyal */ 72bb3b02f562bef4de063099c085d3199a77d06cfdSunny Goyal public static final int FLAG_RESTORED_APP_TYPE = 0B0011110000; 739448536b113afa6ceefce26604a1b44618d1d4f2Sunny Goyal 749448536b113afa6ceefce26604a1b44618d1d4f2Sunny Goyal /** 750589f0f66ce498512c6ee47482c649d88294c9d0Joe Onorato * The intent used to start the application. 760589f0f66ce498512c6ee47482c649d88294c9d0Joe Onorato */ 77fedca43d396d6fd7c46fbb2f37dfa7cfe3b31834Vadim Tryshev public Intent intent; 780589f0f66ce498512c6ee47482c649d88294c9d0Joe Onorato 790589f0f66ce498512c6ee47482c649d88294c9d0Joe Onorato /** 8056d8291af6a28c6ba64113120efdf84a785e816cJoe Onorato * Indicates whether we're using the default fallback icon instead of something from the 8156d8291af6a28c6ba64113120efdf84a785e816cJoe Onorato * app. 8256d8291af6a28c6ba64113120efdf84a785e816cJoe Onorato */ 8356d8291af6a28c6ba64113120efdf84a785e816cJoe Onorato boolean usingFallbackIcon; 8456d8291af6a28c6ba64113120efdf84a785e816cJoe Onorato 8556d8291af6a28c6ba64113120efdf84a785e816cJoe Onorato /** 8634b6527cefd36fbd5da78464ce9771e379158552Sunny Goyal * Indicates whether we're using a low res icon 8734b6527cefd36fbd5da78464ce9771e379158552Sunny Goyal */ 8834b6527cefd36fbd5da78464ce9771e379158552Sunny Goyal boolean usingLowResIcon; 8934b6527cefd36fbd5da78464ce9771e379158552Sunny Goyal 9034b6527cefd36fbd5da78464ce9771e379158552Sunny Goyal /** 910589f0f66ce498512c6ee47482c649d88294c9d0Joe Onorato * If isShortcut=true and customIcon=false, this contains a reference to the 920589f0f66ce498512c6ee47482c649d88294c9d0Joe Onorato * shortcut icon as an application's resource. 930589f0f66ce498512c6ee47482c649d88294c9d0Joe Onorato */ 944e5cc64eaf1f63d866d51ce0a6bbafb3d4085c21Sunny Goyal public Intent.ShortcutIconResource iconResource; 950589f0f66ce498512c6ee47482c649d88294c9d0Joe Onorato 960589f0f66ce498512c6ee47482c649d88294c9d0Joe Onorato /** 970589f0f66ce498512c6ee47482c649d88294c9d0Joe Onorato * The application icon. 980589f0f66ce498512c6ee47482c649d88294c9d0Joe Onorato */ 990589f0f66ce498512c6ee47482c649d88294c9d0Joe Onorato private Bitmap mIcon; 1000589f0f66ce498512c6ee47482c649d88294c9d0Joe Onorato 10140c5ed303909c4df71037be3429aa1423e59585fChris Wren /** 1021a745e8f18e54aff152ff51743ae7595adde6927Sunny Goyal * Indicates that the icon is disabled due to safe mode restrictions. 1031a745e8f18e54aff152ff51743ae7595adde6927Sunny Goyal */ 1041a745e8f18e54aff152ff51743ae7595adde6927Sunny Goyal public static final int FLAG_DISABLED_SAFEMODE = 1; 1051a745e8f18e54aff152ff51743ae7595adde6927Sunny Goyal 1061a745e8f18e54aff152ff51743ae7595adde6927Sunny Goyal /** 1071a745e8f18e54aff152ff51743ae7595adde6927Sunny Goyal * Indicates that the icon is disabled as the app is not available. 1081a745e8f18e54aff152ff51743ae7595adde6927Sunny Goyal */ 1091a745e8f18e54aff152ff51743ae7595adde6927Sunny Goyal public static final int FLAG_DISABLED_NOT_AVAILABLE = 2; 1101a745e8f18e54aff152ff51743ae7595adde6927Sunny Goyal 1111a745e8f18e54aff152ff51743ae7595adde6927Sunny Goyal /** 11244cba696386b44f9115cad13ec9ecf67a0ac9119Kenny Guy * Indicates that the icon is disabled as the app is suspended 11344cba696386b44f9115cad13ec9ecf67a0ac9119Kenny Guy */ 11444cba696386b44f9115cad13ec9ecf67a0ac9119Kenny Guy public static final int FLAG_DISABLED_SUSPENDED = 4; 11544cba696386b44f9115cad13ec9ecf67a0ac9119Kenny Guy 11644cba696386b44f9115cad13ec9ecf67a0ac9119Kenny Guy /** 117ff05f4375dd47242d7e4864287e0d5af8ac8ba8fKenny Guy * Indicates that the icon is disabled as the user is in quiet mode. 118ff05f4375dd47242d7e4864287e0d5af8ac8ba8fKenny Guy */ 119ff05f4375dd47242d7e4864287e0d5af8ac8ba8fKenny Guy public static final int FLAG_DISABLED_QUIET_USER = 8; 120ff05f4375dd47242d7e4864287e0d5af8ac8ba8fKenny Guy 121ff05f4375dd47242d7e4864287e0d5af8ac8ba8fKenny Guy /** 122c5c60ad3592f53549c9ffaa58e9a87b0480080e8Sunny Goyal * Could be disabled, if the the app is installed but unavailable (eg. in safe mode or when 123c5c60ad3592f53549c9ffaa58e9a87b0480080e8Sunny Goyal * sd-card is not available). 124c5c60ad3592f53549c9ffaa58e9a87b0480080e8Sunny Goyal */ 1251a745e8f18e54aff152ff51743ae7595adde6927Sunny Goyal int isDisabled = DEFAULT; 126c5c60ad3592f53549c9ffaa58e9a87b0480080e8Sunny Goyal 127349426234e8c5a0e5bcf2c8d94dbb9844b5f724aSunny Goyal int status; 12840c5ed303909c4df71037be3429aa1423e59585fChris Wren 129e755d469d40b95e763a9dcb67d0e4f511d1948ddSunny Goyal /** 130e755d469d40b95e763a9dcb67d0e4f511d1948ddSunny Goyal * The installation progress [0-100] of the package that this shortcut represents. 131e755d469d40b95e763a9dcb67d0e4f511d1948ddSunny Goyal */ 132349426234e8c5a0e5bcf2c8d94dbb9844b5f724aSunny Goyal private int mInstallProgress; 133e755d469d40b95e763a9dcb67d0e4f511d1948ddSunny Goyal 134349426234e8c5a0e5bcf2c8d94dbb9844b5f724aSunny Goyal /** 1350c2f0700a55080318a4c21457408abb8af26740dSunny Goyal * TODO move this to {@link #status} 136b6d4c2827a1514432b5eda46ff7d484d6cf244acChris Wren */ 137349426234e8c5a0e5bcf2c8d94dbb9844b5f724aSunny Goyal int flags = 0; 138b6d4c2827a1514432b5eda46ff7d484d6cf244acChris Wren 1393484638cad97e255a412b0489a63873fb3ca4218Sunny Goyal /** 140349426234e8c5a0e5bcf2c8d94dbb9844b5f724aSunny Goyal * If this shortcut is a placeholder, then intent will be a market intent for the package, and 141349426234e8c5a0e5bcf2c8d94dbb9844b5f724aSunny Goyal * this will hold the original intent from the database. Otherwise, null. 1420c2f0700a55080318a4c21457408abb8af26740dSunny Goyal * Refer {@link #FLAG_RESTORED_ICON}, {@link #FLAG_AUTOINTALL_ICON} 1433484638cad97e255a412b0489a63873fb3ca4218Sunny Goyal */ 144349426234e8c5a0e5bcf2c8d94dbb9844b5f724aSunny Goyal Intent promisedIntent; 1453484638cad97e255a412b0489a63873fb3ca4218Sunny Goyal 146c9d95c5897fc5ebbf53903d4ab18ad13d196f643Michael Jurka ShortcutInfo() { 1470589f0f66ce498512c6ee47482c649d88294c9d0Joe Onorato itemType = LauncherSettings.BaseLauncherColumns.ITEM_TYPE_SHORTCUT; 1480589f0f66ce498512c6ee47482c649d88294c9d0Joe Onorato } 149997a92348a6d6e061737399321393449c16cd4d8Winson Chung 150a7ce166b2e06c834ac7d90ba0f4db16a84d10171Sunny Goyal @Override 151e3e646e1f05caa2b500cc3deecc3a31457c83302Anjali Koppal public Intent getIntent() { 152997a92348a6d6e061737399321393449c16cd4d8Winson Chung return intent; 153997a92348a6d6e061737399321393449c16cd4d8Winson Chung } 15472fbec17e09a1120971621587d5005f683baafd1Mathew Inwood 155d6fe52636dcaa96ec1e10ce2daebe98b820c9739Kenny Guy ShortcutInfo(Intent intent, CharSequence title, CharSequence contentDescription, 156c2bd8101b8e26b9ebb2c079ae6867229dad3f196Kenny Guy Bitmap icon, UserHandleCompat user) { 15772fbec17e09a1120971621587d5005f683baafd1Mathew Inwood this(); 15872fbec17e09a1120971621587d5005f683baafd1Mathew Inwood this.intent = intent; 15982b016cb56540fe26213e817dd0dd668099c8e20Winson Chung this.title = Utilities.trim(title); 160c2bd8101b8e26b9ebb2c079ae6867229dad3f196Kenny Guy this.contentDescription = contentDescription; 16172fbec17e09a1120971621587d5005f683baafd1Mathew Inwood mIcon = icon; 162ed13187a745866483139e2878037e1f8427ce567Kenny Guy this.user = user; 16372fbec17e09a1120971621587d5005f683baafd1Mathew Inwood } 16472fbec17e09a1120971621587d5005f683baafd1Mathew Inwood 16510923b30a22b4ec8d10cf8536bddf3f176e6c26fSunny Goyal public ShortcutInfo(ShortcutInfo info) { 166c9d95c5897fc5ebbf53903d4ab18ad13d196f643Michael Jurka super(info); 16710923b30a22b4ec8d10cf8536bddf3f176e6c26fSunny Goyal title = info.title; 1680589f0f66ce498512c6ee47482c649d88294c9d0Joe Onorato intent = new Intent(info.intent); 16910923b30a22b4ec8d10cf8536bddf3f176e6c26fSunny Goyal iconResource = info.iconResource; 1700589f0f66ce498512c6ee47482c649d88294c9d0Joe Onorato mIcon = info.mIcon; // TODO: should make a copy here. maybe we don't need this ctor at all 171ed13187a745866483139e2878037e1f8427ce567Kenny Guy flags = info.flags; 172349426234e8c5a0e5bcf2c8d94dbb9844b5f724aSunny Goyal status = info.status; 17310923b30a22b4ec8d10cf8536bddf3f176e6c26fSunny Goyal mInstallProgress = info.mInstallProgress; 17410923b30a22b4ec8d10cf8536bddf3f176e6c26fSunny Goyal isDisabled = info.isDisabled; 17510923b30a22b4ec8d10cf8536bddf3f176e6c26fSunny Goyal usingFallbackIcon = info.usingFallbackIcon; 1760589f0f66ce498512c6ee47482c649d88294c9d0Joe Onorato } 1770589f0f66ce498512c6ee47482c649d88294c9d0Joe Onorato 1780589f0f66ce498512c6ee47482c649d88294c9d0Joe Onorato /** TODO: Remove this. It's only called by ApplicationInfo.makeShortcut. */ 179eadbfc564d84aaf1d800da3d0d6edf6312f89648Michael Jurka public ShortcutInfo(AppInfo info) { 180c9d95c5897fc5ebbf53903d4ab18ad13d196f643Michael Jurka super(info); 18182b016cb56540fe26213e817dd0dd668099c8e20Winson Chung title = Utilities.trim(info.title); 1820589f0f66ce498512c6ee47482c649d88294c9d0Joe Onorato intent = new Intent(info.intent); 1831e2f465f46ded990ea30516cdb7f0fcf3280411fMichael Jurka flags = info.flags; 18444cba696386b44f9115cad13ec9ecf67a0ac9119Kenny Guy isDisabled = info.isDisabled; 1851e2f465f46ded990ea30516cdb7f0fcf3280411fMichael Jurka } 1861e2f465f46ded990ea30516cdb7f0fcf3280411fMichael Jurka 18710923b30a22b4ec8d10cf8536bddf3f176e6c26fSunny Goyal public ShortcutInfo(LauncherActivityInfoCompat info, Context context) { 18810923b30a22b4ec8d10cf8536bddf3f176e6c26fSunny Goyal user = info.getUser(); 18910923b30a22b4ec8d10cf8536bddf3f176e6c26fSunny Goyal title = Utilities.trim(info.getLabel()); 19010923b30a22b4ec8d10cf8536bddf3f176e6c26fSunny Goyal contentDescription = UserManagerCompat.getInstance(context) 19110923b30a22b4ec8d10cf8536bddf3f176e6c26fSunny Goyal .getBadgedLabelForUser(info.getLabel(), info.getUser()); 19210923b30a22b4ec8d10cf8536bddf3f176e6c26fSunny Goyal intent = AppInfo.makeLaunchIntent(context, info, info.getUser()); 19310923b30a22b4ec8d10cf8536bddf3f176e6c26fSunny Goyal itemType = LauncherSettings.Favorites.ITEM_TYPE_APPLICATION; 19410923b30a22b4ec8d10cf8536bddf3f176e6c26fSunny Goyal flags = AppInfo.initFlags(info); 19510923b30a22b4ec8d10cf8536bddf3f176e6c26fSunny Goyal } 19610923b30a22b4ec8d10cf8536bddf3f176e6c26fSunny Goyal 19710923b30a22b4ec8d10cf8536bddf3f176e6c26fSunny Goyal /** 19810923b30a22b4ec8d10cf8536bddf3f176e6c26fSunny Goyal * Creates a {@link ShortcutInfo} from a {@link ShortcutInfoCompat}. 19910923b30a22b4ec8d10cf8536bddf3f176e6c26fSunny Goyal */ 20010923b30a22b4ec8d10cf8536bddf3f176e6c26fSunny Goyal @TargetApi(Build.VERSION_CODES.N) 20110923b30a22b4ec8d10cf8536bddf3f176e6c26fSunny Goyal public ShortcutInfo(ShortcutInfoCompat shortcutInfo, Context context) { 20210923b30a22b4ec8d10cf8536bddf3f176e6c26fSunny Goyal user = shortcutInfo.getUserHandle(); 20310923b30a22b4ec8d10cf8536bddf3f176e6c26fSunny Goyal itemType = LauncherSettings.Favorites.ITEM_TYPE_DEEP_SHORTCUT; 20410923b30a22b4ec8d10cf8536bddf3f176e6c26fSunny Goyal intent = shortcutInfo.makeIntent(context); 20510923b30a22b4ec8d10cf8536bddf3f176e6c26fSunny Goyal flags = 0; 20610923b30a22b4ec8d10cf8536bddf3f176e6c26fSunny Goyal updateFromDeepShortcutInfo(shortcutInfo, context); 20710923b30a22b4ec8d10cf8536bddf3f176e6c26fSunny Goyal } 20810923b30a22b4ec8d10cf8536bddf3f176e6c26fSunny Goyal 2090589f0f66ce498512c6ee47482c649d88294c9d0Joe Onorato public void setIcon(Bitmap b) { 2100589f0f66ce498512c6ee47482c649d88294c9d0Joe Onorato mIcon = b; 2110589f0f66ce498512c6ee47482c649d88294c9d0Joe Onorato } 2120589f0f66ce498512c6ee47482c649d88294c9d0Joe Onorato 2130589f0f66ce498512c6ee47482c649d88294c9d0Joe Onorato public Bitmap getIcon(IconCache iconCache) { 2140589f0f66ce498512c6ee47482c649d88294c9d0Joe Onorato if (mIcon == null) { 215e384affda684a48c61d99ebfe8be40fb7d46d761Michael Jurka updateIcon(iconCache); 2160589f0f66ce498512c6ee47482c649d88294c9d0Joe Onorato } 2170589f0f66ce498512c6ee47482c649d88294c9d0Joe Onorato return mIcon; 2180589f0f66ce498512c6ee47482c649d88294c9d0Joe Onorato } 2190589f0f66ce498512c6ee47482c649d88294c9d0Joe Onorato 220317698bd012c1930b83bb4e2e47ac9e363fa6c6aSunny Goyal public void updateIcon(IconCache iconCache, boolean useLowRes) { 2214fbc3828c5ae1e8c5789ede974447fa365f3c5a1Sunny Goyal if (itemType == Favorites.ITEM_TYPE_APPLICATION) { 22234b6527cefd36fbd5da78464ce9771e379158552Sunny Goyal iconCache.getTitleAndIcon(this, promisedIntent != null ? promisedIntent : intent, user, 223317698bd012c1930b83bb4e2e47ac9e363fa6c6aSunny Goyal useLowRes); 2244fbc3828c5ae1e8c5789ede974447fa365f3c5a1Sunny Goyal } 2250589f0f66ce498512c6ee47482c649d88294c9d0Joe Onorato } 2260589f0f66ce498512c6ee47482c649d88294c9d0Joe Onorato 227317698bd012c1930b83bb4e2e47ac9e363fa6c6aSunny Goyal public void updateIcon(IconCache iconCache) { 228317698bd012c1930b83bb4e2e47ac9e363fa6c6aSunny Goyal updateIcon(iconCache, shouldUseLowResIcon()); 229317698bd012c1930b83bb4e2e47ac9e363fa6c6aSunny Goyal } 230317698bd012c1930b83bb4e2e47ac9e363fa6c6aSunny Goyal 2310589f0f66ce498512c6ee47482c649d88294c9d0Joe Onorato @Override 232ed13187a745866483139e2878037e1f8427ce567Kenny Guy void onAddToDatabase(Context context, ContentValues values) { 233ed13187a745866483139e2878037e1f8427ce567Kenny Guy super.onAddToDatabase(context, values); 2340589f0f66ce498512c6ee47482c649d88294c9d0Joe Onorato 2350589f0f66ce498512c6ee47482c649d88294c9d0Joe Onorato String titleStr = title != null ? title.toString() : null; 2360589f0f66ce498512c6ee47482c649d88294c9d0Joe Onorato values.put(LauncherSettings.BaseLauncherColumns.TITLE, titleStr); 2370589f0f66ce498512c6ee47482c649d88294c9d0Joe Onorato 238349426234e8c5a0e5bcf2c8d94dbb9844b5f724aSunny Goyal String uri = promisedIntent != null ? promisedIntent.toUri(0) 2399623a9951acd3e2e7ceb4c8551e3bff4b35001ddSunny Goyal : (intent != null ? intent.toUri(0) : null); 2400589f0f66ce498512c6ee47482c649d88294c9d0Joe Onorato values.put(LauncherSettings.BaseLauncherColumns.INTENT, uri); 241756adbc3e41ee1edb53c580b8c679f343924fab5Sunny Goyal values.put(LauncherSettings.Favorites.RESTORED, status); 2420589f0f66ce498512c6ee47482c649d88294c9d0Joe Onorato 243eb4b79935e9f75dda72e4953f45e616e252d7b03Sunny Goyal if (!usingFallbackIcon && !usingLowResIcon) { 24456d8291af6a28c6ba64113120efdf84a785e816cJoe Onorato writeBitmap(values, mIcon); 245eb4b79935e9f75dda72e4953f45e616e252d7b03Sunny Goyal } 246eb4b79935e9f75dda72e4953f45e616e252d7b03Sunny Goyal if (iconResource != null) { 247eb4b79935e9f75dda72e4953f45e616e252d7b03Sunny Goyal values.put(LauncherSettings.BaseLauncherColumns.ICON_PACKAGE, 248eb4b79935e9f75dda72e4953f45e616e252d7b03Sunny Goyal iconResource.packageName); 249eb4b79935e9f75dda72e4953f45e616e252d7b03Sunny Goyal values.put(LauncherSettings.BaseLauncherColumns.ICON_RESOURCE, 250eb4b79935e9f75dda72e4953f45e616e252d7b03Sunny Goyal iconResource.resourceName); 2510589f0f66ce498512c6ee47482c649d88294c9d0Joe Onorato } 2520589f0f66ce498512c6ee47482c649d88294c9d0Joe Onorato } 2530589f0f66ce498512c6ee47482c649d88294c9d0Joe Onorato 2540589f0f66ce498512c6ee47482c649d88294c9d0Joe Onorato @Override 2550589f0f66ce498512c6ee47482c649d88294c9d0Joe Onorato public String toString() { 256ed13187a745866483139e2878037e1f8427ce567Kenny Guy return "ShortcutInfo(title=" + title + "intent=" + intent + "id=" + this.id 257dcd297f05a866e07090d6e2af8fb4b15f28cb555Adam Cohen + " type=" + this.itemType + " container=" + this.container + " screen=" + screenId 258db8a8944ede3be4ee63b43e24c407a3aaabee4deWinson Chung + " cellX=" + cellX + " cellY=" + cellY + " spanX=" + spanX + " spanY=" + spanY 259aa8ef119f18864f4ab41c12f9c2ad6d7f643a0a9Sunny Goyal + " user=" + user + ")"; 2600589f0f66ce498512c6ee47482c649d88294c9d0Joe Onorato } 2610589f0f66ce498512c6ee47482c649d88294c9d0Joe Onorato 262349426234e8c5a0e5bcf2c8d94dbb9844b5f724aSunny Goyal public ComponentName getTargetComponent() { 263349426234e8c5a0e5bcf2c8d94dbb9844b5f724aSunny Goyal return promisedIntent != null ? promisedIntent.getComponent() : intent.getComponent(); 264aeff7ea43409d817490fbb8c22b8d4b9725bb54fChris Wren } 265aeff7ea43409d817490fbb8c22b8d4b9725bb54fChris Wren 266349426234e8c5a0e5bcf2c8d94dbb9844b5f724aSunny Goyal public boolean hasStatusFlag(int flag) { 267349426234e8c5a0e5bcf2c8d94dbb9844b5f724aSunny Goyal return (status & flag) != 0; 268aeff7ea43409d817490fbb8c22b8d4b9725bb54fChris Wren } 26940c5ed303909c4df71037be3429aa1423e59585fChris Wren 270e755d469d40b95e763a9dcb67d0e4f511d1948ddSunny Goyal 271349426234e8c5a0e5bcf2c8d94dbb9844b5f724aSunny Goyal public final boolean isPromise() { 272349426234e8c5a0e5bcf2c8d94dbb9844b5f724aSunny Goyal return hasStatusFlag(FLAG_RESTORED_ICON | FLAG_AUTOINTALL_ICON); 27340c5ed303909c4df71037be3429aa1423e59585fChris Wren } 27440c5ed303909c4df71037be3429aa1423e59585fChris Wren 275349426234e8c5a0e5bcf2c8d94dbb9844b5f724aSunny Goyal public int getInstallProgress() { 276349426234e8c5a0e5bcf2c8d94dbb9844b5f724aSunny Goyal return mInstallProgress; 27740c5ed303909c4df71037be3429aa1423e59585fChris Wren } 278e755d469d40b95e763a9dcb67d0e4f511d1948ddSunny Goyal 279349426234e8c5a0e5bcf2c8d94dbb9844b5f724aSunny Goyal public void setInstallProgress(int progress) { 280349426234e8c5a0e5bcf2c8d94dbb9844b5f724aSunny Goyal mInstallProgress = progress; 281349426234e8c5a0e5bcf2c8d94dbb9844b5f724aSunny Goyal status |= FLAG_INSTALL_SESSION_ACTIVE; 282e755d469d40b95e763a9dcb67d0e4f511d1948ddSunny Goyal } 28334b6527cefd36fbd5da78464ce9771e379158552Sunny Goyal 28434b6527cefd36fbd5da78464ce9771e379158552Sunny Goyal public boolean shouldUseLowResIcon() { 28534b6527cefd36fbd5da78464ce9771e379158552Sunny Goyal return usingLowResIcon && container >= 0 && rank >= FolderIcon.NUM_ITEMS_IN_PREVIEW; 28634b6527cefd36fbd5da78464ce9771e379158552Sunny Goyal } 28718bf8e2ffde3444d53aaa9654da02cdedd0b7cd1Sunny Goyal 2889994b2b171ab78d1d93e8a25086d6853f766e80fSunny Goyal public void updateFromDeepShortcutInfo(ShortcutInfoCompat shortcutInfo, Context context) { 289bfbf7f9f4a0b300613f0ff27a4eb592d88c08325Tony Wickham title = shortcutInfo.getShortLabel(); 290bfbf7f9f4a0b300613f0ff27a4eb592d88c08325Tony Wickham 291bfbf7f9f4a0b300613f0ff27a4eb592d88c08325Tony Wickham CharSequence label = shortcutInfo.getLongLabel(); 292bfbf7f9f4a0b300613f0ff27a4eb592d88c08325Tony Wickham if (TextUtils.isEmpty(label)) { 293bfbf7f9f4a0b300613f0ff27a4eb592d88c08325Tony Wickham label = shortcutInfo.getShortLabel(); 294bfbf7f9f4a0b300613f0ff27a4eb592d88c08325Tony Wickham } 295b93f34a8be4450d2b6cb47a73f43c84c194bdb95Winson contentDescription = UserManagerCompat.getInstance(context) 296bfbf7f9f4a0b300613f0ff27a4eb592d88c08325Tony Wickham .getBadgedLabelForUser(label, user); 297bfbf7f9f4a0b300613f0ff27a4eb592d88c08325Tony Wickham 298bfbf7f9f4a0b300613f0ff27a4eb592d88c08325Tony Wickham LauncherAppState launcherAppState = LauncherAppState.getInstance(); 2999994b2b171ab78d1d93e8a25086d6853f766e80fSunny Goyal Drawable unbadgedIcon = launcherAppState.getShortcutManager() 3009994b2b171ab78d1d93e8a25086d6853f766e80fSunny Goyal .getShortcutIconDrawable(shortcutInfo, 3019994b2b171ab78d1d93e8a25086d6853f766e80fSunny Goyal launcherAppState.getInvariantDeviceProfile().fillResIconDpi); 30210923b30a22b4ec8d10cf8536bddf3f176e6c26fSunny Goyal Bitmap icon = unbadgedIcon == null ? null : getBadgedIcon(unbadgedIcon, context); 303bfbf7f9f4a0b300613f0ff27a4eb592d88c08325Tony Wickham setIcon(icon != null ? icon : launcherAppState.getIconCache().getDefaultIcon(user)); 304bfbf7f9f4a0b300613f0ff27a4eb592d88c08325Tony Wickham } 305bfbf7f9f4a0b300613f0ff27a4eb592d88c08325Tony Wickham 30610923b30a22b4ec8d10cf8536bddf3f176e6c26fSunny Goyal protected Bitmap getBadgedIcon(Drawable unbadgedIcon, Context context) { 30710923b30a22b4ec8d10cf8536bddf3f176e6c26fSunny Goyal return Utilities.createBadgedIconBitmapWithShadow(unbadgedIcon, user, context); 30810923b30a22b4ec8d10cf8536bddf3f176e6c26fSunny Goyal } 30910923b30a22b4ec8d10cf8536bddf3f176e6c26fSunny Goyal 310bfbf7f9f4a0b300613f0ff27a4eb592d88c08325Tony Wickham /** Returns the ShortcutInfo id associated with the deep shortcut. */ 311bfbf7f9f4a0b300613f0ff27a4eb592d88c08325Tony Wickham public String getDeepShortcutId() { 312bfbf7f9f4a0b300613f0ff27a4eb592d88c08325Tony Wickham return itemType == Favorites.ITEM_TYPE_DEEP_SHORTCUT ? 313bfbf7f9f4a0b300613f0ff27a4eb592d88c08325Tony Wickham intent.getStringExtra(ShortcutInfoCompat.EXTRA_SHORTCUT_ID) : null; 314bfbf7f9f4a0b300613f0ff27a4eb592d88c08325Tony Wickham } 315bfbf7f9f4a0b300613f0ff27a4eb592d88c08325Tony Wickham 31644cba696386b44f9115cad13ec9ecf67a0ac9119Kenny Guy @Override 31744cba696386b44f9115cad13ec9ecf67a0ac9119Kenny Guy public boolean isDisabled() { 31844cba696386b44f9115cad13ec9ecf67a0ac9119Kenny Guy return isDisabled != 0; 31944cba696386b44f9115cad13ec9ecf67a0ac9119Kenny Guy } 3200589f0f66ce498512c6ee47482c649d88294c9d0Joe Onorato} 321