Java 类android.content.pm.LauncherApps.ShortcutQuery 实例源码

项目:FlickLauncher    文件:DeepShortcutManagerN.java   
@Override
protected List<ShortcutInfoCompat> query(int flags, String packageName, ComponentName componentName, List<String> shortcutIds, UserHandle userHandle) {
    List<ShortcutInfo> shortcuts = null;
    ShortcutQuery shortcutQuery = new ShortcutQuery();
    shortcutQuery.setQueryFlags(flags);
    if (packageName != null) {
        shortcutQuery.setPackage(packageName);
        shortcutQuery.setActivity(componentName);
        shortcutQuery.setShortcutIds(shortcutIds);
    }
    try {
        shortcuts = mLauncherApps.getShortcuts(shortcutQuery, userHandle);
        mWasLastCallSuccess = true;
    } catch (Throwable e) {
        Log.e("DeepShortcutManager", "Failed to query for shortcuts", e);
        mWasLastCallSuccess = false;
    }
    if (shortcuts == null) {
        return Collections.emptyList();
    }
    List<ShortcutInfoCompat> shortcutList = new ArrayList<>(shortcuts.size());
    for (ShortcutInfo shortcutInfoCompat : shortcuts) {
        shortcutList.add(new ShortcutInfoCompat(shortcutInfoCompat));
    }
    return shortcutList;
}
项目:LaunchEnr    文件:DeepShortcutManager.java   
/**
 * Query the system server for all the shortcuts matching the given parameters.
 * If packageName == null, we query for all shortcuts with the passed flags, regardless of app.
 *
 * TODO: Use the cache to optimize this so we don't make an RPC every time.
 */
@TargetApi(25)
private List<ShortcutInfoCompat> query(int flags, String packageName,
        ComponentName activity, List<String> shortcutIds, UserHandle user) {
    if (AndroidVersion.isAtLeastNougatMR1) {
        ShortcutQuery q = new ShortcutQuery();
        q.setQueryFlags(flags);
        if (packageName != null) {
            q.setPackage(packageName);
            q.setActivity(activity);
            q.setShortcutIds(shortcutIds);
        }
        List<ShortcutInfo> shortcutInfos = null;
        try {
            shortcutInfos = mLauncherApps.getShortcuts(q, user);
            mWasLastCallSuccess = true;
        } catch (SecurityException|IllegalStateException e) {
            e.printStackTrace();
            mWasLastCallSuccess = false;
        }
        if (shortcutInfos == null) {
            return Collections.EMPTY_LIST;
        }
        List<ShortcutInfoCompat> shortcutInfoCompats = new ArrayList<>(shortcutInfos.size());
        for (ShortcutInfo shortcutInfo : shortcutInfos) {
            shortcutInfoCompats.add(new ShortcutInfoCompat(shortcutInfo));
        }
        return shortcutInfoCompats;
    } else {
        return Collections.EMPTY_LIST;
    }
}
项目:SimpleUILauncher    文件:DeepShortcutManager.java   
/**
 * Query the system server for all the shortcuts matching the given parameters.
 * If packageName == null, we query for all shortcuts with the passed flags, regardless of app.
 *
 * TODO: Use the cache to optimize this so we don't make an RPC every time.
 */
@TargetApi(25)
private List<ShortcutInfoCompat> query(int flags, String packageName,
        ComponentName activity, List<String> shortcutIds, UserHandleCompat user) {
    if (Utilities.isNycMR1OrAbove()) {
        ShortcutQuery q = new ShortcutQuery();
        q.setQueryFlags(flags);
        if (packageName != null) {
            q.setPackage(packageName);
            q.setActivity(activity);
            q.setShortcutIds(shortcutIds);
        }
        List<ShortcutInfo> shortcutInfos = null;
        try {
            shortcutInfos = mLauncherApps.getShortcuts(q, user.getUser());
            mWasLastCallSuccess = true;
        } catch (SecurityException|IllegalStateException e) {
            Log.e(TAG, "Failed to query for shortcuts", e);
            mWasLastCallSuccess = false;
        }
        if (shortcutInfos == null) {
            return Collections.EMPTY_LIST;
        }
        List<ShortcutInfoCompat> shortcutInfoCompats = new ArrayList<>(shortcutInfos.size());
        for (ShortcutInfo shortcutInfo : shortcutInfos) {
            shortcutInfoCompats.add(new ShortcutInfoCompat(shortcutInfo));
        }
        return shortcutInfoCompats;
    } else {
        return Collections.EMPTY_LIST;
    }
}
项目:LaunchEnr    文件:DeepShortcutManager.java   
/**
 * 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> queryForShortcutsContainer(ComponentName activity,
        List<String> ids, UserHandle user) {
    return query(ShortcutQuery.FLAG_MATCH_MANIFEST | ShortcutQuery.FLAG_MATCH_DYNAMIC,
            activity.getPackageName(), activity, ids, user);
}
项目:FlickLauncher    文件:DeepShortcutManagerN.java   
@Override
public List<ShortcutInfoCompat> queryForFullDetails(String str, List<String> list, UserHandle userHandle) {
    return query(ShortcutQuery.FLAG_MATCH_DYNAMIC | ShortcutQuery.FLAG_MATCH_MANIFEST | ShortcutQuery.FLAG_MATCH_PINNED,
            str, null, list, userHandle);
}
项目:FlickLauncher    文件:DeepShortcutManagerN.java   
@Override
public List<ShortcutInfoCompat> queryForShortcutsContainer(ComponentName componentName, List<String> list, UserHandle userHandle) {
    return query(ShortcutQuery.FLAG_MATCH_DYNAMIC | ShortcutQuery.FLAG_MATCH_MANIFEST,
            componentName.getPackageName(), componentName, list, userHandle);
}