|
@@ -3,9 +3,7 @@ package com.zhpan.bannerview.indicator.drawer;
|
|
|
import android.graphics.Canvas;
|
|
|
|
|
|
import com.zhpan.bannerview.manager.IndicatorOptions;
|
|
|
-
|
|
|
-import static com.zhpan.bannerview.constants.IndicatorSlideMode.NORMAL;
|
|
|
-import static com.zhpan.bannerview.constants.IndicatorSlideMode.SMOOTH;
|
|
|
+import com.zhpan.bannerview.utils.BannerUtils;
|
|
|
|
|
|
/**
|
|
|
* <pre>
|
|
@@ -27,11 +25,11 @@ public class CircleDrawer extends BaseDrawer {
|
|
|
public MeasureResult onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
|
|
|
maxWidth = Math.max(mIndicatorOptions.getNormalIndicatorWidth(), mIndicatorOptions.getCheckedIndicatorWidth());
|
|
|
minWidth = Math.min(mIndicatorOptions.getNormalIndicatorWidth(), mIndicatorOptions.getCheckedIndicatorWidth());
|
|
|
- mMeasureResult.setMeasureResult(getMeasureWidth(), (int) maxWidth);
|
|
|
+ mMeasureResult.setMeasureResult(measureWidth(), (int) maxWidth);
|
|
|
return mMeasureResult;
|
|
|
}
|
|
|
|
|
|
- private int getMeasureWidth() {
|
|
|
+ private int measureWidth() {
|
|
|
int pageSize = mIndicatorOptions.getPageSize();
|
|
|
float indicatorGap = mIndicatorOptions.getIndicatorGap();
|
|
|
return (int) ((pageSize - 1) * indicatorGap + maxWidth + (pageSize - 1) * minWidth);
|
|
@@ -39,39 +37,34 @@ public class CircleDrawer extends BaseDrawer {
|
|
|
|
|
|
@Override
|
|
|
public void onDraw(Canvas canvas) {
|
|
|
- drawIndicator(canvas);
|
|
|
+ if (mIndicatorOptions.getPageSize() > 1) {
|
|
|
+ drawableNormalCircle(canvas);
|
|
|
+ drawSelectedCircle(canvas);
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
- private void drawIndicator(Canvas canvas) {
|
|
|
- if (mIndicatorOptions.getPageSize() > 1) {
|
|
|
- float normalIndicatorWidth = mIndicatorOptions.getNormalIndicatorWidth();
|
|
|
- for (int i = 0; i < mIndicatorOptions.getPageSize(); i++) {
|
|
|
- mPaint.setColor(mIndicatorOptions.getNormalColor());
|
|
|
- canvas.drawCircle(maxWidth / 2 + (normalIndicatorWidth + mIndicatorOptions.getIndicatorGap()) * i,
|
|
|
- maxWidth / 2f, normalIndicatorWidth / 2, mPaint);
|
|
|
- }
|
|
|
- drawSliderStyle(canvas);
|
|
|
+ private void drawableNormalCircle(Canvas canvas) {
|
|
|
+ float normalIndicatorWidth = mIndicatorOptions.getNormalIndicatorWidth();
|
|
|
+ mPaint.setColor(mIndicatorOptions.getNormalColor());
|
|
|
+ for (int i = 0; i < mIndicatorOptions.getPageSize(); i++) {
|
|
|
+ float coordinateX = BannerUtils.getCoordinateX(mIndicatorOptions, maxWidth, i);
|
|
|
+ float coordinateY = BannerUtils.getCoordinateY(maxWidth);
|
|
|
+ drawCircle(canvas, coordinateX, coordinateY, normalIndicatorWidth / 2);
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- private void drawSliderStyle(Canvas canvas) {
|
|
|
+ private void drawSelectedCircle(Canvas canvas) {
|
|
|
mPaint.setColor(mIndicatorOptions.getCheckedColor());
|
|
|
float normalIndicatorWidth = mIndicatorOptions.getNormalIndicatorWidth();
|
|
|
float indicatorGap = mIndicatorOptions.getIndicatorGap();
|
|
|
- switch (mIndicatorOptions.getSlideMode()) {
|
|
|
- case NORMAL:
|
|
|
- case SMOOTH:
|
|
|
- drawSmoothSlide(canvas, normalIndicatorWidth, indicatorGap);
|
|
|
- break;
|
|
|
-// case WORM:
|
|
|
-// drawWormSlider(canvas, normalIndicatorWidth, indicatorGap);
|
|
|
-// break;
|
|
|
- }
|
|
|
+ float coordinateX = maxWidth / 2 + (normalIndicatorWidth + indicatorGap) * mIndicatorOptions.getCurrentPosition()
|
|
|
+ + (normalIndicatorWidth + indicatorGap) * mIndicatorOptions.getSlideProgress();
|
|
|
+ float coordinateY = maxWidth / 2f;
|
|
|
+ float radius = mIndicatorOptions.getCheckedIndicatorWidth() / 2;
|
|
|
+ drawCircle(canvas, coordinateX, coordinateY, radius);
|
|
|
}
|
|
|
|
|
|
- private void drawSmoothSlide(Canvas canvas, float normalIndicatorWidth, float indicatorGap) {
|
|
|
- canvas.drawCircle(maxWidth / 2 + (normalIndicatorWidth + indicatorGap) * mIndicatorOptions.getCurrentPosition()
|
|
|
- + (normalIndicatorWidth + indicatorGap) * mIndicatorOptions.getSlideProgress(),
|
|
|
- maxWidth / 2f, mIndicatorOptions.getCheckedIndicatorWidth() / 2, mPaint);
|
|
|
+ private void drawCircle(Canvas canvas, float coordinateX, float coordinateY, float radius) {
|
|
|
+ canvas.drawCircle(coordinateX, coordinateY, radius, mPaint);
|
|
|
}
|
|
|
}
|