diff options
| author | Svetoslav Ganov <svetoslavganov@google.com> | 2011-07-12 12:26:20 -0700 |
|---|---|---|
| committer | Svetoslav Ganov <svetoslavganov@google.com> | 2011-07-12 14:15:37 -0700 |
| commit | f5926962cc665d4a2e6464f9ba9e3e9788496a6f (patch) | |
| tree | 7e0e4abdbf012834b896c0a9dade1f8e7e92adf9 /core/java/android/widget/TimePicker.java | |
| parent | f81673d7670cb1978933a1599de7a2cb39f58b38 (diff) | |
Date/time pickers and calendar view not handling locale change.
1. The data/time pickers and calendar view do not handle locale
change properly since they use cached Calendar instances to
limit the GC but fail to update them when the local changes.
Change-Id: I2a92d7f4e0f2798422843123e5aa483f8044bbed
Diffstat (limited to 'core/java/android/widget/TimePicker.java')
| -rw-r--r-- | core/java/android/widget/TimePicker.java | 28 |
1 files changed, 26 insertions, 2 deletions
diff --git a/core/java/android/widget/TimePicker.java b/core/java/android/widget/TimePicker.java index 423e735c787b..05474382613d 100644 --- a/core/java/android/widget/TimePicker.java +++ b/core/java/android/widget/TimePicker.java @@ -20,6 +20,7 @@ import com.android.internal.R; import android.annotation.Widget; import android.content.Context; +import android.content.res.Configuration; import android.content.res.TypedArray; import android.os.Parcel; import android.os.Parcelable; @@ -32,6 +33,7 @@ import android.widget.NumberPicker.OnValueChangeListener; import java.text.DateFormatSymbols; import java.util.Calendar; +import java.util.Locale; /** * A view for selecting the time of day, in either 24 hour or AM/PM mode. The @@ -92,6 +94,8 @@ public class TimePicker extends FrameLayout { private Calendar mTempCalendar; + private Locale mCurrentLocale; + /** * The callback interface used to indicate the time has been adjusted. */ @@ -116,6 +120,9 @@ public class TimePicker extends FrameLayout { public TimePicker(Context context, AttributeSet attrs, int defStyle) { super(context, attrs, defStyle); + // initialization based on locale + setCurrentLocale(Locale.getDefault()); + // process style attributes TypedArray attributesArray = context.obtainStyledAttributes( attrs, R.styleable.TimePicker, defStyle, 0); @@ -211,8 +218,6 @@ public class TimePicker extends FrameLayout { updateHourControl(); updateAmPmControl(); - // initialize to current time - mTempCalendar = Calendar.getInstance(); setOnTimeChangedListener(NO_OP_CHANGE_LISTENER); // set to current time @@ -248,6 +253,25 @@ public class TimePicker extends FrameLayout { return mIsEnabled; } + @Override + protected void onConfigurationChanged(Configuration newConfig) { + super.onConfigurationChanged(newConfig); + setCurrentLocale(newConfig.locale); + } + + /** + * Sets the current locale. + * + * @param locale The current locale. + */ + private void setCurrentLocale(Locale locale) { + if (locale.equals(mCurrentLocale)) { + return; + } + mCurrentLocale = locale; + mTempCalendar = Calendar.getInstance(locale); + } + /** * Used to save / restore state of time picker */ |
