|
|
@@ -7,8 +7,13 @@ import android.graphics.Paint;
|
|
|
import android.support.annotation.Nullable;
|
|
|
import android.support.v7.widget.RecyclerView;
|
|
|
import android.util.AttributeSet;
|
|
|
+import android.util.Log;
|
|
|
+import android.view.MotionEvent;
|
|
|
import android.view.View;
|
|
|
|
|
|
+import kr.co.zumo.app.lifeplus.view.Event;
|
|
|
+import kr.co.zumo.app.lifeplus.view.IEventListener;
|
|
|
+
|
|
|
/**
|
|
|
* CustomIndicator
|
|
|
* <pre>
|
|
|
@@ -41,18 +46,24 @@ public class CustomIndicator extends View {
|
|
|
private int activeColor;
|
|
|
private int inActiveColor;
|
|
|
private int activePosition;
|
|
|
+ private float totalLength;
|
|
|
+ private float indicatorTotalWidth;
|
|
|
+ private float indicatorStartX;
|
|
|
+ private int itemCount;
|
|
|
|
|
|
private static final float DP = Resources.getSystem().getDisplayMetrics().density;
|
|
|
private final int mIndicatorHeight = (int) (DP * 16);
|
|
|
- private final float mIndicatorStrokeWidth = DP * 2;
|
|
|
+ private final float mIndicatorStrokeWidth = DP * 10;
|
|
|
private final float mIndicatorItemLength = DP * 4;
|
|
|
private final float mIndicatorItemPadding = DP * 8;
|
|
|
private final Paint mPaint = new Paint();
|
|
|
+ private IEventListener listener;
|
|
|
|
|
|
- public void setIndicatorSetting(RecyclerView recyclerview, int inActiveColor, int activeColor) {
|
|
|
+ public void setIndicatorSetting(RecyclerView recyclerview, int inActiveColor, int activeColor, IEventListener listener) {
|
|
|
this.recyclerView = recyclerview;
|
|
|
this.inActiveColor = inActiveColor;
|
|
|
this.activeColor = activeColor;
|
|
|
+ this.listener = listener;
|
|
|
mPaint.setStrokeCap(Paint.Cap.ROUND);
|
|
|
mPaint.setStrokeWidth(mIndicatorStrokeWidth);
|
|
|
mPaint.setStyle(Paint.Style.FILL);
|
|
|
@@ -70,16 +81,14 @@ public class CustomIndicator extends View {
|
|
|
return;
|
|
|
}
|
|
|
|
|
|
- int itemCount = recyclerView.getAdapter().getItemCount();
|
|
|
- float totalLength = mIndicatorItemLength * itemCount;
|
|
|
+ itemCount = recyclerView.getAdapter().getItemCount();
|
|
|
+ totalLength = mIndicatorItemLength * itemCount;
|
|
|
float paddingBetweenItems = Math.max(0, itemCount - 1) * mIndicatorItemPadding;
|
|
|
- float indicatorTotalWidth = totalLength + paddingBetweenItems;
|
|
|
- float indicatorStartX = (recyclerView.getWidth() - indicatorTotalWidth) / 2F;
|
|
|
- //float indicatorPosY = getHeight() - 38F * DP;
|
|
|
+ indicatorTotalWidth = totalLength + paddingBetweenItems; //인디케이터 width
|
|
|
+ indicatorStartX = (recyclerView.getWidth() - indicatorTotalWidth) / 2F; //중앙
|
|
|
float indicatorPosY = getHeight() - mIndicatorHeight / 2F;
|
|
|
|
|
|
|
|
|
-
|
|
|
drawInactiveIndicators(canvas, indicatorStartX, indicatorPosY, itemCount);
|
|
|
if (activePosition == RecyclerView.NO_POSITION) {
|
|
|
return;
|
|
|
@@ -89,7 +98,7 @@ public class CustomIndicator extends View {
|
|
|
|
|
|
private void drawInactiveIndicators(Canvas c, float indicatorStartX, float indicatorPosY, int itemCount) {
|
|
|
mPaint.setColor(context.getResources().getColor(inActiveColor));
|
|
|
- final float itemWidth = mIndicatorItemLength + mIndicatorItemPadding;
|
|
|
+ float itemWidth = mIndicatorItemLength + mIndicatorItemPadding; //한칸
|
|
|
|
|
|
float start = indicatorStartX;
|
|
|
for (int i = 0; i < itemCount; i++) {
|
|
|
@@ -116,4 +125,22 @@ public class CustomIndicator extends View {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+ @Override
|
|
|
+ public boolean onTouchEvent(MotionEvent event) {
|
|
|
+ Log.e("APP# CustomIndicator | onTouchEvent", "|" + "==== > ");
|
|
|
+ if ((event.getAction() & MotionEvent.ACTION_MASK) == MotionEvent.ACTION_DOWN) {
|
|
|
+ return true;
|
|
|
+ }
|
|
|
+ else if ((event.getAction() & MotionEvent.ACTION_MASK) == MotionEvent.ACTION_UP) {
|
|
|
+ float itemWidth = mIndicatorItemLength + mIndicatorItemPadding;
|
|
|
+ int index = (int) Math.floor((event.getX() - indicatorStartX) / itemWidth); //인디케이터 안에서 찍힌 x 좌표
|
|
|
+ Log.e("APP# CustomIndicator | onTouchEvent", "index |" + index);
|
|
|
+ if (index >= 0 && index < itemCount) {
|
|
|
+ listener.onEvent(new Event.Builder(Event.CLICK).index((int) index).build());
|
|
|
+ }
|
|
|
+ //return true;
|
|
|
+ }
|
|
|
+
|
|
|
+ return super.onTouchEvent(event);
|
|
|
+ }
|
|
|
}
|