Skip to content

Commit

Permalink
fix missing conversion
Browse files Browse the repository at this point in the history
  • Loading branch information
tobiasKaminsky committed Dec 21, 2017
1 parent 3ba3f9b commit 213ce41
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -906,7 +906,7 @@ public static class AsyncAvatarDrawable extends BitmapDrawable {
private final WeakReference<AvatarGenerationTask> avatarWorkerTaskReference;

public AsyncAvatarDrawable(Resources res, Drawable bitmap, AvatarGenerationTask avatarWorkerTask) {
super(res, bitmap);
super(res, BitmapUtils.drawableToBitmap(bitmap));
avatarWorkerTaskReference = new WeakReference<>(avatarWorkerTask);
}

Expand Down
26 changes: 26 additions & 0 deletions src/main/java/com/owncloud/android/utils/BitmapUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,10 @@
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.BitmapFactory.Options;
import android.graphics.Canvas;
import android.graphics.Matrix;
import android.graphics.drawable.BitmapDrawable;
import android.graphics.drawable.Drawable;
import android.support.media.ExifInterface;
import android.support.v4.graphics.drawable.RoundedBitmapDrawable;
import android.support.v4.graphics.drawable.RoundedBitmapDrawableFactory;
Expand Down Expand Up @@ -375,4 +378,27 @@ public static RoundedBitmapDrawable bitmapToCircularBitmapDrawable(Resources res
roundedBitmap.setCircular(true);
return roundedBitmap;
}

public static Bitmap drawableToBitmap(Drawable drawable) {
Bitmap bitmap;

if (drawable instanceof BitmapDrawable) {
BitmapDrawable bitmapDrawable = (BitmapDrawable) drawable;
if (bitmapDrawable.getBitmap() != null) {
return bitmapDrawable.getBitmap();
}
}

if (drawable.getIntrinsicWidth() <= 0 || drawable.getIntrinsicHeight() <= 0) {
bitmap = Bitmap.createBitmap(1, 1, Bitmap.Config.ARGB_8888);
} else {
bitmap = Bitmap.createBitmap(drawable.getIntrinsicWidth(), drawable.getIntrinsicHeight(),
Bitmap.Config.ARGB_8888);
}

Canvas canvas = new Canvas(bitmap);
drawable.setBounds(0, 0, canvas.getWidth(), canvas.getHeight());
drawable.draw(canvas);
return bitmap;
}
}
1 change: 1 addition & 0 deletions src/main/java/com/owncloud/android/utils/DisplayUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
import android.content.Context;
import android.content.Intent;
import android.content.res.Resources;
import android.graphics.Bitmap;
import android.graphics.Color;
import android.graphics.Point;
import android.graphics.drawable.Drawable;
Expand Down

0 comments on commit 213ce41

Please sign in to comment.