Search in sources :

Example 21 with ShortcutManager

use of android.content.pm.ShortcutManager in project SpotiQ by ZinoKader.

the class ShortcutUtil method addSearchShortcut.

@RequiresApi(api = Build.VERSION_CODES.N_MR1)
public static void addSearchShortcut(Context context, String searchWithPartyTitle) {
    ShortcutManager shortcutManager = context.getSystemService(ShortcutManager.class);
    Intent openSearch = new Intent(context.getApplicationContext(), SearchActivity.class);
    openSearch.putExtra(ApplicationConstants.PARTY_NAME_EXTRA, searchWithPartyTitle);
    openSearch.setAction(Intent.ACTION_VIEW);
    ShortcutInfo shortcut = new ShortcutInfo.Builder(context, ApplicationConstants.SEARCH_SHORTCUT_ID).setShortLabel("Search songs").setLongLabel("Search for songs to add to the queue").setIcon(Icon.createWithResource(context, R.drawable.ic_shortcut_search)).setIntent(openSearch).build();
    shortcutManager.setDynamicShortcuts(Arrays.asList(shortcut));
}
Also used : ShortcutInfo(android.content.pm.ShortcutInfo) ShortcutManager(android.content.pm.ShortcutManager) Intent(android.content.Intent) RequiresApi(android.support.annotation.RequiresApi)

Example 22 with ShortcutManager

use of android.content.pm.ShortcutManager in project Conversations by siacs.

the class ShortcutService method createShortcut.

@NonNull
public Intent createShortcut(Contact contact, boolean legacy) {
    Intent intent;
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O && !legacy) {
        ShortcutInfo shortcut = getShortcutInfo(contact);
        ShortcutManager shortcutManager = xmppConnectionService.getSystemService(ShortcutManager.class);
        intent = shortcutManager.createShortcutResultIntent(shortcut);
    } else {
        intent = createShortcutResultIntent(contact);
    }
    return intent;
}
Also used : ShortcutInfo(android.content.pm.ShortcutInfo) ShortcutManager(android.content.pm.ShortcutManager) Intent(android.content.Intent) NonNull(androidx.annotation.NonNull)

Example 23 with ShortcutManager

use of android.content.pm.ShortcutManager in project Conversations by siacs.

the class ShortcutService method refreshImpl.

@TargetApi(25)
private void refreshImpl(boolean forceUpdate) {
    List<FrequentContact> frequentContacts = xmppConnectionService.databaseBackend.getFrequentContacts(30);
    HashMap<String, Account> accounts = new HashMap<>();
    for (Account account : xmppConnectionService.getAccounts()) {
        accounts.put(account.getUuid(), account);
    }
    List<Contact> contacts = new ArrayList<>();
    for (FrequentContact frequentContact : frequentContacts) {
        Account account = accounts.get(frequentContact.account);
        if (account != null) {
            contacts.add(account.getRoster().getContact(frequentContact.contact));
        }
    }
    ShortcutManager shortcutManager = xmppConnectionService.getSystemService(ShortcutManager.class);
    boolean needsUpdate = forceUpdate || contactsChanged(contacts, shortcutManager.getDynamicShortcuts());
    if (!needsUpdate) {
        Log.d(Config.LOGTAG, "skipping shortcut update");
        return;
    }
    List<ShortcutInfo> newDynamicShortCuts = new ArrayList<>();
    for (Contact contact : contacts) {
        ShortcutInfo shortcut = getShortcutInfo(contact);
        newDynamicShortCuts.add(shortcut);
    }
    if (shortcutManager.setDynamicShortcuts(newDynamicShortCuts)) {
        Log.d(Config.LOGTAG, "updated dynamic shortcuts");
    } else {
        Log.d(Config.LOGTAG, "unable to update dynamic shortcuts");
    }
}
Also used : Account(eu.siacs.conversations.entities.Account) ShortcutInfo(android.content.pm.ShortcutInfo) HashMap(java.util.HashMap) ShortcutManager(android.content.pm.ShortcutManager) ArrayList(java.util.ArrayList) Contact(eu.siacs.conversations.entities.Contact) TargetApi(android.annotation.TargetApi)

Example 24 with ShortcutManager

use of android.content.pm.ShortcutManager in project Resurrection_packages_apps_Settings by ResurrectionRemix.

the class CreateShortcutPreferenceController method updateRestoredShortcuts.

public static void updateRestoredShortcuts(Context context) {
    ShortcutManager sm = context.getSystemService(ShortcutManager.class);
    List<ShortcutInfo> updatedShortcuts = new ArrayList<>();
    for (ShortcutInfo si : sm.getPinnedShortcuts()) {
        if (si.getId().startsWith(SHORTCUT_ID_PREFIX)) {
            ResolveInfo ri = context.getPackageManager().resolveActivity(si.getIntent(), 0);
            if (ri != null) {
                updatedShortcuts.add(createShortcutInfo(context, buildShortcutIntent(ri), ri, si.getShortLabel()));
            }
        }
    }
    if (!updatedShortcuts.isEmpty()) {
        sm.updateShortcuts(updatedShortcuts);
    }
}
Also used : ResolveInfo(android.content.pm.ResolveInfo) ShortcutInfo(android.content.pm.ShortcutInfo) ShortcutManager(android.content.pm.ShortcutManager) ArrayList(java.util.ArrayList)

Example 25 with ShortcutManager

use of android.content.pm.ShortcutManager in project Resurrection_packages_apps_Settings by ResurrectionRemix.

the class ShortcutsUpdateTask method doInBackground.

@Override
public Void doInBackground(Void... params) {
    ShortcutManager sm = mContext.getSystemService(ShortcutManager.class);
    PackageManager pm = mContext.getPackageManager();
    List<ShortcutInfo> updates = new ArrayList<>();
    for (ShortcutInfo info : sm.getPinnedShortcuts()) {
        if (!info.getId().startsWith(SHORTCUT_ID_PREFIX)) {
            continue;
        }
        ComponentName cn = ComponentName.unflattenFromString(info.getId().substring(SHORTCUT_ID_PREFIX.length()));
        ResolveInfo ri = pm.resolveActivity(new Intent(SHORTCUT_PROBE).setComponent(cn), 0);
        if (ri == null) {
            continue;
        }
        updates.add(new ShortcutInfo.Builder(mContext, info.getId()).setShortLabel(ri.loadLabel(pm)).build());
    }
    if (!updates.isEmpty()) {
        sm.updateShortcuts(updates);
    }
    return null;
}
Also used : ResolveInfo(android.content.pm.ResolveInfo) PackageManager(android.content.pm.PackageManager) ShortcutInfo(android.content.pm.ShortcutInfo) ShortcutManager(android.content.pm.ShortcutManager) ArrayList(java.util.ArrayList) ComponentName(android.content.ComponentName) Intent(android.content.Intent)

Aggregations

ShortcutManager (android.content.pm.ShortcutManager)55 ShortcutInfo (android.content.pm.ShortcutInfo)39 Intent (android.content.Intent)31 ArrayList (java.util.ArrayList)19 TargetApi (android.annotation.TargetApi)15 PendingIntent (android.app.PendingIntent)7 Icon (android.graphics.drawable.Icon)7 ActivityInfo (android.content.pm.ActivityInfo)6 Bundle (android.os.Bundle)6 ComponentName (android.content.ComponentName)5 ResolveInfo (android.content.pm.ResolveInfo)4 PackageManager (android.content.pm.PackageManager)3 WorkerThread (android.support.annotation.WorkerThread)3 SuppressLint (android.annotation.SuppressLint)2 ActivityNotFoundException (android.content.ActivityNotFoundException)2 Cursor (android.database.Cursor)2 Bitmap (android.graphics.Bitmap)2 Uri (android.net.Uri)2 RequiresApi (android.support.annotation.RequiresApi)2 VisibleForTesting (androidx.annotation.VisibleForTesting)2