display contact picture in notification
This commit is contained in:
parent
82fa29bfc5
commit
01e2a3a4cd
|
@ -1,9 +1,11 @@
|
||||||
package eu.siacs.conversations.utils;
|
package eu.siacs.conversations.utils;
|
||||||
|
|
||||||
|
import java.io.FileNotFoundException;
|
||||||
import java.text.SimpleDateFormat;
|
import java.text.SimpleDateFormat;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Date;
|
import java.util.Date;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.Locale;
|
||||||
|
|
||||||
import eu.siacs.conversations.R;
|
import eu.siacs.conversations.R;
|
||||||
import eu.siacs.conversations.entities.Account;
|
import eu.siacs.conversations.entities.Account;
|
||||||
|
@ -24,6 +26,7 @@ import android.content.Intent;
|
||||||
import android.content.SharedPreferences;
|
import android.content.SharedPreferences;
|
||||||
import android.content.res.Resources;
|
import android.content.res.Resources;
|
||||||
import android.graphics.Bitmap;
|
import android.graphics.Bitmap;
|
||||||
|
import android.graphics.BitmapFactory;
|
||||||
import android.graphics.Canvas;
|
import android.graphics.Canvas;
|
||||||
import android.graphics.Paint;
|
import android.graphics.Paint;
|
||||||
import android.graphics.Rect;
|
import android.graphics.Rect;
|
||||||
|
@ -53,16 +56,16 @@ public class UIHelper {
|
||||||
} else if (difference < 60 * 10) {
|
} else if (difference < 60 * 10) {
|
||||||
return difference / 60 + " min ago";
|
return difference / 60 + " min ago";
|
||||||
} else if (difference < 60 * 60 * 24) {
|
} else if (difference < 60 * 60 * 24) {
|
||||||
SimpleDateFormat sdf = new SimpleDateFormat("HH:mm");
|
SimpleDateFormat sdf = new SimpleDateFormat("HH:mm",Locale.US);
|
||||||
return sdf.format(date);
|
return sdf.format(date);
|
||||||
} else {
|
} else {
|
||||||
SimpleDateFormat sdf = new SimpleDateFormat("MM/dd");
|
SimpleDateFormat sdf = new SimpleDateFormat("MM/dd",Locale.US);
|
||||||
return sdf.format(date);
|
return sdf.format(date);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static Bitmap getUnknownContactPicture(String name, int size) {
|
public static Bitmap getUnknownContactPicture(String name, int size) {
|
||||||
String firstLetter = name.substring(0, 1).toUpperCase();
|
String firstLetter = name.substring(0, 1).toUpperCase(Locale.US);
|
||||||
|
|
||||||
int holoColors[] = { 0xFF1da9da, 0xFFb368d9, 0xFF83b600, 0xFFffa713,
|
int holoColors[] = { 0xFF1da9da, 0xFFb368d9, 0xFF83b600, 0xFFffa713,
|
||||||
0xFFe92727 };
|
0xFFe92727 };
|
||||||
|
@ -87,6 +90,19 @@ public class UIHelper {
|
||||||
|
|
||||||
return bitmap;
|
return bitmap;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static Bitmap getContactPicture(Contact contact, int size, Context context) {
|
||||||
|
String uri = contact.getProfilePhoto();
|
||||||
|
if (uri==null) {
|
||||||
|
return getUnknownContactPicture(contact.getDisplayName(), size);
|
||||||
|
}
|
||||||
|
try {
|
||||||
|
Bitmap bm = BitmapFactory.decodeStream(context.getContentResolver().openInputStream(Uri.parse(uri)));
|
||||||
|
return Bitmap.createScaledBitmap(bm, size, size, false);
|
||||||
|
} catch (FileNotFoundException e) {
|
||||||
|
return getUnknownContactPicture(contact.getDisplayName(), size);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public static Bitmap getErrorPicture(int size) {
|
public static Bitmap getErrorPicture(int size) {
|
||||||
Bitmap bitmap = Bitmap
|
Bitmap bitmap = Bitmap
|
||||||
|
@ -134,10 +150,12 @@ public class UIHelper {
|
||||||
} else if (unread.size() == 1) {
|
} else if (unread.size() == 1) {
|
||||||
Conversation conversation = unread.get(0);
|
Conversation conversation = unread.get(0);
|
||||||
targetUuid = conversation.getUuid();
|
targetUuid = conversation.getUuid();
|
||||||
mBuilder.setLargeIcon(UIHelper.getUnknownContactPicture(
|
/*mBuilder.setLargeIcon(UIHelper.getUnknownContactPicture(
|
||||||
conversation.getName(),
|
conversation.getName(),
|
||||||
(int) res
|
(int) res
|
||||||
.getDimension(android.R.dimen.notification_large_icon_width)));
|
.getDimension(android.R.dimen.notification_large_icon_width)));*/
|
||||||
|
mBuilder.setLargeIcon(UIHelper.getContactPicture(conversation.getContact(), (int) res
|
||||||
|
.getDimension(android.R.dimen.notification_large_icon_width), context));
|
||||||
mBuilder.setContentTitle(conversation.getName());
|
mBuilder.setContentTitle(conversation.getName());
|
||||||
if (notify) {
|
if (notify) {
|
||||||
mBuilder.setTicker(conversation.getLatestMessage().getBody().trim());
|
mBuilder.setTicker(conversation.getLatestMessage().getBody().trim());
|
||||||
|
|
|
@ -193,7 +193,7 @@ public class XmppConnection implements Runnable {
|
||||||
processStream(tagReader.readTag());
|
processStream(tagReader.readTag());
|
||||||
break;
|
break;
|
||||||
} else if (nextTag.isStart("failure")) {
|
} else if (nextTag.isStart("failure")) {
|
||||||
Element failure = tagReader.readElement(nextTag);
|
tagReader.readElement(nextTag);
|
||||||
changeStatus(Account.STATUS_UNAUTHORIZED);
|
changeStatus(Account.STATUS_UNAUTHORIZED);
|
||||||
} else if (nextTag.isStart("enabled")) {
|
} else if (nextTag.isStart("enabled")) {
|
||||||
this.stanzasSent = 0;
|
this.stanzasSent = 0;
|
||||||
|
@ -224,6 +224,12 @@ public class XmppConnection implements Runnable {
|
||||||
this.stanzasSent = serverSequence;
|
this.stanzasSent = serverSequence;
|
||||||
}
|
}
|
||||||
//Log.d(LOGTAG,"server ack"+ack.toString()+" ("+this.stanzasSent+")");
|
//Log.d(LOGTAG,"server ack"+ack.toString()+" ("+this.stanzasSent+")");
|
||||||
|
} else if (nextTag.isStart("failed")) {
|
||||||
|
Log.d(LOGTAG,account.getJid()+": resumption failed");
|
||||||
|
streamId = null;
|
||||||
|
if (account.getStatus() != Account.STATUS_ONLINE) {
|
||||||
|
sendBindRequest();
|
||||||
|
}
|
||||||
} else if (nextTag.isStart("iq")) {
|
} else if (nextTag.isStart("iq")) {
|
||||||
processIq(nextTag);
|
processIq(nextTag);
|
||||||
} else if (nextTag.isStart("message")) {
|
} else if (nextTag.isStart("message")) {
|
||||||
|
|
Loading…
Reference in a new issue