Loading core/java/android/content/res/Resources.java +1 −7 Original line number Diff line number Diff line Loading @@ -1711,7 +1711,7 @@ public class Resources { String locale = null; if (mConfiguration.locale != null) { locale = adjustLanguageTag(localeToLanguageTag(mConfiguration.locale)); locale = adjustLanguageTag(mConfiguration.locale.toLanguageTag()); } int width, height; if (mMetrics.widthPixels >= mMetrics.heightPixels) { Loading Loading @@ -1800,12 +1800,6 @@ public class Resources { } } // Locale.toLanguageTag() is not available in Java6. LayoutLib overrides // this method to enable users to use Java6. private String localeToLanguageTag(Locale locale) { return locale.toLanguageTag(); } /** * {@code Locale.toLanguageTag} will transform the obsolete (and deprecated) * language codes "in", "ji" and "iw" to "id", "yi" and "he" respectively. Loading tools/layoutlib/bridge/src/android/content/res/Resources_Delegate.java→tools/layoutlib/bridge/src/com/android/layoutlib/bridge/android/AndroidLocale.java +8 −9 Original line number Diff line number Diff line Loading @@ -14,24 +14,23 @@ * limitations under the License. */ package android.content.res; package com.android.layoutlib.bridge.android; import java.util.Locale; import com.android.tools.layoutlib.annotations.LayoutlibDelegate; import com.ibm.icu.util.ULocale; /** * Delegate used to provide new implementation of a select few methods of {@link Resources} * * Through the layoutlib_create tool, the original methods of Resources have been replaced * by calls to methods of the same name in this delegate class. * This class provides an alternate implementation for {@code java.util.Locale#toLanguageTag} * which is only available after Java 6. * * The create tool re-writes references to the above mentioned method to this one. Hence it's * imperative that this class is not deleted unless the create tool is modified. */ public class Resources_Delegate { @SuppressWarnings("UnusedDeclaration") public class AndroidLocale { @LayoutlibDelegate /*package*/ static String localeToLanguageTag(Resources res, Locale locale) { public static String toLanguageTag(Locale locale) { return ULocale.forLocale(locale).toLanguageTag(); } } tools/layoutlib/create/README.txt +8 −5 Original line number Diff line number Diff line Loading @@ -39,7 +39,8 @@ The ASM library is used to do the bytecode modification using its visitor patter The layoutlib_create is *NOT* generic. There is no configuration file. Instead all the configuration is done in the main() method and the CreateInfo structure is expected to change with the Android platform as new classes are added, changed or removed. platform as new classes are added, changed or removed. Some configuration that may be platform dependent is also present elsewhere in code. The resulting JAR is used by layoutlib_bridge (a.k.a. "the bridge"), also part of the platform, that provides all the necessary missing implementation for rendering graphics in Eclipse. Loading Loading @@ -95,7 +96,7 @@ The generator is constructed from a CreateInfo struct that acts as a config file - specific classes to refactor. Each of these are specific strategies we use to be able to modify the Android code to fit within the Eclipse renderer. These strategies are explained beow. Eclipse renderer. These strategies are explained below. The core method of the generator is transform(): it takes an input ASM ClassReader and modifies it to produce a byte array suitable for the final JAR file. Loading Loading @@ -130,9 +131,11 @@ the StackMapTable correctly and Java 7 VM enforces that classes with version gre valid StackMapTable. As a side benefit of this, we can continue to support Java 6 because Java 7 on Mac has horrible font rendering support. ReplaceMethodCallsAdapter replaces calls to certain methods. Currently, it only rewrites calls to specialized versions of java.lang.System.arraycopy(), which are not part of the Desktop VM to call the more general method java.lang.System.arraycopy(Ljava/lang/Object;ILjava/lang/Object;II)V. ReplaceMethodCallsAdapter replaces calls to certain methods. This is different from the DelegateMethodAdapter since it doesn't preserve the original copy of the method and more importantly changes the calls to a method in each class instead of changing the implementation of the method. This is useful for methods in the Java namespace where we cannot add delegates. The configuration for this is not done through the CreateInfo class, but done in the ReplaceMethodAdapter. The ClassAdapters are chained together to achieve the desired output. (Look at section 2.2.7 Transformation chains in the asm user guide, link in the References.) The order of execution of Loading tools/layoutlib/create/src/com/android/tools/layoutlib/create/AsmAnalyzer.java +2 −3 Original line number Diff line number Diff line Loading @@ -724,9 +724,8 @@ public class AsmAnalyzer { considerDesc(desc); // Check if method is a specialized version of java.lang.System.arrayCopy() if (owner.equals("java/lang/System") && name.equals("arraycopy") && !desc.equals("(Ljava/lang/Object;ILjava/lang/Object;II)V")) { // Check if method needs to replaced by a call to a different method. if (ReplaceMethodCallsAdapter.isReplacementNeeded(owner, name, desc)) { mReplaceMethodCallClasses.add(mOwnerClass); } } Loading tools/layoutlib/create/src/com/android/tools/layoutlib/create/CreateInfo.java +0 −1 Original line number Diff line number Diff line Loading @@ -126,7 +126,6 @@ public final class CreateInfo implements ICreateInfo { "android.content.res.Resources$Theme#obtainStyledAttributes", "android.content.res.Resources$Theme#resolveAttribute", "android.content.res.Resources$Theme#resolveAttributes", "android.content.res.Resources#localeToLanguageTag", "android.content.res.AssetManager#newTheme", "android.content.res.AssetManager#deleteTheme", "android.content.res.AssetManager#applyThemeStyle", Loading Loading
core/java/android/content/res/Resources.java +1 −7 Original line number Diff line number Diff line Loading @@ -1711,7 +1711,7 @@ public class Resources { String locale = null; if (mConfiguration.locale != null) { locale = adjustLanguageTag(localeToLanguageTag(mConfiguration.locale)); locale = adjustLanguageTag(mConfiguration.locale.toLanguageTag()); } int width, height; if (mMetrics.widthPixels >= mMetrics.heightPixels) { Loading Loading @@ -1800,12 +1800,6 @@ public class Resources { } } // Locale.toLanguageTag() is not available in Java6. LayoutLib overrides // this method to enable users to use Java6. private String localeToLanguageTag(Locale locale) { return locale.toLanguageTag(); } /** * {@code Locale.toLanguageTag} will transform the obsolete (and deprecated) * language codes "in", "ji" and "iw" to "id", "yi" and "he" respectively. Loading
tools/layoutlib/bridge/src/android/content/res/Resources_Delegate.java→tools/layoutlib/bridge/src/com/android/layoutlib/bridge/android/AndroidLocale.java +8 −9 Original line number Diff line number Diff line Loading @@ -14,24 +14,23 @@ * limitations under the License. */ package android.content.res; package com.android.layoutlib.bridge.android; import java.util.Locale; import com.android.tools.layoutlib.annotations.LayoutlibDelegate; import com.ibm.icu.util.ULocale; /** * Delegate used to provide new implementation of a select few methods of {@link Resources} * * Through the layoutlib_create tool, the original methods of Resources have been replaced * by calls to methods of the same name in this delegate class. * This class provides an alternate implementation for {@code java.util.Locale#toLanguageTag} * which is only available after Java 6. * * The create tool re-writes references to the above mentioned method to this one. Hence it's * imperative that this class is not deleted unless the create tool is modified. */ public class Resources_Delegate { @SuppressWarnings("UnusedDeclaration") public class AndroidLocale { @LayoutlibDelegate /*package*/ static String localeToLanguageTag(Resources res, Locale locale) { public static String toLanguageTag(Locale locale) { return ULocale.forLocale(locale).toLanguageTag(); } }
tools/layoutlib/create/README.txt +8 −5 Original line number Diff line number Diff line Loading @@ -39,7 +39,8 @@ The ASM library is used to do the bytecode modification using its visitor patter The layoutlib_create is *NOT* generic. There is no configuration file. Instead all the configuration is done in the main() method and the CreateInfo structure is expected to change with the Android platform as new classes are added, changed or removed. platform as new classes are added, changed or removed. Some configuration that may be platform dependent is also present elsewhere in code. The resulting JAR is used by layoutlib_bridge (a.k.a. "the bridge"), also part of the platform, that provides all the necessary missing implementation for rendering graphics in Eclipse. Loading Loading @@ -95,7 +96,7 @@ The generator is constructed from a CreateInfo struct that acts as a config file - specific classes to refactor. Each of these are specific strategies we use to be able to modify the Android code to fit within the Eclipse renderer. These strategies are explained beow. Eclipse renderer. These strategies are explained below. The core method of the generator is transform(): it takes an input ASM ClassReader and modifies it to produce a byte array suitable for the final JAR file. Loading Loading @@ -130,9 +131,11 @@ the StackMapTable correctly and Java 7 VM enforces that classes with version gre valid StackMapTable. As a side benefit of this, we can continue to support Java 6 because Java 7 on Mac has horrible font rendering support. ReplaceMethodCallsAdapter replaces calls to certain methods. Currently, it only rewrites calls to specialized versions of java.lang.System.arraycopy(), which are not part of the Desktop VM to call the more general method java.lang.System.arraycopy(Ljava/lang/Object;ILjava/lang/Object;II)V. ReplaceMethodCallsAdapter replaces calls to certain methods. This is different from the DelegateMethodAdapter since it doesn't preserve the original copy of the method and more importantly changes the calls to a method in each class instead of changing the implementation of the method. This is useful for methods in the Java namespace where we cannot add delegates. The configuration for this is not done through the CreateInfo class, but done in the ReplaceMethodAdapter. The ClassAdapters are chained together to achieve the desired output. (Look at section 2.2.7 Transformation chains in the asm user guide, link in the References.) The order of execution of Loading
tools/layoutlib/create/src/com/android/tools/layoutlib/create/AsmAnalyzer.java +2 −3 Original line number Diff line number Diff line Loading @@ -724,9 +724,8 @@ public class AsmAnalyzer { considerDesc(desc); // Check if method is a specialized version of java.lang.System.arrayCopy() if (owner.equals("java/lang/System") && name.equals("arraycopy") && !desc.equals("(Ljava/lang/Object;ILjava/lang/Object;II)V")) { // Check if method needs to replaced by a call to a different method. if (ReplaceMethodCallsAdapter.isReplacementNeeded(owner, name, desc)) { mReplaceMethodCallClasses.add(mOwnerClass); } } Loading
tools/layoutlib/create/src/com/android/tools/layoutlib/create/CreateInfo.java +0 −1 Original line number Diff line number Diff line Loading @@ -126,7 +126,6 @@ public final class CreateInfo implements ICreateInfo { "android.content.res.Resources$Theme#obtainStyledAttributes", "android.content.res.Resources$Theme#resolveAttribute", "android.content.res.Resources$Theme#resolveAttributes", "android.content.res.Resources#localeToLanguageTag", "android.content.res.AssetManager#newTheme", "android.content.res.AssetManager#deleteTheme", "android.content.res.AssetManager#applyThemeStyle", Loading