Browse Source

Revert CircleIndicatorView and DashIndicatorView

zhpanvip 5 years ago
parent
commit
f38ff50808

+ 71 - 0
bannerview/src/main/java/com/zhpan/bannerview/indicator/CircleIndicatorView.java

@@ -0,0 +1,71 @@
+package com.zhpan.bannerview.indicator;
+
+import android.content.Context;
+import android.graphics.Canvas;
+import android.util.AttributeSet;
+
+import com.zhpan.indicatorview.IndicatorView;
+import com.zhpan.indicatorview.base.BaseIndicatorView;
+
+/**
+ * Created by zhpan on 2017/12/6.
+ *
+ * @deprecated Use {@link IndicatorView} instead.
+ */
+public class CircleIndicatorView extends BaseIndicatorView {
+
+    private float mNormalRadius;
+    private float mCheckedRadius;
+    private float maxRadius;
+    private int height;
+
+    public CircleIndicatorView(Context context) {
+        this(context, null);
+    }
+
+    public CircleIndicatorView(Context context, AttributeSet attrs) {
+        this(context, attrs, 0);
+    }
+
+    public CircleIndicatorView(Context context, AttributeSet attrs, int defStyleAttr) {
+        super(context, attrs, defStyleAttr);
+        mPaint.setColor(getNormalColor());
+        mNormalRadius = getNormalIndicatorWidth() / 2;
+        mCheckedRadius = getCheckedIndicatorWidth() / 2;
+        getIndicatorOptions().setIndicatorGap(mNormalRadius * 2);
+    }
+
+    @Override
+    protected void onSizeChanged(int w, int h, int oldw, int oldh) {
+        super.onSizeChanged(w, h, oldw, oldh);
+        height = getHeight();
+    }
+
+    @Override
+    protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
+        super.onMeasure(widthMeasureSpec, heightMeasureSpec);
+        mNormalRadius = getNormalIndicatorWidth() / 2;
+        mCheckedRadius = getCheckedIndicatorWidth() / 2;
+        maxRadius = Math.max(mCheckedRadius, mNormalRadius);
+        setMeasuredDimension((int) ((getPageSize() - 1) * getIndicatorGap() + 2 * (maxRadius + mNormalRadius * (getPageSize() - 1))),
+                (int) (2 * maxRadius));
+    }
+
+    @Override
+    protected void onDraw(Canvas canvas) {
+        super.onDraw(canvas);
+        if (getPageSize() > 1) {
+            for (int i = 0; i < getPageSize(); i++) {
+                mPaint.setColor(getNormalColor());
+                canvas.drawCircle(maxRadius + (2 * mNormalRadius + getIndicatorGap()) * i, height / 2f, mNormalRadius, mPaint);
+            }
+            drawSliderStyle(canvas);
+        }
+    }
+
+    private void drawSliderStyle(Canvas canvas) {
+        mPaint.setColor(getCheckedColor());
+        canvas.drawCircle(maxRadius + (2 * mNormalRadius + getIndicatorGap()) * getCurrentPosition() + (2 * mNormalRadius + getIndicatorGap()) * getSlideProgress(),
+                height / 2f, mCheckedRadius, mPaint);
+    }
+}

+ 102 - 0
bannerview/src/main/java/com/zhpan/bannerview/indicator/DashIndicatorView.java

@@ -0,0 +1,102 @@
+package com.zhpan.bannerview.indicator;
+
+import android.content.Context;
+import android.graphics.Canvas;
+import android.util.AttributeSet;
+
+import com.zhpan.indicatorview.IndicatorView;
+import com.zhpan.indicatorview.base.BaseIndicatorView;
+import com.zhpan.indicatorview.enums.IndicatorSlideMode;
+
+/**
+ * Created by zhpan on 2017/12/6.
+ *
+ * @deprecated Use {@link IndicatorView} instead.
+ */
+@Deprecated
+public class DashIndicatorView extends BaseIndicatorView {
+    private float sliderHeight;
+    private float maxWidth;
+    private float minWidth;
+
+    public DashIndicatorView(Context context) {
+        this(context, null);
+    }
+
+    public DashIndicatorView(Context context, AttributeSet attrs) {
+        this(context, attrs, 0);
+    }
+
+    public DashIndicatorView(Context context, AttributeSet attrs, int defStyleAttr) {
+        super(context, attrs, defStyleAttr);
+        mPaint.setColor(getNormalColor());
+        sliderHeight = getNormalIndicatorWidth() / 2;
+    }
+
+    @Override
+    protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
+        super.onMeasure(widthMeasureSpec, heightMeasureSpec);
+        maxWidth = Math.max(getNormalIndicatorWidth(), getCheckedIndicatorWidth());
+        minWidth = Math.min(getNormalIndicatorWidth(), getCheckedIndicatorWidth());
+        setMeasuredDimension((int) ((getPageSize() - 1) * getIndicatorGap() + maxWidth + (getPageSize() - 1) * minWidth),
+                (int) (getSliderHeight()));
+    }
+
+    @Override
+    protected void onDraw(Canvas canvas) {
+        super.onDraw(canvas);
+        if (getPageSize() > 1) {
+            for (int i = 0; i < getPageSize(); i++) {
+                if (getSlideMode() == IndicatorSlideMode.SMOOTH) {
+                    smoothSlide(canvas, i);
+                } else {
+                    normalSlide(canvas, i);
+                }
+            }
+        }
+    }
+
+
+    private void normalSlide(Canvas canvas, int i) {
+        if (getNormalIndicatorWidth() == getCheckedIndicatorWidth()) {
+            mPaint.setColor(getNormalColor());
+            float left = i * (getNormalIndicatorWidth()) + i * +getIndicatorGap();
+            canvas.drawRect(left, 0, left + getNormalIndicatorWidth(), getSliderHeight(), mPaint);
+            drawSliderStyle(canvas);
+        } else {  //  仿支付宝首页轮播图的Indicator
+            if (i < getCurrentPosition()) {
+                mPaint.setColor(getNormalColor());
+                float left = i * minWidth + i * getIndicatorGap();
+                canvas.drawRect(left, 0, left + minWidth, getSliderHeight(), mPaint);
+            } else if (i == getCurrentPosition()) {
+                mPaint.setColor(getCheckedColor());
+                float left = i * minWidth + i * getIndicatorGap();
+                canvas.drawRect(left, 0, left + minWidth + (maxWidth - minWidth), getSliderHeight(), mPaint);
+            } else {
+                mPaint.setColor(getNormalColor());
+                float left = i * minWidth + i * getIndicatorGap() + (maxWidth - minWidth);
+                canvas.drawRect(left, 0, left + minWidth, getSliderHeight(), mPaint);
+            }
+        }
+    }
+
+    private void smoothSlide(Canvas canvas, int i) {
+        mPaint.setColor(getNormalColor());
+        float left = i * (maxWidth) + i * +getIndicatorGap() + (maxWidth - minWidth);
+        canvas.drawRect(left, 0, left + minWidth, getSliderHeight(), mPaint);
+        drawSliderStyle(canvas);
+    }
+
+    private void drawSliderStyle(Canvas canvas) {
+        mPaint.setColor(getCheckedColor());
+        float left = getCurrentPosition() * (maxWidth) + getCurrentPosition() * +getIndicatorGap() + (maxWidth + getIndicatorGap()) * getSlideProgress();
+        canvas.drawRect(left, 0, left + maxWidth, getSliderHeight(), mPaint);
+    }
+
+    public float getSliderHeight() {
+        if (getIndicatorOptions().getSliderHeight() > 0) {
+            return getIndicatorOptions().getSliderHeight();
+        }
+        return sliderHeight;
+    }
+}