From 97503ab4fbbda1ef44b710fce964514c007f5a4c Mon Sep 17 00:00:00 2001 From: Sebastian Franco Date: Mon, 25 Oct 2021 15:19:38 -0500 Subject: [PATCH] Fixing the possibility of opening multiple WidgetsFullSheet The error is that you can open multiple times the view for selecting widgets for the Home Screen (i.e. WidgetsFullSheet.java) but only when using a keyboard by using the command ctrl+w creating a new instance every time you use it. To fix this I added a singleton pattern so that only one instance of WidgetsFullSheet.java can be open at any given point. Test: Manually Tested Fix: 196704061 Change-Id: I7a364ee5e746e77455da326a21aff6830ac18e8c --- src/com/android/launcher3/views/OptionsPopupView.java | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/src/com/android/launcher3/views/OptionsPopupView.java b/src/com/android/launcher3/views/OptionsPopupView.java index 33ab0d28fb..9774c46624 100644 --- a/src/com/android/launcher3/views/OptionsPopupView.java +++ b/src/com/android/launcher3/views/OptionsPopupView.java @@ -40,6 +40,7 @@ import androidx.annotation.Nullable; import androidx.annotation.VisibleForTesting; import androidx.core.content.ContextCompat; +import com.android.launcher3.AbstractFloatingView; import com.android.launcher3.Launcher; import com.android.launcher3.LauncherSettings; import com.android.launcher3.R; @@ -220,6 +221,11 @@ public class OptionsPopupView extends ArrowPopup Toast.makeText(launcher, R.string.safemode_widget_error, Toast.LENGTH_SHORT).show(); return null; } else { + AbstractFloatingView floatingView = AbstractFloatingView.getTopOpenViewWithType( + launcher, TYPE_WIDGETS_FULL_SHEET); + if (floatingView != null) { + return (WidgetsFullSheet) floatingView; + } return WidgetsFullSheet.show(launcher, true /* animated */); } } @@ -279,7 +285,7 @@ public class OptionsPopupView extends ArrowPopup public final OnLongClickListener clickListener; public OptionItem(Context context, int labelRes, int iconRes, EventEnum eventId, - OnLongClickListener clickListener) { + OnLongClickListener clickListener) { this.labelRes = labelRes; this.label = context.getText(labelRes); this.icon = ContextCompat.getDrawable(context, iconRes); @@ -288,7 +294,7 @@ public class OptionsPopupView extends ArrowPopup } public OptionItem(CharSequence label, Drawable icon, EventEnum eventId, - OnLongClickListener clickListener) { + OnLongClickListener clickListener) { this.labelRes = 0; this.label = label; this.icon = icon;