use of com.rey.material.drawable.CircularProgressDrawable in project material by rey5137.
the class ProgressView method applyStyle.
protected void applyStyle(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) {
TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.ProgressView, defStyleAttr, defStyleRes);
int progressId = 0;
int progressMode = -1;
float progress = -1;
float secondaryProgress = -1;
for (int i = 0, count = a.getIndexCount(); i < count; i++) {
int attr = a.getIndex(i);
if (attr == R.styleable.ProgressView_pv_autostart)
mAutostart = a.getBoolean(attr, false);
else if (attr == R.styleable.ProgressView_pv_circular)
mCircular = a.getBoolean(attr, true);
else if (attr == R.styleable.ProgressView_pv_progressStyle)
progressId = a.getResourceId(attr, 0);
else if (attr == R.styleable.ProgressView_pv_progressMode)
progressMode = a.getInteger(attr, 0);
else if (attr == R.styleable.ProgressView_pv_progress)
progress = a.getFloat(attr, 0);
else if (attr == R.styleable.ProgressView_pv_secondaryProgress)
secondaryProgress = a.getFloat(attr, 0);
}
a.recycle();
boolean needStart = false;
if (needCreateProgress(mCircular)) {
mProgressId = progressId;
if (mProgressId == 0)
mProgressId = mCircular ? R.style.Material_Drawable_CircularProgress : R.style.Material_Drawable_LinearProgress;
needStart = mProgressDrawable != null && ((Animatable) mProgressDrawable).isRunning();
mProgressDrawable = mCircular ? new CircularProgressDrawable.Builder(context, mProgressId).build() : new LinearProgressDrawable.Builder(context, mProgressId).build();
ViewUtil.setBackground(this, mProgressDrawable);
} else if (mProgressId != progressId) {
mProgressId = progressId;
if (mProgressDrawable instanceof CircularProgressDrawable)
((CircularProgressDrawable) mProgressDrawable).applyStyle(context, mProgressId);
else
((LinearProgressDrawable) mProgressDrawable).applyStyle(context, mProgressId);
}
if (progressMode >= 0) {
if (mProgressDrawable instanceof CircularProgressDrawable)
((CircularProgressDrawable) mProgressDrawable).setProgressMode(progressMode);
else
((LinearProgressDrawable) mProgressDrawable).setProgressMode(progressMode);
}
if (progress >= 0)
setProgress(progress);
if (secondaryProgress >= 0)
setSecondaryProgress(secondaryProgress);
if (needStart)
start();
}
Aggregations