Example usage for android.content.pm ShortcutInfo getExtras

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

Introduction

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

Prototype

@Nullable
public PersistableBundle getExtras() 

Source Link

Document

Extras that the app can set for any purpose.

Usage

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 w  w w.  ja v a  2  s.c o m

        // 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));
}