mirror of
https://github.com/M66B/FairEmail.git
synced 2024-12-25 09:17:58 +00:00
Create round icons in background
This commit is contained in:
parent
88a0452803
commit
c795dda8b8
3 changed files with 43 additions and 14 deletions
|
@ -35,7 +35,6 @@ import android.content.SharedPreferences;
|
|||
import android.content.pm.PackageManager;
|
||||
import android.content.res.ColorStateList;
|
||||
import android.database.Cursor;
|
||||
import android.graphics.Bitmap;
|
||||
import android.graphics.Color;
|
||||
import android.graphics.Rect;
|
||||
import android.graphics.Typeface;
|
||||
|
@ -82,8 +81,6 @@ import androidx.annotation.Nullable;
|
|||
import androidx.appcompat.widget.PopupMenu;
|
||||
import androidx.constraintlayout.widget.ConstraintLayout;
|
||||
import androidx.constraintlayout.widget.Group;
|
||||
import androidx.core.graphics.drawable.RoundedBitmapDrawable;
|
||||
import androidx.core.graphics.drawable.RoundedBitmapDrawableFactory;
|
||||
import androidx.lifecycle.Lifecycle;
|
||||
import androidx.lifecycle.LifecycleObserver;
|
||||
import androidx.lifecycle.LifecycleOwner;
|
||||
|
@ -147,7 +144,6 @@ public class AdapterMessage extends RecyclerView.Adapter<AdapterMessage.ViewHold
|
|||
private boolean contacts;
|
||||
private boolean search;
|
||||
private boolean avatars;
|
||||
private boolean circular;
|
||||
private boolean flags;
|
||||
private boolean preview;
|
||||
private boolean autohtml;
|
||||
|
@ -734,15 +730,9 @@ public class AdapterMessage extends RecyclerView.Adapter<AdapterMessage.ViewHold
|
|||
}
|
||||
|
||||
private void bindContactInfo(ContactInfo info, TupleMessageEx message) {
|
||||
if (info.hasPhoto()) {
|
||||
Bitmap bm = info.getPhotoBitmap();
|
||||
if (circular) {
|
||||
RoundedBitmapDrawable rounded = RoundedBitmapDrawableFactory.create(context.getResources(), bm);
|
||||
rounded.setCircular(true);
|
||||
ivAvatar.setImageDrawable(rounded);
|
||||
} else
|
||||
ivAvatar.setImageBitmap(info.getPhotoBitmap());
|
||||
} else
|
||||
if (info.hasPhoto())
|
||||
ivAvatar.setImageBitmap(info.getPhotoBitmap());
|
||||
else
|
||||
ivAvatar.setImageResource(R.drawable.baseline_person_24);
|
||||
ivAvatar.setVisibility(avatars ? View.VISIBLE : View.GONE);
|
||||
tvFrom.setText(info.getDisplayName(name_email));
|
||||
|
@ -3080,7 +3070,6 @@ public class AdapterMessage extends RecyclerView.Adapter<AdapterMessage.ViewHold
|
|||
PackageManager.COMPONENT_ENABLED_STATE_ENABLED);
|
||||
this.avatars = (prefs.getBoolean("avatars", true) ||
|
||||
prefs.getBoolean("identicons", false));
|
||||
this.circular = prefs.getBoolean("circular", true);
|
||||
this.flags = prefs.getBoolean("flags", true);
|
||||
this.preview = prefs.getBoolean("preview", false);
|
||||
this.autohtml = prefs.getBoolean("autohtml", false);
|
||||
|
|
|
@ -7,6 +7,13 @@ import android.content.SharedPreferences;
|
|||
import android.database.Cursor;
|
||||
import android.graphics.Bitmap;
|
||||
import android.graphics.BitmapFactory;
|
||||
import android.graphics.Canvas;
|
||||
import android.graphics.Color;
|
||||
import android.graphics.Paint;
|
||||
import android.graphics.PorterDuff;
|
||||
import android.graphics.PorterDuffXfermode;
|
||||
import android.graphics.Rect;
|
||||
import android.graphics.RectF;
|
||||
import android.net.Uri;
|
||||
import android.provider.ContactsContract;
|
||||
import android.util.TypedValue;
|
||||
|
@ -145,6 +152,38 @@ public class ContactInfo {
|
|||
info.bitmap = Identicon.letter(key, dp, dark);
|
||||
}
|
||||
|
||||
boolean circular = prefs.getBoolean("circular", true);
|
||||
if (info.bitmap != null && circular) {
|
||||
int w = info.bitmap.getWidth();
|
||||
int h = info.bitmap.getHeight();
|
||||
|
||||
Rect source;
|
||||
if (w > h) {
|
||||
int off = (w - h) / 2;
|
||||
source = new Rect(off, 0, w - off, h);
|
||||
} else if (w < h) {
|
||||
int off = (h - w) / 2;
|
||||
source = new Rect(0, off, w, h - off);
|
||||
} else
|
||||
source = new Rect(0, 0, w, h);
|
||||
|
||||
Rect dest = new Rect(0, 0, source.width(), source.height());
|
||||
|
||||
Bitmap round = Bitmap.createBitmap(source.width(), source.height(), Bitmap.Config.ARGB_8888);
|
||||
Canvas canvas = new Canvas(round);
|
||||
|
||||
Paint paint = new Paint();
|
||||
paint.setAntiAlias(true);
|
||||
canvas.drawARGB(0, 0, 0, 0);
|
||||
paint.setColor(Color.GRAY);
|
||||
canvas.drawOval(new RectF(dest), paint);
|
||||
paint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.SRC_IN));
|
||||
canvas.drawBitmap(info.bitmap, source, dest, paint);
|
||||
|
||||
info.bitmap.recycle();
|
||||
info.bitmap = round;
|
||||
}
|
||||
|
||||
if (info.displayName == null)
|
||||
info.displayName = address.getPersonal();
|
||||
|
||||
|
|
|
@ -345,6 +345,7 @@ public class FragmentOptions extends FragmentBase implements SharedPreferences.O
|
|||
@Override
|
||||
public void onCheckedChanged(CompoundButton compoundButton, boolean checked) {
|
||||
prefs.edit().putBoolean("circular", checked).apply();
|
||||
ContactInfo.clearCache();
|
||||
}
|
||||
});
|
||||
|
||||
|
|
Loading…
Reference in a new issue