Skip to content

Commit

Permalink
bugfix
Browse files Browse the repository at this point in the history
  • Loading branch information
Relex committed Jan 21, 2021
1 parent 5aeeb26 commit aa31b62
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 40 deletions.
4 changes: 2 additions & 2 deletions circleindicator/build.gradle
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
apply plugin: 'com.android.library'

version = "2.1.5"
version = "2.1.6"

android {
compileSdkVersion 29

defaultConfig {
minSdkVersion 14
targetSdkVersion 29
versionCode 215
versionCode 216
versionName version
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -210,12 +210,15 @@ public void createIndicators(int count, int currentPosition) {
for (int i = 0; i < count; i++) {
indicator = getChildAt(i);
if (currentPosition == i) {
indicator.setBackgroundResource(mIndicatorBackgroundResId);
bindIndicatorBackground(indicator, mIndicatorBackgroundResId, mIndicatorTintColor);
mImmediateAnimatorOut.setTarget(indicator);
mImmediateAnimatorOut.start();
mImmediateAnimatorOut.end();
} else {
indicator.setBackgroundResource(mIndicatorUnselectedBackgroundResId);

bindIndicatorBackground(indicator, mIndicatorUnselectedBackgroundResId,
mIndicatorTintUnselectedColor);

mImmediateAnimatorIn.setTarget(indicator);
mImmediateAnimatorIn.start();
mImmediateAnimatorIn.end();
Expand Down Expand Up @@ -262,30 +265,17 @@ public void animatePageSelected(int position) {

View currentIndicator;
if (mLastPosition >= 0 && (currentIndicator = getChildAt(mLastPosition)) != null) {
if (mIndicatorTintUnselectedColor != null) {
Drawable indicatorDrawable = DrawableCompat.wrap(
ContextCompat.getDrawable(getContext(), mIndicatorUnselectedBackgroundResId)
.mutate());
DrawableCompat.setTintList(indicatorDrawable, mIndicatorTintUnselectedColor);
ViewCompat.setBackground(currentIndicator, indicatorDrawable);
} else {
currentIndicator.setBackgroundResource(mIndicatorUnselectedBackgroundResId);
}
bindIndicatorBackground(currentIndicator, mIndicatorUnselectedBackgroundResId,
mIndicatorTintUnselectedColor);
mAnimatorIn.setTarget(currentIndicator);
mAnimatorIn.start();
}

View selectedIndicator = getChildAt(position);
if (selectedIndicator != null) {
if (mIndicatorTintColor != null) {
Drawable indicatorDrawable = DrawableCompat.wrap(
ContextCompat.getDrawable(getContext(), mIndicatorBackgroundResId)
.mutate());
DrawableCompat.setTintList(indicatorDrawable, mIndicatorTintColor);
ViewCompat.setBackground(selectedIndicator, indicatorDrawable);
} else {
selectedIndicator.setBackgroundResource(mIndicatorBackgroundResId);
}
bindIndicatorBackground(selectedIndicator, mIndicatorBackgroundResId,
mIndicatorTintColor);

mAnimatorOut.setTarget(selectedIndicator);
mAnimatorOut.start();
}
Expand All @@ -301,29 +291,27 @@ protected void changeIndicatorBackground() {
for (int i = 0; i < count; i++) {
currentIndicator = getChildAt(i);
if (i == mLastPosition) {
if (mIndicatorTintColor != null) {
Drawable indicatorDrawable = DrawableCompat.wrap(
ContextCompat.getDrawable(getContext(), mIndicatorBackgroundResId)
.mutate());
DrawableCompat.setTintList(indicatorDrawable, mIndicatorTintColor);
ViewCompat.setBackground(currentIndicator, indicatorDrawable);
} else {
currentIndicator.setBackgroundResource(mIndicatorBackgroundResId);
}
bindIndicatorBackground(currentIndicator, mIndicatorBackgroundResId,
mIndicatorTintColor);
} else {
if (mIndicatorTintUnselectedColor != null) {
Drawable indicatorDrawable = DrawableCompat.wrap(
ContextCompat.getDrawable(getContext(),
mIndicatorUnselectedBackgroundResId).mutate());
DrawableCompat.setTintList(indicatorDrawable, mIndicatorTintUnselectedColor);
ViewCompat.setBackground(currentIndicator, indicatorDrawable);
} else {
currentIndicator.setBackgroundResource(mIndicatorUnselectedBackgroundResId);
}
bindIndicatorBackground(currentIndicator, mIndicatorUnselectedBackgroundResId,
mIndicatorTintUnselectedColor);
}
}
}

private void bindIndicatorBackground(View view, @DrawableRes int drawableRes,
@Nullable ColorStateList tintColor) {
if (tintColor != null) {
Drawable indicatorDrawable = DrawableCompat.wrap(
ContextCompat.getDrawable(getContext(), drawableRes).mutate());
DrawableCompat.setTintList(indicatorDrawable, tintColor);
ViewCompat.setBackground(view, indicatorDrawable);
} else {
view.setBackgroundResource(drawableRes);
}
}

protected static class ReverseInterpolator implements Interpolator {
@Override public float getInterpolation(float value) {
return Math.abs(1.0f - value);
Expand Down

0 comments on commit aa31b62

Please sign in to comment.