Skip to content
This repository has been archived by the owner on Jan 27, 2023. It is now read-only.

Commit

Permalink
v2.2.0. Move corner constants to Corner class.
Browse files Browse the repository at this point in the history
  • Loading branch information
vinc3m1 committed Aug 23, 2015
1 parent d0a9bfd commit feae466
Show file tree
Hide file tree
Showing 8 changed files with 56 additions and 61 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ repositories {
}
dependencies {
compile 'com.makeramen:roundedimageview:2.1.2'
compile 'com.makeramen:roundedimageview:2.1.3'
}
```

Expand Down
8 changes: 4 additions & 4 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -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"
}
6 changes: 3 additions & 3 deletions example/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -23,7 +23,7 @@ android {
defaultConfig {
applicationId "com.makeramen.roundedimageview.example"
minSdkVersion 14
targetSdkVersion 22
targetSdkVersion 23
versionCode 1
versionName version
}
Expand Down
6 changes: 3 additions & 3 deletions roundedimageview/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ android {

defaultConfig {
minSdkVersion 8
targetSdkVersion 22
targetSdkVersion 23
versionCode 1
versionName version
}
Expand All @@ -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) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down Expand Up @@ -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);
}
Expand All @@ -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);
}
Expand Down Expand Up @@ -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;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 {

Expand Down Expand Up @@ -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++) {
Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
}

Expand Down

0 comments on commit feae466

Please sign in to comment.