Example usage for android.content.pm ShortcutInfo getId

List of usage examples for android.content.pm ShortcutInfo getId

Introduction

In this page you can find the example usage for android.content.pm ShortcutInfo getId.

Prototype

@NonNull
public String getId() 

Source Link

Document

Returns the ID of a shortcut.

Usage

From source file:com.android.contacts.DynamicShortcuts.java

private void removeAllShortcuts() {
    mShortcutManager.removeAllDynamicShortcuts();

    final List<ShortcutInfo> pinned = mShortcutManager.getPinnedShortcuts();
    final List<String> ids = new ArrayList<>(pinned.size());
    for (ShortcutInfo shortcut : pinned) {
        ids.add(shortcut.getId());
    }/*from   w  ww  .  ja va  2  s.c o  m*/
    mShortcutManager.disableShortcuts(ids, mContext.getString(R.string.dynamic_shortcut_disabled_message));
    if (Log.isLoggable(TAG, Log.DEBUG)) {
        Log.d(TAG, "DynamicShortcuts have been removed.");
    }
}

From source file:org.deviceconnect.android.deviceplugin.demo.DemoSettingFragment.java

private boolean isCreatedShortcut() {
    if (DEBUG) {/*from w  w  w. ja  va2s.  c  o m*/
        Log.d(TAG, "DemoPageSetting: isCreatedShortcut");
    }
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N_MR1) {
        ShortcutManager shortcutManager = mShortcutManager;
        List<ShortcutInfo> infoList = shortcutManager.getPinnedShortcuts();
        if (DEBUG) {
            Log.d(TAG, "DemoPageSetting: isCreatedShortcut: PinnedShortcuts=" + infoList.size());
            Log.d(TAG, "DemoPageSetting: isCreatedShortcut: DynamicShortcuts="
                    + shortcutManager.getDynamicShortcuts());
        }
        for (ShortcutInfo info : infoList) {
            if (DEBUG) {
                Log.d(TAG, "DemoPageSetting: isCreatedShortcut: info=" + info.getPackage());
            }
            if (info.getId().equals(CAMERA_DEMO_SHORTCUT_ID)) {
                return true;
            }
        }
        return false;
    } else {
        return false;
    }
}

From source file:com.android.contacts.DynamicShortcuts.java

@VisibleForTesting
void updatePinned() {
    final List<ShortcutInfo> updates = new ArrayList<>();
    final List<String> removedIds = new ArrayList<>();
    final List<String> enable = new ArrayList<>();

    for (ShortcutInfo shortcut : mShortcutManager.getPinnedShortcuts()) {
        final PersistableBundle extras = shortcut.getExtras();

        if (extras == null
                || extras.getInt(EXTRA_SHORTCUT_TYPE, SHORTCUT_TYPE_UNKNOWN) != SHORTCUT_TYPE_CONTACT_URI) {
            continue;
        }/*from  www  .  j a v  a 2 s.  com*/

        // The contact ID may have changed but that's OK because it is just an optimization
        final long contactId = extras.getLong(Contacts._ID);

        final ShortcutInfo update = createShortcutForUri(Contacts.getLookupUri(contactId, shortcut.getId()));
        if (update != null) {
            updates.add(update);
            if (!shortcut.isEnabled()) {
                // Handle the case that a contact is disabled because it doesn't exist but
                // later is created (for instance by a sync)
                enable.add(update.getId());
            }
        } else if (shortcut.isEnabled()) {
            removedIds.add(shortcut.getId());
        }
    }

    if (Log.isLoggable(TAG, Log.DEBUG)) {
        Log.d(TAG, "updating " + updates);
        Log.d(TAG, "enabling " + enable);
        Log.d(TAG, "disabling " + removedIds);
    }

    mShortcutManager.updateShortcuts(updates);
    mShortcutManager.enableShortcuts(enable);
    mShortcutManager.disableShortcuts(removedIds,
            mContext.getString(R.string.dynamic_shortcut_contact_removed_message));
}