Search in sources :

Example 46 with ShortcutManager

use of android.content.pm.ShortcutManager in project xabber-android by redsolution.

the class ShortcutBuilder method createPinnedShortcut.

public static Intent createPinnedShortcut(Context context, AbstractContact contact) {
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
        ShortcutManager manager = context.getSystemService(ShortcutManager.class);
        if (manager != null && manager.isRequestPinShortcutSupported()) {
            ShortcutInfo shortcutInfo = createShortcutInfo(context, contact);
            Intent callbackIntent = manager.createShortcutResultIntent(shortcutInfo);
            PendingIntent successCallback = PendingIntent.getBroadcast(context, 0, callbackIntent, 0);
            manager.requestPinShortcut(shortcutInfo, successCallback.getIntentSender());
            return null;
        }
    }
    Intent intent = new Intent();
    intent.putExtra(Intent.EXTRA_SHORTCUT_INTENT, ChatActivity.createClearTopIntent(context, contact.getAccount(), contact.getUser()));
    intent.putExtra(Intent.EXTRA_SHORTCUT_NAME, contact.getName());
    intent.putExtra(Intent.EXTRA_SHORTCUT_ICON, getAvatar(contact));
    return intent;
}
Also used : ShortcutInfo(android.content.pm.ShortcutInfo) ShortcutManager(android.content.pm.ShortcutManager) Intent(android.content.Intent) PendingIntent(android.app.PendingIntent) PendingIntent(android.app.PendingIntent)

Example 47 with ShortcutManager

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

the class ShortcutService method report.

@TargetApi(25)
public void report(Contact contact) {
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N_MR1) {
        ShortcutManager shortcutManager = xmppConnectionService.getSystemService(ShortcutManager.class);
        shortcutManager.reportShortcutUsed(getShortcutId(contact));
    }
}
Also used : ShortcutManager(android.content.pm.ShortcutManager) TargetApi(android.annotation.TargetApi)

Example 48 with ShortcutManager

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

the class ShortcutUtil method removeAllShortcuts.

@RequiresApi(api = Build.VERSION_CODES.N_MR1)
public static void removeAllShortcuts(Context context) {
    ShortcutManager shortcutManager = context.getSystemService(ShortcutManager.class);
    shortcutManager.disableShortcuts(Arrays.asList(ApplicationConstants.SEARCH_SHORTCUT_ID));
    shortcutManager.removeAllDynamicShortcuts();
}
Also used : ShortcutManager(android.content.pm.ShortcutManager) RequiresApi(android.support.annotation.RequiresApi)

Example 49 with ShortcutManager

use of android.content.pm.ShortcutManager in project Pix-Art-Messenger by kriztan.

the class ShortcutService method report.

@TargetApi(25)
public void report(Contact contact) {
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N_MR1) {
        ShortcutManager shortcutManager = xmppConnectionService.getSystemService(ShortcutManager.class);
        shortcutManager.reportShortcutUsed(getShortcutId(contact));
    }
}
Also used : ShortcutManager(android.content.pm.ShortcutManager) TargetApi(android.annotation.TargetApi)

Example 50 with ShortcutManager

use of android.content.pm.ShortcutManager in project Pix-Art-Messenger by kriztan.

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 = new ShortcutInfo.Builder(xmppConnectionService, getShortcutId(contact)).setShortLabel(contact.getDisplayName()).setIntent(getShortcutIntent(contact)).setIcon(Icon.createWithBitmap(xmppConnectionService.getAvatarService().getRoundedShortcut(contact))).build();
        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(de.pixart.messenger.entities.Account) ShortcutInfo(android.content.pm.ShortcutInfo) HashMap(java.util.HashMap) ShortcutManager(android.content.pm.ShortcutManager) ArrayList(java.util.ArrayList) Contact(de.pixart.messenger.entities.Contact) TargetApi(android.annotation.TargetApi)

Aggregations

ShortcutManager (android.content.pm.ShortcutManager)60 ShortcutInfo (android.content.pm.ShortcutInfo)43 Intent (android.content.Intent)33 ArrayList (java.util.ArrayList)20 TargetApi (android.annotation.TargetApi)17 Icon (android.graphics.drawable.Icon)9 Bundle (android.os.Bundle)7 PendingIntent (android.app.PendingIntent)6 ActivityInfo (android.content.pm.ActivityInfo)6 ComponentName (android.content.ComponentName)5 ResolveInfo (android.content.pm.ResolveInfo)5 PackageManager (android.content.pm.PackageManager)4 File (java.io.File)4 ActivityNotFoundException (android.content.ActivityNotFoundException)3 SharedPreferences (android.content.SharedPreferences)3 Uri (android.net.Uri)3 WorkerThread (android.support.annotation.WorkerThread)3 SuppressLint (android.annotation.SuppressLint)2 AlertDialog (android.app.AlertDialog)2 FragmentTransaction (android.app.FragmentTransaction)2