diff options
| author | 2016-02-17 18:54:17 +0000 | |
|---|---|---|
| committer | 2016-02-17 18:54:17 +0000 | |
| commit | aa9c9fb29e0630f252fb60e1972d333bbc54d70d (patch) | |
| tree | 1ab1d21102edf3666697da11b689a5786eb1f675 | |
| parent | 3381cde9f293c52f195b31b0e4049649db31181a (diff) | |
Replace SimpleDateFormat implementation
This will process all the classes and replace all the uses of
java.text.DateFormat and java.text.SimpleDateFormat with the
android.icu.text. package implementations. The original ones do not
match the Android platform behaviour.
Change-Id: Id55f103c21117a8d6403bf2124b6c1a0e1fb2f71
3 files changed, 4 insertions, 103 deletions
diff --git a/tools/layoutlib/bridge/src/android/widget/SimpleMonthView_Delegate.java b/tools/layoutlib/bridge/src/android/widget/SimpleMonthView_Delegate.java deleted file mode 100644 index 8e41e5162513..000000000000 --- a/tools/layoutlib/bridge/src/android/widget/SimpleMonthView_Delegate.java +++ /dev/null @@ -1,99 +0,0 @@ -/* - * Copyright (C) 2015 The Android Open Source Project - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package android.widget; - -import com.android.tools.layoutlib.annotations.LayoutlibDelegate; - -import android.annotation.NonNull; -import android.annotation.Nullable; -import android.icu.text.SimpleDateFormat; -import android.text.format.DateFormat; - -import java.util.Calendar; -import java.util.Locale; - -/** - * Delegate that provides implementation for some methods in {@link SimpleMonthView}. - * <p/> - * Through the layoutlib_create tool, selected methods of SimpleMonthView have been replaced by - * calls to methods of the same name in this delegate class. - * <p/> - * The main purpose of this class is to use {@link android.icu.text.SimpleDateFormat} instead of - * {@link java.text.SimpleDateFormat}. - */ -public class SimpleMonthView_Delegate { - - private static final String DEFAULT_TITLE_FORMAT = "MMMMy"; - private static final String DAY_OF_WEEK_FORMAT = "EEEEE"; - - // Maintain a cache of the last view used, so that the formatters can be reused. - @Nullable private static SimpleMonthView sLastView; - @Nullable private static SimpleMonthView_Delegate sLastDelegate; - - private SimpleDateFormat mTitleFormatter; - private SimpleDateFormat mDayOfWeekFormatter; - - private Locale locale; - - @LayoutlibDelegate - /*package*/ static CharSequence getTitle(SimpleMonthView view) { - if (view.mTitle == null) { - SimpleMonthView_Delegate delegate = getDelegate(view); - if (delegate.mTitleFormatter == null) { - delegate.mTitleFormatter = new SimpleDateFormat(DateFormat.getBestDateTimePattern( - getLocale(delegate, view), DEFAULT_TITLE_FORMAT)); - } - view.mTitle = delegate.mTitleFormatter.format(view.mCalendar.getTime()); - } - return view.mTitle; - } - - @LayoutlibDelegate - /*package*/ static String getDayOfWeekLabel(SimpleMonthView view, int dayOfWeek) { - view.mDayOfWeekLabelCalendar.set(Calendar.DAY_OF_WEEK, dayOfWeek); - SimpleMonthView_Delegate delegate = getDelegate(view); - if (delegate.mDayOfWeekFormatter == null) { - delegate.mDayOfWeekFormatter = - new SimpleDateFormat(DAY_OF_WEEK_FORMAT, getLocale(delegate, view)); - } - return delegate.mDayOfWeekFormatter.format(view.mDayOfWeekLabelCalendar.getTime()); - } - - private static Locale getLocale(SimpleMonthView_Delegate delegate, SimpleMonthView view) { - if (delegate.locale == null) { - delegate.locale = view.getContext().getResources().getConfiguration().locale; - } - return delegate.locale; - } - - @NonNull - private static SimpleMonthView_Delegate getDelegate(SimpleMonthView view) { - if (view == sLastView) { - assert sLastDelegate != null; - return sLastDelegate; - } else { - sLastView = view; - sLastDelegate = new SimpleMonthView_Delegate(); - return sLastDelegate; - } - } - - public static void clearCache() { - sLastView = null; - sLastDelegate = null; - } -} diff --git a/tools/layoutlib/bridge/src/com/android/layoutlib/bridge/impl/RenderAction.java b/tools/layoutlib/bridge/src/com/android/layoutlib/bridge/impl/RenderAction.java index 6d9e872f1a79..4e4fcd0aff2d 100644 --- a/tools/layoutlib/bridge/src/com/android/layoutlib/bridge/impl/RenderAction.java +++ b/tools/layoutlib/bridge/src/com/android/layoutlib/bridge/impl/RenderAction.java @@ -36,7 +36,6 @@ import android.util.DisplayMetrics; import android.view.ViewConfiguration_Accessor; import android.view.inputmethod.InputMethodManager; import android.view.inputmethod.InputMethodManager_Accessor; -import android.widget.SimpleMonthView_Delegate; import java.util.Locale; import java.util.concurrent.TimeUnit; @@ -278,7 +277,6 @@ public abstract class RenderAction<T extends RenderParams> extends FrameworkReso mContext.getRenderResources().setLogger(null); } ParserFactory.setParserFactory(null); - SimpleMonthView_Delegate.clearCache(); } public static BridgeContext getCurrentContext() { diff --git a/tools/layoutlib/create/src/com/android/tools/layoutlib/create/CreateInfo.java b/tools/layoutlib/create/src/com/android/tools/layoutlib/create/CreateInfo.java index cb84a1b0a416..b2fe214d3899 100644 --- a/tools/layoutlib/create/src/com/android/tools/layoutlib/create/CreateInfo.java +++ b/tools/layoutlib/create/src/com/android/tools/layoutlib/create/CreateInfo.java @@ -216,8 +216,6 @@ public final class CreateInfo implements ICreateInfo { "android.view.RenderNode#nGetScaleY", "android.view.RenderNode#nIsPivotExplicitlySet", "android.view.ViewGroup#drawChild", - "android.widget.SimpleMonthView#getTitle", - "android.widget.SimpleMonthView#getDayOfWeekLabel", "android.widget.TimePickerClockDelegate#getAmOrPmKeyCode", "com.android.internal.view.menu.MenuBuilder#createNewMenuItem", "com.android.internal.util.XmlUtils#convertValueToInt", @@ -315,6 +313,10 @@ public final class CreateInfo implements ICreateInfo { "java.lang.IntegralToString", "com.android.tools.layoutlib.java.IntegralToString", "java.lang.UnsafeByteSequence", "com.android.tools.layoutlib.java.UnsafeByteSequence", "java.nio.charset.StandardCharsets", "com.android.tools.layoutlib.java.Charsets", + // Use android.icu.text versions of DateFormat and SimpleDateFormat since the + // original ones do not match the Android implementation + "java.text.DateFormat", "android.icu.text.DateFormat", + "java.text.SimpleDateFormat", "android.icu.text.SimpleDateFormat" }; private final static String[] EXCLUDED_CLASSES = |