Skip to content
This repository has been archived by the owner on Jun 1, 2024. It is now read-only.

[WIP] Working on refactor for SwipeBackLayout.java class #3486

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -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());
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
public class BottomShadow extends Shadow {
@Override
public void setShadow(int edgeFlag, Drawable shadow) {
if ((edgeFlag & EDGE_BOTTOM) != 0) {
mShadowBottom = shadow;
}
}
}
Original file line number Diff line number Diff line change
@@ -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);
}
}
}
Original file line number Diff line number Diff line change
@@ -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());
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
public class LeftShadow extends Shadowable {
@Override
public void setShadow(int edgeFlag, Drawable shadow) {
if ((edgeFlag & EDGE_LEFT) != 0) {
mShadowLeft = shadow;
}
}

}
Original file line number Diff line number Diff line change
@@ -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);
}
}
}
Original file line number Diff line number Diff line change
@@ -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());
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
public class RightShadow extends Shadowable {
@Override
public void setShadow(int edgeFlag, Drawable shadow) {
if ((edgeFlag & EDGE_RIGHT) != 0) {
mShadowRight = shadow;
}
}
}
Original file line number Diff line number Diff line change
@@ -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);
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
public interface ScrimStrategy {
public void drawScrim(Canvas canvas, int mTrackingEdge);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
public abstract class Shadow {
public Shadow() {}
public abstract void setShadow(int edgeFlag, Drawable shadow);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
public interface ShadowStrategy {
public void drawShadow(Drawable mShadow, Rect rect, float scrimOpacity, Canvas canvas);
}
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}

Expand Down Expand Up @@ -413,49 +416,34 @@ 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);
}

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);
}

/**
Expand Down
Original file line number Diff line number Diff line change
@@ -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());
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
public class TopShadow extends Shadowable {
@Override
public void setShadow(int edgeFlag, Drawable shadow) {
if ((edgeFlag & EDGE_TOP) != 0) {
mShadowTop = shadow;
}
}
}
Original file line number Diff line number Diff line change
@@ -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);
}
}
}