mirror of
https://github.com/oxen-io/session-android.git
synced 2025-06-20 15:38:29 +00:00
Fix for lollipop notifications not rendering generated avatars.
// FREEBIE Fixes #3120 Closes #3122
This commit is contained in:
parent
2d8de5291e
commit
e62528d3e2
@ -24,6 +24,7 @@ import android.content.BroadcastReceiver;
|
|||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.content.Intent;
|
import android.content.Intent;
|
||||||
import android.database.Cursor;
|
import android.database.Cursor;
|
||||||
|
import android.graphics.Bitmap;
|
||||||
import android.graphics.BitmapFactory;
|
import android.graphics.BitmapFactory;
|
||||||
import android.graphics.Color;
|
import android.graphics.Color;
|
||||||
import android.graphics.drawable.Drawable;
|
import android.graphics.drawable.Drawable;
|
||||||
@ -178,12 +179,17 @@ public class MessageNotifier {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
List<NotificationItem> notifications = notificationState.getNotifications();
|
List<NotificationItem> notifications = notificationState.getNotifications();
|
||||||
NotificationCompat.Builder builder = new NotificationCompat.Builder(context);
|
NotificationCompat.Builder builder = new NotificationCompat.Builder(context);
|
||||||
Recipient recipient = notifications.get(0).getIndividualRecipient();
|
Recipient recipient = notifications.get(0).getIndividualRecipient();
|
||||||
Drawable recipientPhoto = recipient.getContactPhoto();
|
Drawable recipientPhoto = recipient.getContactPhoto();
|
||||||
|
int largeIconTargetSize = context.getResources().getDimensionPixelSize(R.dimen.contact_photo_target_size);
|
||||||
|
|
||||||
|
if (recipientPhoto != null) {
|
||||||
|
Bitmap recipientPhotoBitmap = BitmapUtil.createFromDrawable(recipientPhoto, largeIconTargetSize, largeIconTargetSize);
|
||||||
|
if (recipientPhotoBitmap != null) builder.setLargeIcon(recipientPhotoBitmap);
|
||||||
|
}
|
||||||
|
|
||||||
if (recipientPhoto != null) builder.setLargeIcon(BitmapUtil.createFromDrawable(recipientPhoto));
|
|
||||||
builder.setSmallIcon(R.drawable.icon_notification);
|
builder.setSmallIcon(R.drawable.icon_notification);
|
||||||
builder.setColor(context.getResources().getColor(R.color.textsecure_primary));
|
builder.setColor(context.getResources().getColor(R.color.textsecure_primary));
|
||||||
builder.setContentTitle(recipient.toShortString());
|
builder.setContentTitle(recipient.toShortString());
|
||||||
|
@ -15,10 +15,13 @@ import android.graphics.RectF;
|
|||||||
import android.graphics.drawable.BitmapDrawable;
|
import android.graphics.drawable.BitmapDrawable;
|
||||||
import android.graphics.drawable.Drawable;
|
import android.graphics.drawable.Drawable;
|
||||||
import android.net.Uri;
|
import android.net.Uri;
|
||||||
|
import android.os.Handler;
|
||||||
|
import android.os.Looper;
|
||||||
import android.util.Log;
|
import android.util.Log;
|
||||||
import android.util.Pair;
|
import android.util.Pair;
|
||||||
|
|
||||||
import com.android.gallery3d.data.Exif;
|
import com.android.gallery3d.data.Exif;
|
||||||
|
import com.makeramen.RoundedDrawable;
|
||||||
|
|
||||||
import org.thoughtcrime.securesms.crypto.MasterSecret;
|
import org.thoughtcrime.securesms.crypto.MasterSecret;
|
||||||
import org.thoughtcrime.securesms.mms.PartAuthority;
|
import org.thoughtcrime.securesms.mms.PartAuthority;
|
||||||
@ -28,6 +31,7 @@ import java.io.ByteArrayInputStream;
|
|||||||
import java.io.ByteArrayOutputStream;
|
import java.io.ByteArrayOutputStream;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.io.InputStream;
|
import java.io.InputStream;
|
||||||
|
import java.util.concurrent.atomic.AtomicBoolean;
|
||||||
|
|
||||||
public class BitmapUtil {
|
public class BitmapUtil {
|
||||||
private static final String TAG = BitmapUtil.class.getSimpleName();
|
private static final String TAG = BitmapUtil.class.getSimpleName();
|
||||||
@ -255,22 +259,47 @@ public class BitmapUtil {
|
|||||||
return output;
|
return output;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static Bitmap createFromDrawable(Drawable drawable) {
|
public static Bitmap createFromDrawable(final Drawable drawable, final int width, final int height) {
|
||||||
if (drawable instanceof BitmapDrawable) {
|
final AtomicBoolean created = new AtomicBoolean(false);
|
||||||
return ((BitmapDrawable)drawable).getBitmap();
|
final Bitmap[] result = new Bitmap[1];
|
||||||
|
|
||||||
|
new Handler(Looper.getMainLooper()).post(new Runnable() {
|
||||||
|
@Override
|
||||||
|
public void run() {
|
||||||
|
if (drawable instanceof BitmapDrawable) {
|
||||||
|
result[0] = ((BitmapDrawable) drawable).getBitmap();
|
||||||
|
} else {
|
||||||
|
int canvasWidth = drawable.getIntrinsicWidth();
|
||||||
|
if (canvasWidth <= 0) canvasWidth = width;
|
||||||
|
|
||||||
|
int canvasHeight = drawable.getIntrinsicHeight();
|
||||||
|
if (canvasHeight <= 0) canvasHeight = height;
|
||||||
|
|
||||||
|
Bitmap bitmap;
|
||||||
|
|
||||||
|
try {
|
||||||
|
bitmap = Bitmap.createBitmap(canvasWidth, canvasHeight, Bitmap.Config.ARGB_8888);
|
||||||
|
Canvas canvas = new Canvas(bitmap);
|
||||||
|
drawable.setBounds(0, 0, canvas.getWidth(), canvas.getHeight());
|
||||||
|
drawable.draw(canvas);
|
||||||
|
} catch (Exception e) {
|
||||||
|
Log.w(TAG, e);
|
||||||
|
bitmap = null;
|
||||||
|
}
|
||||||
|
|
||||||
|
result[0] = bitmap;
|
||||||
|
}
|
||||||
|
|
||||||
|
synchronized (result) {
|
||||||
|
created.set(true);
|
||||||
|
result.notifyAll();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
synchronized (result) {
|
||||||
|
while (!created.get()) Util.wait(result, 0);
|
||||||
|
return result[0];
|
||||||
}
|
}
|
||||||
|
|
||||||
int width = drawable.getIntrinsicWidth();
|
|
||||||
width = width > 0 ? width : 1;
|
|
||||||
|
|
||||||
int height = drawable.getIntrinsicHeight();
|
|
||||||
height = height > 0 ? height : 1;
|
|
||||||
|
|
||||||
Bitmap bitmap = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888);
|
|
||||||
Canvas canvas = new Canvas(bitmap);
|
|
||||||
drawable.draw(canvas);
|
|
||||||
|
|
||||||
return bitmap;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user