parent
0aeb002720
commit
136d1e1905
|
@ -9,8 +9,12 @@ import android.graphics.PorterDuff;
|
||||||
import android.graphics.PorterDuffXfermode;
|
import android.graphics.PorterDuffXfermode;
|
||||||
import android.graphics.Rect;
|
import android.graphics.Rect;
|
||||||
import android.graphics.Typeface;
|
import android.graphics.Typeface;
|
||||||
|
import android.graphics.drawable.BitmapDrawable;
|
||||||
|
import android.graphics.drawable.Drawable;
|
||||||
import android.net.Uri;
|
import android.net.Uri;
|
||||||
|
import android.support.annotation.DrawableRes;
|
||||||
import android.support.annotation.Nullable;
|
import android.support.annotation.Nullable;
|
||||||
|
import android.support.v4.content.res.ResourcesCompat;
|
||||||
import android.text.TextUtils;
|
import android.text.TextUtils;
|
||||||
import android.util.DisplayMetrics;
|
import android.util.DisplayMetrics;
|
||||||
import android.util.Log;
|
import android.util.Log;
|
||||||
|
@ -116,10 +120,11 @@ public class AvatarService implements OnAdvancedStreamFeaturesLoaded {
|
||||||
}
|
}
|
||||||
|
|
||||||
private void drawIcon(Canvas canvas, Paint paint) {
|
private void drawIcon(Canvas canvas, Paint paint) {
|
||||||
BitmapFactory.Options opts = new BitmapFactory.Options();
|
final Resources resources = mXmppConnectionService.getResources();
|
||||||
opts.inSampleSize = 2;
|
final Bitmap icon = getRoundLauncherIcon(resources);
|
||||||
Resources resources = mXmppConnectionService.getResources();
|
if (icon == null) {
|
||||||
Bitmap icon = BitmapFactory.decodeResource(resources, R.mipmap.new_launcher_round, opts);
|
return;
|
||||||
|
}
|
||||||
paint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.SRC_OVER));
|
paint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.SRC_OVER));
|
||||||
|
|
||||||
int iconSize = Math.round(canvas.getHeight() / 2.6f);
|
int iconSize = Math.round(canvas.getHeight() / 2.6f);
|
||||||
|
@ -130,6 +135,25 @@ public class AvatarService implements OnAdvancedStreamFeaturesLoaded {
|
||||||
canvas.drawBitmap(icon, null, rect, paint);
|
canvas.drawBitmap(icon, null, rect, paint);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static Bitmap getRoundLauncherIcon(Resources resources) {
|
||||||
|
|
||||||
|
final Drawable drawable = ResourcesCompat.getDrawable(resources, R.mipmap.new_launcher_round,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) {
|
public Bitmap get(final MucOptions.User user, final int size, boolean cachedOnly) {
|
||||||
Contact c = user.getContact();
|
Contact c = user.getContact();
|
||||||
if (c != null && (c.getProfilePhoto() != null || c.getAvatarFilename() != null || user.getAvatar() == null)) {
|
if (c != null && (c.getProfilePhoto() != null || c.getAvatarFilename() != null || user.getAvatar() == null)) {
|
||||||
|
|
|
@ -128,9 +128,9 @@ public class ShortcutService {
|
||||||
}
|
}
|
||||||
|
|
||||||
@NonNull
|
@NonNull
|
||||||
public Intent createShortcut(Contact contact) {
|
public Intent createShortcut(Contact contact, boolean legacy) {
|
||||||
Intent intent;
|
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);
|
ShortcutInfo shortcut = getShortcutInfo(contact);
|
||||||
ShortcutManager shortcutManager = xmppConnectionService.getSystemService(ShortcutManager.class);
|
ShortcutManager shortcutManager = xmppConnectionService.getSystemService(ShortcutManager.class);
|
||||||
intent = shortcutManager.createShortcutResultIntent(shortcut);
|
intent = shortcutManager.createShortcutResultIntent(shortcut);
|
||||||
|
@ -142,9 +142,9 @@ public class ShortcutService {
|
||||||
|
|
||||||
@NonNull
|
@NonNull
|
||||||
private Intent createShortcutResultIntent(Contact contact) {
|
private Intent createShortcutResultIntent(Contact contact) {
|
||||||
Intent intent;AvatarService avatarService = xmppConnectionService.getAvatarService();
|
AvatarService avatarService = xmppConnectionService.getAvatarService();
|
||||||
Bitmap icon = avatarService.getRoundedShortcutWithIcon(contact);
|
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_NAME, contact.getDisplayName());
|
||||||
intent.putExtra(Intent.EXTRA_SHORTCUT_ICON, icon);
|
intent.putExtra(Intent.EXTRA_SHORTCUT_ICON, icon);
|
||||||
intent.putExtra(Intent.EXTRA_SHORTCUT_INTENT, getShortcutIntent(contact));
|
intent.putExtra(Intent.EXTRA_SHORTCUT_INTENT, getShortcutIntent(contact));
|
||||||
|
|
|
@ -1,20 +1,27 @@
|
||||||
package eu.siacs.conversations.ui;
|
package eu.siacs.conversations.ui;
|
||||||
|
|
||||||
|
import android.content.ComponentName;
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.content.Intent;
|
import android.content.Intent;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
import android.support.v7.app.ActionBar;
|
import android.support.v7.app.ActionBar;
|
||||||
|
import android.util.Log;
|
||||||
import android.view.View;
|
import android.view.View;
|
||||||
import android.view.inputmethod.InputMethodManager;
|
import android.view.inputmethod.InputMethodManager;
|
||||||
|
|
||||||
|
import java.util.Arrays;
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
import eu.siacs.conversations.Config;
|
||||||
import eu.siacs.conversations.R;
|
import eu.siacs.conversations.R;
|
||||||
import eu.siacs.conversations.entities.Account;
|
import eu.siacs.conversations.entities.Account;
|
||||||
import eu.siacs.conversations.entities.Contact;
|
import eu.siacs.conversations.entities.Contact;
|
||||||
import eu.siacs.conversations.entities.ListItem;
|
import eu.siacs.conversations.entities.ListItem;
|
||||||
|
|
||||||
public class ShortcutActivity extends AbstractSearchableListItemActivity{
|
public class ShortcutActivity extends AbstractSearchableListItemActivity {
|
||||||
|
|
||||||
|
private static final List<String> BLACKLISTED_ACTIVITIES = Arrays.asList("com.teslacoilsw.launcher.ChooseActionIntentActivity");
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void refreshUiReal() {
|
protected void refreshUiReal() {
|
||||||
|
@ -25,15 +32,18 @@ public class ShortcutActivity extends AbstractSearchableListItemActivity{
|
||||||
public void onCreate(Bundle savedInstanceState) {
|
public void onCreate(Bundle savedInstanceState) {
|
||||||
super.onCreate(savedInstanceState);
|
super.onCreate(savedInstanceState);
|
||||||
getListView().setOnItemClickListener((parent, view, position, id) -> {
|
getListView().setOnItemClickListener((parent, view, position, id) -> {
|
||||||
|
|
||||||
|
final ComponentName callingActivity = getCallingActivity();
|
||||||
|
|
||||||
final InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
|
final InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
|
||||||
imm.hideSoftInputFromWindow(getSearchEditText().getWindowToken(), InputMethodManager.HIDE_IMPLICIT_ONLY);
|
imm.hideSoftInputFromWindow(getSearchEditText().getWindowToken(), InputMethodManager.HIDE_IMPLICIT_ONLY);
|
||||||
|
|
||||||
ListItem listItem = getListItems().get(position);
|
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);
|
setResult(RESULT_OK,shortcut);
|
||||||
finish();
|
finish();
|
||||||
});
|
});
|
||||||
binding.fab.setVisibility(View.GONE);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
Loading…
Reference in New Issue