From feae466e2df21929597f6dbc2ae833fab14bd8aa Mon Sep 17 00:00:00 2001 From: Vince Mi Date: Sun, 23 Aug 2015 00:28:06 -0700 Subject: [PATCH] v2.2.0. Move corner constants to Corner class. --- README.md | 2 +- build.gradle | 8 ++-- example/build.gradle | 6 +-- roundedimageview/build.gradle | 6 +-- .../makeramen/roundedimageview/Corner.java | 11 +++-- .../roundedimageview/RoundedDrawable.java | 29 ++++++------- .../roundedimageview/RoundedImageView.java | 42 +++++++++---------- .../RoundedTransformationBuilder.java | 13 ++---- 8 files changed, 56 insertions(+), 61 deletions(-) diff --git a/README.md b/README.md index b881744..3fb8c2e 100644 --- a/README.md +++ b/README.md @@ -41,7 +41,7 @@ repositories { } dependencies { - compile 'com.makeramen:roundedimageview:2.1.2' + compile 'com.makeramen:roundedimageview:2.1.3' } ``` diff --git a/build.gradle b/build.gradle index d2d14f4..7f90075 100644 --- a/build.gradle +++ b/build.gradle @@ -4,19 +4,19 @@ buildscript { } dependencies { - classpath 'com.android.tools.build:gradle:1.2.3' + classpath 'com.android.tools.build:gradle:1.3.0' } } allprojects { group 'com.makeramen' - version '2.1.2' + version '2.2.0' repositories { mavenCentral() } } ext { - compileSdkVersion = 22 - buildToolsVersion = "22.0.1" + compileSdkVersion = 23 + buildToolsVersion = "23.0.0" } \ No newline at end of file diff --git a/example/build.gradle b/example/build.gradle index 00bd407..663000e 100644 --- a/example/build.gradle +++ b/example/build.gradle @@ -12,8 +12,8 @@ dependencies { //compile 'com.makeramen:roundedimageview:2.0.0-SNAPSHOT' compile project(':roundedimageview') compile 'com.squareup.picasso:picasso:2.5.2' - compile 'com.android.support:support-v4:22.2.0' - compile 'com.android.support:appcompat-v7:22.2.0' + compile 'com.android.support:support-v4:23.0.0' + compile 'com.android.support:appcompat-v7:23.0.0' } android { @@ -23,7 +23,7 @@ android { defaultConfig { applicationId "com.makeramen.roundedimageview.example" minSdkVersion 14 - targetSdkVersion 22 + targetSdkVersion 23 versionCode 1 versionName version } diff --git a/roundedimageview/build.gradle b/roundedimageview/build.gradle index f45992f..e7322ff 100644 --- a/roundedimageview/build.gradle +++ b/roundedimageview/build.gradle @@ -11,7 +11,7 @@ android { defaultConfig { minSdkVersion 8 - targetSdkVersion 22 + targetSdkVersion 23 versionCode 1 versionName version } @@ -23,8 +23,8 @@ android { } dependencies { - provided 'com.squareup.picasso:picasso:2.5.0' - provided 'com.android.support:support-annotations:22.2.1' + provided 'com.squareup.picasso:picasso:2.5.2' + provided 'com.android.support:support-annotations:23.0.0' } task androidJavadocs(type: Javadoc) { diff --git a/roundedimageview/src/main/java/com/makeramen/roundedimageview/Corner.java b/roundedimageview/src/main/java/com/makeramen/roundedimageview/Corner.java index f019890..b68d562 100644 --- a/roundedimageview/src/main/java/com/makeramen/roundedimageview/Corner.java +++ b/roundedimageview/src/main/java/com/makeramen/roundedimageview/Corner.java @@ -6,7 +6,12 @@ @Retention(RetentionPolicy.SOURCE) @IntDef({ - RoundedDrawable.CORNER_TOP_LEFT, RoundedDrawable.CORNER_TOP_RIGHT, - RoundedDrawable.CORNER_BOTTOM_LEFT, RoundedDrawable.CORNER_BOTTOM_RIGHT + Corner.TOP_LEFT, Corner.TOP_RIGHT, + Corner.BOTTOM_LEFT, Corner.BOTTOM_RIGHT }) -public @interface Corner {} +public @interface Corner { + int TOP_LEFT = 0; + int TOP_RIGHT = 1; + int BOTTOM_RIGHT = 2; + int BOTTOM_LEFT = 3; +} diff --git a/roundedimageview/src/main/java/com/makeramen/roundedimageview/RoundedDrawable.java b/roundedimageview/src/main/java/com/makeramen/roundedimageview/RoundedDrawable.java index 6452e6a..8f31d19 100644 --- a/roundedimageview/src/main/java/com/makeramen/roundedimageview/RoundedDrawable.java +++ b/roundedimageview/src/main/java/com/makeramen/roundedimageview/RoundedDrawable.java @@ -45,11 +45,6 @@ public class RoundedDrawable extends Drawable { public static final String TAG = "RoundedDrawable"; public static final int DEFAULT_BORDER_COLOR = Color.BLACK; - public static final int CORNER_TOP_LEFT = 0; - public static final int CORNER_TOP_RIGHT = 1; - public static final int CORNER_BOTTOM_RIGHT = 2; - public static final int CORNER_BOTTOM_LEFT = 3; - private final RectF mBounds = new RectF(); private final RectF mDrawableRect = new RectF(); private final RectF mBitmapRect = new RectF(); @@ -327,22 +322,22 @@ private void redrawBitmapForSquareCorners(Canvas canvas) { float bottom = top + mDrawableRect.height(); float radius = mCornerRadius; - if (!mCornersRounded[CORNER_TOP_LEFT]) { + if (!mCornersRounded[Corner.TOP_LEFT]) { mSquareCornersRect.set(left, top, left + radius, top + radius); canvas.drawRect(mSquareCornersRect, mBitmapPaint); } - if (!mCornersRounded[CORNER_TOP_RIGHT]) { + if (!mCornersRounded[Corner.TOP_RIGHT]) { mSquareCornersRect.set(right - radius, top, right, radius); canvas.drawRect(mSquareCornersRect, mBitmapPaint); } - if (!mCornersRounded[CORNER_BOTTOM_RIGHT]) { + if (!mCornersRounded[Corner.BOTTOM_RIGHT]) { mSquareCornersRect.set(right - radius, bottom - radius, right, bottom); canvas.drawRect(mSquareCornersRect, mBitmapPaint); } - if (!mCornersRounded[CORNER_BOTTOM_LEFT]) { + if (!mCornersRounded[Corner.BOTTOM_LEFT]) { mSquareCornersRect.set(left, bottom - radius, left + radius, bottom); canvas.drawRect(mSquareCornersRect, mBitmapPaint); } @@ -365,22 +360,22 @@ private void redrawBorderForSquareCorners(Canvas canvas) { float radius = mCornerRadius; float offset = mBorderWidth / 2; - if (!mCornersRounded[CORNER_TOP_LEFT]) { + if (!mCornersRounded[Corner.TOP_LEFT]) { canvas.drawLine(left - offset, top, left + radius, top, mBorderPaint); canvas.drawLine(left, top - offset, left, top + radius, mBorderPaint); } - if (!mCornersRounded[CORNER_TOP_RIGHT]) { + if (!mCornersRounded[Corner.TOP_RIGHT]) { canvas.drawLine(right - radius - offset, top, right, top, mBorderPaint); canvas.drawLine(right, top - offset, right, top + radius, mBorderPaint); } - if (!mCornersRounded[CORNER_BOTTOM_RIGHT]) { + if (!mCornersRounded[Corner.BOTTOM_RIGHT]) { canvas.drawLine(right - radius - offset, bottom, right + offset, bottom, mBorderPaint); canvas.drawLine(right, bottom - radius, right, bottom, mBorderPaint); } - if (!mCornersRounded[CORNER_BOTTOM_LEFT]) { + if (!mCornersRounded[Corner.BOTTOM_LEFT]) { canvas.drawLine(left - offset, bottom, left + radius, bottom, mBorderPaint); canvas.drawLine(left, bottom - radius, left, bottom, mBorderPaint); } @@ -521,10 +516,10 @@ public RoundedDrawable setCornerRadius(float topLeft, float topRight, float bott mCornerRadius = 0f; } - mCornersRounded[CORNER_TOP_LEFT] = topLeft > 0; - mCornersRounded[CORNER_TOP_RIGHT] = topRight > 0; - mCornersRounded[CORNER_BOTTOM_RIGHT] = bottomRight > 0; - mCornersRounded[CORNER_BOTTOM_LEFT] = bottomLeft > 0; + mCornersRounded[Corner.TOP_LEFT] = topLeft > 0; + mCornersRounded[Corner.TOP_RIGHT] = topRight > 0; + mCornersRounded[Corner.BOTTOM_RIGHT] = bottomRight > 0; + mCornersRounded[Corner.BOTTOM_LEFT] = bottomLeft > 0; return this; } diff --git a/roundedimageview/src/main/java/com/makeramen/roundedimageview/RoundedImageView.java b/roundedimageview/src/main/java/com/makeramen/roundedimageview/RoundedImageView.java index 1ee8754..dd297e2 100644 --- a/roundedimageview/src/main/java/com/makeramen/roundedimageview/RoundedImageView.java +++ b/roundedimageview/src/main/java/com/makeramen/roundedimageview/RoundedImageView.java @@ -33,12 +33,6 @@ import android.util.Log; import android.widget.ImageView; -import static com.makeramen.roundedimageview.RoundedDrawable.CORNER_BOTTOM_LEFT; -import static com.makeramen.roundedimageview.RoundedDrawable.CORNER_BOTTOM_RIGHT; -import static com.makeramen.roundedimageview.RoundedDrawable.CORNER_TOP_LEFT; -import static com.makeramen.roundedimageview.RoundedDrawable.CORNER_TOP_RIGHT; - - @SuppressWarnings("UnusedDeclaration") public class RoundedImageView extends ImageView { @@ -105,10 +99,14 @@ public RoundedImageView(Context context, AttributeSet attrs, int defStyle) { float cornerRadiusOverride = a.getDimensionPixelSize(R.styleable.RoundedImageView_riv_corner_radius, -1); - mCornerRadii[CORNER_TOP_LEFT] = a.getDimensionPixelSize(R.styleable.RoundedImageView_riv_corner_radius_top_left, -1); - mCornerRadii[CORNER_TOP_RIGHT] = a.getDimensionPixelSize(R.styleable.RoundedImageView_riv_corner_radius_top_right, -1); - mCornerRadii[CORNER_BOTTOM_RIGHT] = a.getDimensionPixelSize(R.styleable.RoundedImageView_riv_corner_radius_bottom_right, -1); - mCornerRadii[CORNER_BOTTOM_LEFT] = a.getDimensionPixelSize(R.styleable.RoundedImageView_riv_corner_radius_bottom_left, -1); + mCornerRadii[Corner.TOP_LEFT] = + a.getDimensionPixelSize(R.styleable.RoundedImageView_riv_corner_radius_top_left, -1); + mCornerRadii[Corner.TOP_RIGHT] = + a.getDimensionPixelSize(R.styleable.RoundedImageView_riv_corner_radius_top_right, -1); + mCornerRadii[Corner.BOTTOM_RIGHT] = + a.getDimensionPixelSize(R.styleable.RoundedImageView_riv_corner_radius_bottom_right, -1); + mCornerRadii[Corner.BOTTOM_LEFT] = + a.getDimensionPixelSize(R.styleable.RoundedImageView_riv_corner_radius_bottom_left, -1); boolean any = false; for (int i = 0, len = mCornerRadii.length; i < len; i++) { @@ -322,9 +320,11 @@ private void updateAttrs(Drawable drawable) { .setTileModeY(mTileModeY); if (mCornerRadii != null) { - ((RoundedDrawable) drawable).setCornerRadius(mCornerRadii[CORNER_TOP_LEFT], - mCornerRadii[CORNER_TOP_RIGHT], mCornerRadii[CORNER_BOTTOM_RIGHT], - mCornerRadii[CORNER_BOTTOM_LEFT]); + ((RoundedDrawable) drawable).setCornerRadius( + mCornerRadii[Corner.TOP_LEFT], + mCornerRadii[Corner.TOP_RIGHT], + mCornerRadii[Corner.BOTTOM_RIGHT], + mCornerRadii[Corner.BOTTOM_LEFT]); } applyColorMod(); @@ -429,17 +429,17 @@ public void setCornerRadius(@Corner int corner, float radius) { * @param bottomLeft radius of the bottom left corner in px. */ public void setCornerRadius(float topLeft, float topRight, float bottomLeft, float bottomRight) { - if (mCornerRadii[CORNER_TOP_LEFT] == topLeft - && mCornerRadii[CORNER_TOP_RIGHT] == topRight - && mCornerRadii[CORNER_BOTTOM_RIGHT] == bottomRight - && mCornerRadii[CORNER_BOTTOM_LEFT] == bottomLeft) { + if (mCornerRadii[Corner.TOP_LEFT] == topLeft + && mCornerRadii[Corner.TOP_RIGHT] == topRight + && mCornerRadii[Corner.BOTTOM_RIGHT] == bottomRight + && mCornerRadii[Corner.BOTTOM_LEFT] == bottomLeft) { return; } - mCornerRadii[CORNER_TOP_LEFT] = topLeft; - mCornerRadii[CORNER_TOP_RIGHT] = topRight; - mCornerRadii[CORNER_BOTTOM_LEFT] = bottomLeft; - mCornerRadii[CORNER_BOTTOM_RIGHT] = bottomRight; + mCornerRadii[Corner.TOP_LEFT] = topLeft; + mCornerRadii[Corner.TOP_RIGHT] = topRight; + mCornerRadii[Corner.BOTTOM_LEFT] = bottomLeft; + mCornerRadii[Corner.BOTTOM_RIGHT] = bottomRight; updateDrawableAttrs(); updateBackgroundDrawableAttrs(false); diff --git a/roundedimageview/src/main/java/com/makeramen/roundedimageview/RoundedTransformationBuilder.java b/roundedimageview/src/main/java/com/makeramen/roundedimageview/RoundedTransformationBuilder.java index f133b6f..50e94cb 100644 --- a/roundedimageview/src/main/java/com/makeramen/roundedimageview/RoundedTransformationBuilder.java +++ b/roundedimageview/src/main/java/com/makeramen/roundedimageview/RoundedTransformationBuilder.java @@ -25,11 +25,6 @@ import com.squareup.picasso.Transformation; import java.util.Arrays; -import static com.makeramen.roundedimageview.RoundedDrawable.CORNER_BOTTOM_LEFT; -import static com.makeramen.roundedimageview.RoundedDrawable.CORNER_BOTTOM_RIGHT; -import static com.makeramen.roundedimageview.RoundedDrawable.CORNER_TOP_LEFT; -import static com.makeramen.roundedimageview.RoundedDrawable.CORNER_TOP_RIGHT; - public final class RoundedTransformationBuilder { //private final Resources mResources; @@ -59,10 +54,10 @@ public RoundedTransformationBuilder scaleType(ImageView.ScaleType scaleType) { * @return the builder for chaining. */ public RoundedTransformationBuilder cornerRadius(float radius) { - mCornerRadii[CORNER_TOP_LEFT] = radius; - mCornerRadii[CORNER_TOP_RIGHT] = radius; - mCornerRadii[CORNER_BOTTOM_RIGHT] = radius; - mCornerRadii[CORNER_BOTTOM_LEFT] = radius; + mCornerRadii[Corner.TOP_LEFT] = radius; + mCornerRadii[Corner.TOP_RIGHT] = radius; + mCornerRadii[Corner.BOTTOM_RIGHT] = radius; + mCornerRadii[Corner.BOTTOM_LEFT] = radius; return this; }