Skip to content

Commit

Permalink
SetProgess(..) FIXED
Browse files Browse the repository at this point in the history
SetProgress(....) not working. FIXED.
  • Loading branch information
learnNcode committed Feb 10, 2014
1 parent e291157 commit ef7c0c1
Showing 1 changed file with 33 additions and 15 deletions.
48 changes: 33 additions & 15 deletions CircularSeekBar.java
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ public class CircularSeekBar extends View {
/**
* The adjustment factor. This adds an adjustment of the specified size to
* both sides of the progress bar, allowing touch events to be processed
* more user friendlily (yes, I know that's not a word)
* more user friendly (yes, I know that's not a word)
*/
private float adjustmentFactor = 100;

Expand All @@ -130,6 +130,8 @@ public class CircularSeekBar extends View {
*/
private boolean CALLED_FROM_ANGLE = false;

private boolean SHOW_SEEKBAR = true;

/** The rectangle containing our circles and arcs. */
private RectF rect = new RectF();

Expand All @@ -147,11 +149,11 @@ public void onProgressChange(CircularSeekBar view, int newProgress) {
circleRing = new Paint();

circleColor.setColor(Color.parseColor("#ff33b5e5")); // Set default
// progress
// color to holo
// blue.
// progress
// color to holo
// blue.
innerColor.setColor(Color.BLACK); // Set default background color to
// black
// black
circleRing.setColor(Color.GRAY);// Set default background color to Gray

circleColor.setAntiAlias(true);
Expand Down Expand Up @@ -229,9 +231,9 @@ protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
height = getHeight();// Get View Height

int size = (width > height) ? height : width; // Choose the smaller
// between width and
// height to make a
// square
// between width and
// height to make a
// square

cx = width / 2; // Center X for circle
cy = height / 2; // Center Y for circle
Expand Down Expand Up @@ -259,14 +261,16 @@ protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
*/
@Override
protected void onDraw(Canvas canvas) {
dx = getXFromAngle();
dy = getYFromAngle();


canvas.drawCircle(cx, cy, outerRadius, circleRing);
canvas.drawArc(rect, startAngle, angle, true, circleColor);
canvas.drawCircle(cx, cy, innerRadius, innerColor);
drawMarkerAtProgress(canvas);

if(SHOW_SEEKBAR){
dx = getXFromAngle();
dy = getYFromAngle();
drawMarkerAtProgress(canvas);
}
super.onDraw(canvas);
}

Expand Down Expand Up @@ -436,8 +440,8 @@ public void setProgress(int progress) {
if (this.progress != progress) {
this.progress = progress;
if (!CALLED_FROM_ANGLE) {
int newPercent = (this.progress / this.maxProgress) * 100;
int newAngle = (newPercent / 100) * 360;
int newPercent = (this.progress * 100) / this.maxProgress;
int newAngle = (newPercent * 360) / 100 ;
this.setAngle(newAngle);
this.setProgressPercent(newPercent);
}
Expand Down Expand Up @@ -537,7 +541,7 @@ private void moved(float x, float y, boolean up) {

markPointX = (float) (cx + outerRadius * Math.cos(Math.atan2(x - cx, cy - y) - (Math.PI /2)));
markPointY = (float) (cy + outerRadius * Math.sin(Math.atan2(x - cx, cy - y) - (Math.PI /2)));

float degrees = (float) ((float) ((Math.toDegrees(Math.atan2(x - cx, cy - y)) + 360.0)) % 360.0);
// and to make it count 0-360
if (degrees < 0) {
Expand Down Expand Up @@ -572,4 +576,18 @@ public float getAdjustmentFactor() {
public void setAdjustmentFactor(float adjustmentFactor) {
this.adjustmentFactor = adjustmentFactor;
}

/**
* To display seekbar
*/
public void ShowSeekBar() {
SHOW_SEEKBAR = true;
}

/**
* To hide seekbar
*/
public void hideSeekBar() {
SHOW_SEEKBAR = false;
}
}

0 comments on commit ef7c0c1

Please sign in to comment.