Skip to content

Instantly share code, notes, and snippets.

View virendersran01's full-sized avatar
💻
Working from home

Virender Srxn virendersran01

💻
Working from home
  • India
View GitHub Profile
/*
* Create placeholder drawable
* */
private void setDrawable() {
drawable = new Drawable() {
@Override
public void draw(@NonNull Canvas canvas) {
int centerX = Math.round(canvas.getWidth() * 0.5f);
int centerY = Math.round(canvas.getHeight() * 0.5f);
/*
* Return user short name
* */
public static String getShortName(String name) {
String[] strings = name.split(" ");//no i18n
String shortName;
if (strings.length == 1) {
shortName = strings[0].substring(0, 2);
} else {
shortName = strings[0].substring(0, 1) + strings[1].substring(0, 1);
/*
* Initialize fields
* */
protected void init() {
rectF = new RectF();
clipPath = new Path();
imageSize = getResources().getDimensionPixelSize(R.dimen.avatar_size);
cornerRadius = (int) Utils.dpToPixel(2, getResources());
/*
* Path of them image to be clipped (to be shown)
* */
Path clipPath;
/*
* Place holder drawable (with background color and initials)
* */
Drawable drawable;
if(circleTheme){
Drawable drawable = ContextCompat.getDrawable(context, R.drawable.circle);
placeholder.setBackground(drawable);
} else {
Drawable drawable = ContextCompat.getDrawable(context, R.drawable.square);
placeholder.setBackground(drawable);
}
placeholder.setText(getInitials());
ViewUtil.setVisibility(avatar, View.GONE);
ViewUtil.setVisibility(squareAvatar, View.GONE);
<FrameLayout
android:id="@+id/speaker_avatar_container"
android:layout_width="40dp"
android:layout_height="40dp"
android:layout_gravity="center_vertical">
<TextView
android:id="@+id/placeholder"
android:layout_width="40dp"
android:layout_height="40dp"
<FrameLayout
android:id="@+id/speaker_avatar_container"
android:layout_width="40dp"
android:layout_height="40dp"
android:layout_gravity="center_vertical">
<TextView
android:id="@+id/placeholder"
android:layout_width="40dp"
android:layout_height="40dp"
placeholder.setText(getInitials());
ViewUtil.setVisibility(avatar, View.GONE);
Glide.with(context)
.load(member.getAvatar())
.asBitmap()
.into(new SimpleTarget<Bitmap>() {
@Override
public void onResourceReady(Bitmap resource, GlideAnimation<? super Bitmap> glideAnimation) {
avatar.setImageBitmap(resource);
ViewUtil.setVisibility(placeholder, View.GONE);
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle">
<solid android:color="@color/grey" />
<size
android:width="40dp"
android:height="40dp" />
</shape>
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle">
<corners android:radius="20dp" />
<solid android:color="@color/grey" />
<size
android:width="40dp"
android:height="40dp" />
</shape>