Skip to content

Commit

Permalink
[Refactor] Minor refactoring.
Browse files Browse the repository at this point in the history
  • Loading branch information
zhanghai committed Apr 11, 2017
1 parent ee3cba6 commit 8ea4a61
Showing 1 changed file with 23 additions and 38 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
import android.graphics.drawable.Drawable;
import android.graphics.drawable.LayerDrawable;
import android.os.Build;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.support.v7.widget.TintTypedArray;
import android.util.AttributeSet;
Expand Down Expand Up @@ -163,7 +162,8 @@ public synchronized void setIndeterminate(boolean indeterminate) {
super.setIndeterminate(indeterminate);

if (mSuperInitialized && !(getCurrentDrawable() instanceof MaterialProgressDrawable)) {
Log.w(TAG, "Current drawable is not a MaterialProgressDrawable, you may want to set app:mpb_setBothDrawables");
Log.w(TAG,
"Current drawable is not a MaterialProgressDrawable, you may want to set app:mpb_setBothDrawables");
}
}

Expand Down Expand Up @@ -464,13 +464,11 @@ private void applyProgressTints() {
}

private void applyPrimaryProgressTint() {
Drawable progressDrawable = getProgressDrawable();
if (progressDrawable == null) {
if (getProgressDrawable() == null) {
return;
}
if (mProgressTintInfo.mHasProgressTint || mProgressTintInfo.mHasProgressTintMode) {
Drawable target = getTintTargetFromProgressDrawable(progressDrawable,
android.R.id.progress, true);
Drawable target = getTintTargetFromProgressDrawable(android.R.id.progress, true);
if (target != null) {
applyTintForDrawable(target, mProgressTintInfo.mProgressTint,
mProgressTintInfo.mHasProgressTint, mProgressTintInfo.mProgressTintMode,
Expand All @@ -480,47 +478,29 @@ private void applyPrimaryProgressTint() {
}

private void applySecondaryProgressTint() {
Drawable progressDrawable = getProgressDrawable();
if (progressDrawable == null) {
if (getProgressDrawable() == null) {
return;
}
if (mProgressTintInfo.mHasSecondaryProgressTint
|| mProgressTintInfo.mHasSecondaryProgressTintMode) {

/*if (progressDrawable instanceof CircularProgressDrawable) {
// Don't apply to secondary progress directly in this case as
// CircularProgressDrawable needs to know about the color update
if (mProgressTintInfo.mHasSecondaryProgressTint) {
((CircularProgressDrawable) progressDrawable)
.setSecondaryProgressTintList(mProgressTintInfo.mSecondaryProgressTint);
}
if (mProgressTintInfo.mHasSecondaryProgressTintMode) {
((CircularProgressDrawable) progressDrawable)
.setSecondaryProgressTintMode(mProgressTintInfo.mSecondaryProgressTintMode);
}
} else */{
Drawable target = getTintTargetFromProgressDrawable(progressDrawable,
android.R.id.secondaryProgress, false);
if (target != null) {
applyTintForDrawable(target, mProgressTintInfo.mSecondaryProgressTint,
mProgressTintInfo.mHasSecondaryProgressTint,
mProgressTintInfo.mSecondaryProgressTintMode,
mProgressTintInfo.mHasSecondaryProgressTintMode);
}
Drawable target = getTintTargetFromProgressDrawable(android.R.id.secondaryProgress,
false);
if (target != null) {
applyTintForDrawable(target, mProgressTintInfo.mSecondaryProgressTint,
mProgressTintInfo.mHasSecondaryProgressTint,
mProgressTintInfo.mSecondaryProgressTintMode,
mProgressTintInfo.mHasSecondaryProgressTintMode);
}
}
}

private void applyProgressBackgroundTint() {
Drawable progressDrawable = getProgressDrawable();
if (progressDrawable == null) {
if (getProgressDrawable() == null) {
return;
}
if (mProgressTintInfo.mHasProgressBackgroundTint
|| mProgressTintInfo.mHasProgressBackgroundTintMode) {
Drawable target = getTintTargetFromProgressDrawable(progressDrawable,
android.R.id.background, false);
Drawable target = getTintTargetFromProgressDrawable(android.R.id.background, false);
if (target != null) {
applyTintForDrawable(target, mProgressTintInfo.mProgressBackgroundTint,
mProgressTintInfo.mHasProgressBackgroundTint,
Expand All @@ -530,8 +510,11 @@ private void applyProgressBackgroundTint() {
}
}

private Drawable getTintTargetFromProgressDrawable(
@NonNull Drawable progressDrawable, int layerId, boolean shouldFallback) {
private Drawable getTintTargetFromProgressDrawable(int layerId, boolean shouldFallback) {
Drawable progressDrawable = getProgressDrawable();
if (progressDrawable == null) {
return null;
}
progressDrawable.mutate();
Drawable layerDrawable = null;
if (progressDrawable instanceof LayerDrawable) {
Expand Down Expand Up @@ -572,7 +555,8 @@ private void applyTintForDrawable(Drawable drawable, ColorStateList tint,
//noinspection RedundantCast
((TintableDrawable) drawable).setTintList(tint);
} else {
Log.w(TAG, "Drawable did not implement TintableDrawable, it won't be tinted below Lollipop");
Log.w(TAG,
"Drawable did not implement TintableDrawable, it won't be tinted below Lollipop");
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
drawable.setTintList(tint);
}
Expand All @@ -584,7 +568,8 @@ private void applyTintForDrawable(Drawable drawable, ColorStateList tint,
//noinspection RedundantCast
((TintableDrawable) drawable).setTintMode(tintMode);
} else {
Log.w(TAG, "Drawable did not implement TintableDrawable, it won't be tinted below Lollipop");
Log.w(TAG,
"Drawable did not implement TintableDrawable, it won't be tinted below Lollipop");
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
drawable.setTintMode(tintMode);
}
Expand Down

0 comments on commit 8ea4a61

Please sign in to comment.