From 688621498a0798862db468a20b00ff3ed693fe23 Mon Sep 17 00:00:00 2001 From: Jon Spivack Date: Thu, 28 Oct 2021 18:37:19 -0700 Subject: [PATCH] P2P App Sharing: Gray out disabled SystemShortcut The Share App system shortcut is disabled for apps that are deemed unshareable. This updates the UX to gray out the shortcut instead of hiding it. When the user clicks on the grayed out shortcut, a Toast message is displayed. This update also enables the shareability check. In order to properly gray out the shortcut, this also fixes a bug with BubbleTextView in which ColorStateLists weren't applied correctly. Bug: 202556634 Bug: 204495363 Test: Manual (observed UX on Wembley device in regular and dark themes) Test: m -j RunLauncherGoGoogleRoboTests Change-Id: Ieb04baf8c9cb9d325119cb97fceb96f2fc5a62ff --- go/quickstep/res/values/strings.xml | 4 ++++ .../src/com/android/launcher3/AppSharing.java | 14 +++++++++++++- res/color/system_shortcut_text.xml | 19 +++++++++++++++++++ res/layout/system_shortcut_content.xml | 4 ++-- src/com/android/launcher3/BubbleTextView.java | 10 +++++++++- .../popup/PopupContainerWithArrow.java | 5 ----- .../launcher3/popup/SystemShortcut.java | 3 +++ 7 files changed, 50 insertions(+), 9 deletions(-) create mode 100644 res/color/system_shortcut_text.xml diff --git a/go/quickstep/res/values/strings.xml b/go/quickstep/res/values/strings.xml index 8429f6a7f2..42f4702141 100644 --- a/go/quickstep/res/values/strings.xml +++ b/go/quickstep/res/values/strings.xml @@ -41,4 +41,8 @@ Tap here to listen to text on this screen Tap here to translate text on this screen + + + + This app can’t be shared diff --git a/go/quickstep/src/com/android/launcher3/AppSharing.java b/go/quickstep/src/com/android/launcher3/AppSharing.java index fd5456c73b..7c66f6e105 100644 --- a/go/quickstep/src/com/android/launcher3/AppSharing.java +++ b/go/quickstep/src/com/android/launcher3/AppSharing.java @@ -25,6 +25,7 @@ import android.net.Uri; import android.text.TextUtils; import android.util.Log; import android.view.View; +import android.widget.Toast; import androidx.core.content.FileProvider; @@ -53,7 +54,7 @@ public final class AppSharing { * With this flag enabled, the Share App button will be dynamically enabled/disabled based * on each app's shareability status. */ - public static final boolean ENABLE_SHAREABILITY_CHECK = false; + public static final boolean ENABLE_SHAREABILITY_CHECK = true; private static final String TAG = "AppSharing"; private static final String FILE_PROVIDER_SUFFIX = ".overview.fileprovider"; @@ -111,6 +112,11 @@ public final class AppSharing { @Override public void onClick(View view) { + if (!isEnabled()) { + showCannotShareToast(view.getContext()); + return; + } + Intent sendIntent = new Intent(); sendIntent.setAction(Intent.ACTION_SEND); @@ -163,6 +169,12 @@ public final class AppSharing { mShareabilityMgr.requestAppStatusUpdate(packageName, this::onStatusUpdated); } } + + private void showCannotShareToast(Context context) { + CharSequence text = context.getText(R.string.toast_p2p_app_not_shareable); + int duration = Toast.LENGTH_SHORT; + Toast.makeText(context, text, duration).show(); + } } /** diff --git a/res/color/system_shortcut_text.xml b/res/color/system_shortcut_text.xml new file mode 100644 index 0000000000..f9f8239a99 --- /dev/null +++ b/res/color/system_shortcut_text.xml @@ -0,0 +1,19 @@ + + + + + + \ No newline at end of file diff --git a/res/layout/system_shortcut_content.xml b/res/layout/system_shortcut_content.xml index e693dbd8eb..ddcef096e0 100644 --- a/res/layout/system_shortcut_content.xml +++ b/res/layout/system_shortcut_content.xml @@ -33,7 +33,7 @@ android:maxLines="2" android:ellipsize="end" android:hyphenationFrequency="full" - android:textColor="?android:attr/textColorPrimary" + android:textColor="@color/system_shortcut_text" launcher:iconDisplay="shortcut_popup" launcher:layoutHorizontal="true" android:focusable="false" /> @@ -44,5 +44,5 @@ android:layout_height="@dimen/system_shortcut_icon_size" android:layout_marginStart="@dimen/system_shortcut_margin_start" android:layout_gravity="start|center_vertical" - android:backgroundTint="?android:attr/textColorPrimary"/> + android:backgroundTint="@color/system_shortcut_text"/> diff --git a/src/com/android/launcher3/BubbleTextView.java b/src/com/android/launcher3/BubbleTextView.java index 78110474fd..3992e316ba 100644 --- a/src/com/android/launcher3/BubbleTextView.java +++ b/src/com/android/launcher3/BubbleTextView.java @@ -148,6 +148,8 @@ public class BubbleTextView extends TextView implements ItemInfoUpdateReceiver, @ViewDebug.ExportedProperty(category = "launcher") private int mTextColor; @ViewDebug.ExportedProperty(category = "launcher") + private ColorStateList mTextColorStateList; + @ViewDebug.ExportedProperty(category = "launcher") private float mTextAlpha = 1; @ViewDebug.ExportedProperty(category = "launcher") @@ -617,12 +619,14 @@ public class BubbleTextView extends TextView implements ItemInfoUpdateReceiver, @Override public void setTextColor(int color) { mTextColor = color; + mTextColorStateList = null; super.setTextColor(getModifiedColor()); } @Override public void setTextColor(ColorStateList colors) { mTextColor = colors.getDefaultColor(); + mTextColorStateList = colors; if (Float.compare(mTextAlpha, 1) == 0) { super.setTextColor(colors); } else { @@ -644,7 +648,11 @@ public class BubbleTextView extends TextView implements ItemInfoUpdateReceiver, private void setTextAlpha(float alpha) { mTextAlpha = alpha; - super.setTextColor(getModifiedColor()); + if (mTextColorStateList != null) { + setTextColor(mTextColorStateList); + } else { + super.setTextColor(getModifiedColor()); + } } private int getModifiedColor() { diff --git a/src/com/android/launcher3/popup/PopupContainerWithArrow.java b/src/com/android/launcher3/popup/PopupContainerWithArrow.java index fbf2b69b75..2470f13491 100644 --- a/src/com/android/launcher3/popup/PopupContainerWithArrow.java +++ b/src/com/android/launcher3/popup/PopupContainerWithArrow.java @@ -363,11 +363,6 @@ public class PopupContainerWithArrow } private void initializeSystemShortcut(int resId, ViewGroup container, SystemShortcut info) { - if (!info.isEnabled()) { - // If the shortcut is disabled, do not display it - return; - } - View view = inflateAndAdd( resId, container, getInsertIndexForSystemShortcut(container, info)); if (view instanceof DeepShortcutView) { diff --git a/src/com/android/launcher3/popup/SystemShortcut.java b/src/com/android/launcher3/popup/SystemShortcut.java index e5424cfe0a..0703db0835 100644 --- a/src/com/android/launcher3/popup/SystemShortcut.java +++ b/src/com/android/launcher3/popup/SystemShortcut.java @@ -75,12 +75,15 @@ public abstract class SystemShortcut extends Ite public void setIconAndLabelFor(View iconView, TextView labelView) { iconView.setBackgroundResource(mIconResId); + iconView.setEnabled(isEnabled); labelView.setText(mLabelResId); + labelView.setEnabled(isEnabled); } public void setIconAndContentDescriptionFor(ImageView view) { view.setImageResource(mIconResId); view.setContentDescription(view.getContext().getText(mLabelResId)); + view.setEnabled(isEnabled); } public AccessibilityNodeInfo.AccessibilityAction createAccessibilityAction(Context context) {