Major Contact Picture code cleanup
Notifications now have pseudotransparent icons, icons are generated in the correct size.
This commit is contained in:
parent
084ab51b1d
commit
901ce085a7
|
@ -381,7 +381,7 @@ public class ContactsActivity extends XmppActivity {
|
||||||
contactJid.setText(contact.getJid());
|
contactJid.setText(contact.getJid());
|
||||||
ImageView imageView = (ImageView) view
|
ImageView imageView = (ImageView) view
|
||||||
.findViewById(R.id.contact_photo);
|
.findViewById(R.id.contact_photo);
|
||||||
imageView.setImageBitmap(UIHelper.getContactPicture(contact, 90, this.getContext()));
|
imageView.setImageBitmap(UIHelper.getContactPicture(contact, 48, this.getContext(), false));
|
||||||
return view;
|
return view;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
|
@ -164,7 +164,7 @@ public class ConversationActivity extends XmppActivity {
|
||||||
ImageView imageView = (ImageView) view
|
ImageView imageView = (ImageView) view
|
||||||
.findViewById(R.id.conversation_image);
|
.findViewById(R.id.conversation_image);
|
||||||
imageView.setImageBitmap(UIHelper.getContactPicture(
|
imageView.setImageBitmap(UIHelper.getContactPicture(
|
||||||
conv, 200, activity.getApplicationContext()));
|
conv, 56, activity.getApplicationContext(), false));
|
||||||
return view;
|
return view;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -333,7 +333,7 @@ public class ConversationFragment extends Fragment {
|
||||||
boolean showPhoneSelfContactPicture = sharedPref.getBoolean(
|
boolean showPhoneSelfContactPicture = sharedPref.getBoolean(
|
||||||
"show_phone_selfcontact_picture", true);
|
"show_phone_selfcontact_picture", true);
|
||||||
|
|
||||||
return UIHelper.getSelfContactPicture(conversation.getAccount(), 200,
|
return UIHelper.getSelfContactPicture(conversation.getAccount(), 48,
|
||||||
showPhoneSelfContactPicture, getActivity());
|
showPhoneSelfContactPicture, getActivity());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -616,9 +616,9 @@ public class ConversationFragment extends Fragment {
|
||||||
} else {
|
} else {
|
||||||
Bitmap bm;
|
Bitmap bm;
|
||||||
if (contact != null){
|
if (contact != null){
|
||||||
bm = UIHelper.getContactPicture(contact, 200, context);
|
bm = UIHelper.getContactPicture(contact, 48, context, false);
|
||||||
} else {
|
} else {
|
||||||
bm = UIHelper.getContactPicture(name, 200, context);
|
bm = UIHelper.getContactPicture(name, 48, context, false);
|
||||||
}
|
}
|
||||||
bitmaps.put(name, bm);
|
bitmaps.put(name, bm);
|
||||||
return bm;
|
return bm;
|
||||||
|
|
|
@ -179,7 +179,7 @@ public class MucDetailsActivity extends XmppActivity {
|
||||||
role.setText(getReadableRole(contact.getRole()));
|
role.setText(getReadableRole(contact.getRole()));
|
||||||
ImageView imageView = (ImageView) view
|
ImageView imageView = (ImageView) view
|
||||||
.findViewById(R.id.contact_photo);
|
.findViewById(R.id.contact_photo);
|
||||||
imageView.setImageBitmap(UIHelper.getContactPicture(contact.getName(), 90,this.getApplicationContext()));
|
imageView.setImageBitmap(UIHelper.getContactPicture(contact.getName(), 48,this.getApplicationContext(), false));
|
||||||
membersView.addView(view);
|
membersView.addView(view);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -83,7 +83,8 @@ public class ShareWithActivity extends XmppActivity {
|
||||||
for(final Conversation conversation : convList) {
|
for(final Conversation conversation : convList) {
|
||||||
View view = createContactView(conversation.getName(useSubject),
|
View view = createContactView(conversation.getName(useSubject),
|
||||||
conversation.getLatestMessage().getBody().trim(),
|
conversation.getLatestMessage().getBody().trim(),
|
||||||
UIHelper.getContactPicture(conversation, 90,this.getApplicationContext()));
|
UIHelper.getContactPicture(conversation, 48,
|
||||||
|
this.getApplicationContext(), false));
|
||||||
view.setOnClickListener(new OnClickListener() {
|
view.setOnClickListener(new OnClickListener() {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -118,7 +119,7 @@ public class ShareWithActivity extends XmppActivity {
|
||||||
for(int i = 0; i < contactsList.size(); ++i) {
|
for(int i = 0; i < contactsList.size(); ++i) {
|
||||||
final Contact con = contactsList.get(i);
|
final Contact con = contactsList.get(i);
|
||||||
View view = createContactView(con.getDisplayName(), con.getJid(),
|
View view = createContactView(con.getDisplayName(), con.getJid(),
|
||||||
UIHelper.getContactPicture(con, 90, this.getApplicationContext()));
|
UIHelper.getContactPicture(con, 48, this.getApplicationContext(), false));
|
||||||
view.setOnClickListener(new OnClickListener() {
|
view.setOnClickListener(new OnClickListener() {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
@ -72,10 +72,10 @@ public class PhoneHelper {
|
||||||
mCursorLoader.startLoading();
|
mCursorLoader.startLoading();
|
||||||
}
|
}
|
||||||
|
|
||||||
public static Uri getSefliUri(Activity activity) {
|
public static Uri getSefliUri(Context context) {
|
||||||
String[] mProjection = new String[] { Profile._ID,
|
String[] mProjection = new String[] { Profile._ID,
|
||||||
Profile.PHOTO_THUMBNAIL_URI };
|
Profile.PHOTO_THUMBNAIL_URI };
|
||||||
Cursor mProfileCursor = activity.getContentResolver().query(
|
Cursor mProfileCursor = context.getContentResolver().query(
|
||||||
Profile.CONTENT_URI, mProjection, null, null, null);
|
Profile.CONTENT_URI, mProjection, null, null, null);
|
||||||
|
|
||||||
if (mProfileCursor.getCount() == 0) {
|
if (mProfileCursor.getCount() == 0) {
|
||||||
|
|
|
@ -40,6 +40,7 @@ import android.support.v4.app.NotificationCompat;
|
||||||
import android.support.v4.app.NotificationCompat.InboxStyle;
|
import android.support.v4.app.NotificationCompat.InboxStyle;
|
||||||
import android.support.v4.app.TaskStackBuilder;
|
import android.support.v4.app.TaskStackBuilder;
|
||||||
import android.text.Html;
|
import android.text.Html;
|
||||||
|
import android.util.DisplayMetrics;
|
||||||
import android.util.Log;
|
import android.util.Log;
|
||||||
import android.view.LayoutInflater;
|
import android.view.LayoutInflater;
|
||||||
import android.view.View;
|
import android.view.View;
|
||||||
|
@ -48,6 +49,10 @@ import android.widget.QuickContactBadge;
|
||||||
import android.widget.TextView;
|
import android.widget.TextView;
|
||||||
|
|
||||||
public class UIHelper {
|
public class UIHelper {
|
||||||
|
private static final int BG_COLOR = 0xFF181818;
|
||||||
|
private static final int FG_COLOR = 0xFFE5E5E5;
|
||||||
|
private static final int TRANSPARENT = 0x00000000;
|
||||||
|
|
||||||
public static String readableTimeDifference(long time) {
|
public static String readableTimeDifference(long time) {
|
||||||
if (time == 0) {
|
if (time == 0) {
|
||||||
return "just now";
|
return "just now";
|
||||||
|
@ -67,6 +72,11 @@ public class UIHelper {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static int getRealPx(int dp, Context context) {
|
||||||
|
final DisplayMetrics metrics = context.getResources().getDisplayMetrics();
|
||||||
|
return ((int) (dp * metrics.density));
|
||||||
|
}
|
||||||
|
|
||||||
private static int getNameColor(String name) {
|
private static int getNameColor(String name) {
|
||||||
int holoColors[] = { 0xFF1da9da, 0xFFb368d9, 0xFF83b600, 0xFFffa713,
|
int holoColors[] = { 0xFF1da9da, 0xFFb368d9, 0xFF83b600, 0xFFffa713,
|
||||||
0xFFe92727 };
|
0xFFe92727 };
|
||||||
|
@ -74,9 +84,8 @@ public class UIHelper {
|
||||||
return color;
|
return color;
|
||||||
}
|
}
|
||||||
|
|
||||||
private static Bitmap getUnknownContactPicture(String[] names, int size) {
|
|
||||||
final int fgColor = 0xffe5e5e5;
|
|
||||||
int tiles = (names.length > 4)? 4 : names.length;
|
int tiles = (names.length > 4)? 4 : names.length;
|
||||||
|
private static Bitmap getUnknownContactPicture(String[] names, int size, int bgColor, int fgColor) {
|
||||||
Bitmap bitmap = Bitmap
|
Bitmap bitmap = Bitmap
|
||||||
.createBitmap(size, size, Bitmap.Config.ARGB_8888);
|
.createBitmap(size, size, Bitmap.Config.ARGB_8888);
|
||||||
Canvas canvas = new Canvas(bitmap);
|
Canvas canvas = new Canvas(bitmap);
|
||||||
|
@ -107,7 +116,7 @@ public class UIHelper {
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 2:
|
case 2:
|
||||||
bitmap.eraseColor(fgColor);
|
bitmap.eraseColor(bgColor);
|
||||||
|
|
||||||
tilePaint.setColor(colors[0]);
|
tilePaint.setColor(colors[0]);
|
||||||
left = new Rect(0, 0, (size/2)-2, size);
|
left = new Rect(0, 0, (size/2)-2, size);
|
||||||
|
@ -131,7 +140,7 @@ public class UIHelper {
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 3:
|
case 3:
|
||||||
bitmap.eraseColor(fgColor);
|
bitmap.eraseColor(bgColor);
|
||||||
|
|
||||||
tilePaint.setColor(colors[0]);
|
tilePaint.setColor(colors[0]);
|
||||||
left = new Rect(0, 0, (size/2)-2, size);
|
left = new Rect(0, 0, (size/2)-2, size);
|
||||||
|
@ -166,7 +175,7 @@ public class UIHelper {
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 4:
|
case 4:
|
||||||
bitmap.eraseColor(fgColor);
|
bitmap.eraseColor(bgColor);
|
||||||
|
|
||||||
tilePaint.setColor(colors[0]);
|
tilePaint.setColor(colors[0]);
|
||||||
topLeft = new Rect(0, 0, (size/2)-2, (size/2)-2);
|
topLeft = new Rect(0, 0, (size/2)-2, (size/2)-2);
|
||||||
|
@ -208,27 +217,18 @@ public class UIHelper {
|
||||||
canvas.drawText(letters[3], (3 * size / 4) - (width / 2), (3* size / 4)
|
canvas.drawText(letters[3], (3 * size / 4) - (width / 2), (3* size / 4)
|
||||||
+ (rect.height() / 2), textPaint);
|
+ (rect.height() / 2), textPaint);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
default:
|
|
||||||
bitmap.eraseColor(colors[0]);
|
|
||||||
|
|
||||||
textPaint.setTextSize((float) (size * 0.9));
|
|
||||||
textPaint.setAntiAlias(true);
|
|
||||||
rect = new Rect();
|
|
||||||
textPaint.getTextBounds(letters[0], 0, 1, rect);
|
|
||||||
width = textPaint.measureText(letters[0]);
|
|
||||||
canvas.drawText(letters[0], (size / 2) - (width / 2), (size / 2)
|
|
||||||
+ (rect.height() / 2), textPaint);
|
|
||||||
break;
|
|
||||||
|
|
||||||
}
|
}
|
||||||
return bitmap;
|
return bitmap;
|
||||||
}
|
}
|
||||||
|
|
||||||
private static Bitmap getMucContactPicture(Conversation conversation, int size) {
|
private static Bitmap getUnknownContactPicture(String[] names, int size) {
|
||||||
|
return getUnknownContactPicture(names, size, UIHelper.BG_COLOR, UIHelper.FG_COLOR);
|
||||||
|
}
|
||||||
|
|
||||||
|
private static Bitmap getMucContactPicture(Conversation conversation, int size, int bgColor, int fgColor) {
|
||||||
List<User> members = conversation.getMucOptions().getUsers();
|
List<User> members = conversation.getMucOptions().getUsers();
|
||||||
if (members.size() == 0) {
|
if (members.size() == 0) {
|
||||||
return getUnknownContactPicture(new String[]{conversation.getName(false)}, size);
|
return getUnknownContactPicture(new String[]{conversation.getName(false)}, size, bgColor, fgColor);
|
||||||
}
|
}
|
||||||
String[] names = new String[members.size()+1];
|
String[] names = new String[members.size()+1];
|
||||||
names[0] = conversation.getMucOptions().getNick();
|
names[0] = conversation.getMucOptions().getNick();
|
||||||
|
@ -236,40 +236,56 @@ public class UIHelper {
|
||||||
names[i+1] = members.get(i).getName();
|
names[i+1] = members.get(i).getName();
|
||||||
}
|
}
|
||||||
|
|
||||||
return getUnknownContactPicture(names, size);
|
return getUnknownContactPicture(names, size, bgColor, fgColor);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static Bitmap getContactPicture(Conversation conversation, int size, Context context) {
|
public static Bitmap getContactPicture(Conversation conversation, int dpSize, Context context, boolean notification) {
|
||||||
if(conversation.getMode() == Conversation.MODE_SINGLE) {
|
if(conversation.getMode() == Conversation.MODE_SINGLE) {
|
||||||
if (conversation.getContact() != null){
|
if (conversation.getContact() != null){
|
||||||
return getContactPicture(conversation.getContact(), size, context);
|
return getContactPicture(conversation.getContact(), dpSize,
|
||||||
|
context, notification);
|
||||||
} else {
|
} else {
|
||||||
return getContactPicture(conversation.getName(false), size);
|
return getContactPicture(conversation.getName(false), dpSize,
|
||||||
|
context, notification);
|
||||||
}
|
}
|
||||||
} else{
|
} else{
|
||||||
return getMucContactPicture(conversation, size);
|
int fgColor = UIHelper.FG_COLOR,
|
||||||
|
bgColor = (notification) ?
|
||||||
|
UIHelper.BG_COLOR : UIHelper.TRANSPARENT;
|
||||||
|
|
||||||
|
return getMucContactPicture(conversation, getRealPx(dpSize, context),
|
||||||
|
bgColor, fgColor);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static Bitmap getContactPicture(Contact contact, int size, Context context) {
|
public static Bitmap getContactPicture(Contact contact, int dpSize, Context context, boolean notification) {
|
||||||
|
int fgColor = UIHelper.FG_COLOR,
|
||||||
|
bgColor = (notification) ?
|
||||||
|
UIHelper.BG_COLOR : UIHelper.TRANSPARENT;
|
||||||
|
|
||||||
String uri = contact.getProfilePhoto();
|
String uri = contact.getProfilePhoto();
|
||||||
if (uri==null) {
|
if (uri==null) {
|
||||||
return getContactPicture(contact.getDisplayName(), size);
|
return getContactPicture(contact.getDisplayName(), dpSize,
|
||||||
|
context, notification);
|
||||||
}
|
}
|
||||||
try {
|
try {
|
||||||
Bitmap bm = BitmapFactory.decodeStream(context.getContentResolver().openInputStream(Uri.parse(uri)));
|
Bitmap bm = BitmapFactory.decodeStream(context.getContentResolver()
|
||||||
return Bitmap.createScaledBitmap(bm, size, size, false);
|
.openInputStream(Uri.parse(uri)));
|
||||||
|
return Bitmap.createScaledBitmap(bm, getRealPx(dpSize, context),
|
||||||
|
getRealPx(dpSize, context), false);
|
||||||
} catch (FileNotFoundException e) {
|
} catch (FileNotFoundException e) {
|
||||||
return getContactPicture(contact.getDisplayName(), size);
|
return getContactPicture(contact.getDisplayName(), dpSize,
|
||||||
|
context, notification);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static Bitmap getContactPicture(String name, int size, Context context) {
|
public static Bitmap getContactPicture(String name, int dpSize, Context context, boolean notification) {
|
||||||
return getContactPicture(name, size);
|
int fgColor = UIHelper.FG_COLOR,
|
||||||
}
|
bgColor = (notification) ?
|
||||||
|
UIHelper.BG_COLOR : UIHelper.TRANSPARENT;
|
||||||
|
|
||||||
public static Bitmap getContactPicture(String name, int size) {
|
return getUnknownContactPicture(new String[]{name}, getRealPx(dpSize, context),
|
||||||
return getUnknownContactPicture(new String[]{name}, size);
|
bgColor, fgColor);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static Bitmap getErrorPicture(int size) {
|
public static Bitmap getErrorPicture(int size) {
|
||||||
|
@ -367,7 +383,6 @@ public class UIHelper {
|
||||||
}
|
}
|
||||||
String ringtone = preferences.getString("notification_ringtone", null);
|
String ringtone = preferences.getString("notification_ringtone", null);
|
||||||
|
|
||||||
Resources res = context.getResources();
|
|
||||||
NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(
|
NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(
|
||||||
context);
|
context);
|
||||||
if (unread.size() == 0) {
|
if (unread.size() == 0) {
|
||||||
|
@ -376,8 +391,8 @@ 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.getContactPicture(conversation, (int) res
|
mBuilder.setLargeIcon(UIHelper.getContactPicture(conversation, 64,
|
||||||
.getDimension(android.R.dimen.notification_large_icon_width), context));
|
context, true));
|
||||||
mBuilder.setContentTitle(conversation.getName(useSubject));
|
mBuilder.setContentTitle(conversation.getName(useSubject));
|
||||||
if (notify) {
|
if (notify) {
|
||||||
mBuilder.setTicker(conversation.getLatestMessage().getBody().trim());
|
mBuilder.setTicker(conversation.getLatestMessage().getBody().trim());
|
||||||
|
@ -480,7 +495,7 @@ public class UIHelper {
|
||||||
long id = Long.parseLong(systemAccount[0]);
|
long id = Long.parseLong(systemAccount[0]);
|
||||||
badge.assignContactUri(Contacts.getLookupUri(id, systemAccount[1]));
|
badge.assignContactUri(Contacts.getLookupUri(id, systemAccount[1]));
|
||||||
}
|
}
|
||||||
badge.setImageBitmap(UIHelper.getContactPicture(contact, 400, context));
|
badge.setImageBitmap(UIHelper.getContactPicture(contact, 72, context, false));
|
||||||
}
|
}
|
||||||
|
|
||||||
public static AlertDialog getVerifyFingerprintDialog(
|
public static AlertDialog getVerifyFingerprintDialog(
|
||||||
|
@ -516,20 +531,20 @@ public class UIHelper {
|
||||||
return builder.create();
|
return builder.create();
|
||||||
}
|
}
|
||||||
|
|
||||||
public static Bitmap getSelfContactPicture(Account account, int size, boolean showPhoneSelfContactPicture, Activity activity) {
|
public static Bitmap getSelfContactPicture(Account account, int size, boolean showPhoneSelfContactPicture, Context context) {
|
||||||
if (showPhoneSelfContactPicture) {
|
if (showPhoneSelfContactPicture) {
|
||||||
Uri selfiUri = PhoneHelper.getSefliUri(activity);
|
Uri selfiUri = PhoneHelper.getSefliUri(context);
|
||||||
if (selfiUri != null) {
|
if (selfiUri != null) {
|
||||||
try {
|
try {
|
||||||
return BitmapFactory.decodeStream(activity
|
return BitmapFactory.decodeStream(context
|
||||||
.getContentResolver().openInputStream(selfiUri));
|
.getContentResolver().openInputStream(selfiUri));
|
||||||
} catch (FileNotFoundException e) {
|
} catch (FileNotFoundException e) {
|
||||||
return getContactPicture(account.getJid(), size);
|
return getContactPicture(account.getJid(), size, context, false);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return getContactPicture(account.getJid(), size);
|
return getContactPicture(account.getJid(), size, context, false);
|
||||||
} else {
|
} else {
|
||||||
return getContactPicture(account.getJid(), size);
|
return getContactPicture(account.getJid(), size, context, false);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue