Skip to content
This repository has been archived by the owner on May 24, 2022. It is now read-only.

Commit

Permalink
Add OnProgressChangeListener (close #11)
Browse files Browse the repository at this point in the history
  • Loading branch information
antonKozyriatskyi committed Sep 2, 2018
1 parent f92f39c commit d25886f
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 0 deletions.
12 changes: 12 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,18 @@ Acceptable values are from 0 to 360 degrees. But be aware that they go clockwise

---

#### Listening to progress changes
```java
circularProgress.setOnProgressChangeListener(new CircularProgressIndicator.OnProgressChangeListener() {
@Override
public void onProgressChanged(double progress, double maxProgress) {
Log.d("PROGRESS", String.format("Current: %1$.0f, max: %2$.0f", progress, maxProgress));
}
});
```

---

### Download using Gradle

Add this in your root `build.gradle` at the end of `repositories` in `allprojects` section:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,9 @@ public class CircularProgressIndicator extends View {
@NonNull
private ProgressTextAdapter progressTextAdapter;

@Nullable
private OnProgressChangeListener onProgressChangeListener;

public CircularProgressIndicator(Context context) {
super(context);
init(context, null);
Expand Down Expand Up @@ -334,6 +337,10 @@ public void setProgress(double current, double max) {
maxProgressValue = max;
progressValue = Math.min(current, max);

if (onProgressChangeListener != null) {
onProgressChangeListener.onProgressChanged(progressValue, maxProgressValue);
}

reformatProgressText();
calculateTextBounds();

Expand Down Expand Up @@ -574,6 +581,15 @@ public void setProgressStrokeCap(@Cap int cap) {
}
}

public void setOnProgressChangeListener(@Nullable OnProgressChangeListener onProgressChangeListener) {
this.onProgressChangeListener = onProgressChangeListener;
}

@Nullable
public OnProgressChangeListener getOnProgressChangeListener() {
return onProgressChangeListener;
}

@IntDef({DIRECTION_CLOCKWISE, DIRECTION_COUNTERCLOCKWISE})
public @interface Direction {
}
Expand All @@ -587,4 +603,8 @@ public interface ProgressTextAdapter {
@NonNull
String formatText(double currentProgress);
}

public interface OnProgressChangeListener {
void onProgressChanged(double progress, double maxProgress);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import android.graphics.Color;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.util.Log;
import android.view.View;
import android.widget.Button;
import android.widget.CheckBox;
Expand Down Expand Up @@ -80,6 +81,13 @@ public void onCheckedChanged(RadioGroup group, int checkedId) {
}
}
});

circularProgress.setOnProgressChangeListener(new CircularProgressIndicator.OnProgressChangeListener() {
@Override
public void onProgressChanged(double progress, double maxProgress) {
Log.d("PROGRESS", String.format("Current: %1$.0f, max: %2$.0f", progress, maxProgress));
}
});
}

@Override
Expand Down

0 comments on commit d25886f

Please sign in to comment.