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

Commit f2ea399e authored by Brandon Dayauon's avatar Brandon Dayauon
Browse files

Fix prediction row title consistency

There's an inconsistency with prediction row in 0-state and all apps page.
This happens because we change the number of lines (to 1 line) after calculating and rendering the two lines.
Which is why if you look at the photos, in all apps, Amazon app just shows "Amazon" instead of "Amazon Sh.."

Instead of changing the number of lines after processing, just set a separate display to the prediction app row

bug:288811197
Flag: teamfood
Test: manual - locally added test BubbleTextView
before 0-state: https://screenshot.googleplex.com/5q9iYypgwwtDa8b
before allapps prediction row: https://screenshot.googleplex.com/BVxGMTT43stDzZ9
after allapps prediction row: https://screenshot.googleplex.com/BfNTFPXwf4FHuRN

Change-Id: Ifefe6dc8dd4a117be7b63f92ff837d0467a51f8b
parent c84ecc0f
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);
        }
    }
}