Loading core/java/android/app/TimePickerDialog.java +1 −15 Original line number Diff line number Diff line Loading @@ -23,10 +23,8 @@ import android.os.Bundle; import android.util.TypedValue; import android.view.LayoutInflater; import android.view.View; import android.widget.Button; import android.widget.TimePicker; import android.widget.TimePicker.OnTimeChangedListener; import android.widget.TimePicker.ValidationCallback; import com.android.internal.R; Loading Loading @@ -64,7 +62,7 @@ public class TimePickerDialog extends AlertDialog implements OnClickListener, * @param hourOfDay the hour that was set * @param minute the minute that was set */ public void onTimeSet(TimePicker view, int hourOfDay, int minute); void onTimeSet(TimePicker view, int hourOfDay, int minute); } /** Loading Loading @@ -115,7 +113,6 @@ public class TimePickerDialog extends AlertDialog implements OnClickListener, final TypedValue outValue = new TypedValue(); context.getTheme().resolveAttribute(R.attr.timePickerDialogTheme, outValue, true); final int layoutResId = outValue.resourceId; final LayoutInflater inflater = LayoutInflater.from(themeContext); final View view = inflater.inflate(R.layout.time_picker_dialog, null); Loading @@ -129,7 +126,6 @@ public class TimePickerDialog extends AlertDialog implements OnClickListener, mTimePicker.setCurrentHour(mInitialHourOfDay); mTimePicker.setCurrentMinute(mInitialMinute); mTimePicker.setOnTimeChangedListener(this); mTimePicker.setValidationCallback(mValidationCallback); } @Override Loading Loading @@ -181,14 +177,4 @@ public class TimePickerDialog extends AlertDialog implements OnClickListener, mTimePicker.setCurrentHour(hour); mTimePicker.setCurrentMinute(minute); } private final ValidationCallback mValidationCallback = new ValidationCallback() { @Override public void onValidationChanged(boolean valid) { final Button positive = getButton(BUTTON_POSITIVE); if (positive != null) { positive.setEnabled(valid); } } }; } core/java/android/widget/TimePicker.java +20 −76 Original line number Diff line number Diff line Loading @@ -100,7 +100,7 @@ public class TimePicker extends FrameLayout { * @see #getHour() */ public void setHour(int hour) { mDelegate.setCurrentHour(hour); mDelegate.setHour(hour); } /** Loading @@ -110,7 +110,7 @@ public class TimePicker extends FrameLayout { * @see #setHour(int) */ public int getHour() { return mDelegate.getCurrentHour(); return mDelegate.getHour(); } /** Loading @@ -120,7 +120,7 @@ public class TimePicker extends FrameLayout { * @see #getMinute() */ public void setMinute(int minute) { mDelegate.setCurrentMinute(minute); mDelegate.setMinute(minute); } /** Loading @@ -130,7 +130,7 @@ public class TimePicker extends FrameLayout { * @see #setMinute(int) */ public int getMinute() { return mDelegate.getCurrentMinute(); return mDelegate.getMinute(); } /** Loading @@ -150,7 +150,7 @@ public class TimePicker extends FrameLayout { @NonNull @Deprecated public Integer getCurrentHour() { return mDelegate.getCurrentHour(); return mDelegate.getHour(); } /** Loading @@ -160,7 +160,7 @@ public class TimePicker extends FrameLayout { */ @Deprecated public void setCurrentMinute(@NonNull Integer currentMinute) { mDelegate.setCurrentMinute(currentMinute); mDelegate.setMinute(currentMinute); } /** Loading @@ -170,7 +170,7 @@ public class TimePicker extends FrameLayout { @NonNull @Deprecated public Integer getCurrentMinute() { return mDelegate.getCurrentMinute(); return mDelegate.getMinute(); } /** Loading @@ -186,7 +186,7 @@ public class TimePicker extends FrameLayout { return; } mDelegate.setIs24HourView(is24HourView); mDelegate.setIs24Hour(is24HourView); } /** Loading @@ -195,7 +195,7 @@ public class TimePicker extends FrameLayout { * @see #setIs24HourView(Boolean) */ public boolean is24HourView() { return mDelegate.is24HourView(); return mDelegate.is24Hour(); } /** Loading @@ -207,16 +207,6 @@ public class TimePicker extends FrameLayout { mDelegate.setOnTimeChangedListener(onTimeChangedListener); } /** * Sets the callback that indicates the current time is valid. * * @param callback the callback, may be null * @hide */ public void setValidationCallback(@Nullable ValidationCallback callback) { mDelegate.setValidationCallback(callback); } @Override public void setEnabled(boolean enabled) { super.setEnabled(enabled); Loading @@ -233,12 +223,6 @@ public class TimePicker extends FrameLayout { return mDelegate.getBaseline(); } @Override protected void onConfigurationChanged(Configuration newConfig) { super.onConfigurationChanged(newConfig); mDelegate.onConfigurationChanged(newConfig); } @Override protected Parcelable onSaveInstanceState() { Parcelable superState = super.onSaveInstanceState(); Loading Loading @@ -269,25 +253,22 @@ public class TimePicker extends FrameLayout { * for the real behavior. */ interface TimePickerDelegate { void setCurrentHour(int currentHour); int getCurrentHour(); void setHour(int hour); int getHour(); void setCurrentMinute(int currentMinute); int getCurrentMinute(); void setMinute(int minute); int getMinute(); void setIs24HourView(boolean is24HourView); boolean is24HourView(); void setIs24Hour(boolean is24Hour); boolean is24Hour(); void setOnTimeChangedListener(OnTimeChangedListener onTimeChangedListener); void setValidationCallback(ValidationCallback callback); void setEnabled(boolean enabled); boolean isEnabled(); int getBaseline(); void onConfigurationChanged(Configuration newConfig); Parcelable onSaveInstanceState(Parcelable superState); void onRestoreInstanceState(Parcelable state); Loading @@ -295,16 +276,6 @@ public class TimePicker extends FrameLayout { void onPopulateAccessibilityEvent(AccessibilityEvent event); } /** * A callback interface for updating input validity when the TimePicker * when included into a Dialog. * * @hide */ public static interface ValidationCallback { void onValidationChanged(boolean valid); } static String[] getAmPmStrings(Context context) { final Locale locale = context.getResources().getConfiguration().locale; final LocaleData d = LocaleData.get(locale); Loading @@ -319,43 +290,16 @@ public class TimePicker extends FrameLayout { * An abstract class which can be used as a start for TimePicker implementations */ abstract static class AbstractTimePickerDelegate implements TimePickerDelegate { // The delegator protected TimePicker mDelegator; protected final TimePicker mDelegator; protected final Context mContext; protected final Locale mLocale; // The context protected Context mContext; // The current locale protected Locale mCurrentLocale; // Callbacks protected OnTimeChangedListener mOnTimeChangedListener; protected ValidationCallback mValidationCallback; public AbstractTimePickerDelegate(TimePicker delegator, Context context) { public AbstractTimePickerDelegate(@NonNull TimePicker delegator, @NonNull Context context) { mDelegator = delegator; mContext = context; // initialization based on locale setCurrentLocale(Locale.getDefault()); } public void setCurrentLocale(Locale locale) { if (locale.equals(mCurrentLocale)) { return; } mCurrentLocale = locale; } @Override public void setValidationCallback(ValidationCallback callback) { mValidationCallback = callback; } protected void onValidationChanged(boolean valid) { if (mValidationCallback != null) { mValidationCallback.onValidationChanged(valid); } mLocale = context.getResources().getConfiguration().locale; } } } core/java/android/widget/TimePickerClockDelegate.java +63 −80 Original line number Diff line number Diff line Loading @@ -19,7 +19,6 @@ package android.widget; import android.annotation.Nullable; import android.content.Context; import android.content.res.ColorStateList; import android.content.res.Configuration; import android.content.res.Resources; import android.content.res.TypedArray; import android.os.Parcel; Loading Loading @@ -89,7 +88,7 @@ class TimePickerClockDelegate extends TimePicker.AbstractTimePickerDelegate impl private boolean mAllowAutoAdvance; private int mInitialHourOfDay; private int mInitialMinute; private boolean mIs24HourView; private boolean mIs24Hour; private boolean mIsAmPmAtStart; // Accessibility strings. Loading Loading @@ -200,19 +199,19 @@ class TimePickerClockDelegate extends TimePicker.AbstractTimePickerDelegate impl mAllowAutoAdvance = true; // Updates mHourFormat variables used below. updateHourFormat(mCurrentLocale, mIs24HourView); updateHourFormat(mLocale, mIs24Hour); // Update hour text field. final int minHour = mHourFormatStartsAtZero ? 0 : 1; final int maxHour = (mIs24HourView ? 23 : 11) + minHour; final int maxHour = (mIs24Hour ? 23 : 11) + minHour; mHourView.setRange(minHour, maxHour); mHourView.setShowLeadingZeroes(mHourFormatShowLeadingZero); // Initialize with current time. mTempCalendar = Calendar.getInstance(mCurrentLocale); mTempCalendar = Calendar.getInstance(mLocale); final int currentHour = mTempCalendar.get(Calendar.HOUR_OF_DAY); final int currentMinute = mTempCalendar.get(Calendar.MINUTE); initialize(currentHour, currentMinute, mIs24HourView, HOUR_INDEX); initialize(currentHour, currentMinute, mIs24Hour, HOUR_INDEX); } /** Loading Loading @@ -333,7 +332,7 @@ class TimePickerClockDelegate extends TimePicker.AbstractTimePickerDelegate impl private void initialize(int hourOfDay, int minute, boolean is24HourView, int index) { mInitialHourOfDay = hourOfDay; mInitialMinute = minute; mIs24HourView = is24HourView; mIs24Hour = is24HourView; updateUI(index); } Loading @@ -352,17 +351,16 @@ class TimePickerClockDelegate extends TimePicker.AbstractTimePickerDelegate impl } private void updateRadialPicker(int index) { mRadialTimePickerView.initialize(mInitialHourOfDay, mInitialMinute, mIs24HourView); mRadialTimePickerView.initialize(mInitialHourOfDay, mInitialMinute, mIs24Hour); setCurrentItemShowing(index, false, true); } private void updateHeaderAmPm() { if (mIs24HourView) { if (mIs24Hour) { mAmPmLayout.setVisibility(View.GONE); } else { // Ensure that AM/PM layout is in the correct position. final String dateTimePattern = DateFormat.getBestDateTimePattern(mCurrentLocale, "hm"); final String dateTimePattern = DateFormat.getBestDateTimePattern(mLocale, "hm"); final boolean isAmPmAtStart = dateTimePattern.startsWith("a"); setAmPmAtStart(isAmPmAtStart); Loading Loading @@ -395,84 +393,81 @@ class TimePickerClockDelegate extends TimePicker.AbstractTimePickerDelegate impl * Set the current hour. */ @Override public void setCurrentHour(int currentHour) { if (mInitialHourOfDay == currentHour) { return; } mInitialHourOfDay = currentHour; updateHeaderHour(currentHour, true); public void setHour(int hour) { if (mInitialHourOfDay != hour) { mInitialHourOfDay = hour; updateHeaderHour(hour, true); updateHeaderAmPm(); mRadialTimePickerView.setCurrentHour(currentHour); mRadialTimePickerView.setCurrentHour(hour); mRadialTimePickerView.setAmOrPm(mInitialHourOfDay < 12 ? AM : PM); mDelegator.invalidate(); onTimeChanged(); } } /** * @return The current hour in the range (0-23). * @return the current hour in the range (0-23) */ @Override public int getCurrentHour() { int currentHour = mRadialTimePickerView.getCurrentHour(); if (mIs24HourView) { public int getHour() { final int currentHour = mRadialTimePickerView.getCurrentHour(); if (mIs24Hour) { return currentHour; } else { switch(mRadialTimePickerView.getAmOrPm()) { case PM: } if (mRadialTimePickerView.getAmOrPm() == PM) { return (currentHour % HOURS_IN_HALF_DAY) + HOURS_IN_HALF_DAY; case AM: default: } else { return currentHour % HOURS_IN_HALF_DAY; } } } /** * Set the current minute (0-59). */ @Override public void setCurrentMinute(int currentMinute) { if (mInitialMinute == currentMinute) { return; } mInitialMinute = currentMinute; updateHeaderMinute(currentMinute, true); mRadialTimePickerView.setCurrentMinute(currentMinute); public void setMinute(int minute) { if (mInitialMinute != minute) { mInitialMinute = minute; updateHeaderMinute(minute, true); mRadialTimePickerView.setCurrentMinute(minute); mDelegator.invalidate(); onTimeChanged(); } } /** * @return The current minute. */ @Override public int getCurrentMinute() { public int getMinute() { return mRadialTimePickerView.getCurrentMinute(); } /** * Set whether in 24 hour or AM/PM mode. * Sets whether time is displayed in 24-hour mode or 12-hour mode with * AM/PM indicators. * * @param is24HourView True = 24 hour mode. False = AM/PM. * @param is24Hour {@code true} to display time in 24-hour mode or * {@code false} for 12-hour mode with AM/PM */ @Override public void setIs24HourView(boolean is24HourView) { if (is24HourView == mIs24HourView) { return; } mIs24HourView = is24HourView; mInitialHourOfDay = getCurrentHour(); public void setIs24Hour(boolean is24Hour) { if (mIs24Hour != is24Hour) { mIs24Hour = is24Hour; mInitialHourOfDay = getHour(); updateUI(mRadialTimePickerView.getCurrentItemShowing()); } } /** * @return true if this is in 24 hour view else false. * @return {@code true} if time is displayed in 24-hour mode, or * {@code false} if time is displayed in 12-hour mode with AM/PM * indicators */ @Override public boolean is24HourView() { return mIs24HourView; public boolean is24Hour() { return mIs24Hour; } @Override Loading Loading @@ -501,15 +496,10 @@ class TimePickerClockDelegate extends TimePicker.AbstractTimePickerDelegate impl return -1; } @Override public void onConfigurationChanged(Configuration newConfig) { updateUI(mRadialTimePickerView.getCurrentItemShowing()); } @Override public Parcelable onSaveInstanceState(Parcelable superState) { return new SavedState(superState, getCurrentHour(), getCurrentMinute(), is24HourView(), getCurrentItemShowing()); return new SavedState(superState, getHour(), getMinute(), is24Hour(), getCurrentItemShowing()); } @Override Loading @@ -519,12 +509,6 @@ class TimePickerClockDelegate extends TimePicker.AbstractTimePickerDelegate impl mRadialTimePickerView.invalidate(); } @Override public void setCurrentLocale(Locale locale) { super.setCurrentLocale(locale); mTempCalendar = Calendar.getInstance(locale); } @Override public boolean dispatchPopulateAccessibilityEvent(AccessibilityEvent event) { onPopulateAccessibilityEvent(event); Loading @@ -534,13 +518,13 @@ class TimePickerClockDelegate extends TimePicker.AbstractTimePickerDelegate impl @Override public void onPopulateAccessibilityEvent(AccessibilityEvent event) { int flags = DateUtils.FORMAT_SHOW_TIME; if (mIs24HourView) { if (mIs24Hour) { flags |= DateUtils.FORMAT_24HOUR; } else { flags |= DateUtils.FORMAT_12HOUR; } mTempCalendar.set(Calendar.HOUR_OF_DAY, getCurrentHour()); mTempCalendar.set(Calendar.MINUTE, getCurrentMinute()); mTempCalendar.set(Calendar.HOUR_OF_DAY, getHour()); mTempCalendar.set(Calendar.MINUTE, getMinute()); String selectedDate = DateUtils.formatDateTime(mContext, mTempCalendar.getTimeInMillis(), flags); event.getText().add(selectedDate); Loading @@ -559,8 +543,7 @@ class TimePickerClockDelegate extends TimePicker.AbstractTimePickerDelegate impl private void onTimeChanged() { mDelegator.sendAccessibilityEvent(AccessibilityEvent.TYPE_VIEW_SELECTED); if (mOnTimeChangedListener != null) { mOnTimeChangedListener.onTimeChanged(mDelegator, getCurrentHour(), getCurrentMinute()); mOnTimeChangedListener.onTimeChanged(mDelegator, getHour(), getMinute()); } } Loading Loading @@ -666,7 +649,7 @@ class TimePickerClockDelegate extends TimePicker.AbstractTimePickerDelegate impl } if (mOnTimeChangedListener != null) { mOnTimeChangedListener.onTimeChanged(mDelegator, getCurrentHour(), getCurrentMinute()); mOnTimeChangedListener.onTimeChanged(mDelegator, getHour(), getMinute()); } } Loading @@ -677,14 +660,14 @@ class TimePickerClockDelegate extends TimePicker.AbstractTimePickerDelegate impl * @return a localized hour number */ private int getLocalizedHour(int hourOfDay) { if (!mIs24HourView) { if (!mIs24Hour) { // Convert to hour-of-am-pm. hourOfDay %= 12; } if (!mHourFormatStartsAtZero && hourOfDay == 0) { // Convert to clock-hour (either of-day or of-am-pm). hourOfDay = mIs24HourView ? 24 : 12; hourOfDay = mIs24Hour ? 24 : 12; } return hourOfDay; Loading Loading @@ -716,8 +699,8 @@ class TimePickerClockDelegate extends TimePicker.AbstractTimePickerDelegate impl * separator as the character which is just after the hour marker in the returned pattern. */ private void updateHeaderSeparator() { final String bestDateTimePattern = DateFormat.getBestDateTimePattern(mCurrentLocale, (mIs24HourView) ? "Hm" : "hm"); final String bestDateTimePattern = DateFormat.getBestDateTimePattern(mLocale, (mIs24Hour) ? "Hm" : "hm"); final String separatorText; // See http://www.unicode.org/reports/tr35/tr35-dates.html for hour formats final char[] hourFormats = {'H', 'h', 'K', 'k'}; Loading Loading @@ -819,14 +802,14 @@ class TimePickerClockDelegate extends TimePicker.AbstractTimePickerDelegate impl private final Runnable mCommitHour = new Runnable() { @Override public void run() { setCurrentHour(mHourView.getValue()); setHour(mHourView.getValue()); } }; private final Runnable mCommitMinute = new Runnable() { @Override public void run() { setCurrentMinute(mMinuteView.getValue()); setMinute(mMinuteView.getValue()); } }; Loading core/java/android/widget/TimePickerSpinnerDelegate.java +33 −52 File changed.Preview size limit exceeded, changes collapsed. Show changes Loading
core/java/android/app/TimePickerDialog.java +1 −15 Original line number Diff line number Diff line Loading @@ -23,10 +23,8 @@ import android.os.Bundle; import android.util.TypedValue; import android.view.LayoutInflater; import android.view.View; import android.widget.Button; import android.widget.TimePicker; import android.widget.TimePicker.OnTimeChangedListener; import android.widget.TimePicker.ValidationCallback; import com.android.internal.R; Loading Loading @@ -64,7 +62,7 @@ public class TimePickerDialog extends AlertDialog implements OnClickListener, * @param hourOfDay the hour that was set * @param minute the minute that was set */ public void onTimeSet(TimePicker view, int hourOfDay, int minute); void onTimeSet(TimePicker view, int hourOfDay, int minute); } /** Loading Loading @@ -115,7 +113,6 @@ public class TimePickerDialog extends AlertDialog implements OnClickListener, final TypedValue outValue = new TypedValue(); context.getTheme().resolveAttribute(R.attr.timePickerDialogTheme, outValue, true); final int layoutResId = outValue.resourceId; final LayoutInflater inflater = LayoutInflater.from(themeContext); final View view = inflater.inflate(R.layout.time_picker_dialog, null); Loading @@ -129,7 +126,6 @@ public class TimePickerDialog extends AlertDialog implements OnClickListener, mTimePicker.setCurrentHour(mInitialHourOfDay); mTimePicker.setCurrentMinute(mInitialMinute); mTimePicker.setOnTimeChangedListener(this); mTimePicker.setValidationCallback(mValidationCallback); } @Override Loading Loading @@ -181,14 +177,4 @@ public class TimePickerDialog extends AlertDialog implements OnClickListener, mTimePicker.setCurrentHour(hour); mTimePicker.setCurrentMinute(minute); } private final ValidationCallback mValidationCallback = new ValidationCallback() { @Override public void onValidationChanged(boolean valid) { final Button positive = getButton(BUTTON_POSITIVE); if (positive != null) { positive.setEnabled(valid); } } }; }
core/java/android/widget/TimePicker.java +20 −76 Original line number Diff line number Diff line Loading @@ -100,7 +100,7 @@ public class TimePicker extends FrameLayout { * @see #getHour() */ public void setHour(int hour) { mDelegate.setCurrentHour(hour); mDelegate.setHour(hour); } /** Loading @@ -110,7 +110,7 @@ public class TimePicker extends FrameLayout { * @see #setHour(int) */ public int getHour() { return mDelegate.getCurrentHour(); return mDelegate.getHour(); } /** Loading @@ -120,7 +120,7 @@ public class TimePicker extends FrameLayout { * @see #getMinute() */ public void setMinute(int minute) { mDelegate.setCurrentMinute(minute); mDelegate.setMinute(minute); } /** Loading @@ -130,7 +130,7 @@ public class TimePicker extends FrameLayout { * @see #setMinute(int) */ public int getMinute() { return mDelegate.getCurrentMinute(); return mDelegate.getMinute(); } /** Loading @@ -150,7 +150,7 @@ public class TimePicker extends FrameLayout { @NonNull @Deprecated public Integer getCurrentHour() { return mDelegate.getCurrentHour(); return mDelegate.getHour(); } /** Loading @@ -160,7 +160,7 @@ public class TimePicker extends FrameLayout { */ @Deprecated public void setCurrentMinute(@NonNull Integer currentMinute) { mDelegate.setCurrentMinute(currentMinute); mDelegate.setMinute(currentMinute); } /** Loading @@ -170,7 +170,7 @@ public class TimePicker extends FrameLayout { @NonNull @Deprecated public Integer getCurrentMinute() { return mDelegate.getCurrentMinute(); return mDelegate.getMinute(); } /** Loading @@ -186,7 +186,7 @@ public class TimePicker extends FrameLayout { return; } mDelegate.setIs24HourView(is24HourView); mDelegate.setIs24Hour(is24HourView); } /** Loading @@ -195,7 +195,7 @@ public class TimePicker extends FrameLayout { * @see #setIs24HourView(Boolean) */ public boolean is24HourView() { return mDelegate.is24HourView(); return mDelegate.is24Hour(); } /** Loading @@ -207,16 +207,6 @@ public class TimePicker extends FrameLayout { mDelegate.setOnTimeChangedListener(onTimeChangedListener); } /** * Sets the callback that indicates the current time is valid. * * @param callback the callback, may be null * @hide */ public void setValidationCallback(@Nullable ValidationCallback callback) { mDelegate.setValidationCallback(callback); } @Override public void setEnabled(boolean enabled) { super.setEnabled(enabled); Loading @@ -233,12 +223,6 @@ public class TimePicker extends FrameLayout { return mDelegate.getBaseline(); } @Override protected void onConfigurationChanged(Configuration newConfig) { super.onConfigurationChanged(newConfig); mDelegate.onConfigurationChanged(newConfig); } @Override protected Parcelable onSaveInstanceState() { Parcelable superState = super.onSaveInstanceState(); Loading Loading @@ -269,25 +253,22 @@ public class TimePicker extends FrameLayout { * for the real behavior. */ interface TimePickerDelegate { void setCurrentHour(int currentHour); int getCurrentHour(); void setHour(int hour); int getHour(); void setCurrentMinute(int currentMinute); int getCurrentMinute(); void setMinute(int minute); int getMinute(); void setIs24HourView(boolean is24HourView); boolean is24HourView(); void setIs24Hour(boolean is24Hour); boolean is24Hour(); void setOnTimeChangedListener(OnTimeChangedListener onTimeChangedListener); void setValidationCallback(ValidationCallback callback); void setEnabled(boolean enabled); boolean isEnabled(); int getBaseline(); void onConfigurationChanged(Configuration newConfig); Parcelable onSaveInstanceState(Parcelable superState); void onRestoreInstanceState(Parcelable state); Loading @@ -295,16 +276,6 @@ public class TimePicker extends FrameLayout { void onPopulateAccessibilityEvent(AccessibilityEvent event); } /** * A callback interface for updating input validity when the TimePicker * when included into a Dialog. * * @hide */ public static interface ValidationCallback { void onValidationChanged(boolean valid); } static String[] getAmPmStrings(Context context) { final Locale locale = context.getResources().getConfiguration().locale; final LocaleData d = LocaleData.get(locale); Loading @@ -319,43 +290,16 @@ public class TimePicker extends FrameLayout { * An abstract class which can be used as a start for TimePicker implementations */ abstract static class AbstractTimePickerDelegate implements TimePickerDelegate { // The delegator protected TimePicker mDelegator; protected final TimePicker mDelegator; protected final Context mContext; protected final Locale mLocale; // The context protected Context mContext; // The current locale protected Locale mCurrentLocale; // Callbacks protected OnTimeChangedListener mOnTimeChangedListener; protected ValidationCallback mValidationCallback; public AbstractTimePickerDelegate(TimePicker delegator, Context context) { public AbstractTimePickerDelegate(@NonNull TimePicker delegator, @NonNull Context context) { mDelegator = delegator; mContext = context; // initialization based on locale setCurrentLocale(Locale.getDefault()); } public void setCurrentLocale(Locale locale) { if (locale.equals(mCurrentLocale)) { return; } mCurrentLocale = locale; } @Override public void setValidationCallback(ValidationCallback callback) { mValidationCallback = callback; } protected void onValidationChanged(boolean valid) { if (mValidationCallback != null) { mValidationCallback.onValidationChanged(valid); } mLocale = context.getResources().getConfiguration().locale; } } }
core/java/android/widget/TimePickerClockDelegate.java +63 −80 Original line number Diff line number Diff line Loading @@ -19,7 +19,6 @@ package android.widget; import android.annotation.Nullable; import android.content.Context; import android.content.res.ColorStateList; import android.content.res.Configuration; import android.content.res.Resources; import android.content.res.TypedArray; import android.os.Parcel; Loading Loading @@ -89,7 +88,7 @@ class TimePickerClockDelegate extends TimePicker.AbstractTimePickerDelegate impl private boolean mAllowAutoAdvance; private int mInitialHourOfDay; private int mInitialMinute; private boolean mIs24HourView; private boolean mIs24Hour; private boolean mIsAmPmAtStart; // Accessibility strings. Loading Loading @@ -200,19 +199,19 @@ class TimePickerClockDelegate extends TimePicker.AbstractTimePickerDelegate impl mAllowAutoAdvance = true; // Updates mHourFormat variables used below. updateHourFormat(mCurrentLocale, mIs24HourView); updateHourFormat(mLocale, mIs24Hour); // Update hour text field. final int minHour = mHourFormatStartsAtZero ? 0 : 1; final int maxHour = (mIs24HourView ? 23 : 11) + minHour; final int maxHour = (mIs24Hour ? 23 : 11) + minHour; mHourView.setRange(minHour, maxHour); mHourView.setShowLeadingZeroes(mHourFormatShowLeadingZero); // Initialize with current time. mTempCalendar = Calendar.getInstance(mCurrentLocale); mTempCalendar = Calendar.getInstance(mLocale); final int currentHour = mTempCalendar.get(Calendar.HOUR_OF_DAY); final int currentMinute = mTempCalendar.get(Calendar.MINUTE); initialize(currentHour, currentMinute, mIs24HourView, HOUR_INDEX); initialize(currentHour, currentMinute, mIs24Hour, HOUR_INDEX); } /** Loading Loading @@ -333,7 +332,7 @@ class TimePickerClockDelegate extends TimePicker.AbstractTimePickerDelegate impl private void initialize(int hourOfDay, int minute, boolean is24HourView, int index) { mInitialHourOfDay = hourOfDay; mInitialMinute = minute; mIs24HourView = is24HourView; mIs24Hour = is24HourView; updateUI(index); } Loading @@ -352,17 +351,16 @@ class TimePickerClockDelegate extends TimePicker.AbstractTimePickerDelegate impl } private void updateRadialPicker(int index) { mRadialTimePickerView.initialize(mInitialHourOfDay, mInitialMinute, mIs24HourView); mRadialTimePickerView.initialize(mInitialHourOfDay, mInitialMinute, mIs24Hour); setCurrentItemShowing(index, false, true); } private void updateHeaderAmPm() { if (mIs24HourView) { if (mIs24Hour) { mAmPmLayout.setVisibility(View.GONE); } else { // Ensure that AM/PM layout is in the correct position. final String dateTimePattern = DateFormat.getBestDateTimePattern(mCurrentLocale, "hm"); final String dateTimePattern = DateFormat.getBestDateTimePattern(mLocale, "hm"); final boolean isAmPmAtStart = dateTimePattern.startsWith("a"); setAmPmAtStart(isAmPmAtStart); Loading Loading @@ -395,84 +393,81 @@ class TimePickerClockDelegate extends TimePicker.AbstractTimePickerDelegate impl * Set the current hour. */ @Override public void setCurrentHour(int currentHour) { if (mInitialHourOfDay == currentHour) { return; } mInitialHourOfDay = currentHour; updateHeaderHour(currentHour, true); public void setHour(int hour) { if (mInitialHourOfDay != hour) { mInitialHourOfDay = hour; updateHeaderHour(hour, true); updateHeaderAmPm(); mRadialTimePickerView.setCurrentHour(currentHour); mRadialTimePickerView.setCurrentHour(hour); mRadialTimePickerView.setAmOrPm(mInitialHourOfDay < 12 ? AM : PM); mDelegator.invalidate(); onTimeChanged(); } } /** * @return The current hour in the range (0-23). * @return the current hour in the range (0-23) */ @Override public int getCurrentHour() { int currentHour = mRadialTimePickerView.getCurrentHour(); if (mIs24HourView) { public int getHour() { final int currentHour = mRadialTimePickerView.getCurrentHour(); if (mIs24Hour) { return currentHour; } else { switch(mRadialTimePickerView.getAmOrPm()) { case PM: } if (mRadialTimePickerView.getAmOrPm() == PM) { return (currentHour % HOURS_IN_HALF_DAY) + HOURS_IN_HALF_DAY; case AM: default: } else { return currentHour % HOURS_IN_HALF_DAY; } } } /** * Set the current minute (0-59). */ @Override public void setCurrentMinute(int currentMinute) { if (mInitialMinute == currentMinute) { return; } mInitialMinute = currentMinute; updateHeaderMinute(currentMinute, true); mRadialTimePickerView.setCurrentMinute(currentMinute); public void setMinute(int minute) { if (mInitialMinute != minute) { mInitialMinute = minute; updateHeaderMinute(minute, true); mRadialTimePickerView.setCurrentMinute(minute); mDelegator.invalidate(); onTimeChanged(); } } /** * @return The current minute. */ @Override public int getCurrentMinute() { public int getMinute() { return mRadialTimePickerView.getCurrentMinute(); } /** * Set whether in 24 hour or AM/PM mode. * Sets whether time is displayed in 24-hour mode or 12-hour mode with * AM/PM indicators. * * @param is24HourView True = 24 hour mode. False = AM/PM. * @param is24Hour {@code true} to display time in 24-hour mode or * {@code false} for 12-hour mode with AM/PM */ @Override public void setIs24HourView(boolean is24HourView) { if (is24HourView == mIs24HourView) { return; } mIs24HourView = is24HourView; mInitialHourOfDay = getCurrentHour(); public void setIs24Hour(boolean is24Hour) { if (mIs24Hour != is24Hour) { mIs24Hour = is24Hour; mInitialHourOfDay = getHour(); updateUI(mRadialTimePickerView.getCurrentItemShowing()); } } /** * @return true if this is in 24 hour view else false. * @return {@code true} if time is displayed in 24-hour mode, or * {@code false} if time is displayed in 12-hour mode with AM/PM * indicators */ @Override public boolean is24HourView() { return mIs24HourView; public boolean is24Hour() { return mIs24Hour; } @Override Loading Loading @@ -501,15 +496,10 @@ class TimePickerClockDelegate extends TimePicker.AbstractTimePickerDelegate impl return -1; } @Override public void onConfigurationChanged(Configuration newConfig) { updateUI(mRadialTimePickerView.getCurrentItemShowing()); } @Override public Parcelable onSaveInstanceState(Parcelable superState) { return new SavedState(superState, getCurrentHour(), getCurrentMinute(), is24HourView(), getCurrentItemShowing()); return new SavedState(superState, getHour(), getMinute(), is24Hour(), getCurrentItemShowing()); } @Override Loading @@ -519,12 +509,6 @@ class TimePickerClockDelegate extends TimePicker.AbstractTimePickerDelegate impl mRadialTimePickerView.invalidate(); } @Override public void setCurrentLocale(Locale locale) { super.setCurrentLocale(locale); mTempCalendar = Calendar.getInstance(locale); } @Override public boolean dispatchPopulateAccessibilityEvent(AccessibilityEvent event) { onPopulateAccessibilityEvent(event); Loading @@ -534,13 +518,13 @@ class TimePickerClockDelegate extends TimePicker.AbstractTimePickerDelegate impl @Override public void onPopulateAccessibilityEvent(AccessibilityEvent event) { int flags = DateUtils.FORMAT_SHOW_TIME; if (mIs24HourView) { if (mIs24Hour) { flags |= DateUtils.FORMAT_24HOUR; } else { flags |= DateUtils.FORMAT_12HOUR; } mTempCalendar.set(Calendar.HOUR_OF_DAY, getCurrentHour()); mTempCalendar.set(Calendar.MINUTE, getCurrentMinute()); mTempCalendar.set(Calendar.HOUR_OF_DAY, getHour()); mTempCalendar.set(Calendar.MINUTE, getMinute()); String selectedDate = DateUtils.formatDateTime(mContext, mTempCalendar.getTimeInMillis(), flags); event.getText().add(selectedDate); Loading @@ -559,8 +543,7 @@ class TimePickerClockDelegate extends TimePicker.AbstractTimePickerDelegate impl private void onTimeChanged() { mDelegator.sendAccessibilityEvent(AccessibilityEvent.TYPE_VIEW_SELECTED); if (mOnTimeChangedListener != null) { mOnTimeChangedListener.onTimeChanged(mDelegator, getCurrentHour(), getCurrentMinute()); mOnTimeChangedListener.onTimeChanged(mDelegator, getHour(), getMinute()); } } Loading Loading @@ -666,7 +649,7 @@ class TimePickerClockDelegate extends TimePicker.AbstractTimePickerDelegate impl } if (mOnTimeChangedListener != null) { mOnTimeChangedListener.onTimeChanged(mDelegator, getCurrentHour(), getCurrentMinute()); mOnTimeChangedListener.onTimeChanged(mDelegator, getHour(), getMinute()); } } Loading @@ -677,14 +660,14 @@ class TimePickerClockDelegate extends TimePicker.AbstractTimePickerDelegate impl * @return a localized hour number */ private int getLocalizedHour(int hourOfDay) { if (!mIs24HourView) { if (!mIs24Hour) { // Convert to hour-of-am-pm. hourOfDay %= 12; } if (!mHourFormatStartsAtZero && hourOfDay == 0) { // Convert to clock-hour (either of-day or of-am-pm). hourOfDay = mIs24HourView ? 24 : 12; hourOfDay = mIs24Hour ? 24 : 12; } return hourOfDay; Loading Loading @@ -716,8 +699,8 @@ class TimePickerClockDelegate extends TimePicker.AbstractTimePickerDelegate impl * separator as the character which is just after the hour marker in the returned pattern. */ private void updateHeaderSeparator() { final String bestDateTimePattern = DateFormat.getBestDateTimePattern(mCurrentLocale, (mIs24HourView) ? "Hm" : "hm"); final String bestDateTimePattern = DateFormat.getBestDateTimePattern(mLocale, (mIs24Hour) ? "Hm" : "hm"); final String separatorText; // See http://www.unicode.org/reports/tr35/tr35-dates.html for hour formats final char[] hourFormats = {'H', 'h', 'K', 'k'}; Loading Loading @@ -819,14 +802,14 @@ class TimePickerClockDelegate extends TimePicker.AbstractTimePickerDelegate impl private final Runnable mCommitHour = new Runnable() { @Override public void run() { setCurrentHour(mHourView.getValue()); setHour(mHourView.getValue()); } }; private final Runnable mCommitMinute = new Runnable() { @Override public void run() { setCurrentMinute(mMinuteView.getValue()); setMinute(mMinuteView.getValue()); } }; Loading
core/java/android/widget/TimePickerSpinnerDelegate.java +33 −52 File changed.Preview size limit exceeded, changes collapsed. Show changes