- public boolean enableWidgets(ItemInfo itemInfo) {
- for (View systemShortcut : mSystemShortcutViews) {
- if (systemShortcut.getTag() instanceof SystemShortcut.Widgets) {
- View.OnClickListener onClickListener =
- ((SystemShortcut.Widgets) systemShortcut.getTag()).getOnClickListener(
- mLauncher, itemInfo);
- if (onClickListener != null) {
- systemShortcut.setAlpha(1f);
- systemShortcut.setOnClickListener(onClickListener);
- return true;
- }
- return false;
+ public void enableWidgetsIfExist(final BubbleTextView originalIcon) {
+ ItemInfo itemInfo = (ItemInfo) originalIcon.getTag();
+ SystemShortcut widgetInfo = new SystemShortcut.Widgets();
+ View.OnClickListener onClickListener = widgetInfo.getOnClickListener(mLauncher, itemInfo);
+ View widgetsView = null;
+ for (View systemShortcutView : mSystemShortcutViews) {
+ if (systemShortcutView.getTag() instanceof SystemShortcut.Widgets) {
+ widgetsView = systemShortcutView;
+ break;
+ }
+ }
+ final PopupPopulator.Item widgetsItem = mSystemShortcutIcons == null
+ ? PopupPopulator.Item.SYSTEM_SHORTCUT
+ : PopupPopulator.Item.SYSTEM_SHORTCUT_ICON;
+ if (onClickListener != null && widgetsView == null) {
+ // We didn't have any widgets cached but now there are some, so enable the shortcut.
+ widgetsView = mLauncher.getLayoutInflater().inflate(widgetsItem.layoutId, this, false);
+ PopupPopulator.initializeSystemShortcut(getContext(), widgetsView, widgetInfo);
+ widgetsView.setOnClickListener(onClickListener);
+ if (widgetsItem == PopupPopulator.Item.SYSTEM_SHORTCUT_ICON) {
+ addShortcutView(widgetsView, widgetsItem, 0);
+ } else {
+ // If using the expanded system shortcut (as opposed to just the icon), we need to
+ // reopen the container to ensure measurements etc. all work out. While this could
+ // be quite janky, in practice the user would typically see a small flicker as the
+ // animation restarts partway through, and this is a very rare edge case anyway.
+ ((PopupContainerWithArrow) getParent()).close(false);
+ PopupContainerWithArrow.showForIcon(originalIcon);
+ }
+ } else if (onClickListener == null && widgetsView != null) {
+ // No widgets exist, but we previously added the shortcut so remove it.
+ if (widgetsItem == PopupPopulator.Item.SYSTEM_SHORTCUT_ICON) {
+ mSystemShortcutViews.remove(widgetsView);
+ mSystemShortcutIcons.removeView(widgetsView);
+ } else {
+ ((PopupContainerWithArrow) getParent()).close(false);
+ PopupContainerWithArrow.showForIcon(originalIcon);