diff options
author | Scott Jackson <daneren2005@gmail.com> | 2015-12-20 14:12:37 -0800 |
---|---|---|
committer | Scott Jackson <daneren2005@gmail.com> | 2015-12-20 14:12:37 -0800 |
commit | b3cab61a025e1d828785b930e59721c4dbe62a08 (patch) | |
tree | 35db2f6a961878a7d0f586d781714b08f2d74e30 /app/src/main/java/github | |
parent | 7643d4fb60b91f8cc87510f5f09d841993ec2917 (diff) | |
download | dsub-b3cab61a025e1d828785b930e59721c4dbe62a08.tar.gz dsub-b3cab61a025e1d828785b930e59721c4dbe62a08.tar.bz2 dsub-b3cab61a025e1d828785b930e59721c4dbe62a08.zip |
Add some small shadow to cards
Diffstat (limited to 'app/src/main/java/github')
-rw-r--r-- | app/src/main/java/github/daneren2005/dsub/view/CardView.java | 22 | ||||
-rw-r--r-- | app/src/main/java/github/daneren2005/dsub/view/GridSpacingDecoration.java | 33 |
2 files changed, 38 insertions, 17 deletions
diff --git a/app/src/main/java/github/daneren2005/dsub/view/CardView.java b/app/src/main/java/github/daneren2005/dsub/view/CardView.java index ba6b66a4..973e63fa 100644 --- a/app/src/main/java/github/daneren2005/dsub/view/CardView.java +++ b/app/src/main/java/github/daneren2005/dsub/view/CardView.java @@ -2,12 +2,12 @@ package github.daneren2005.dsub.view; import android.annotation.TargetApi; import android.content.Context; -import android.content.res.Resources; import android.graphics.Canvas; import android.graphics.Path; import android.graphics.RectF; import android.os.Build; import android.util.AttributeSet; +import android.util.Log; import android.widget.FrameLayout; import github.daneren2005.dsub.R; @@ -15,27 +15,23 @@ import github.daneren2005.dsub.R; public class CardView extends FrameLayout{ public CardView(Context context) { super(context); - this.setClipChildren(true); - this.setBackgroundResource(R.drawable.card_rounded_corners); + init(context); } public CardView(Context context, AttributeSet attrs) { super(context, attrs); - this.setClipChildren(true); - this.setBackgroundResource(R.drawable.card_rounded_corners); + init(context); } public CardView(Context context, AttributeSet attrs, int defStyleAttr) { super(context, attrs, defStyleAttr); - this.setClipChildren(true); - this.setBackgroundResource(R.drawable.card_rounded_corners); + init(context); } @TargetApi(Build.VERSION_CODES.LOLLIPOP) public CardView(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) { super(context, attrs, defStyleAttr, defStyleRes); - this.setClipChildren(true); - this.setBackgroundResource(R.drawable.card_rounded_corners); + init(context); } @Override @@ -47,4 +43,12 @@ public class CardView extends FrameLayout{ canvas.clipPath(clipPath); super.onDraw(canvas); } + + private void init(Context context) { + setClipChildren(true); + setBackgroundResource(R.drawable.card_rounded_corners); + if(Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { + setElevation(10.0f); + } + } } diff --git a/app/src/main/java/github/daneren2005/dsub/view/GridSpacingDecoration.java b/app/src/main/java/github/daneren2005/dsub/view/GridSpacingDecoration.java index c6d3dbb1..a33746c4 100644 --- a/app/src/main/java/github/daneren2005/dsub/view/GridSpacingDecoration.java +++ b/app/src/main/java/github/daneren2005/dsub/view/GridSpacingDecoration.java @@ -21,6 +21,11 @@ import android.support.v7.widget.RecyclerView; import android.util.Log; import android.util.TypedValue; import android.view.View; +import android.view.ViewGroup; +import android.widget.FrameLayout; +import android.widget.LinearLayout; + +import static android.widget.LinearLayout.*; public class GridSpacingDecoration extends RecyclerView.ItemDecoration { private static final String TAG = GridSpacingDecoration.class.getSimpleName(); @@ -56,25 +61,37 @@ public class GridSpacingDecoration extends RecyclerView.ItemDecoration { /* INVALID SPAN */ if (spanCount < 1 || spanSize > 1) return; - outRect.top = halfSpacing; - outRect.bottom = halfSpacing; - outRect.left = halfSpacing; - outRect.right = halfSpacing; + int margins = 0; + if(view instanceof UpdateView) { + View firstChild = ((ViewGroup) view).getChildAt(0); + ViewGroup.LayoutParams layoutParams = firstChild.getLayoutParams(); + if (layoutParams instanceof LinearLayout.LayoutParams) { + margins = ((LinearLayout.LayoutParams) layoutParams).bottomMargin; + } else if (layoutParams instanceof FrameLayout.LayoutParams) { + margins = ((FrameLayout.LayoutParams) layoutParams).bottomMargin; + } + } + int doubleMargins = margins * 2; + + outRect.top = halfSpacing - margins; + outRect.bottom = halfSpacing - margins; + outRect.left = halfSpacing - margins; + outRect.right = halfSpacing - margins; if (isTopEdge(childIndex, spanCount)) { - outRect.top = spacing; + outRect.top = spacing - doubleMargins; } if (isLeftEdge(spanIndex, spanCount)) { - outRect.left = spacing; + outRect.left = spacing - doubleMargins; } if (isRightEdge(spanIndex, spanCount)) { - outRect.right = spacing; + outRect.right = spacing - doubleMargins; } if (isBottomEdge(childIndex, childCount, spanCount)) { - outRect.bottom = spacing; + outRect.bottom = spacing - doubleMargins; } } |