Rounded corners on avatars in statuses
This commit is contained in:
parent
dd68e79a93
commit
9fdd14b722
4 changed files with 48 additions and 1 deletions
|
@ -160,6 +160,7 @@ public class MyFirebaseMessagingService extends FirebaseMessagingService {
|
||||||
Picasso.with(this)
|
Picasso.with(this)
|
||||||
.load(body.account.avatar)
|
.load(body.account.avatar)
|
||||||
.placeholder(R.drawable.avatar_default)
|
.placeholder(R.drawable.avatar_default)
|
||||||
|
.transform(new RoundedTransformation(7, 0))
|
||||||
.into(mTarget);
|
.into(mTarget);
|
||||||
|
|
||||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
|
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
|
||||||
|
|
|
@ -0,0 +1,45 @@
|
||||||
|
package com.keylesspalace.tusky;
|
||||||
|
|
||||||
|
import android.graphics.Bitmap;
|
||||||
|
import android.graphics.BitmapShader;
|
||||||
|
import android.graphics.Canvas;
|
||||||
|
import android.graphics.Paint;
|
||||||
|
import android.graphics.RectF;
|
||||||
|
import android.graphics.Shader;
|
||||||
|
|
||||||
|
import com.squareup.picasso.Transformation;
|
||||||
|
|
||||||
|
public class RoundedTransformation implements Transformation {
|
||||||
|
|
||||||
|
private final int radius;
|
||||||
|
private final int margin;
|
||||||
|
|
||||||
|
public RoundedTransformation(final int radius, final int margin) {
|
||||||
|
this.radius = radius;
|
||||||
|
this.margin = margin;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Bitmap transform(Bitmap source) {
|
||||||
|
final Paint paint = new Paint();
|
||||||
|
|
||||||
|
paint.setAntiAlias(true);
|
||||||
|
paint.setShader(new BitmapShader(source, Shader.TileMode.CLAMP, Shader.TileMode.CLAMP));
|
||||||
|
|
||||||
|
Bitmap output = Bitmap.createBitmap(source.getWidth(), source.getHeight(), Bitmap.Config.ARGB_8888);
|
||||||
|
Canvas canvas = new Canvas(output);
|
||||||
|
|
||||||
|
canvas.drawRoundRect(new RectF(margin, margin, source.getWidth() - margin, source.getHeight() - margin), radius, radius, paint);
|
||||||
|
|
||||||
|
if (source != output) {
|
||||||
|
source.recycle();
|
||||||
|
}
|
||||||
|
|
||||||
|
return output;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String key() {
|
||||||
|
return "rounded";
|
||||||
|
}
|
||||||
|
}
|
|
@ -158,6 +158,7 @@ class StatusViewHolder extends RecyclerView.ViewHolder {
|
||||||
.load(url)
|
.load(url)
|
||||||
.placeholder(R.drawable.avatar_default)
|
.placeholder(R.drawable.avatar_default)
|
||||||
.error(R.drawable.avatar_error)
|
.error(R.drawable.avatar_error)
|
||||||
|
.transform(new RoundedTransformation(7, 0))
|
||||||
.into(avatar);
|
.into(avatar);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -40,7 +40,7 @@
|
||||||
android:scaleType="fitCenter"
|
android:scaleType="fitCenter"
|
||||||
android:id="@+id/status_avatar"
|
android:id="@+id/status_avatar"
|
||||||
android:layout_below="@+id/status_reblogged_bar"
|
android:layout_below="@+id/status_reblogged_bar"
|
||||||
android:layout_marginTop="10dp"
|
android:layout_marginTop="11dp"
|
||||||
android:layout_marginRight="10dp" />
|
android:layout_marginRight="10dp" />
|
||||||
|
|
||||||
<RelativeLayout
|
<RelativeLayout
|
||||||
|
|
Loading…
Reference in a new issue