Loading core/java/android/app/DatePickerDialog.java +16 −7 Original line number Diff line number Diff line Loading @@ -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); Loading @@ -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, Loading Loading @@ -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(); Loading core/java/android/app/TimePickerDialog.java +16 −8 Original line number Diff line number Diff line Loading @@ -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); Loading @@ -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) { Loading @@ -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(); Loading core/java/android/widget/NumberPicker.java +50 −10 Original line number Diff line number Diff line Loading @@ -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. Loading @@ -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. Loading Loading @@ -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 { Loading Loading @@ -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 { Loading Loading @@ -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. */ Loading core/res/res/layout/date_picker_holo.xml +6 −0 Original line number Diff line number Diff line Loading @@ -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" Loading @@ -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" Loading @@ -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" Loading core/res/res/layout/time_picker_holo.xml +6 −0 Original line number Diff line number Diff line Loading @@ -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" Loading @@ -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" Loading @@ -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" Loading Loading
core/java/android/app/DatePickerDialog.java +16 −7 Original line number Diff line number Diff line Loading @@ -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); Loading @@ -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, Loading Loading @@ -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(); Loading
core/java/android/app/TimePickerDialog.java +16 −8 Original line number Diff line number Diff line Loading @@ -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); Loading @@ -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) { Loading @@ -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(); Loading
core/java/android/widget/NumberPicker.java +50 −10 Original line number Diff line number Diff line Loading @@ -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. Loading @@ -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. Loading Loading @@ -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 { Loading Loading @@ -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 { Loading Loading @@ -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. */ Loading
core/res/res/layout/date_picker_holo.xml +6 −0 Original line number Diff line number Diff line Loading @@ -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" Loading @@ -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" Loading @@ -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" Loading
core/res/res/layout/time_picker_holo.xml +6 −0 Original line number Diff line number Diff line Loading @@ -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" Loading @@ -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" Loading @@ -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" Loading