Increased tap target size of buttons
This commit is contained in:
parent
1162e9177c
commit
e2df1aef28
@ -45,6 +45,8 @@ import java.util.Locale;
|
|||||||
import butterknife.Bind;
|
import butterknife.Bind;
|
||||||
import butterknife.OnClick;
|
import butterknife.OnClick;
|
||||||
|
|
||||||
|
import static com.philliphsu.clock2.util.ConversionUtils.dpToPx;
|
||||||
|
|
||||||
//import com.android.datetimepicker.HapticFeedbackController;
|
//import com.android.datetimepicker.HapticFeedbackController;
|
||||||
//import com.android.datetimepicker.R;
|
//import com.android.datetimepicker.R;
|
||||||
//import com.android.datetimepicker.Utils;
|
//import com.android.datetimepicker.Utils;
|
||||||
@ -129,8 +131,10 @@ public class NumberGridTimePickerDialog extends BaseTimePickerDialog /*DialogFra
|
|||||||
private static final int[] HOURS_24_HALF_DAY_1 = {0,1,2,3,4,5,6,7,8,9,10,11};
|
private static final int[] HOURS_24_HALF_DAY_1 = {0,1,2,3,4,5,6,7,8,9,10,11};
|
||||||
private static final int[] HOURS_24_HALF_DAY_2 = {12,13,14,15,16,17,18,19,20,21,22,23};
|
private static final int[] HOURS_24_HALF_DAY_2 = {12,13,14,15,16,17,18,19,20,21,22,23};
|
||||||
private static final int[] MINUTES = {0,5,10,15,20,25,30,35,40,45,50,55};
|
private static final int[] MINUTES = {0,5,10,15,20,25,30,35,40,45,50,55};
|
||||||
// The delay before a OnLongClick on a TwentyFourHourGridItem defers to OnClick
|
// The delay in ms before a OnLongClick on a TwentyFourHourGridItem defers to OnClick
|
||||||
private static final int LONG_CLICK_RESULT_LEEWAY = 150;
|
private static final int LONG_CLICK_RESULT_LEEWAY = 150;
|
||||||
|
// The padding in dp for the half day icon compound drawable
|
||||||
|
public static final int HALF_DAY_ICON_PADDING = 8;
|
||||||
|
|
||||||
// TODO: Private?
|
// TODO: Private?
|
||||||
// Describes both AM/PM in the 12-hour clock and the half-days of the 24-hour clock.
|
// Describes both AM/PM in the 12-hour clock and the half-days of the 24-hour clock.
|
||||||
@ -267,15 +271,16 @@ public class NumberGridTimePickerDialog extends BaseTimePickerDialog /*DialogFra
|
|||||||
((TwentyFourHourGridItem) v).swapTexts();
|
((TwentyFourHourGridItem) v).swapTexts();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// TODO: Verify the corresponding TwentyFourHourGridItem retains its indicator
|
// TODO: Verify the corresponding TwentyFourHourGridItem retains its indicator
|
||||||
if (amOrPm == HALF_DAY_1) {
|
if (amOrPm == HALF_DAY_1) {
|
||||||
mSelectedHourOfDay -= 12;
|
mSelectedHourOfDay %= 12;
|
||||||
} else if (amOrPm == HALF_DAY_2) {
|
} else if (amOrPm == HALF_DAY_2) {
|
||||||
mSelectedHourOfDay += 12;
|
mSelectedHourOfDay = (mSelectedHourOfDay % 12) + 12;
|
||||||
}
|
}
|
||||||
onValueSelected(HOUR_INDEX, mSelectedHourOfDay, false);
|
onValueSelected(HOUR_INDEX, mSelectedHourOfDay, false);
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
// TODO: Break this into two OnClickListeners instead--one for normal TextViews and
|
// TODO: Break this into two OnClickListeners instead--one for normal TextViews and
|
||||||
// the other for TwentyFourHourGridItem.
|
// the other for TwentyFourHourGridItem.
|
||||||
@ -454,13 +459,15 @@ public class NumberGridTimePickerDialog extends BaseTimePickerDialog /*DialogFra
|
|||||||
TextView tv1 = (TextView) mLeftHalfDayToggle.getChildAt(0);
|
TextView tv1 = (TextView) mLeftHalfDayToggle.getChildAt(0);
|
||||||
TextView tv2 = (TextView) mRightHalfDayToggle.getChildAt(0);
|
TextView tv2 = (TextView) mRightHalfDayToggle.getChildAt(0);
|
||||||
if (mIs24HourMode) {
|
if (mIs24HourMode) {
|
||||||
tv1.setText("00-11");
|
tv1.setText("00 - 11");
|
||||||
// Intrinsic bounds meaning the drawable's own bounds? So 24dp box.
|
// Intrinsic bounds meaning the drawable's own bounds? So 24dp box.
|
||||||
tv1.setCompoundDrawablesWithIntrinsicBounds(
|
tv1.setCompoundDrawablesWithIntrinsicBounds(
|
||||||
R.drawable.ic_half_day_1_black_24dp, 0, 0, 0);
|
R.drawable.ic_half_day_1_black_24dp, 0, 0, 0);
|
||||||
tv2.setText("12-23");
|
tv1.setCompoundDrawablePadding((int) dpToPx(getActivity(), HALF_DAY_ICON_PADDING));
|
||||||
|
tv2.setText("12 - 23");
|
||||||
tv2.setCompoundDrawablesWithIntrinsicBounds(
|
tv2.setCompoundDrawablesWithIntrinsicBounds(
|
||||||
R.drawable.ic_half_day_2_black_24dp, 0, 0, 0);
|
R.drawable.ic_half_day_2_black_24dp, 0, 0, 0);
|
||||||
|
tv2.setCompoundDrawablePadding((int) dpToPx(getActivity(), HALF_DAY_ICON_PADDING));
|
||||||
} else {
|
} else {
|
||||||
tv1.setText(mAmText);
|
tv1.setText(mAmText);
|
||||||
tv2.setText(mPmText);
|
tv2.setText(mPmText);
|
||||||
|
|||||||
@ -0,0 +1,27 @@
|
|||||||
|
package com.philliphsu.clock2.util;
|
||||||
|
|
||||||
|
import android.content.Context;
|
||||||
|
import android.support.annotation.NonNull;
|
||||||
|
import android.util.TypedValue;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Created by Phillip Hsu on 4/21/2016.
|
||||||
|
*/
|
||||||
|
public final class ConversionUtils {
|
||||||
|
|
||||||
|
public static float dpToPx(@NonNull final Context context, final float dp) {
|
||||||
|
return toPx(context, TypedValue.COMPLEX_UNIT_DIP, dp);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static float spToPx(@NonNull final Context context, final float sp) {
|
||||||
|
return toPx(context, TypedValue.COMPLEX_UNIT_SP, sp);
|
||||||
|
}
|
||||||
|
|
||||||
|
private static float toPx(@NonNull final Context context, final int unit, final float val) {
|
||||||
|
// This always returns a floating point value, i.e. pixels.
|
||||||
|
return TypedValue.applyDimension(unit, val, context.getResources().getDisplayMetrics());
|
||||||
|
}
|
||||||
|
|
||||||
|
private ConversionUtils() {}
|
||||||
|
|
||||||
|
}
|
||||||
@ -3,17 +3,11 @@
|
|||||||
xmlns:app="http://schemas.android.com/apk/res-auto">
|
xmlns:app="http://schemas.android.com/apk/res-auto">
|
||||||
<!-- TODO: Use fixed width and height -->
|
<!-- TODO: Use fixed width and height -->
|
||||||
<ImageButton
|
<ImageButton
|
||||||
android:layout_width="wrap_content"
|
|
||||||
android:layout_height="wrap_content"
|
|
||||||
style="@style/GridLayoutNumpadElement"
|
style="@style/GridLayoutNumpadElement"
|
||||||
android:src="@drawable/ic_minus_circle_24dp"
|
android:src="@drawable/ic_minus_circle_24dp"
|
||||||
app:layout_gravity="center"
|
|
||||||
app:layout_column="1"/>
|
app:layout_column="1"/>
|
||||||
<ImageButton
|
<ImageButton
|
||||||
android:layout_width="wrap_content"
|
|
||||||
android:layout_height="wrap_content"
|
|
||||||
style="@style/GridLayoutNumpadElement"
|
style="@style/GridLayoutNumpadElement"
|
||||||
android:src="@drawable/ic_add_circle_24dp"
|
android:src="@drawable/ic_add_circle_24dp"
|
||||||
app:layout_gravity="center"
|
|
||||||
app:layout_column="2"/>
|
app:layout_column="2"/>
|
||||||
</merge>
|
</merge>
|
||||||
@ -52,7 +52,6 @@
|
|||||||
<TextView
|
<TextView
|
||||||
android:layout_width="wrap_content"
|
android:layout_width="wrap_content"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:drawablePadding="8dp"
|
|
||||||
android:gravity="center"
|
android:gravity="center"
|
||||||
android:layout_gravity="center"
|
android:layout_gravity="center"
|
||||||
style="@style/TextAppearance.AppCompat.Button"
|
style="@style/TextAppearance.AppCompat.Button"
|
||||||
@ -70,7 +69,6 @@
|
|||||||
<TextView
|
<TextView
|
||||||
android:layout_width="wrap_content"
|
android:layout_width="wrap_content"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:drawablePadding="8dp"
|
|
||||||
android:gravity="center"
|
android:gravity="center"
|
||||||
android:layout_gravity="center"
|
android:layout_gravity="center"
|
||||||
style="@style/TextAppearance.AppCompat.Button"
|
style="@style/TextAppearance.AppCompat.Button"
|
||||||
|
|||||||
@ -4,9 +4,6 @@
|
|||||||
|
|
||||||
<!-- TODO: Define a grid item style with the first 3 attrs-->
|
<!-- TODO: Define a grid item style with the first 3 attrs-->
|
||||||
<com.philliphsu.clock2.editalarm.TwentyFourHourGridItem
|
<com.philliphsu.clock2.editalarm.TwentyFourHourGridItem
|
||||||
android:layout_width="wrap_content"
|
|
||||||
android:layout_height="wrap_content"
|
|
||||||
app:layout_gravity="center"
|
|
||||||
style="@style/GridLayoutNumpadElement"/>
|
style="@style/GridLayoutNumpadElement"/>
|
||||||
|
|
||||||
</merge>
|
</merge>
|
||||||
@ -2,12 +2,9 @@
|
|||||||
<merge xmlns:android="http://schemas.android.com/apk/res/android"
|
<merge xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
xmlns:app="http://schemas.android.com/apk/res-auto">
|
xmlns:app="http://schemas.android.com/apk/res-auto">
|
||||||
|
|
||||||
<!-- TODO: Define another style with LWW and LHW -->
|
|
||||||
<!-- TODO: Use a fixed height so the circular indicator doesn't stretch into an oval. -->
|
<!-- TODO: Use a fixed height so the circular indicator doesn't stretch into an oval. -->
|
||||||
<TextView
|
<!-- Or measure the text dimensions and use the larger of its width and height, plus some
|
||||||
android:layout_width="wrap_content"
|
small integer extra, and use that as the diameter of the circle indicator. -->
|
||||||
android:layout_height="wrap_content"
|
<TextView style="@style/GridLayoutNumpadButton"/>
|
||||||
style="@style/GridLayoutNumpadButton"
|
|
||||||
app:layout_gravity="center"/>
|
|
||||||
|
|
||||||
</merge>
|
</merge>
|
||||||
@ -34,6 +34,7 @@
|
|||||||
<item name="layout_columnWeight">1</item>
|
<item name="layout_columnWeight">1</item>
|
||||||
<item name="layout_rowWeight">1</item>
|
<item name="layout_rowWeight">1</item>
|
||||||
<item name="android:background">?android:attr/selectableItemBackground</item>
|
<item name="android:background">?android:attr/selectableItemBackground</item>
|
||||||
|
<item name="android:gravity">center</item>
|
||||||
</style>
|
</style>
|
||||||
|
|
||||||
<!-- TODO: Rename to GridLayout[Text/Button/TextView]? -->
|
<!-- TODO: Rename to GridLayout[Text/Button/TextView]? -->
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user