diff --git a/CHANGELOG.md b/CHANGELOG.md index db81a17..00f0e91 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,7 @@ +##0.3.1 + +- Added a `applyStyle(int styleResId)` method + ##0.3.0 - `SmoothProgressDrawable.Builder#width` is now `setStrokeWidth` diff --git a/gradle.properties b/gradle.properties index 6208f13..759bbb5 100644 --- a/gradle.properties +++ b/gradle.properties @@ -1,5 +1,5 @@ -VERSION_NAME=0.3.0 -VERSION_CODE=7 +VERSION_NAME=0.3.1 +VERSION_CODE=8 GROUP=com.github.castorflex.smoothprogressbar #storeFile=nice try diff --git a/library/src/main/java/fr/castorflex/android/smoothprogressbar/SmoothProgressBar.java b/library/src/main/java/fr/castorflex/android/smoothprogressbar/SmoothProgressBar.java index c58019b..014b34f 100644 --- a/library/src/main/java/fr/castorflex/android/smoothprogressbar/SmoothProgressBar.java +++ b/library/src/main/java/fr/castorflex/android/smoothprogressbar/SmoothProgressBar.java @@ -88,6 +88,64 @@ public SmoothProgressBar(Context context, AttributeSet attrs, int defStyle) { setIndeterminateDrawable(builder.build()); } + public void applyStyle(int styleResId){ + TypedArray a = getContext().obtainStyledAttributes(null, R.styleable.SmoothProgressBar, 0, styleResId); + + if(a.hasValue(R.styleable.SmoothProgressBar_spb_color)){ + setSmoothProgressDrawableColor(a.getColor(R.styleable.SmoothProgressBar_spb_color, 0)); + } + if(a.hasValue(R.styleable.SmoothProgressBar_spb_colors)){ + int colorsId = a.getResourceId(R.styleable.SmoothProgressBar_spb_colors, 0); + if(colorsId != 0){ + int[] colors = getResources().getIntArray(colorsId); + if(colors != null && colors.length > 0) + setSmoothProgressDrawableColors(colors); + } + } + if(a.hasValue(R.styleable.SmoothProgressBar_spb_sections_count)){ + setSmoothProgressDrawableSectionsCount(a.getInteger(R.styleable.SmoothProgressBar_spb_sections_count, 0)); + } + if(a.hasValue(R.styleable.SmoothProgressBar_spb_stroke_separator_length)){ + setSmoothProgressDrawableSeparatorLength(a.getDimensionPixelSize(R.styleable.SmoothProgressBar_spb_stroke_separator_length, 0)); + } + if(a.hasValue(R.styleable.SmoothProgressBar_spb_stroke_width)){ + setSmoothProgressDrawableStrokeWidth(a.getDimension(R.styleable.SmoothProgressBar_spb_stroke_width, 0)); + } + if(a.hasValue(R.styleable.SmoothProgressBar_spb_speed)){ + setSmoothProgressDrawableSpeed(a.getFloat(R.styleable.SmoothProgressBar_spb_speed, 0)); + } + if(a.hasValue(R.styleable.SmoothProgressBar_spb_reversed)){ + setSmoothProgressDrawableReversed(a.getBoolean(R.styleable.SmoothProgressBar_spb_reversed, false)); + } + if(a.hasValue(R.styleable.SmoothProgressBar_spb_mirror_mode)){ + setSmoothProgressDrawableMirrorMode(a.getBoolean(R.styleable.SmoothProgressBar_spb_mirror_mode, false)); + } + if(a.hasValue(R.styleable.SmoothProgressBar_spb_interpolator)){ + int iInterpolator = a.getInteger(R.styleable.SmoothProgressBar_spb_interpolator, -1); + Interpolator interpolator; + switch (iInterpolator) { + case INTERPOLATOR_ACCELERATEDECELERATE: + interpolator = new AccelerateDecelerateInterpolator(); + break; + case INTERPOLATOR_DECELERATE: + interpolator = new DecelerateInterpolator(); + break; + case INTERPOLATOR_LINEAR: + interpolator = new LinearInterpolator(); + break; + case INTERPOLATOR_ACCELERATE: + interpolator = new AccelerateInterpolator(); + break; + default: + interpolator = null; + } + if(interpolator != null){ + setInterpolator(interpolator); + } + } + a.recycle(); + } + private SmoothProgressDrawable checkIndeterminateDrawable(){ Drawable ret = getIndeterminateDrawable(); if(ret == null || !(ret instanceof SmoothProgressDrawable))