Increased tap target size of buttons

This commit is contained in:
Phillip Hsu 2016-07-24 00:20:12 -07:00
parent 1162e9177c
commit e2df1aef28
7 changed files with 48 additions and 27 deletions

View File

@ -45,6 +45,8 @@ import java.util.Locale;
import butterknife.Bind;
import butterknife.OnClick;
import static com.philliphsu.clock2.util.ConversionUtils.dpToPx;
//import com.android.datetimepicker.HapticFeedbackController;
//import com.android.datetimepicker.R;
//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_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};
// 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;
// The padding in dp for the half day icon compound drawable
public static final int HALF_DAY_ICON_PADDING = 8;
// TODO: Private?
// Describes both AM/PM in the 12-hour clock and the half-days of the 24-hour clock.
@ -267,14 +271,15 @@ public class NumberGridTimePickerDialog extends BaseTimePickerDialog /*DialogFra
((TwentyFourHourGridItem) v).swapTexts();
}
}
// TODO: Verify the corresponding TwentyFourHourGridItem retains its indicator
if (amOrPm == HALF_DAY_1) {
mSelectedHourOfDay -= 12;
} else if (amOrPm == HALF_DAY_2) {
mSelectedHourOfDay += 12;
}
onValueSelected(HOUR_INDEX, mSelectedHourOfDay, false);
}
// TODO: Verify the corresponding TwentyFourHourGridItem retains its indicator
if (amOrPm == HALF_DAY_1) {
mSelectedHourOfDay %= 12;
} else if (amOrPm == HALF_DAY_2) {
mSelectedHourOfDay = (mSelectedHourOfDay % 12) + 12;
}
onValueSelected(HOUR_INDEX, mSelectedHourOfDay, false);
}
// TODO: Break this into two OnClickListeners instead--one for normal TextViews and
@ -454,13 +459,15 @@ public class NumberGridTimePickerDialog extends BaseTimePickerDialog /*DialogFra
TextView tv1 = (TextView) mLeftHalfDayToggle.getChildAt(0);
TextView tv2 = (TextView) mRightHalfDayToggle.getChildAt(0);
if (mIs24HourMode) {
tv1.setText("00-11");
tv1.setText("00 - 11");
// Intrinsic bounds meaning the drawable's own bounds? So 24dp box.
tv1.setCompoundDrawablesWithIntrinsicBounds(
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(
R.drawable.ic_half_day_2_black_24dp, 0, 0, 0);
tv2.setCompoundDrawablePadding((int) dpToPx(getActivity(), HALF_DAY_ICON_PADDING));
} else {
tv1.setText(mAmText);
tv2.setText(mPmText);

View File

@ -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() {}
}

View File

@ -3,17 +3,11 @@
xmlns:app="http://schemas.android.com/apk/res-auto">
<!-- TODO: Use fixed width and height -->
<ImageButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
style="@style/GridLayoutNumpadElement"
android:src="@drawable/ic_minus_circle_24dp"
app:layout_gravity="center"
app:layout_column="1"/>
<ImageButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
style="@style/GridLayoutNumpadElement"
android:src="@drawable/ic_add_circle_24dp"
app:layout_gravity="center"
app:layout_column="2"/>
</merge>

View File

@ -52,7 +52,6 @@
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:drawablePadding="8dp"
android:gravity="center"
android:layout_gravity="center"
style="@style/TextAppearance.AppCompat.Button"
@ -70,7 +69,6 @@
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:drawablePadding="8dp"
android:gravity="center"
android:layout_gravity="center"
style="@style/TextAppearance.AppCompat.Button"

View File

@ -4,9 +4,6 @@
<!-- TODO: Define a grid item style with the first 3 attrs-->
<com.philliphsu.clock2.editalarm.TwentyFourHourGridItem
android:layout_width="wrap_content"
android:layout_height="wrap_content"
app:layout_gravity="center"
style="@style/GridLayoutNumpadElement"/>
</merge>

View File

@ -2,12 +2,9 @@
<merge xmlns:android="http://schemas.android.com/apk/res/android"
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. -->
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
style="@style/GridLayoutNumpadButton"
app:layout_gravity="center"/>
<!-- Or measure the text dimensions and use the larger of its width and height, plus some
small integer extra, and use that as the diameter of the circle indicator. -->
<TextView style="@style/GridLayoutNumpadButton"/>
</merge>

View File

@ -34,6 +34,7 @@
<item name="layout_columnWeight">1</item>
<item name="layout_rowWeight">1</item>
<item name="android:background">?android:attr/selectableItemBackground</item>
<item name="android:gravity">center</item>
</style>
<!-- TODO: Rename to GridLayout[Text/Button/TextView]? -->