android.content.pm.ShortcutInfo#getId()源码实例Demo

下面列出了android.content.pm.ShortcutInfo#getId() 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。

源代码1 项目: 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;
}
 
源代码2 项目: android_9.0.0_r45   文件: ShortcutPackage.java
private void ensureNotImmutable(@Nullable ShortcutInfo shortcut, boolean ignoreInvisible) {
    if (shortcut != null && shortcut.isImmutable()
            && (!ignoreInvisible || shortcut.isVisibleToPublisher())) {
        throw new IllegalArgumentException(
                "Manifest shortcut ID=" + shortcut.getId()
                        + " may not be manipulated via APIs");
    }
}
 
源代码3 项目: android_9.0.0_r45   文件: ShortcutService.java
/**
 * Handles {@link #requestPinShortcut} and {@link ShortcutServiceInternal#requestPinAppWidget}.
 * After validating the caller, it passes the request to {@link #mShortcutRequestPinProcessor}.
 * Either {@param shortcut} or {@param appWidget} should be non-null.
 */
private boolean requestPinItem(String packageName, int userId, ShortcutInfo shortcut,
        AppWidgetProviderInfo appWidget, Bundle extras, IntentSender resultIntent) {
    verifyCaller(packageName, userId);
    verifyShortcutInfoPackage(packageName, shortcut);

    final boolean ret;
    synchronized (mLock) {
        throwIfUserLockedL(userId);

        Preconditions.checkState(isUidForegroundLocked(injectBinderCallingUid()),
                "Calling application must have a foreground activity or a foreground service");

        // If it's a pin shortcut request, and there's already a shortcut with the same ID
        // that's not visible to the caller (i.e. restore-blocked; meaning it's pinned by
        // someone already), then we just replace the existing one with this new one,
        // and then proceed the rest of the process.
        if (shortcut != null) {
            final ShortcutPackage ps = getPackageShortcutsForPublisherLocked(
                    packageName, userId);
            final String id = shortcut.getId();
            if (ps.isShortcutExistsAndInvisibleToPublisher(id)) {

                ps.updateInvisibleShortcutForPinRequestWith(shortcut);

                packageShortcutsChanged(packageName, userId);
            }
        }

        // Send request to the launcher, if supported.
        ret = mShortcutRequestPinProcessor.requestPinItemLocked(shortcut, appWidget, extras,
                userId, resultIntent);
    }

    verifyStates();

    return ret;
}
 
源代码4 项目: ui   文件: MainActivity.java
@Override
protected void onResume() {
    super.onResume();
    Log.v(TAG, "Intent action is " + getIntent().getAction());
    if (mShortcutManager.getDynamicShortcuts().size() == 0) {
        //there are no dynamic shortcuts, so lets add two of them.
        Log.v(TAG, "no shortcuts, adding 2");
        logthis("no shortcuts, adding 2");
        addshortcuts();
    } else {
        //log the shortcuts to the screen.
        for (ShortcutInfo shortcut : mShortcutManager.getDynamicShortcuts()) {
            String temp = "ID: " + shortcut.getId() + " ShortLabel:" + shortcut.getShortLabel();
            Log.v(TAG, temp);
            logthis(temp);
        }

        //we should refresh them, in case things changed in dynamic.  (or in debugging, if we changed something.  doesn't auto update
        addshortcuts();


    }

    if (getIntent().getAction().compareTo("edu.cs4730.appshortcutsdemo.CustomAction") ==0) {
        //this is our custom intent fromt he xml file
        logthis("Custom Action intent from the Static shortcut.");
    }


}
 
/**
 * The last step of the "request pin shortcut" flow.  Called when the launcher accepted a
 * request.
 */
public boolean directPinShortcut(PinShortcutRequestInner request) {

    final ShortcutInfo original = request.shortcutOriginal;
    final int appUserId = original.getUserId();
    final String appPackageName = original.getPackage();
    final int launcherUserId = request.launcherUserId;
    final String launcherPackage = request.launcherPackage;
    final String shortcutId = original.getId();

    synchronized (mLock) {
        if (!(mService.isUserUnlockedL(appUserId)
                && mService.isUserUnlockedL(request.launcherUserId))) {
            Log.w(TAG, "User is locked now.");
            return false;
        }

        final ShortcutLauncher launcher = mService.getLauncherShortcutsLocked(
                launcherPackage, appUserId, launcherUserId);
        launcher.attemptToRestoreIfNeededAndSave();
        if (launcher.hasPinned(original)) {
            if (DEBUG) {
                Slog.d(TAG, "Shortcut " + original + " already pinned.");                       // This too.
            }
            return true;
        }

        final ShortcutPackage ps = mService.getPackageShortcutsForPublisherLocked(
                appPackageName, appUserId);
        final ShortcutInfo current = ps.findShortcutById(shortcutId);

        // The shortcut might have been changed, so we need to do the same validation again.
        try {
            if (current == null) {
                // It doesn't exist, so it must have all necessary fields.
                mService.validateShortcutForPinRequest(original);
            } else {
                validateExistingShortcut(current);
            }
        } catch (RuntimeException e) {
            Log.w(TAG, "Unable to pin shortcut: " + e.getMessage());
            return false;
        }

        // If the shortcut doesn't exist, need to create it.
        // First, create it as a dynamic shortcut.
        if (current == null) {
            if (DEBUG) {
                Slog.d(TAG, "Temporarily adding " + shortcutId + " as dynamic");
            }
            // Add as a dynamic shortcut.  In order for a shortcut to be dynamic, it must
            // have a target activity, so we set a dummy here.  It's later removed
            // in deleteDynamicWithId().
            if (original.getActivity() == null) {
                original.setActivity(mService.getDummyMainActivity(appPackageName));
            }
            ps.addOrReplaceDynamicShortcut(original);
        }

        // Pin the shortcut.
        if (DEBUG) {
            Slog.d(TAG, "Pinning " + shortcutId);
        }

        launcher.addPinnedShortcut(appPackageName, appUserId, shortcutId,
                /*forPinRequest=*/ true);

        if (current == null) {
            if (DEBUG) {
                Slog.d(TAG, "Removing " + shortcutId + " as dynamic");
            }
            ps.deleteDynamicWithId(shortcutId, /*ignoreInvisible=*/ false);
        }

        ps.adjustRanks(); // Shouldn't be needed, but just in case.
    }

    mService.verifyStates();
    mService.packageShortcutsChanged(appPackageName, appUserId);

    return true;
}