Skip to content

Commit

Permalink
Merge pull request #87 from hoseinit/master
Browse files Browse the repository at this point in the history
Added Float ArcProgress
  • Loading branch information
uknownothingsnow committed Nov 12, 2017
2 parents 60a8f30 + be7c411 commit dd46251
Showing 1 changed file with 10 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@
import android.util.AttributeSet;
import android.view.View;

import java.text.DecimalFormat;

/**
* Created by bruce on 11/6/14.
*/
Expand All @@ -28,7 +30,7 @@ public class ArcProgress extends View {
private String bottomText;
private float textSize;
private int textColor;
private int progress = 0;
private float progress = 0;
private int max;
private int finishedStrokeColor;
private int unfinishedStrokeColor;
Expand Down Expand Up @@ -100,7 +102,7 @@ protected void initByAttributes(TypedArray attributes) {
textSize = attributes.getDimension(R.styleable.ArcProgress_arc_text_size, default_text_size);
arcAngle = attributes.getFloat(R.styleable.ArcProgress_arc_angle, default_arc_angle);
setMax(attributes.getInt(R.styleable.ArcProgress_arc_max, default_max));
setProgress(attributes.getInt(R.styleable.ArcProgress_arc_progress, 0));
setProgress(attributes.getFloat(R.styleable.ArcProgress_arc_progress, 0));
strokeWidth = attributes.getDimension(R.styleable.ArcProgress_arc_stroke_width, default_stroke_width);
suffixTextSize = attributes.getDimension(R.styleable.ArcProgress_arc_suffix_text_size, default_suffix_text_size);
suffixText = TextUtils.isEmpty(attributes.getString(R.styleable.ArcProgress_arc_suffix_text)) ? default_suffix_text : attributes.getString(R.styleable.ArcProgress_arc_suffix_text);
Expand Down Expand Up @@ -156,12 +158,13 @@ public void setBottomText(String bottomText) {
this.invalidate();
}

public int getProgress() {
public float getProgress() {
return progress;
}

public void setProgress(int progress) {
this.progress = progress;
public void setProgress(float progress) {
this.progress = Float.valueOf(new DecimalFormat("#.##").format(progress));

if (this.progress > getMax()) {
this.progress %= getMax();
}
Expand Down Expand Up @@ -319,7 +322,7 @@ protected Parcelable onSaveInstanceState() {
bundle.putString(INSTANCE_BOTTOM_TEXT, getBottomText());
bundle.putFloat(INSTANCE_TEXT_SIZE, getTextSize());
bundle.putInt(INSTANCE_TEXT_COLOR, getTextColor());
bundle.putInt(INSTANCE_PROGRESS, getProgress());
bundle.putFloat(INSTANCE_PROGRESS, getProgress());
bundle.putInt(INSTANCE_MAX, getMax());
bundle.putInt(INSTANCE_FINISHED_STROKE_COLOR, getFinishedStrokeColor());
bundle.putInt(INSTANCE_UNFINISHED_STROKE_COLOR, getUnfinishedStrokeColor());
Expand All @@ -340,7 +343,7 @@ protected void onRestoreInstanceState(Parcelable state) {
textSize = bundle.getFloat(INSTANCE_TEXT_SIZE);
textColor = bundle.getInt(INSTANCE_TEXT_COLOR);
setMax(bundle.getInt(INSTANCE_MAX));
setProgress(bundle.getInt(INSTANCE_PROGRESS));
setProgress(bundle.getFloat(INSTANCE_PROGRESS));
finishedStrokeColor = bundle.getInt(INSTANCE_FINISHED_STROKE_COLOR);
unfinishedStrokeColor = bundle.getInt(INSTANCE_UNFINISHED_STROKE_COLOR);
suffixText = bundle.getString(INSTANCE_SUFFIX);
Expand Down

0 comments on commit dd46251

Please sign in to comment.