From 24284467b5b2ac334629e8aa320c476c1c5bc7ce Mon Sep 17 00:00:00 2001 From: Jeremy Sim Date: Tue, 2 Apr 2024 15:49:42 -0700 Subject: [PATCH] Fix bug where app pair title was not updating with language This CL adds the ability for an app pair icon to update its title string when package changes are detected. It also reorganizes some code in the app pairs classes for readability. Fixes: 316051810 Flag: ACONFIG com.android.wm.shell.enable_app_pairs TRUNKFOOD Test: Manual Change-Id: I833e4f9766b7da8c0a3a5fb4b9fc050d8897437e --- .../quickstep/util/AppPairsController.java | 10 ----- .../launcher3/apppairs/AppPairIcon.java | 37 +++++++++++++++---- .../launcher3/apppairs/AppPairIconGraphic.kt | 8 +--- .../launcher3/model/data/AppPairInfo.kt | 19 ++++++++++ 4 files changed, 49 insertions(+), 25 deletions(-) diff --git a/quickstep/src/com/android/quickstep/util/AppPairsController.java b/quickstep/src/com/android/quickstep/util/AppPairsController.java index 59bf10533c..3ed3e40ca7 100644 --- a/quickstep/src/com/android/quickstep/util/AppPairsController.java +++ b/quickstep/src/com/android/quickstep/util/AppPairsController.java @@ -45,7 +45,6 @@ import com.android.internal.jank.Cuj; import com.android.launcher3.Launcher; import com.android.launcher3.LauncherAppState; import com.android.launcher3.LauncherSettings; -import com.android.launcher3.R; import com.android.launcher3.accessibility.LauncherAccessibilityDelegate; import com.android.launcher3.allapps.AllAppsStore; import com.android.launcher3.apppairs.AppPairIcon; @@ -158,8 +157,6 @@ public class AppPairsController { member.bitmap = iconCache.getDefaultIcon(newAppPair.user); iconCache.getTitleAndIcon(member, member.usingLowResIcon()); }); - newAppPair.title = getDefaultTitle(newAppPair.getFirstApp().title, - newAppPair.getSecondApp().title); MAIN_EXECUTOR.execute(() -> { LauncherAccessibilityDelegate delegate = Launcher.getLauncher(mContext).getAccessibilityDelegate(); @@ -488,13 +485,6 @@ public class AppPairsController { return rank & BITMASK_FOR_SNAP_POSITION; } - /** - * Returns a formatted default title for the app pair. - */ - public String getDefaultTitle(CharSequence app1, CharSequence app2) { - return mContext.getString(R.string.app_pair_default_title, app1, app2); - } - /** * Gets the TopTaskTracker, which is a cached record of the top running Task. */ diff --git a/src/com/android/launcher3/apppairs/AppPairIcon.java b/src/com/android/launcher3/apppairs/AppPairIcon.java index 8e82d89115..0e955adb56 100644 --- a/src/com/android/launcher3/apppairs/AppPairIcon.java +++ b/src/com/android/launcher3/apppairs/AppPairIcon.java @@ -110,22 +110,42 @@ public class AppPairIcon extends FrameLayout implements DraggableView, Reorderab // For some reason, app icons have setIncludeFontPadding(false) inside folders, so we set it // here to match that. icon.mAppPairName.setIncludeFontPadding(container != DISPLAY_FOLDER); - icon.mAppPairName.applyLabel(appPairInfo); + // Set title text and accessibility title text. + icon.updateTitleAndA11yTitle(); - // Set up accessibility - icon.setContentDescription(icon.getAccessibilityTitle(appPairInfo)); icon.setAccessibilityDelegate(activity.getAccessibilityDelegate()); return icon; } /** - * Returns a formatted accessibility title for app pairs. + * Updates the title and a11y title of the app pair. Called on creation and when packages + * change, to reflect app name changes or user language changes. */ - public String getAccessibilityTitle(AppPairInfo appPairInfo) { - CharSequence app1 = appPairInfo.getFirstApp().title; - CharSequence app2 = appPairInfo.getSecondApp().title; - return getContext().getString(R.string.app_pair_name_format, app1, app2); + public void updateTitleAndA11yTitle() { + updateTitleAndTextView(); + updateAccessibilityTitle(); + } + + /** + * Updates AppPairInfo with a formatted app pair title, and sets it on the BubbleTextView. + */ + public void updateTitleAndTextView() { + CharSequence newTitle = getInfo().generateTitle(getContext()); + mAppPairName.setText(newTitle); + } + + /** + * Updates the accessibility title with a formatted string template. + */ + public void updateAccessibilityTitle() { + CharSequence app1 = getInfo().getFirstApp().title; + CharSequence app2 = getInfo().getSecondApp().title; + String a11yTitle = getContext().getString(R.string.app_pair_name_format, app1, app2); + setContentDescription( + getInfo().shouldDrawAsDisabled(getContext()) + ? getContext().getString(R.string.disabled_app_label, a11yTitle) + : a11yTitle); } // Required for DraggableView @@ -200,6 +220,7 @@ public class AppPairIcon extends FrameLayout implements DraggableView, Reorderab // If either of the app pair icons return true on the predicate (i.e. in the list of // updated apps), redraw the icon graphic (icon background and both icons). if (getInfo().anyMatch(itemCheck)) { + updateTitleAndA11yTitle(); mIconGraphic.redraw(); } } diff --git a/src/com/android/launcher3/apppairs/AppPairIconGraphic.kt b/src/com/android/launcher3/apppairs/AppPairIconGraphic.kt index a974133755..7809102150 100644 --- a/src/com/android/launcher3/apppairs/AppPairIconGraphic.kt +++ b/src/com/android/launcher3/apppairs/AppPairIconGraphic.kt @@ -42,13 +42,7 @@ constructor(context: Context, attrs: AttributeSet? = null) : private val TAG = "AppPairIconGraphic" companion object { - /** - * Composes a drawable for this icon, consisting of a background and 2 app icons. The app - * pair will draw as "disabled" if either of the following is true: - * 1) One of the member WorkspaceItemInfos is disabled (i.e. the app software itself is - * paused or can't be launched for some other reason). - * 2) One of the member apps can't be launched due to screen size requirements. - */ + /** Composes a drawable for this icon, consisting of a background and 2 app icons. */ @JvmStatic fun composeDrawable( appPairInfo: AppPairInfo, diff --git a/src/com/android/launcher3/model/data/AppPairInfo.kt b/src/com/android/launcher3/model/data/AppPairInfo.kt index 63c77bb755..fad365c43d 100644 --- a/src/com/android/launcher3/model/data/AppPairInfo.kt +++ b/src/com/android/launcher3/model/data/AppPairInfo.kt @@ -18,6 +18,7 @@ package com.android.launcher3.model.data import android.content.Context import com.android.launcher3.LauncherSettings +import com.android.launcher3.R import com.android.launcher3.icons.IconCache import com.android.launcher3.logger.LauncherAtom import com.android.launcher3.views.ActivityContext @@ -81,6 +82,24 @@ class AppPairInfo() : CollectionInfo() { } } + /** + * App pairs will draw as "disabled" if either of the following is true: + * 1) One of the member WorkspaceItemInfos is disabled (i.e. the app software itself is paused + * or can't be launched for some other reason). + * 2) One of the member apps can't be launched due to screen size requirements. + */ + fun shouldDrawAsDisabled(context: Context): Boolean { + return isDisabled || !isLaunchable(context) + } + + /** Generates a default title for the app pair and sets it. */ + fun generateTitle(context: Context): CharSequence? { + val app1: CharSequence? = getFirstApp().title + val app2: CharSequence? = getSecondApp().title + title = context.getString(R.string.app_pair_default_title, app1, app2) + return title + } + /** Generates an ItemInfo for logging. */ override fun buildProto(cInfo: CollectionInfo?): LauncherAtom.ItemInfo { val appPairIcon = LauncherAtom.FolderIcon.newBuilder().setCardinality(contents.size)