am 2081769f: am 618d96da: am 385ce0a3: Merge "Replace Locale.getDefault with custom impl." into mnc-dev

* commit '2081769f4c6128bf3e8af29643aaf5f8da0902d8':
  Replace Locale.getDefault with custom impl.
This commit is contained in:
Deepanshu Gupta
2015-08-06 23:38:42 +00:00
committed by Android Git Automerger
3 changed files with 22 additions and 2 deletions

View File

@ -16,6 +16,8 @@
package com.android.layoutlib.bridge.android;
import com.android.layoutlib.bridge.impl.RenderAction;
import android.icu.util.ULocale;
import java.util.Locale;
@ -56,4 +58,15 @@ public class AndroidLocale {
public static String getScript(Locale locale) {
return ULocale.forLocale(locale).getScript();
}
public static Locale getDefault() {
BridgeContext context = RenderAction.getCurrentContext();
if (context != null) {
Locale locale = context.getConfiguration().locale;
if (locale != null) {
return locale;
}
}
return Locale.getDefault();
}
}

View File

@ -37,6 +37,7 @@ import android.view.ViewConfiguration_Accessor;
import android.view.inputmethod.InputMethodManager;
import android.view.inputmethod.InputMethodManager_Accessor;
import java.util.Locale;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.locks.ReentrantLock;
@ -397,6 +398,8 @@ public abstract class RenderAction<T extends RenderParams> extends FrameworkReso
// preview releases of API 15.
// TODO: Remove the try catch around Oct 2015.
}
String locale = getParams().getLocale();
if (locale != null && !locale.isEmpty()) config.locale = new Locale(locale);
// TODO: fill in more config info.

View File

@ -93,18 +93,22 @@ public class ReplaceMethodCallsAdapter extends ClassVisitor {
}
});
// Case 3: java.util.Locale.adjustLanguageCode() or java.util.Locale.forLanguageTag()
// Case 3: java.util.Locale.adjustLanguageCode() or java.util.Locale.forLanguageTag() or
// java.util.Locale.getDefault()
METHOD_REPLACERS.add(new MethodReplacer() {
private final String STRING_TO_STRING = Type.getMethodDescriptor(STRING, STRING);
private final String STRING_TO_LOCALE = Type.getMethodDescriptor(
Type.getType(Locale.class), STRING);
private final String VOID_TO_LOCALE =
Type.getMethodDescriptor(Type.getType(Locale.class));
@Override
public boolean isNeeded(String owner, String name, String desc, String sourceClass) {
return JAVA_LOCALE_CLASS.equals(owner) &&
("adjustLanguageCode".equals(name) && desc.equals(STRING_TO_STRING) ||
"forLanguageTag".equals(name) && desc.equals(STRING_TO_LOCALE));
"forLanguageTag".equals(name) && desc.equals(STRING_TO_LOCALE) ||
"getDefault".equals(name) && desc.equals(VOID_TO_LOCALE));
}
@Override