From 9c651747600b56e85e87c4cd0da8c445cc98c224 Mon Sep 17 00:00:00 2001 From: Brandon Dayauon Date: Mon, 21 Oct 2024 17:25:22 -0700 Subject: [PATCH] Set twoline toggle to false when not in english language. Set toggle preference in deviceProfile as this is the first step after the locale change before any binding/inflation happens. Otherwise the toggle will be stale if we set this false during "apply"/bind which can cause complexities. bug:373670311 Test manually vid: https://drive.google.com/file/d/1WXl_fMU8eynwlxdwYBamEnqP1tU_q0kb/view?usp=sharing Flag: NONE bugfix Change-Id: Iaf9e88ef76ebda6b62942b7bc3f4e39b4ced5116 --- src/com/android/launcher3/DeviceProfile.java | 11 +++++++++-- src/com/android/launcher3/Utilities.java | 8 ++++++++ 2 files changed, 17 insertions(+), 2 deletions(-) diff --git a/src/com/android/launcher3/DeviceProfile.java b/src/com/android/launcher3/DeviceProfile.java index 1e7fd7f57d..3ca6ce419c 100644 --- a/src/com/android/launcher3/DeviceProfile.java +++ b/src/com/android/launcher3/DeviceProfile.java @@ -24,6 +24,7 @@ import static com.android.launcher3.InvariantDeviceProfile.INDEX_LANDSCAPE; import static com.android.launcher3.InvariantDeviceProfile.INDEX_TWO_PANEL_LANDSCAPE; import static com.android.launcher3.InvariantDeviceProfile.INDEX_TWO_PANEL_PORTRAIT; import static com.android.launcher3.Utilities.dpiFromPx; +import static com.android.launcher3.Utilities.isEnglishLanguage; import static com.android.launcher3.Utilities.pxFromSp; import static com.android.launcher3.folder.ClippedFolderIconLayoutRule.ICON_OVERLAP_FACTOR; import static com.android.launcher3.icons.GraphicsUtils.getShapePath; @@ -1344,8 +1345,14 @@ public class DeviceProfile { } if ((Flags.enableTwolineToggle() && LauncherPrefs.ENABLE_TWOLINE_ALLAPPS_TOGGLE.get(context))) { - // Add extra textHeight to the existing allAppsCellHeight. - allAppsCellHeightPx += Utilities.calculateTextHeight(allAppsIconTextSizePx); + if (!isEnglishLanguage(context)) { + // Set toggle preference value to false if not english here as it's possible the + // preference is stale after language change. + LauncherPrefs.get(context).put(LauncherPrefs.ENABLE_TWOLINE_ALLAPPS_TOGGLE, false); + } else { + // Add extra textHeight to the existing allAppsCellHeight. + allAppsCellHeightPx += Utilities.calculateTextHeight(allAppsIconTextSizePx); + } } updateHotseatSizes(iconSizePx); diff --git a/src/com/android/launcher3/Utilities.java b/src/com/android/launcher3/Utilities.java index 9192e13cd0..71a2589dc7 100644 --- a/src/com/android/launcher3/Utilities.java +++ b/src/com/android/launcher3/Utilities.java @@ -615,6 +615,14 @@ public final class Utilities { return options; } + /** + * Utility method to know if a device's primary language is English. + */ + public static boolean isEnglishLanguage(Context context) { + return context.getResources().getConfiguration().locale.getLanguage() + .equals(Locale.ENGLISH.getLanguage()); + } + /** * Returns the full drawable for info as multiple layers of AdaptiveIconDrawable. The second * drawable in the Pair is the badge used with the icon.