Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 6f699d23 authored by Charlie Anderson's avatar Charlie Anderson Committed by Android (Google) Code Review
Browse files

Merge "Handles Bold Text setting for inline icon by providing bolded cloud icon" into main

parents 453734f0 114e8490
Loading
Loading
Loading
Loading
+11 −0
Original line number Diff line number Diff line
<!-- From GM3 icon cloud_download:wght600_vd_theme_24 -->
<vector xmlns:android="http://schemas.android.com/apk/res/android"
    android:width="24dp"
    android:height="24dp"
    android:viewportWidth="960"
    android:viewportHeight="960"
    android:tint="?attr/colorControlNormal">
  <path
      android:fillColor="@android:color/white"
      android:pathData="M260,819.22Q162.22,819.22 92.35,751.7Q22.48,684.17 22.48,586.63Q22.48,503.03 70.61,437.64Q118.74,372.26 198.13,354.13Q217.39,283.26 284.26,217.98Q351.13,152.7 428.7,152.7Q467.91,152.7 496.22,179.3Q524.52,205.91 524.52,244L524.52,484.3L584,425.7L646.22,487.91L480,654.13L313.78,487.91L376,425.7L435.48,484.3L435.48,252.48Q365.13,269.87 326.8,327.11Q288.48,384.35 288.48,446.78L261.7,446.78Q206.51,446.78 167.49,485.8Q128.48,524.81 128.48,580Q128.48,635.74 167,674.48Q205.51,713.22 260,713.22L740,713.22Q778.04,713.22 804.78,686.48Q831.52,659.74 831.52,620Q831.52,581.39 804.78,554.09Q778.04,526.78 738.3,526.78L675.48,526.78L675.48,441.7Q675.48,396.52 656.3,358.98Q637.13,321.44 604.52,292.44L604.52,171.74Q680.78,206.74 726.33,275.8Q771.87,344.87 776.39,428.13L776.39,428.13L776.39,428.13Q847.09,442.35 892.31,496.96Q937.52,551.57 937.52,623.39Q937.52,704.99 879.91,762.1Q822.3,819.22 740,819.22L260,819.22ZM480,431.83Q480,431.83 480,431.83Q480,431.83 480,431.83L480,431.83Q480,431.83 480,431.83Q480,431.83 480,431.83L480,431.83Q480,431.83 480,431.83Q480,431.83 480,431.83L480,431.83Q480,431.83 480,431.83Q480,431.83 480,431.83Q480,431.83 480,431.83Q480,431.83 480,431.83L480,431.83Q480,431.83 480,431.83Q480,431.83 480,431.83Q480,431.83 480,431.83Q480,431.83 480,431.83L480,431.83L480,431.83Q480,431.83 480,431.83Q480,431.83 480,431.83Z"/>
</vector>
+24 −5
Original line number Diff line number Diff line
@@ -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"
+68 −0
Original line number Diff line number Diff line
@@ -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;