Forráskód Böngészése

Merge branch 'develop' of https://github.com/swict/LifePlusAndroid into develop

hyodong.min 7 éve
szülő
commit
3d7c8a9ecd

+ 148 - 0
app/src/main/java/kr/co/zumo/app/lifeplus/view/screen/event/CustomIndicator.java

@@ -0,0 +1,148 @@
+package kr.co.zumo.app.lifeplus.view.screen.event;
+
+import android.content.Context;
+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.view.View;
+
+import kr.co.zumo.app.lifeplus.view.IndexScrollListener;
+
+/**
+ * CustomIndicator
+ * <pre>
+ * </pre>
+ *
+ * @author 하세미
+ * @version 1.0
+ * @history 하세미   [2019-01-03]   [최초 작성]
+ * @since 2019-01-03
+ */
+public class CustomIndicator extends View {
+
+  public CustomIndicator(Context context) {
+    super(context);
+  }
+
+  public CustomIndicator(Context context, @Nullable AttributeSet attrs) {
+    super(context, attrs);
+  }
+
+  public CustomIndicator(Context context, @Nullable AttributeSet attrs, int defStyleAttr) {
+    super(context, attrs, defStyleAttr);
+  }
+
+  private Context context;
+  private int activeColor;
+  private int inActiveColor;
+  private int bottomOffset;
+
+  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 onDrawOver(Canvas canvas, RecyclerView parent, RecyclerView.State state) {
+
+    if (null == parent || null == parent.getAdapter()) {
+      return;
+    }
+
+    int itemCount = parent.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;
+
+    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);
+        start += itemWidth;
+      }
+    }
+  }
+
+  private void drawHighlights(Canvas canvas, float indicatorStartX, float indicatorPosY,
+                              int highlightPosition, int itemCount) {
+    mPaint.setColor(context.getResources().getColor(activeColor));
+
+    // width of item indicator including padding
+    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);
+      }
+      start += itemWidth;
+    }
+
+  }
+}

+ 2 - 2
app/src/main/java/kr/co/zumo/app/lifeplus/view/screen/event/EventFragment.java

@@ -33,7 +33,7 @@ import kr.co.zumo.app.lifeplus.view.screen.FragmentBase;
  * @since 2018-11-12
  */
 public class EventFragment extends FragmentBase<EventPresenter> implements IEventView {
-
+  private CustomIndicator customIndicator;
   private RecyclerView recyclerViewEvent;
   private ConstraintLayout layoutMyEvent;
   private LinearLayoutManager layoutManager;
@@ -69,7 +69,7 @@ public class EventFragment extends FragmentBase<EventPresenter> implements IEven
     recyclerViewEvent.addItemDecoration(new MainBannerViewItemDotIndicator(getActivity(), R.color.C19000000, R.color.C000000, ResourceUtil.dpToPx(38)));
 
     layoutMyEvent = findViewById(R.id.layout_my_event);
-
+    customIndicator = findViewById(R.id.custom_indicator);
     recyclerViewEvent.addOnScrollListener(new RecyclerView.OnScrollListener() {
       @Override
       public void onScrolled(RecyclerView recyclerView, int dx, int dy) {

+ 12 - 2
app/src/main/res/layout/fragment_event.xml

@@ -20,8 +20,17 @@
     app:layout_constraintTop_toTopOf="parent"
     tools:background="@color/CE5E5E5"/>
 
+  <kr.co.zumo.app.lifeplus.view.screen.event.CustomIndicator
+    android:id="@+id/custom_indicator"
+    android:layout_width="match_parent"
+    android:layout_height="wrap_content"
+    android:layout_marginTop="30dp"
+    app:layout_constraintEnd_toEndOf="parent"
+    app:layout_constraintStart_toStartOf="parent"
+    app:layout_constraintTop_toBottomOf="@+id/recycler_view_event"
+    />
+
   <android.support.constraint.ConstraintLayout
-    android:visibility="gone"
     android:id="@+id/layout_my_event"
     android:layout_width="match_parent"
     android:layout_height="wrap_content"
@@ -29,6 +38,7 @@
     android:layout_marginEnd="25dp"
     android:layout_marginBottom="25dp"
     android:background="@drawable/rectangle_black_radius_2"
+    android:visibility="gone"
     app:layout_constraintBottom_toBottomOf="parent"
     app:layout_constraintEnd_toEndOf="parent"
     app:layout_constraintStart_toStartOf="parent">
@@ -40,13 +50,13 @@
       android:layout_marginBottom="10dp"
       android:gravity="center_horizontal"
       android:lineSpacingExtra="6sp"
+      android:text="@string/my_event"
       android:textColor="@color/CFFFFFF"
       android:textSize="16sp"
       app:layout_constraintBottom_toBottomOf="parent"
       app:layout_constraintEnd_toEndOf="parent"
       app:layout_constraintStart_toStartOf="parent"
       app:layout_constraintTop_toTopOf="parent"
-      android:text="@string/my_event"
       />
 
   </android.support.constraint.ConstraintLayout>