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
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
67 changes: 67 additions & 0 deletions pageindicatorview/src/main/java/com/rd/PageIndicatorView.java
Original file line number Diff line number Diff line change
Expand Up @@ -251,6 +251,44 @@ public int getPadding() {
return manager.indicator().getPadding();
}

/**
* Set padding in dp for foreground circle in indicator. Default value is {@link Indicator#DEFAULT_FOREGROUND_PADDING_DP}.
*
* @param paddingDp foreground padding in dp.
*/
public void setForegroundPadding(int paddingDp) {
if (paddingDp < 0) {
paddingDp = 0;
}

int paddingPx = DensityUtils.dpToPx(paddingDp);
manager.indicator().setForegroundPadding(paddingPx);
invalidate();
}

/**
* Set padding in dp for foreground circle in indicator. Default value is {@link Indicator#DEFAULT_FOREGROUND_PADDING_DP}.
*
* @param paddingPx foreground padding in px.
*/
public void setForegroundPadding(float paddingPx) {
if (paddingPx < 0) {
paddingPx = 0;
}

manager.indicator().setForegroundPadding((int) paddingPx);
invalidate();
}

/**
* Return padding in px for foreground circle in indicator. If custom padding is not set,
* return default value {@link Indicator#DEFAULT_FOREGROUND_PADDING_DP}.
*/
public int getForegroundPadding() {
return manager.indicator().getForegroundPadding();
}


/**
* Set scale factor used in {@link AnimationType#SCALE} animation.
* Defines size of unselected indicator circles in comparing to selected one.
Expand Down Expand Up @@ -367,6 +405,24 @@ public int getUnselectedColor() {
return manager.indicator().getUnselectedColor();
}

/**
* Set color of unselected state to indicator foreground. Default color {@link ColorAnimation#DEFAULT_FOREGROUND_UNSELECTED_COLOR}.
*
* @param color color of each unselected circle.
*/
public void setUnselectedForegroundColor(int color) {
manager.indicator().setUnselectedForegroundColor(color);
invalidate();
}

/**
* Return color of unselected state of indicator foreground. If custom unselected foreground color
* is not set, return default color {@link ColorAnimation#DEFAULT_FOREGROUND_UNSELECTED_COLOR}.
*/
public int getUnselectedForegroundColor() {
return manager.indicator().getUnselectedForegroundColor();
}

/**
* Automatically hide (View.INVISIBLE) PageIndicatorView while indicator count is <= 1.
* Default is true.
Expand All @@ -382,6 +438,17 @@ public void setAutoVisibility(boolean autoVisibility) {
updateVisibility();
}

/**
* Set customized foreground for items.
* Default is false;
*
* @param isEnabled is foreground mode enabled
*/
public void setForegroundEnable(boolean isEnabled) {
manager.indicator().setHasForeground(isEnabled);
invalidate();
}

/**
* Set orientation for indicator, one of HORIZONTAL or VERTICAL.
* Default is HORIZONTAL.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -90,11 +90,14 @@ private void animate() {
private void colorAnimation() {
int selectedColor = indicator.getSelectedColor();
int unselectedColor = indicator.getUnselectedColor();
int foregroundSelectedColor = indicator.getSelectedForegroundColor();
int foregroundUnselectedColor = indicator.getUnselectedForegroundColor();

long animationDuration = indicator.getAnimationDuration();

BaseAnimation animation = valueController
.color()
.with(unselectedColor, selectedColor)
.with(unselectedColor, selectedColor, foregroundUnselectedColor, foregroundSelectedColor)
.duration(animationDuration);

if (isInteractive) {
Expand All @@ -109,13 +112,16 @@ private void colorAnimation() {
private void scaleAnimation() {
int selectedColor = indicator.getSelectedColor();
int unselectedColor = indicator.getUnselectedColor();
int foregroundSelectedColor = indicator.getSelectedForegroundColor();
int foregroundUnselectedColor = indicator.getUnselectedForegroundColor();
int radiusPx = indicator.getRadius();
float scaleFactor = indicator.getScaleFactor();
long animationDuration = indicator.getAnimationDuration();

BaseAnimation animation = valueController
.scale()
.with(unselectedColor, selectedColor, radiusPx, scaleFactor)
.with(unselectedColor, selectedColor, foregroundUnselectedColor,
foregroundSelectedColor, radiusPx, scaleFactor)
.duration(animationDuration);

if (isInteractive) {
Expand Down Expand Up @@ -276,13 +282,16 @@ private void swapAnimation() {
private void scaleDownAnimation() {
int selectedColor = indicator.getSelectedColor();
int unselectedColor = indicator.getUnselectedColor();
int foregroundSelectedColor = indicator.getSelectedForegroundColor();
int foregroundUnselectedColor = indicator.getUnselectedForegroundColor();
int radiusPx = indicator.getRadius();
float scaleFactor = indicator.getScaleFactor();
long animationDuration = indicator.getAnimationDuration();

BaseAnimation animation = valueController
.scaleDown()
.with(unselectedColor, selectedColor, radiusPx, scaleFactor)
.with(unselectedColor, selectedColor,
foregroundUnselectedColor, foregroundSelectedColor, radiusPx, scaleFactor)
.duration(animationDuration);

if (isInteractive) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ public class ColorAnimationValue implements Value {

private int color;
private int colorReverse;
private int foregroundColor;
private int foregroundColorReverse;

public int getColor() {
return color;
Expand All @@ -22,4 +24,20 @@ public int getColorReverse() {
public void setColorReverse(int colorReverse) {
this.colorReverse = colorReverse;
}

public int getForegroundColor() {
return foregroundColor;
}

public void setForegroundColor(int foregroundColor) {
this.foregroundColor = foregroundColor;
}

public int getForegroundColorReverse() {
return foregroundColorReverse;
}

public void setForegroundColorReverse(int foregroundColorReverse) {
this.foregroundColorReverse = foregroundColorReverse;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,20 @@ public class ColorAnimation extends BaseAnimation<ValueAnimator> {

public static final String DEFAULT_UNSELECTED_COLOR = "#33ffffff";
public static final String DEFAULT_SELECTED_COLOR = "#ffffff";
public static final String DEFAULT_FOREGROUND_UNSELECTED_COLOR = "#33ffffff";
public static final String DEFAULT_FOREGROUND_SELECTED_COLOR = "#ffffff";

static final String ANIMATION_COLOR_REVERSE = "ANIMATION_COLOR_REVERSE";
static final String ANIMATION_COLOR = "ANIMATION_COLOR";
static final String ANIMATION_FOREGROUND_COLOR_REVERSE = "ANIMATION_COLOR_FOREGROUND_REVERSE";
static final String ANIMATION_FOREGROUND_COLOR = "ANIMATION_FOREGROUND_COLOR";

private ColorAnimationValue value;

int colorStart;
int colorEnd;
int foregroundColorStart;
int foregroundColorEnd;

public ColorAnimation(@Nullable ValueController.UpdateListener listener) {
super(listener);
Expand Down Expand Up @@ -57,35 +63,39 @@ public ColorAnimation progress(float progress) {
}

@NonNull
public ColorAnimation with(int colorStart, int colorEnd) {
if (animator != null && hasChanges(colorStart, colorEnd)) {
public ColorAnimation with(int colorStart, int colorEnd, int foregroundColorStart, int foregroundColorEnd) {
if (animator != null && hasChanges(colorStart, colorEnd, foregroundColorStart, foregroundColorEnd)) {

this.colorStart = colorStart;
this.colorEnd = colorEnd;
this.foregroundColorStart = foregroundColorStart;
this.foregroundColorEnd = foregroundColorEnd;

PropertyValuesHolder colorHolder = createColorPropertyHolder(false);
PropertyValuesHolder reverseColorHolder = createColorPropertyHolder(true);
PropertyValuesHolder colorHolder = createColorPropertyHolder(false, false);
PropertyValuesHolder reverseColorHolder = createColorPropertyHolder(true, false);
PropertyValuesHolder colorForegroundHolder = createColorPropertyHolder(false, true);
PropertyValuesHolder reverseForegroundColorHolder = createColorPropertyHolder(true, true);

animator.setValues(colorHolder, reverseColorHolder);
animator.setValues(colorHolder, reverseColorHolder, colorForegroundHolder, reverseForegroundColorHolder);
}

return this;
}

PropertyValuesHolder createColorPropertyHolder(boolean isReverse) {
PropertyValuesHolder createColorPropertyHolder(boolean isReverse, boolean isForeground) {
String propertyName;
int colorStart;
int colorEnd;

if (isReverse) {
propertyName = ANIMATION_COLOR_REVERSE;
colorStart = this.colorEnd;
colorEnd = this.colorStart;
propertyName = isForeground ? ANIMATION_FOREGROUND_COLOR_REVERSE : ANIMATION_COLOR_REVERSE;
colorStart = isForeground ? this.foregroundColorEnd : this.colorEnd;
colorEnd = isForeground ? this.foregroundColorStart : this.colorStart;

} else {
propertyName = ANIMATION_COLOR;
colorStart = this.colorStart;
colorEnd = this.colorEnd;
propertyName = isForeground ? ANIMATION_FOREGROUND_COLOR : ANIMATION_COLOR;
colorStart = isForeground ? this.foregroundColorStart : this.colorStart;
colorEnd = isForeground ? this.foregroundColorEnd : this.colorEnd;
}

PropertyValuesHolder holder = PropertyValuesHolder.ofInt(propertyName, colorStart, colorEnd);
Expand All @@ -95,7 +105,7 @@ PropertyValuesHolder createColorPropertyHolder(boolean isReverse) {
}

@SuppressWarnings("RedundantIfStatement")
private boolean hasChanges(int colorStart, int colorEnd) {
private boolean hasChanges(int colorStart, int colorEnd, int foregroundColorStart, int foregroundColorEnd) {
if (this.colorStart != colorStart) {
return true;
}
Expand All @@ -104,15 +114,27 @@ private boolean hasChanges(int colorStart, int colorEnd) {
return true;
}

if (this.foregroundColorStart != foregroundColorStart) {
return true;
}

if (this.foregroundColorEnd != foregroundColorEnd) {
return true;
}

return false;
}

private void onAnimateUpdated(@NonNull ValueAnimator animation) {
int color = (int) animation.getAnimatedValue(ANIMATION_COLOR);
int colorReverse = (int) animation.getAnimatedValue(ANIMATION_COLOR_REVERSE);
int foregroundColor = (int) animation.getAnimatedValue(ANIMATION_FOREGROUND_COLOR);
int foregroundColorReverse = (int) animation.getAnimatedValue(ANIMATION_FOREGROUND_COLOR_REVERSE);

value.setColor(color);
value.setColorReverse(colorReverse);
value.setForegroundColor(foregroundColor);
value.setForegroundColorReverse(foregroundColorReverse);

if (listener != null) {
listener.onValueUpdated(value);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,8 @@ public FillAnimation with(int colorStart, int colorEnd, int radius, int stroke)
this.radius = radius;
this.stroke = stroke;

PropertyValuesHolder colorHolder = createColorPropertyHolder(false);
PropertyValuesHolder reverseColorHolder = createColorPropertyHolder(true);
PropertyValuesHolder colorHolder = createColorPropertyHolder(false, false);
PropertyValuesHolder reverseColorHolder = createColorPropertyHolder(true, false);

PropertyValuesHolder radiusHolder = createRadiusPropertyHolder(false);
PropertyValuesHolder radiusReverseHolder = createRadiusPropertyHolder(true);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,22 +44,28 @@ public void onAnimationUpdate(ValueAnimator animation) {
}

@NonNull
public ScaleAnimation with(int colorStart, int colorEnd, int radius, float scaleFactor) {
if (animator != null && hasChanges(colorStart, colorEnd, radius, scaleFactor)) {
public ScaleAnimation with(int colorStart, int colorEnd,
int foregroundColorStart, int foregroundColorEnd, int radius, float scaleFactor) {
if (animator != null && hasChanges(colorStart, colorEnd, foregroundColorStart, foregroundColorEnd, radius, scaleFactor)) {

this.colorStart = colorStart;
this.colorEnd = colorEnd;
this.foregroundColorStart = foregroundColorStart;
this.foregroundColorEnd = foregroundColorEnd;

this.radius = radius;
this.scaleFactor = scaleFactor;

PropertyValuesHolder colorHolder = createColorPropertyHolder(false);
PropertyValuesHolder reverseColorHolder = createColorPropertyHolder(true);
PropertyValuesHolder colorHolder = createColorPropertyHolder(false, false);
PropertyValuesHolder reverseColorHolder = createColorPropertyHolder(true, false);
PropertyValuesHolder foregroundColorHolder = createColorPropertyHolder(false, true);
PropertyValuesHolder foregroundReverseColorHolder = createColorPropertyHolder(true, true);


PropertyValuesHolder scaleHolder = createScalePropertyHolder(false);
PropertyValuesHolder scaleReverseHolder = createScalePropertyHolder(true);

animator.setValues(colorHolder, reverseColorHolder, scaleHolder, scaleReverseHolder);
animator.setValues(colorHolder, reverseColorHolder, foregroundColorHolder, foregroundReverseColorHolder, scaleHolder, scaleReverseHolder);
}

return this;
Expand All @@ -69,12 +75,18 @@ private void onAnimateUpdated(@NonNull ValueAnimator animation) {
int color = (int) animation.getAnimatedValue(ANIMATION_COLOR);
int colorReverse = (int) animation.getAnimatedValue(ANIMATION_COLOR_REVERSE);

int foregroundColor = (int) animation.getAnimatedValue(ANIMATION_FOREGROUND_COLOR);
int foregroundColorReverse = (int) animation.getAnimatedValue(ANIMATION_FOREGROUND_COLOR_REVERSE);

int radius = (int) animation.getAnimatedValue(ANIMATION_SCALE);
int radiusReverse = (int) animation.getAnimatedValue(ANIMATION_SCALE_REVERSE);

value.setColor(color);
value.setColorReverse(colorReverse);

value.setForegroundColor(foregroundColor);
value.setForegroundColorReverse(foregroundColorReverse);

value.setRadius(radius);
value.setRadiusReverse(radiusReverse);

Expand Down Expand Up @@ -106,7 +118,7 @@ protected PropertyValuesHolder createScalePropertyHolder(boolean isReverse) {
}

@SuppressWarnings("RedundantIfStatement")
private boolean hasChanges(int colorStart, int colorEnd, int radiusValue, float scaleFactorValue) {
private boolean hasChanges(int colorStart, int colorEnd, int foregroundColorStart, int foregroundColorEnd, int radiusValue, float scaleFactorValue) {
if (this.colorStart != colorStart) {
return true;
}
Expand All @@ -115,6 +127,14 @@ private boolean hasChanges(int colorStart, int colorEnd, int radiusValue, float
return true;
}

if (this.foregroundColorStart != foregroundColorStart) {
return true;
}

if (this.foregroundColorEnd != foregroundColorEnd) {
return true;
}

if (radius != radiusValue) {
return true;
}
Expand Down
Loading