From 2dc411f999332b25534d8c19521652992c75b5c9 Mon Sep 17 00:00:00 2001 From: Phillip Hsu Date: Tue, 30 Aug 2016 02:39:18 -0700 Subject: [PATCH] Create GridLayoutManager for TimersFragment in landscape --- .../clock2/timers/TimersFragment.java | 15 ++++ app/src/main/res/layout-land/item_timer.xml | 84 +++++++++++++++++++ .../res/layout/fragment_recycler_view.xml | 4 +- 3 files changed, 102 insertions(+), 1 deletion(-) create mode 100644 app/src/main/res/layout-land/item_timer.xml 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 73e46ae..b3e79c3 100644 --- a/app/src/main/java/com/philliphsu/clock2/timers/TimersFragment.java +++ b/app/src/main/java/com/philliphsu/clock2/timers/TimersFragment.java @@ -3,9 +3,12 @@ package com.philliphsu.clock2.timers; import android.app.Activity; import android.content.Intent; +import android.content.res.Configuration; import android.os.Bundle; import android.support.annotation.Nullable; import android.support.v4.content.Loader; +import android.support.v7.widget.GridLayoutManager; +import android.support.v7.widget.RecyclerView; import com.philliphsu.clock2.AsyncTimersTableUpdateHandler; import com.philliphsu.clock2.RecyclerViewFragment; @@ -19,6 +22,8 @@ public class TimersFragment extends RecyclerViewFragment< TimerViewHolder, TimerCursor, TimersCursorAdapter> { + private static final int LANDSCAPE_LAYOUT_COLUMNS = 2; + public static final int REQUEST_CREATE_TIMER = 0; private AsyncTimersTableUpdateHandler mAsyncTimersTableUpdateHandler; @@ -67,6 +72,16 @@ public class TimersFragment extends RecyclerViewFragment< return new TimersCursorAdapter(this, mAsyncTimersTableUpdateHandler); } + @Override + protected RecyclerView.LayoutManager getLayoutManager() { + switch (getResources().getConfiguration().orientation) { + case Configuration.ORIENTATION_LANDSCAPE: + return new GridLayoutManager(getActivity(), LANDSCAPE_LAYOUT_COLUMNS); + default: + return super.getLayoutManager(); + } + } + @Override public Loader onCreateLoader(int id, Bundle args) { return new TimersListCursorLoader(getActivity()); diff --git a/app/src/main/res/layout-land/item_timer.xml b/app/src/main/res/layout-land/item_timer.xml new file mode 100644 index 0000000..3a03826 --- /dev/null +++ b/app/src/main/res/layout-land/item_timer.xml @@ -0,0 +1,84 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/app/src/main/res/layout/fragment_recycler_view.xml b/app/src/main/res/layout/fragment_recycler_view.xml index 5cf8f54..f4c8010 100644 --- a/app/src/main/res/layout/fragment_recycler_view.xml +++ b/app/src/main/res/layout/fragment_recycler_view.xml @@ -4,4 +4,6 @@ xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="match_parent" - android:scrollbars="vertical"/> + android:scrollbars="vertical" + android:paddingStart="8dp" + android:paddingTop="8dp"/>