Skip to content

Commit

Permalink
优化代码,增加是否显示圆角属性
Browse files Browse the repository at this point in the history
  • Loading branch information
lexluthors committed Sep 20, 2017
1 parent 28e2854 commit a9b112d
Show file tree
Hide file tree
Showing 8 changed files with 43 additions and 93 deletions.
2 changes: 1 addition & 1 deletion .idea/misc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ public CircularProgressBar(Context context, AttributeSet attrs, int defStyle) {
final int colorsId = a.getResourceId(R.styleable.CircularProgressBar_cpb_colors, 0);
final int minSweepAngle = a.getInteger(R.styleable.CircularProgressBar_cpb_min_sweep_angle, res.getInteger(R.integer.cpb_default_min_sweep_angle));
final int maxSweepAngle = a.getInteger(R.styleable.CircularProgressBar_cpb_max_sweep_angle, res.getInteger(R.integer.cpb_default_max_sweep_angle));
final boolean capRound = a.getBoolean(R.styleable.CircularProgressBar_cpb_cap_round, false);
a.recycle();

int[] colors = null;
Expand All @@ -54,7 +55,7 @@ public CircularProgressBar(Context context, AttributeSet attrs, int defStyle) {
.rotationSpeed(rotationSpeed)
.strokeWidth(strokeWidth)
.minSweepAngle(minSweepAngle)
.maxSweepAngle(maxSweepAngle);
.maxSweepAngle(maxSweepAngle).style(capRound?CircularProgressDrawable.Style.ROUNDED:CircularProgressDrawable.Style.NORMAL);

if (colors != null && colors.length > 0)
builder.colors(colors);
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,6 @@
import android.view.animation.Interpolator;
import android.view.animation.LinearInterpolator;

import static com.jaywei.mdprogress.CircularProgressBarUtils.checkAngle;
import static com.jaywei.mdprogress.CircularProgressBarUtils.checkColors;
import static com.jaywei.mdprogress.CircularProgressBarUtils.checkNotNull;
import static com.jaywei.mdprogress.CircularProgressBarUtils.checkPositiveOrZero;
import static com.jaywei.mdprogress.CircularProgressBarUtils.checkSpeed;

public class CircularProgressDrawable extends Drawable
implements Animatable {

Expand Down Expand Up @@ -403,7 +397,7 @@ private void initValues(Context context) {
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;
mStyle = Style.NORMAL;
}

public Builder color(int color) {
Expand Down Expand Up @@ -477,4 +471,34 @@ public CircularProgressDrawable build() {
mSweepInterpolator);
}
}

static void checkSpeed(float speed) {
if (speed <= 0f)
throw new IllegalArgumentException("Speed must be >= 0");
}

static void checkColors(int[] colors) {
if (colors == null || colors.length == 0)
throw new IllegalArgumentException("You must provide at least 1 color");
}

static void checkAngle(int angle) {
if (angle < 0 || angle > 360)
throw new IllegalArgumentException(String.format("Illegal angle %d: must be >=0 and <= 360", angle));
}

static void checkPositiveOrZero(float number, String name) {
if (number < 0)
throw new IllegalArgumentException(String.format("%s %d must be positive", name, number));
}

static void checkPositive(int number, String name){
if(number <= 0)
throw new IllegalArgumentException(String.format("%s must not be null", name));
}

static void checkNotNull(Object o, String name) {
if (o == null)
throw new IllegalArgumentException(String.format("%s must be not null", name));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,12 @@
<item name="spb_default_speed" format="float" type="string">1.0</item>
<bool name="spb_default_reversed">false</bool>
<bool name="spb_default_mirror_mode">false</bool>
<bool name="spb_default_progressiveStart_activated">false</bool>

<color name="cpb_default_color">#33b5e5</color>
<dimen name="cpb_default_stroke_width">4dp</dimen>
<integer name="cpb_default_min_sweep_angle">20</integer>
<integer name="cpb_default_max_sweep_angle">300</integer>
<integer name="cpb_default_max_sweep_angle">315</integer>
<item name="cpb_default_sweep_speed" format="float" type="string">1</item>
<item name="cpb_default_rotation_speed" format="float" type="string">1</item>
</resources>
Original file line number Diff line number Diff line change
@@ -1,24 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<resources>

<style name="Theme.SmoothProgressBarDefaults" parent="android:Theme.Holo">
<item name="spbStyle">@style/SmoothProgressBar</item>
<item name="cpbStyle">@style/CircularProgressBar</item>
</style>

<style name="SmoothProgressBar" parent="android:Widget.ProgressBar.Horizontal">
<item name="spb_color">@color/spb_default_color</item>
<item name="spb_sections_count">@integer/spb_default_sections_count</item>
<item name="spb_speed">@string/spb_default_speed</item>
<item name="spb_stroke_width">@dimen/spb_default_stroke_width</item>
<item name="spb_stroke_separator_length">@dimen/spb_default_stroke_separator_length</item>
<item name="spb_reversed">@bool/spb_default_reversed</item>
<item name="spb_mirror_mode">@bool/spb_default_mirror_mode</item>
<item name="spb_interpolator">@integer/spb_default_interpolator</item>
<item name="android:minHeight">48dp</item>
<item name="android:maxHeight">48dp</item>
</style>

<declare-styleable name="CircularProgressBar">
<attr name="cpbStyle" format="reference"/>
<attr name="cpb_color" format="color"/>
Expand All @@ -28,6 +10,7 @@
<attr name="cpb_max_sweep_angle" format="integer"/>
<attr name="cpb_sweep_speed" format="float"/>
<attr name="cpb_rotation_speed" format="float"/>
<attr name="cpb_cap_round" format="boolean"/>
</declare-styleable>

<style name="CircularProgressBar" parent="android:Widget.Holo.ProgressBar">
Expand Down
26 changes: 0 additions & 26 deletions MDProgress/src/main/res/values/smoothprogressbar_attrs.xml

This file was deleted.

6 changes: 6 additions & 0 deletions app/src/main/res/values/colors.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,10 @@
<color name="colorPrimary">#3F51B5</color>
<color name="colorPrimaryDark">#303F9F</color>
<color name="colorAccent">#FF4081</color>

<array name="color_sequence">
<item>#00ff00</item>
<item>#ff0084</item>
<item>#0000ff</item>
</array>
</resources>

0 comments on commit a9b112d

Please sign in to comment.