use of android.content.pm.ShortcutInfo in project android_frameworks_base by DirtyUnicorns.
the class BaseShortcutManagerTest method assertAllHaveIconResId.
public static List<ShortcutInfo> assertAllHaveIconResId(List<ShortcutInfo> actualShortcuts) {
for (ShortcutInfo s : actualShortcuts) {
assertTrue("ID " + s.getId() + " not have icon res ID", s.hasIconResource());
assertFalse("ID " + s.getId() + " shouldn't have icon FD", s.hasIconFile());
}
return actualShortcuts;
}
use of android.content.pm.ShortcutInfo in project K6nele by Kaljurand.
the class Utils method publishShortcuts.
/**
* Constructs and publishes the list of app shortcuts, one for each combo that is selected for the
* search panel. The intent behind the shortcut sets AUTO_START=true and sets RESULTS_REWRITES
* to the list of default rewrites (at creation time), and PROMPT to the list of rewrite names.
* All other settings (e.g. MAX_RESULTS) depend on the settings at execution time.
*/
@TargetApi(Build.VERSION_CODES.N_MR1)
public static void publishShortcuts(Context context, List<Combo> selectedCombos, Set<String> rewriteTables) {
ShortcutManager shortcutManager = context.getSystemService(ShortcutManager.class);
List<ShortcutInfo> shortcuts = new ArrayList<>();
int maxShortcutCountPerActivity = shortcutManager.getMaxShortcutCountPerActivity();
int counter = 0;
// TODO: rewriteTables should be a list (not a set that needs to be sorted)
String[] names = rewriteTables.toArray(new String[rewriteTables.size()]);
Arrays.sort(names);
String rewritesId = TextUtils.join(", ", names);
for (Combo combo : selectedCombos) {
Intent intent = new Intent(context, SpeechActionActivity.class);
intent.setAction(RecognizerIntent.ACTION_WEB_SEARCH);
intent.putExtra(RecognizerIntent.EXTRA_LANGUAGE, combo.getLocaleAsStr());
intent.putExtra(Extras.EXTRA_SERVICE_COMPONENT, combo.getServiceComponent().flattenToShortString());
if (names.length > 0) {
intent.putExtra(RecognizerIntent.EXTRA_PROMPT, rewritesId);
}
intent.putExtra(Extras.EXTRA_RESULT_REWRITES, names);
intent.putExtra(Extras.EXTRA_AUTO_START, true);
// Launch the activity so that the existing Kõnele activities are not in the background stack.
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TASK);
shortcuts.add(new ShortcutInfo.Builder(context, combo.getId() + rewritesId).setIntent(intent).setShortLabel(combo.getShortLabel()).setLongLabel(combo.getLongLabel() + "; " + rewritesId).setIcon(Icon.createWithBitmap(drawableToBitmap(combo.getIcon(context)))).build());
counter++;
// We are only allowed a certain number (5) of shortcuts
if (counter >= maxShortcutCountPerActivity) {
break;
}
}
shortcutManager.setDynamicShortcuts(shortcuts);
}
use of android.content.pm.ShortcutInfo in project android_frameworks_base by ResurrectionRemix.
the class ShortcutPackage method parseShortcut.
private static ShortcutInfo parseShortcut(XmlPullParser parser, String packageName, @UserIdInt int userId) throws IOException, XmlPullParserException {
String id;
ComponentName activityComponent;
// Icon icon;
String title;
int titleResId;
String titleResName;
String text;
int textResId;
String textResName;
String disabledMessage;
int disabledMessageResId;
String disabledMessageResName;
Intent intentLegacy;
PersistableBundle intentPersistableExtrasLegacy = null;
ArrayList<Intent> intents = new ArrayList<>();
int rank;
PersistableBundle extras = null;
long lastChangedTimestamp;
int flags;
int iconResId;
String iconResName;
String bitmapPath;
ArraySet<String> categories = null;
id = ShortcutService.parseStringAttribute(parser, ATTR_ID);
activityComponent = ShortcutService.parseComponentNameAttribute(parser, ATTR_ACTIVITY);
title = ShortcutService.parseStringAttribute(parser, ATTR_TITLE);
titleResId = ShortcutService.parseIntAttribute(parser, ATTR_TITLE_RES_ID);
titleResName = ShortcutService.parseStringAttribute(parser, ATTR_TITLE_RES_NAME);
text = ShortcutService.parseStringAttribute(parser, ATTR_TEXT);
textResId = ShortcutService.parseIntAttribute(parser, ATTR_TEXT_RES_ID);
textResName = ShortcutService.parseStringAttribute(parser, ATTR_TEXT_RES_NAME);
disabledMessage = ShortcutService.parseStringAttribute(parser, ATTR_DISABLED_MESSAGE);
disabledMessageResId = ShortcutService.parseIntAttribute(parser, ATTR_DISABLED_MESSAGE_RES_ID);
disabledMessageResName = ShortcutService.parseStringAttribute(parser, ATTR_DISABLED_MESSAGE_RES_NAME);
intentLegacy = ShortcutService.parseIntentAttributeNoDefault(parser, ATTR_INTENT_LEGACY);
rank = (int) ShortcutService.parseLongAttribute(parser, ATTR_RANK);
lastChangedTimestamp = ShortcutService.parseLongAttribute(parser, ATTR_TIMESTAMP);
flags = (int) ShortcutService.parseLongAttribute(parser, ATTR_FLAGS);
iconResId = (int) ShortcutService.parseLongAttribute(parser, ATTR_ICON_RES_ID);
iconResName = ShortcutService.parseStringAttribute(parser, ATTR_ICON_RES_NAME);
bitmapPath = ShortcutService.parseStringAttribute(parser, ATTR_BITMAP_PATH);
final int outerDepth = parser.getDepth();
int type;
while ((type = parser.next()) != XmlPullParser.END_DOCUMENT && (type != XmlPullParser.END_TAG || parser.getDepth() > outerDepth)) {
if (type != XmlPullParser.START_TAG) {
continue;
}
final int depth = parser.getDepth();
final String tag = parser.getName();
if (ShortcutService.DEBUG_LOAD) {
Slog.d(TAG, String.format(" depth=%d type=%d name=%s", depth, type, tag));
}
switch(tag) {
case TAG_INTENT_EXTRAS_LEGACY:
intentPersistableExtrasLegacy = PersistableBundle.restoreFromXml(parser);
continue;
case TAG_INTENT:
intents.add(parseIntent(parser));
continue;
case TAG_EXTRAS:
extras = PersistableBundle.restoreFromXml(parser);
continue;
case TAG_CATEGORIES:
// This just contains string-array.
continue;
case TAG_STRING_ARRAY_XMLUTILS:
if (NAME_CATEGORIES.equals(ShortcutService.parseStringAttribute(parser, ATTR_NAME_XMLUTILS))) {
final String[] ar = XmlUtils.readThisStringArrayXml(parser, TAG_STRING_ARRAY_XMLUTILS, null);
categories = new ArraySet<>(ar.length);
for (int i = 0; i < ar.length; i++) {
categories.add(ar[i]);
}
}
continue;
}
throw ShortcutService.throwForInvalidTag(depth, tag);
}
if (intentLegacy != null) {
// For the legacy file format which supported only one intent per shortcut.
ShortcutInfo.setIntentExtras(intentLegacy, intentPersistableExtrasLegacy);
intents.clear();
intents.add(intentLegacy);
}
return new ShortcutInfo(userId, id, packageName, activityComponent, /* icon =*/
null, title, titleResId, titleResName, text, textResId, textResName, disabledMessage, disabledMessageResId, disabledMessageResName, categories, intents.toArray(new Intent[intents.size()]), rank, extras, lastChangedTimestamp, flags, iconResId, iconResName, bitmapPath);
}
use of android.content.pm.ShortcutInfo in project android_frameworks_base by ResurrectionRemix.
the class ShortcutPackage method refreshPinnedFlags.
/**
* Called after a launcher updates the pinned set. For each shortcut in this package,
* set FLAG_PINNED if any launcher has pinned it. Otherwise, clear it.
*
* <p>Then remove all shortcuts that are not dynamic and no longer pinned either.
*/
public void refreshPinnedFlags() {
// First, un-pin all shortcuts
for (int i = mShortcuts.size() - 1; i >= 0; i--) {
mShortcuts.valueAt(i).clearFlags(ShortcutInfo.FLAG_PINNED);
}
// Then, for the pinned set for each launcher, set the pin flag one by one.
mShortcutUser.mService.getUserShortcutsLocked(getPackageUserId()).forAllLaunchers(launcherShortcuts -> {
final ArraySet<String> pinned = launcherShortcuts.getPinnedShortcutIds(getPackageName(), getPackageUserId());
if (pinned == null || pinned.size() == 0) {
return;
}
for (int i = pinned.size() - 1; i >= 0; i--) {
final String id = pinned.valueAt(i);
final ShortcutInfo si = mShortcuts.get(id);
if (si == null) {
continue;
}
si.addFlags(ShortcutInfo.FLAG_PINNED);
}
});
// Lastly, remove the ones that are no longer pinned nor dynamic.
removeOrphans();
}
use of android.content.pm.ShortcutInfo in project android_frameworks_base by ResurrectionRemix.
the class ShortcutPackage method loadFromXml.
public static ShortcutPackage loadFromXml(ShortcutService s, ShortcutUser shortcutUser, XmlPullParser parser, boolean fromBackup) throws IOException, XmlPullParserException {
final String packageName = ShortcutService.parseStringAttribute(parser, ATTR_NAME);
final ShortcutPackage ret = new ShortcutPackage(shortcutUser, shortcutUser.getUserId(), packageName);
ret.mApiCallCount = ShortcutService.parseIntAttribute(parser, ATTR_CALL_COUNT);
ret.mLastResetTime = ShortcutService.parseLongAttribute(parser, ATTR_LAST_RESET);
final int outerDepth = parser.getDepth();
int type;
while ((type = parser.next()) != XmlPullParser.END_DOCUMENT && (type != XmlPullParser.END_TAG || parser.getDepth() > outerDepth)) {
if (type != XmlPullParser.START_TAG) {
continue;
}
final int depth = parser.getDepth();
final String tag = parser.getName();
if (depth == outerDepth + 1) {
switch(tag) {
case ShortcutPackageInfo.TAG_ROOT:
ret.getPackageInfo().loadFromXml(parser, fromBackup);
continue;
case TAG_SHORTCUT:
final ShortcutInfo si = parseShortcut(parser, packageName, shortcutUser.getUserId());
// Don't use addShortcut(), we don't need to save the icon.
ret.mShortcuts.put(si.getId(), si);
continue;
}
}
ShortcutService.warnForInvalidTag(depth, tag);
}
return ret;
}
Aggregations