Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
import android.animation.ObjectAnimator;
import android.animation.ValueAnimator;
import android.content.Context;
import android.content.res.Resources;
import android.content.res.TypedArray;
import android.graphics.Paint;
import android.graphics.drawable.ClipDrawable;
Expand All @@ -14,6 +13,7 @@
import android.graphics.drawable.ShapeDrawable;
import android.support.annotation.ColorInt;
import android.support.annotation.NonNull;
import android.support.v4.content.ContextCompat;
import android.util.AttributeSet;
import android.view.Gravity;
import android.view.animation.AccelerateInterpolator;
Expand All @@ -28,7 +28,7 @@ public class MaterialProgressBar extends ProgressBar {

private Animator animator = null;

private final int duration;
private final int duration, repeatMode;

public MaterialProgressBar(Context context) {
this(context, null, -1);
Expand All @@ -49,12 +49,12 @@ public MaterialProgressBar(Context context, AttributeSet attrs, int defStyleAttr
progressColour = ta.getColor(R.styleable.MaterialProgressBar_progressColour, 0);
int defaultDuration = context.getResources().getInteger(android.R.integer.config_mediumAnimTime);
duration = ta.getInteger(R.styleable.MaterialProgressBar_duration, defaultDuration);
repeatMode = ta.getInteger(R.styleable.MaterialProgressBar_repeatMode, ValueAnimator.RESTART);
} finally {
ta.recycle();
}
Resources resources = context.getResources();
//noinspection deprecation
setProgressDrawable(resources.getDrawable(android.R.drawable.progress_horizontal));

setProgressDrawable(ContextCompat.getDrawable(context, android.R.drawable.progress_horizontal));
createIndeterminateProgressDrawable(backgroundColour, progressColour);
setMax(INDETERMINATE_MAX);
super.setIndeterminate(false);
Expand Down Expand Up @@ -115,7 +115,7 @@ private ObjectAnimator getAnimator(String propertyName, Interpolator interpolato
ObjectAnimator progressAnimator = ObjectAnimator.ofInt(this, propertyName, 0, INDETERMINATE_MAX);
progressAnimator.setInterpolator(interpolator);
progressAnimator.setDuration(duration);
progressAnimator.setRepeatMode(ValueAnimator.RESTART);
progressAnimator.setRepeatMode(repeatMode);
progressAnimator.setRepeatCount(ValueAnimator.INFINITE);
return progressAnimator;
}
Expand Down
3 changes: 2 additions & 1 deletion app/src/main/res/layout/activity_main.xml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@
android:visibility="visible"
app:duration="2000"
app:progressColour="@color/sa_accent"
app:backgroundColour="@color/sa_accent_transparent" />
app:backgroundColour="@color/sa_accent_transparent"
app:repeatMode="restart"/>

<ProgressBar
style="@style/Base.Widget.AppCompat.ProgressBar.Horizontal"
Expand Down
6 changes: 5 additions & 1 deletion app/src/main/res/values/attrs.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,12 @@
<resources>
<declare-styleable name="MaterialProgressBar">
<attr name="progressColour" format="color" />
<attr name="secondaryProgressColour" format="color" />
<!--<attr name="secondaryProgressColour" format="color" />-->
<attr name="backgroundColour" format="color" />
<attr name="duration" format="integer" />
<attr name="repeatMode" format="enum">
<enum name="restart" value="1"/>
<enum name="reverse" value="2"/>
</attr>
</declare-styleable>
</resources>