diff --git a/app/src/main/java/me/ccrama/redditslide/SwipeLayout/BottomScrimStrategy.java b/app/src/main/java/me/ccrama/redditslide/SwipeLayout/BottomScrimStrategy.java new file mode 100644 index 0000000000..b41af1f0e2 --- /dev/null +++ b/app/src/main/java/me/ccrama/redditslide/SwipeLayout/BottomScrimStrategy.java @@ -0,0 +1,7 @@ +public class BottomScrimStrategy implements ScrimStrategy{ + public void drawScrim(Canvas canvas, int mTrackingEdge) { + if ((mTrackingEdge & EDGE_BOTTOM) != 0) { + canvas.clipRect(child.getLeft(), child.getBottom(), getRight(), getHeight()); + } + } +} diff --git a/app/src/main/java/me/ccrama/redditslide/SwipeLayout/BottomShadow.java b/app/src/main/java/me/ccrama/redditslide/SwipeLayout/BottomShadow.java new file mode 100644 index 0000000000..101704c0f3 --- /dev/null +++ b/app/src/main/java/me/ccrama/redditslide/SwipeLayout/BottomShadow.java @@ -0,0 +1,8 @@ +public class BottomShadow extends Shadow { + @Override + public void setShadow(int edgeFlag, Drawable shadow) { + if ((edgeFlag & EDGE_BOTTOM) != 0) { + mShadowBottom = shadow; + } + } +} diff --git a/app/src/main/java/me/ccrama/redditslide/SwipeLayout/BottomShadowDrawer.java b/app/src/main/java/me/ccrama/redditslide/SwipeLayout/BottomShadowDrawer.java new file mode 100644 index 0000000000..a8a41a573e --- /dev/null +++ b/app/src/main/java/me/ccrama/redditslide/SwipeLayout/BottomShadowDrawer.java @@ -0,0 +1,10 @@ +public class BottomShadowDrawer implements ShadowStrategy { + public void drawShadow(Drawable mShadow, Rect rect, float scrimOpacity, Canvas canvas) { + if ((mEdgeFlag & EDGE_BOTTOM) != 0) { + mShadow.setBounds(childRect.left, childRect.bottom, childRect.right, + childRect.bottom + mShadow.getIntrinsicHeight()); + mShadow.setAlpha((int) (mScrimOpacity * FULL_ALPHA)); + mShadow.draw(canvas); + } + } +} diff --git a/app/src/main/java/me/ccrama/redditslide/SwipeLayout/LeftScrimStrategy.java b/app/src/main/java/me/ccrama/redditslide/SwipeLayout/LeftScrimStrategy.java new file mode 100644 index 0000000000..a781e01c7a --- /dev/null +++ b/app/src/main/java/me/ccrama/redditslide/SwipeLayout/LeftScrimStrategy.java @@ -0,0 +1,7 @@ +public class LeftScrimStrategy implements ScrimStrategy{ + public void drawScrim(Canvas canvas, int mTrackingEdge) { + if ((mTrackingEdge & EDGE_LEFT) != 0) { + canvas.clipRect(0, 0, child.getLeft(), getHeight()); + } + } +} diff --git a/app/src/main/java/me/ccrama/redditslide/SwipeLayout/LeftShadow.java b/app/src/main/java/me/ccrama/redditslide/SwipeLayout/LeftShadow.java new file mode 100644 index 0000000000..1f82706ddb --- /dev/null +++ b/app/src/main/java/me/ccrama/redditslide/SwipeLayout/LeftShadow.java @@ -0,0 +1,9 @@ +public class LeftShadow extends Shadowable { + @Override + public void setShadow(int edgeFlag, Drawable shadow) { + if ((edgeFlag & EDGE_LEFT) != 0) { + mShadowLeft = shadow; + } + } + +} diff --git a/app/src/main/java/me/ccrama/redditslide/SwipeLayout/LeftShadowDrawer.java b/app/src/main/java/me/ccrama/redditslide/SwipeLayout/LeftShadowDrawer.java new file mode 100644 index 0000000000..f6a06c5b84 --- /dev/null +++ b/app/src/main/java/me/ccrama/redditslide/SwipeLayout/LeftShadowDrawer.java @@ -0,0 +1,10 @@ +public class LeftShadowDrawer implements ShadowStrategy{ + public void drawShadow(Drawable mShadow, Rect rect, float scrimOpacity, Canvas canvas) { + if ((mEdgeFlag & EDGE_LEFT) != 0) { + mShadow.setBounds(childRect.left - mShadow.getIntrinsicWidth(), childRect.top, + childRect.left, childRect.bottom); + mShadow.setAlpha((int) (mScrimOpacity * FULL_ALPHA)); + mShadow.draw(canvas); + } + } +} diff --git a/app/src/main/java/me/ccrama/redditslide/SwipeLayout/RightScrimStrategy.java b/app/src/main/java/me/ccrama/redditslide/SwipeLayout/RightScrimStrategy.java new file mode 100644 index 0000000000..70a2f0cdce --- /dev/null +++ b/app/src/main/java/me/ccrama/redditslide/SwipeLayout/RightScrimStrategy.java @@ -0,0 +1,7 @@ +public class RightScrimStrategy implements ScrimStrategy{ + public void drawScrim(Canvas canvas, int mTrackingEdge) { + if ((mTrackingEdge & EDGE_RIGHT) != 0) { + canvas.clipRect(child.getRight(), 0, getRight(), getHeight()); + } + } +} diff --git a/app/src/main/java/me/ccrama/redditslide/SwipeLayout/RightShadow.java b/app/src/main/java/me/ccrama/redditslide/SwipeLayout/RightShadow.java new file mode 100644 index 0000000000..1efa030d58 --- /dev/null +++ b/app/src/main/java/me/ccrama/redditslide/SwipeLayout/RightShadow.java @@ -0,0 +1,8 @@ +public class RightShadow extends Shadowable { + @Override + public void setShadow(int edgeFlag, Drawable shadow) { + if ((edgeFlag & EDGE_RIGHT) != 0) { + mShadowRight = shadow; + } + } +} diff --git a/app/src/main/java/me/ccrama/redditslide/SwipeLayout/RightShadowDrawer.java b/app/src/main/java/me/ccrama/redditslide/SwipeLayout/RightShadowDrawer.java new file mode 100644 index 0000000000..1138f28f0d --- /dev/null +++ b/app/src/main/java/me/ccrama/redditslide/SwipeLayout/RightShadowDrawer.java @@ -0,0 +1,10 @@ +public class RightShadowDrawer implements ShadowStrategy{ + public void drawShadow(Drawable mShadow, Rect rect, float scrimOpacity, Canvas canvas) { + if ((mEdgeFlag & EDGE_RIGHT) != 0) { + mShadow.setBounds(childRect.right, childRect.top, + childRect.right + mShadow.getIntrinsicWidth(), childRect.bottom); + mShadow.setAlpha((int) (mScrimOpacity * FULL_ALPHA)); + mShadow.draw(canvas); + } + } +} diff --git a/app/src/main/java/me/ccrama/redditslide/SwipeLayout/ScrimStrategy.java b/app/src/main/java/me/ccrama/redditslide/SwipeLayout/ScrimStrategy.java new file mode 100644 index 0000000000..99c2e5657e --- /dev/null +++ b/app/src/main/java/me/ccrama/redditslide/SwipeLayout/ScrimStrategy.java @@ -0,0 +1,3 @@ +public interface ScrimStrategy { + public void drawScrim(Canvas canvas, int mTrackingEdge); +} diff --git a/app/src/main/java/me/ccrama/redditslide/SwipeLayout/Shadow.java b/app/src/main/java/me/ccrama/redditslide/SwipeLayout/Shadow.java new file mode 100644 index 0000000000..c9e4f16bb7 --- /dev/null +++ b/app/src/main/java/me/ccrama/redditslide/SwipeLayout/Shadow.java @@ -0,0 +1,4 @@ +public abstract class Shadow { + public Shadow() {} + public abstract void setShadow(int edgeFlag, Drawable shadow); +} diff --git a/app/src/main/java/me/ccrama/redditslide/SwipeLayout/ShadowStrategy.java b/app/src/main/java/me/ccrama/redditslide/SwipeLayout/ShadowStrategy.java new file mode 100644 index 0000000000..28fc7386c8 --- /dev/null +++ b/app/src/main/java/me/ccrama/redditslide/SwipeLayout/ShadowStrategy.java @@ -0,0 +1,3 @@ +public interface ShadowStrategy { + public void drawShadow(Drawable mShadow, Rect rect, float scrimOpacity, Canvas canvas); +} diff --git a/app/src/main/java/me/ccrama/redditslide/SwipeLayout/SwipeBackLayout.java b/app/src/main/java/me/ccrama/redditslide/SwipeLayout/SwipeBackLayout.java index 3d45db25d5..0a3c073028 100644 --- a/app/src/main/java/me/ccrama/redditslide/SwipeLayout/SwipeBackLayout.java +++ b/app/src/main/java/me/ccrama/redditslide/SwipeLayout/SwipeBackLayout.java @@ -301,15 +301,18 @@ public void setScrollThresHold(float threshold) { * @see #EDGE_TOP */ public void setShadow(Drawable shadow, int edgeFlag) { - if ((edgeFlag & EDGE_LEFT) != 0) { - mShadowLeft = shadow; - } else if ((edgeFlag & EDGE_RIGHT) != 0) { - mShadowRight = shadow; - } else if ((edgeFlag & EDGE_BOTTOM) != 0) { - mShadowBottom = shadow; - } else if ((edgeFlag & EDGE_TOP) != 0) { - mShadowTop = shadow; - } + ShadowSetter shadowSetter = new ShadowSetter(); + + Shadow leftShadow = new LeftShadow(); + Shadow rightShadow = new RightShadow(); + Shadow topShadow = new TopShadow(); + Shadow bottomShadow = new BottomShadow(); + + leftShadow.setShadow(edgeFlag, shadow); + rightShadow.setShadow(edgeFlag, shadow); + topShadow.setShadow(edgeFlag, shadow); + bottomShadow.setShadow(edgeFlag, shadow); + invalidate(); } @@ -413,15 +416,16 @@ private void drawScrim(Canvas canvas, View child) { final int alpha = (int) (baseAlpha * mScrimOpacity); final int color = alpha << 24 | (mScrimColor & 0xffffff); - if ((mTrackingEdge & EDGE_LEFT) != 0) { - canvas.clipRect(0, 0, child.getLeft(), getHeight()); - } else if ((mTrackingEdge & EDGE_RIGHT) != 0) { - canvas.clipRect(child.getRight(), 0, getRight(), getHeight()); - } else if ((mTrackingEdge & EDGE_BOTTOM) != 0) { - canvas.clipRect(child.getLeft(), child.getBottom(), getRight(), getHeight()); - } else if ((mTrackingEdge & EDGE_TOP) != 0) { - canvas.clipRect(child.getLeft(), 0, getRight(), child.getTop() + getStatusBarHeight()); - } + ScrimStrategy top = new TopScrimStrategy(); + ScrimStrategy right = new RightScrimStrategy(); + ScrimStrategy bottom = new BottomScrimStrategy(); + ScrimStrategy left = new LeftScrimStrategy(); + + top.drawScrim(canvas, child); + right.drawScrim(canvas, child); + bottom.drawScrim(canvas, child); + left.drawScrim(canvas, child); + canvas.drawColor(color); } @@ -429,33 +433,17 @@ private void drawShadow(Canvas canvas, View child) { final Rect childRect = mTmpRect; child.getHitRect(childRect); - if ((mEdgeFlag & EDGE_LEFT) != 0) { - mShadowLeft.setBounds(childRect.left - mShadowLeft.getIntrinsicWidth(), childRect.top, - childRect.left, childRect.bottom); - mShadowLeft.setAlpha((int) (mScrimOpacity * FULL_ALPHA)); - mShadowLeft.draw(canvas); - } + ShadowStrategy left = new LeftShadowDrawer(); + left.drawShadow(mShadowLeft, childRect, mScrimOpacity, canvas); - if ((mEdgeFlag & EDGE_RIGHT) != 0) { - mShadowRight.setBounds(childRect.right, childRect.top, - childRect.right + mShadowRight.getIntrinsicWidth(), childRect.bottom); - mShadowRight.setAlpha((int) (mScrimOpacity * FULL_ALPHA)); - mShadowRight.draw(canvas); - } + ShadowStrategy right = new RightShadowDrawer(); + right.drawShadow(mShadowRight, childRect, mScrimOpacity, canvas); - if ((mEdgeFlag & EDGE_BOTTOM) != 0) { - mShadowBottom.setBounds(childRect.left, childRect.bottom, childRect.right, - childRect.bottom + mShadowBottom.getIntrinsicHeight()); - mShadowBottom.setAlpha((int) (mScrimOpacity * FULL_ALPHA)); - mShadowBottom.draw(canvas); - } + ShadowStrategy bottom = new BottomShadowDrawer(); + right.drawShadow(mShadowBottom, childRect, mScrimOpacity, canvas); - if ((mEdgeFlag & EDGE_TOP) != 0) { - mShadowTop.setBounds(childRect.left, childRect.top - mShadowTop.getIntrinsicHeight(), - childRect.right, childRect.top + getStatusBarHeight()); - mShadowTop.setAlpha((int) (mScrimOpacity * FULL_ALPHA)); - mShadowTop.draw(canvas); - } + ShadowStrategy top = new TopShadowDrawer(); + top.drawShadow(mShadowTop, childRect, mScrimOpacity, canvas); } /** diff --git a/app/src/main/java/me/ccrama/redditslide/SwipeLayout/TopScrimStrategy.java b/app/src/main/java/me/ccrama/redditslide/SwipeLayout/TopScrimStrategy.java new file mode 100644 index 0000000000..39c10f1359 --- /dev/null +++ b/app/src/main/java/me/ccrama/redditslide/SwipeLayout/TopScrimStrategy.java @@ -0,0 +1,7 @@ +public class TopScrimStrategy implements ScrimStrategy{ + public void drawScrim(Canvas canvas, int mTrackingEdge) { + if ((mTrackingEdge & EDGE_TOP) != 0) { + canvas.clipRect(child.getLeft(), 0, getRight(), child.getTop() + getStatusBarHeight()); + } + } +} diff --git a/app/src/main/java/me/ccrama/redditslide/SwipeLayout/TopShadow.java b/app/src/main/java/me/ccrama/redditslide/SwipeLayout/TopShadow.java new file mode 100644 index 0000000000..1eabd51b72 --- /dev/null +++ b/app/src/main/java/me/ccrama/redditslide/SwipeLayout/TopShadow.java @@ -0,0 +1,8 @@ +public class TopShadow extends Shadowable { + @Override + public void setShadow(int edgeFlag, Drawable shadow) { + if ((edgeFlag & EDGE_TOP) != 0) { + mShadowTop = shadow; + } + } +} diff --git a/app/src/main/java/me/ccrama/redditslide/SwipeLayout/TopShadowDrawer.java b/app/src/main/java/me/ccrama/redditslide/SwipeLayout/TopShadowDrawer.java new file mode 100644 index 0000000000..be945b6710 --- /dev/null +++ b/app/src/main/java/me/ccrama/redditslide/SwipeLayout/TopShadowDrawer.java @@ -0,0 +1,10 @@ +public class TopShadowDrawer implements ShadowStrategy{ + public void drawShadow(Drawable mShadow, Rect rect, float scrimOpacity, Canvas canvas) { + if ((mEdgeFlag & EDGE_TOP) != 0) { + mShadow.setBounds(childRect.left, childRect.top - mShadow.getIntrinsicHeight(), + childRect.right, childRect.top + getStatusBarHeight()); + mShadow.setAlpha((int) (mScrimOpacity * FULL_ALPHA)); + mShadow.draw(canvas); + } + } +}