diff options
| -rw-r--r-- | core/java/android/app/DatePickerDialog.java | 23 | ||||
| -rw-r--r-- | core/java/android/app/TimePickerDialog.java | 24 | ||||
| -rw-r--r-- | core/java/android/widget/NumberPicker.java | 60 | ||||
| -rw-r--r-- | core/res/res/layout/date_picker_holo.xml | 6 | ||||
| -rw-r--r-- | core/res/res/layout/time_picker_holo.xml | 6 | ||||
| -rw-r--r-- | core/res/res/values/public.xml | 1 | ||||
| -rwxr-xr-x | core/res/res/values/strings.xml | 2 | ||||
| -rw-r--r-- | core/res/res/values/styles.xml | 2 |
8 files changed, 98 insertions, 26 deletions
diff --git a/core/java/android/app/DatePickerDialog.java b/core/java/android/app/DatePickerDialog.java index bf8fde00ed6e..c62e5cf60466 100644 --- a/core/java/android/app/DatePickerDialog.java +++ b/core/java/android/app/DatePickerDialog.java @@ -92,8 +92,7 @@ public class DatePickerDialog extends AlertDialog implements OnClickListener, mCallBack = callBack; Context themeContext = getContext(); - setButton(BUTTON_POSITIVE, themeContext.getText(R.string.date_time_set), this); - setButton(BUTTON_NEGATIVE, themeContext.getText(R.string.cancel), (OnClickListener) null); + setButton(BUTTON_POSITIVE, themeContext.getText(R.string.date_time_done), this); setIcon(0); setTitle(R.string.date_picker_dialog_title); @@ -106,11 +105,7 @@ public class DatePickerDialog extends AlertDialog implements OnClickListener, } public void onClick(DialogInterface dialog, int which) { - if (mCallBack != null) { - mDatePicker.clearFocus(); - mCallBack.onDateSet(mDatePicker, mDatePicker.getYear(), - mDatePicker.getMonth(), mDatePicker.getDayOfMonth()); - } + tryNotifyDateSet(); } public void onDateChanged(DatePicker view, int year, @@ -138,6 +133,20 @@ public class DatePickerDialog extends AlertDialog implements OnClickListener, mDatePicker.updateDate(year, monthOfYear, dayOfMonth); } + private void tryNotifyDateSet() { + if (mCallBack != null) { + mDatePicker.clearFocus(); + mCallBack.onDateSet(mDatePicker, mDatePicker.getYear(), + mDatePicker.getMonth(), mDatePicker.getDayOfMonth()); + } + } + + @Override + protected void onStop() { + tryNotifyDateSet(); + super.onStop(); + } + @Override public Bundle onSaveInstanceState() { Bundle state = super.onSaveInstanceState(); diff --git a/core/java/android/app/TimePickerDialog.java b/core/java/android/app/TimePickerDialog.java index 353b41522162..d773bc8a444d 100644 --- a/core/java/android/app/TimePickerDialog.java +++ b/core/java/android/app/TimePickerDialog.java @@ -96,9 +96,7 @@ public class TimePickerDialog extends AlertDialog setTitle(R.string.time_picker_dialog_title); Context themeContext = getContext(); - setButton(BUTTON_POSITIVE, themeContext.getText(R.string.date_time_set), this); - setButton(BUTTON_NEGATIVE, themeContext.getText(R.string.cancel), - (OnClickListener) null); + setButton(BUTTON_POSITIVE, themeContext.getText(R.string.date_time_done), this); LayoutInflater inflater = (LayoutInflater) themeContext.getSystemService(Context.LAYOUT_INFLATER_SERVICE); @@ -114,11 +112,7 @@ public class TimePickerDialog extends AlertDialog } public void onClick(DialogInterface dialog, int which) { - if (mCallback != null) { - mTimePicker.clearFocus(); - mCallback.onTimeSet(mTimePicker, mTimePicker.getCurrentHour(), - mTimePicker.getCurrentMinute()); - } + tryNotifyTimeSet(); } public void updateTime(int hourOfDay, int minutOfHour) { @@ -130,6 +124,20 @@ public class TimePickerDialog extends AlertDialog /* do nothing */ } + private void tryNotifyTimeSet() { + if (mCallback != null) { + mTimePicker.clearFocus(); + mCallback.onTimeSet(mTimePicker, mTimePicker.getCurrentHour(), + mTimePicker.getCurrentMinute()); + } + } + + @Override + protected void onStop() { + tryNotifyTimeSet(); + super.onStop(); + } + @Override public Bundle onSaveInstanceState() { Bundle state = super.onSaveInstanceState(); diff --git a/core/java/android/widget/NumberPicker.java b/core/java/android/widget/NumberPicker.java index 4e56cd6a46ee..d897a39ce08c 100644 --- a/core/java/android/widget/NumberPicker.java +++ b/core/java/android/widget/NumberPicker.java @@ -112,10 +112,10 @@ public class NumberPicker extends LinearLayout { private static final int SELECTOR_ADJUSTMENT_DURATION_MILLIS = 800; /** - * The duration of scrolling to the next/previous value while changing the - * current value by one, i.e. increment or decrement. + * The duration of scrolling to the next/previous value while snapping to + * a given position. */ - private static final int CHANGE_CURRENT_BY_ONE_SCROLL_DURATION = 300; + private static final int SNAP_SCROLL_DURATION = 300; /** * The strength of fading in the top and bottom while drawing the selector. @@ -140,7 +140,7 @@ public class NumberPicker extends LinearLayout { /** * Coefficient for adjusting touch scroll distance. */ - private static final float TOUCH_SCROLL_DECELERATION_COEFFICIENT = 2.5f; + private static final float TOUCH_SCROLL_DECELERATION_COEFFICIENT = 2.0f; /** * The resource id for the default layout. @@ -152,7 +152,7 @@ public class NumberPicker extends LinearLayout { */ private static final char[] DIGIT_CHARACTERS = new char[] { '0', '1', '2', '3', '4', '5', '6', '7', '8', '9' - }; + }; /** * Constant for unspecified size. @@ -838,7 +838,13 @@ public class NumberPicker extends LinearLayout { if (absDeltaMoveY > mMinFlingDistance) { fling(initialVelocity); } else { - changeValueByOne(deltaMove < 0); + final int normalizedDeltaMove = + (int) (absDeltaMoveY / TOUCH_SCROLL_DECELERATION_COEFFICIENT); + if (normalizedDeltaMove < mSelectorElementHeight) { + snapToNextValue(deltaMove < 0); + } else { + snapToClosestValue(); + } } onScrollStateChange(OnScrollListener.SCROLL_STATE_FLING); } else { @@ -1509,11 +1515,9 @@ public class NumberPicker extends LinearLayout { } mPreviousScrollerY = 0; if (increment) { - mFlingScroller.startScroll(0, 0, 0, -mSelectorElementHeight, - CHANGE_CURRENT_BY_ONE_SCROLL_DURATION); + mFlingScroller.startScroll(0, 0, 0, -mSelectorElementHeight, SNAP_SCROLL_DURATION); } else { - mFlingScroller.startScroll(0, 0, 0, mSelectorElementHeight, - CHANGE_CURRENT_BY_ONE_SCROLL_DURATION); + mFlingScroller.startScroll(0, 0, 0, mSelectorElementHeight, SNAP_SCROLL_DURATION); } invalidate(); } else { @@ -1902,6 +1906,42 @@ public class NumberPicker extends LinearLayout { return false; } + private void snapToNextValue(boolean increment) { + int deltaY = mCurrentScrollOffset - mInitialScrollOffset; + int amountToScroll = 0; + if (deltaY != 0) { + mPreviousScrollerY = 0; + if (deltaY > 0) { + if (increment) { + amountToScroll = - deltaY; + } else { + amountToScroll = mSelectorElementHeight - deltaY; + } + } else { + if (increment) { + amountToScroll = - mSelectorElementHeight - deltaY; + } else { + amountToScroll = - deltaY; + } + } + mFlingScroller.startScroll(0, 0, 0, amountToScroll, SNAP_SCROLL_DURATION); + invalidate(); + } + } + + private void snapToClosestValue() { + // adjust to the closest value + int deltaY = mInitialScrollOffset - mCurrentScrollOffset; + if (deltaY != 0) { + mPreviousScrollerY = 0; + if (Math.abs(deltaY) > mSelectorElementHeight / 2) { + deltaY += (deltaY > 0) ? -mSelectorElementHeight : mSelectorElementHeight; + } + mFlingScroller.startScroll(0, 0, 0, deltaY, SNAP_SCROLL_DURATION); + invalidate(); + } + } + /** * Command for setting the input text selection. */ diff --git a/core/res/res/layout/date_picker_holo.xml b/core/res/res/layout/date_picker_holo.xml index 57b5614b4ee3..122a61ade4c3 100644 --- a/core/res/res/layout/date_picker_holo.xml +++ b/core/res/res/layout/date_picker_holo.xml @@ -41,6 +41,8 @@ android:id="@+id/month" android:layout_width="wrap_content" android:layout_height="wrap_content" + android:layout_marginTop="10dip" + android:layout_marginBottom="10dip" android:layout_marginLeft="16dip" android:layout_marginRight="16dip" android:focusable="true" @@ -52,6 +54,8 @@ android:id="@+id/day" android:layout_width="wrap_content" android:layout_height="wrap_content" + android:layout_marginTop="10dip" + android:layout_marginBottom="10dip" android:layout_marginLeft="16dip" android:layout_marginRight="16dip" android:focusable="true" @@ -63,6 +67,8 @@ android:id="@+id/year" android:layout_width="wrap_content" android:layout_height="wrap_content" + android:layout_marginTop="10dip" + android:layout_marginBottom="10dip" android:layout_marginLeft="16dip" android:layout_marginRight="16dip" android:focusable="true" diff --git a/core/res/res/layout/time_picker_holo.xml b/core/res/res/layout/time_picker_holo.xml index 29c97b71af93..24b61949f9a9 100644 --- a/core/res/res/layout/time_picker_holo.xml +++ b/core/res/res/layout/time_picker_holo.xml @@ -30,6 +30,8 @@ android:id="@+id/hour" android:layout_width="wrap_content" android:layout_height="wrap_content" + android:layout_marginTop="10dip" + android:layout_marginBottom="10dip" android:layout_marginLeft="16dip" android:layout_marginRight="14dip" android:focusable="true" @@ -49,6 +51,8 @@ android:id="@+id/minute" android:layout_width="wrap_content" android:layout_height="wrap_content" + android:layout_marginTop="10dip" + android:layout_marginBottom="10dip" android:layout_marginLeft="14dip" android:layout_marginRight="16dip" android:focusable="true" @@ -60,6 +64,8 @@ android:id="@+id/amPm" android:layout_width="wrap_content" android:layout_height="wrap_content" + android:layout_marginTop="10dip" + android:layout_marginBottom="10dip" android:layout_marginLeft="16dip" android:layout_marginRight="16dip" android:focusable="true" diff --git a/core/res/res/values/public.xml b/core/res/res/values/public.xml index b60cda7e1a72..9f296303a66d 100644 --- a/core/res/res/values/public.xml +++ b/core/res/res/values/public.xml @@ -421,6 +421,7 @@ <java-symbol type="string" name="date_picker_increment_year_button" /> <java-symbol type="string" name="date_time" /> <java-symbol type="string" name="date_time_set" /> + <java-symbol type="string" name="date_time_done" /> <java-symbol type="string" name="day_of_week_long_friday" /> <java-symbol type="string" name="day_of_week_long_monday" /> <java-symbol type="string" name="day_of_week_long_saturday" /> diff --git a/core/res/res/values/strings.xml b/core/res/res/values/strings.xml index 89196642b471..718de0a52129 100755 --- a/core/res/res/values/strings.xml +++ b/core/res/res/values/strings.xml @@ -2816,6 +2816,8 @@ <string name="date_picker_dialog_title">Set date</string> <!-- Name of the button in the date/time picker to accept the date/time change --> <string name="date_time_set">Set</string> + <!-- Name of the button in the date/time picker to accept the date/time change --> + <string name="date_time_done">Done</string> <!-- Security Permissions strings--> <!-- The default permission group for any permissions that have not explicitly set a group. --> diff --git a/core/res/res/values/styles.xml b/core/res/res/values/styles.xml index 288b8b2a1f57..baeb9cc82cbf 100644 --- a/core/res/res/values/styles.xml +++ b/core/res/res/values/styles.xml @@ -1643,7 +1643,7 @@ please see styles_device_defaults.xml. <item name="android:selectionDividerHeight">2dip</item> <item name="android:selectionDividersDistance">48dip</item> <item name="android:internalMinWidth">48dip</item> - <item name="android:internalMaxHeight">200dip</item> + <item name="android:internalMaxHeight">180dip</item> <item name="android:minFlingDistance">150dip</item> </style> |