diff --git a/quickstep/src/com/android/launcher3/appprediction/PredictionRowView.java b/quickstep/src/com/android/launcher3/appprediction/PredictionRowView.java index e1443d0987..b36fd662fe 100644 --- a/quickstep/src/com/android/launcher3/appprediction/PredictionRowView.java +++ b/quickstep/src/com/android/launcher3/appprediction/PredictionRowView.java @@ -138,9 +138,9 @@ public class PredictionRowView int totalHeight = iconHeight + iconPadding + textHeight + mVerticalPadding * 2; // Prediction row height will be 4dp bigger than the regular apps in A-Z list when two line // is not enabled. Otherwise, the extra height will increase by just the textHeight. - int extraHeight = (FeatureFlags.enableTwolineAllapps() && (!Flags.enableTwolineToggle() - || (Flags.enableTwolineToggle() && LauncherPrefs.ENABLE_TWOLINE_ALLAPPS_TOGGLE.get( - getContext())))) ? textHeight : mTopRowExtraHeight; + int extraHeight = (Flags.enableTwolineToggle() && + LauncherPrefs.ENABLE_TWOLINE_ALLAPPS_TOGGLE.get(getContext())) + ? textHeight : mTopRowExtraHeight; totalHeight += extraHeight; return getVisibility() == GONE ? 0 : totalHeight + getPaddingTop() + getPaddingBottom(); } diff --git a/src/com/android/launcher3/BubbleTextView.java b/src/com/android/launcher3/BubbleTextView.java index a9cf2ff121..3ee1c614f2 100644 --- a/src/com/android/launcher3/BubbleTextView.java +++ b/src/com/android/launcher3/BubbleTextView.java @@ -285,9 +285,6 @@ public class BubbleTextView extends TextView implements ItemInfoUpdateReceiver, mDotParams.scale = 0f; mForceHideDot = false; setBackground(null); - if (FeatureFlags.enableTwolineAllapps() || FeatureFlags.ENABLE_TWOLINE_DEVICESEARCH.get()) { - setMaxLines(1); - } setTag(null); if (mIconLoadRequest != null) { @@ -299,6 +296,7 @@ public class BubbleTextView extends TextView implements ItemInfoUpdateReceiver, setAlpha(1); setScaleY(1); setTranslationY(0); + setMaxLines(1); setVisibility(VISIBLE); } @@ -428,10 +426,9 @@ public class BubbleTextView extends TextView implements ItemInfoUpdateReceiver, * Only if actual text can be displayed in two line, the {@code true} value will be effective. */ protected boolean shouldUseTwoLine() { - return FeatureFlags.enableTwolineAllapps() && isCurrentLanguageEnglish() - && (mDisplay == DISPLAY_ALL_APPS || mDisplay == DISPLAY_PREDICTION_ROW) - && (!Flags.enableTwolineToggle() || (Flags.enableTwolineToggle() - && LauncherPrefs.ENABLE_TWOLINE_ALLAPPS_TOGGLE.get(getContext()))); + return isCurrentLanguageEnglish() && (mDisplay == DISPLAY_ALL_APPS + || mDisplay == DISPLAY_PREDICTION_ROW) && (Flags.enableTwolineToggle() + && LauncherPrefs.ENABLE_TWOLINE_ALLAPPS_TOGGLE.get(getContext())); } protected boolean isCurrentLanguageEnglish() { diff --git a/src/com/android/launcher3/DeviceProfile.java b/src/com/android/launcher3/DeviceProfile.java index 4b4bdc2ecf..f96d59ebba 100644 --- a/src/com/android/launcher3/DeviceProfile.java +++ b/src/com/android/launcher3/DeviceProfile.java @@ -1233,9 +1233,8 @@ public class DeviceProfile { if (isVerticalLayout && !mIsResponsiveGrid) { hideWorkspaceLabelsIfNotEnoughSpace(); } - if (FeatureFlags.enableTwolineAllapps() - && (!Flags.enableTwolineToggle() || (Flags.enableTwolineToggle() - && LauncherPrefs.ENABLE_TWOLINE_ALLAPPS_TOGGLE.get(context)))) { + if ((Flags.enableTwolineToggle() + && LauncherPrefs.ENABLE_TWOLINE_ALLAPPS_TOGGLE.get(context))) { // Add extra textHeight to the existing allAppsCellHeight. allAppsCellHeightPx += Utilities.calculateTextHeight(allAppsIconTextSizePx); } diff --git a/src/com/android/launcher3/allapps/BaseAllAppsAdapter.java b/src/com/android/launcher3/allapps/BaseAllAppsAdapter.java index ca587c16f0..5e5795d4e1 100644 --- a/src/com/android/launcher3/allapps/BaseAllAppsAdapter.java +++ b/src/com/android/launcher3/allapps/BaseAllAppsAdapter.java @@ -223,10 +223,9 @@ public abstract class BaseAllAppsAdapter ex public ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) { switch (viewType) { case VIEW_TYPE_ICON: - int layout = (FeatureFlags.enableTwolineAllapps() && - (!Flags.enableTwolineToggle() || (Flags.enableTwolineToggle() - && LauncherPrefs.ENABLE_TWOLINE_ALLAPPS_TOGGLE.get( - mActivityContext.getApplicationContext())))) + int layout = (Flags.enableTwolineToggle() + && LauncherPrefs.ENABLE_TWOLINE_ALLAPPS_TOGGLE.get( + mActivityContext.getApplicationContext())) ? R.layout.all_apps_icon_twoline : R.layout.all_apps_icon; BubbleTextView icon = (BubbleTextView) mLayoutInflater.inflate( layout, parent, false); diff --git a/src/com/android/launcher3/config/FeatureFlags.java b/src/com/android/launcher3/config/FeatureFlags.java index a0e857131f..b28964ab36 100644 --- a/src/com/android/launcher3/config/FeatureFlags.java +++ b/src/com/android/launcher3/config/FeatureFlags.java @@ -165,7 +165,7 @@ public final class FeatureFlags { // TODO(Block 5): Clean up flags public static final BooleanFlag ENABLE_TWOLINE_DEVICESEARCH = getDebugFlag(201388851, - "ENABLE_TWOLINE_DEVICESEARCH", ENABLED, + "ENABLE_TWOLINE_DEVICESEARCH", DISABLED, "Enable two line label for icons with labels on device search."); public static final BooleanFlag ENABLE_ICON_IN_TEXT_HEADER = getDebugFlag(270395143, @@ -281,10 +281,7 @@ public final class FeatureFlags { // Aconfig migration complete for ENABLE_TWOLINE_ALLAPPS. public static final BooleanFlag ENABLE_TWOLINE_ALLAPPS = getDebugFlag(270390937, - "ENABLE_TWOLINE_ALLAPPS", ENABLED, "Enables two line label inside all apps."); - public static boolean enableTwolineAllapps() { - return ENABLE_TWOLINE_ALLAPPS.get() || Flags.enableTwolineAllapps(); - } + "ENABLE_TWOLINE_ALLAPPS", DISABLED, "Enables two line label inside all apps."); public static final BooleanFlag IME_STICKY_SNACKBAR_EDU = getDebugFlag(270391693, "IME_STICKY_SNACKBAR_EDU", ENABLED, "Show sticky IME edu in AllApps"); diff --git a/tests/src/com/android/launcher3/AbstractDeviceProfileTest.kt b/tests/src/com/android/launcher3/AbstractDeviceProfileTest.kt index 3ba563d0df..ffcf83f303 100644 --- a/tests/src/com/android/launcher3/AbstractDeviceProfileTest.kt +++ b/tests/src/com/android/launcher3/AbstractDeviceProfileTest.kt @@ -38,17 +38,17 @@ import com.android.launcher3.util.rule.setFlags import com.android.launcher3.util.window.CachedDisplayInfo import com.android.launcher3.util.window.WindowManagerProxy import com.google.common.truth.Truth +import org.junit.Rule +import org.mockito.kotlin.any +import org.mockito.kotlin.mock +import org.mockito.kotlin.spy +import org.mockito.kotlin.whenever import java.io.BufferedReader import java.io.File import java.io.PrintWriter import java.io.StringWriter import kotlin.math.max import kotlin.math.min -import org.junit.Rule -import org.mockito.kotlin.any -import org.mockito.kotlin.mock -import org.mockito.kotlin.spy -import org.mockito.kotlin.whenever /** * This is an abstract class for DeviceProfile tests that create an InvariantDeviceProfile based on @@ -274,7 +274,8 @@ abstract class AbstractDeviceProfileTest { isGestureMode: Boolean = true, densityDpi: Int ) { - setFlagsRule.setFlags(false, Flags.FLAG_ENABLE_TWOLINE_TOGGLE) + setFlagsRule.setFlags(true, Flags.FLAG_ENABLE_TWOLINE_TOGGLE) + LauncherPrefs.get(testContext).put(LauncherPrefs.ENABLE_TWOLINE_ALLAPPS_TOGGLE, true) val windowsBounds = perDisplayBoundsCache[displayInfo]!! val realBounds = windowsBounds[rotation] whenever(windowManagerProxy.getDisplayInfo(any())).thenReturn(displayInfo) diff --git a/tests/src/com/android/launcher3/ui/BubbleTextViewTest.java b/tests/src/com/android/launcher3/ui/BubbleTextViewTest.java index 6df3ecd078..90ded100fe 100644 --- a/tests/src/com/android/launcher3/ui/BubbleTextViewTest.java +++ b/tests/src/com/android/launcher3/ui/BubbleTextViewTest.java @@ -22,7 +22,7 @@ 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.config.FeatureFlags.ENABLE_TWOLINE_ALLAPPS; +import static com.android.launcher3.LauncherPrefs.ENABLE_TWOLINE_ALLAPPS_TOGGLE; import static com.google.common.truth.Truth.assertThat; @@ -39,6 +39,7 @@ import android.view.ViewGroup; import com.android.launcher3.BubbleTextView; import com.android.launcher3.Flags; +import com.android.launcher3.LauncherPrefs; import com.android.launcher3.Utilities; import com.android.launcher3.model.data.AppInfo; import com.android.launcher3.model.data.ItemInfoWithIcon; @@ -46,7 +47,6 @@ import com.android.launcher3.search.StringMatcherUtility; import com.android.launcher3.util.ActivityContextWrapper; import com.android.launcher3.util.FlagOp; import com.android.launcher3.util.IntArray; -import com.android.launcher3.util.TestUtil; import com.android.launcher3.views.BaseDragLayer; import org.junit.Before; @@ -96,13 +96,14 @@ public class BubbleTextViewTest { private Context mContext; private int mLimitedWidth; private AppInfo mGmailAppInfo; + private LauncherPrefs mLauncherPrefs; @Before public void setUp() throws Exception { MockitoAnnotations.initMocks(this); Utilities.enableRunningInTestHarnessForTests(); - mSetFlagsRule.disableFlags(Flags.FLAG_ENABLE_TWOLINE_TOGGLE); mContext = new ActivityContextWrapper(getApplicationContext()); + mLauncherPrefs = LauncherPrefs.get(mContext); mBubbleTextView = new BubbleTextView(mContext); mBubbleTextView.reset(); @@ -130,190 +131,155 @@ public class BubbleTextViewTest { @Test public void testEmptyString_flagOn() { - mSetFlagsRule.enableFlags(Flags.FLAG_ENABLE_TWOLINE_ALLAPPS); - 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, LIMITED_HEIGHT); + mSetFlagsRule.enableFlags(Flags.FLAG_ENABLE_TWOLINE_TOGGLE); + mLauncherPrefs.put(ENABLE_TWOLINE_ALLAPPS_TOGGLE, true); + mItemInfoWithIcon.title = EMPTY_STRING; + mBubbleTextView.setDisplay(DISPLAY_ALL_APPS); + mBubbleTextView.applyLabel(mItemInfoWithIcon); + mBubbleTextView.setTypeface(Typeface.MONOSPACE); + mBubbleTextView.measure(mLimitedWidth, LIMITED_HEIGHT); - mBubbleTextView.onPreDraw(); + mBubbleTextView.onPreDraw(); - assertNotEquals(TWO_LINE, mBubbleTextView.getMaxLines()); - } catch (Exception e) { - throw new RuntimeException(e); - } + assertNotEquals(TWO_LINE, mBubbleTextView.getMaxLines()); } @Test public void testEmptyString_flagOff() { - mSetFlagsRule.disableFlags(Flags.FLAG_ENABLE_TWOLINE_ALLAPPS); - 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, LIMITED_HEIGHT); + mSetFlagsRule.disableFlags(Flags.FLAG_ENABLE_TWOLINE_TOGGLE); + mItemInfoWithIcon.title = EMPTY_STRING; + mBubbleTextView.setDisplay(DISPLAY_ALL_APPS); + mBubbleTextView.applyLabel(mItemInfoWithIcon); + mBubbleTextView.setTypeface(Typeface.MONOSPACE); + mBubbleTextView.measure(mLimitedWidth, LIMITED_HEIGHT); - mBubbleTextView.onPreDraw(); + mBubbleTextView.onPreDraw(); - assertEquals(ONE_LINE, mBubbleTextView.getLineCount()); - } catch (Exception e) { - throw new RuntimeException(e); - } + assertEquals(ONE_LINE, mBubbleTextView.getLineCount()); } @Test public void testStringWithSpaceLongerThanCharLimit_flagOn() { - mSetFlagsRule.enableFlags(Flags.FLAG_ENABLE_TWOLINE_ALLAPPS); - try (AutoCloseable flag = TestUtil.overrideFlag(ENABLE_TWOLINE_ALLAPPS, true)) { - // 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, MAX_HEIGHT); + mSetFlagsRule.enableFlags(Flags.FLAG_ENABLE_TWOLINE_TOGGLE); + mLauncherPrefs.put(ENABLE_TWOLINE_ALLAPPS_TOGGLE, true); + // 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, MAX_HEIGHT); - mBubbleTextView.onPreDraw(); + mBubbleTextView.onPreDraw(); - assertEquals(TWO_LINE, mBubbleTextView.getLineCount()); - } catch (Exception e) { - throw new RuntimeException(e); - } + assertEquals(TWO_LINE, mBubbleTextView.getLineCount()); } @Test public void testStringWithSpaceLongerThanCharLimit_flagOff() { - mSetFlagsRule.disableFlags(Flags.FLAG_ENABLE_TWOLINE_ALLAPPS); - try (AutoCloseable flag = TestUtil.overrideFlag(ENABLE_TWOLINE_ALLAPPS, false)) { - // 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, LIMITED_HEIGHT); + mSetFlagsRule.disableFlags(Flags.FLAG_ENABLE_TWOLINE_TOGGLE); + // 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, LIMITED_HEIGHT); - mBubbleTextView.onPreDraw(); + mBubbleTextView.onPreDraw(); - assertEquals(ONE_LINE, mBubbleTextView.getLineCount()); - } catch (Exception e) { - throw new RuntimeException(e); - } + assertEquals(ONE_LINE, mBubbleTextView.getLineCount()); } @Test public void testLongStringNoSpaceLongerThanCharLimit_flagOn() { - mSetFlagsRule.enableFlags(Flags.FLAG_ENABLE_TWOLINE_ALLAPPS); - try (AutoCloseable flag = TestUtil.overrideFlag(ENABLE_TWOLINE_ALLAPPS, true)) { - // 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, LIMITED_HEIGHT); + mSetFlagsRule.enableFlags(Flags.FLAG_ENABLE_TWOLINE_TOGGLE); + mLauncherPrefs.put(ENABLE_TWOLINE_ALLAPPS_TOGGLE, true); + // 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, LIMITED_HEIGHT); - mBubbleTextView.onPreDraw(); + mBubbleTextView.onPreDraw(); - assertEquals(ONE_LINE, mBubbleTextView.getLineCount()); - } catch (Exception e) { - throw new RuntimeException(e); - } + assertEquals(ONE_LINE, mBubbleTextView.getLineCount()); } @Test public void testLongStringNoSpaceLongerThanCharLimit_flagOff() { - mSetFlagsRule.disableFlags(Flags.FLAG_ENABLE_TWOLINE_ALLAPPS); - try (AutoCloseable flag = TestUtil.overrideFlag(ENABLE_TWOLINE_ALLAPPS, false)) { - // 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, LIMITED_HEIGHT); + mSetFlagsRule.disableFlags(Flags.FLAG_ENABLE_TWOLINE_TOGGLE); + // 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, LIMITED_HEIGHT); - mBubbleTextView.onPreDraw(); + mBubbleTextView.onPreDraw(); - assertEquals(ONE_LINE, mBubbleTextView.getLineCount()); - } catch (Exception e) { - throw new RuntimeException(e); - } + assertEquals(ONE_LINE, mBubbleTextView.getLineCount()); } @Test public void testLongStringWithSpaceLongerThanCharLimit_flagOn() { - mSetFlagsRule.enableFlags(Flags.FLAG_ENABLE_TWOLINE_ALLAPPS); - try (AutoCloseable flag = TestUtil.overrideFlag(ENABLE_TWOLINE_ALLAPPS, true)) { - // 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, MAX_HEIGHT); + mSetFlagsRule.enableFlags(Flags.FLAG_ENABLE_TWOLINE_TOGGLE); + mLauncherPrefs.put(ENABLE_TWOLINE_ALLAPPS_TOGGLE, true); + // 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, MAX_HEIGHT); - mBubbleTextView.onPreDraw(); + mBubbleTextView.onPreDraw(); - assertEquals(TWO_LINE, mBubbleTextView.getLineCount()); - } catch (Exception e) { - throw new RuntimeException(e); - } + assertEquals(TWO_LINE, mBubbleTextView.getLineCount()); } @Test public void testLongStringWithSpaceLongerThanCharLimit_flagOff() { - mSetFlagsRule.disableFlags(Flags.FLAG_ENABLE_TWOLINE_ALLAPPS); - try (AutoCloseable flag = TestUtil.overrideFlag(ENABLE_TWOLINE_ALLAPPS, false)) { - // 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, LIMITED_HEIGHT); + mSetFlagsRule.disableFlags(Flags.FLAG_ENABLE_TWOLINE_TOGGLE); + // 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, LIMITED_HEIGHT); - mBubbleTextView.onPreDraw(); + mBubbleTextView.onPreDraw(); - assertEquals(ONE_LINE, mBubbleTextView.getLineCount()); - } catch (Exception e) { - throw new RuntimeException(e); - } + assertEquals(ONE_LINE, mBubbleTextView.getLineCount()); } @Test public void testLongStringSymbolLongerThanCharLimit_flagOn() { - mSetFlagsRule.enableFlags(Flags.FLAG_ENABLE_TWOLINE_ALLAPPS); - try (AutoCloseable flag = TestUtil.overrideFlag(ENABLE_TWOLINE_ALLAPPS, true)) { - // 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, MAX_HEIGHT); + mSetFlagsRule.enableFlags(Flags.FLAG_ENABLE_TWOLINE_TOGGLE); + mLauncherPrefs.put(ENABLE_TWOLINE_ALLAPPS_TOGGLE, true); + // 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, MAX_HEIGHT); - mBubbleTextView.onPreDraw(); + mBubbleTextView.onPreDraw(); - assertEquals(TWO_LINE, mBubbleTextView.getLineCount()); - } catch (Exception e) { - throw new RuntimeException(e); - } + assertEquals(TWO_LINE, mBubbleTextView.getLineCount()); } @Test public void testLongStringSymbolLongerThanCharLimit_flagOff() { - mSetFlagsRule.disableFlags(Flags.FLAG_ENABLE_TWOLINE_ALLAPPS); - try (AutoCloseable flag = TestUtil.overrideFlag(ENABLE_TWOLINE_ALLAPPS, false)) { - // 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, LIMITED_HEIGHT); + mSetFlagsRule.disableFlags(Flags.FLAG_ENABLE_TWOLINE_TOGGLE); + // 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, LIMITED_HEIGHT); - mBubbleTextView.onPreDraw(); + mBubbleTextView.onPreDraw(); - assertEquals(ONE_LINE, mBubbleTextView.getLineCount()); - } catch (Exception e) { - throw new RuntimeException(e); - } + assertEquals(ONE_LINE, mBubbleTextView.getLineCount()); } @Test @@ -374,58 +340,49 @@ public class BubbleTextViewTest { @Test public void testEnsurePredictionRowIsTwoLine() { - mSetFlagsRule.enableFlags(Flags.FLAG_ENABLE_TWOLINE_ALLAPPS); - 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, MAX_HEIGHT); + mSetFlagsRule.enableFlags(Flags.FLAG_ENABLE_TWOLINE_TOGGLE); + mLauncherPrefs.put(ENABLE_TWOLINE_ALLAPPS_TOGGLE, 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, MAX_HEIGHT); - mBubbleTextView.onPreDraw(); + mBubbleTextView.onPreDraw(); - assertEquals(TWO_LINE, mBubbleTextView.getLineCount()); - } catch (Exception e) { - throw new RuntimeException(e); - } + assertEquals(TWO_LINE, mBubbleTextView.getLineCount()); } @Test public void modifyTitleToSupportMultiLine_whenLimitedHeight_shouldBeOneLine() { - mSetFlagsRule.enableFlags(Flags.FLAG_ENABLE_TWOLINE_ALLAPPS); - try (AutoCloseable flag = TestUtil.overrideFlag(ENABLE_TWOLINE_ALLAPPS, true)) { - // test string: "LEGO®Builder" - mItemInfoWithIcon.title = TEST_LONG_STRING_SYMBOL_LONGER_THAN_CHAR_LIMIT; - mBubbleTextView.applyLabel(mItemInfoWithIcon); - mBubbleTextView.setTypeface(Typeface.MONOSPACE); - mBubbleTextView.measure(mLimitedWidth, LIMITED_HEIGHT); + mSetFlagsRule.enableFlags(Flags.FLAG_ENABLE_TWOLINE_TOGGLE); + mLauncherPrefs.put(ENABLE_TWOLINE_ALLAPPS_TOGGLE, true); + // test string: "LEGO®Builder" + mItemInfoWithIcon.title = TEST_LONG_STRING_SYMBOL_LONGER_THAN_CHAR_LIMIT; + mBubbleTextView.applyLabel(mItemInfoWithIcon); + mBubbleTextView.setTypeface(Typeface.MONOSPACE); + mBubbleTextView.measure(mLimitedWidth, LIMITED_HEIGHT); - mBubbleTextView.onPreDraw(); + mBubbleTextView.onPreDraw(); - assertEquals(ONE_LINE, mBubbleTextView.getLineCount()); - } catch (Exception e) { - throw new RuntimeException(e); - } + assertEquals(ONE_LINE, mBubbleTextView.getLineCount()); } @Test public void modifyTitleToSupportMultiLine_whenUnlimitedHeight_shouldBeTwoLine() { - mSetFlagsRule.enableFlags(Flags.FLAG_ENABLE_TWOLINE_ALLAPPS); - try (AutoCloseable flag = TestUtil.overrideFlag(ENABLE_TWOLINE_ALLAPPS, true)) { - // test string: "LEGO®Builder" - mItemInfoWithIcon.title = TEST_LONG_STRING_SYMBOL_LONGER_THAN_CHAR_LIMIT; - mBubbleTextView.setDisplay(DISPLAY_ALL_APPS); - mBubbleTextView.applyLabel(mItemInfoWithIcon); - mBubbleTextView.setTypeface(Typeface.MONOSPACE); - mBubbleTextView.measure(mLimitedWidth, MAX_HEIGHT); + mSetFlagsRule.enableFlags(Flags.FLAG_ENABLE_TWOLINE_TOGGLE); + mLauncherPrefs.put(ENABLE_TWOLINE_ALLAPPS_TOGGLE, true); + // test string: "LEGO®Builder" + mItemInfoWithIcon.title = TEST_LONG_STRING_SYMBOL_LONGER_THAN_CHAR_LIMIT; + mBubbleTextView.setDisplay(DISPLAY_ALL_APPS); + mBubbleTextView.applyLabel(mItemInfoWithIcon); + mBubbleTextView.setTypeface(Typeface.MONOSPACE); + mBubbleTextView.measure(mLimitedWidth, MAX_HEIGHT); - mBubbleTextView.onPreDraw(); + mBubbleTextView.onPreDraw(); - assertEquals(TWO_LINE, mBubbleTextView.getLineCount()); - } catch (Exception e) { - throw new RuntimeException(e); - } + assertEquals(TWO_LINE, mBubbleTextView.getLineCount()); } @Test