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
@@ -16,28 +16,41 @@
package com.android.launcher3.ui;
import static android.graphics.fonts.FontStyle.FONT_WEIGHT_BOLD;
import static android.graphics.fonts.FontStyle.FONT_WEIGHT_NORMAL;
import static android.text.style.DynamicDrawableSpan.ALIGN_CENTER;
import static androidx.test.core.app.ApplicationProvider.getApplicationContext;
import static com.android.launcher3.BubbleTextView.DISPLAY_ALL_APPS;
import static com.android.launcher3.BubbleTextView.DISPLAY_PREDICTION_ROW;
import static com.android.launcher3.BubbleTextView.DISPLAY_SEARCH_RESULT;
import static com.android.launcher3.BubbleTextView.DISPLAY_SEARCH_RESULT_SMALL;
import static com.android.launcher3.Flags.FLAG_ENABLE_NEW_ARCHIVING_ICON;
import static com.android.launcher3.LauncherPrefs.ENABLE_TWOLINE_ALLAPPS_TOGGLE;
import static com.android.launcher3.model.data.ItemInfoWithIcon.FLAG_ARCHIVED;
import static com.google.common.truth.Truth.assertThat;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotEquals;
import static org.mockito.Mockito.spy;
import static org.mockito.Mockito.verify;
import android.content.ComponentName;
import android.content.Context;
import android.content.Intent;
import android.graphics.Typeface;
import android.os.Build;
import android.os.UserHandle;
import android.platform.test.annotations.EnableFlags;
import android.platform.test.flag.junit.SetFlagsRule;
import android.text.SpannedString;
import android.text.style.ImageSpan;
import android.view.ViewGroup;
import androidx.test.ext.junit.runners.AndroidJUnit4;
import androidx.test.filters.SdkSuppress;
import androidx.test.filters.SmallTest;
import com.android.launcher3.BubbleTextView;
@@ -403,6 +416,62 @@ public class BubbleTextViewTest {
assertThat(mBubbleTextView.getIcon().hasBadge()).isEqualTo(false);
}
@EnableFlags(FLAG_ENABLE_NEW_ARCHIVING_ICON)
@Test
public void applyIconAndLabel_setsImageSpan_whenInactiveArchivedApp() {
// Given
BubbleTextView spyTextView = spy(mBubbleTextView);
mGmailAppInfo.runtimeStatusFlags |= FLAG_ARCHIVED;
BubbleTextView expectedTextView = new BubbleTextView(mContext);
mContext.getResources().getConfiguration().fontWeightAdjustment = 0;
int expectedDrawableId = mContext.getResources().getIdentifier(
"cloud_download_24px", /* name */
"drawable", /* defType */
mContext.getPackageName()
);
expectedTextView.setTextWithStartIcon(mGmailAppInfo.title, expectedDrawableId);
// When
spyTextView.applyIconAndLabel(mGmailAppInfo);
// Then
SpannedString expectedText = (SpannedString) expectedTextView.getText();
SpannedString actualText = (SpannedString) spyTextView.getText();
ImageSpan actualSpan = actualText.getSpans(
0, /* queryStart */
1, /* queryEnd */
ImageSpan.class
)[0];
ImageSpan expectedSpan = expectedText.getSpans(
0, /* queryStart */
1, /* queryEnd */
ImageSpan.class
)[0];
verify(spyTextView).setTextWithStartIcon(mGmailAppInfo.title, expectedDrawableId);
assertThat(actualText.toString()).isEqualTo(expectedText.toString());
assertThat(actualSpan.getDrawable().getBounds())
.isEqualTo(expectedSpan.getDrawable().getBounds());
assertThat(actualSpan.getVerticalAlignment()).isEqualTo(ALIGN_CENTER);
}
@EnableFlags(FLAG_ENABLE_NEW_ARCHIVING_ICON)
@SdkSuppress(minSdkVersion = Build.VERSION_CODES.S)
@Test
public void applyIconAndLabel_setsBoldDrawable_whenBoldedTextForArchivedApp() {
// Given
int expectedDrawableId = mContext.getResources().getIdentifier(
"cloud_download_semibold_24px", /* name */
"drawable", /* defType */
mContext.getPackageName()
);
mContext.getResources().getConfiguration().fontWeightAdjustment =
FONT_WEIGHT_BOLD - FONT_WEIGHT_NORMAL;
BubbleTextView spyTextView = spy(mBubbleTextView);
mGmailAppInfo.runtimeStatusFlags |= FLAG_ARCHIVED;
// When
spyTextView.applyIconAndLabel(mGmailAppInfo);
// Then
verify(spyTextView).setTextWithStartIcon(mGmailAppInfo.title, expectedDrawableId);
}
@Test
public void applyIconAndLabel_whenDisplay_DISPLAY_SEARCH_RESULT_hasBadge() {
FlagOp op = FlagOp.NO_OP;