You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@weex.apache.org by mi...@apache.org on 2017/09/21 06:23:15 UTC
[2/5] incubator-weex git commit: * [android] fix wrong draw indicator
* [android] fix wrong draw indicator
Project: http://git-wip-us.apache.org/repos/asf/incubator-weex/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-weex/commit/5123304c
Tree: http://git-wip-us.apache.org/repos/asf/incubator-weex/tree/5123304c
Diff: http://git-wip-us.apache.org/repos/asf/incubator-weex/diff/5123304c
Branch: refs/heads/0.16-dev
Commit: 5123304c7eb885953e189ebf29b63e4836059286
Parents: e52d273
Author: misakuo <mi...@apache.org>
Authored: Wed Sep 20 14:12:30 2017 +0800
Committer: misakuo <mi...@apache.org>
Committed: Wed Sep 20 14:12:30 2017 +0800
----------------------------------------------------------------------
.../weex/ui/view/WXBaseCircleIndicator.java | 131 +++----------------
1 file changed, 19 insertions(+), 112 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-weex/blob/5123304c/android/sdk/src/main/java/com/taobao/weex/ui/view/WXBaseCircleIndicator.java
----------------------------------------------------------------------
diff --git a/android/sdk/src/main/java/com/taobao/weex/ui/view/WXBaseCircleIndicator.java b/android/sdk/src/main/java/com/taobao/weex/ui/view/WXBaseCircleIndicator.java
index 1fdba29..604561c 100644
--- a/android/sdk/src/main/java/com/taobao/weex/ui/view/WXBaseCircleIndicator.java
+++ b/android/sdk/src/main/java/com/taobao/weex/ui/view/WXBaseCircleIndicator.java
@@ -37,7 +37,6 @@ import com.taobao.weex.utils.WXViewUtils;
public class WXBaseCircleIndicator extends FrameLayout implements OnPageChangeListener, WXGestureObservable {
private final Paint mPaintPage = new Paint();
- private final Paint mPaintStroke = new Paint();
private final Paint mPaintFill = new Paint();
private WXGesture wxGesture;
private WXCircleViewPager mCircleViewPager;
@@ -53,38 +52,24 @@ public class WXBaseCircleIndicator extends FrameLayout implements OnPageChangeLi
/**
* Fill color of unselected circle
*/
- private int pageColor;
+ private int pageColor = Color.BLUE;
/**
* Fill color of the selected circle
*/
- private int fillColor;
+ private int fillColor = Color.BLACK;
private int realCurrentItem;
- private OnPageChangeListener mListener;
public WXBaseCircleIndicator(Context context) {
super(context);
- getAttrs(context);
init();
}
- /**
- * Get attribute of xml
- */
- private void getAttrs(Context context) {
+ private void init() {
radius = WXViewUtils.dip2px(5);
circlePadding = WXViewUtils.dip2px(5);
- pageColor = Color.parseColor("#ffffff");
- // strokeWidth= WAViewUtils.dip2px((float)1.5);
- // strokeColor = Color.parseColor("#FFDDDDDD");
- fillColor = Color.parseColor("#ffd545");
- }
-
- private void init() {
- mPaintStroke.setAntiAlias(true);
- mPaintStroke.setStyle(Style.STROKE);
- // mPaintStroke.setColor(strokeColor);
- // mPaintStroke.setStrokeWidth(strokeWidth);
+ pageColor = Color.LTGRAY;
+ fillColor = Color.DKGRAY;
mPaintFill.setStyle(Style.FILL);
mPaintFill.setAntiAlias(true);
@@ -102,21 +87,9 @@ public class WXBaseCircleIndicator extends FrameLayout implements OnPageChangeLi
*/
public WXBaseCircleIndicator(Context context, AttributeSet attrs) {
super(context, attrs);
- getAttrs(context);
init();
}
- public void setOnPageChangeListener(OnPageChangeListener listener) {
- mListener = listener;
- }
-
- /**
- * @return the mCircleViewPager
- */
- public WXCircleViewPager getCircleViewPager() {
- return mCircleViewPager;
- }
-
/**
* @param mCircleViewPager the mCircleViewPager to set
*/
@@ -125,38 +98,27 @@ public class WXBaseCircleIndicator extends FrameLayout implements OnPageChangeLi
if (this.mCircleViewPager != null) {
this.mCircleViewPager.addOnPageChangeListener(this);
this.realCurrentItem = mCircleViewPager.getRealCurrentItem();
+ if (realCurrentItem < 0) {
+ realCurrentItem = 0;
+ }
}
requestLayout();
}
@Override
public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) {
- if (mListener != null) {
- mListener.onPageScrolled(position, positionOffset, positionOffsetPixels);
- }
+
}
@Override
public void onPageSelected(int position) {
realCurrentItem = mCircleViewPager.getRealCurrentItem();
invalidate();
- if (mListener != null) {
- mListener.onPageSelected(position);
- }
}
@Override
public void onPageScrollStateChanged(int state) {
- if (mListener != null) {
- mListener.onPageScrollStateChanged(state);
- }
- }
- /**
- * @return the radius
- */
- public float getRadius() {
- return radius;
}
/**
@@ -167,27 +129,6 @@ public class WXBaseCircleIndicator extends FrameLayout implements OnPageChangeLi
}
/**
- * @return the circlePadding
- */
- public float getCirclePadding() {
- return circlePadding;
- }
-
- /**
- * @param circlePadding the circlePadding to set
- */
- public void setCirclePadding(float circlePadding) {
- this.circlePadding = circlePadding;
- }
-
- /**
- * @return the fillColor
- */
- public int getFillColor() {
- return fillColor;
- }
-
- /**
* @param fillColor the fillColor to set
*/
public void setFillColor(int fillColor) {
@@ -212,36 +153,9 @@ public class WXBaseCircleIndicator extends FrameLayout implements OnPageChangeLi
*/
public void setRealCurrentItem(int realCurrentItem) {
this.realCurrentItem = realCurrentItem;
+ invalidate();
}
- // /**
- // * @return the strokeColor
- // */
- // public int getStrokeColor() {
- // return strokeColor;
- // }
- //
- // /**
- // * @param strokeColor the strokeColor to set
- // */
- // public void setStrokeColor(int strokeColor) {
- // this.strokeColor = strokeColor;
- // }
- //
- // /**
- // * @return the strokeWidth
- // */
- // public float getStrokeWidth() {
- // return strokeWidth;
- // }
- //
- // /**
- // * @param strokeWidth the strokeWidth to set
- // */
- // public void setStrokeWidth(float strokeWidth) {
- // this.strokeWidth = strokeWidth;
- // }
-
@Override
public void registerGestureListener(WXGesture wxGesture) {
this.wxGesture = wxGesture;
@@ -258,29 +172,22 @@ public class WXBaseCircleIndicator extends FrameLayout implements OnPageChangeLi
@Override
protected void onDraw(Canvas canvas) {
- // TODO Auto-generated method stub
super.onDraw(canvas);
- float firstX = getWidth() / 2 + getPaddingLeft() - getCount() / 2.0f * (radius + circlePadding);// + radius;
- float firstY = getHeight() / 2 + getPaddingTop();// + radius;
+ float dotWidth = (circlePadding + radius) * 2;
- //draw stroked circles
- for (int i = 0; i < getCount(); i++) {
- float dx = firstX + circlePadding * i + radius * 2 * i;
- float dy = firstY;
- if (mPaintStroke.getStrokeWidth() > 0) {
- canvas.drawCircle(dx, dy, radius, mPaintStroke);
- }
+ float firstCenterX = getWidth() / 2 - (dotWidth * (getCount() - 1) / 2);
+ float firstCenterY = getHeight() / 2 + getPaddingTop();
- if (mPaintPage.getAlpha() > 0) {
+ for (int i = 0; i < getCount(); i++) {
+ float dx = firstCenterX + dotWidth * i;
+ float dy = firstCenterY;
+ if (i != realCurrentItem) {
canvas.drawCircle(dx, dy, radius, mPaintPage);
+ } else {
+ canvas.drawCircle(dx, dy, radius, mPaintFill);
}
}
-
- //Draw the filled circle
- float dx = firstX + realCurrentItem * circlePadding + radius * 2 * realCurrentItem;
- float dy = firstY;
- canvas.drawCircle(dx, dy, radius, mPaintFill);
}
@Override