类android.content.pm.ShortcutInfo源码实例Demo

下面列出了怎么用android.content.pm.ShortcutInfo的API类实例代码及写法,或者点击链接到github查看源代码。

源代码1 项目: android_9.0.0_r45   文件: ShortcutService.java
@Override
public boolean isPinnedByCaller(int launcherUserId, @NonNull String callingPackage,
        @NonNull String packageName, @NonNull String shortcutId, int userId) {
    Preconditions.checkStringNotEmpty(packageName, "packageName");
    Preconditions.checkStringNotEmpty(shortcutId, "shortcutId");

    synchronized (mLock) {
        throwIfUserLockedL(userId);
        throwIfUserLockedL(launcherUserId);

        getLauncherShortcutsLocked(callingPackage, userId, launcherUserId)
                .attemptToRestoreIfNeededAndSave();

        final ShortcutInfo si = getShortcutInfoLocked(
                launcherUserId, callingPackage, packageName, shortcutId, userId,
                /*getPinnedByAnyLauncher=*/ false);
        return si != null && si.isPinned();
    }
}
 
源代码2 项目: shortrain   文件: ShortcutsUtils.java
public static int getNextRailNumber(ShortcutManager shortcutManager) {
    List<ShortcutInfo> shortcuts = shortcutManager.getPinnedShortcuts();

    int newRailId = -1;

    for (ShortcutInfo shortcutInfo : shortcuts) {
        String id = shortcutInfo.getId();
        if (isRailShortcut(id)) {
            int railId = getRailNumber(id);
            if (railId > newRailId) {
                newRailId = railId;
            }
        }
    }

    newRailId++;

    return newRailId;
}
 
源代码3 项目: android-proguards   文件: ShortcutHelper.java
@TargetApi(Build.VERSION_CODES.N_MR1)
public static void enablePostShortcut(@NonNull Context context) {
    if (Build.VERSION.SDK_INT < Build.VERSION_CODES.N_MR1) return;
    ShortcutManager shortcutManager = context.getSystemService(ShortcutManager.class);

    Intent intent = new Intent(context, PostNewDesignerNewsStory.class);
    intent.setAction(Intent.ACTION_VIEW);
    intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK);
    ShortcutInfo postShortcut
            = new ShortcutInfo.Builder(context, POST_SHORTCUT_ID)
            .setShortLabel(context.getString(R.string.shortcut_post_short_label))
            .setLongLabel(context.getString(R.string.shortcut_post_long_label))
            .setDisabledMessage(context.getString(R.string.shortcut_post_disabled))
            .setIcon(Icon.createWithResource(context, R.drawable.ic_shortcut_post))
            .setIntent(intent)
            .build();
    shortcutManager.addDynamicShortcuts(Collections.singletonList(postShortcut));
}
 
源代码4 项目: rcloneExplorer   文件: AppShortcutsHelper.java
@RequiresApi(api = Build.VERSION_CODES.N_MR1)
public static void addRemoteToAppShortcuts(Context context, RemoteItem remoteItem, String id) {
    ShortcutManager shortcutManager = context.getSystemService(ShortcutManager.class);
    if (shortcutManager == null) {
        return;
    }

    Intent intent = new Intent(Intent.ACTION_MAIN, Uri.EMPTY, context, MainActivity.class);
    intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK);
    intent.putExtra(APP_SHORTCUT_REMOTE_NAME, remoteItem.getName());

    ShortcutInfo shortcut = new ShortcutInfo.Builder(context, id)
            .setShortLabel(remoteItem.getName())
            .setIcon(Icon.createWithResource(context, AppShortcutsHelper.getRemoteIcon(remoteItem.getType(), remoteItem.isCrypt())))
            .setIntent(intent)
            .build();

    shortcutManager.addDynamicShortcuts(Collections.singletonList(shortcut));
}
 
源代码5 项目: HgLauncher   文件: AppUtils.java
/**
 * Fetch and return shortcuts for a specific app.
 *
 * @param launcherApps  LauncherApps service from an activity.
 * @param componentName The component name to flatten to package name.
 *
 * @return A list of shortcut. Null if nonexistent.
 */
@TargetApi(Build.VERSION_CODES.N_MR1)
public static List<ShortcutInfo> getShortcuts(LauncherApps launcherApps, String componentName) {
    // Return nothing if we don't have permission to retrieve shortcuts.
    if (launcherApps == null || !launcherApps.hasShortcutHostPermission()) {
        return new ArrayList<>(0);
    }

    LauncherApps.ShortcutQuery shortcutQuery = new LauncherApps.ShortcutQuery();
    shortcutQuery.setQueryFlags(LauncherApps.ShortcutQuery.FLAG_MATCH_DYNAMIC
            | LauncherApps.ShortcutQuery.FLAG_MATCH_MANIFEST
            | LauncherApps.ShortcutQuery.FLAG_MATCH_PINNED);
    shortcutQuery.setPackage(getPackageName(componentName));

    return launcherApps.getShortcuts(shortcutQuery, Process.myUserHandle());
}
 
public static List<List<ShortcutInfo>> createShortcuts(Context context) {
    List<ShortcutInfo> enabledShortcuts = new ArrayList<>();
    List<ShortcutInfo> disabledShortcuts = new ArrayList<>();
    enabledShortcuts.add(new ShortcutInfo.Builder(context, "ID")
            .setShortLabel(context.getString(34))
            .setLongLabel(context.getString(56))
            .setIcon(Icon.createWithResource(context, 12))
            .setDisabledMessage(context.getString(78))
            .setIntents(TaskStackBuilder.create(context)
                    .addParentStack(ResourcesShortcutActivity.class)
                    .addNextIntent(new Intent(context, ResourcesShortcutActivity.class)
                            .setAction(Intent.ACTION_VIEW))
                    .getIntents())
            .setRank(0)
            .build());
    return Arrays.asList(enabledShortcuts, disabledShortcuts);
}
 
源代码7 项目: rebootmenu   文件: UIUtils.java
/**
 * 启动器添加快捷方式
 *
 * @param context     上下文
 * @param titleRes    标题资源id
 * @param iconRes     图标资源id
 * @param shortcutAct Shortcut额外
 * @param isForce     是否是root强制模式
 * @see com.ryuunoakaihitomi.rebootmenu.activity.Shortcut
 */
public static void addLauncherShortcut(@NonNull Context context, @StringRes int titleRes, @DrawableRes int iconRes, int shortcutAct, boolean isForce) {
    new DebugLog("addLauncherShortcut", DebugLog.LogLevel.V);
    String forceToken = isForce ? "*" : "";
    String title = forceToken + context.getString(titleRes);
    if (Build.VERSION.SDK_INT < Build.VERSION_CODES.O)
        context.sendBroadcast(new Intent("com.android.launcher.action.INSTALL_SHORTCUT")
                .putExtra("duplicate", false)
                .putExtra(Intent.EXTRA_SHORTCUT_NAME, title)
                .putExtra(Intent.EXTRA_SHORTCUT_ICON_RESOURCE, Intent.ShortcutIconResource.fromContext(context, iconRes))
                .putExtra(Intent.EXTRA_SHORTCUT_INTENT, new Intent(context, Shortcut.class)
                        .putExtra(Shortcut.extraTag, shortcutAct)));
    else {
        ShortcutInfo shortcutInfo = new ShortcutInfo.Builder(context, "o_launcher_shortcut:" + shortcutAct)
                .setShortLabel(title)
                .setIcon(Icon.createWithResource(context, iconRes))
                .setIntent(new Intent(context, Shortcut.class)
                        .putExtra(Shortcut.extraTag, shortcutAct)
                        .setAction(Intent.ACTION_VIEW))
                .build();
        new DebugLog("addLauncherShortcut: requestPinShortcut:"
                + context.getSystemService(ShortcutManager.class).requestPinShortcut(shortcutInfo, null));
    }
}
 
源代码8 项目: Aegis   文件: AegisApplication.java
@RequiresApi(api = Build.VERSION_CODES.N_MR1)
private void initAppShortcuts() {
    ShortcutManager shortcutManager = getSystemService(ShortcutManager.class);
    if (shortcutManager == null) {
        return;
    }

    Intent intent = new Intent(this, MainActivity.class);
    intent.putExtra("action", "scan");
    intent.setAction(Intent.ACTION_MAIN);

    ShortcutInfo shortcut = new ShortcutInfo.Builder(this, "shortcut_new")
            .setShortLabel(getString(R.string.new_entry))
            .setLongLabel(getString(R.string.add_new_entry))
            .setIcon(Icon.createWithResource(this, R.drawable.ic_qr_code))
            .setIntent(intent)
            .build();

    shortcutManager.setDynamicShortcuts(Collections.singletonList(shortcut));
}
 
源代码9 项目: HgLauncher   文件: AppUtils.java
/**
 * Fetch and return shortcuts for a specific app.
 *
 * @param launcherApps  LauncherApps service from an activity.
 * @param componentName The component name to flatten to package name.
 *
 * @return A list of shortcut. Null if nonexistent.
 */
@TargetApi(Build.VERSION_CODES.N_MR1)
public static List<ShortcutInfo> getShortcuts(LauncherApps launcherApps, String componentName) {
    // Return nothing if we don't have permission to retrieve shortcuts.
    if (launcherApps == null || !launcherApps.hasShortcutHostPermission()) {
        return new ArrayList<>(0);
    }

    LauncherApps.ShortcutQuery shortcutQuery = new LauncherApps.ShortcutQuery();
    shortcutQuery.setQueryFlags(LauncherApps.ShortcutQuery.FLAG_MATCH_DYNAMIC
            | LauncherApps.ShortcutQuery.FLAG_MATCH_MANIFEST
            | LauncherApps.ShortcutQuery.FLAG_MATCH_PINNED);
    shortcutQuery.setPackage(getPackageName(componentName));

    return launcherApps.getShortcuts(shortcutQuery, Process.myUserHandle());
}
 
源代码10 项目: android_9.0.0_r45   文件: ShortcutPackage.java
/**
 * Build a list of shortcuts for each target activity and return as a map. The result won't
 * contain "floating" shortcuts because they don't belong on any activities.
 */
private ArrayMap<ComponentName, ArrayList<ShortcutInfo>> sortShortcutsToActivities() {
    final ArrayMap<ComponentName, ArrayList<ShortcutInfo>> activitiesToShortcuts
            = new ArrayMap<>();
    for (int i = mShortcuts.size() - 1; i >= 0; i--) {
        final ShortcutInfo si = mShortcuts.valueAt(i);
        if (si.isFloating()) {
            continue; // Ignore floating shortcuts, which are not tied to any activities.
        }

        final ComponentName activity = si.getActivity();
        if (activity == null) {
            mShortcutUser.mService.wtf("null activity detected.");
            continue;
        }

        ArrayList<ShortcutInfo> list = activitiesToShortcuts.get(activity);
        if (list == null) {
            list = new ArrayList<>();
            activitiesToShortcuts.put(activity, list);
        }
        list.add(si);
    }
    return activitiesToShortcuts;
}
 
源代码11 项目: zapp   文件: ShortcutHelper.java
/**
 * Adds the given channel as shortcut to the launcher icon.
 * Only call on api level >= 25.
 *
 * @param context to access system services
 * @param channel channel to create a shortcut for
 * @return true if the channel could be added
 */
@TargetApi(25)
public static boolean addShortcutForChannel(Context context, ChannelModel channel) {
	ShortcutManager shortcutManager = context.getSystemService(ShortcutManager.class);

	if (shortcutManager == null || shortcutManager.getDynamicShortcuts().size() >= 4) {
		return false;
	}

	ShortcutInfo shortcut = new ShortcutInfo.Builder(context, channel.getId())
		.setShortLabel(channel.getName())
		.setLongLabel(channel.getName())
		.setIcon(Icon.createWithResource(context, channel.getDrawableId()))
		.setIntent(ChannelDetailActivity.getStartIntent(context, channel.getId()))
		.build();

	try {
		return shortcutManager.addDynamicShortcuts(Collections.singletonList(shortcut));
	} catch (IllegalArgumentException e) {
		// too many shortcuts
		return false;
	}
}
 
源代码12 项目: SecondScreen   文件: MainActivity.java
private void setLauncherShortcuts() {
    if(Build.VERSION.SDK_INT >= Build.VERSION_CODES.N_MR1) {
        ShortcutManager shortcutManager = getSystemService(ShortcutManager.class);

        if(shortcutManager.getDynamicShortcuts().size() == 0) {
            Intent intent = new Intent(Intent.ACTION_MAIN);
            intent.setClassName(BuildConfig.APPLICATION_ID, TaskerQuickActionsActivity.class.getName());
            intent.putExtra("launched-from-app", true);

            ShortcutInfo shortcut = new ShortcutInfo.Builder(this, "quick_actions")
                    .setShortLabel(getString(R.string.label_quick_actions))
                    .setIcon(Icon.createWithResource(this, R.drawable.shortcut_icon))
                    .setIntent(intent)
                    .build();

            shortcutManager.setDynamicShortcuts(Collections.singletonList(shortcut));
        }
    }
}
 
源代码13 项目: AppOpsX   文件: Helper.java
@RequiresApi(api = Build.VERSION_CODES.N_MR1)
private static void updataShortcuts(Context context, List<AppInfo> items) {
  ShortcutManager shortcutManager = context.getSystemService(ShortcutManager.class);
  List<ShortcutInfo> shortcutInfoList = new ArrayList<>();
  int max = shortcutManager.getMaxShortcutCountPerActivity();
  for (int i = 0; i < max && i < items.size(); i++) {
    AppInfo appInfo = items.get(i);
    ShortcutInfo.Builder shortcut = new ShortcutInfo.Builder(context, appInfo.packageName);
    shortcut.setShortLabel(appInfo.appName);
    shortcut.setLongLabel(appInfo.appName);

    shortcut.setIcon(
        Icon.createWithBitmap(drawableToBitmap(LocalImageLoader.getDrawable(context, appInfo))));

    Intent intent = new Intent(context, AppPermissionActivity.class);
    intent.putExtra(AppPermissionActivity.EXTRA_APP_PKGNAME, appInfo.packageName);
    intent.putExtra(AppPermissionActivity.EXTRA_APP_NAME, appInfo.appName);
    intent.setAction(Intent.ACTION_DEFAULT);
    shortcut.setIntent(intent);

    shortcutInfoList.add(shortcut.build());
  }
  shortcutManager.setDynamicShortcuts(shortcutInfoList);
}
 
源代码14 项目: hash-checker   文件: App.java
@RequiresApi(api = Build.VERSION_CODES.N_MR1)
@SuppressLint("ResourceType")
@NonNull
private ShortcutInfo getShortcut(
        @NonNull String id,
        @IdRes int labelResId,
        @IdRes int iconResId,
        @NonNull String intentAction
) {
    Intent intent = new Intent(
            this,
            MainActivity.class
    );
    intent.setAction(intentAction);
    return new ShortcutInfo.Builder(this, id)
            .setShortLabel(getString(labelResId))
            .setIcon(
                    Icon.createWithResource(
                            this,
                            iconResId
                    )
            )
            .setIntent(intent)
            .build();
}
 
源代码15 项目: Android7_Shortcuts_Demo   文件: MainActivity.java
private void setupShortcuts() {
        mShortcutManager = getSystemService(ShortcutManager.class);

        List<ShortcutInfo> infos = new ArrayList<>();
        for (int i = 0; i < mShortcutManager.getMaxShortcutCountPerActivity(); i++) {
            Intent intent = new Intent(this, MessageActivity.class);
            intent.setAction(Intent.ACTION_VIEW);
            intent.putExtra("msg", "我和" + mAdapter.getItem(i) + "的对话");

            ShortcutInfo info = new ShortcutInfo.Builder(this, "id" + i)
                    .setShortLabel(mAdapter.getItem(i))
                    .setLongLabel("联系人:" + mAdapter.getItem(i))
                    .setIcon(Icon.createWithResource(this, R.drawable.icon))
                    .setIntent(intent)
                    .build();
            infos.add(info);
//            manager.addDynamicShortcuts(Arrays.asList(info));
        }

        mShortcutManager.setDynamicShortcuts(infos);
    }
 
源代码16 项目: android_9.0.0_r45   文件: ShortcutBitmapSaver.java
/**
 * Wait for all pending saves to finish, and then return the given shortcut's bitmap path.
 */
@Nullable
public String getBitmapPathMayWaitLocked(ShortcutInfo shortcut) {
    final boolean success = waitForAllSavesLocked();
    if (success && shortcut.hasIconFile()) {
        return shortcut.getBitmapPath();
    } else {
        return null;
    }
}
 
源代码17 项目: RetroMusicPlayer   文件: TopTracksShortcutType.java
public ShortcutInfo getShortcutInfo() {
    return new ShortcutInfo.Builder(context, getId())
            .setShortLabel(context.getString(R.string.app_shortcut_top_tracks_short))
            .setLongLabel(context.getString(R.string.app_shortcut_top_tracks_long))
            .setIcon(AppShortcutIconGenerator.generateThemedIcon(context, R.drawable.ic_app_shortcut_top_tracks))
            .setIntent(getPlaySongsIntent(AppShortcutLauncherActivity.SHORTCUT_TYPE_TOP_TRACKS))
            .build();
}
 
源代码18 项目: ui   文件: MainActivity.java
void addshortcuts() {
    //first create the list.
    ArrayList<ShortcutInfo> myList = new ArrayList<ShortcutInfo>();
    ShortcutInfo item;
    //now add them.
    //first one, a web link to cosc 4735 pages
    item = new ShortcutInfo.Builder(this,"id1")
            .setShortLabel("Web Site")
            .setLongLabel("Cosc 4735 Web site")
            .setIcon(Icon.createWithResource(this, R.drawable.bookmark))
            .setIntent(new Intent(Intent.ACTION_VIEW,
                    Uri.parse("http://www.cs.uwyo.edu/~seker/courses/4735/")))
            .build();
    myList.add(item);
    //second one, a custom intent to commonActivity.
    item = new ShortcutInfo.Builder(this,"id2")
            .setShortLabel("Common Act message")
            .setLongLabel("Start a message on Commmon Activity")
            .setIcon(Icon.createWithResource(this, R.drawable.ic_touch_app_black_24dp))
            .setIntent(
                    new Intent("edu.cs4730.appshortcutsdemo.AddMessage")
                    .setClassName("edu.cs4730.appshortcutsdemo","edu.cs4730.appshortcutsdemo.CommonActivity")
                    //this is like any intent, you can add data to it as well, so key pairs of data.
                    .putExtra("Name", "fred")
            )
            .build();
    myList.add(item);

    //add the list to the shortcutmanager.
    mShortcutManager.setDynamicShortcuts(myList);
    //or we could have added each individually with this statement:  (addd skip myList)
    //mShortcutManager.addDynamicShortcuts(Arrays.asList(item));


}
 
源代码19 项目: user-interface-samples   文件: ShortcutHelper.java
public void addWebSiteShortcut(String urlAsString) {
    final String uriFinal = urlAsString;
    callShortcutManager(() -> {
        final ShortcutInfo shortcut = createShortcutForUrl(normalizeUrl(uriFinal));
        return mShortcutManager.addDynamicShortcuts(Arrays.asList(shortcut));
    });
}
 
/**
 * Handle {@link android.content.pm.ShortcutManager#requestPinShortcut)} and
 * {@link android.appwidget.AppWidgetManager#requestPinAppWidget}.
 * In this flow the PinItemRequest is delivered directly to the default launcher app.
 * One of {@param inShortcut} and {@param inAppWidget} is always non-null and the other is
 * always null.
 */
public boolean requestPinItemLocked(ShortcutInfo inShortcut, AppWidgetProviderInfo inAppWidget,
    Bundle extras, int userId, IntentSender resultIntent) {

    // First, make sure the launcher supports it.

    // Find the confirmation activity in the default launcher.
    final int requestType = inShortcut != null ?
            PinItemRequest.REQUEST_TYPE_SHORTCUT : PinItemRequest.REQUEST_TYPE_APPWIDGET;
    final Pair<ComponentName, Integer> confirmActivity =
            getRequestPinConfirmationActivity(userId, requestType);

    // If the launcher doesn't support it, just return a rejected result and finish.
    if (confirmActivity == null) {
        Log.w(TAG, "Launcher doesn't support requestPinnedShortcut(). Shortcut not created.");
        return false;
    }

    final int launcherUserId = confirmActivity.second;

    // Make sure the launcher user is unlocked. (it's always the parent profile, so should
    // really be unlocked here though.)
    mService.throwIfUserLockedL(launcherUserId);

    // Next, validate the incoming shortcut, etc.
    final PinItemRequest request;
    if (inShortcut != null) {
        request = requestPinShortcutLocked(inShortcut, resultIntent, confirmActivity);
    } else {
        int launcherUid = mService.injectGetPackageUid(
                confirmActivity.first.getPackageName(), launcherUserId);
        request = new PinItemRequest(
                new PinAppWidgetRequestInner(this, resultIntent, launcherUid, inAppWidget,
                        extras),
                PinItemRequest.REQUEST_TYPE_APPWIDGET);
    }
    return startRequestConfirmActivity(confirmActivity.first, launcherUserId, request,
            requestType);
}
 
源代码21 项目: Phonograph   文件: TopTracksShortcutType.java
public ShortcutInfo getShortcutInfo() {
    return new ShortcutInfo.Builder(context, getId())
            .setShortLabel(context.getString(R.string.app_shortcut_top_tracks_short))
            .setLongLabel(context.getString(R.string.my_top_tracks))
            .setIcon(AppShortcutIconGenerator.generateThemedIcon(context, R.drawable.ic_app_shortcut_top_tracks))
            .setIntent(getPlaySongsIntent(AppShortcutLauncherActivity.SHORTCUT_TYPE_TOP_TRACKS))
            .build();
}
 
源代码22 项目: android-AppShortcuts   文件: ShortcutHelper.java
public void addWebSiteShortcut(String urlAsString) {
    final String uriFinal = urlAsString;
    callShortcutManager(() -> {
        final ShortcutInfo shortcut = createShortcutForUrl(normalizeUrl(uriFinal));
        return mShortcutManager.addDynamicShortcuts(Arrays.asList(shortcut));
    });
}
 
源代码23 项目: Phonograph   文件: LastAddedShortcutType.java
public ShortcutInfo getShortcutInfo() {
    return new ShortcutInfo.Builder(context, getId())
            .setShortLabel(context.getString(R.string.app_shortcut_last_added_short))
            .setLongLabel(context.getString(R.string.last_added))
            .setIcon(AppShortcutIconGenerator.generateThemedIcon(context, R.drawable.ic_app_shortcut_last_added))
            .setIntent(getPlaySongsIntent(AppShortcutLauncherActivity.SHORTCUT_TYPE_LAST_ADDED))
            .build();
}
 
源代码24 项目: android_9.0.0_r45   文件: ShortcutPackageItem.java
public void attemptToRestoreIfNeededAndSave() {
    if (!mPackageInfo.isShadow()) {
        return; // Already installed, nothing to do.
    }
    final ShortcutService s = mShortcutUser.mService;
    if (!s.isPackageInstalled(mPackageName, mPackageUserId)) {
        if (ShortcutService.DEBUG) {
            Slog.d(TAG, String.format("Package still not installed: %s/u%d",
                    mPackageName, mPackageUserId));
        }
        return; // Not installed, no need to restore yet.
    }
    int restoreBlockReason;
    long currentVersionCode = ShortcutInfo.VERSION_CODE_UNKNOWN;

    if (!mPackageInfo.hasSignatures()) {
        s.wtf("Attempted to restore package " + mPackageName + "/u" + mPackageUserId
                + " but signatures not found in the restore data.");
        restoreBlockReason = ShortcutInfo.DISABLED_REASON_SIGNATURE_MISMATCH;
    } else {
        final PackageInfo pi = s.getPackageInfoWithSignatures(mPackageName, mPackageUserId);
        currentVersionCode = pi.getLongVersionCode();
        restoreBlockReason = mPackageInfo.canRestoreTo(s, pi, canRestoreAnyVersion());
    }

    if (ShortcutService.DEBUG) {
        Slog.d(TAG, String.format("Restoring package: %s/u%d (version=%d) %s for u%d",
                mPackageName, mPackageUserId, currentVersionCode,
                ShortcutInfo.getDisabledReasonDebugString(restoreBlockReason),
                getOwnerUserId()));
    }

    onRestored(restoreBlockReason);

    // Either way, it's no longer a shadow.
    mPackageInfo.setShadow(false);

    s.scheduleSaveUser(mPackageUserId);
}
 
private void setShortcuts() {
    if (Build.VERSION.SDK_INT < Build.VERSION_CODES.N_MR1) return;

    PriorityQueue<Class<? extends Fragment>> queue = new PriorityQueue<>(
            (o1, o2) -> {
                int opened1 = AppSettings.getFragmentOpened(o1, this);
                int opened2 = AppSettings.getFragmentOpened(o2, this);
                return opened2 - opened1;
            });

    for (Map.Entry<Integer, Class<? extends Fragment>> entry : mActualFragments.entrySet()) {
        Class<? extends Fragment> fragmentClass = entry.getValue();
        if (fragmentClass == null || fragmentClass == SettingsFragment.class) continue;

        queue.offer(fragmentClass);
    }

    List<ShortcutInfo> shortcutInfos = new ArrayList<>();
    ShortcutManager shortcutManager = getSystemService(ShortcutManager.class);
    shortcutManager.removeAllDynamicShortcuts();
    for (int i = 0; i < 4; i++) {
        NavigationFragment fragment = findNavigationFragmentByClass(queue.poll());
        if (fragment == null || fragment.mFragmentClass == null) continue;
        Intent intent = new Intent(this, MainActivity.class);
        intent.setAction(Intent.ACTION_VIEW);
        intent.putExtra(INTENT_SECTION, fragment.mFragmentClass.getCanonicalName());
        intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TOP);

        ShortcutInfo shortcut = new ShortcutInfo.Builder(this,
                fragment.mFragmentClass.getSimpleName())
                .setShortLabel(getString(fragment.mId))
                .setLongLabel(Utils.strFormat(getString(R.string.open), getString(fragment.mId)))
                .setIcon(Icon.createWithResource(this, fragment.mDrawable == 0 ?
                        R.drawable.ic_blank : fragment.mDrawable))
                .setIntent(intent)
                .build();
        shortcutInfos.add(shortcut);
    }
    shortcutManager.setDynamicShortcuts(shortcutInfos);
}
 
源代码26 项目: android_9.0.0_r45   文件: ShortcutLauncher.java
@Override
protected void onRestored(int restoreBlockReason) {
    // For launcher, possible reasons here are DISABLED_REASON_SIGNATURE_MISMATCH or
    // DISABLED_REASON_BACKUP_NOT_SUPPORTED.
    // DISABLED_REASON_VERSION_LOWER will NOT happen because we don't check version
    // code for launchers.
    if (restoreBlockReason != ShortcutInfo.DISABLED_REASON_NOT_DISABLED) {
        onRestoreBlocked();
    }
}
 
@Override
public void onBindViewHolder(ViewHolder holder, int position) {
    if (!SDKUtil.AT_LEAST_N_MR1) {
        return;
    }

    final ShortcutInfo shortcutInfo = mShortcuts.get(position);

    holder.titleTextView.setText(shortcutInfo.getShortLabel());
    holder.iconImageView.setImageDrawable(ShortcutUtil.loadDrawable(holder.itemView.getContext(), shortcutInfo));
    holder.itemView.setOnClickListener(view -> ShortcutUtil.launchShortcut(view, shortcutInfo));
}
 
源代码28 项目: paper-launcher   文件: ShortcutUtil.java
public static void launchShortcut(View view, ShortcutInfo shortcutInfo) {
    if (!SDKUtil.AT_LEAST_N_MR1) {
        return;
    }

    ((LauncherApps) view.getContext().getSystemService(Context.LAUNCHER_APPS_SERVICE))
            .startShortcut(shortcutInfo, IntentUtil.getViewBounds(view), new Bundle());
}
 
源代码29 项目: VinylMusicPlayer   文件: DynamicShortcutManager.java
public List<ShortcutInfo> getDefaultShortcuts() {
    return (Arrays.asList(
            new ShuffleAllShortcutType(context).getShortcutInfo(),
            new TopTracksShortcutType(context).getShortcutInfo(),
            new LastAddedShortcutType(context).getShortcutInfo()
    ));
}
 
源代码30 项目: android_9.0.0_r45   文件: ShortcutPackage.java
/**
 * Delete a shortcut by ID. This will *always* remove it even if it's immutable or invisible.
 */
private ShortcutInfo forceDeleteShortcutInner(@NonNull String id) {
    final ShortcutInfo shortcut = mShortcuts.remove(id);
    if (shortcut != null) {
        mShortcutUser.mService.removeIconLocked(shortcut);
        shortcut.clearFlags(ShortcutInfo.FLAG_DYNAMIC | ShortcutInfo.FLAG_PINNED
                | ShortcutInfo.FLAG_MANIFEST);
    }
    return shortcut;
}
 
 类所在包
 同包方法