Search in sources :

Example 6 with ShortcutInfoCompat

use of androidx.core.content.pm.ShortcutInfoCompat in project Signal-Android by WhisperSystems.

the class ConversationParentFragment method addIconToHomeScreen.

private static void addIconToHomeScreen(@NonNull Context context, @NonNull Bitmap bitmap, @NonNull Recipient recipient) {
    IconCompat icon = IconCompat.createWithAdaptiveBitmap(bitmap);
    String name = recipient.isSelf() ? context.getString(R.string.note_to_self) : recipient.getDisplayName(context);
    ShortcutInfoCompat shortcutInfoCompat = new ShortcutInfoCompat.Builder(context, recipient.getId().serialize() + '-' + System.currentTimeMillis()).setShortLabel(name).setIcon(icon).setIntent(ShortcutLauncherActivity.createIntent(context, recipient.getId())).build();
    Intent callbackIntent = new Intent(ACTION_PINNED_SHORTCUT);
    PendingIntent shortcutPinnedCallback = PendingIntent.getBroadcast(context, REQUEST_CODE_PIN_SHORTCUT, callbackIntent, 0);
    ShortcutManagerCompat.requestPinShortcut(context, shortcutInfoCompat, shortcutPinnedCallback.getIntentSender());
    bitmap.recycle();
}
Also used : IconCompat(androidx.core.graphics.drawable.IconCompat) SpannableStringBuilder(android.text.SpannableStringBuilder) MaterialAlertDialogBuilder(com.google.android.material.dialog.MaterialAlertDialogBuilder) PendingIntent(android.app.PendingIntent) Intent(android.content.Intent) SpannableString(android.text.SpannableString) PendingIntent(android.app.PendingIntent) ShortcutInfoCompat(androidx.core.content.pm.ShortcutInfoCompat)

Example 7 with ShortcutInfoCompat

use of androidx.core.content.pm.ShortcutInfoCompat in project Signal-Android by WhisperSystems.

the class ConversationUtil method buildShortcutInfo.

/**
 * Builds the shortcut info object for a given Recipient.
 *
 * @param context   The Context under which we are operating
 * @param recipient The Recipient to generate a ShortcutInfo for
 * @param rank      The rank that should be assigned to this recipient
 * @return The new ShortcutInfo
 */
@WorkerThread
@NonNull
private static ShortcutInfoCompat buildShortcutInfo(@NonNull Context context, @NonNull Recipient recipient, int rank) {
    Recipient resolved = recipient.resolve();
    Person[] persons = buildPersons(context, resolved);
    Long threadId = SignalDatabase.threads().getThreadIdFor(resolved.getId());
    String shortName = resolved.isSelf() ? context.getString(R.string.note_to_self) : resolved.getShortDisplayName(context);
    String longName = resolved.isSelf() ? context.getString(R.string.note_to_self) : resolved.getDisplayName(context);
    String shortcutId = getShortcutId(resolved);
    return new ShortcutInfoCompat.Builder(context, shortcutId).setLongLived(true).setIntent(ConversationIntents.createBuilder(context, resolved.getId(), threadId != null ? threadId : -1).build()).setShortLabel(shortName).setLongLabel(longName).setIcon(AvatarUtil.getIconCompatForShortcut(context, resolved)).setPersons(persons).setCategories(Collections.singleton(CATEGORY_SHARE_TARGET)).setActivity(new ComponentName(context, "org.thoughtcrime.securesms.RoutingActivity")).setRank(rank).setLocusId(new LocusIdCompat(shortcutId)).build();
}
Also used : Recipient(org.thoughtcrime.securesms.recipients.Recipient) ComponentName(android.content.ComponentName) Person(androidx.core.app.Person) ShortcutInfoCompat(androidx.core.content.pm.ShortcutInfoCompat) LocusIdCompat(androidx.core.content.LocusIdCompat) WorkerThread(androidx.annotation.WorkerThread) NonNull(androidx.annotation.NonNull)

Example 8 with ShortcutInfoCompat

use of androidx.core.content.pm.ShortcutInfoCompat in project Signal-Android by WhisperSystems.

the class ConversationUtil method setActiveShortcuts.

/**
 * Sets the shortcuts to match the provided recipient list. This call may fail due to getting
 * rate-limited.
 *
 * @param rankedRecipients The recipients in descending priority order. Meaning the most important
 *                         recipient should be first in the list.
 * @return True if the update was successful, false if we were rate-limited.
 */
@WorkerThread
public static boolean setActiveShortcuts(@NonNull Context context, @NonNull List<Recipient> rankedRecipients) {
    if (ShortcutManagerCompat.isRateLimitingActive(context)) {
        return false;
    }
    int maxShortcuts = ShortcutManagerCompat.getMaxShortcutCountPerActivity(context);
    if (rankedRecipients.size() > maxShortcuts) {
        Log.w(TAG, "Too many recipients provided! Provided: " + rankedRecipients.size() + ", Max: " + maxShortcuts);
        rankedRecipients = rankedRecipients.subList(0, maxShortcuts);
    }
    List<ShortcutInfoCompat> shortcuts = new ArrayList<>(rankedRecipients.size());
    for (int i = 0; i < rankedRecipients.size(); i++) {
        ShortcutInfoCompat info = buildShortcutInfo(context, rankedRecipients.get(i), i);
        shortcuts.add(info);
    }
    return ShortcutManagerCompat.setDynamicShortcuts(context, shortcuts);
}
Also used : ArrayList(java.util.ArrayList) ShortcutInfoCompat(androidx.core.content.pm.ShortcutInfoCompat) WorkerThread(androidx.annotation.WorkerThread)

Example 9 with ShortcutInfoCompat

use of androidx.core.content.pm.ShortcutInfoCompat in project Signal-Android by WhisperSystems.

the class ConversationUtil method pushShortcutForRecipientInternal.

/**
 * Pushes a dynamic shortcut for a given recipient to the shortcut manager
 */
@WorkerThread
private static void pushShortcutForRecipientInternal(@NonNull Context context, @NonNull Recipient recipient, int rank) {
    ShortcutInfoCompat shortcutInfo = buildShortcutInfo(context, recipient, rank);
    ShortcutManagerCompat.pushDynamicShortcut(context, shortcutInfo);
}
Also used : ShortcutInfoCompat(androidx.core.content.pm.ShortcutInfoCompat) WorkerThread(androidx.annotation.WorkerThread)

Example 10 with ShortcutInfoCompat

use of androidx.core.content.pm.ShortcutInfoCompat in project AntennaPod by AntennaPod.

the class SelectSubscriptionActivity method addShortcut.

private void addShortcut(Feed feed, Bitmap bitmap) {
    Intent intent = new Intent(this, MainActivity.class);
    intent.setAction(Intent.ACTION_MAIN);
    intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TASK);
    intent.putExtra(EXTRA_FEED_ID, feed.getId());
    String id = "subscription-" + feed.getId();
    IconCompat icon;
    if (bitmap != null) {
        icon = IconCompat.createWithAdaptiveBitmap(bitmap);
    } else {
        icon = IconCompat.createWithResource(this, R.drawable.ic_folder_shortcut);
    }
    ShortcutInfoCompat shortcut = new ShortcutInfoCompat.Builder(this, id).setShortLabel(feed.getTitle()).setLongLabel(feed.getFeedTitle()).setIntent(intent).setIcon(icon).build();
    setResult(RESULT_OK, ShortcutManagerCompat.createShortcutResultIntent(this, shortcut));
    finish();
}
Also used : IconCompat(androidx.core.graphics.drawable.IconCompat) Intent(android.content.Intent) ShortcutInfoCompat(androidx.core.content.pm.ShortcutInfoCompat)

Aggregations

ShortcutInfoCompat (androidx.core.content.pm.ShortcutInfoCompat)17 Intent (android.content.Intent)10 IconCompat (androidx.core.graphics.drawable.IconCompat)7 WorkerThread (androidx.annotation.WorkerThread)6 Bitmap (android.graphics.Bitmap)3 NonNull (androidx.annotation.NonNull)3 File (java.io.File)3 ArrayList (java.util.ArrayList)3 PendingIntent (android.app.PendingIntent)2 ComponentName (android.content.ComponentName)2 SpannableString (android.text.SpannableString)2 SpannableStringBuilder (android.text.SpannableStringBuilder)2 Person (androidx.core.app.Person)2 LocusIdCompat (androidx.core.content.LocusIdCompat)2 MaterialAlertDialogBuilder (com.google.android.material.dialog.MaterialAlertDialogBuilder)2 Book (com.orgzly.android.db.entity.Book)2 Recipient (org.thoughtcrime.securesms.recipients.Recipient)2 ActivityManager (android.app.ActivityManager)1 Context (android.content.Context)1 IntentSender (android.content.IntentSender)1