Search in sources :

Example 96 with ShortcutInfo

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;
}
Also used : ShortcutInfo(android.content.pm.ShortcutInfo)

Example 97 with ShortcutInfo

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);
}
Also used : ShortcutInfo(android.content.pm.ShortcutInfo) ShortcutManager(android.content.pm.ShortcutManager) ArrayList(java.util.ArrayList) Combo(ee.ioc.phon.android.speak.model.Combo) Intent(android.content.Intent) RecognizerIntent(android.speech.RecognizerIntent) ExecutableString(ee.ioc.phon.android.speak.ExecutableString) SpannableString(android.text.SpannableString) Paint(android.graphics.Paint) TargetApi(android.annotation.TargetApi)

Example 98 with ShortcutInfo

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);
}
Also used : PersistableBundle(android.os.PersistableBundle) ShortcutInfo(android.content.pm.ShortcutInfo) ArrayList(java.util.ArrayList) ComponentName(android.content.ComponentName) Intent(android.content.Intent)

Example 99 with ShortcutInfo

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();
}
Also used : ShortcutInfo(android.content.pm.ShortcutInfo)

Example 100 with ShortcutInfo

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;
}
Also used : ShortcutInfo(android.content.pm.ShortcutInfo)

Aggregations

ShortcutInfo (android.content.pm.ShortcutInfo)324 ComponentName (android.content.ComponentName)144 PersistableBundle (android.os.PersistableBundle)48 ArrayList (java.util.ArrayList)46 Intent (android.content.Intent)44 Icon (android.graphics.drawable.Icon)32 List (java.util.List)17 Matchers.anyString (org.mockito.Matchers.anyString)16 LocaleList (android.os.LocaleList)12 File (java.io.File)12 Nullable (android.annotation.Nullable)8 ShortcutQuery (android.content.pm.LauncherApps.ShortcutQuery)8 Resources (android.content.res.Resources)8 Bundle (android.os.Bundle)8 ArrayMap (android.util.ArrayMap)8 PackageWithUser (com.android.server.pm.ShortcutUser.PackageWithUser)8 ShortcutManagerTestUtils.makeBundle (com.android.server.pm.shortcutmanagertest.ShortcutManagerTestUtils.makeBundle)8 IOException (java.io.IOException)8 ArraySet (android.util.ArraySet)5 Manifest.permission (android.Manifest.permission)4