Example usage for android.content.pm ShortcutInfo isEnabled

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

Introduction

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

Prototype

public boolean isEnabled() 

Source Link

Document

Returns false if a shortcut is disabled with ShortcutManager#disableShortcuts .

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  ww . j  a 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));
}