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();
}
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();
}
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);
}
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();
}
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();
}
Aggregations