From 5787a2710cdb3511f0f93f3a9e080dc1985e4e51 Mon Sep 17 00:00:00 2001 From: Brandon Dayauon Date: Thu, 14 Dec 2023 13:47:17 -0800 Subject: [PATCH] Add home settings toggle featureflag for enablingTwoLineText - Have shouldUseTwoLine() be decided with the home settings toggle value bug:316027081 spec: https://www.figma.com/file/uMzPkNMZpb7EyfHDo8usIa/V-%E2%80%A2-Toast-Butter?type=design&node-id=405-384593&mode=design&t=UBkdeuNlAdRh2FGU-0 Test: Video: https://drive.google.com/file/d/15VUhNVro2fiwv3SzMda1StiPb3PV1eMT/view?usp=sharing before searchPreferenceScreen: https://screenshot.googleplex.com/3uqdMsZoGSBYb6c after searchPreferenceScreen: https://drive.google.com/file/d/15dswiHRTnafyhgQA_tL2tRc7vHFWdHbZ/view?usp=sharing before homeSettingsPage: https://screenshot.googleplex.com/7wsNevxGun2KCCB after homeSettingsPage: https://drive.google.com/file/d/15m5bjEyewlNHI_h26aygHa7zrgZ5qDF6/view?usp=sharing AppListSettingsPage: https://drive.google.com/file/d/15hl4ScHBOLgKv3M38HtatMxQw85pgl7t/view?usp=sharing Flag: enableTwolineToggle DEVELOPMENT Change-Id: I3ad133dd51dcb97e14ccded730e7737c5049261a --- aconfig/launcher.aconfig | 7 +++++++ .../appprediction/PredictionRowView.java | 5 ++++- .../taskbar/TaskbarActivityContext.java | 2 +- src/com/android/launcher3/BubbleTextView.java | 6 ++++-- src/com/android/launcher3/DeviceProfile.java | 18 ++++++++++-------- src/com/android/launcher3/LauncherPrefs.kt | 2 ++ .../launcher3/allapps/BaseAllAppsAdapter.java | 9 +++++++-- 7 files changed, 35 insertions(+), 14 deletions(-) diff --git a/aconfig/launcher.aconfig b/aconfig/launcher.aconfig index 6d899d90e5..06943fbdac 100644 --- a/aconfig/launcher.aconfig +++ b/aconfig/launcher.aconfig @@ -15,6 +15,13 @@ flag { bug: "270390937" } +flag { + name: "enable_twoline_toggle" + namespace: "launcher" + description: "Enables visibility in home settings to see the toggle to turn on/off two lines in all apps." + bug: "316027081" +} + flag { name: "enable_grid_only_overview" namespace: "launcher" diff --git a/quickstep/src/com/android/launcher3/appprediction/PredictionRowView.java b/quickstep/src/com/android/launcher3/appprediction/PredictionRowView.java index caf8a0bf1e..e1443d0987 100644 --- a/quickstep/src/com/android/launcher3/appprediction/PredictionRowView.java +++ b/quickstep/src/com/android/launcher3/appprediction/PredictionRowView.java @@ -31,6 +31,7 @@ import com.android.launcher3.BubbleTextView; import com.android.launcher3.DeviceProfile; import com.android.launcher3.DeviceProfile.OnDeviceProfileChangeListener; import com.android.launcher3.Flags; +import com.android.launcher3.LauncherPrefs; import com.android.launcher3.R; import com.android.launcher3.Utilities; import com.android.launcher3.allapps.FloatingHeaderRow; @@ -137,7 +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() ? textHeight : mTopRowExtraHeight; + int extraHeight = (FeatureFlags.enableTwolineAllapps() && (!Flags.enableTwolineToggle() + || (Flags.enableTwolineToggle() && LauncherPrefs.ENABLE_TWOLINE_ALLAPPS_TOGGLE.get( + getContext())))) ? textHeight : mTopRowExtraHeight; totalHeight += extraHeight; return getVisibility() == GONE ? 0 : totalHeight + getPaddingTop() + getPaddingBottom(); } diff --git a/quickstep/src/com/android/launcher3/taskbar/TaskbarActivityContext.java b/quickstep/src/com/android/launcher3/taskbar/TaskbarActivityContext.java index 55deca884b..e0bf39fda1 100644 --- a/quickstep/src/com/android/launcher3/taskbar/TaskbarActivityContext.java +++ b/quickstep/src/com/android/launcher3/taskbar/TaskbarActivityContext.java @@ -329,7 +329,7 @@ public class TaskbarActivityContext extends BaseTaskbarContext { // Update icon size deviceProfile.iconSizePx = deviceProfile.taskbarIconSize; - deviceProfile.updateIconSize(1f, getResources()); + deviceProfile.updateIconSize(1f, this); }; mDeviceProfile = originDeviceProfile.toBuilder(this) .withDimensionsOverride(overrideProvider).build(); diff --git a/src/com/android/launcher3/BubbleTextView.java b/src/com/android/launcher3/BubbleTextView.java index 2f0c0968e9..5bec5061b3 100644 --- a/src/com/android/launcher3/BubbleTextView.java +++ b/src/com/android/launcher3/BubbleTextView.java @@ -422,8 +422,10 @@ 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); + return FeatureFlags.enableTwolineAllapps() && isCurrentLanguageEnglish() + && (mDisplay == DISPLAY_ALL_APPS || mDisplay == DISPLAY_PREDICTION_ROW) + && (!Flags.enableTwolineToggle() || (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 563dfe2f20..c505d9c5c4 100644 --- a/src/com/android/launcher3/DeviceProfile.java +++ b/src/com/android/launcher3/DeviceProfile.java @@ -714,7 +714,7 @@ public class DeviceProfile { } // Calculate all of the remaining variables. - extraSpace = updateAvailableDimensions(res); + extraSpace = updateAvailableDimensions(context); calculateAndSetWorkspaceVerticalPadding(context, inv, extraSpace); @@ -1006,14 +1006,14 @@ public class DeviceProfile { /** * Returns the amount of extra (or unused) vertical space. */ - private int updateAvailableDimensions(Resources res) { + private int updateAvailableDimensions(Context context) { iconCenterVertically = (mIsScalableGrid || mIsResponsiveGrid) && isVerticalBarLayout(); if (mIsResponsiveGrid) { iconSizePx = mResponsiveWorkspaceCellSpec.getIconSize(); iconTextSizePx = mResponsiveWorkspaceCellSpec.getIconTextSize(); mIconDrawablePaddingOriginalPx = mResponsiveWorkspaceCellSpec.getIconDrawablePadding(); - updateIconSize(1f, res); + updateIconSize(1f, context); updateWorkspacePadding(); return 0; } @@ -1023,7 +1023,7 @@ public class DeviceProfile { iconSizePx = Math.max(1, pxFromDp(invIconSizeDp, mMetrics)); iconTextSizePx = pxFromSp(invIconTextSizeSp, mMetrics); - updateIconSize(1f, res); + updateIconSize(1f, context); updateWorkspacePadding(); // Check to see if the icons fit within the available height. @@ -1047,7 +1047,7 @@ public class DeviceProfile { if (shouldScale) { float scale = Math.min(scaleX, scaleY); - updateIconSize(scale, res); + updateIconSize(scale, context); extraHeight = Math.max(0, maxHeight - getCellLayoutHeightSpecification()); } @@ -1093,7 +1093,7 @@ public class DeviceProfile { * iconTextSizePx, iconDrawablePaddingPx, cellWidth/Height, allApps* variants, * hotseat sizes, workspaceSpringLoadedShrinkFactor, folderIconSizePx, and folderIconOffsetYPx. */ - public void updateIconSize(float scale, Resources res) { + public void updateIconSize(float scale, Context context) { // Icon scale should never exceed 1, otherwise pixellation may occur. iconScale = Math.min(1f, scale); cellScaleToFit = scale; @@ -1213,13 +1213,15 @@ public class DeviceProfile { if (mIsResponsiveGrid) { updateAllAppsWithResponsiveMeasures(); } else { - updateAllAppsIconSize(scale, res); + updateAllAppsIconSize(scale, context.getResources()); } updateAllAppsContainerWidth(); if (isVerticalLayout && !mIsResponsiveGrid) { hideWorkspaceLabelsIfNotEnoughSpace(); } - if (FeatureFlags.enableTwolineAllapps()) { + if (FeatureFlags.enableTwolineAllapps() + && (!Flags.enableTwolineToggle() || (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/LauncherPrefs.kt b/src/com/android/launcher3/LauncherPrefs.kt index 3b62ae1cff..b0a644b269 100644 --- a/src/com/android/launcher3/LauncherPrefs.kt +++ b/src/com/android/launcher3/LauncherPrefs.kt @@ -349,6 +349,8 @@ class LauncherPrefs(private val encryptedContext: Context) { @JvmField val PRIVATE_SPACE_APPS = nonRestorableItem("pref_private_space_apps", 0, EncryptionType.MOVE_TO_DEVICE_PROTECTED) + @JvmField val ENABLE_TWOLINE_ALLAPPS_TOGGLE = + backedUpItem("pref_enable_two_line_toggle", false) @JvmField val THEMED_ICONS = backedUpItem(Themes.KEY_THEMED_ICONS, false, EncryptionType.MOVE_TO_DEVICE_PROTECTED) diff --git a/src/com/android/launcher3/allapps/BaseAllAppsAdapter.java b/src/com/android/launcher3/allapps/BaseAllAppsAdapter.java index 28c87b6fa7..f9ad352138 100644 --- a/src/com/android/launcher3/allapps/BaseAllAppsAdapter.java +++ b/src/com/android/launcher3/allapps/BaseAllAppsAdapter.java @@ -36,6 +36,8 @@ import androidx.annotation.Nullable; import androidx.recyclerview.widget.RecyclerView; import com.android.launcher3.BubbleTextView; +import com.android.launcher3.Flags; +import com.android.launcher3.LauncherPrefs; import com.android.launcher3.R; import com.android.launcher3.allapps.search.SearchAdapterProvider; import com.android.launcher3.config.FeatureFlags; @@ -221,8 +223,11 @@ public abstract class BaseAllAppsAdapter ex public ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) { switch (viewType) { case VIEW_TYPE_ICON: - int layout = !FeatureFlags.enableTwolineAllapps() ? R.layout.all_apps_icon - : R.layout.all_apps_icon_twoline; + int layout = (FeatureFlags.enableTwolineAllapps() && + (!Flags.enableTwolineToggle() || (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); icon.setLongPressTimeoutFactor(1f);