Skip to content

Commit feae466

Browse files
committed
v2.2.0. Move corner constants to Corner class.
1 parent d0a9bfd commit feae466

8 files changed

Lines changed: 56 additions & 61 deletions

File tree

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ repositories {
4141
}
4242
4343
dependencies {
44-
compile 'com.makeramen:roundedimageview:2.1.2'
44+
compile 'com.makeramen:roundedimageview:2.1.3'
4545
}
4646
```
4747

build.gradle

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,19 +4,19 @@ buildscript {
44
}
55

66
dependencies {
7-
classpath 'com.android.tools.build:gradle:1.2.3'
7+
classpath 'com.android.tools.build:gradle:1.3.0'
88
}
99
}
1010

1111
allprojects {
1212
group 'com.makeramen'
13-
version '2.1.2'
13+
version '2.2.0'
1414
repositories {
1515
mavenCentral()
1616
}
1717
}
1818

1919
ext {
20-
compileSdkVersion = 22
21-
buildToolsVersion = "22.0.1"
20+
compileSdkVersion = 23
21+
buildToolsVersion = "23.0.0"
2222
}

example/build.gradle

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,8 @@ dependencies {
1212
//compile 'com.makeramen:roundedimageview:2.0.0-SNAPSHOT'
1313
compile project(':roundedimageview')
1414
compile 'com.squareup.picasso:picasso:2.5.2'
15-
compile 'com.android.support:support-v4:22.2.0'
16-
compile 'com.android.support:appcompat-v7:22.2.0'
15+
compile 'com.android.support:support-v4:23.0.0'
16+
compile 'com.android.support:appcompat-v7:23.0.0'
1717
}
1818

1919
android {
@@ -23,7 +23,7 @@ android {
2323
defaultConfig {
2424
applicationId "com.makeramen.roundedimageview.example"
2525
minSdkVersion 14
26-
targetSdkVersion 22
26+
targetSdkVersion 23
2727
versionCode 1
2828
versionName version
2929
}

roundedimageview/build.gradle

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ android {
1111

1212
defaultConfig {
1313
minSdkVersion 8
14-
targetSdkVersion 22
14+
targetSdkVersion 23
1515
versionCode 1
1616
versionName version
1717
}
@@ -23,8 +23,8 @@ android {
2323
}
2424

2525
dependencies {
26-
provided 'com.squareup.picasso:picasso:2.5.0'
27-
provided 'com.android.support:support-annotations:22.2.1'
26+
provided 'com.squareup.picasso:picasso:2.5.2'
27+
provided 'com.android.support:support-annotations:23.0.0'
2828
}
2929

3030
task androidJavadocs(type: Javadoc) {

roundedimageview/src/main/java/com/makeramen/roundedimageview/Corner.java

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,12 @@
66

77
@Retention(RetentionPolicy.SOURCE)
88
@IntDef({
9-
RoundedDrawable.CORNER_TOP_LEFT, RoundedDrawable.CORNER_TOP_RIGHT,
10-
RoundedDrawable.CORNER_BOTTOM_LEFT, RoundedDrawable.CORNER_BOTTOM_RIGHT
9+
Corner.TOP_LEFT, Corner.TOP_RIGHT,
10+
Corner.BOTTOM_LEFT, Corner.BOTTOM_RIGHT
1111
})
12-
public @interface Corner {}
12+
public @interface Corner {
13+
int TOP_LEFT = 0;
14+
int TOP_RIGHT = 1;
15+
int BOTTOM_RIGHT = 2;
16+
int BOTTOM_LEFT = 3;
17+
}

roundedimageview/src/main/java/com/makeramen/roundedimageview/RoundedDrawable.java

Lines changed: 12 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -45,11 +45,6 @@ public class RoundedDrawable extends Drawable {
4545
public static final String TAG = "RoundedDrawable";
4646
public static final int DEFAULT_BORDER_COLOR = Color.BLACK;
4747

48-
public static final int CORNER_TOP_LEFT = 0;
49-
public static final int CORNER_TOP_RIGHT = 1;
50-
public static final int CORNER_BOTTOM_RIGHT = 2;
51-
public static final int CORNER_BOTTOM_LEFT = 3;
52-
5348
private final RectF mBounds = new RectF();
5449
private final RectF mDrawableRect = new RectF();
5550
private final RectF mBitmapRect = new RectF();
@@ -327,22 +322,22 @@ private void redrawBitmapForSquareCorners(Canvas canvas) {
327322
float bottom = top + mDrawableRect.height();
328323
float radius = mCornerRadius;
329324

330-
if (!mCornersRounded[CORNER_TOP_LEFT]) {
325+
if (!mCornersRounded[Corner.TOP_LEFT]) {
331326
mSquareCornersRect.set(left, top, left + radius, top + radius);
332327
canvas.drawRect(mSquareCornersRect, mBitmapPaint);
333328
}
334329

335-
if (!mCornersRounded[CORNER_TOP_RIGHT]) {
330+
if (!mCornersRounded[Corner.TOP_RIGHT]) {
336331
mSquareCornersRect.set(right - radius, top, right, radius);
337332
canvas.drawRect(mSquareCornersRect, mBitmapPaint);
338333
}
339334

340-
if (!mCornersRounded[CORNER_BOTTOM_RIGHT]) {
335+
if (!mCornersRounded[Corner.BOTTOM_RIGHT]) {
341336
mSquareCornersRect.set(right - radius, bottom - radius, right, bottom);
342337
canvas.drawRect(mSquareCornersRect, mBitmapPaint);
343338
}
344339

345-
if (!mCornersRounded[CORNER_BOTTOM_LEFT]) {
340+
if (!mCornersRounded[Corner.BOTTOM_LEFT]) {
346341
mSquareCornersRect.set(left, bottom - radius, left + radius, bottom);
347342
canvas.drawRect(mSquareCornersRect, mBitmapPaint);
348343
}
@@ -365,22 +360,22 @@ private void redrawBorderForSquareCorners(Canvas canvas) {
365360
float radius = mCornerRadius;
366361
float offset = mBorderWidth / 2;
367362

368-
if (!mCornersRounded[CORNER_TOP_LEFT]) {
363+
if (!mCornersRounded[Corner.TOP_LEFT]) {
369364
canvas.drawLine(left - offset, top, left + radius, top, mBorderPaint);
370365
canvas.drawLine(left, top - offset, left, top + radius, mBorderPaint);
371366
}
372367

373-
if (!mCornersRounded[CORNER_TOP_RIGHT]) {
368+
if (!mCornersRounded[Corner.TOP_RIGHT]) {
374369
canvas.drawLine(right - radius - offset, top, right, top, mBorderPaint);
375370
canvas.drawLine(right, top - offset, right, top + radius, mBorderPaint);
376371
}
377372

378-
if (!mCornersRounded[CORNER_BOTTOM_RIGHT]) {
373+
if (!mCornersRounded[Corner.BOTTOM_RIGHT]) {
379374
canvas.drawLine(right - radius - offset, bottom, right + offset, bottom, mBorderPaint);
380375
canvas.drawLine(right, bottom - radius, right, bottom, mBorderPaint);
381376
}
382377

383-
if (!mCornersRounded[CORNER_BOTTOM_LEFT]) {
378+
if (!mCornersRounded[Corner.BOTTOM_LEFT]) {
384379
canvas.drawLine(left - offset, bottom, left + radius, bottom, mBorderPaint);
385380
canvas.drawLine(left, bottom - radius, left, bottom, mBorderPaint);
386381
}
@@ -521,10 +516,10 @@ public RoundedDrawable setCornerRadius(float topLeft, float topRight, float bott
521516
mCornerRadius = 0f;
522517
}
523518

524-
mCornersRounded[CORNER_TOP_LEFT] = topLeft > 0;
525-
mCornersRounded[CORNER_TOP_RIGHT] = topRight > 0;
526-
mCornersRounded[CORNER_BOTTOM_RIGHT] = bottomRight > 0;
527-
mCornersRounded[CORNER_BOTTOM_LEFT] = bottomLeft > 0;
519+
mCornersRounded[Corner.TOP_LEFT] = topLeft > 0;
520+
mCornersRounded[Corner.TOP_RIGHT] = topRight > 0;
521+
mCornersRounded[Corner.BOTTOM_RIGHT] = bottomRight > 0;
522+
mCornersRounded[Corner.BOTTOM_LEFT] = bottomLeft > 0;
528523
return this;
529524
}
530525

roundedimageview/src/main/java/com/makeramen/roundedimageview/RoundedImageView.java

Lines changed: 21 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -33,12 +33,6 @@
3333
import android.util.Log;
3434
import android.widget.ImageView;
3535

36-
import static com.makeramen.roundedimageview.RoundedDrawable.CORNER_BOTTOM_LEFT;
37-
import static com.makeramen.roundedimageview.RoundedDrawable.CORNER_BOTTOM_RIGHT;
38-
import static com.makeramen.roundedimageview.RoundedDrawable.CORNER_TOP_LEFT;
39-
import static com.makeramen.roundedimageview.RoundedDrawable.CORNER_TOP_RIGHT;
40-
41-
4236
@SuppressWarnings("UnusedDeclaration")
4337
public class RoundedImageView extends ImageView {
4438

@@ -105,10 +99,14 @@ public RoundedImageView(Context context, AttributeSet attrs, int defStyle) {
10599
float cornerRadiusOverride =
106100
a.getDimensionPixelSize(R.styleable.RoundedImageView_riv_corner_radius, -1);
107101

108-
mCornerRadii[CORNER_TOP_LEFT] = a.getDimensionPixelSize(R.styleable.RoundedImageView_riv_corner_radius_top_left, -1);
109-
mCornerRadii[CORNER_TOP_RIGHT] = a.getDimensionPixelSize(R.styleable.RoundedImageView_riv_corner_radius_top_right, -1);
110-
mCornerRadii[CORNER_BOTTOM_RIGHT] = a.getDimensionPixelSize(R.styleable.RoundedImageView_riv_corner_radius_bottom_right, -1);
111-
mCornerRadii[CORNER_BOTTOM_LEFT] = a.getDimensionPixelSize(R.styleable.RoundedImageView_riv_corner_radius_bottom_left, -1);
102+
mCornerRadii[Corner.TOP_LEFT] =
103+
a.getDimensionPixelSize(R.styleable.RoundedImageView_riv_corner_radius_top_left, -1);
104+
mCornerRadii[Corner.TOP_RIGHT] =
105+
a.getDimensionPixelSize(R.styleable.RoundedImageView_riv_corner_radius_top_right, -1);
106+
mCornerRadii[Corner.BOTTOM_RIGHT] =
107+
a.getDimensionPixelSize(R.styleable.RoundedImageView_riv_corner_radius_bottom_right, -1);
108+
mCornerRadii[Corner.BOTTOM_LEFT] =
109+
a.getDimensionPixelSize(R.styleable.RoundedImageView_riv_corner_radius_bottom_left, -1);
112110

113111
boolean any = false;
114112
for (int i = 0, len = mCornerRadii.length; i < len; i++) {
@@ -322,9 +320,11 @@ private void updateAttrs(Drawable drawable) {
322320
.setTileModeY(mTileModeY);
323321

324322
if (mCornerRadii != null) {
325-
((RoundedDrawable) drawable).setCornerRadius(mCornerRadii[CORNER_TOP_LEFT],
326-
mCornerRadii[CORNER_TOP_RIGHT], mCornerRadii[CORNER_BOTTOM_RIGHT],
327-
mCornerRadii[CORNER_BOTTOM_LEFT]);
323+
((RoundedDrawable) drawable).setCornerRadius(
324+
mCornerRadii[Corner.TOP_LEFT],
325+
mCornerRadii[Corner.TOP_RIGHT],
326+
mCornerRadii[Corner.BOTTOM_RIGHT],
327+
mCornerRadii[Corner.BOTTOM_LEFT]);
328328
}
329329

330330
applyColorMod();
@@ -429,17 +429,17 @@ public void setCornerRadius(@Corner int corner, float radius) {
429429
* @param bottomLeft radius of the bottom left corner in px.
430430
*/
431431
public void setCornerRadius(float topLeft, float topRight, float bottomLeft, float bottomRight) {
432-
if (mCornerRadii[CORNER_TOP_LEFT] == topLeft
433-
&& mCornerRadii[CORNER_TOP_RIGHT] == topRight
434-
&& mCornerRadii[CORNER_BOTTOM_RIGHT] == bottomRight
435-
&& mCornerRadii[CORNER_BOTTOM_LEFT] == bottomLeft) {
432+
if (mCornerRadii[Corner.TOP_LEFT] == topLeft
433+
&& mCornerRadii[Corner.TOP_RIGHT] == topRight
434+
&& mCornerRadii[Corner.BOTTOM_RIGHT] == bottomRight
435+
&& mCornerRadii[Corner.BOTTOM_LEFT] == bottomLeft) {
436436
return;
437437
}
438438

439-
mCornerRadii[CORNER_TOP_LEFT] = topLeft;
440-
mCornerRadii[CORNER_TOP_RIGHT] = topRight;
441-
mCornerRadii[CORNER_BOTTOM_LEFT] = bottomLeft;
442-
mCornerRadii[CORNER_BOTTOM_RIGHT] = bottomRight;
439+
mCornerRadii[Corner.TOP_LEFT] = topLeft;
440+
mCornerRadii[Corner.TOP_RIGHT] = topRight;
441+
mCornerRadii[Corner.BOTTOM_LEFT] = bottomLeft;
442+
mCornerRadii[Corner.BOTTOM_RIGHT] = bottomRight;
443443

444444
updateDrawableAttrs();
445445
updateBackgroundDrawableAttrs(false);

roundedimageview/src/main/java/com/makeramen/roundedimageview/RoundedTransformationBuilder.java

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -25,11 +25,6 @@
2525
import com.squareup.picasso.Transformation;
2626
import java.util.Arrays;
2727

28-
import static com.makeramen.roundedimageview.RoundedDrawable.CORNER_BOTTOM_LEFT;
29-
import static com.makeramen.roundedimageview.RoundedDrawable.CORNER_BOTTOM_RIGHT;
30-
import static com.makeramen.roundedimageview.RoundedDrawable.CORNER_TOP_LEFT;
31-
import static com.makeramen.roundedimageview.RoundedDrawable.CORNER_TOP_RIGHT;
32-
3328
public final class RoundedTransformationBuilder {
3429

3530
//private final Resources mResources;
@@ -59,10 +54,10 @@ public RoundedTransformationBuilder scaleType(ImageView.ScaleType scaleType) {
5954
* @return the builder for chaining.
6055
*/
6156
public RoundedTransformationBuilder cornerRadius(float radius) {
62-
mCornerRadii[CORNER_TOP_LEFT] = radius;
63-
mCornerRadii[CORNER_TOP_RIGHT] = radius;
64-
mCornerRadii[CORNER_BOTTOM_RIGHT] = radius;
65-
mCornerRadii[CORNER_BOTTOM_LEFT] = radius;
57+
mCornerRadii[Corner.TOP_LEFT] = radius;
58+
mCornerRadii[Corner.TOP_RIGHT] = radius;
59+
mCornerRadii[Corner.BOTTOM_RIGHT] = radius;
60+
mCornerRadii[Corner.BOTTOM_LEFT] = radius;
6661
return this;
6762
}
6863

0 commit comments

Comments
 (0)