Skip to content

Commit

Permalink
Added viewEditMode check in the progressDrawable builder. should fix c…
Browse files Browse the repository at this point in the history
  • Loading branch information
castorflex committed Feb 23, 2015
1 parent 688c322 commit b644cd5
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ public CircularProgressBar(Context context, AttributeSet attrs, int defStyle) {
super(context, attrs, defStyle);

if (isInEditMode()) {
setIndeterminateDrawable(new CircularProgressDrawable.Builder(context).build());
setIndeterminateDrawable(new CircularProgressDrawable.Builder(context, true).build());
return;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,24 +5,24 @@
import android.animation.ValueAnimator;
import android.content.Context;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.ColorFilter;
import android.graphics.Paint;
import android.graphics.PixelFormat;
import android.graphics.Rect;
import android.graphics.RectF;
import android.graphics.drawable.Animatable;
import android.graphics.drawable.Drawable;
import android.util.Log;
import android.view.animation.DecelerateInterpolator;
import android.view.animation.Interpolator;
import android.view.animation.LinearInterpolator;

import static fr.castorflex.android.circularprogressbar.CircularProgressBarUtils.checkAngle;
import static fr.castorflex.android.circularprogressbar.CircularProgressBarUtils.getAnimatedFraction;
import static fr.castorflex.android.circularprogressbar.CircularProgressBarUtils.checkColors;
import static fr.castorflex.android.circularprogressbar.CircularProgressBarUtils.checkNotNull;
import static fr.castorflex.android.circularprogressbar.CircularProgressBarUtils.checkPositiveOrZero;
import static fr.castorflex.android.circularprogressbar.CircularProgressBarUtils.checkSpeed;
import static fr.castorflex.android.circularprogressbar.CircularProgressBarUtils.getAnimatedFraction;

public class CircularProgressDrawable extends Drawable
implements Animatable {
Expand Down Expand Up @@ -395,16 +395,26 @@ public static class Builder {
private Interpolator mAngleInterpolator = DEFAULT_ROTATION_INTERPOLATOR;

public Builder(Context context) {
initValues(context);
this(context, false);
}

private void initValues(Context context) {
public Builder(Context context, boolean editMode) {
initValues(context, editMode);
}

private void initValues(Context context, boolean editMode) {
mStrokeWidth = context.getResources().getDimension(R.dimen.cpb_default_stroke_width);
mSweepSpeed = 1f;
mRotationSpeed = 1f;
mColors = new int[]{context.getResources().getColor(R.color.cpb_default_color)};
mMinSweepAngle = context.getResources().getInteger(R.integer.cpb_default_min_sweep_angle);
mMaxSweepAngle = context.getResources().getInteger(R.integer.cpb_default_max_sweep_angle);
if (editMode) {
mColors = new int[]{Color.BLUE};
mMinSweepAngle = 20;
mMaxSweepAngle = 300;
} else {
mColors = new int[]{context.getResources().getColor(R.color.cpb_default_color)};
mMinSweepAngle = context.getResources().getInteger(R.integer.cpb_default_min_sweep_angle);
mMaxSweepAngle = context.getResources().getInteger(R.integer.cpb_default_max_sweep_angle);
}
mStyle = Style.ROUNDED;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ public SmoothProgressBar(Context context, AttributeSet attrs, int defStyle) {
super(context, attrs, defStyle);

if (isInEditMode()) {
setIndeterminateDrawable(new SmoothProgressDrawable.Builder(context).build());
setIndeterminateDrawable(new SmoothProgressDrawable.Builder(context, true).build());
return;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -626,7 +626,11 @@ public static class Builder {
private Callbacks mOnProgressiveStopEndedListener;

public Builder(Context context) {
initValues(context);
this(context, false);
}

public Builder(Context context, boolean editMode) {
initValues(context, editMode);
}

public SmoothProgressDrawable build() {
Expand All @@ -651,18 +655,28 @@ public SmoothProgressDrawable build() {
return ret;
}

private void initValues(Context context) {
private void initValues(Context context, boolean editMode) {
Resources res = context.getResources();
mInterpolator = new AccelerateInterpolator();
mSectionsCount = res.getInteger(R.integer.spb_default_sections_count);
mColors = new int[]{res.getColor(R.color.spb_default_color)};
mSpeed = Float.parseFloat(res.getString(R.string.spb_default_speed));
if (!editMode) {
mSectionsCount = res.getInteger(R.integer.spb_default_sections_count);
mSpeed = Float.parseFloat(res.getString(R.string.spb_default_speed));
mReversed = res.getBoolean(R.bool.spb_default_reversed);
mProgressiveStartActivated = res.getBoolean(R.bool.spb_default_progressiveStart_activated);
mColors = new int[]{res.getColor(R.color.spb_default_color)};
mStrokeSeparatorLength = res.getDimensionPixelSize(R.dimen.spb_default_stroke_separator_length);
mStrokeWidth = res.getDimensionPixelOffset(R.dimen.spb_default_stroke_width);
} else {
mSectionsCount = 4;
mSpeed = 1f;
mReversed = false;
mProgressiveStartActivated = false;
mColors = new int[]{0xff33b5e5};
mStrokeSeparatorLength = 4;
mStrokeWidth = 4;
}
mProgressiveStartSpeed = mSpeed;
mProgressiveStopSpeed = mSpeed;
mReversed = res.getBoolean(R.bool.spb_default_reversed);
mStrokeSeparatorLength = res.getDimensionPixelSize(R.dimen.spb_default_stroke_separator_length);
mStrokeWidth = res.getDimensionPixelOffset(R.dimen.spb_default_stroke_width);
mProgressiveStartActivated = res.getBoolean(R.bool.spb_default_progressiveStart_activated);
mGradients = false;
}

Expand Down

0 comments on commit b644cd5

Please sign in to comment.