Skip to content

Commit

Permalink
optimize progress tint
Browse files Browse the repository at this point in the history
  • Loading branch information
xyczero committed Nov 6, 2017
1 parent 0d25534 commit 4d4ae58
Showing 1 changed file with 10 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,17 +16,13 @@

package com.bilibili.magicasakura.widgets;

import android.content.res.ColorStateList;
import android.content.res.TypedArray;
import android.graphics.drawable.Drawable;
import android.graphics.drawable.LayerDrawable;
import android.support.annotation.Nullable;
import android.util.AttributeSet;
import android.view.View;
import android.widget.ProgressBar;

import com.bilibili.magicasakura.R;
import com.bilibili.magicasakura.utils.ThemeUtils;
import com.bilibili.magicasakura.utils.TintInfo;
import com.bilibili.magicasakura.utils.TintManager;

Expand All @@ -51,34 +47,32 @@ public AppCompatProgressBarHelper(TintProgressBar view, TintManager tintManager)
void loadFromAttribute(AttributeSet attrs, int defStyleAttr) {
TypedArray array = mView.getContext().obtainStyledAttributes(attrs, R.styleable.TintProgressBarHelper, defStyleAttr, 0);
if (array.hasValue(R.styleable.TintProgressBarHelper_progressTint)) {
mProgressTintResId = array.getResourceId(R.styleable.TintProgressBarHelper_progressTint, 0);
setSupportProgressTint(array.getColorStateList(R.styleable.TintProgressBarHelper_progressTint));
setSupportProgressTint(mProgressTintResId = array.getResourceId(R.styleable.TintProgressBarHelper_progressTint, 0));
}
if (array.hasValue(R.styleable.TintProgressBarHelper_progressIndeterminateTint)) {
mIndeterminateTintResId = array.getResourceId(R.styleable.TintProgressBarHelper_progressIndeterminateTint, 0);
setSupportIndeterminateTint(array.getColorStateList(R.styleable.TintProgressBarHelper_progressIndeterminateTint));
setSupportIndeterminateTint(mIndeterminateTintResId = array.getResourceId(R.styleable.TintProgressBarHelper_progressIndeterminateTint, 0));
}
array.recycle();
}

private void setSupportProgressTint(ColorStateList tint) {
if (tint != null) {
private void setSupportProgressTint(int resId) {
if (resId != 0) {
if (mProgressTintInfo == null) {
mProgressTintInfo = new TintInfo();
}
mProgressTintInfo.mHasTintList = true;
mProgressTintInfo.mTintList = ColorStateList.valueOf(ThemeUtils.getColor(mView.getContext(), tint.getDefaultColor()));
mProgressTintInfo.mTintList = mTintManager.getColorStateList(resId);
}
applySupportProgressTint();
}

private void setSupportIndeterminateTint(ColorStateList tint) {
if (tint != null) {
private void setSupportIndeterminateTint(int resId) {
if (resId != 0) {
if (mIndeterminateTintInfo == null) {
mIndeterminateTintInfo = new TintInfo();
}
mIndeterminateTintInfo.mHasTintList = true;
mIndeterminateTintInfo.mTintList = ColorStateList.valueOf(ThemeUtils.getColor(mView.getContext(), tint.getDefaultColor()));
mIndeterminateTintInfo.mTintList = mTintManager.getColorStateList(resId);
}
applySupportIndeterminateTint();
}
Expand Down Expand Up @@ -137,10 +131,10 @@ private Drawable getTintTarget(int layerId, boolean shouldFallback) {
@Override
public void tint() {
if (mProgressTintResId != 0) {
setSupportProgressTint(mView.getResources().getColorStateList(mProgressTintResId));
setSupportProgressTint(mProgressTintResId);
}
if (mIndeterminateTintResId != 0) {
setSupportIndeterminateTint(mView.getResources().getColorStateList(mIndeterminateTintResId));
setSupportIndeterminateTint(mIndeterminateTintResId);
}
}
}

0 comments on commit 4d4ae58

Please sign in to comment.