24 hour grid fit to landscape mode
This commit is contained in:
parent
742d5f3b1e
commit
2d4d661d7f
@ -19,6 +19,7 @@ package com.philliphsu.clock2.editalarm;
|
|||||||
import android.animation.ObjectAnimator;
|
import android.animation.ObjectAnimator;
|
||||||
import android.app.ActionBar.LayoutParams;
|
import android.app.ActionBar.LayoutParams;
|
||||||
import android.content.res.ColorStateList;
|
import android.content.res.ColorStateList;
|
||||||
|
import android.content.res.Configuration;
|
||||||
import android.content.res.Resources;
|
import android.content.res.Resources;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
import android.support.design.widget.FloatingActionButton;
|
import android.support.design.widget.FloatingActionButton;
|
||||||
@ -318,17 +319,29 @@ public class NumberGridTimePickerDialog extends BaseTimePickerDialog implements
|
|||||||
if (mIs24HourMode) {
|
if (mIs24HourMode) {
|
||||||
final int iconPadding = getResources().getDimensionPixelSize(R.dimen.half_day_icon_padding);
|
final int iconPadding = getResources().getDimensionPixelSize(R.dimen.half_day_icon_padding);
|
||||||
tv1.setText("00 - 11");
|
tv1.setText("00 - 11");
|
||||||
// Intrinsic bounds meaning the drawable's own bounds? So 24dp box.
|
tv2.setText("12 - 23");
|
||||||
// We need different drawable resources for each case, not a single one that we
|
// We need different drawable resources for each case, not a single one that we
|
||||||
// just tint differently, because the orientation of each one is different.
|
// just tint differently, because the orientation of each one is different.
|
||||||
tv1.setCompoundDrawablesWithIntrinsicBounds(
|
final int icon1 = mThemeDark? R.drawable.ic_half_day_1_dark_24dp : R.drawable.ic_half_day_1_24dp;
|
||||||
mThemeDark? R.drawable.ic_half_day_1_dark_24dp : R.drawable.ic_half_day_1_24dp,
|
final int icon2 = mThemeDark? R.drawable.ic_half_day_2_dark_24dp : R.drawable.ic_half_day_2_24dp;
|
||||||
0, 0, 0);
|
// Determine the direction the icons should be in
|
||||||
|
int left1 = 0, left2 = 0, top1 = 0, top2 = 0;
|
||||||
|
switch (getResources().getConfiguration().orientation) {
|
||||||
|
case Configuration.ORIENTATION_PORTRAIT:
|
||||||
|
left1 = icon1;
|
||||||
|
left2 = icon2;
|
||||||
|
top1 = top2 = 0;
|
||||||
|
break;
|
||||||
|
case Configuration.ORIENTATION_LANDSCAPE:
|
||||||
|
left1 = left2 = 0;
|
||||||
|
top1 = icon1;
|
||||||
|
top2 = icon2;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
// Intrinsic bounds means the drawable's own bounds? So 24dp box.
|
||||||
|
tv1.setCompoundDrawablesWithIntrinsicBounds(left1, top1, 0, 0);
|
||||||
|
tv2.setCompoundDrawablesWithIntrinsicBounds(left2, top2, 0, 0);
|
||||||
tv1.setCompoundDrawablePadding(iconPadding);
|
tv1.setCompoundDrawablePadding(iconPadding);
|
||||||
tv2.setText("12 - 23");
|
|
||||||
tv2.setCompoundDrawablesWithIntrinsicBounds(
|
|
||||||
mThemeDark? R.drawable.ic_half_day_2_dark_24dp : R.drawable.ic_half_day_2_24dp,
|
|
||||||
0, 0, 0);
|
|
||||||
tv2.setCompoundDrawablePadding(iconPadding);
|
tv2.setCompoundDrawablePadding(iconPadding);
|
||||||
} else {
|
} else {
|
||||||
tv1.setText(mAmText);
|
tv1.setText(mAmText);
|
||||||
|
|||||||
@ -1,6 +1,7 @@
|
|||||||
package com.philliphsu.clock2.editalarm;
|
package com.philliphsu.clock2.editalarm;
|
||||||
|
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
|
import android.content.res.Configuration;
|
||||||
import android.content.res.TypedArray;
|
import android.content.res.TypedArray;
|
||||||
import android.util.AttributeSet;
|
import android.util.AttributeSet;
|
||||||
import android.view.Gravity;
|
import android.view.Gravity;
|
||||||
@ -69,7 +70,9 @@ public class TwentyFourHourGridItem extends LinearLayout {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private void init() {
|
private void init() {
|
||||||
setOrientation(VERTICAL);
|
final int orientation = getResources().getConfiguration().orientation;
|
||||||
|
setOrientation(orientation == Configuration.ORIENTATION_PORTRAIT ?
|
||||||
|
VERTICAL : /*LANDSCAPE*/HORIZONTAL);
|
||||||
setGravity(Gravity.CENTER);
|
setGravity(Gravity.CENTER);
|
||||||
inflate(getContext(), R.layout.content_24h_grid_item, this);
|
inflate(getContext(), R.layout.content_24h_grid_item, this);
|
||||||
ButterKnife.bind(this);
|
ButterKnife.bind(this);
|
||||||
|
|||||||
22
app/src/main/res/layout-land/content_24h_grid_item.xml
Normal file
22
app/src/main/res/layout-land/content_24h_grid_item.xml
Normal file
@ -0,0 +1,22 @@
|
|||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<merge xmlns:android="http://schemas.android.com/apk/res/android">
|
||||||
|
|
||||||
|
<!-- TODO: Define styles -->
|
||||||
|
|
||||||
|
<TextView
|
||||||
|
android:id="@+id/primary"
|
||||||
|
android:layout_width="wrap_content"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:fontFamily="sans-serif-light"
|
||||||
|
android:textSize="@dimen/number_grid_24_hour_item_primary_text_size"
|
||||||
|
android:includeFontPadding="false"
|
||||||
|
style="@style/TextAppearance.AppCompat"
|
||||||
|
android:layout_marginEnd="6dp"/>
|
||||||
|
|
||||||
|
<TextView
|
||||||
|
android:id="@+id/secondary"
|
||||||
|
android:layout_width="wrap_content"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:includeFontPadding="false"/>
|
||||||
|
|
||||||
|
</merge>
|
||||||
@ -16,7 +16,7 @@
|
|||||||
<dimen name="number_grid_minute_cell_height">44dp</dimen>
|
<dimen name="number_grid_minute_cell_height">44dp</dimen>
|
||||||
<!--TODO: Change the height suffix to size or dimen, because this is used as a width in landscape and a height in portrait. -->
|
<!--TODO: Change the height suffix to size or dimen, because this is used as a width in landscape and a height in portrait. -->
|
||||||
<dimen name="half_day_button_bar_height">64dp</dimen>
|
<dimen name="half_day_button_bar_height">64dp</dimen>
|
||||||
<dimen name="number_grid_24_hour_item_primary_text_size">30sp</dimen>
|
<dimen name="number_grid_24_hour_item_primary_text_size">26sp</dimen>
|
||||||
<dimen name="number_grid_minute_text_size">20sp</dimen>
|
<dimen name="number_grid_minute_text_size">20sp</dimen>
|
||||||
|
|
||||||
</resources>
|
</resources>
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user