Reapply "Handles Bold Text setting for inline icon by providing bolded cloud icon"

This reverts commit 00fb1adab4.
Also fixes test applyIconAndLabel_setsImageSpan_whenInactiveArchivedApp.

Bug: 350758155
Fixes: 356166053
Test: unit test
Flag: com.android.launcher3.enable_new_archiving_icon

Change-Id: I93f2ac47dc3a8fa81d59e0f089385d2b3fe93306
This commit is contained in:
Charlie Anderson
2024-08-02 17:24:50 +00:00
parent 01a1169d57
commit fe23e711fd
3 changed files with 104 additions and 5 deletions
+24 -5
View File
@@ -16,6 +16,8 @@
package com.android.launcher3;
import static android.graphics.fonts.FontStyle.FONT_WEIGHT_BOLD;
import static android.graphics.fonts.FontStyle.FONT_WEIGHT_NORMAL;
import static android.text.Layout.Alignment.ALIGN_NORMAL;
import static com.android.launcher3.Flags.enableCursorHoverStates;
@@ -118,6 +120,7 @@ public class BubbleTextView extends TextView implements ItemInfoUpdateReceiver,
private static final String EMPTY = "";
private static final StringMatcherUtility.StringMatcher MATCHER =
StringMatcherUtility.StringMatcher.getInstance();
private static final int BOLD_TEXT_ADJUSTMENT = FONT_WEIGHT_BOLD - FONT_WEIGHT_NORMAL;
private static final int[] STATE_PRESSED = new int[]{android.R.attr.state_pressed};
@@ -504,7 +507,7 @@ public class BubbleTextView extends TextView implements ItemInfoUpdateReceiver,
if (Flags.enableNewArchivingIcon()
&& info instanceof ItemInfoWithIcon infoWithIcon
&& infoWithIcon.isInactiveArchive()) {
setTextWithStartIcon(label, R.drawable.cloud_download_24px);
setTextWithArchivingIcon(label);
} else {
setText(label);
}
@@ -820,7 +823,7 @@ public class BubbleTextView extends TextView implements ItemInfoUpdateReceiver,
if (Flags.enableNewArchivingIcon()
&& getTag() instanceof ItemInfoWithIcon infoWithIcon
&& infoWithIcon.isInactiveArchive()) {
setTextWithStartIcon(modifiedString, R.drawable.cloud_download_24px);
setTextWithArchivingIcon(modifiedString);
} else {
setText(modifiedString);
}
@@ -844,13 +847,29 @@ public class BubbleTextView extends TextView implements ItemInfoUpdateReceiver,
super.setTextColor(getModifiedColor());
}
/**
* Sets text with a start icon for App Archiving.
* Uses a bolded drawable if text is bolded.
* @param text
*/
private void setTextWithArchivingIcon(CharSequence text) {
var drawableId = R.drawable.cloud_download_24px;
if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.S
&& getResources().getConfiguration().fontWeightAdjustment >= BOLD_TEXT_ADJUSTMENT) {
// If System bold text setting is on, then use a bolded icon
drawableId = R.drawable.cloud_download_semibold_24px;
}
setTextWithStartIcon(text, drawableId);
}
/**
* 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
* @param drawableId Drawable Resource to use for drawing image at start of text
*/
private void setTextWithStartIcon(CharSequence text, @DrawableRes int drawableRes) {
Drawable drawable = getContext().getDrawable(drawableRes);
@VisibleForTesting
public void setTextWithStartIcon(CharSequence text, @DrawableRes int drawableId) {
Drawable drawable = getContext().getDrawable(drawableId);
if (drawable == null) {
setText(text);
Log.w(TAG, "setTextWithStartIcon: start icon Drawable not found from resources"