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

Bug: 350758155
Test: locally tested + unit tests
Flag: com.android.launcher3.enable_new_archiving_icon

Change-Id: I6e1fccbb7c8cb87a7e2675a60b05bf0cb402acf2
This commit is contained in:
Charlie Anderson
2024-07-11 16:19:01 -04:00
parent c4ae2f65b6
commit 114e84908f
3 changed files with 103 additions and 5 deletions

View File

@@ -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,61 @@ 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);
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;