Skip to content

Commit

Permalink
Merge pull request #10 from Omega-R/develop
Browse files Browse the repository at this point in the history
Added alpha for dividers
  • Loading branch information
anton-knyazev authored Oct 24, 2017
2 parents c8bbe6e + 93d0754 commit 7b8b754
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 7 deletions.
1 change: 1 addition & 0 deletions app/src/main/res/layout/fragment_test.xml
Original file line number Diff line number Diff line change
Expand Up @@ -12,5 +12,6 @@
android:divider="@drawable/divider"
android:dividerHeight="1dp"
app:itemSpace="32dp"
app:alphaDivider="0.5"
app:showDivider="middle"/>
</FrameLayout>
Original file line number Diff line number Diff line change
Expand Up @@ -33,18 +33,20 @@ public interface ShowDivider {
private int mDividerSize;
private int mShowDivider;
private final int mOffset;
private final float mDividerAlpha;
private int mOrientation;

public DividerItemDecoration(Drawable divider, int dividerSize, int showDivider, int offset) {
this(divider, Orientation.UNKNOWN, dividerSize, showDivider, offset);
public DividerItemDecoration(Drawable divider, int dividerSize, int showDivider, int offset, float dividerAlpha) {
this(divider, Orientation.UNKNOWN, dividerSize, showDivider, offset, dividerAlpha);
}

public DividerItemDecoration(Drawable divider, int orientation, int dividerSize, int showDivider, int offset) {
public DividerItemDecoration(Drawable divider, int orientation, int dividerSize, int showDivider, int offset, float dividerAlpha) {
mOrientation = orientation;
mDivider = divider;
mDividerSize = dividerSize;
mShowDivider = showDivider;
mOffset = offset;
mDividerAlpha = dividerAlpha;
updateSize();
}

Expand Down Expand Up @@ -129,7 +131,7 @@ public void onDrawOver(Canvas c, RecyclerView parent, RecyclerView.State state)
left = child.getRight() + params.rightMargin;
right = left + size;
}
divider.setAlpha((int) (child.getAlpha() * 255f));
divider.setAlpha((int) (child.getAlpha() * 255f * mDividerAlpha));
divider.setBounds(left, top, right, bottom);
divider.draw(c);
startIndex = i;
Expand All @@ -152,7 +154,7 @@ public void onDrawOver(Canvas c, RecyclerView parent, RecyclerView.State state)
left = child.getLeft() - params.leftMargin - mOffset;
right = left + size;
}
divider.setAlpha((int) (child.getAlpha() * 255f));
divider.setAlpha((int) (child.getAlpha() * 255f * mDividerAlpha));
divider.setBounds(left, top, right, bottom);
divider.draw(c);
}
Expand All @@ -176,7 +178,7 @@ public void onDrawOver(Canvas c, RecyclerView parent, RecyclerView.State state)
right = left + size;
}

divider.setAlpha((int) (child.getAlpha() * 255f));
divider.setAlpha((int) (child.getAlpha() * 255f * mDividerAlpha));
divider.setBounds(left, top, right, bottom);
divider.draw(c);
break;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,8 @@ public void initDivider(TypedArray a) {
}

float dividerHeight = a.getDimension(R.styleable.OmegaRecyclerView_android_dividerHeight, -1);
addItemDecoration(new DividerItemDecoration(dividerDrawable, (int) dividerHeight, showDivider, mItemSpace / 2));
float alpha = a.getFloat(R.styleable.OmegaRecyclerView_alphaDivider, 1);
addItemDecoration(new DividerItemDecoration(dividerDrawable, (int) dividerHeight, showDivider, mItemSpace / 2, alpha));
}
}
}
Expand Down
1 change: 1 addition & 0 deletions omegarecyclerviewlibs/src/main/res/values/attrs.xml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
<flag name="middle" value="2" />
<flag name="end" value="4" />
</attr>
<attr name="alphaDivider" format="float"/>
<attr name="emptyView" format="reference" />
</declare-styleable>
</resources>

0 comments on commit 7b8b754

Please sign in to comment.