aboutsummaryrefslogtreecommitdiffstats
path: root/src/main/java/de/pixart/messenger/services/ShortcutService.java
diff options
context:
space:
mode:
authorChristian Schneppe <christian@pix-art.de>2018-04-23 21:13:12 +0200
committerChristian Schneppe <christian@pix-art.de>2018-04-23 21:13:12 +0200
commit80064f6040cab219702d8221a052eace5f47661c (patch)
tree67c0676deebe0a6f899989eac3a96db5f4f2a167 /src/main/java/de/pixart/messenger/services/ShortcutService.java
parent44cf4a0ecbfef6303872316d20e4b18444f6932f (diff)
support contact shortcuts
* support contact shortcuts * make ShortcutActivity extends AbstractSearchableListItemActivity * Draw the app icon in the corner of the icon and modify the name of the widget * updated label and icon size
Diffstat (limited to 'src/main/java/de/pixart/messenger/services/ShortcutService.java')
-rw-r--r--src/main/java/de/pixart/messenger/services/ShortcutService.java42
1 files changed, 37 insertions, 5 deletions
diff --git a/src/main/java/de/pixart/messenger/services/ShortcutService.java b/src/main/java/de/pixart/messenger/services/ShortcutService.java
index c5d73d5b1..0578a8ce5 100644
--- a/src/main/java/de/pixart/messenger/services/ShortcutService.java
+++ b/src/main/java/de/pixart/messenger/services/ShortcutService.java
@@ -4,9 +4,11 @@ import android.annotation.TargetApi;
import android.content.Intent;
import android.content.pm.ShortcutInfo;
import android.content.pm.ShortcutManager;
+import android.graphics.Bitmap;
import android.graphics.drawable.Icon;
import android.net.Uri;
import android.os.Build;
+import android.support.annotation.NonNull;
import android.util.Log;
import java.util.ArrayList;
@@ -74,11 +76,7 @@ public class ShortcutService {
}
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();
+ ShortcutInfo shortcut = getShortcutInfo(contact);
newDynamicShortCuts.add(shortcut);
}
if (shortcutManager.setDynamicShortcuts(newDynamicShortCuts)) {
@@ -88,6 +86,15 @@ public class ShortcutService {
}
}
+ @TargetApi(Build.VERSION_CODES.N_MR1)
+ private ShortcutInfo getShortcutInfo(Contact contact) {
+ return new ShortcutInfo.Builder(xmppConnectionService, getShortcutId(contact))
+ .setShortLabel(contact.getDisplayName())
+ .setIntent(getShortcutIntent(contact))
+ .setIcon(Icon.createWithBitmap(xmppConnectionService.getAvatarService().getRoundedShortcut(contact)))
+ .build();
+ }
+
private static boolean contactsChanged(List<Contact> needles, List<ShortcutInfo> haystack) {
for (Contact needle : needles) {
if (!contactExists(needle, haystack)) {
@@ -119,6 +126,31 @@ public class ShortcutService {
return intent;
}
+ @NonNull
+ public Intent createShortcut(Contact contact) {
+ Intent intent;
+ if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
+ ShortcutInfo shortcut = getShortcutInfo(contact);
+ ShortcutManager shortcutManager = xmppConnectionService.getSystemService(ShortcutManager.class);
+ intent = shortcutManager.createShortcutResultIntent(shortcut);
+ } else {
+ intent = createShortcutResultIntent(contact);
+ }
+ return intent;
+ }
+
+ @NonNull
+ private Intent createShortcutResultIntent(Contact contact) {
+ Intent intent;
+ AvatarService avatarService = xmppConnectionService.getAvatarService();
+ Bitmap icon = avatarService.getRoundedShortcutWithIcon(contact);
+ intent = new Intent();
+ intent.putExtra(Intent.EXTRA_SHORTCUT_NAME, contact.getDisplayName());
+ intent.putExtra(Intent.EXTRA_SHORTCUT_ICON, icon);
+ intent.putExtra(Intent.EXTRA_SHORTCUT_INTENT, getShortcutIntent(contact));
+ return intent;
+ }
+
public static class FrequentContact {
private final String account;
private final Jid contact;