make avatar rounding independent of image size

main
Konrad Pozniak 7 years ago
parent 714cb4e5bd
commit 45b18ac7a4
  1. 2
      app/src/main/java/com/keylesspalace/tusky/ComposeActivity.java
  2. 2
      app/src/main/java/com/keylesspalace/tusky/adapter/MentionAutoCompleteAdapter.java
  3. 6
      app/src/main/java/com/keylesspalace/tusky/adapter/NotificationsAdapter.java
  4. 2
      app/src/main/java/com/keylesspalace/tusky/adapter/StatusBaseViewHolder.java
  5. 2
      app/src/main/java/com/keylesspalace/tusky/adapter/StatusViewHolder.java
  6. 2
      app/src/main/java/com/keylesspalace/tusky/util/NotificationHelper.java
  7. 28
      app/src/main/java/com/keylesspalace/tusky/view/RoundedTransformation.java

@ -226,7 +226,7 @@ public final class ComposeActivity extends BaseActivity
composeAvatar.setImageResource(R.drawable.avatar_default);
} else {
Picasso.with(this).load(activeAccount.getProfilePictureUrl())
.transform(new RoundedTransformation(7, 0))
.transform(new RoundedTransformation(25))
.error(R.drawable.avatar_default)
.placeholder(R.drawable.avatar_default)
.into(composeAvatar);

@ -129,7 +129,7 @@ public class MentionAutoCompleteAdapter extends ArrayAdapter<Account>
Picasso.with(context)
.load(account.getAvatar())
.placeholder(R.drawable.avatar_default)
.transform(new RoundedTransformation(7, 0))
.transform(new RoundedTransformation(25))
.into(avatar);
}
}

@ -284,7 +284,7 @@ public class NotificationsAdapter extends RecyclerView.Adapter {
Picasso.with(context)
.load(avatarUrl)
.fit()
.transform(new RoundedTransformation(7, 0))
.transform(new RoundedTransformation(25))
.placeholder(R.drawable.avatar_default)
.into(avatar);
}
@ -445,7 +445,7 @@ public class NotificationsAdapter extends RecyclerView.Adapter {
Picasso.with(context)
.load(statusAvatarUrl)
.placeholder(R.drawable.avatar_default)
.transform(new RoundedTransformation(7, 0))
.transform(new RoundedTransformation(25))
.into(statusAvatar);
}
@ -456,7 +456,7 @@ public class NotificationsAdapter extends RecyclerView.Adapter {
.load(notificationAvatarUrl)
.placeholder(R.drawable.avatar_default)
.fit()
.transform(new RoundedTransformation(7, 0))
.transform(new RoundedTransformation(25))
.into(notificationAvatar);
}
}

@ -120,7 +120,7 @@ abstract class StatusBaseViewHolder extends RecyclerView.ViewHolder {
Picasso.with(avatar.getContext())
.load(url)
.placeholder(R.drawable.avatar_default)
.transform(new RoundedTransformation(7, 0))
.transform(new RoundedTransformation(25))
.into(avatar);
}
}

@ -63,7 +63,7 @@ public class StatusViewHolder extends StatusBaseViewHolder {
Picasso.with(context)
.load(rebloggedUrl)
.fit()
.transform(new RoundedTransformation(7, 0))
.transform(new RoundedTransformation(25))
.into(avatarReblog);
} else {
avatarReblog.setVisibility(View.GONE);

@ -145,7 +145,7 @@ public class NotificationHelper {
try {
accountAvatar = Picasso.with(context)
.load(body.getAccount().getAvatar())
.transform(new RoundedTransformation(7, 0))
.transform(new RoundedTransformation(20))
.get();
} catch (IOException e) {
Log.d(TAG, "error loading account avatar", e);

@ -26,25 +26,35 @@ import com.squareup.picasso.Transformation;
public class RoundedTransformation implements Transformation {
private final int radius;
private final int margin;
private final float percent;
public RoundedTransformation(final int radius, final int margin) {
this.radius = radius;
this.margin = margin;
/** 100% would mean a perfectly round image **/
public RoundedTransformation(final float percent) {
this.percent = percent;
}
@Override
public Bitmap transform(Bitmap source) {
final Paint paint = new Paint();
final int width = source.getWidth();
final int height = source.getHeight();
final int shorterSide;
if (width > height) {
shorterSide = height;
} else {
shorterSide = width;
}
final float radius = shorterSide / 2 * percent / 100;
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);
Bitmap output = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888);
Canvas canvas = new Canvas(output);
canvas.drawRoundRect(new RectF(margin, margin, source.getWidth() - margin, source.getHeight() - margin), radius, radius, paint);
canvas.drawRoundRect(new RectF(0, 0, width, height), radius, radius, paint);
if (source != output) {
source.recycle();
@ -55,6 +65,6 @@ public class RoundedTransformation implements Transformation {
@Override
public String key() {
return "rounded";
return "rounded "+percent+"%";
}
}

Loading…
Cancel
Save