diff options
author | Christian Schneppe <christian@pix-art.de> | 2019-01-07 20:49:44 +0100 |
---|---|---|
committer | Christian Schneppe <christian@pix-art.de> | 2019-01-07 20:49:44 +0100 |
commit | fb91826bd816ee363d509788bf9bd1276cef871e (patch) | |
tree | 777695c967790091a5bfea8da3e94ea35518d256 /src | |
parent | 63b800fabe3ea48595844643e653212c6ff61fa7 (diff) |
added work around to create 'actions' from nova launcher
Diffstat (limited to 'src')
3 files changed, 38 insertions, 10 deletions
diff --git a/src/main/java/de/pixart/messenger/services/AvatarService.java b/src/main/java/de/pixart/messenger/services/AvatarService.java index edc0a2e67..23e2da4d6 100644 --- a/src/main/java/de/pixart/messenger/services/AvatarService.java +++ b/src/main/java/de/pixart/messenger/services/AvatarService.java @@ -10,8 +10,11 @@ import android.graphics.PorterDuffXfermode; import android.graphics.Rect; import android.graphics.RectF; import android.graphics.Typeface; +import android.graphics.drawable.BitmapDrawable; +import android.graphics.drawable.Drawable; import android.net.Uri; import android.support.annotation.Nullable; +import android.support.v4.content.res.ResourcesCompat; import android.text.TextUtils; import android.util.DisplayMetrics; import android.util.Log; @@ -131,10 +134,11 @@ public class AvatarService implements OnAdvancedStreamFeaturesLoaded { } private void drawIcon(Canvas canvas, Paint paint) { - BitmapFactory.Options opts = new BitmapFactory.Options(); - opts.inSampleSize = 2; - Resources resources = mXmppConnectionService.getResources(); - Bitmap icon = BitmapFactory.decodeResource(resources, R.drawable.ic_launcher, opts); + final Resources resources = mXmppConnectionService.getResources(); + final Bitmap icon = getRoundLauncherIcon(resources); + if (icon == null) { + return; + } paint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.SRC_OVER)); int iconSize = Math.round(canvas.getHeight() / 2.6f); @@ -145,6 +149,25 @@ public class AvatarService implements OnAdvancedStreamFeaturesLoaded { canvas.drawBitmap(icon, null, rect, paint); } + private static Bitmap getRoundLauncherIcon(Resources resources) { + + final Drawable drawable = ResourcesCompat.getDrawable(resources, R.drawable.ic_launcher, null); + if (drawable == null) { + return null; + } + + if (drawable instanceof BitmapDrawable) { + return ((BitmapDrawable) drawable).getBitmap(); + } + + Bitmap bitmap = Bitmap.createBitmap(drawable.getIntrinsicWidth(), drawable.getIntrinsicHeight(), Bitmap.Config.ARGB_8888); + Canvas canvas = new Canvas(bitmap); + drawable.setBounds(0, 0, canvas.getWidth(), canvas.getHeight()); + drawable.draw(canvas); + + return bitmap; + } + public Bitmap get(final MucOptions.User user, final int size, boolean cachedOnly) { Contact c = user.getContact(); if (c != null && (c.getProfilePhoto() != null || c.getAvatarFilename() != null || user.getAvatar() == null)) { diff --git a/src/main/java/de/pixart/messenger/services/ShortcutService.java b/src/main/java/de/pixart/messenger/services/ShortcutService.java index 8051c8849..fa4853665 100644 --- a/src/main/java/de/pixart/messenger/services/ShortcutService.java +++ b/src/main/java/de/pixart/messenger/services/ShortcutService.java @@ -127,9 +127,9 @@ public class ShortcutService { } @NonNull - public Intent createShortcut(Contact contact) { + public Intent createShortcut(Contact contact, boolean legacy) { Intent intent; - if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) { + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O && !legacy) { ShortcutInfo shortcut = getShortcutInfo(contact); ShortcutManager shortcutManager = xmppConnectionService.getSystemService(ShortcutManager.class); intent = shortcutManager.createShortcutResultIntent(shortcut); @@ -141,10 +141,9 @@ public class ShortcutService { @NonNull private Intent createShortcutResultIntent(Contact contact) { - Intent intent; AvatarService avatarService = xmppConnectionService.getAvatarService(); Bitmap icon = avatarService.getRoundedShortcutWithIcon(contact); - intent = new Intent(); + Intent 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)); diff --git a/src/main/java/de/pixart/messenger/ui/ShortcutActivity.java b/src/main/java/de/pixart/messenger/ui/ShortcutActivity.java index ef5c296e0..68ad0cb86 100644 --- a/src/main/java/de/pixart/messenger/ui/ShortcutActivity.java +++ b/src/main/java/de/pixart/messenger/ui/ShortcutActivity.java @@ -1,5 +1,6 @@ package de.pixart.messenger.ui; +import android.content.ComponentName; import android.content.Context; import android.content.Intent; import android.os.Bundle; @@ -7,7 +8,9 @@ import android.support.v7.app.ActionBar; import android.view.View; import android.view.inputmethod.InputMethodManager; +import java.util.Arrays; import java.util.Collections; +import java.util.List; import de.pixart.messenger.R; import de.pixart.messenger.entities.Account; @@ -16,6 +19,8 @@ import de.pixart.messenger.entities.ListItem; public class ShortcutActivity extends AbstractSearchableListItemActivity { + private static final List<String> BLACKLISTED_ACTIVITIES = Arrays.asList("com.teslacoilsw.launcher.ChooseActionIntentActivity"); + @Override protected void refreshUiReal() { @@ -25,15 +30,16 @@ public class ShortcutActivity extends AbstractSearchableListItemActivity { public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); getListView().setOnItemClickListener((parent, view, position, id) -> { + final ComponentName callingActivity = getCallingActivity(); final InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE); imm.hideSoftInputFromWindow(getSearchEditText().getWindowToken(), InputMethodManager.HIDE_IMPLICIT_ONLY); ListItem listItem = getListItems().get(position); - Intent shortcut = xmppConnectionService.getShortcutService().createShortcut(((Contact) listItem)); + final boolean legacy = BLACKLISTED_ACTIVITIES.contains(callingActivity == null ? null : callingActivity.getClassName()); + Intent shortcut = xmppConnectionService.getShortcutService().createShortcut(((Contact) listItem), legacy); setResult(RESULT_OK, shortcut); finish(); }); - binding.fab.setVisibility(View.GONE); } @Override |