Revert to include fragment_recycler_view in Fragment layouts, programmatically set padding as needed. Replace hardcoded dimens with dimen resources.
This commit is contained in:
parent
02fc6f2bdd
commit
d970505dd5
@ -46,6 +46,8 @@ import java.util.Locale;
|
||||
import butterknife.Bind;
|
||||
import butterknife.OnClick;
|
||||
|
||||
import static com.philliphsu.clock2.util.ConfigurationUtils.getOrientation;
|
||||
|
||||
//import com.android.datetimepicker.HapticFeedbackController;
|
||||
//import com.android.datetimepicker.R;
|
||||
//import com.android.datetimepicker.Utils;
|
||||
@ -326,7 +328,7 @@ public class NumberGridTimePickerDialog extends BaseTimePickerDialog implements
|
||||
final int icon2 = mThemeDark? R.drawable.ic_half_day_2_dark_24dp : R.drawable.ic_half_day_2_24dp;
|
||||
// Determine the direction the icons should be in
|
||||
int left1 = 0, left2 = 0, top1 = 0, top2 = 0;
|
||||
switch (getResources().getConfiguration().orientation) {
|
||||
switch (getOrientation(getResources())) {
|
||||
case Configuration.ORIENTATION_PORTRAIT:
|
||||
left1 = icon1;
|
||||
left2 = icon2;
|
||||
|
||||
@ -9,6 +9,7 @@ import android.widget.LinearLayout;
|
||||
import android.widget.TextView;
|
||||
|
||||
import com.philliphsu.clock2.R;
|
||||
import com.philliphsu.clock2.util.ConfigurationUtils;
|
||||
|
||||
import butterknife.Bind;
|
||||
import butterknife.ButterKnife;
|
||||
@ -70,7 +71,8 @@ public class TwentyFourHourGridItem extends LinearLayout {
|
||||
}
|
||||
|
||||
private void init() {
|
||||
final int orientation = getResources().getConfiguration().orientation;
|
||||
// TODO: Why isn't ALT-ENTER giving us an option to static import this method?
|
||||
final int orientation = ConfigurationUtils.getOrientation(getResources());
|
||||
setOrientation(orientation == Configuration.ORIENTATION_PORTRAIT ?
|
||||
VERTICAL : /*LANDSCAPE*/HORIZONTAL);
|
||||
setGravity(Gravity.CENTER);
|
||||
|
||||
@ -4,19 +4,27 @@ package com.philliphsu.clock2.timers;
|
||||
import android.app.Activity;
|
||||
import android.content.Intent;
|
||||
import android.content.res.Configuration;
|
||||
import android.content.res.Resources;
|
||||
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 android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
|
||||
import com.philliphsu.clock2.AsyncTimersTableUpdateHandler;
|
||||
import com.philliphsu.clock2.R;
|
||||
import com.philliphsu.clock2.RecyclerViewFragment;
|
||||
import com.philliphsu.clock2.Timer;
|
||||
import com.philliphsu.clock2.edittimer.EditTimerActivity;
|
||||
import com.philliphsu.clock2.model.TimerCursor;
|
||||
import com.philliphsu.clock2.model.TimersListCursorLoader;
|
||||
|
||||
import static butterknife.ButterKnife.findById;
|
||||
import static com.philliphsu.clock2.util.ConfigurationUtils.getOrientation;
|
||||
|
||||
public class TimersFragment extends RecyclerViewFragment<
|
||||
Timer,
|
||||
TimerViewHolder,
|
||||
@ -34,6 +42,24 @@ public class TimersFragment extends RecyclerViewFragment<
|
||||
mAsyncTimersTableUpdateHandler = new AsyncTimersTableUpdateHandler(getActivity(), this);
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
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, 0);
|
||||
break;
|
||||
case Configuration.ORIENTATION_PORTRAIT:
|
||||
list.setPaddingRelative(0, 0, 0, cardViewMargin);
|
||||
break;
|
||||
}
|
||||
return view;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onActivityResult(int requestCode, int resultCode, Intent data) {
|
||||
if (resultCode != Activity.RESULT_OK || data == null)
|
||||
@ -74,7 +100,7 @@ public class TimersFragment extends RecyclerViewFragment<
|
||||
|
||||
@Override
|
||||
protected RecyclerView.LayoutManager getLayoutManager() {
|
||||
switch (getResources().getConfiguration().orientation) {
|
||||
switch (getOrientation(getResources())) {
|
||||
case Configuration.ORIENTATION_LANDSCAPE:
|
||||
return new GridLayoutManager(getActivity(), LANDSCAPE_LAYOUT_COLUMNS);
|
||||
default:
|
||||
|
||||
@ -0,0 +1,16 @@
|
||||
package com.philliphsu.clock2.util;
|
||||
|
||||
import android.content.res.Resources;
|
||||
|
||||
/**
|
||||
* Created by Phillip Hsu on 8/30/2016.
|
||||
*/
|
||||
public final class ConfigurationUtils {
|
||||
|
||||
public static int getOrientation(Resources res) {
|
||||
return res.getConfiguration().orientation;
|
||||
}
|
||||
|
||||
private ConfigurationUtils() {}
|
||||
|
||||
}
|
||||
@ -26,15 +26,11 @@
|
||||
android:textSize="@dimen/text_size_display_3"
|
||||
style="@style/TextAppearance.AppCompat.Inverse"/>
|
||||
|
||||
<!-- Unfortunately, we can't reuse fragment_recycler_view
|
||||
- due to different padding requirements here. -->
|
||||
<android.support.v7.widget.RecyclerView
|
||||
android:id="@+id/list"
|
||||
<include layout="@layout/fragment_recycler_view"
|
||||
android:layout_width="0dp"
|
||||
android:layout_weight="1"
|
||||
android:layout_height="match_parent"
|
||||
android:scrollbars="vertical"
|
||||
android:paddingTop="8dp"/>
|
||||
android:layout_marginTop="8dp"/>
|
||||
|
||||
</LinearLayout>
|
||||
|
||||
|
||||
@ -3,9 +3,8 @@
|
||||
xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
xmlns:app="http://schemas.android.com/apk/res-auto"
|
||||
android:layout_marginBottom="8dp"
|
||||
android:layout_marginEnd="8dp">
|
||||
android:layout_marginBottom="@dimen/cardview_margin"
|
||||
android:layout_marginEnd="@dimen/cardview_margin">
|
||||
|
||||
<RelativeLayout
|
||||
android:layout_width="match_parent"
|
||||
@ -17,9 +16,9 @@
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_centerHorizontal="true"
|
||||
android:text="Label"
|
||||
android:textSize="17sp"
|
||||
android:layout_marginTop="8dp"
|
||||
android:layout_marginBottom="8dp"/>
|
||||
android:textSize="@dimen/text_size_medium"
|
||||
android:layout_marginTop="@dimen/item_margin_between_elements"
|
||||
android:layout_marginBottom="@dimen/item_margin_between_elements"/>
|
||||
|
||||
<com.philliphsu.clock2.timers.CountdownChronometer
|
||||
android:id="@+id/duration"
|
||||
@ -27,8 +26,8 @@
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_below="@id/label"
|
||||
android:layout_centerHorizontal="true"
|
||||
android:textSize="45sp"
|
||||
android:layout_marginBottom="8dp"/>
|
||||
android:textSize="@dimen/text_size_display_2"
|
||||
android:layout_marginBottom="@dimen/item_margin_between_elements"/>
|
||||
<!--TODO: Consider removing this bottom margin, because the seekbar
|
||||
is rendering with HUGE top and bottom padding already. -->
|
||||
|
||||
@ -44,18 +43,18 @@
|
||||
|
||||
<ImageButton
|
||||
android:id="@+id/add_one_minute"
|
||||
android:layout_width="48dp"
|
||||
android:layout_height="48dp"
|
||||
android:layout_width="@dimen/cardview_action_icon_size"
|
||||
android:layout_height="@dimen/cardview_action_icon_size"
|
||||
android:src="@drawable/ic_half_day_1_24dp"
|
||||
android:background="?selectableItemBackground"
|
||||
android:layout_below="@id/seek_bar"
|
||||
android:layout_alignParentStart="true"
|
||||
android:layout_marginStart="8dp"/>
|
||||
android:layout_marginStart="@dimen/cardview_action_icon_margin"/>
|
||||
|
||||
<ImageButton
|
||||
android:id="@+id/start_pause"
|
||||
android:layout_width="48dp"
|
||||
android:layout_height="48dp"
|
||||
android:layout_width="@dimen/cardview_action_icon_size"
|
||||
android:layout_height="@dimen/cardview_action_icon_size"
|
||||
android:src="@drawable/ic_half_day_1_24dp"
|
||||
android:background="?selectableItemBackground"
|
||||
android:layout_below="@id/seek_bar"
|
||||
@ -63,22 +62,19 @@
|
||||
|
||||
<ImageButton
|
||||
android:id="@+id/stop"
|
||||
android:layout_width="48dp"
|
||||
android:layout_height="48dp"
|
||||
android:layout_width="@dimen/cardview_action_icon_size"
|
||||
android:layout_height="@dimen/cardview_action_icon_size"
|
||||
android:src="@drawable/ic_half_day_1_24dp"
|
||||
android:background="?selectableItemBackground"
|
||||
android:layout_below="@id/seek_bar"
|
||||
android:layout_alignParentEnd="true"
|
||||
android:layout_marginEnd="8dp"/>
|
||||
android:layout_marginEnd="@dimen/cardview_action_icon_margin"/>
|
||||
|
||||
<Space
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="8dp"
|
||||
android:layout_height="@dimen/cardview_action_icon_margin"
|
||||
android:layout_below="@id/stop"/>
|
||||
|
||||
<!--<View style="@style/Divider.Horizontal"
|
||||
android:layout_below="@id/space"/>-->
|
||||
|
||||
</RelativeLayout>
|
||||
|
||||
</android.support.v7.widget.CardView>
|
||||
@ -4,6 +4,4 @@
|
||||
xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:scrollbars="vertical"
|
||||
android:paddingStart="8dp"
|
||||
android:paddingTop="8dp"/>
|
||||
android:scrollbars="vertical"/>
|
||||
|
||||
@ -20,14 +20,10 @@
|
||||
android:textSize="@dimen/text_size_display_3"
|
||||
style="@style/TextAppearance.AppCompat.Inverse"/>
|
||||
|
||||
<!-- Unfortunately, we can't reuse fragment_recycler_view
|
||||
- due to different padding requirements here. -->
|
||||
<android.support.v7.widget.RecyclerView
|
||||
android:id="@+id/list"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:scrollbars="vertical"
|
||||
android:paddingTop="8dp"/>
|
||||
<include layout="@layout/fragment_recycler_view"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:layout_marginTop="8dp"/>
|
||||
|
||||
</LinearLayout>
|
||||
|
||||
|
||||
@ -37,7 +37,7 @@
|
||||
android:layout_height="wrap_content"
|
||||
android:textAppearance="?textAppearanceListItem"
|
||||
android:text="in %dh %dm"
|
||||
android:layout_marginStart="4dp"
|
||||
android:layout_marginStart="@dimen/item_margin_between_elements"
|
||||
android:layout_below="@id/time_layout"
|
||||
android:layout_toEndOf="@id/label"/>
|
||||
|
||||
|
||||
@ -3,9 +3,9 @@
|
||||
xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
xmlns:app="http://schemas.android.com/apk/res-auto"
|
||||
android:layout_marginBottom="8dp"
|
||||
android:layout_marginEnd="8dp">
|
||||
android:layout_marginStart="@dimen/cardview_margin"
|
||||
android:layout_marginTop="@dimen/cardview_margin"
|
||||
android:layout_marginEnd="@dimen/cardview_margin">
|
||||
|
||||
<RelativeLayout
|
||||
android:layout_width="match_parent"
|
||||
@ -17,9 +17,9 @@
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_centerHorizontal="true"
|
||||
android:text="Label"
|
||||
android:textSize="17sp"
|
||||
android:layout_marginTop="8dp"
|
||||
android:layout_marginBottom="8dp"/>
|
||||
android:textSize="@dimen/text_size_medium"
|
||||
android:layout_marginTop="@dimen/item_margin_between_elements"
|
||||
android:layout_marginBottom="@dimen/item_margin_between_elements"/>
|
||||
|
||||
<com.philliphsu.clock2.timers.CountdownChronometer
|
||||
android:id="@+id/duration"
|
||||
@ -27,8 +27,8 @@
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_below="@id/label"
|
||||
android:layout_centerHorizontal="true"
|
||||
android:textSize="45sp"
|
||||
android:layout_marginBottom="8dp"/>
|
||||
android:textSize="@dimen/text_size_display_2"
|
||||
android:layout_marginBottom="@dimen/item_margin_between_elements"/>
|
||||
<!--TODO: Consider removing this bottom margin, because the seekbar
|
||||
is rendering with HUGE top and bottom padding already. -->
|
||||
|
||||
@ -44,18 +44,18 @@
|
||||
|
||||
<ImageButton
|
||||
android:id="@+id/add_one_minute"
|
||||
android:layout_width="48dp"
|
||||
android:layout_height="48dp"
|
||||
android:layout_width="@dimen/cardview_action_icon_size"
|
||||
android:layout_height="@dimen/cardview_action_icon_size"
|
||||
android:src="@drawable/ic_half_day_1_24dp"
|
||||
android:background="?selectableItemBackground"
|
||||
android:layout_below="@id/seek_bar"
|
||||
android:layout_alignParentStart="true"
|
||||
android:layout_marginStart="8dp"/>
|
||||
android:layout_marginStart="@dimen/cardview_action_icon_margin"/>
|
||||
|
||||
<ImageButton
|
||||
android:id="@+id/start_pause"
|
||||
android:layout_width="48dp"
|
||||
android:layout_height="48dp"
|
||||
android:layout_width="@dimen/cardview_action_icon_size"
|
||||
android:layout_height="@dimen/cardview_action_icon_size"
|
||||
android:src="@drawable/ic_half_day_1_24dp"
|
||||
android:background="?selectableItemBackground"
|
||||
android:layout_below="@id/seek_bar"
|
||||
@ -63,22 +63,19 @@
|
||||
|
||||
<ImageButton
|
||||
android:id="@+id/stop"
|
||||
android:layout_width="48dp"
|
||||
android:layout_height="48dp"
|
||||
android:layout_width="@dimen/cardview_action_icon_size"
|
||||
android:layout_height="@dimen/cardview_action_icon_size"
|
||||
android:src="@drawable/ic_half_day_1_24dp"
|
||||
android:background="?selectableItemBackground"
|
||||
android:layout_below="@id/seek_bar"
|
||||
android:layout_alignParentEnd="true"
|
||||
android:layout_marginEnd="8dp"/>
|
||||
android:layout_marginEnd="@dimen/cardview_action_icon_margin"/>
|
||||
|
||||
<Space
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="8dp"
|
||||
android:layout_height="@dimen/cardview_action_icon_margin"
|
||||
android:layout_below="@id/stop"/>
|
||||
|
||||
<!--<View style="@style/Divider.Horizontal"
|
||||
android:layout_below="@id/space"/>-->
|
||||
|
||||
</RelativeLayout>
|
||||
|
||||
</android.support.v7.widget.CardView>
|
||||
@ -47,6 +47,11 @@
|
||||
<dimen name="button_text_left_padding">16dp</dimen>
|
||||
<dimen name="button_text_right_padding">16dp</dimen>
|
||||
|
||||
<!-- CardView -->
|
||||
<dimen name="cardview_margin">8dp</dimen>
|
||||
<dimen name="cardview_action_icon_margin">8dp</dimen>
|
||||
<dimen name="cardview_action_icon_size">48dp</dimen>
|
||||
|
||||
<dimen name="text_size_body_1">14sp</dimen>
|
||||
<dimen name="text_size_body_2">14sp</dimen>
|
||||
<dimen name="text_size_button">14sp</dimen>
|
||||
|
||||
Loading…
Reference in New Issue
Block a user