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

Commit 1e3d490e authored by Tony Wickham's avatar Tony Wickham Committed by Android (Google) Code Review
Browse files

Merge "Implement ranking for shortcuts." into ub-launcher3-calgary

parents bbff2926 2c99d2ce
Loading
Loading
Loading
Loading
+5 −3
Original line number Diff line number Diff line
@@ -81,11 +81,13 @@ public class DeepShortcutManager {
    }

    /**
     * Gets all the shortcuts associated with the given package and user.
     * Gets all the manifest and dynamic shortcuts associated with the given package and user,
     * to be displayed in the shortcuts container on long press.
     */
    public List<ShortcutInfoCompat> queryForAllAppShortcuts(ComponentName activity,
    public List<ShortcutInfoCompat> queryForShortcutsContainer(ComponentName activity,
            List<String> ids, UserHandleCompat user) {
        return query(FLAG_GET_ALL, activity.getPackageName(), activity, ids, user);
        return query(FLAG_MATCH_MANIFEST | FLAG_MATCH_DYNAMIC,
                activity.getPackageName(), activity, ids, user);
    }

    /**
+27 −1
Original line number Diff line number Diff line
@@ -38,6 +38,8 @@ import com.android.launcher3.userevent.nano.LauncherLogProto;
import com.android.launcher3.userevent.nano.LauncherLogProto.Target;
import com.android.launcher3.util.UiThreadCircularReveal;

import java.util.Collections;
import java.util.Comparator;
import java.util.List;

/**
@@ -65,6 +67,26 @@ public class DeepShortcutsContainer extends LinearLayout implements View.OnLongC
    private boolean mIsLeftAligned;
    private boolean mIsAboveIcon;

    /**
     * Sorts shortcuts in rank order, with manifest shortcuts coming before dynamic shortcuts.
     */
    private static final Comparator<ShortcutInfoCompat> sShortcutsComparator
            = new Comparator<ShortcutInfoCompat>() {
        @Override
        public int compare(ShortcutInfoCompat a, ShortcutInfoCompat b) {
            if (a.isDeclaredInManifest() && !b.isDeclaredInManifest()) {
                return -1;
            }
            if (!a.isDeclaredInManifest() && b.isDeclaredInManifest()) {
                return 1;
            }
            return Integer.compare(a.getRank(), b.getRank());
        }
    };

    private static final Comparator<ShortcutInfoCompat> sShortcutsComparatorReversed
            = Collections.reverseOrder(sShortcutsComparator);

    public DeepShortcutsContainer(Context context, AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);
        mLauncher = (Launcher) context;
@@ -109,7 +131,11 @@ public class DeepShortcutsContainer extends LinearLayout implements View.OnLongC
            @Override
            public void run() {
                final List<ShortcutInfoCompat> shortcuts = mDeepShortcutsManager
                        .queryForAllAppShortcuts(activity, ids, user);
                        .queryForShortcutsContainer(activity, ids, user);
                // We want the lowest rank to be closest to the user's finger.
                final Comparator<ShortcutInfoCompat> shortcutsComparator = mIsAboveIcon ?
                        sShortcutsComparatorReversed : sShortcutsComparator;
                Collections.sort(shortcuts, shortcutsComparator);
                for (int i = 0; i < shortcuts.size(); i++) {
                    final ShortcutInfoCompat shortcut = shortcuts.get(i);
                    final ShortcutInfo launcherShortcutInfo = ShortcutInfo
+8 −0
Original line number Diff line number Diff line
@@ -97,6 +97,14 @@ public class ShortcutInfoCompat {
        return mShortcutInfo.isPinned();
    }

    public boolean isDeclaredInManifest() {
        return mShortcutInfo.isDeclaredInManifest();
    }

    public int getRank() {
        return mShortcutInfo.getRank();
    }

    @Override
    public String toString() {
        return mShortcutInfo.toString();