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

Commit aa9332af authored by Brandon Dayauon's avatar Brandon Dayauon Committed by Android (Google) Code Review
Browse files

Merge "Fix prediction row title consistency" into udc-qpr-dev

parents b704c1d4 f2ea399e
Loading
Loading
Loading
Loading
+3 −11
Original line number Diff line number Diff line
@@ -16,6 +16,8 @@

package com.android.launcher3.appprediction;

import static com.android.launcher3.BubbleTextView.DISPLAY_PREDICTION_ROW;

import android.annotation.TargetApi;
import android.content.Context;
import android.graphics.Canvas;
@@ -36,7 +38,6 @@ import com.android.launcher3.Utilities;
import com.android.launcher3.allapps.FloatingHeaderRow;
import com.android.launcher3.allapps.FloatingHeaderView;
import com.android.launcher3.anim.AlphaUpdateListener;
import com.android.launcher3.config.FeatureFlags;
import com.android.launcher3.keyboard.FocusIndicatorHelper;
import com.android.launcher3.keyboard.FocusIndicatorHelper.SimpleFocusIndicatorHelper;
import com.android.launcher3.model.data.ItemInfo;
@@ -106,22 +107,12 @@ public class PredictionRowView<T extends Context & ActivityContext>
                mActivityContext.getAppsView().getAppsStore().unregisterIconContainer(this);
            }
        }

        // Set the predicted row in All Apps' text line to 1.
        if (FeatureFlags.ENABLE_TWOLINE_ALLAPPS.get()
                || FeatureFlags.ENABLE_TWOLINE_DEVICESEARCH.get()) {
            for (int i = 0; i < getChildCount(); i++) {
                BubbleTextView icon = (BubbleTextView) getChildAt(i);
                icon.setMaxLines(1);
            }
        }
    }

    @Override
    protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
        super.onMeasure(widthMeasureSpec, MeasureSpec.makeMeasureSpec(getExpectedHeight(),
                MeasureSpec.EXACTLY));
        updateVisibility();
    }

    @Override
@@ -231,6 +222,7 @@ public class PredictionRowView<T extends Context & ActivityContext>
            icon.reset();
            if (predictionCount > i) {
                icon.setVisibility(View.VISIBLE);
                icon.setDisplay(DISPLAY_PREDICTION_ROW);
                icon.applyFromWorkspaceItem(mPredictedApps.get(i));
            } else {
                icon.setVisibility(predictionCount == 0 ? GONE : INVISIBLE);
+1 −0
Original line number Diff line number Diff line
@@ -85,6 +85,7 @@
            <enum name="taskbar" value="5" />
            <enum name="search_result_tall" value="6" />
            <enum name="search_result_small" value="7" />
            <enum name="prediction_row" value="8" />
        </attr>
        <attr name="centerVertically" format="boolean" />
    </declare-styleable>
+7 −6
Original line number Diff line number Diff line
@@ -94,11 +94,12 @@ public class BubbleTextView extends TextView implements ItemInfoUpdateReceiver,
        IconLabelDotView, DraggableView, Reorderable {

    private static final int DISPLAY_WORKSPACE = 0;
    private static final int DISPLAY_ALL_APPS = 1;
    public static final int DISPLAY_ALL_APPS = 1;
    private static final int DISPLAY_FOLDER = 2;
    protected static final int DISPLAY_TASKBAR = 5;
    private static final int DISPLAY_SEARCH_RESULT = 6;
    private static final int DISPLAY_SEARCH_RESULT_SMALL = 7;
    public static final int DISPLAY_PREDICTION_ROW = 8;

    private static final float MIN_LETTER_SPACING = -0.05f;
    private static final int MAX_SEARCH_LOOP_COUNT = 20;
@@ -211,7 +212,7 @@ public class BubbleTextView extends TextView implements ItemInfoUpdateReceiver,
            setCompoundDrawablePadding(grid.iconDrawablePaddingPx);
            defaultIconSize = grid.iconSizePx;
            setCenterVertically(grid.iconCenterVertically);
        } else if (mDisplay == DISPLAY_ALL_APPS) {
        } else if (mDisplay == DISPLAY_ALL_APPS || mDisplay == DISPLAY_PREDICTION_ROW) {
            setTextSize(TypedValue.COMPLEX_UNIT_PX, grid.allAppsIconTextSizePx);
            setCompoundDrawablePadding(grid.allAppsIconDrawablePaddingPx);
            defaultIconSize = grid.allAppsIconSizePx;
@@ -424,10 +425,10 @@ public class BubbleTextView extends TextView implements ItemInfoUpdateReceiver,
        }
    }

    /** This is used for testing to forcefully set the display to ALL_APPS */
    /** This is used for testing to forcefully set the display. */
    @VisibleForTesting
    public void setDisplayAllApps() {
        mDisplay = DISPLAY_ALL_APPS;
    public void setDisplay(int display) {
        mDisplay = display;
    }

    /**
+28 −1
Original line number Diff line number Diff line
@@ -18,6 +18,8 @@ package com.android.launcher3.ui;

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.config.FeatureFlags.ENABLE_TWOLINE_ALLAPPS;

import static org.junit.Assert.assertEquals;
@@ -79,7 +81,6 @@ public class BubbleTextViewTest {
        mContext = new ActivityContextWrapper(getApplicationContext());
        mBubbleTextView = new BubbleTextView(mContext);
        mBubbleTextView.reset();
        mBubbleTextView.setDisplayAllApps();

        BubbleTextView testView = new BubbleTextView(mContext);
        testView.setTypeface(Typeface.MONOSPACE);
@@ -104,6 +105,7 @@ public class BubbleTextViewTest {
    public void testEmptyString_flagOn() {
        try (AutoCloseable flag = TestUtil.overrideFlag(ENABLE_TWOLINE_ALLAPPS, true)) {
            mItemInfoWithIcon.title = EMPTY_STRING;
            mBubbleTextView.setDisplay(DISPLAY_ALL_APPS);
            mBubbleTextView.applyLabel(mItemInfoWithIcon);
            mBubbleTextView.setTypeface(Typeface.MONOSPACE);
            mBubbleTextView.measure(mLimitedWidth, 0);
@@ -118,6 +120,7 @@ public class BubbleTextViewTest {
    public void testEmptyString_flagOff() {
        try (AutoCloseable flag = TestUtil.overrideFlag(ENABLE_TWOLINE_ALLAPPS, false)) {
            mItemInfoWithIcon.title = EMPTY_STRING;
            mBubbleTextView.setDisplay(DISPLAY_ALL_APPS);
            mBubbleTextView.applyLabel(mItemInfoWithIcon);
            mBubbleTextView.setTypeface(Typeface.MONOSPACE);
            mBubbleTextView.measure(mLimitedWidth, 0);
@@ -134,6 +137,7 @@ public class BubbleTextViewTest {
            // test string: "Battery Stats"
            mItemInfoWithIcon.title = TEST_STRING_WITH_SPACE_LONGER_THAN_CHAR_LIMIT;
            mBubbleTextView.applyLabel(mItemInfoWithIcon);
            mBubbleTextView.setDisplay(DISPLAY_ALL_APPS);
            mBubbleTextView.setTypeface(Typeface.MONOSPACE);
            mBubbleTextView.measure(mLimitedWidth, 0);
            mBubbleTextView.onPreDraw();
@@ -149,6 +153,7 @@ public class BubbleTextViewTest {
            // test string: "Battery Stats"
            mItemInfoWithIcon.title = TEST_STRING_WITH_SPACE_LONGER_THAN_CHAR_LIMIT;
            mBubbleTextView.applyLabel(mItemInfoWithIcon);
            mBubbleTextView.setDisplay(DISPLAY_ALL_APPS);
            mBubbleTextView.setTypeface(Typeface.MONOSPACE);
            mBubbleTextView.measure(mLimitedWidth, 0);
            mBubbleTextView.onPreDraw();
@@ -164,6 +169,7 @@ public class BubbleTextViewTest {
            // test string: "flutterappflorafy"
            mItemInfoWithIcon.title = TEST_LONG_STRING_NO_SPACE_LONGER_THAN_CHAR_LIMIT;
            mBubbleTextView.applyLabel(mItemInfoWithIcon);
            mBubbleTextView.setDisplay(DISPLAY_ALL_APPS);
            mBubbleTextView.setTypeface(Typeface.MONOSPACE);
            mBubbleTextView.measure(mLimitedWidth, 0);
            mBubbleTextView.onPreDraw();
@@ -179,6 +185,7 @@ public class BubbleTextViewTest {
            // test string: "flutterappflorafy"
            mItemInfoWithIcon.title = TEST_LONG_STRING_NO_SPACE_LONGER_THAN_CHAR_LIMIT;
            mBubbleTextView.applyLabel(mItemInfoWithIcon);
            mBubbleTextView.setDisplay(DISPLAY_ALL_APPS);
            mBubbleTextView.setTypeface(Typeface.MONOSPACE);
            mBubbleTextView.measure(mLimitedWidth, 0);
            mBubbleTextView.onPreDraw();
@@ -194,6 +201,7 @@ public class BubbleTextViewTest {
            // test string: "System UWB Field Test"
            mItemInfoWithIcon.title = TEST_LONG_STRING_WITH_SPACE_LONGER_THAN_CHAR_LIMIT;
            mBubbleTextView.applyLabel(mItemInfoWithIcon);
            mBubbleTextView.setDisplay(DISPLAY_ALL_APPS);
            mBubbleTextView.setTypeface(Typeface.MONOSPACE);
            mBubbleTextView.measure(mLimitedWidth, 0);
            mBubbleTextView.onPreDraw();
@@ -209,6 +217,7 @@ public class BubbleTextViewTest {
            // test string: "System UWB Field Test"
            mItemInfoWithIcon.title = TEST_LONG_STRING_WITH_SPACE_LONGER_THAN_CHAR_LIMIT;
            mBubbleTextView.applyLabel(mItemInfoWithIcon);
            mBubbleTextView.setDisplay(DISPLAY_ALL_APPS);
            mBubbleTextView.setTypeface(Typeface.MONOSPACE);
            mBubbleTextView.measure(mLimitedWidth, 0);
            mBubbleTextView.onPreDraw();
@@ -224,6 +233,7 @@ public class BubbleTextViewTest {
            // test string: "LEGO®Builder"
            mItemInfoWithIcon.title = TEST_LONG_STRING_SYMBOL_LONGER_THAN_CHAR_LIMIT;
            mBubbleTextView.applyLabel(mItemInfoWithIcon);
            mBubbleTextView.setDisplay(DISPLAY_ALL_APPS);
            mBubbleTextView.setTypeface(Typeface.MONOSPACE);
            mBubbleTextView.measure(mLimitedWidth, 0);
            mBubbleTextView.onPreDraw();
@@ -239,6 +249,7 @@ public class BubbleTextViewTest {
            // test string: "LEGO®Builder"
            mItemInfoWithIcon.title = TEST_LONG_STRING_SYMBOL_LONGER_THAN_CHAR_LIMIT;
            mBubbleTextView.applyLabel(mItemInfoWithIcon);
            mBubbleTextView.setDisplay(DISPLAY_ALL_APPS);
            mBubbleTextView.setTypeface(Typeface.MONOSPACE);
            mBubbleTextView.measure(mLimitedWidth, 0);
            mBubbleTextView.onPreDraw();
@@ -291,4 +302,20 @@ public class BubbleTextViewTest {
                breakPoints);
        assertEquals(TEST_LONG_STRING_SYMBOL_LONGER_THAN_CHAR_LIMIT_RESULT, newString);
    }

    @Test
    public void testEnsurePredictionRowIsOneLine() {
        try (AutoCloseable flag = TestUtil.overrideFlag(ENABLE_TWOLINE_ALLAPPS, true)) {
            // test string: "Battery Stats"
            mItemInfoWithIcon.title = TEST_STRING_WITH_SPACE_LONGER_THAN_CHAR_LIMIT;
            mBubbleTextView.setDisplay(DISPLAY_PREDICTION_ROW);
            mBubbleTextView.applyLabel(mItemInfoWithIcon);
            mBubbleTextView.setTypeface(Typeface.MONOSPACE);
            mBubbleTextView.measure(mLimitedWidth, 0);
            mBubbleTextView.onPreDraw();
            assertEquals(ONE_LINE, mBubbleTextView.getLineCount());
        } catch (Exception e) {
            throw new RuntimeException(e);
        }
    }
}