Add new Cloud archived app icon and support for inline icons for BubbleTextView
- Can now set start drawable for BubbleTextView title with setTextWithStartIcon()
- App Archiving cloud overlay icon will be disabled when flag on
Bug: 350758155
Test: locally tested B&R with pre-archiving
Flag: com.android.launcher3.enable_new_archiving_icon
Change-Id: I4d395a7ea7dc5ee11259f897d45b83eabdabb766
diff --git a/src/com/android/launcher3/BubbleTextView.java b/src/com/android/launcher3/BubbleTextView.java
index 83427a0..0cb2137 100644
--- a/src/com/android/launcher3/BubbleTextView.java
+++ b/src/com/android/launcher3/BubbleTextView.java
@@ -40,11 +40,15 @@
import android.graphics.drawable.ColorDrawable;
import android.graphics.drawable.Drawable;
import android.icu.text.MessageFormat;
+import android.text.Spannable;
+import android.text.SpannableString;
import android.text.StaticLayout;
import android.text.TextPaint;
import android.text.TextUtils;
import android.text.TextUtils.TruncateAt;
+import android.text.style.ImageSpan;
import android.util.AttributeSet;
+import android.util.Log;
import android.util.Property;
import android.util.Size;
import android.util.TypedValue;
@@ -54,6 +58,7 @@
import android.view.ViewDebug;
import android.widget.TextView;
+import androidx.annotation.DrawableRes;
import androidx.annotation.Nullable;
import androidx.annotation.UiThread;
import androidx.annotation.VisibleForTesting;
@@ -96,6 +101,8 @@
public class BubbleTextView extends TextView implements ItemInfoUpdateReceiver,
IconLabelDotView, DraggableView, Reorderable {
+ public static final String TAG = "BubbleTextView";
+
public static final int DISPLAY_WORKSPACE = 0;
public static final int DISPLAY_ALL_APPS = 1;
public static final int DISPLAY_FOLDER = 2;
@@ -494,7 +501,13 @@
mLastOriginalText = label;
mLastModifiedText = mLastOriginalText;
mBreakPointsIntArray = StringMatcherUtility.getListOfBreakpoints(label, MATCHER);
- setText(label);
+ if (Flags.enableNewArchivingIcon()
+ && info instanceof ItemInfoWithIcon infoWithIcon
+ && infoWithIcon.isInactiveArchive()) {
+ setTextWithStartIcon(label, R.drawable.cloud_download_24px);
+ } else {
+ setText(label);
+ }
}
if (info.contentDescription != null) {
setContentDescription(info.isDisabled()
@@ -804,7 +817,13 @@
getLineSpacingExtra());
if (!TextUtils.equals(modifiedString, mLastModifiedText)) {
mLastModifiedText = modifiedString;
- setText(modifiedString);
+ if (Flags.enableNewArchivingIcon()
+ && getTag() instanceof ItemInfoWithIcon infoWithIcon
+ && infoWithIcon.isInactiveArchive()) {
+ setTextWithStartIcon(modifiedString, R.drawable.cloud_download_24px);
+ } else {
+ setText(modifiedString);
+ }
// if text contains NEW_LINE, set max lines to 2
if (TextUtils.indexOf(modifiedString, NEW_LINE) != -1) {
setSingleLine(false);
@@ -825,6 +844,28 @@
super.setTextColor(getModifiedColor());
}
+ /**
+ * Uses a SpannableString to set text with a Drawable at the start of the TextView
+ * @param text text to use for TextView
+ * @param drawableRes Drawable Resource to use for drawing image at start of text
+ */
+ private void setTextWithStartIcon(CharSequence text, @DrawableRes int drawableRes) {
+ Drawable drawable = getContext().getDrawable(drawableRes);
+ if (drawable == null) {
+ setText(text);
+ Log.w(TAG, "setTextWithStartIcon: start icon Drawable not found from resources"
+ + ", will just set text instead. text=" + text);
+ return;
+ }
+ drawable.setTint(getCurrentTextColor());
+ drawable.setBounds(0, 0, Math.round(getTextSize()), Math.round(getTextSize()));
+ ImageSpan imageSpan = new ImageSpan(drawable, ImageSpan.ALIGN_CENTER);
+ // First space will be replaced with Drawable, second space is for space before text.
+ SpannableString spannable = new SpannableString(" " + text);
+ spannable.setSpan(imageSpan, 0, 1, Spannable.SPAN_INCLUSIVE_EXCLUSIVE);
+ setText(spannable);
+ }
+
@Override
public void setTextColor(ColorStateList colors) {
mTextColor = colors.getDefaultColor();
diff --git a/src/com/android/launcher3/LauncherAppState.java b/src/com/android/launcher3/LauncherAppState.java
index 85c8b57..b41da0f 100644
--- a/src/com/android/launcher3/LauncherAppState.java
+++ b/src/com/android/launcher3/LauncherAppState.java
@@ -115,6 +115,9 @@
if (BuildCompat.isAtLeastV() && Flags.enableSupportForArchiving()) {
ArchiveCompatibilityParams params = new ArchiveCompatibilityParams();
params.setEnableUnarchivalConfirmation(false);
+ if (Flags.enableNewArchivingIcon()) {
+ params.setEnableIconOverlay(false);
+ }
launcherApps.setArchiveCompatibility(params);
}