From ccc2616857a7711db689e3cfde5ccbc903a38e50 Mon Sep 17 00:00:00 2001 From: Yuriy Budiyev Date: Fri, 18 Feb 2022 20:51:39 +0300 Subject: [PATCH] Dev --- README.md | 30 +++- build.gradle | 129 ++++++------------ gradle/wrapper/gradle-wrapper.properties | 2 +- .../CircularProgressBar.java | 114 ++++++++++------ 4 files changed, 134 insertions(+), 141 deletions(-) diff --git a/README.md b/README.md index 3f8c45c..f24dc9d 100644 --- a/README.md +++ b/README.md @@ -1,18 +1,39 @@ # Circular Progress Bar -[ ![Download](https://api.bintray.com/packages/yuriy-budiyev/maven/circular-progress-bar/images/download.svg) ](https://bintray.com/yuriy-budiyev/maven/circular-progress-bar/_latestVersion) [![Android Arsenal](https://img.shields.io/badge/Android%20Arsenal-Circular%20Progress%20Bar-blue.svg?style=flat)](https://android-arsenal.com/details/1/6515) [![API](https://img.shields.io/badge/API-14%2B-blue.svg?style=flat)](https://android-arsenal.com/api?level=14) -[![Codacy Badge](https://api.codacy.com/project/badge/Grade/04aff697e57642bb96579fbaa6cc3dad)](https://www.codacy.com/app/yuriy-budiyev/circular-progress-bar?utm_source=github.com&utm_medium=referral&utm_content=yuriy-budiyev/circular-progress-bar&utm_campaign=Badge_Grade) Circular progress bar, supports animations and indeterminate mode, highly customizable, Kotlin-friendly ### Usage ([sample](https://github.com/yuriy-budiyev/lib-demo-app)) -Add dependency: + +Step 1. Add it in your root build.gradle at the end of repositories: +```gradle +allprojects { + repositories { + ... + maven { url 'https://jitpack.io' } + } +} +``` + +or in settings.gradle file: +```gradle +dependencyResolutionManagement { + ... + repositories { + ... + maven { url 'https://jitpack.io' } + } +} +``` + +Step 2. Add dependency: ```gradle dependencies { - implementation 'com.budiyev.android:circular-progress-bar:1.2.2' + implementation 'com.github.yuriy-budiyev:circular-progress-bar:1.2.3' } ``` + Define a view in your layout file: ```xml @@ -43,6 +64,7 @@ Define a view in your layout file: app:startAngle="270"/> ``` + And (or) add following code to your activity: Kotlin diff --git a/build.gradle b/build.gradle index 5133827..f4ac87e 100644 --- a/build.gradle +++ b/build.gradle @@ -1,57 +1,53 @@ buildscript { + repositories { + google() - jcenter() + + mavenCentral() } dependencies { - classpath 'com.android.tools.build:gradle:3.2.1' - classpath 'com.github.dcendents:android-maven-gradle-plugin:2.1' - classpath 'com.jfrog.bintray.gradle:gradle-bintray-plugin:1.8.4' + + classpath 'com.android.tools.build:gradle:7.0.4' } } allprojects { + repositories { + google() - jcenter() + + mavenCentral() } } apply plugin: 'com.android.library' -apply plugin: 'com.github.dcendents.android-maven' -apply plugin: 'com.jfrog.bintray' +apply plugin: 'maven-publish' ext { - libraryName = 'CircularProgressBar' - libraryDescription = 'Circular progress bar' - libraryVersion = '1.2.2' - artifact = 'circular-progress-bar' - developerId = 'yuriy-budiyev' - developerName = 'Yuriy Budiyev' - developerEmail = 'yuriy.budiyev@yandex.ru' + libraryVersion = '1.2.3' publishedGroupId = 'com.budiyev.android' - siteUrl = 'https://github.com/yuriy-budiyev/circular-progress-bar' - gitUrl = 'https://github.com/yuriy-budiyev/circular-progress-bar.git' - bintrayRepo = 'maven' - bintrayName = 'circular-progress-bar' - licenseName = 'MIT License' - allLicenses = ['MIT'] } +group = publishedGroupId +version = libraryVersion + android { - compileSdkVersion 28 + compileSdkVersion 31 + buildToolsVersion '31.0.0' defaultConfig { minSdkVersion 14 - targetSdkVersion 28 - versionCode 23 + targetSdkVersion 31 + versionCode 24 versionName libraryVersion } compileOptions { - sourceCompatibility JavaVersion.VERSION_1_6 - targetCompatibility JavaVersion.VERSION_1_6 + sourceCompatibility JavaVersion.VERSION_1_7 + targetCompatibility JavaVersion.VERSION_1_7 } buildTypes { @@ -63,89 +59,40 @@ android { } dependencies { - api 'androidx.annotation:annotation:1.0.1' -} - -group = publishedGroupId - -install { - repositories.mavenInstaller { - pom { - project { - packaging 'aar' - groupId publishedGroupId - artifactId artifact - name libraryName - description libraryDescription - url siteUrl - - licenses { - license { - name licenseName - } - } - - developers { - developer { - id developerId - name developerName - email developerEmail - } - } - - scm { - connection gitUrl - developerConnection gitUrl - url siteUrl - } - } - } - } + api 'androidx.annotation:annotation:1.3.0' } -version = libraryVersion - task sourcesJar(type: Jar) { - classifier = 'sources' + archiveClassifier.set('sources') from android.sourceSets.main.java.srcDirs } task javadoc(type: Javadoc) { - source = android.sourceSets.main.java.srcDirs + options.charSet = 'UTF-8' + failOnError false + source = android.sourceSets.main.java.sourceFiles classpath += project.files(android.getBootClasspath().join(File.pathSeparator)) - failOnError = false } task javadocJar(type: Jar, dependsOn: javadoc) { - classifier = 'javadoc' - from javadoc.getDestinationDir() + archiveClassifier.set('javadoc') + from javadoc.destinationDir } artifacts { - archives javadocJar archives sourcesJar + archives javadocJar } -Properties properties = new Properties() -properties.load(project.rootProject.file('local.properties').newDataInputStream()) - -bintray { - user = properties.getProperty('bintray.user') - key = properties.getProperty('bintray.apikey') - configurations = ['archives'] - - pkg { - repo = bintrayRepo - name = bintrayName - desc = libraryDescription - websiteUrl = siteUrl - vcsUrl = gitUrl - licenses = allLicenses - publish = true - - version { - desc = libraryDescription - vcsTag = 'v' + libraryVersion +afterEvaluate { + publishing { + publications { + release(MavenPublication) { + from components.release + artifactId = 'circular-progress-bar' + groupId = publishedGroupId + version = libraryVersion + } } } } diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties index 8deb97f..515f98a 100644 --- a/gradle/wrapper/gradle-wrapper.properties +++ b/gradle/wrapper/gradle-wrapper.properties @@ -3,4 +3,4 @@ distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists zipStoreBase=GRADLE_USER_HOME zipStorePath=wrapper/dists -distributionUrl=https\://services.gradle.org/distributions/gradle-4.6-all.zip +distributionUrl=https\://services.gradle.org/distributions/gradle-7.3.3-all.zip diff --git a/src/main/java/com/budiyev/android/circularprogressbar/CircularProgressBar.java b/src/main/java/com/budiyev/android/circularprogressbar/CircularProgressBar.java index 9c01271..e99c93c 100644 --- a/src/main/java/com/budiyev/android/circularprogressbar/CircularProgressBar.java +++ b/src/main/java/com/budiyev/android/circularprogressbar/CircularProgressBar.java @@ -184,7 +184,8 @@ public float getStartAngle() { */ public void setStartAngle(@FloatRange(from = -360f, to = 360f) final float angle) { if (angle < -360f || angle > 360f) { - throw new IllegalArgumentException("Start angle value should be between -360 and 360 degrees (inclusive)"); + throw new IllegalArgumentException( + "Start angle value should be between -360 and 360 degrees (inclusive)"); } mStartAngle = angle; invalidate(); @@ -306,7 +307,8 @@ public TimeInterpolator getIndeterminateRotationAnimationInterpolator() { /** * Rotation animation interpolator for indeterminate mode */ - public void setIndeterminateRotationAnimationInterpolator(@NonNull final TimeInterpolator interpolator) { + public void setIndeterminateRotationAnimationInterpolator( + @NonNull final TimeInterpolator interpolator) { //noinspection ConstantConditions if (interpolator == null) { throw new IllegalArgumentException("Interpolator can't be null"); @@ -353,7 +355,8 @@ public TimeInterpolator getIndeterminateSweepAnimationInterpolator() { /** * Sweep animation interpolator for indeterminate mode */ - public void setIndeterminateSweepAnimationInterpolator(@NonNull final TimeInterpolator interpolator) { + public void setIndeterminateSweepAnimationInterpolator( + @NonNull final TimeInterpolator interpolator) { //noinspection ConstantConditions if (interpolator == null) { throw new IllegalArgumentException("Interpolator can't be null"); @@ -414,7 +417,8 @@ public float getForegroundStrokeWidth() { /** * Foreground stroke width (in pixels) */ - public void setForegroundStrokeWidth(@FloatRange(from = 0f, to = Float.MAX_VALUE) final float width) { + public void setForegroundStrokeWidth( + @FloatRange(from = 0f, to = Float.MAX_VALUE) final float width) { if (width < 0f) { throw new IllegalArgumentException("Width can't be negative"); } @@ -450,7 +454,8 @@ public float getBackgroundStrokeWidth() { /** * Background stroke width (in pixels) */ - public void setBackgroundStrokeWidth(@FloatRange(from = 0f, to = Float.MAX_VALUE) final float width) { + public void setBackgroundStrokeWidth( + @FloatRange(from = 0f, to = Float.MAX_VALUE) final float width) { if (width < 0f) { throw new IllegalArgumentException("Width can't be negative"); } @@ -584,7 +589,8 @@ protected void onMeasure(final int widthMeasureSpec, final int heightMeasureSpec } @Override - protected void onSizeChanged(final int width, final int height, final int oldWidth, final int oldHeight) { + protected void onSizeChanged(final int width, final int height, final int oldWidth, + final int oldHeight) { invalidateDrawRect(width, height); } @@ -605,8 +611,9 @@ protected void onDetachedFromWindow() { cancelProgressAnimation(); } - private void initialize(@NonNull final Context context, @Nullable final AttributeSet attributeSet, - @AttrRes final int defStyleAttr, @StyleRes final int defStyleRes) { + private void initialize(@NonNull final Context context, + @Nullable final AttributeSet attributeSet, @AttrRes final int defStyleAttr, + @StyleRes final int defStyleRes) { mForegroundStrokePaint.setStyle(Paint.Style.STROKE); mBackgroundStrokePaint.setStyle(Paint.Style.STROKE); final DisplayMetrics displayMetrics = context.getResources().getDisplayMetrics(); @@ -621,51 +628,65 @@ private void initialize(@NonNull final Context context, @Nullable final Attribut mAnimateProgress = DEFAULT_ANIMATE_PROGRESS; mDrawBackgroundStroke = DEFAULT_DRAW_BACKGROUND_STROKE; mForegroundStrokePaint.setColor(DEFAULT_FOREGROUND_STROKE_COLOR); - mForegroundStrokePaint - .setStrokeWidth(Math.round(DEFAULT_FOREGROUND_STROKE_WIDTH_DP * displayMetrics.density)); + mForegroundStrokePaint.setStrokeWidth( + Math.round(DEFAULT_FOREGROUND_STROKE_WIDTH_DP * displayMetrics.density)); mForegroundStrokePaint.setStrokeCap(getStrokeCap(DEFAULT_FOREGROUND_STROKE_CAP)); mBackgroundStrokePaint.setColor(DEFAULT_BACKGROUND_STROKE_COLOR); - mBackgroundStrokePaint - .setStrokeWidth(Math.round(DEFAULT_BACKGROUND_STROKE_WIDTH_DP * displayMetrics.density)); - mIndeterminateRotationAnimator.setDuration(DEFAULT_INDETERMINATE_ROTATION_ANIMATION_DURATION); + mBackgroundStrokePaint.setStrokeWidth( + Math.round(DEFAULT_BACKGROUND_STROKE_WIDTH_DP * displayMetrics.density)); + mIndeterminateRotationAnimator + .setDuration(DEFAULT_INDETERMINATE_ROTATION_ANIMATION_DURATION); mIndeterminateSweepAnimator.setDuration(DEFAULT_INDETERMINATE_SWEEP_ANIMATION_DURATION); } else { TypedArray attributes = null; try { attributes = context.getTheme() - .obtainStyledAttributes(attributeSet, R.styleable.CircularProgressBar, defStyleAttr, - defStyleRes); - setMaximum(attributes.getFloat(R.styleable.CircularProgressBar_maximum, DEFAULT_MAXIMUM)); - setProgress(attributes.getFloat(R.styleable.CircularProgressBar_progress, DEFAULT_PROGRESS)); - setStartAngle(attributes.getFloat(R.styleable.CircularProgressBar_startAngle, DEFAULT_START_ANGLE)); + .obtainStyledAttributes(attributeSet, R.styleable.CircularProgressBar, + defStyleAttr, defStyleRes); + setMaximum(attributes + .getFloat(R.styleable.CircularProgressBar_maximum, DEFAULT_MAXIMUM)); + setProgress(attributes + .getFloat(R.styleable.CircularProgressBar_progress, DEFAULT_PROGRESS)); + setStartAngle(attributes + .getFloat(R.styleable.CircularProgressBar_startAngle, DEFAULT_START_ANGLE)); setIndeterminateMinimumAngle(attributes .getFloat(R.styleable.CircularProgressBar_indeterminateMinimumAngle, DEFAULT_INDETERMINATE_MINIMUM_ANGLE)); setProgressAnimationDuration(attributes .getInteger(R.styleable.CircularProgressBar_progressAnimationDuration, DEFAULT_PROGRESS_ANIMATION_DURATION)); - setIndeterminateRotationAnimationDuration(attributes - .getInteger(R.styleable.CircularProgressBar_indeterminateRotationAnimationDuration, - DEFAULT_INDETERMINATE_ROTATION_ANIMATION_DURATION)); - setIndeterminateSweepAnimationDuration(attributes - .getInteger(R.styleable.CircularProgressBar_indeterminateSweepAnimationDuration, - DEFAULT_INDETERMINATE_SWEEP_ANIMATION_DURATION)); - setForegroundStrokeColor(attributes.getColor(R.styleable.CircularProgressBar_foregroundStrokeColor, - DEFAULT_FOREGROUND_STROKE_COLOR)); - setBackgroundStrokeColor(attributes.getColor(R.styleable.CircularProgressBar_backgroundStrokeColor, - DEFAULT_BACKGROUND_STROKE_COLOR)); - setForegroundStrokeWidth(attributes.getDimension(R.styleable.CircularProgressBar_foregroundStrokeWidth, - Math.round(DEFAULT_FOREGROUND_STROKE_WIDTH_DP * displayMetrics.density))); + setIndeterminateRotationAnimationDuration(attributes.getInteger( + R.styleable.CircularProgressBar_indeterminateRotationAnimationDuration, + DEFAULT_INDETERMINATE_ROTATION_ANIMATION_DURATION)); + setIndeterminateSweepAnimationDuration(attributes.getInteger( + R.styleable.CircularProgressBar_indeterminateSweepAnimationDuration, + DEFAULT_INDETERMINATE_SWEEP_ANIMATION_DURATION)); + setForegroundStrokeColor(attributes + .getColor(R.styleable.CircularProgressBar_foregroundStrokeColor, + DEFAULT_FOREGROUND_STROKE_COLOR)); + setBackgroundStrokeColor(attributes + .getColor(R.styleable.CircularProgressBar_backgroundStrokeColor, + DEFAULT_BACKGROUND_STROKE_COLOR)); + setForegroundStrokeWidth(attributes + .getDimension(R.styleable.CircularProgressBar_foregroundStrokeWidth, + Math.round(DEFAULT_FOREGROUND_STROKE_WIDTH_DP * + displayMetrics.density))); setForegroundStrokeCap(getStrokeCap(attributes - .getInt(R.styleable.CircularProgressBar_foregroundStrokeCap, DEFAULT_FOREGROUND_STROKE_CAP))); - setBackgroundStrokeWidth(attributes.getDimension(R.styleable.CircularProgressBar_backgroundStrokeWidth, - Math.round(DEFAULT_BACKGROUND_STROKE_WIDTH_DP * displayMetrics.density))); + .getInt(R.styleable.CircularProgressBar_foregroundStrokeCap, + DEFAULT_FOREGROUND_STROKE_CAP))); + setBackgroundStrokeWidth(attributes + .getDimension(R.styleable.CircularProgressBar_backgroundStrokeWidth, + Math.round(DEFAULT_BACKGROUND_STROKE_WIDTH_DP * + displayMetrics.density))); setAnimateProgress(attributes - .getBoolean(R.styleable.CircularProgressBar_animateProgress, DEFAULT_ANIMATE_PROGRESS)); - setDrawBackgroundStroke(attributes.getBoolean(R.styleable.CircularProgressBar_drawBackgroundStroke, - DEFAULT_DRAW_BACKGROUND_STROKE)); - setIndeterminate( - attributes.getBoolean(R.styleable.CircularProgressBar_indeterminate, DEFAULT_INDETERMINATE)); + .getBoolean(R.styleable.CircularProgressBar_animateProgress, + DEFAULT_ANIMATE_PROGRESS)); + setDrawBackgroundStroke(attributes + .getBoolean(R.styleable.CircularProgressBar_drawBackgroundStroke, + DEFAULT_DRAW_BACKGROUND_STROKE)); + setIndeterminate(attributes + .getBoolean(R.styleable.CircularProgressBar_indeterminate, + DEFAULT_INDETERMINATE)); } finally { if (attributes != null) { attributes.recycle(); @@ -696,18 +717,19 @@ private void invalidateDrawRect() { private void invalidateDrawRect(final int width, final int height) { final float thickness; if (mDrawBackgroundStroke) { - thickness = Math.max(mForegroundStrokePaint.getStrokeWidth(), mBackgroundStrokePaint.getStrokeWidth()); + thickness = Math.max(mForegroundStrokePaint.getStrokeWidth(), + mBackgroundStrokePaint.getStrokeWidth()); } else { thickness = mForegroundStrokePaint.getStrokeWidth(); } if (width > height) { final float offset = (width - height) / 2f; - mDrawRect.set(offset + thickness / 2f + 1f, thickness / 2f + 1f, width - offset - thickness / 2f - 1f, - height - thickness / 2f - 1f); + mDrawRect.set(offset + thickness / 2f + 1f, thickness / 2f + 1f, + width - offset - thickness / 2f - 1f, height - thickness / 2f - 1f); } else if (width < height) { final float offset = (height - width) / 2f; - mDrawRect.set(thickness / 2f + 1f, offset + thickness / 2f + 1f, width - thickness / 2f - 1f, - height - offset - thickness / 2f - 1f); + mDrawRect.set(thickness / 2f + 1f, offset + thickness / 2f + 1f, + width - thickness / 2f - 1f, height - offset - thickness / 2f - 1f); } else { mDrawRect.set(thickness / 2f + 1f, thickness / 2f + 1f, width - thickness / 2f - 1f, height - thickness / 2f - 1f); @@ -726,7 +748,8 @@ private void invalidateForegroundStrokeCapAngle() { case ROUND: { final float r = mDrawRect.width() / 2f; if (r != 0) { - mForegroundStrokeCapAngle = 90f * mForegroundStrokePaint.getStrokeWidth() / (float) Math.PI / r; + mForegroundStrokeCapAngle = + 90f * mForegroundStrokePaint.getStrokeWidth() / (float) Math.PI / r; } else { mForegroundStrokeCapAngle = 0f; } @@ -849,7 +872,8 @@ private final class SweepRestartAction implements Runnable { public void run() { mIndeterminateGrowMode = !mIndeterminateGrowMode; if (mIndeterminateGrowMode) { - mIndeterminateOffsetAngle = (mIndeterminateOffsetAngle + mIndeterminateMinimumAngle * 2f) % 360f; + mIndeterminateOffsetAngle = + (mIndeterminateOffsetAngle + mIndeterminateMinimumAngle * 2f) % 360f; } if (mIndeterminateSweepAnimator.isRunning()) { mIndeterminateSweepAnimator.cancel();