From 6649f808c2c6bafc6a3b614e0b26e674de4d7619 Mon Sep 17 00:00:00 2001 From: Alexander Martinz Date: Fri, 6 Jul 2018 13:01:20 +0200 Subject: Edit dialog: dynamically apply foreground to icon If there are no icon packs installed, we can not edit the icon, though it always applied a foreground and click listener. Only apply foreground and set click listener, if there are icon packs installed and clicking on it actually does something. Change-Id: I09ac1473c75d5edcf5e940a0e5bb2ec7f2296e8f Signed-off-by: Alexander Martinz --- res/layout/target_edit_dialog.xml | 1 - src/com/android/launcher3/Launcher.java | 42 ++++++++++++++++++++------------- 2 files changed, 25 insertions(+), 18 deletions(-) diff --git a/res/layout/target_edit_dialog.xml b/res/layout/target_edit_dialog.xml index 11bfefc80..7567411a7 100644 --- a/res/layout/target_edit_dialog.xml +++ b/res/layout/target_edit_dialog.xml @@ -28,7 +28,6 @@ android:layout_gravity="bottom" android:layout_marginEnd="16dp" android:background="?android:selectableItemBackground" - android:foreground="@drawable/ic_icon_change" android:scaleType="fitCenter" tools:src="@mipmap/ic_launcher" /> diff --git a/src/com/android/launcher3/Launcher.java b/src/com/android/launcher3/Launcher.java index 9d85a64b9..8bdd8836c 100644 --- a/src/com/android/launcher3/Launcher.java +++ b/src/com/android/launcher3/Launcher.java @@ -3991,8 +3991,8 @@ public class Launcher extends BaseActivity CharSequence label = mIconCache.getCacheEntry(app).title; View dialogView = getLayoutInflater().inflate(R.layout.target_edit_dialog, null); - ImageView editIcon = (ImageView) dialogView.findViewById(R.id.edit_dialog_icon); - mIconEditTitle = (EditText) dialogView.findViewById(R.id.edit_dialog_title); + ImageView editIcon = dialogView.findViewById(R.id.edit_dialog_icon); + mIconEditTitle = dialogView.findViewById(R.id.edit_dialog_title); mIconEditTitle.setText(label); Bitmap originalIcon = mIconsHandler.getDrawableIconForPackage(component); @@ -4007,21 +4007,29 @@ public class Launcher extends BaseActivity } editIcon.setImageBitmap(icon); - Pair, List> iconPacks = mIconsHandler.getAllIconPacks(); - ListPopupWindow listPopup = new ListPopupWindow(this); - listPopup.setAdapter(new ArrayAdapter<>(this, R.layout.target_edit_dialog_item, - iconPacks.second)); - listPopup.setWidth(getResources().getDimensionPixelSize(R.dimen.edit_dialog_min_width)); - listPopup.setAnchorView(editIcon); - listPopup.setModal(true); - listPopup.setOnItemClickListener(getIconPackClickListener(info, component, label, - iconPacks.first)); - - editIcon.setOnClickListener(v -> { - if (!iconPacks.second.isEmpty()) { - listPopup.show(); - } - }); + final Pair, List> iconPacks = mIconsHandler.getAllIconPacks(); + final Drawable editIconForeground; + + // if no custom icon packs are installed, disallow icon editing + if (iconPacks.second.isEmpty()) { + editIconForeground = null; + editIcon.setEnabled(false); + } else { + editIconForeground = getDrawable(R.drawable.ic_icon_change); + editIcon.setEnabled(true); + + ListPopupWindow listPopup = new ListPopupWindow(this); + listPopup.setAdapter(new ArrayAdapter<>(this, R.layout.target_edit_dialog_item, + iconPacks.second)); + listPopup.setWidth(getResources().getDimensionPixelSize(R.dimen.edit_dialog_min_width)); + listPopup.setAnchorView(editIcon); + listPopup.setModal(true); + listPopup.setOnItemClickListener(getIconPackClickListener(info, component, label, + iconPacks.first)); + + editIcon.setOnClickListener(v -> listPopup.show()); + } + editIcon.setForeground(editIconForeground); mIconEditDialog = new AlertDialog.Builder(this) .setTitle(R.string.app_edit_drop_target_label) -- cgit v1.2.3