Search in sources :

Example 1 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 2 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 3 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 4 with ShortcutInfoCompat

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

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 5 with ShortcutInfoCompat

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

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)

Aggregations

ShortcutInfoCompat (androidx.core.content.pm.ShortcutInfoCompat)13 Intent (android.content.Intent)7 WorkerThread (androidx.annotation.WorkerThread)6 IconCompat (androidx.core.graphics.drawable.IconCompat)6 NonNull (androidx.annotation.NonNull)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 Bitmap (android.graphics.Bitmap)1 Canvas (android.graphics.Canvas)1 Point (android.graphics.Point)1 Rect (android.graphics.Rect)1