Display a generated avatar icon rather than a single default.

If the contact doesn't have an image, render a color-coded
background and the first letter of the contact's name.

1) Don't display anything during recipient resolution.

2) Display a # icon in material gray for recipients with no name.

3) Display a material group icon in material gray for groups with
   no avatar icon set.

Closes #3104

// FREEBIE
This commit is contained in:
Moxie Marlinspike
2015-05-04 11:36:18 -07:00
parent 356d9949b7
commit 41cad291f9
24 changed files with 342 additions and 422 deletions

View File

@@ -0,0 +1,49 @@
package org.thoughtcrime.securesms.components;
import android.content.Context;
import android.content.Intent;
import android.provider.ContactsContract;
import android.util.AttributeSet;
import android.view.View;
import android.widget.ImageView;
import org.thoughtcrime.securesms.recipients.Recipient;
public class AvatarImageView extends ImageView {
public AvatarImageView(Context context) {
super(context);
setScaleType(ScaleType.CENTER_INSIDE);
}
public AvatarImageView(Context context, AttributeSet attrs) {
super(context, attrs);
setScaleType(ScaleType.CENTER_INSIDE);
}
public void setAvatar(Recipient recipient, boolean quickContactEnabled) {
setImageDrawable(recipient.getContactPhoto());
setAvatarClickHandler(recipient, quickContactEnabled);
}
private void setAvatarClickHandler(final Recipient recipient, boolean quickContactEnabled) {
if (!recipient.isGroupRecipient() && quickContactEnabled) {
setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
if (recipient.getContactUri() != null) {
ContactsContract.QuickContact.showQuickContact(getContext(), AvatarImageView.this, recipient.getContactUri(), ContactsContract.QuickContact.MODE_LARGE, null);
} else {
final Intent intent = new Intent(Intent.ACTION_INSERT_OR_EDIT);
intent.putExtra(ContactsContract.Intents.Insert.PHONE, recipient.getNumber());
intent.setType(ContactsContract.Contacts.CONTENT_ITEM_TYPE);
getContext().startActivity(intent);
}
}
});
} else {
setOnClickListener(null);
}
}
}

View File

@@ -0,0 +1,69 @@
package org.thoughtcrime.securesms.components;
import android.content.Context;
import android.content.res.TypedArray;
import android.graphics.Typeface;
import android.text.Spannable;
import android.text.SpannableStringBuilder;
import android.text.TextUtils;
import android.text.style.StyleSpan;
import android.util.AttributeSet;
import android.widget.TextView;
import org.thoughtcrime.securesms.R;
import org.thoughtcrime.securesms.recipients.Recipient;
import org.thoughtcrime.securesms.recipients.Recipients;
public class FromTextView extends TextView {
public FromTextView(Context context) {
super(context);
}
public FromTextView(Context context, AttributeSet attrs) {
super(context, attrs);
}
public void setText(Recipient recipient) {
setText(new Recipients(recipient));
}
public void setText(Recipients recipients) {
setText(recipients, true);
}
public void setText(Recipients recipients, boolean read) {
int attributes[] = new int[]{R.attr.conversation_list_item_count_color};
TypedArray colors = getContext().obtainStyledAttributes(attributes);
boolean isUnnamedGroup = recipients.isGroupRecipient() && TextUtils.isEmpty(recipients.getPrimaryRecipient().getName());
String fromString;
if (isUnnamedGroup) {
fromString = getContext().getString(R.string.ConversationActivity_unnamed_group);
} else {
fromString = recipients.toShortString();
}
int typeface;
if (isUnnamedGroup) {
if (!read) typeface = Typeface.BOLD_ITALIC;
else typeface = Typeface.ITALIC;
} else if (!read) {
typeface = Typeface.BOLD;
} else {
typeface = Typeface.NORMAL;
}
SpannableStringBuilder builder = new SpannableStringBuilder(fromString);
builder.setSpan(new StyleSpan(typeface), 0, builder.length(),
Spannable.SPAN_INCLUSIVE_EXCLUSIVE);
colors.recycle();
setText(builder);
}
}