From a1f7b4727c770e3e693777e8fe72859bee81f31a Mon Sep 17 00:00:00 2001 From: Kislay Date: Wed, 19 Apr 2017 10:44:47 +0530 Subject: [PATCH] Version 0.1.3 --- CircularImageProgressView/app/build.gradle | 4 +- .../circularimageprogressview/build.gradle | 6 +- .../CircularImageProgressView.java | 79 ++++++++++++++++++- CircularImageProgressView/gradle.properties | 2 +- README.md | 8 +- 5 files changed, 89 insertions(+), 10 deletions(-) diff --git a/CircularImageProgressView/app/build.gradle b/CircularImageProgressView/app/build.gradle index 4051ef9..f4b3c4b 100644 --- a/CircularImageProgressView/app/build.gradle +++ b/CircularImageProgressView/app/build.gradle @@ -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') } diff --git a/CircularImageProgressView/circularimageprogressview/build.gradle b/CircularImageProgressView/circularimageprogressview/build.gradle index 0fc3398..4109ac3 100644 --- a/CircularImageProgressView/circularimageprogressview/build.gradle +++ b/CircularImageProgressView/circularimageprogressview/build.gradle @@ -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" } @@ -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' } diff --git a/CircularImageProgressView/circularimageprogressview/src/main/java/com/mobstac/circularimageprogress/CircularImageProgressView.java b/CircularImageProgressView/circularimageprogressview/src/main/java/com/mobstac/circularimageprogress/CircularImageProgressView.java index b5ca7b7..9a78611 100644 --- a/CircularImageProgressView/circularimageprogressview/src/main/java/com/mobstac/circularimageprogress/CircularImageProgressView.java +++ b/CircularImageProgressView/circularimageprogressview/src/main/java/com/mobstac/circularimageprogress/CircularImageProgressView.java @@ -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; @@ -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; } @@ -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); } @@ -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; @@ -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 @@ -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; @@ -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() { { @@ -299,6 +373,9 @@ private void initArcPaint() { }; } + /** + * Initialise the paint for the image + */ private void initImagePaint() { mImagePaint = new Paint() { { diff --git a/CircularImageProgressView/gradle.properties b/CircularImageProgressView/gradle.properties index a566740..de6020d 100644 --- a/CircularImageProgressView/gradle.properties +++ b/CircularImageProgressView/gradle.properties @@ -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 diff --git a/README.md b/README.md index 2159ffb..7189817 100644 --- a/README.md +++ b/README.md @@ -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) @@ -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 @@ -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 @@ -77,4 +79,4 @@ circularImageProgressView.hideImage(); //Hide progress circle circularImageProgressView.hideProgress(); -``` \ No newline at end of file +```