Welcome to mirror list, hosted at ThFree Co, Russian Federation.

DotDividerItemDecoration.java « recycler « widget « maps « mapswithme « com « src « android - github.com/mapsme/omim.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 7f8f6f6cb9aee6212a944ebdfe521ea1f789d01b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
package com.mapswithme.maps.widget.recycler;

import android.graphics.Canvas;
import android.graphics.Rect;
import android.graphics.drawable.Drawable;
import android.support.annotation.Dimension;
import android.support.annotation.NonNull;
import android.support.v7.widget.RecyclerView;
import android.view.View;

public class DotDividerItemDecoration extends RecyclerView.ItemDecoration
{
  @Dimension
  private final int mHorizontalMargin;
  @Dimension
  private final int mVerticalMargin;
  @NonNull
  private final Drawable mDivider;

  public DotDividerItemDecoration(@NonNull Drawable divider, @Dimension int horizontalMargin,
                                  @Dimension int verticalMargin)
  {
    mDivider = divider;
    mHorizontalMargin = horizontalMargin;
    mVerticalMargin = verticalMargin;
  }

  @Override
  public void getItemOffsets(Rect outRect, View view, RecyclerView parent, RecyclerView.State state)
  {
    super.getItemOffsets(outRect, view, parent, state);
    outRect.right = mHorizontalMargin;
    outRect.bottom = mVerticalMargin;
  }

  @Override
  public void onDraw(Canvas c, RecyclerView parent, RecyclerView.State state)
  {
    if (state.isMeasuring())
      return;

    int childCount = parent.getChildCount();
    for (int i = 0; i < childCount - 1; i++)
    {
      View child = parent.getChildAt(i);

      int centerX = mHorizontalMargin / 2 + child.getRight();
      int centerY = child.getHeight() / 2 + child.getTop();
      int left = centerX - mDivider.getIntrinsicWidth() / 2;
      int right = left + mDivider.getIntrinsicWidth();
      int top = centerY - mDivider.getIntrinsicHeight() / 2;
      int bottom = top + mDivider.getIntrinsicHeight();

      mDivider.setBounds(left, top, right, bottom);

      mDivider.draw(c);
    }
  }
}