forked from upstream-mirrors/quik
Prettier avatars
This commit is contained in:
@@ -15,6 +15,7 @@ import android.graphics.drawable.Drawable;
|
|||||||
import android.net.Uri;
|
import android.net.Uri;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
import android.provider.ContactsContract;
|
import android.provider.ContactsContract;
|
||||||
|
import android.support.v4.content.ContextCompat;
|
||||||
import android.text.TextUtils;
|
import android.text.TextUtils;
|
||||||
import android.util.AttributeSet;
|
import android.util.AttributeSet;
|
||||||
import android.view.View;
|
import android.view.View;
|
||||||
@@ -22,12 +23,11 @@ import android.view.accessibility.AccessibilityEvent;
|
|||||||
import android.view.accessibility.AccessibilityNodeInfo;
|
import android.view.accessibility.AccessibilityNodeInfo;
|
||||||
import android.widget.ImageView;
|
import android.widget.ImageView;
|
||||||
import com.moez.QKSMS.R;
|
import com.moez.QKSMS.R;
|
||||||
import com.moez.QKSMS.interfaces.LiveView;
|
|
||||||
import com.moez.QKSMS.common.LiveViewManager;
|
import com.moez.QKSMS.common.LiveViewManager;
|
||||||
import com.moez.QKSMS.common.TypefaceManager;
|
import com.moez.QKSMS.common.TypefaceManager;
|
||||||
import com.moez.QKSMS.common.utils.ImageUtils;
|
import com.moez.QKSMS.common.utils.ImageUtils;
|
||||||
import com.moez.QKSMS.common.utils.PhoneNumberUtils;
|
|
||||||
import com.moez.QKSMS.common.utils.Units;
|
import com.moez.QKSMS.common.utils.Units;
|
||||||
|
import com.moez.QKSMS.interfaces.LiveView;
|
||||||
import com.moez.QKSMS.ui.ThemeManager;
|
import com.moez.QKSMS.ui.ThemeManager;
|
||||||
import com.moez.QKSMS.ui.settings.SettingsFragment;
|
import com.moez.QKSMS.ui.settings.SettingsFragment;
|
||||||
|
|
||||||
@@ -39,7 +39,7 @@ public class AvatarView extends ImageView implements View.OnClickListener, LiveV
|
|||||||
ContactsContract.PhoneLookup.LOOKUP_KEY,
|
ContactsContract.PhoneLookup.LOOKUP_KEY,
|
||||||
};
|
};
|
||||||
|
|
||||||
public static final String ME = ":)";
|
public static final String ME = "Me";
|
||||||
|
|
||||||
static final int PHONE_ID_COLUMN_INDEX = 0;
|
static final int PHONE_ID_COLUMN_INDEX = 0;
|
||||||
static final int PHONE_LOOKUP_STRING_COLUMN_INDEX = 1;
|
static final int PHONE_LOOKUP_STRING_COLUMN_INDEX = 1;
|
||||||
@@ -53,6 +53,7 @@ public class AvatarView extends ImageView implements View.OnClickListener, LiveV
|
|||||||
private Bundle mExtras = null;
|
private Bundle mExtras = null;
|
||||||
private String mInitial = "#";
|
private String mInitial = "#";
|
||||||
private Paint mPaint;
|
private Paint mPaint;
|
||||||
|
private Drawable mDefaultDrawable;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* When setImageDrawable is called with a drawable, we circle crop to size of this view and use
|
* When setImageDrawable is called with a drawable, we circle crop to size of this view and use
|
||||||
@@ -79,6 +80,8 @@ public class AvatarView extends ImageView implements View.OnClickListener, LiveV
|
|||||||
mPaint.setAntiAlias(true);
|
mPaint.setAntiAlias(true);
|
||||||
mPaint.setTypeface(TypefaceManager.obtainTypeface(getContext(), TypefaceManager.Typefaces.ROBOTO_LIGHT));
|
mPaint.setTypeface(TypefaceManager.obtainTypeface(getContext(), TypefaceManager.Typefaces.ROBOTO_LIGHT));
|
||||||
|
|
||||||
|
mDefaultDrawable = ContextCompat.getDrawable(context, R.drawable.ic_person);
|
||||||
|
|
||||||
final TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.AvatarView, defStyle, 0);
|
final TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.AvatarView, defStyle, 0);
|
||||||
for (int i = 0; i < a.getIndexCount(); i++) {
|
for (int i = 0; i < a.getIndexCount(); i++) {
|
||||||
if (a.getIndex(i) == R.styleable.AvatarView_initialSize) {
|
if (a.getIndex(i) == R.styleable.AvatarView_initialSize) {
|
||||||
@@ -160,38 +163,23 @@ public class AvatarView extends ImageView implements View.OnClickListener, LiveV
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void setContactName(String name) {
|
public void setContactName(String name) {
|
||||||
if (TextUtils.isEmpty(name)) {
|
if (TextUtils.isEmpty(name) || name.equals(ME)) {
|
||||||
mInitial = "#";
|
mInitial = "";
|
||||||
} else if (name.length() == 1 || name.equals(ME)) {
|
super.setImageDrawable(mDefaultDrawable);
|
||||||
|
} else if (name.length() == 1) {
|
||||||
mInitial = "" + name.toUpperCase();
|
mInitial = "" + name.toUpperCase();
|
||||||
|
if (mOriginalDrawable == null) super.setImageDrawable(null);
|
||||||
} else if (isPhoneNumberFormat(name)) {
|
} else if (isPhoneNumberFormat(name)) {
|
||||||
mInitial = "#";
|
mInitial = "";
|
||||||
|
super.setImageDrawable(mDefaultDrawable);
|
||||||
} else {
|
} else {
|
||||||
mInitial = "" + name.toUpperCase().charAt(0);
|
mInitial = "" + name.toUpperCase().charAt(0);
|
||||||
|
if (mOriginalDrawable == null) super.setImageDrawable(null);
|
||||||
}
|
}
|
||||||
|
|
||||||
invalidate();
|
invalidate();
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getContactPhone() {
|
|
||||||
return mContactPhone;
|
|
||||||
}
|
|
||||||
|
|
||||||
private boolean isValidPhoneNumber(String address) {
|
|
||||||
String networkPortion = PhoneNumberUtils.extractNetworkPortion(address);
|
|
||||||
|
|
||||||
return (!(networkPortion.equals("+") || TextUtils.isEmpty(networkPortion))) && isDialable(networkPortion);
|
|
||||||
}
|
|
||||||
|
|
||||||
private boolean isDialable(String address) {
|
|
||||||
for (int i = 0, count = address.length(); i < count; i++) {
|
|
||||||
if (!PhoneNumberUtils.isReallyDialable(address.charAt(i))) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
private boolean isPhoneNumberFormat(String name) {
|
private boolean isPhoneNumberFormat(String name) {
|
||||||
if (TextUtils.isEmpty(name)) {
|
if (TextUtils.isEmpty(name)) {
|
||||||
return false;
|
return false;
|
||||||
@@ -272,7 +260,7 @@ public class AvatarView extends ImageView implements View.OnClickListener, LiveV
|
|||||||
super.setImageDrawable(new BitmapDrawable(getResources(), roundBitmap));
|
super.setImageDrawable(new BitmapDrawable(getResources(), roundBitmap));
|
||||||
getBackground().setColorFilter(0x00000000, PorterDuff.Mode.MULTIPLY);
|
getBackground().setColorFilter(0x00000000, PorterDuff.Mode.MULTIPLY);
|
||||||
} else {
|
} else {
|
||||||
super.setImageDrawable(null);
|
super.setImageDrawable(TextUtils.isEmpty(mInitial) ? mDefaultDrawable : null);
|
||||||
getBackground().setColorFilter(ThemeManager.getColor(), PorterDuff.Mode.MULTIPLY);
|
getBackground().setColorFilter(ThemeManager.getColor(), PorterDuff.Mode.MULTIPLY);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -292,6 +280,7 @@ public class AvatarView extends ImageView implements View.OnClickListener, LiveV
|
|||||||
@Override
|
@Override
|
||||||
public void refresh() {
|
public void refresh() {
|
||||||
mPaint.setColor(ThemeManager.getTextOnColorPrimary());
|
mPaint.setColor(ThemeManager.getTextOnColorPrimary());
|
||||||
|
mDefaultDrawable.setColorFilter(ThemeManager.getTextOnColorPrimary(), PorterDuff.Mode.SRC_ATOP);
|
||||||
|
|
||||||
if (getBackground() == null) {
|
if (getBackground() == null) {
|
||||||
setBackgroundResource(R.drawable.circle);
|
setBackgroundResource(R.drawable.circle);
|
||||||
|
|||||||
@@ -0,0 +1,9 @@
|
|||||||
|
<vector xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
|
android:width="24dp"
|
||||||
|
android:height="24dp"
|
||||||
|
android:viewportHeight="40.0"
|
||||||
|
android:viewportWidth="40.0">
|
||||||
|
<path
|
||||||
|
android:fillColor="#FF000000"
|
||||||
|
android:pathData="M20,19c2.21,0 4,-1.79 4,-4s-1.79,-4 -4,-4 -4,1.79 -4,4 1.79,4 4, 4zM20,22c-2.67,0 -8,1.34 -8,4v2h16v-2c0,-2.66 -5.33,-4 -8,-4z" />
|
||||||
|
</vector>
|
||||||
Reference in New Issue
Block a user