summaryrefslogtreecommitdiffstats
path: root/src/com/android/launcher3/shortcuts
diff options
context:
space:
mode:
authorTony Wickham <twickham@google.com>2017-04-13 16:24:38 -0700
committerTony Wickham <twickham@google.com>2017-04-20 15:10:38 -0700
commita7e1c1c08854930ddb4366698d5bf079ae0536f3 (patch)
tree7ca715956276ac891cd4f5eced4db8c84a15633f /src/com/android/launcher3/shortcuts
parent343a77e609382bcb9b1d69ea235a9e6d779b719e (diff)
downloadandroid_packages_apps_Trebuchet-a7e1c1c08854930ddb4366698d5bf079ae0536f3.tar.gz
android_packages_apps_Trebuchet-a7e1c1c08854930ddb4366698d5bf079ae0536f3.tar.bz2
android_packages_apps_Trebuchet-a7e1c1c08854930ddb4366698d5bf079ae0536f3.zip
Only add widgets system shortcut if widgets exist
Before we were adding it in a disabled state, and then enabling it once widgets were bound (if widgets existed for that app). Now we load all widgets when launcher starts so that we can use the values for the purpose of animating the popup container. Then, as the container opens, we reload widgets/shortcuts for that particular app and add/remove the widgets shortcut if necessary. Bug: 34940468 Change-Id: I64bd009442d10d3d1f9a977bdedfdb639a7dd193
Diffstat (limited to 'src/com/android/launcher3/shortcuts')
-rw-r--r--src/com/android/launcher3/shortcuts/ShortcutsItemView.java62
1 files changed, 45 insertions, 17 deletions
diff --git a/src/com/android/launcher3/shortcuts/ShortcutsItemView.java b/src/com/android/launcher3/shortcuts/ShortcutsItemView.java
index 1f90bb023..ee64b984a 100644
--- a/src/com/android/launcher3/shortcuts/ShortcutsItemView.java
+++ b/src/com/android/launcher3/shortcuts/ShortcutsItemView.java
@@ -26,6 +26,7 @@ import android.view.View;
import android.widget.LinearLayout;
import com.android.launcher3.AbstractFloatingView;
+import com.android.launcher3.BubbleTextView;
import com.android.launcher3.ItemInfo;
import com.android.launcher3.Launcher;
import com.android.launcher3.LauncherAnimUtils;
@@ -119,6 +120,10 @@ public class ShortcutsItemView extends PopupItemView implements View.OnLongClick
}
public void addShortcutView(View shortcutView, PopupPopulator.Item shortcutType) {
+ addShortcutView(shortcutView, shortcutType, -1);
+ }
+
+ private void addShortcutView(View shortcutView, PopupPopulator.Item shortcutType, int index) {
if (shortcutType == PopupPopulator.Item.SHORTCUT) {
mDeepShortcutViews.add((DeepShortcutView) shortcutView);
} else {
@@ -131,7 +136,7 @@ public class ShortcutsItemView extends PopupItemView implements View.OnLongClick
R.layout.system_shortcut_icons, mShortcutsLayout, false);
mShortcutsLayout.addView(mSystemShortcutIcons, 0);
}
- mSystemShortcutIcons.addView(shortcutView);
+ mSystemShortcutIcons.addView(shortcutView, index);
} else {
if (mShortcutsLayout.getChildCount() > 0) {
View prevChild = mShortcutsLayout.getChildAt(mShortcutsLayout.getChildCount() - 1);
@@ -139,7 +144,7 @@ public class ShortcutsItemView extends PopupItemView implements View.OnLongClick
prevChild.findViewById(R.id.divider).setVisibility(VISIBLE);
}
}
- mShortcutsLayout.addView(shortcutView);
+ mShortcutsLayout.addView(shortcutView, index);
}
}
@@ -160,24 +165,47 @@ public class ShortcutsItemView extends PopupItemView implements View.OnLongClick
}
/**
- * Sets the onClickListener on widgets system shortcut child, and updates alpha to 1.
- * @return whether widgets is enabled, i.e. the onClickListener is not null.
+ * Adds a {@link SystemShortcut.Widgets} item if there are widgets for the given ItemInfo.
*/
- 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);
}
}
- return false;
}
@Override