diff --git a/holdingbutton/src/main/java/com/dewarder/holdinglibrary/VectorDrawableHelper.java b/holdingbutton/src/main/java/com/dewarder/holdinglibrary/DrawableHelper.java similarity index 62% rename from holdingbutton/src/main/java/com/dewarder/holdinglibrary/VectorDrawableHelper.java rename to holdingbutton/src/main/java/com/dewarder/holdinglibrary/DrawableHelper.java index dbeef26..41fd1b5 100644 --- a/holdingbutton/src/main/java/com/dewarder/holdinglibrary/VectorDrawableHelper.java +++ b/holdingbutton/src/main/java/com/dewarder/holdinglibrary/DrawableHelper.java @@ -5,19 +5,27 @@ import android.graphics.Canvas; import android.graphics.drawable.Drawable; import android.os.Build; +import android.support.annotation.DrawableRes; import android.support.v4.content.ContextCompat; import android.support.v4.graphics.drawable.DrawableCompat; -final class VectorDrawableHelper { +final class DrawableHelper { - static Bitmap getBitmap(Context context, int drawableId) { + static Bitmap getBitmap(Context context, @DrawableRes int drawableId) { Drawable drawable = ContextCompat.getDrawable(context, drawableId); + return getBitmap(drawable); + } + + static Bitmap getBitmap(Drawable drawable) { if (Build.VERSION.SDK_INT < Build.VERSION_CODES.LOLLIPOP) { drawable = (DrawableCompat.wrap(drawable)).mutate(); } - Bitmap bitmap = Bitmap.createBitmap(drawable.getIntrinsicWidth(), - drawable.getIntrinsicHeight(), Bitmap.Config.ARGB_8888); + Bitmap 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); diff --git a/holdingbutton/src/main/java/com/dewarder/holdinglibrary/HoldingButtonLayout.java b/holdingbutton/src/main/java/com/dewarder/holdinglibrary/HoldingButtonLayout.java index 6461531..b124a60 100644 --- a/holdingbutton/src/main/java/com/dewarder/holdinglibrary/HoldingButtonLayout.java +++ b/holdingbutton/src/main/java/com/dewarder/holdinglibrary/HoldingButtonLayout.java @@ -23,6 +23,7 @@ import android.graphics.Bitmap; import android.graphics.BitmapFactory; import android.graphics.Rect; +import android.graphics.drawable.Drawable; import android.os.Build; import android.support.annotation.AttrRes; import android.support.annotation.ColorInt; @@ -397,7 +398,11 @@ public void setSecondRadius(float radius) { } public void setIcon(@DrawableRes int drawableRes) { - setIcon(VectorDrawableHelper.getBitmap(getContext(), drawableRes)); + setIcon(DrawableHelper.getBitmap(getContext(), drawableRes)); + } + + public void setIcon(Drawable drawable) { + setIcon(DrawableHelper.getBitmap(drawable)); } public void setIcon(Bitmap bitmap) {