Loading src/com/android/launcher3/LauncherModel.java +10 −0 Original line number Diff line number Diff line Loading @@ -732,6 +732,16 @@ public class LauncherModel extends BroadcastReceiver if (DEBUG_LOADERS) Log.d(TAG, "step 3.2: bind deep shortcuts"); bindDeepShortcuts(); // Take a break if (DEBUG_LOADERS) Log.d(TAG, "step 3 completed, wait for idle"); waitForIdle(); verifyNotStopped(); // fourth step if (DEBUG_LOADERS) Log.d(TAG, "step 4.1: loading widgets"); refreshAndBindWidgetsAndShortcuts(getCallback(), false /* bindFirst */, null /* packageUser */); synchronized (mLock) { // Everything loaded bind the data. mModelLoaded = true; Loading src/com/android/launcher3/model/PackageUpdatedTask.java +9 −0 Original line number Diff line number Diff line Loading @@ -44,6 +44,7 @@ import com.android.launcher3.graphics.LauncherIcons; import com.android.launcher3.util.FlagOp; import com.android.launcher3.util.ItemInfoMatcher; import com.android.launcher3.util.ManagedProfileHeuristic; import com.android.launcher3.util.PackageUserKey; import java.util.ArrayList; import java.util.Arrays; Loading Loading @@ -370,6 +371,14 @@ public class PackageUpdatedTask extends ExtendedModelTask { callbacks.notifyWidgetProvidersChanged(); } }); } else if (Utilities.isAtLeastO() && mOp == OP_ADD) { // Load widgets for the new package. for (int i = 0; i < N; i++) { LauncherModel model = app.getModel(); model.refreshAndBindWidgetsAndShortcuts( model.getCallback(), false /* bindFirst */, new PackageUserKey(packages[i], mUser) /* packageUser */); } } } } src/com/android/launcher3/popup/PopupContainerWithArrow.java +12 −12 Original line number Diff line number Diff line Loading @@ -146,21 +146,24 @@ public class PopupContainerWithArrow extends AbstractFloatingView implements Dra return null; } List<String> shortcutIds = launcher.getPopupDataProvider().getShortcutIdsForItem(itemInfo); List<NotificationKeyData> notificationKeys = launcher.getPopupDataProvider() PopupDataProvider popupDataProvider = launcher.getPopupDataProvider(); List<String> shortcutIds = popupDataProvider.getShortcutIdsForItem(itemInfo); List<NotificationKeyData> notificationKeys = popupDataProvider .getNotificationKeysForItem(itemInfo); List<SystemShortcut> systemShortcuts = popupDataProvider .getEnabledSystemShortcutsForItem(itemInfo); final PopupContainerWithArrow container = (PopupContainerWithArrow) launcher.getLayoutInflater().inflate( R.layout.popup_container, launcher.getDragLayer(), false); container.setVisibility(View.INVISIBLE); launcher.getDragLayer().addView(container); container.populateAndShow(icon, shortcutIds, notificationKeys); container.populateAndShow(icon, shortcutIds, notificationKeys, systemShortcuts); return container; } public void populateAndShow(final BubbleTextView originalIcon, final List<String> shortcutIds, final List<NotificationKeyData> notificationKeys) { final List<NotificationKeyData> notificationKeys, List<SystemShortcut> systemShortcuts) { final Resources resources = getResources(); final int arrowWidth = resources.getDimensionPixelSize(R.dimen.popup_arrow_width); final int arrowHeight = resources.getDimensionPixelSize(R.dimen.popup_arrow_height); Loading @@ -171,7 +174,7 @@ public class PopupContainerWithArrow extends AbstractFloatingView implements Dra // Add dummy views first, and populate with real info when ready. PopupPopulator.Item[] itemsToPopulate = PopupPopulator .getItemsToPopulate(shortcutIds, notificationKeys); .getItemsToPopulate(shortcutIds, notificationKeys, systemShortcuts); addDummyViews(originalIcon, itemsToPopulate, notificationKeys.size() > 1); measure(MeasureSpec.UNSPECIFIED, MeasureSpec.UNSPECIFIED); Loading Loading @@ -218,7 +221,7 @@ public class PopupContainerWithArrow extends AbstractFloatingView implements Dra new Handler(workerLooper).postAtFrontOfQueue(PopupPopulator.createUpdateRunnable( mLauncher, originalItemInfo, new Handler(Looper.getMainLooper()), this, shortcutIds, shortcutViews, notificationKeys, mNotificationItemView, systemShortcutViews)); systemShortcuts, systemShortcutViews)); } private void addDummyViews(BubbleTextView originalIcon, Loading Loading @@ -624,12 +627,9 @@ public class PopupContainerWithArrow extends AbstractFloatingView implements Dra @Override protected void onWidgetsBound() { enableWidgets(); if (mShortcutsItemView != null) { mShortcutsItemView.enableWidgetsIfExist(mOriginalIcon); } public boolean enableWidgets() { return mShortcutsItemView != null && mShortcutsItemView.enableWidgets( (ItemInfo) mOriginalIcon.getTag()); } private ObjectAnimator createArrowScaleAnim(float scale) { Loading src/com/android/launcher3/popup/PopupDataProvider.java +12 −1 Original line number Diff line number Diff line Loading @@ -33,6 +33,7 @@ import com.android.launcher3.util.ComponentKey; import com.android.launcher3.util.MultiHashMap; import com.android.launcher3.util.PackageUserKey; import java.util.ArrayList; import java.util.Collections; import java.util.HashMap; import java.util.Iterator; Loading @@ -49,7 +50,7 @@ public class PopupDataProvider implements NotificationListener.NotificationsChan private static final String TAG = "PopupDataProvider"; /** Note that these are in order of priority. */ public static final SystemShortcut[] SYSTEM_SHORTCUTS = new SystemShortcut[] { private static final SystemShortcut[] SYSTEM_SHORTCUTS = new SystemShortcut[] { new SystemShortcut.AppInfo(), new SystemShortcut.Widgets(), }; Loading Loading @@ -240,6 +241,16 @@ public class PopupDataProvider implements NotificationListener.NotificationsChan : notificationListener.getNotificationsForKeys(notificationKeys); } public @NonNull List<SystemShortcut> getEnabledSystemShortcutsForItem(ItemInfo info) { List<SystemShortcut> systemShortcuts = new ArrayList<>(); for (SystemShortcut systemShortcut : SYSTEM_SHORTCUTS) { if (systemShortcut.getOnClickListener(mLauncher, info) != null) { systemShortcuts.add(systemShortcut); } } return systemShortcuts; } public void cancelNotification(String notificationKey) { NotificationListener notificationListener = NotificationListener.getInstanceIfConnected(); if (notificationListener == null) { Loading src/com/android/launcher3/popup/PopupPopulator.java +28 −32 Original line number Diff line number Diff line Loading @@ -72,7 +72,8 @@ public class PopupPopulator { } public static @NonNull Item[] getItemsToPopulate(@NonNull List<String> shortcutIds, @NonNull List<NotificationKeyData> notificationKeys) { @NonNull List<NotificationKeyData> notificationKeys, @NonNull List<SystemShortcut> systemShortcuts) { boolean hasNotifications = notificationKeys.size() > 0; int numNotificationItems = hasNotifications ? 1 : 0; int numShortcuts = shortcutIds.size(); Loading @@ -80,7 +81,7 @@ public class PopupPopulator { numShortcuts = MAX_SHORTCUTS_IF_NOTIFICATIONS; } int numItems = Math.min(MAX_ITEMS, numShortcuts + numNotificationItems) + PopupDataProvider.SYSTEM_SHORTCUTS.length; + systemShortcuts.size(); Item[] items = new Item[numItems]; for (int i = 0; i < numItems; i++) { items[i] = Item.SHORTCUT; Loading @@ -91,7 +92,7 @@ public class PopupPopulator { } // The system shortcuts are always last. boolean iconsOnly = !shortcutIds.isEmpty(); for (int i = 0; i < PopupDataProvider.SYSTEM_SHORTCUTS.length; i++) { for (int i = 0; i < systemShortcuts.size(); i++) { items[numItems - 1 - i] = iconsOnly ? Item.SYSTEM_SHORTCUT_ICON : Item.SYSTEM_SHORTCUT; } return items; Loading Loading @@ -182,7 +183,8 @@ public class PopupPopulator { final Handler uiHandler, final PopupContainerWithArrow container, final List<String> shortcutIds, final List<DeepShortcutView> shortcutViews, final List<NotificationKeyData> notificationKeys, final NotificationItemView notificationView, final List<View> systemShortcutViews) { final NotificationItemView notificationView, final List<SystemShortcut> systemShortcuts, final List<View> systemShortcutViews) { final ComponentName activity = originalInfo.getTargetComponent(); final UserHandle user = originalInfo.user; return new Runnable() { Loading Loading @@ -217,8 +219,8 @@ public class PopupPopulator { // This ensures that mLauncher.getWidgetsForPackageUser() // doesn't return null (it puts all the widgets in memory). for (int i = 0; i < PopupDataProvider.SYSTEM_SHORTCUTS.length; i++) { final SystemShortcut systemShortcut = PopupDataProvider.SYSTEM_SHORTCUTS[i]; for (int i = 0; i < systemShortcuts.size(); i++) { final SystemShortcut systemShortcut = systemShortcuts.get(i); uiHandler.post(new UpdateSystemShortcutChild(container, systemShortcutViews.get(i), systemShortcut, launcher, originalInfo)); } Loading Loading @@ -274,7 +276,6 @@ public class PopupPopulator { /** Updates the system shortcut child based on the given shortcut info. */ private static class UpdateSystemShortcutChild implements Runnable { private static final float DISABLED_ALPHA = 0.38f; private final PopupContainerWithArrow mContainer; private final View mSystemShortcutChild; Loading @@ -294,31 +295,26 @@ public class PopupPopulator { @Override public void run() { final Context context = mSystemShortcutChild.getContext(); if (mSystemShortcutChild instanceof DeepShortcutView) { // Expanded system shortcut, with both icon and text shown on white background. final DeepShortcutView shortcutView = (DeepShortcutView) mSystemShortcutChild; shortcutView.getIconView().setBackground(mSystemShortcutInfo.getIcon(context, android.R.attr.textColorTertiary)); shortcutView.getBubbleText().setText(mSystemShortcutInfo.getLabel(context)); } else if (mSystemShortcutChild instanceof ImageView) { // Only the system shortcut icon shows on a gray background header. final ImageView shortcutIcon = (ImageView) mSystemShortcutChild; shortcutIcon.setImageDrawable(mSystemShortcutInfo.getIcon(context, android.R.attr.textColorHint)); shortcutIcon.setContentDescription(mSystemShortcutInfo.getLabel(context)); } if (!(mSystemShortcutInfo instanceof SystemShortcut.Widgets)) { initializeSystemShortcut(context, mSystemShortcutChild, mSystemShortcutInfo); mSystemShortcutChild.setOnClickListener(mSystemShortcutInfo .getOnClickListener(mLauncher, mItemInfo)); } else { mSystemShortcutChild.setTag(mSystemShortcutInfo); // Widgets might not be enabled right away. if (mContainer.enableWidgets()) { return; } // Disable Widgets (we might be able to re-enable when widgets are bound). mSystemShortcutChild.setAlpha(DISABLED_ALPHA); } public static void initializeSystemShortcut(Context context, View view, SystemShortcut info) { if (view instanceof DeepShortcutView) { // Expanded system shortcut, with both icon and text shown on white background. final DeepShortcutView shortcutView = (DeepShortcutView) view; shortcutView.getIconView().setBackground(info.getIcon(context, android.R.attr.textColorTertiary)); shortcutView.getBubbleText().setText(info.getLabel(context)); } else if (view instanceof ImageView) { // Only the system shortcut icon shows on a gray background header. final ImageView shortcutIcon = (ImageView) view; shortcutIcon.setImageDrawable(info.getIcon(context, android.R.attr.textColorHint)); shortcutIcon.setContentDescription(info.getLabel(context)); } view.setTag(info); } } Loading
src/com/android/launcher3/LauncherModel.java +10 −0 Original line number Diff line number Diff line Loading @@ -732,6 +732,16 @@ public class LauncherModel extends BroadcastReceiver if (DEBUG_LOADERS) Log.d(TAG, "step 3.2: bind deep shortcuts"); bindDeepShortcuts(); // Take a break if (DEBUG_LOADERS) Log.d(TAG, "step 3 completed, wait for idle"); waitForIdle(); verifyNotStopped(); // fourth step if (DEBUG_LOADERS) Log.d(TAG, "step 4.1: loading widgets"); refreshAndBindWidgetsAndShortcuts(getCallback(), false /* bindFirst */, null /* packageUser */); synchronized (mLock) { // Everything loaded bind the data. mModelLoaded = true; Loading
src/com/android/launcher3/model/PackageUpdatedTask.java +9 −0 Original line number Diff line number Diff line Loading @@ -44,6 +44,7 @@ import com.android.launcher3.graphics.LauncherIcons; import com.android.launcher3.util.FlagOp; import com.android.launcher3.util.ItemInfoMatcher; import com.android.launcher3.util.ManagedProfileHeuristic; import com.android.launcher3.util.PackageUserKey; import java.util.ArrayList; import java.util.Arrays; Loading Loading @@ -370,6 +371,14 @@ public class PackageUpdatedTask extends ExtendedModelTask { callbacks.notifyWidgetProvidersChanged(); } }); } else if (Utilities.isAtLeastO() && mOp == OP_ADD) { // Load widgets for the new package. for (int i = 0; i < N; i++) { LauncherModel model = app.getModel(); model.refreshAndBindWidgetsAndShortcuts( model.getCallback(), false /* bindFirst */, new PackageUserKey(packages[i], mUser) /* packageUser */); } } } }
src/com/android/launcher3/popup/PopupContainerWithArrow.java +12 −12 Original line number Diff line number Diff line Loading @@ -146,21 +146,24 @@ public class PopupContainerWithArrow extends AbstractFloatingView implements Dra return null; } List<String> shortcutIds = launcher.getPopupDataProvider().getShortcutIdsForItem(itemInfo); List<NotificationKeyData> notificationKeys = launcher.getPopupDataProvider() PopupDataProvider popupDataProvider = launcher.getPopupDataProvider(); List<String> shortcutIds = popupDataProvider.getShortcutIdsForItem(itemInfo); List<NotificationKeyData> notificationKeys = popupDataProvider .getNotificationKeysForItem(itemInfo); List<SystemShortcut> systemShortcuts = popupDataProvider .getEnabledSystemShortcutsForItem(itemInfo); final PopupContainerWithArrow container = (PopupContainerWithArrow) launcher.getLayoutInflater().inflate( R.layout.popup_container, launcher.getDragLayer(), false); container.setVisibility(View.INVISIBLE); launcher.getDragLayer().addView(container); container.populateAndShow(icon, shortcutIds, notificationKeys); container.populateAndShow(icon, shortcutIds, notificationKeys, systemShortcuts); return container; } public void populateAndShow(final BubbleTextView originalIcon, final List<String> shortcutIds, final List<NotificationKeyData> notificationKeys) { final List<NotificationKeyData> notificationKeys, List<SystemShortcut> systemShortcuts) { final Resources resources = getResources(); final int arrowWidth = resources.getDimensionPixelSize(R.dimen.popup_arrow_width); final int arrowHeight = resources.getDimensionPixelSize(R.dimen.popup_arrow_height); Loading @@ -171,7 +174,7 @@ public class PopupContainerWithArrow extends AbstractFloatingView implements Dra // Add dummy views first, and populate with real info when ready. PopupPopulator.Item[] itemsToPopulate = PopupPopulator .getItemsToPopulate(shortcutIds, notificationKeys); .getItemsToPopulate(shortcutIds, notificationKeys, systemShortcuts); addDummyViews(originalIcon, itemsToPopulate, notificationKeys.size() > 1); measure(MeasureSpec.UNSPECIFIED, MeasureSpec.UNSPECIFIED); Loading Loading @@ -218,7 +221,7 @@ public class PopupContainerWithArrow extends AbstractFloatingView implements Dra new Handler(workerLooper).postAtFrontOfQueue(PopupPopulator.createUpdateRunnable( mLauncher, originalItemInfo, new Handler(Looper.getMainLooper()), this, shortcutIds, shortcutViews, notificationKeys, mNotificationItemView, systemShortcutViews)); systemShortcuts, systemShortcutViews)); } private void addDummyViews(BubbleTextView originalIcon, Loading Loading @@ -624,12 +627,9 @@ public class PopupContainerWithArrow extends AbstractFloatingView implements Dra @Override protected void onWidgetsBound() { enableWidgets(); if (mShortcutsItemView != null) { mShortcutsItemView.enableWidgetsIfExist(mOriginalIcon); } public boolean enableWidgets() { return mShortcutsItemView != null && mShortcutsItemView.enableWidgets( (ItemInfo) mOriginalIcon.getTag()); } private ObjectAnimator createArrowScaleAnim(float scale) { Loading
src/com/android/launcher3/popup/PopupDataProvider.java +12 −1 Original line number Diff line number Diff line Loading @@ -33,6 +33,7 @@ import com.android.launcher3.util.ComponentKey; import com.android.launcher3.util.MultiHashMap; import com.android.launcher3.util.PackageUserKey; import java.util.ArrayList; import java.util.Collections; import java.util.HashMap; import java.util.Iterator; Loading @@ -49,7 +50,7 @@ public class PopupDataProvider implements NotificationListener.NotificationsChan private static final String TAG = "PopupDataProvider"; /** Note that these are in order of priority. */ public static final SystemShortcut[] SYSTEM_SHORTCUTS = new SystemShortcut[] { private static final SystemShortcut[] SYSTEM_SHORTCUTS = new SystemShortcut[] { new SystemShortcut.AppInfo(), new SystemShortcut.Widgets(), }; Loading Loading @@ -240,6 +241,16 @@ public class PopupDataProvider implements NotificationListener.NotificationsChan : notificationListener.getNotificationsForKeys(notificationKeys); } public @NonNull List<SystemShortcut> getEnabledSystemShortcutsForItem(ItemInfo info) { List<SystemShortcut> systemShortcuts = new ArrayList<>(); for (SystemShortcut systemShortcut : SYSTEM_SHORTCUTS) { if (systemShortcut.getOnClickListener(mLauncher, info) != null) { systemShortcuts.add(systemShortcut); } } return systemShortcuts; } public void cancelNotification(String notificationKey) { NotificationListener notificationListener = NotificationListener.getInstanceIfConnected(); if (notificationListener == null) { Loading
src/com/android/launcher3/popup/PopupPopulator.java +28 −32 Original line number Diff line number Diff line Loading @@ -72,7 +72,8 @@ public class PopupPopulator { } public static @NonNull Item[] getItemsToPopulate(@NonNull List<String> shortcutIds, @NonNull List<NotificationKeyData> notificationKeys) { @NonNull List<NotificationKeyData> notificationKeys, @NonNull List<SystemShortcut> systemShortcuts) { boolean hasNotifications = notificationKeys.size() > 0; int numNotificationItems = hasNotifications ? 1 : 0; int numShortcuts = shortcutIds.size(); Loading @@ -80,7 +81,7 @@ public class PopupPopulator { numShortcuts = MAX_SHORTCUTS_IF_NOTIFICATIONS; } int numItems = Math.min(MAX_ITEMS, numShortcuts + numNotificationItems) + PopupDataProvider.SYSTEM_SHORTCUTS.length; + systemShortcuts.size(); Item[] items = new Item[numItems]; for (int i = 0; i < numItems; i++) { items[i] = Item.SHORTCUT; Loading @@ -91,7 +92,7 @@ public class PopupPopulator { } // The system shortcuts are always last. boolean iconsOnly = !shortcutIds.isEmpty(); for (int i = 0; i < PopupDataProvider.SYSTEM_SHORTCUTS.length; i++) { for (int i = 0; i < systemShortcuts.size(); i++) { items[numItems - 1 - i] = iconsOnly ? Item.SYSTEM_SHORTCUT_ICON : Item.SYSTEM_SHORTCUT; } return items; Loading Loading @@ -182,7 +183,8 @@ public class PopupPopulator { final Handler uiHandler, final PopupContainerWithArrow container, final List<String> shortcutIds, final List<DeepShortcutView> shortcutViews, final List<NotificationKeyData> notificationKeys, final NotificationItemView notificationView, final List<View> systemShortcutViews) { final NotificationItemView notificationView, final List<SystemShortcut> systemShortcuts, final List<View> systemShortcutViews) { final ComponentName activity = originalInfo.getTargetComponent(); final UserHandle user = originalInfo.user; return new Runnable() { Loading Loading @@ -217,8 +219,8 @@ public class PopupPopulator { // This ensures that mLauncher.getWidgetsForPackageUser() // doesn't return null (it puts all the widgets in memory). for (int i = 0; i < PopupDataProvider.SYSTEM_SHORTCUTS.length; i++) { final SystemShortcut systemShortcut = PopupDataProvider.SYSTEM_SHORTCUTS[i]; for (int i = 0; i < systemShortcuts.size(); i++) { final SystemShortcut systemShortcut = systemShortcuts.get(i); uiHandler.post(new UpdateSystemShortcutChild(container, systemShortcutViews.get(i), systemShortcut, launcher, originalInfo)); } Loading Loading @@ -274,7 +276,6 @@ public class PopupPopulator { /** Updates the system shortcut child based on the given shortcut info. */ private static class UpdateSystemShortcutChild implements Runnable { private static final float DISABLED_ALPHA = 0.38f; private final PopupContainerWithArrow mContainer; private final View mSystemShortcutChild; Loading @@ -294,31 +295,26 @@ public class PopupPopulator { @Override public void run() { final Context context = mSystemShortcutChild.getContext(); if (mSystemShortcutChild instanceof DeepShortcutView) { // Expanded system shortcut, with both icon and text shown on white background. final DeepShortcutView shortcutView = (DeepShortcutView) mSystemShortcutChild; shortcutView.getIconView().setBackground(mSystemShortcutInfo.getIcon(context, android.R.attr.textColorTertiary)); shortcutView.getBubbleText().setText(mSystemShortcutInfo.getLabel(context)); } else if (mSystemShortcutChild instanceof ImageView) { // Only the system shortcut icon shows on a gray background header. final ImageView shortcutIcon = (ImageView) mSystemShortcutChild; shortcutIcon.setImageDrawable(mSystemShortcutInfo.getIcon(context, android.R.attr.textColorHint)); shortcutIcon.setContentDescription(mSystemShortcutInfo.getLabel(context)); } if (!(mSystemShortcutInfo instanceof SystemShortcut.Widgets)) { initializeSystemShortcut(context, mSystemShortcutChild, mSystemShortcutInfo); mSystemShortcutChild.setOnClickListener(mSystemShortcutInfo .getOnClickListener(mLauncher, mItemInfo)); } else { mSystemShortcutChild.setTag(mSystemShortcutInfo); // Widgets might not be enabled right away. if (mContainer.enableWidgets()) { return; } // Disable Widgets (we might be able to re-enable when widgets are bound). mSystemShortcutChild.setAlpha(DISABLED_ALPHA); } public static void initializeSystemShortcut(Context context, View view, SystemShortcut info) { if (view instanceof DeepShortcutView) { // Expanded system shortcut, with both icon and text shown on white background. final DeepShortcutView shortcutView = (DeepShortcutView) view; shortcutView.getIconView().setBackground(info.getIcon(context, android.R.attr.textColorTertiary)); shortcutView.getBubbleText().setText(info.getLabel(context)); } else if (view instanceof ImageView) { // Only the system shortcut icon shows on a gray background header. final ImageView shortcutIcon = (ImageView) view; shortcutIcon.setImageDrawable(info.getIcon(context, android.R.attr.textColorHint)); shortcutIcon.setContentDescription(info.getLabel(context)); } view.setTag(info); } }