aboutsummaryrefslogtreecommitdiff
path: root/app/src/main/java
diff options
context:
space:
mode:
authorScott Jackson <daneren2005@gmail.com>2015-12-20 14:40:54 -0800
committerScott Jackson <daneren2005@gmail.com>2015-12-20 14:40:54 -0800
commit2347d39ae75bfba9dedeed6b95c554d30c6b8f52 (patch)
tree133137031402d3e5536cc7c34759149dac6206e4 /app/src/main/java
parent121c1339a7213d5ac35483406f90ddf32f7fbdcf (diff)
parentc9b500569cd4c9ae9213b268b45d049f59b751e5 (diff)
downloaddsub-2347d39ae75bfba9dedeed6b95c554d30c6b8f52.tar.gz
dsub-2347d39ae75bfba9dedeed6b95c554d30c6b8f52.tar.bz2
dsub-2347d39ae75bfba9dedeed6b95c554d30c6b8f52.zip
Merge branch 'card'
Diffstat (limited to 'app/src/main/java')
-rw-r--r--app/src/main/java/github/daneren2005/dsub/view/CardView.java54
-rw-r--r--app/src/main/java/github/daneren2005/dsub/view/FastScroller.java2
-rw-r--r--app/src/main/java/github/daneren2005/dsub/view/GridSpacingDecoration.java45
3 files changed, 92 insertions, 9 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
new file mode 100644
index 00000000..973e63fa
--- /dev/null
+++ b/app/src/main/java/github/daneren2005/dsub/view/CardView.java
@@ -0,0 +1,54 @@
+package github.daneren2005.dsub.view;
+
+import android.annotation.TargetApi;
+import android.content.Context;
+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;
+
+public class CardView extends FrameLayout{
+ public CardView(Context context) {
+ super(context);
+ init(context);
+ }
+
+ public CardView(Context context, AttributeSet attrs) {
+ super(context, attrs);
+ init(context);
+ }
+
+ public CardView(Context context, AttributeSet attrs, int defStyleAttr) {
+ super(context, attrs, defStyleAttr);
+ init(context);
+ }
+
+ @TargetApi(Build.VERSION_CODES.LOLLIPOP)
+ public CardView(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) {
+ super(context, attrs, defStyleAttr, defStyleRes);
+ init(context);
+ }
+
+ @Override
+ public void onDraw(Canvas canvas) {
+ Path clipPath = new Path();
+
+ float roundedDp = getResources().getDimension(R.dimen.Card_Radius);
+ clipPath.addRoundRect(new RectF(canvas.getClipBounds()), roundedDp, roundedDp, Path.Direction.CW);
+ 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/FastScroller.java b/app/src/main/java/github/daneren2005/dsub/view/FastScroller.java
index 7cb29835..d3eacefc 100644
--- a/app/src/main/java/github/daneren2005/dsub/view/FastScroller.java
+++ b/app/src/main/java/github/daneren2005/dsub/view/FastScroller.java
@@ -95,7 +95,7 @@ public class FastScroller extends LinearLayout {
switch(action)
{
case MotionEvent.ACTION_DOWN:
- if(event.getX() < (handle.getX() - 20)) {
+ if(event.getX() < (handle.getX() - 30)) {
return false;
}
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 b59e7157..a33746c4 100644
--- a/app/src/main/java/github/daneren2005/dsub/view/GridSpacingDecoration.java
+++ b/app/src/main/java/github/daneren2005/dsub/view/GridSpacingDecoration.java
@@ -18,10 +18,17 @@ package github.daneren2005.dsub.view;
import android.graphics.Rect;
import android.support.v7.widget.GridLayoutManager;
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();
public static final int SPACING = 10;
@Override
@@ -39,30 +46,52 @@ public class GridSpacingDecoration extends RecyclerView.ItemDecoration {
}
int spanCount = getTotalSpan(view, parent);
int spanIndex = childIndex % spanCount;
+
+ // If we can, use the SpanSizeLookup since headers screw up the index calculation
+ RecyclerView.LayoutManager layoutManager = parent.getLayoutManager();
+ if(layoutManager instanceof GridLayoutManager) {
+ GridLayoutManager gridLayoutManager = (GridLayoutManager) layoutManager;
+ GridLayoutManager.SpanSizeLookup spanSizeLookup = gridLayoutManager.getSpanSizeLookup();
+ if(spanSizeLookup != null) {
+ spanIndex = spanSizeLookup.getSpanIndex(childIndex, spanCount);
+ }
+ }
int spanSize = getSpanSize(parent, childIndex);
/* 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;
}
}