From 09f12c81c12ed1993446e98779661d25ced42ad3 Mon Sep 17 00:00:00 2001 From: DSIW Date: Fri, 10 Jun 2016 03:23:35 +0200 Subject: Remove CardView and use divider for separation --- .../com/zeapo/pwdstore/DividerItemDecoration.java | 51 +++++++++++++++++ .../java/com/zeapo/pwdstore/PasswordFragment.java | 7 ++- .../pwdstore/utils/PasswordRecyclerAdapter.java | 18 +++--- app/src/main/res/drawable/divider.xml | 6 ++ app/src/main/res/layout/password_row_layout.xml | 66 +++++++++------------- 5 files changed, 97 insertions(+), 51 deletions(-) create mode 100644 app/src/main/java/com/zeapo/pwdstore/DividerItemDecoration.java create mode 100644 app/src/main/res/drawable/divider.xml (limited to 'app') diff --git a/app/src/main/java/com/zeapo/pwdstore/DividerItemDecoration.java b/app/src/main/java/com/zeapo/pwdstore/DividerItemDecoration.java new file mode 100644 index 00000000..7bc66b62 --- /dev/null +++ b/app/src/main/java/com/zeapo/pwdstore/DividerItemDecoration.java @@ -0,0 +1,51 @@ +package com.zeapo.pwdstore; + +import android.content.Context; +import android.content.res.TypedArray; +import android.graphics.Canvas; +import android.graphics.drawable.Drawable; +import android.support.v4.content.ContextCompat; +import android.support.v7.widget.RecyclerView; +import android.view.View; + +public class DividerItemDecoration extends RecyclerView.ItemDecoration { + + private static final int[] ATTRS = new int[]{android.R.attr.listDivider}; + + private Drawable mDivider; + + /** + * Default divider will be used + */ + public DividerItemDecoration(Context context) { + final TypedArray styledAttributes = context.obtainStyledAttributes(ATTRS); + mDivider = styledAttributes.getDrawable(0); + styledAttributes.recycle(); + } + + /** + * Custom divider will be used + */ + public DividerItemDecoration(Context context, int resId) { + mDivider = ContextCompat.getDrawable(context, resId); + } + + @Override + public void onDraw(Canvas c, RecyclerView parent, RecyclerView.State state) { + int left = parent.getPaddingLeft(); + int right = parent.getWidth() - parent.getPaddingRight(); + + int childCount = parent.getChildCount(); + for (int i = 0; i < childCount; i++) { + View child = parent.getChildAt(i); + + RecyclerView.LayoutParams params = (RecyclerView.LayoutParams) child.getLayoutParams(); + + int top = child.getBottom() + params.bottomMargin; + int bottom = top + mDivider.getIntrinsicHeight(); + + mDivider.setBounds(left, top, right, bottom); + mDivider.draw(c); + } + } +} diff --git a/app/src/main/java/com/zeapo/pwdstore/PasswordFragment.java b/app/src/main/java/com/zeapo/pwdstore/PasswordFragment.java index 1daa4f90..79401fbd 100644 --- a/app/src/main/java/com/zeapo/pwdstore/PasswordFragment.java +++ b/app/src/main/java/com/zeapo/pwdstore/PasswordFragment.java @@ -74,8 +74,11 @@ public class PasswordFragment extends Fragment{ recyclerView = (RecyclerView) view.findViewById(R.id.pass_recycler); recyclerView.setLayoutManager(mLayoutManager); -// -// // Set the adapter + + // use divider + recyclerView.addItemDecoration(new DividerItemDecoration(getActivity(), R.drawable.divider)); + + // Set the adapter recyclerView.setAdapter(recyclerAdapter); final FloatingActionButton fab = (FloatingActionButton) view.findViewById(R.id.fab); diff --git a/app/src/main/java/com/zeapo/pwdstore/utils/PasswordRecyclerAdapter.java b/app/src/main/java/com/zeapo/pwdstore/utils/PasswordRecyclerAdapter.java index 3f240515..af9a6776 100644 --- a/app/src/main/java/com/zeapo/pwdstore/utils/PasswordRecyclerAdapter.java +++ b/app/src/main/java/com/zeapo/pwdstore/utils/PasswordRecyclerAdapter.java @@ -33,14 +33,12 @@ public class PasswordRecyclerAdapter extends RecyclerView.Adapter + + + + \ No newline at end of file diff --git a/app/src/main/res/layout/password_row_layout.xml b/app/src/main/res/layout/password_row_layout.xml index 61c089df..0b877934 100644 --- a/app/src/main/res/layout/password_row_layout.xml +++ b/app/src/main/res/layout/password_row_layout.xml @@ -8,49 +8,37 @@ android:layout_marginRight="8dp" android:layout_marginTop="0dp"> - + android:padding="8dp" + android:gravity="left"> - + android:alpha="0.5" + android:maxLines="1" + android:ellipsize="start" + android:text="TYPE" + android:textSize="14dp" + android:textColor="@android:color/black" + android:layout_alignParentTop="true" + android:layout_alignLeft="@+id/label" + android:layout_alignStart="@+id/label" /> - + + - - - \ No newline at end of file -- cgit v1.2.3