From e025f70965bf909de6ebb90fdeda96217dd67cff Mon Sep 17 00:00:00 2001 From: Phillip Hsu Date: Tue, 30 Aug 2016 17:24:25 -0700 Subject: [PATCH] Replace hardcoded dimens with dimen resources --- .../philliphsu/clock2/timers/TimersFragment.java | 15 ++++++--------- .../main/res/layout-land/fragment_stopwatch.xml | 6 ++---- app/src/main/res/layout/fragment_stopwatch.xml | 7 +++---- app/src/main/res/values/dimens.xml | 4 ++++ 4 files changed, 15 insertions(+), 17 deletions(-) diff --git a/app/src/main/java/com/philliphsu/clock2/timers/TimersFragment.java b/app/src/main/java/com/philliphsu/clock2/timers/TimersFragment.java index e92de73..0dc3503 100644 --- a/app/src/main/java/com/philliphsu/clock2/timers/TimersFragment.java +++ b/app/src/main/java/com/philliphsu/clock2/timers/TimersFragment.java @@ -30,6 +30,8 @@ public class TimersFragment extends RecyclerViewFragment< TimerViewHolder, TimerCursor, TimersCursorAdapter> { + // TODO: Different number of columns for different display densities, instead of landscape. + // Use smallest width qualifiers. I can imagine 3 or 4 columns for a large enough tablet in landscape. private static final int LANDSCAPE_LAYOUT_COLUMNS = 2; public static final int REQUEST_CREATE_TIMER = 0; @@ -47,15 +49,10 @@ public class TimersFragment extends RecyclerViewFragment< public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) { View view = super.onCreateView(inflater, container, savedInstanceState); final Resources r = getResources(); - RecyclerView list = findById(view, R.id.list); - int cardViewMargin = r.getDimensionPixelSize(R.dimen.cardview_margin); - switch (getOrientation(r)) { - case Configuration.ORIENTATION_LANDSCAPE: - list.setPaddingRelative(cardViewMargin/*start*/, cardViewMargin/*top*/, 0, list.getPaddingBottom()); - break; - case Configuration.ORIENTATION_PORTRAIT: -// list.setPaddingRelative(0, 0, 0, cardViewMargin); - break; + if (getOrientation(r) == Configuration.ORIENTATION_LANDSCAPE) { + RecyclerView list = findById(view, R.id.list); + int cardViewMargin = r.getDimensionPixelSize(R.dimen.cardview_margin); + list.setPaddingRelative(cardViewMargin/*start*/, cardViewMargin/*top*/, 0, list.getPaddingBottom()); } return view; } diff --git a/app/src/main/res/layout-land/fragment_stopwatch.xml b/app/src/main/res/layout-land/fragment_stopwatch.xml index 9dae3e4..f92297d 100644 --- a/app/src/main/res/layout-land/fragment_stopwatch.xml +++ b/app/src/main/res/layout-land/fragment_stopwatch.xml @@ -20,7 +20,6 @@ android:layout_width="0dp" android:layout_height="match_parent" android:layout_weight="1" - android:padding="16dp" android:background="@color/colorPrimary" android:gravity="center" android:textSize="@dimen/text_size_display_3" @@ -30,15 +29,14 @@ android:layout_width="0dp" android:layout_weight="1" android:layout_height="match_parent" - android:layout_marginTop="8dp"/> + android:layout_marginTop="@dimen/laps_container_margin_top"/> - diff --git a/app/src/main/res/layout/fragment_stopwatch.xml b/app/src/main/res/layout/fragment_stopwatch.xml index f98fd38..de79257 100644 --- a/app/src/main/res/layout/fragment_stopwatch.xml +++ b/app/src/main/res/layout/fragment_stopwatch.xml @@ -14,7 +14,7 @@ android:id="@+id/chronometer" android:layout_width="match_parent" android:layout_height="wrap_content" - android:padding="16dp" + android:padding="@dimen/chronometer_padding" android:background="@color/colorPrimary" android:gravity="center_horizontal" android:textSize="@dimen/text_size_display_3" @@ -23,7 +23,7 @@ + android:layout_marginTop="@dimen/laps_container_margin_top"/> @@ -36,10 +36,9 @@ android:paddingStart="0dp" android:paddingEnd="0dp"/> - diff --git a/app/src/main/res/values/dimens.xml b/app/src/main/res/values/dimens.xml index f2c281d..20724d7 100644 --- a/app/src/main/res/values/dimens.xml +++ b/app/src/main/res/values/dimens.xml @@ -53,6 +53,10 @@ 8dp 48dp + + 8dp + 16dp + 14sp 14sp 14sp