Fix custom emoji size (#407)

Now custom emoji images adapt to the font size.
This commit is contained in:
Ivan Kupalov 2017-10-24 01:04:53 +04:00 committed by Konrad Pozniak
parent d9bbb1be71
commit 938229d7d4
1 changed files with 4 additions and 5 deletions

View File

@ -524,15 +524,16 @@ class StatusBaseViewHolder extends RecyclerView.ViewHolder {
} }
public void setCallback(Callback callback) { public void setCallback(Callback callback) {
this.callbackWeakReference = new WeakReference<Callback>(callback); this.callbackWeakReference = new WeakReference<>(callback);
} }
@Override @Override
public int getSize(@NonNull Paint paint, CharSequence text, int start, int end, public int getSize(@NonNull Paint paint, CharSequence text, int start, int end,
@Nullable Paint.FontMetricsInt fm) { @Nullable Paint.FontMetricsInt fm) {
if (imageDrawable == null) return 0; if (imageDrawable == null) return 0;
Rect sizeRect = imageDrawable.getBounds(); int textSize = (int) paint.getTextSize();
return sizeRect.right; imageDrawable.setBounds(0, 0, textSize, textSize);
return textSize;
} }
@Override @Override
@ -550,8 +551,6 @@ class StatusBaseViewHolder extends RecyclerView.ViewHolder {
@Override @Override
public void onBitmapLoaded(Bitmap bitmap, Picasso.LoadedFrom from) { public void onBitmapLoaded(Bitmap bitmap, Picasso.LoadedFrom from) {
imageDrawable = new BitmapDrawable(bitmap); imageDrawable = new BitmapDrawable(bitmap);
imageDrawable.setBounds(0, 0, imageDrawable.getIntrinsicWidth() + 10,
imageDrawable.getIntrinsicHeight() + 10);
if (callbackWeakReference != null) { if (callbackWeakReference != null) {
Callback cb = callbackWeakReference.get(); Callback cb = callbackWeakReference.get();
if (cb != null) cb.onSuccess(); if (cb != null) cb.onSuccess();