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

Commit fa3eae99 authored by Jeremy Sim's avatar Jeremy Sim Committed by Android (Google) Code Review
Browse files

Merge "Fix bug where app pair title was not updating with language" into main

parents fe1a9c36 24284467
Loading
Loading
Loading
Loading
+0 −10
Original line number Diff line number Diff line
@@ -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.
     */
+29 −8
Original line number Diff line number Diff line
@@ -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();
        }
    }
+1 −7
Original line number Diff line number Diff line
@@ -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,
+19 −0
Original line number Diff line number Diff line
@@ -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)