Skip to content

Commit

Permalink
Version 0.1.3
Browse files Browse the repository at this point in the history
  • Loading branch information
Kislay committed Apr 19, 2017
1 parent bd911df commit a1f7b47
Show file tree
Hide file tree
Showing 5 changed files with 89 additions and 10 deletions.
4 changes: 2 additions & 2 deletions CircularImageProgressView/app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@ dependencies {
androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', {
exclude group: 'com.android.support', module: 'support-annotations'
})
compile 'com.android.support:appcompat-v7:25.3.0'
compile 'com.android.support:appcompat-v7:25.3.1'
testCompile 'junit:junit:4.12'
compile 'com.android.support:design:25.3.0'
compile 'com.android.support:design:25.3.1'
compile project(':circularimageprogressview')
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ android {
defaultConfig {
minSdkVersion 15
targetSdkVersion 25
versionCode 1
versionName "0.1.2"
versionCode 2
versionName "0.1.3"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"

}
Expand All @@ -30,7 +30,7 @@ dependencies {
androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', {
exclude group: 'com.android.support', module: 'support-annotations'
})
compile 'com.android.support:appcompat-v7:25.3.0'
compile 'com.android.support:appcompat-v7:25.3.1'
testCompile 'junit:junit:4.12'
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,11 @@ private void init(Context context, AttributeSet attrs) {
setProgress(mProgress);
}

/**
* Set the progress to the provided value
*
* @param progress The value for the new progress
*/
public void setProgress(final int progress) {
if (mProgressHidden || progress > mProgressMax || progress < PROGRESS_MIN)
return;
Expand All @@ -102,23 +107,44 @@ public void setProgress(final int progress) {
invalidate();
}

/**
* Remove the tint from the image
*/
public void clearImageTint() {
mImageFilter = null;
initImagePaint();
invalidate();
}

/**
* Will tint the Image at the centre
*
* @param color The colour of the tint
*/
public void setImageTint(int color) {
mImageFilter = new PorterDuffColorFilter(color, PorterDuff.Mode.SRC_ATOP);
initImagePaint();
invalidate();
}

/**
* Set the image at the centre
*
* @param resource Drawable ID of the image resource
*/
public void setImageResource(int resource) {
mImageResource = resource;
if (isValidImageResource(mContext, resource))
mBitmap = getBitmapFromVectorDrawable(mContext, mImageResource);
else {
mBitmap = null;
}
invalidate();
}

/**
* @return Current progress
*/
public int getProgress() {
return mCurrentProgress;
}
Expand All @@ -135,7 +161,7 @@ protected void onDraw(Canvas canvas) {

//draw image in the center
if (!mImageHidden)
if (isValidImageResource(mContext, mImageResource) && mBitmap != null)
if (mBitmap != null)
canvas.drawBitmap(mBitmap, null, mImgRect, mImagePaint);
}

Expand Down Expand Up @@ -183,6 +209,11 @@ protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
super.onMeasure(widthMeasureSpec, heightMeasureSpec);
}

/**
* Set the width of the circular progress arc
*
* @param width Must be between {@link #STROKE_WIDTH_MIN} and {@link #STROKE_WIDTH_MAX}
*/
public void setCircleWidth(int width) {
if (width < STROKE_WIDTH_MIN)
mStrokeWidth = STROKE_WIDTH_MIN;
Expand All @@ -194,14 +225,30 @@ else if (width > STROKE_WIDTH_MAX)
requestLayout();
}

/**
* @return The width of the progress circle.
* Possible value will be between {@link #STROKE_WIDTH_MIN} and {@link #STROKE_WIDTH_MAX}
*/
public int getCircleWidth() {
return mStrokeWidth;
}

/**
* @return Maximum progress, default is 100
*/
public int getMax() {
return mProgressMax;
}

/**
* Set the maximum possible value for the progress bar
*
* @param max The maximum progress
*/
public void setMax(int max) {
mProgressMax = max;
}


/**
* @param drawableId Resource ID of drawable, can also be a vector
Expand All @@ -228,32 +275,55 @@ private static Bitmap getBitmapFromVectorDrawable(Context context, int drawableI
return bitmap;
}

/**
* Hide the circular progress arc.
* This does not affect the visibility of other parts of the view
*/
public void hideProgress() {
mProgressHidden = true;
invalidate();
}

/**
* Make the circular progress arc visible.
* This does not affect the visibility of other parts of the view
*/
public void showProgress() {
mProgressHidden = false;
invalidate();
}

/**
* Hide the image, this does not affect the visibility of other parts of the view
*/
public void hideImage() {
mImageHidden = true;
invalidate();
}

/**
* Make the image visible, this does not affect the visibility of other parts of the view
*/
public void showImage() {
mImageHidden = false;
invalidate();
}

/**
* @param context Application context
* @return THe app's accent color, as defined in the app's theme
*/
private int getAccentColor(Context context) {
final TypedValue value = new TypedValue();
context.getTheme().resolveAttribute(R.attr.colorAccent, value, true);
return value.data;
}

/**
* @param context Application context
* @param resourceId Resource ID of the drawable
* @return Whether the provided resource is a valid drawable
*/
private boolean isValidImageResource(Context context, int resourceId) {
String resourceName = String.valueOf(resourceId);
return getResources().getIdentifier(resourceName, "drawable", context.getPackageName()) > 0;
Expand All @@ -273,6 +343,10 @@ private int dpToPixel(int dp) {
);
}

/**
* Initialise the paint for the circular progress bar,
* includes both the background arc and the progress arc.
*/
private void initArcPaint() {
mArcPaintBackground = new Paint() {
{
Expand All @@ -299,6 +373,9 @@ private void initArcPaint() {
};
}

/**
* Initialise the paint for the image
*/
private void initImagePaint() {
mImagePaint = new Paint() {
{
Expand Down
2 changes: 1 addition & 1 deletion CircularImageProgressView/gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ org.gradle.jvmargs=-Xmx1536m
# This option should only be used with decoupled projects. More details, visit
# http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects
# org.gradle.parallel=true
VERSION_NAME=0.1.2
VERSION_NAME=0.1.3
VERSION_CODE=1
GROUP=com.mobstac.circularimageprogress
RELEASE_SOURCE=true
Expand Down
8 changes: 5 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
## Add to your project

```groovy
compile 'com.mobstac.circularimageprogress:CircularImageProgressView:0.1.2'
compile 'com.mobstac.circularimageprogress:CircularImageProgressView:0.1.3'
```

[ ![Download](https://api.bintray.com/packages/mobstac/maven/CircularImageProgressView/images/download.svg) ](https://bintray.com/mobstac/maven/CircularImageProgressView/_latestVersion)
Expand All @@ -21,7 +21,7 @@ compile 'com.mobstac.circularimageprogress:CircularImageProgressView:0.1.2'
android:layout_width="160dp"
android:layout_height="160dp"
app:image="@drawable/my_icon"
app:max_progress="100" />
app:max="100" />
```

## Configurable properties
Expand Down Expand Up @@ -60,6 +60,8 @@ circularImageProgressView.setProgress(40);
circularImageProgressView.setImageTint(Color.WHITE);
//Set image resource
circularImageProgressView.setImageResource(R.drawable.ic_action_name);
//Set max progress
circularImageProgressView.setMax(50);
//Get current progress
circularImageProgressView.getProgress();
//Get max progress
Expand All @@ -77,4 +79,4 @@ circularImageProgressView.hideImage();
//Hide progress circle
circularImageProgressView.hideProgress();

```
```

0 comments on commit a1f7b47

Please sign in to comment.