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

Commit 05e0835a authored by Josep del Rio's avatar Josep del Rio
Browse files

Show current app name shortcut helper

At the moment, the shortcut helper will not show the name of the
current app, just its shortcuts, which makes it a bit confusing.
This CL addresses that. Icon will be added on a later CL once
the styling has been fully defined.

Bug: 325252986
Test: Flashed on device, tested with Keep, Launcher and Chrome
Flag: NONE
Change-Id: Ie39645e8de7185f01e3997ed2ab1c3718e8f128f
parent c2471884
Loading
Loading
Loading
Loading
+20 −0
Original line number Diff line number Diff line
@@ -35,6 +35,8 @@ public final class KeyboardShortcutGroup implements Parcelable {
    private final List<KeyboardShortcutInfo> mItems;
    // The system group looks different UI wise.
    private boolean mSystemGroup;
    // The package name for the shortcut
    private CharSequence mPackageName;

    /**
     * @param label The title to be used for this group, or null if there is none.
@@ -82,6 +84,7 @@ public final class KeyboardShortcutGroup implements Parcelable {
        mLabel = source.readCharSequence();
        source.readTypedList(mItems, KeyboardShortcutInfo.CREATOR);
        mSystemGroup = source.readInt() == 1;
        mPackageName = source.readCharSequence();
    }

    /**
@@ -104,6 +107,22 @@ public final class KeyboardShortcutGroup implements Parcelable {
        return mSystemGroup;
    }

    /**
     * @param packageName the name of the package associated with this shortcut.
     * @hide
     */
    public void setPackageName(CharSequence packageName) {
        mPackageName = packageName;
    }

    /**
     * Return the package name of the app associated with this shortcut.
     * @hide
     */
    public CharSequence getPackageName() {
        return mPackageName;
    }

    /**
     * Adds an item to the existing list.
     *
@@ -123,6 +142,7 @@ public final class KeyboardShortcutGroup implements Parcelable {
        dest.writeCharSequence(mLabel);
        dest.writeTypedList(mItems);
        dest.writeInt(mSystemGroup ? 1 : 0);
        dest.writeCharSequence(mPackageName);
    }

    public static final @android.annotation.NonNull Creator<KeyboardShortcutGroup> CREATOR =
+6 −0
Original line number Diff line number Diff line
@@ -8612,6 +8612,12 @@ public final class ViewRootImpl implements ViewParent,
        if (mView != null) {
            mView.requestKeyboardShortcuts(list, deviceId);
        }
        int numGroups = list.size();
        for (int i = 0; i < numGroups; ++i) {
            final KeyboardShortcutGroup group = list.get(i);
            group.setPackageName(mBasePackageName);
        }
        data.putParcelableArrayList(WindowManager.PARCEL_KEY_SHORTCUTS_ARRAY, list);
        try {
            receiver.send(0, data);
+43 −0
Original line number Diff line number Diff line
@@ -25,8 +25,11 @@ import android.app.AppGlobals;
import android.content.ComponentName;
import android.content.Context;
import android.content.Intent;
import android.content.pm.ApplicationInfo;
import android.content.pm.IPackageManager;
import android.content.pm.PackageInfo;
import android.content.pm.PackageManager;
import android.content.pm.PackageManager.NameNotFoundException;
import android.content.pm.ResolveInfo;
import android.content.res.Configuration;
import android.graphics.Matrix;
@@ -71,6 +74,7 @@ import com.android.internal.logging.MetricsLogger;
import com.android.internal.logging.nano.MetricsProto;
import com.android.settingslib.Utils;
import com.android.systemui.res.R;
import com.android.systemui.statusbar.phone.CentralSurfaces;

import com.google.android.material.bottomsheet.BottomSheetBehavior;
import com.google.android.material.bottomsheet.BottomSheetDialog;
@@ -114,6 +118,7 @@ public final class KeyboardShortcutListSearch {
    private Button mButtonInput;
    private Button mButtonOpenApps;
    private Button mButtonSpecificApp;
    private CharSequence mCurrentAppPackageName;
    private TextView mNoSearchResults;

    private final SparseArray<String> mSpecialCharacterNames = new SparseArray<>();
@@ -412,8 +417,10 @@ public final class KeyboardShortcutListSearch {
        mWindowManager.requestAppKeyboardShortcuts(result -> {
            // Add specific app shortcuts
            if (result.isEmpty()) {
                mCurrentAppPackageName = null;
                mKeySearchResultMap.put(SHORTCUT_SPECIFICAPP_INDEX, false);
            } else {
                mCurrentAppPackageName = result.get(0).getPackageName();
                mSpecificAppGroup.addAll(reMapToKeyboardShortcutMultiMappingGroup(result));
                mKeySearchResultMap.put(SHORTCUT_SPECIFICAPP_INDEX, true);
            }
@@ -823,6 +830,7 @@ public final class KeyboardShortcutListSearch {
        mNoSearchResults = keyboardShortcutsView.findViewById(R.id.shortcut_search_no_result);
        mKeyboardShortcutsBottomSheetDialog.setContentView(keyboardShortcutsView);
        setButtonsDefaultStatus(keyboardShortcutsView);
        populateCurrentAppButton();
        populateKeyboardShortcutSearchList(shortcutsContainer);

        // Workaround for solve issue about dialog not full expanded when landscape.
@@ -1272,6 +1280,41 @@ public final class KeyboardShortcutListSearch {
        mFullButtonList.add(mButtonSpecificApp);
    }

    private void resetCurrentAppButton() {
        if (mButtonSpecificApp == null) {
            return;
        }
        mButtonSpecificApp.setText(
                mContext.getString(R.string.keyboard_shortcut_search_category_current_app));
        // TODO(b/325252986): Reset icon once the icon is implemented
    }

    private void populateCurrentAppButton() {
        if (mButtonSpecificApp == null) {
            return;
        }
        if (mCurrentAppPackageName != null) {
            final int userId = mContext.getUserId();
            try {
                PackageManager pmUser = CentralSurfaces.getPackageManagerForUser(
                        mContext,
                        userId);
                ApplicationInfo appInfo = pmUser.getApplicationInfoAsUser(
                        mCurrentAppPackageName.toString(),
                        0,
                        userId);
                // According to the API, we will always get a label
                mButtonSpecificApp.setText(pmUser.getApplicationLabel(appInfo));
                // TODO(b/325252986): Show icon once it has been defined
            } catch (NameNotFoundException e) {
                Log.e(TAG, "Package name not found", e);
                resetCurrentAppButton();
            }
        } else {
            resetCurrentAppButton();
        }
    }

    private void setButtonFocusColor(int i, boolean isFocused) {
        if (isFocused) {
            mFullButtonList.get(i).setTextColor(getColorOfTextColorOnAccent());