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

Commit

Permalink
Use @ColorInt isntead of @ColorRes fixes #114, add @corner.
Browse files Browse the repository at this point in the history
  • Loading branch information
vinc3m1 committed Jul 28, 2015
1 parent 8ebf6f4 commit ff6d079
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 9 deletions.
2 changes: 1 addition & 1 deletion roundedimageview/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ android {

dependencies {
provided 'com.squareup.picasso:picasso:2.5.0'
provided 'com.android.support:support-annotations:22.1.0'
provided 'com.android.support:support-annotations:22.2.1'
}

task androidJavadocs(type: Javadoc) {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package com.makeramen.roundedimageview;

import android.support.annotation.IntDef;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;

@Retention(RetentionPolicy.SOURCE)
@IntDef({
RoundedDrawable.CORNER_TOP_LEFT, RoundedDrawable.CORNER_TOP_RIGHT,
RoundedDrawable.CORNER_BOTTOM_LEFT, RoundedDrawable.CORNER_BOTTOM_RIGHT
})
public @interface Corner {}
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
import android.graphics.drawable.BitmapDrawable;
import android.graphics.drawable.Drawable;
import android.graphics.drawable.LayerDrawable;
import android.support.annotation.ColorInt;
import android.support.annotation.NonNull;
import android.util.Log;
import android.widget.ImageView.ScaleType;
Expand Down Expand Up @@ -443,7 +444,7 @@ public float getCornerRadius() {
* @param corner the specific corner to get radius of.
* @return the corner radius of the specified corner.
*/
public float getCornerRadius(int corner) {
public float getCornerRadius(@Corner int corner) {
return mCornersRounded[corner] ? mCornerRadius : 0f;
}

Expand All @@ -465,7 +466,7 @@ public RoundedDrawable setCornerRadius(float radius) {
* @param radius the radius.
* @return the {@link RoundedDrawable} for chaining.
*/
public RoundedDrawable setCornerRadius(int corner, float radius) {
public RoundedDrawable setCornerRadius(@Corner int corner, float radius) {
if (radius != 0 && mCornerRadius != 0 && mCornerRadius != radius) {
throw new IllegalArgumentException("Multiple nonzero corner radii not yet supported.");
}
Expand Down Expand Up @@ -539,7 +540,7 @@ public int getBorderColor() {
return mBorderColor.getDefaultColor();
}

public RoundedDrawable setBorderColor(int color) {
public RoundedDrawable setBorderColor(@ColorInt int color) {
return setBorderColor(ColorStateList.valueOf(color));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
import android.graphics.drawable.Drawable;
import android.graphics.drawable.LayerDrawable;
import android.net.Uri;
import android.support.annotation.ColorRes;
import android.support.annotation.ColorInt;
import android.support.annotation.DimenRes;
import android.support.annotation.DrawableRes;
import android.util.AttributeSet;
Expand Down Expand Up @@ -369,7 +369,7 @@ public float getMaxCornerRadius() {
* @param corner the corner.
* @return the radius.
*/
public float getCornerRadius(int corner) {
public float getCornerRadius(@Corner int corner) {
return mCornerRadii[corner];
}

Expand All @@ -389,7 +389,7 @@ public void setCornerRadiusDimen(@DimenRes int resId) {
* @param corner the corner to set.
* @param resId the dimension resource id of the corner radius.
*/
public void setCornerRadiusDimen(int corner, @DimenRes int resId) {
public void setCornerRadiusDimen(@Corner int corner, @DimenRes int resId) {
setCornerRadius(corner, getResources().getDimensionPixelSize(resId));
}

Expand All @@ -408,7 +408,7 @@ public void setCornerRadius(float radius) {
* @param corner the corner to set.
* @param radius the corner radius to set in px.
*/
public void setCornerRadius(int corner, float radius) {
public void setCornerRadius(@Corner int corner, float radius) {
if (mCornerRadii[corner] == radius) {
return;
}
Expand Down Expand Up @@ -463,11 +463,12 @@ public void setBorderWidth(float width) {
invalidate();
}

@ColorInt
public int getBorderColor() {
return mBorderColor.getDefaultColor();
}

public void setBorderColor(@ColorRes int color) {
public void setBorderColor(@ColorInt int color) {
setBorderColor(ColorStateList.valueOf(color));
}

Expand Down

0 comments on commit ff6d079

Please sign in to comment.