diff --git a/captures/com.rd.pageindicatorview_2018.04.24_14.06.li b/captures/com.rd.pageindicatorview_2018.04.24_14.06.li new file mode 100644 index 0000000..7172328 Binary files /dev/null and b/captures/com.rd.pageindicatorview_2018.04.24_14.06.li differ diff --git a/captures/com.rd.pageindicatorview_2018.04.24_14.17.li b/captures/com.rd.pageindicatorview_2018.04.24_14.17.li new file mode 100644 index 0000000..9201b00 Binary files /dev/null and b/captures/com.rd.pageindicatorview_2018.04.24_14.17.li differ diff --git a/captures/com.rd.pageindicatorview_2018.04.24_14.21.li b/captures/com.rd.pageindicatorview_2018.04.24_14.21.li new file mode 100644 index 0000000..700e771 Binary files /dev/null and b/captures/com.rd.pageindicatorview_2018.04.24_14.21.li differ diff --git a/captures/com.rd.pageindicatorview_2018.04.24_15.00.li b/captures/com.rd.pageindicatorview_2018.04.24_15.00.li new file mode 100644 index 0000000..121ba1e Binary files /dev/null and b/captures/com.rd.pageindicatorview_2018.04.24_15.00.li differ diff --git a/captures/com.rd.pageindicatorview_2018.04.24_15.26.li b/captures/com.rd.pageindicatorview_2018.04.24_15.26.li new file mode 100644 index 0000000..7071889 Binary files /dev/null and b/captures/com.rd.pageindicatorview_2018.04.24_15.26.li differ diff --git a/captures/com.rd.pageindicatorview_2018.04.24_15.28.li b/captures/com.rd.pageindicatorview_2018.04.24_15.28.li new file mode 100644 index 0000000..e542fe6 Binary files /dev/null and b/captures/com.rd.pageindicatorview_2018.04.24_15.28.li differ diff --git a/captures/com.rd.pageindicatorview_2018.04.24_15.32.li b/captures/com.rd.pageindicatorview_2018.04.24_15.32.li new file mode 100644 index 0000000..84b5e27 Binary files /dev/null and b/captures/com.rd.pageindicatorview_2018.04.24_15.32.li differ diff --git a/pageindicatorview/src/main/java/com/rd/PageIndicatorView.java b/pageindicatorview/src/main/java/com/rd/PageIndicatorView.java index 045a20d..6de592d 100644 --- a/pageindicatorview/src/main/java/com/rd/PageIndicatorView.java +++ b/pageindicatorview/src/main/java/com/rd/PageIndicatorView.java @@ -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. @@ -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. @@ -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. diff --git a/pageindicatorview/src/main/java/com/rd/animation/controller/AnimationController.java b/pageindicatorview/src/main/java/com/rd/animation/controller/AnimationController.java index fc5d53a..96bb103 100644 --- a/pageindicatorview/src/main/java/com/rd/animation/controller/AnimationController.java +++ b/pageindicatorview/src/main/java/com/rd/animation/controller/AnimationController.java @@ -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) { @@ -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) { @@ -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) { diff --git a/pageindicatorview/src/main/java/com/rd/animation/data/type/ColorAnimationValue.java b/pageindicatorview/src/main/java/com/rd/animation/data/type/ColorAnimationValue.java index 547e987..b953fd0 100644 --- a/pageindicatorview/src/main/java/com/rd/animation/data/type/ColorAnimationValue.java +++ b/pageindicatorview/src/main/java/com/rd/animation/data/type/ColorAnimationValue.java @@ -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; @@ -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; + } } diff --git a/pageindicatorview/src/main/java/com/rd/animation/type/ColorAnimation.java b/pageindicatorview/src/main/java/com/rd/animation/type/ColorAnimation.java index 31ec82b..be35e3c 100644 --- a/pageindicatorview/src/main/java/com/rd/animation/type/ColorAnimation.java +++ b/pageindicatorview/src/main/java/com/rd/animation/type/ColorAnimation.java @@ -13,14 +13,20 @@ public class ColorAnimation extends BaseAnimation { 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); @@ -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); @@ -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; } @@ -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); diff --git a/pageindicatorview/src/main/java/com/rd/animation/type/FillAnimation.java b/pageindicatorview/src/main/java/com/rd/animation/type/FillAnimation.java index c9aa913..2322c48 100644 --- a/pageindicatorview/src/main/java/com/rd/animation/type/FillAnimation.java +++ b/pageindicatorview/src/main/java/com/rd/animation/type/FillAnimation.java @@ -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); diff --git a/pageindicatorview/src/main/java/com/rd/animation/type/ScaleAnimation.java b/pageindicatorview/src/main/java/com/rd/animation/type/ScaleAnimation.java index 552651a..225ade6 100644 --- a/pageindicatorview/src/main/java/com/rd/animation/type/ScaleAnimation.java +++ b/pageindicatorview/src/main/java/com/rd/animation/type/ScaleAnimation.java @@ -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; @@ -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); @@ -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; } @@ -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; } diff --git a/pageindicatorview/src/main/java/com/rd/draw/controller/AttributeController.java b/pageindicatorview/src/main/java/com/rd/draw/controller/AttributeController.java index 336db6d..cae975e 100644 --- a/pageindicatorview/src/main/java/com/rd/draw/controller/AttributeController.java +++ b/pageindicatorview/src/main/java/com/rd/draw/controller/AttributeController.java @@ -7,7 +7,12 @@ import android.support.annotation.Nullable; import android.util.AttributeSet; import android.view.View; -import com.rd.animation.type.*; + +import com.rd.animation.type.AnimationType; +import com.rd.animation.type.BaseAnimation; +import com.rd.animation.type.ColorAnimation; +import com.rd.animation.type.FillAnimation; +import com.rd.animation.type.ScaleAnimation; import com.rd.draw.data.Indicator; import com.rd.draw.data.Orientation; import com.rd.draw.data.RtlMode; @@ -63,8 +68,14 @@ private void initColorAttribute(@NonNull TypedArray typedArray) { int unselectedColor = typedArray.getColor(R.styleable.PageIndicatorView_piv_unselectedColor, Color.parseColor(ColorAnimation.DEFAULT_UNSELECTED_COLOR)); int selectedColor = typedArray.getColor(R.styleable.PageIndicatorView_piv_selectedColor, Color.parseColor(ColorAnimation.DEFAULT_SELECTED_COLOR)); + int unselectedForegroundColor = typedArray.getColor(R.styleable.PageIndicatorView_piv_unselectedForegroundColor, Color.parseColor(ColorAnimation.DEFAULT_FOREGROUND_UNSELECTED_COLOR)); + int selectedForegroundColor = typedArray.getColor(R.styleable.PageIndicatorView_piv_selectedForegroundColor, Color.parseColor(ColorAnimation.DEFAULT_FOREGROUND_SELECTED_COLOR)); + indicator.setUnselectedColor(unselectedColor); indicator.setSelectedColor(selectedColor); + + indicator.setUnselectedForegroundColor(unselectedForegroundColor); + indicator.setSelectedForegroundColor(selectedForegroundColor); } private void initAnimationAttribute(@NonNull TypedArray typedArray) { @@ -106,6 +117,14 @@ private void initSizeAttribute(@NonNull TypedArray typedArray) { padding = 0; } + boolean hasForeground = (boolean) typedArray.getBoolean(R.styleable.PageIndicatorView_piv_hasForeground, false); + + int foregroundPadding = (int) typedArray.getDimension(R.styleable.PageIndicatorView_piv_foregroundPadding, DensityUtils.dpToPx(Indicator.DEFAULT_FOREGROUND_PADDING_DP)); + if (foregroundPadding < 0) { + foregroundPadding = 0; + } + + float scaleFactor = typedArray.getFloat(R.styleable.PageIndicatorView_piv_scaleFactor, ScaleAnimation.DEFAULT_SCALE_FACTOR); if (scaleFactor < ScaleAnimation.MIN_SCALE_FACTOR) { scaleFactor = ScaleAnimation.MIN_SCALE_FACTOR; @@ -128,6 +147,8 @@ private void initSizeAttribute(@NonNull TypedArray typedArray) { indicator.setPadding(padding); indicator.setScaleFactor(scaleFactor); indicator.setStroke(stroke); + indicator.setHasForeground(hasForeground); + indicator.setForegroundPadding(foregroundPadding); } private AnimationType getAnimationType(int index) { diff --git a/pageindicatorview/src/main/java/com/rd/draw/data/Indicator.java b/pageindicatorview/src/main/java/com/rd/draw/data/Indicator.java index 27686f6..9219cd3 100644 --- a/pageindicatorview/src/main/java/com/rd/draw/data/Indicator.java +++ b/pageindicatorview/src/main/java/com/rd/draw/data/Indicator.java @@ -12,6 +12,7 @@ public class Indicator { public static final int DEFAULT_RADIUS_DP = 6; public static final int DEFAULT_PADDING_DP = 8; + public static final int DEFAULT_FOREGROUND_PADDING_DP = 0; private int height; private int width; @@ -23,15 +24,20 @@ public class Indicator { private int paddingRight; private int paddingBottom; + private int foregroundPadding; private int stroke; //For "Fill" animation only private float scaleFactor; //For "Scale" animation only private int unselectedColor; private int selectedColor; + private int unselectedForegroundColor; + private int selectedForegroundColor; + private boolean interactiveAnimation; private boolean autoVisibility; private boolean dynamicCount; + private boolean hasForeground; private long animationDuration; private int count = DEFAULT_COUNT; @@ -249,4 +255,36 @@ public int getViewPagerId() { public void setViewPagerId(int viewPagerId) { this.viewPagerId = viewPagerId; } + + public boolean isHasForeground() { + return hasForeground; + } + + public void setHasForeground(boolean hasForeground) { + this.hasForeground = hasForeground; + } + + public int getUnselectedForegroundColor() { + return unselectedForegroundColor; + } + + public void setUnselectedForegroundColor(int unselectedForegroundColor) { + this.unselectedForegroundColor = unselectedForegroundColor; + } + + public int getSelectedForegroundColor() { + return selectedForegroundColor; + } + + public void setSelectedForegroundColor(int selectedForegroundColor) { + this.selectedForegroundColor = selectedForegroundColor; + } + + public int getForegroundPadding() { + return foregroundPadding; + } + + public void setForegroundPadding(int foregroundPadding) { + this.foregroundPadding = foregroundPadding; + } } diff --git a/pageindicatorview/src/main/java/com/rd/draw/drawer/Drawer.java b/pageindicatorview/src/main/java/com/rd/draw/drawer/Drawer.java index 1b27943..50f9e85 100644 --- a/pageindicatorview/src/main/java/com/rd/draw/drawer/Drawer.java +++ b/pageindicatorview/src/main/java/com/rd/draw/drawer/Drawer.java @@ -67,7 +67,7 @@ public void drawScale(@NonNull Canvas canvas, @NonNull Value value) { public void drawWorm(@NonNull Canvas canvas, @NonNull Value value) { if (wormDrawer != null) { - wormDrawer.draw(canvas, value, coordinateX, coordinateY); + wormDrawer.draw(canvas, value, coordinateX, coordinateY, position); } } diff --git a/pageindicatorview/src/main/java/com/rd/draw/drawer/type/BasicDrawer.java b/pageindicatorview/src/main/java/com/rd/draw/drawer/type/BasicDrawer.java index 77c574f..f290bd1 100644 --- a/pageindicatorview/src/main/java/com/rd/draw/drawer/type/BasicDrawer.java +++ b/pageindicatorview/src/main/java/com/rd/draw/drawer/type/BasicDrawer.java @@ -32,8 +32,13 @@ public void draw( int selectedColor = indicator.getSelectedColor(); int unselectedColor = indicator.getUnselectedColor(); + + int selectedForegroundColor = indicator.getSelectedForegroundColor(); + int unselectedForegroundColor = indicator.getUnselectedForegroundColor(); + int selectedPosition = indicator.getSelectedPosition(); AnimationType animationType = indicator.getAnimationType(); + boolean hasForeground = indicator.isHasForeground(); if (animationType == AnimationType.SCALE && !isSelectedItem) { radius *= scaleFactor; @@ -43,8 +48,10 @@ public void draw( } int color = unselectedColor; + int foregroundColor = unselectedForegroundColor; if (position == selectedPosition) { color = selectedColor; + foregroundColor = selectedForegroundColor; } Paint paint; @@ -57,5 +64,14 @@ public void draw( paint.setColor(color); canvas.drawCircle(coordinateX, coordinateY, radius, paint); + + if (hasForeground && ( + animationType == AnimationType.COLOR || + animationType == AnimationType.NONE || + animationType == AnimationType.SCALE || + animationType == AnimationType.WORM)) { + paint.setColor(foregroundColor); + canvas.drawCircle(coordinateX, coordinateY, radius - indicator.getForegroundPadding(), paint); + } } } diff --git a/pageindicatorview/src/main/java/com/rd/draw/drawer/type/ColorDrawer.java b/pageindicatorview/src/main/java/com/rd/draw/drawer/type/ColorDrawer.java index d590485..c89fa41 100644 --- a/pageindicatorview/src/main/java/com/rd/draw/drawer/type/ColorDrawer.java +++ b/pageindicatorview/src/main/java/com/rd/draw/drawer/type/ColorDrawer.java @@ -3,6 +3,7 @@ import android.graphics.Canvas; import android.graphics.Paint; import android.support.annotation.NonNull; + import com.rd.animation.data.Value; import com.rd.animation.data.type.ColorAnimationValue; import com.rd.draw.data.Indicator; @@ -14,10 +15,10 @@ public ColorDrawer(@NonNull Paint paint, @NonNull Indicator indicator) { } public void draw(@NonNull Canvas canvas, - @NonNull Value value, - int position, - int coordinateX, - int coordinateY) { + @NonNull Value value, + int position, + int coordinateX, + int coordinateY) { if (!(value instanceof ColorAnimationValue)) { return; @@ -26,6 +27,7 @@ public void draw(@NonNull Canvas canvas, ColorAnimationValue v = (ColorAnimationValue) value; float radius = indicator.getRadius(); int color = indicator.getSelectedColor(); + int foregroundColor = indicator.getSelectedForegroundColor(); int selectedPosition = indicator.getSelectedPosition(); int selectingPosition = indicator.getSelectingPosition(); @@ -34,21 +36,29 @@ public void draw(@NonNull Canvas canvas, if (indicator.isInteractiveAnimation()) { if (position == selectingPosition) { color = v.getColor(); + foregroundColor = v.getForegroundColor(); } else if (position == selectedPosition) { color = v.getColorReverse(); + foregroundColor = v.getForegroundColorReverse(); } } else { if (position == selectedPosition) { color = v.getColor(); + foregroundColor = v.getForegroundColor(); } else if (position == lastSelectedPosition) { color = v.getColorReverse(); + foregroundColor = v.getForegroundColorReverse(); } } paint.setColor(color); canvas.drawCircle(coordinateX, coordinateY, radius, paint); + if (indicator.isHasForeground()) { + paint.setColor(foregroundColor); + canvas.drawCircle(coordinateX, coordinateY, radius - indicator.getForegroundPadding(), paint); + } } } diff --git a/pageindicatorview/src/main/java/com/rd/draw/drawer/type/ScaleDrawer.java b/pageindicatorview/src/main/java/com/rd/draw/drawer/type/ScaleDrawer.java index b10d359..1f9111c 100644 --- a/pageindicatorview/src/main/java/com/rd/draw/drawer/type/ScaleDrawer.java +++ b/pageindicatorview/src/main/java/com/rd/draw/drawer/type/ScaleDrawer.java @@ -3,6 +3,7 @@ import android.graphics.Canvas; import android.graphics.Paint; import android.support.annotation.NonNull; + import com.rd.animation.data.Value; import com.rd.animation.data.type.ScaleAnimationValue; import com.rd.draw.data.Indicator; @@ -27,6 +28,7 @@ public void draw( ScaleAnimationValue v = (ScaleAnimationValue) value; float radius = indicator.getRadius(); int color = indicator.getSelectedColor(); + int foregroundColor = indicator.getSelectedForegroundColor(); int selectedPosition = indicator.getSelectedPosition(); int selectingPosition = indicator.getSelectingPosition(); @@ -36,24 +38,32 @@ public void draw( if (position == selectingPosition) { radius = v.getRadius(); color = v.getColor(); + foregroundColor = v.getForegroundColor(); } else if (position == selectedPosition) { radius = v.getRadiusReverse(); color = v.getColorReverse(); + foregroundColor = v.getForegroundColorReverse(); } } else { if (position == selectedPosition) { radius = v.getRadius(); color = v.getColor(); + foregroundColor = v.getForegroundColor(); } else if (position == lastSelectedPosition) { radius = v.getRadiusReverse(); color = v.getColorReverse(); + foregroundColor = v.getForegroundColorReverse(); } } paint.setColor(color); canvas.drawCircle(coordinateX, coordinateY, radius, paint); + if (indicator.isHasForeground()) { + paint.setColor(foregroundColor); + canvas.drawCircle(coordinateX, coordinateY, radius - indicator.getForegroundPadding(), paint); + } } } diff --git a/pageindicatorview/src/main/java/com/rd/draw/drawer/type/WormDrawer.java b/pageindicatorview/src/main/java/com/rd/draw/drawer/type/WormDrawer.java index 385c460..302c67c 100644 --- a/pageindicatorview/src/main/java/com/rd/draw/drawer/type/WormDrawer.java +++ b/pageindicatorview/src/main/java/com/rd/draw/drawer/type/WormDrawer.java @@ -22,7 +22,8 @@ public void draw( @NonNull Canvas canvas, @NonNull Value value, int coordinateX, - int coordinateY) { + int coordinateY, + int position) { if (!(value instanceof WormAnimationValue)) { return; @@ -35,24 +36,71 @@ public void draw( int radius = indicator.getRadius(); int unselectedColor = indicator.getUnselectedColor(); int selectedColor = indicator.getSelectedColor(); + int color = selectedColor; + int unselectedForegroundColor = indicator.getUnselectedForegroundColor(); + int selectedForegroundColor = indicator.getSelectedForegroundColor(); + + int selectedPosition = indicator.getSelectedPosition(); + int selectingPosition = indicator.getSelectingPosition(); + int lastSelectedPosition = indicator.getLastSelectedPosition(); + + int finalRadius; + + if (indicator.isHasForeground()) { + finalRadius = radius - indicator.getForegroundPadding(); + rectStart += indicator.getForegroundPadding(); + rectEnd -= indicator.getForegroundPadding(); + } else { + finalRadius = radius; + } if (indicator.getOrientation() == Orientation.HORIZONTAL) { rect.left = rectStart; rect.right = rectEnd; - rect.top = coordinateY - radius; - rect.bottom = coordinateY + radius; + rect.top = coordinateY - finalRadius; + rect.bottom = coordinateY + finalRadius; } else { - rect.left = coordinateX - radius; - rect.right = coordinateX + radius; + rect.left = coordinateX - finalRadius; + rect.right = coordinateX + finalRadius; rect.top = rectStart; rect.bottom = rectEnd; } - paint.setColor(unselectedColor); - canvas.drawCircle(coordinateX, coordinateY, radius, paint); + if (indicator.isInteractiveAnimation()) { + if (position == selectingPosition) { + color = indicator.getSelectedColor(); - paint.setColor(selectedColor); - canvas.drawRoundRect(rect, radius, radius, paint); + } else if (position == selectedPosition) { + color = indicator.getUnselectedColor(); + } + + } else { + if (position == selectedPosition) { + color = indicator.getSelectedColor(); + + } else if (position == lastSelectedPosition) { + color = indicator.getUnselectedColor(); + } + } + + + + if (indicator.isHasForeground()) { + paint.setColor(color); + canvas.drawCircle(coordinateX, coordinateY, radius, paint); + + paint.setColor(unselectedForegroundColor); + canvas.drawCircle(coordinateX, coordinateY, finalRadius, paint); + + paint.setColor(selectedForegroundColor); + canvas.drawRoundRect(rect, finalRadius, finalRadius, paint); + } else { + paint.setColor(unselectedColor); + canvas.drawCircle(coordinateX, coordinateY, radius, paint); + + paint.setColor(selectedColor); + canvas.drawRoundRect(rect, radius, radius, paint); + } } } diff --git a/pageindicatorview/src/main/res/values/attrs.xml b/pageindicatorview/src/main/res/values/attrs.xml index 116b7ff..9048da5 100644 --- a/pageindicatorview/src/main/res/values/attrs.xml +++ b/pageindicatorview/src/main/res/values/attrs.xml @@ -22,6 +22,12 @@ + + + + + + diff --git a/sample/src/main/java/com/rd/pageindicatorview/customize/CustomizeActivity.java b/sample/src/main/java/com/rd/pageindicatorview/customize/CustomizeActivity.java index b42288a..f6aac65 100644 --- a/sample/src/main/java/com/rd/pageindicatorview/customize/CustomizeActivity.java +++ b/sample/src/main/java/com/rd/pageindicatorview/customize/CustomizeActivity.java @@ -77,6 +77,10 @@ public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) { case R.id.switchAutoVisibility: customization.setAutoVisibility(isChecked); break; + + case R.id.switchForeground: + customization.setForeground(isChecked); + break; } } @@ -113,6 +117,10 @@ private void initViews() { switchAutoVisibility.setOnCheckedChangeListener(this); switchAutoVisibility.setChecked(customization.isAutoVisibility()); + Switch switchForeground = findViewById(R.id.switchForeground); + switchForeground.setOnCheckedChangeListener(this); + switchForeground.setChecked(customization.isForeground()); + } private void setSpinnerAdapter(@Nullable Spinner spinner, int textArrayId) { diff --git a/sample/src/main/java/com/rd/pageindicatorview/data/Customization.java b/sample/src/main/java/com/rd/pageindicatorview/data/Customization.java index eb5c41a..3be3706 100644 --- a/sample/src/main/java/com/rd/pageindicatorview/data/Customization.java +++ b/sample/src/main/java/com/rd/pageindicatorview/data/Customization.java @@ -14,6 +14,7 @@ public class Customization implements Parcelable { private boolean interactiveAnimation = false; private boolean autoVisibility = true; + private boolean foreground = false; public AnimationType getAnimationType() { return animationType; @@ -64,6 +65,7 @@ public boolean equals(Object o) { if (interactiveAnimation != that.interactiveAnimation) return false; if (autoVisibility != that.autoVisibility) return false; + if (foreground != that.foreground) return false; if (animationType != that.animationType) return false; if (orientation != that.orientation) return false; return rtlMode == that.rtlMode; @@ -77,6 +79,7 @@ public int hashCode() { result = 31 * result + (rtlMode != null ? rtlMode.hashCode() : 0); result = 31 * result + (interactiveAnimation ? 1 : 0); result = 31 * result + (autoVisibility ? 1 : 0); + result = 31 * result + (foreground ? 1 : 0); return result; } @@ -92,6 +95,7 @@ public void writeToParcel(Parcel dest, int flags) { dest.writeInt(this.rtlMode == null ? -1 : this.rtlMode.ordinal()); dest.writeByte(this.interactiveAnimation ? (byte) 1 : (byte) 0); dest.writeByte(this.autoVisibility ? (byte) 1 : (byte) 0); + dest.writeByte(this.foreground ? (byte) 1 : (byte) 0); } public Customization() { @@ -106,6 +110,7 @@ protected Customization(Parcel in) { this.rtlMode = tmpRtlMode == -1 ? null : RtlMode.values()[tmpRtlMode]; this.interactiveAnimation = in.readByte() != 0; this.autoVisibility = in.readByte() != 0; + this.foreground = in.readByte() != 0; } public static final Parcelable.Creator CREATOR = new Parcelable.Creator() { @@ -119,4 +124,12 @@ public Customization[] newArray(int size) { return new Customization[size]; } }; + + public boolean isForeground() { + return foreground; + } + + public void setForeground(boolean foreground) { + this.foreground = foreground; + } } diff --git a/sample/src/main/java/com/rd/pageindicatorview/home/HomeActivity.java b/sample/src/main/java/com/rd/pageindicatorview/home/HomeActivity.java index edd9596..499efb3 100644 --- a/sample/src/main/java/com/rd/pageindicatorview/home/HomeActivity.java +++ b/sample/src/main/java/com/rd/pageindicatorview/home/HomeActivity.java @@ -7,6 +7,8 @@ import android.view.Menu; import android.view.MenuItem; import android.view.View; +import android.widget.Toolbar; + import com.rd.PageIndicatorView; import com.rd.pageindicatorview.base.BaseActivity; import com.rd.pageindicatorview.customize.CustomizeActivity; @@ -37,6 +39,7 @@ protected void onActivityResult(int requestCode, int resultCode, Intent intent) boolean customization = requestCode == CustomizeActivity.EXTRAS_CUSTOMIZATION_REQUEST_CODE && resultCode == RESULT_OK; if (customization && intent != null) { this.customization = intent.getParcelableExtra(CustomizeActivity.EXTRAS_CUSTOMIZATION); + ((android.support.v7.widget.Toolbar)findViewById(R.id.toolbar)).setTitle(this.customization.getAnimationType().toString()); updateIndicator(); } } @@ -100,5 +103,7 @@ private void updateIndicator() { pageIndicatorView.setRtlMode(customization.getRtlMode()); pageIndicatorView.setInteractiveAnimation(customization.isInteractiveAnimation()); pageIndicatorView.setAutoVisibility(customization.isAutoVisibility()); + pageIndicatorView.setForegroundEnable(customization.isForeground()); + } } diff --git a/sample/src/main/res/layout/ac_customize.xml b/sample/src/main/res/layout/ac_customize.xml index ad8394e..e6d38eb 100644 --- a/sample/src/main/res/layout/ac_customize.xml +++ b/sample/src/main/res/layout/ac_customize.xml @@ -133,6 +133,21 @@ android:text="@string/auto_visibility" android:textColor="@color/gray_700" android:textSize="16sp" /> + + + + \ No newline at end of file diff --git a/sample/src/main/res/layout/ac_home.xml b/sample/src/main/res/layout/ac_home.xml index 912a71a..6876dd9 100644 --- a/sample/src/main/res/layout/ac_home.xml +++ b/sample/src/main/res/layout/ac_home.xml @@ -30,6 +30,10 @@ android:layout_alignParentBottom="true" android:layout_centerHorizontal="true" android:layout_marginBottom="48dp" + attrs:piv_hasForeground="false" + attrs:piv_foregroundPadding="2dp" + attrs:piv_selectedForegroundColor="#a92216" + attrs:piv_unselectedForegroundColor="#14d48d" attrs:piv_padding="12dp" attrs:piv_radius="8dp" /> diff --git a/sample/src/main/res/values/strings.xml b/sample/src/main/res/values/strings.xml index 374d77c..358386d 100644 --- a/sample/src/main/res/values/strings.xml +++ b/sample/src/main/res/values/strings.xml @@ -7,6 +7,7 @@ Customize Home Right to left mode + Foreground None