Sort widgets list based on intent-filter priority.

- Sort based on priority, also group them in PreferenceCategory. So
category is divided by horizontal lines.

- Also removed a bunch of intent-filter for VOICE_LAUNCH. I don't think
we support them any more. If we see bugs, can easily put them back.

Change-Id: I286a6bdf8b3c2eb716a36c6a061fc54a8010d8f6
Fixes: 74806595
Test: manual
This commit is contained in:
Fan Zhang
2018-06-22 14:30:09 -07:00
parent 948a028690
commit 5a98177563
3 changed files with 77 additions and 57 deletions

View File

@@ -45,10 +45,13 @@ import com.android.settings.overlay.FeatureFactory;
import com.android.settingslib.core.instrumentation.MetricsFeatureProvider;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.List;
import androidx.annotation.VisibleForTesting;
import androidx.preference.Preference;
import androidx.preference.PreferenceCategory;
import androidx.preference.PreferenceGroup;
/**
@@ -97,9 +100,26 @@ public class CreateShortcutPreferenceController extends BasePreferenceController
group.removeAll();
final List<ResolveInfo> shortcuts = queryShortcuts();
final Context uiContext = preference.getContext();
if (shortcuts.isEmpty()) {
return;
}
PreferenceCategory category = new PreferenceCategory(uiContext);
group.addPreference(category);
int bucket = 0;
for (ResolveInfo info : shortcuts) {
// Priority is not consecutive (aka, jumped), add a divider between prefs.
final int currentBucket = info.priority / 10;
boolean needDivider = currentBucket != bucket;
bucket = currentBucket;
if (needDivider) {
// add a new Category
category = new PreferenceCategory(uiContext);
group.addPreference(category);
}
final Preference pref = new Preference(uiContext);
pref.setTitle(info.loadLabel(mPackageManager));
pref.setKey(info.activityInfo.getComponentName().flattenToString());
pref.setOnPreferenceClickListener(clickTarget -> {
if (mHost == null) {
return false;
@@ -112,7 +132,7 @@ public class CreateShortcutPreferenceController extends BasePreferenceController
mHost.finish();
return true;
});
group.addPreference(pref);
category.addPreference(pref);
}
}
@@ -184,6 +204,7 @@ public class CreateShortcutPreferenceController extends BasePreferenceController
}
shortcuts.add(info);
}
Collections.sort(shortcuts, SHORTCUT_COMPARATOR);
return shortcuts;
}
@@ -228,4 +249,13 @@ public class CreateShortcutPreferenceController extends BasePreferenceController
view.draw(canvas);
return bitmap;
}
private static final Comparator<ResolveInfo> SHORTCUT_COMPARATOR =
new Comparator<ResolveInfo>() {
@Override
public int compare(ResolveInfo i1, ResolveInfo i2) {
return i1.priority - i2.priority;
}
};
}