|
|
@@ -5,13 +5,11 @@ import android.content.res.Resources;
|
|
|
import android.graphics.Canvas;
|
|
|
import android.graphics.Paint;
|
|
|
import android.support.annotation.Nullable;
|
|
|
-import android.support.v7.widget.LinearLayoutManager;
|
|
|
import android.support.v7.widget.RecyclerView;
|
|
|
import android.util.AttributeSet;
|
|
|
+import android.util.Log;
|
|
|
import android.view.View;
|
|
|
|
|
|
-import kr.co.zumo.app.lifeplus.view.IndexScrollListener;
|
|
|
-
|
|
|
/**
|
|
|
* CustomIndicator
|
|
|
* <pre>
|
|
|
@@ -26,106 +24,79 @@ public class CustomIndicator extends View {
|
|
|
|
|
|
public CustomIndicator(Context context) {
|
|
|
super(context);
|
|
|
+ this.context = context;
|
|
|
}
|
|
|
|
|
|
public CustomIndicator(Context context, @Nullable AttributeSet attrs) {
|
|
|
super(context, attrs);
|
|
|
+ this.context = context;
|
|
|
}
|
|
|
|
|
|
public CustomIndicator(Context context, @Nullable AttributeSet attrs, int defStyleAttr) {
|
|
|
super(context, attrs, defStyleAttr);
|
|
|
+ this.context = context;
|
|
|
}
|
|
|
|
|
|
private Context context;
|
|
|
+ private RecyclerView recyclerView;
|
|
|
private int activeColor;
|
|
|
private int inActiveColor;
|
|
|
private int bottomOffset;
|
|
|
+ private int activePosition;
|
|
|
|
|
|
private static final float DP = Resources.getSystem().getDisplayMetrics().density;
|
|
|
-
|
|
|
- /**
|
|
|
- * Height of the space the indicator takes up at the bottom of the view.
|
|
|
- */
|
|
|
private final int mIndicatorHeight = (int) (DP * 16);
|
|
|
-
|
|
|
- /**
|
|
|
- * Indicator stroke width.
|
|
|
- */
|
|
|
private final float mIndicatorStrokeWidth = DP * 2;
|
|
|
-
|
|
|
- /**
|
|
|
- * Indicator width.
|
|
|
- */
|
|
|
private final float mIndicatorItemLength = DP * 4;
|
|
|
- /**
|
|
|
- * Padding between indicators.
|
|
|
- */
|
|
|
private final float mIndicatorItemPadding = DP * 8;
|
|
|
-
|
|
|
-
|
|
|
- /**
|
|
|
- * Some more natural animation interpolation
|
|
|
- */
|
|
|
-
|
|
|
private final Paint mPaint = new Paint();
|
|
|
|
|
|
- private int itemCount = -1;
|
|
|
-
|
|
|
- private int index = -1;
|
|
|
-
|
|
|
- private IndexScrollListener indexScrollListener;
|
|
|
-
|
|
|
- public void onChangedIndex(int itemCount, int index) {
|
|
|
- if (this.itemCount != itemCount || this.index != index) {
|
|
|
- this.itemCount = itemCount;
|
|
|
- this.index = index;
|
|
|
-
|
|
|
- invalidate();
|
|
|
- }
|
|
|
+ public void setIndicatorSetting(RecyclerView recyclerview, int inActiveColor, int activeColor, int bottomOffset) {
|
|
|
+ this.recyclerView = recyclerview;
|
|
|
+ this.inActiveColor = inActiveColor;
|
|
|
+ this.activeColor = activeColor;
|
|
|
+ this.bottomOffset = bottomOffset;
|
|
|
+ mPaint.setStrokeCap(Paint.Cap.ROUND);
|
|
|
+ mPaint.setStrokeWidth(mIndicatorStrokeWidth);
|
|
|
+ mPaint.setStyle(Paint.Style.FILL);
|
|
|
}
|
|
|
|
|
|
- public void onDrawOver(Canvas canvas, RecyclerView parent, RecyclerView.State state) {
|
|
|
+ public void onChangedIndex(int firstVisibleItemPosition) {
|
|
|
+ this.activePosition = firstVisibleItemPosition;
|
|
|
+ invalidate();
|
|
|
+ }
|
|
|
|
|
|
- if (null == parent || null == parent.getAdapter()) {
|
|
|
+ @Override
|
|
|
+ protected void onDraw(Canvas canvas) {
|
|
|
+ if (null == recyclerView || null == recyclerView.getAdapter()) {
|
|
|
return;
|
|
|
}
|
|
|
-
|
|
|
- int itemCount = parent.getAdapter().getItemCount();
|
|
|
-
|
|
|
+ int itemCount = recyclerView.getAdapter().getItemCount();
|
|
|
float totalLength = mIndicatorItemLength * itemCount;
|
|
|
float paddingBetweenItems = Math.max(0, itemCount - 1) * mIndicatorItemPadding;
|
|
|
float indicatorTotalWidth = totalLength + paddingBetweenItems;
|
|
|
- float indicatorStartX = (parent.getWidth() - indicatorTotalWidth) / 2F;
|
|
|
- float indicatorPosY = parent.getHeight() - mIndicatorHeight / 2F;
|
|
|
+ float indicatorStartX = (recyclerView.getWidth() - indicatorTotalWidth) / 2F;
|
|
|
+ float indicatorPosY = getHeight() - 38F * DP;
|
|
|
|
|
|
drawInactiveIndicators(canvas, indicatorStartX, indicatorPosY, itemCount);
|
|
|
-
|
|
|
- // find active page (which should be highlighted)
|
|
|
- LinearLayoutManager layoutManager = (LinearLayoutManager) parent.getLayoutManager();
|
|
|
- int activePosition = IndexScrollListener.getCurrentIndex(layoutManager);
|
|
|
-// Log.e("APP# MainBannerViewItemDotIndicator | onDrawOver", "| activePosition: " + activePosition);
|
|
|
-
|
|
|
if (activePosition == RecyclerView.NO_POSITION) {
|
|
|
return;
|
|
|
}
|
|
|
-
|
|
|
drawHighlights(canvas, indicatorStartX, indicatorPosY, activePosition, itemCount);
|
|
|
-
|
|
|
}
|
|
|
|
|
|
private void drawInactiveIndicators(Canvas c, float indicatorStartX, float indicatorPosY, int itemCount) {
|
|
|
mPaint.setColor(context.getResources().getColor(inActiveColor));
|
|
|
-
|
|
|
- // width of item indicator including padding
|
|
|
final float itemWidth = mIndicatorItemLength + mIndicatorItemPadding;
|
|
|
|
|
|
float start = indicatorStartX;
|
|
|
for (int i = 0; i < itemCount; i++) {
|
|
|
// itemCount 1은 안띄움
|
|
|
if (itemCount != 1) {
|
|
|
- c.drawCircle(start, indicatorPosY, mIndicatorItemLength / 2F, mPaint);
|
|
|
+ c.drawCircle(start, indicatorPosY, mIndicatorItemLength / 2, mPaint);
|
|
|
start += itemWidth;
|
|
|
}
|
|
|
+ Log.e("APP# CustomIndicator | drawInactiveIndicators", "| drawInactiveIndicators " + itemCount);
|
|
|
}
|
|
|
}
|
|
|
|
|
|
@@ -133,16 +104,16 @@ public class CustomIndicator extends View {
|
|
|
int highlightPosition, int itemCount) {
|
|
|
mPaint.setColor(context.getResources().getColor(activeColor));
|
|
|
|
|
|
- // width of item indicator including padding
|
|
|
- final float itemWidth = mIndicatorItemLength + mIndicatorItemPadding;
|
|
|
+ final float itemWidth = mIndicatorItemLength + mIndicatorItemPadding;
|
|
|
|
|
|
float start = indicatorStartX;
|
|
|
for (int i = 0; i < itemCount; i++) {
|
|
|
if (itemCount != 1 && i == highlightPosition) {
|
|
|
- canvas.drawCircle(start, indicatorPosY, mIndicatorItemLength / 2F, mPaint);
|
|
|
+ canvas.drawCircle(start, indicatorPosY, mIndicatorItemLength /2, mPaint);
|
|
|
}
|
|
|
start += itemWidth;
|
|
|
}
|
|
|
-
|
|
|
+ Log.e("APP# CustomIndicator | drawHighlights", "| highlightPosition" + highlightPosition );
|
|
|
}
|
|
|
+
|
|
|
}
|