From d5acd6a016a7a0bbafed0d715325c4363a741073 Mon Sep 17 00:00:00 2001 From: Charlie Anderson Date: Mon, 8 Jul 2024 12:30:00 -0400 Subject: [PATCH] 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 --- res/drawable/cloud_download_24px.xml | 11 +++++ src/com/android/launcher3/BubbleTextView.java | 45 ++++++++++++++++++- .../android/launcher3/LauncherAppState.java | 3 ++ 3 files changed, 57 insertions(+), 2 deletions(-) create mode 100644 res/drawable/cloud_download_24px.xml diff --git a/res/drawable/cloud_download_24px.xml b/res/drawable/cloud_download_24px.xml new file mode 100644 index 0000000000..6f7c95aac2 --- /dev/null +++ b/res/drawable/cloud_download_24px.xml @@ -0,0 +1,11 @@ + + + + diff --git a/src/com/android/launcher3/BubbleTextView.java b/src/com/android/launcher3/BubbleTextView.java index 83427a01ed..0cb213759a 100644 --- a/src/com/android/launcher3/BubbleTextView.java +++ b/src/com/android/launcher3/BubbleTextView.java @@ -40,11 +40,15 @@ import android.graphics.Rect; 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.View; 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 @@ import java.util.Locale; 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 @@ public class BubbleTextView extends TextView implements ItemInfoUpdateReceiver, 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 @@ public class BubbleTextView extends TextView implements ItemInfoUpdateReceiver, 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 @@ public class BubbleTextView extends TextView implements ItemInfoUpdateReceiver, 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 85c8b57978..b41da0fca3 100644 --- a/src/com/android/launcher3/LauncherAppState.java +++ b/src/com/android/launcher3/LauncherAppState.java @@ -115,6 +115,9 @@ public class LauncherAppState implements SafeCloseable { if (BuildCompat.isAtLeastV() && Flags.enableSupportForArchiving()) { ArchiveCompatibilityParams params = new ArchiveCompatibilityParams(); params.setEnableUnarchivalConfirmation(false); + if (Flags.enableNewArchivingIcon()) { + params.setEnableIconOverlay(false); + } launcherApps.setArchiveCompatibility(params); }