Loading tools/layoutlib/bridge/src/android/content/res/Resources_Theme_Delegate.java 0 → 100644 +62 −0 Original line number Diff line number Diff line /* * Copyright (C) 2011 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.content.res; import com.android.layoutlib.bridge.impl.RenderSessionImpl; import android.content.res.Resources.NotFoundException; import android.content.res.Resources.Theme; import android.util.AttributeSet; import android.util.TypedValue; /** * Delegate used to provide new implementation of a select few methods of {@link Theme} * * Through the layoutlib_create tool, the original methods of Theme have been replaced * by calls to methods of the same name in this delegate class. * */ public class Resources_Theme_Delegate { /*package*/ static TypedArray obtainStyledAttributes( Resources thisResources, Theme thisTheme, int[] attrs) { return RenderSessionImpl.getCurrentContext().obtainStyledAttributes(attrs); } /*package*/ static TypedArray obtainStyledAttributes( Resources thisResources, Theme thisTheme, int resid, int[] attrs) throws NotFoundException { return RenderSessionImpl.getCurrentContext().obtainStyledAttributes(resid, attrs); } /*package*/ static TypedArray obtainStyledAttributes( Resources thisResources, Theme thisTheme, AttributeSet set, int[] attrs, int defStyleAttr, int defStyleRes) { return RenderSessionImpl.getCurrentContext().obtainStyledAttributes( set, attrs, defStyleAttr, defStyleRes); } /*package*/ static boolean resolveAttribute( Resources thisResources, Theme thisTheme, int resid, TypedValue outValue, boolean resolveRefs) { return RenderSessionImpl.getCurrentContext().resolveThemeAttribute( resid, outValue, resolveRefs); } } tools/layoutlib/bridge/src/com/android/layoutlib/bridge/android/BridgeContext.java +47 −3 Original line number Diff line number Diff line Loading @@ -56,6 +56,7 @@ import android.os.Handler; import android.os.Looper; import android.util.AttributeSet; import android.util.DisplayMetrics; import android.util.TypedValue; import android.view.LayoutInflater; import android.view.View; Loading @@ -77,7 +78,6 @@ import java.util.Map.Entry; public final class BridgeContext extends Activity { private Resources mSystemResources; private Theme mTheme; private final HashMap<View, Object> mViewKeyMap = new HashMap<View, Object>(); private final Object mProjectKey; private final DisplayMetrics mMetrics; Loading @@ -87,7 +87,7 @@ public final class BridgeContext extends Activity { private final Map<Object, Map<String, String>> mDefaultPropMaps = new IdentityHashMap<Object, Map<String,String>>(); // maps for dynamically generated id representing style objects (IStyleResourceValue) // maps for dynamically generated id representing style objects (StyleResourceValue) private Map<Integer, StyleResourceValue> mDynamicIdToStyleMap; private Map<StyleResourceValue, Integer> mStyleToDynamicIdMap; private int mDynamicIdGenerator = 0x01030000; // Base id for framework R.style Loading Loading @@ -222,6 +222,50 @@ public final class BridgeContext extends Activity { return mParserStack.get(mParserStack.size() - 2); } public boolean resolveThemeAttribute(int resid, TypedValue outValue, boolean resolveRefs) { Pair<ResourceType, String> resourceInfo = Bridge.resolveResourceId(resid); if (resourceInfo == null) { resourceInfo = mProjectCallback.resolveResourceId(resid); } if (resourceInfo == null) { return false; } ResourceValue value = mRenderResources.findItemInTheme(resourceInfo.getSecond()); if (resolveRefs) { value = mRenderResources.resolveResValue(value); } // check if this is a style resource if (value instanceof StyleResourceValue) { // get the id that will represent this style. outValue.resourceId = getDynamicIdByStyle((StyleResourceValue)value); return true; } int a; // if this is a framework value. if (value.isFramework()) { // look for idName in the android R classes. // use 0 a default res value as it's not a valid id value. a = getFrameworkResourceValue(value.getResourceType(), value.getName(), 0 /*defValue*/); } else { // look for idName in the project R class. // use 0 a default res value as it's not a valid id value. a = getProjectResourceValue(value.getResourceType(), value.getName(), 0 /*defValue*/); } if (a != 0) { outValue.resourceId = a; return true; } return false; } // ------------- Activity Methods @Override Loading Loading @@ -275,7 +319,7 @@ public final class BridgeContext extends Activity { @Override public final TypedArray obtainStyledAttributes(int resid, int[] attrs) throws Resources.NotFoundException { // get the IStyleResourceValue based on the resId; // get the StyleResourceValue based on the resId; StyleResourceValue style = getStyleByDynamicId(resid); if (style == null) { Loading tools/layoutlib/bridge/src/com/android/layoutlib/bridge/impl/RenderSessionImpl.java +3 −0 Original line number Diff line number Diff line Loading @@ -334,7 +334,10 @@ public class RenderSessionImpl extends FrameworkResourceIdProvider { Bridge.setLog(null); mContext.getRenderResources().setFrameworkResourceIdProvider(null); mContext.getRenderResources().setLogger(null); } public static BridgeContext getCurrentContext() { return sCurrentContext; } /** Loading tools/layoutlib/bridge/src/libcore/icu/ICU_Delegate.java 0 → 100644 +163 −0 Original line number Diff line number Diff line /* * Copyright (C) 2011 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 libcore.icu; import java.util.Locale; /** * Delegate implementing the native methods of libcore.icu.ICU * * Through the layoutlib_create tool, the original native methods of ICU have been replaced * by calls to methods of the same name in this delegate class. * */ public class ICU_Delegate { /*package*/ static String toLowerCase(String s, String localeName) { return s.toLowerCase(); } /*package*/ static String toUpperCase(String s, String localeName) { return s.toUpperCase(); } // --- Native methods accessing ICU's database. /*package*/ static String[] getAvailableBreakIteratorLocalesNative() { return new String[0]; } /*package*/ static String[] getAvailableCalendarLocalesNative() { return new String[0]; } /*package*/ static String[] getAvailableCollatorLocalesNative() { return new String[0]; } /*package*/ static String[] getAvailableDateFormatLocalesNative() { return new String[0]; } /*package*/ static String[] getAvailableLocalesNative() { return new String[0]; } /*package*/ static String[] getAvailableNumberFormatLocalesNative() { return new String[0]; } /*package*/ static String getCurrencyCodeNative(String locale) { return ""; } /*package*/ static int getCurrencyFractionDigitsNative(String currencyCode) { return 0; } /*package*/ static String getCurrencySymbolNative(String locale, String currencyCode) { return ""; } /*package*/ static String getDisplayCountryNative(String countryCode, String locale) { return ""; } /*package*/ static String getDisplayLanguageNative(String languageCode, String locale) { return ""; } /*package*/ static String getDisplayVariantNative(String variantCode, String locale) { return ""; } /*package*/ static String getISO3CountryNative(String locale) { return ""; } /*package*/ static String getISO3LanguageNative(String locale) { return ""; } /*package*/ static String[] getISOLanguagesNative() { return Locale.getISOLanguages(); } /*package*/ static String[] getISOCountriesNative() { return Locale.getISOCountries(); } /*package*/ static boolean initLocaleDataImpl(String locale, LocaleData result) { // Used by Calendar. result.firstDayOfWeek = Integer.valueOf(1); result.minimalDaysInFirstWeek = Integer.valueOf(1); // Used by DateFormatSymbols. result.amPm = new String[] { "AM", "PM" }; result.eras = new String[] { "BC", "AD" }; result.longMonthNames = new String[] { "January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December" }; result.shortMonthNames = new String[] { "Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec" }; result.longStandAloneMonthNames = result.longMonthNames; result.shortStandAloneMonthNames = result.shortMonthNames; result.longWeekdayNames = new String[] { "Monday" ,"Tuesday", "Wednesday", "Thursday", "Friday", "Saturday", "Sunday" }; result.shortWeekdayNames = new String[] { "Mon" ,"Tue", "Wed", "Thu", "Fri", "Sat", "Sun" }; result.longStandAloneWeekdayNames = result.longWeekdayNames; result.shortStandAloneWeekdayNames = result.shortWeekdayNames; result.fullTimeFormat = ""; result.longTimeFormat = ""; result.mediumTimeFormat = ""; result.shortTimeFormat = ""; result.fullDateFormat = ""; result.longDateFormat = ""; result.mediumDateFormat = ""; result.shortDateFormat = ""; // Used by DecimalFormatSymbols. result.zeroDigit = '0'; result.digit = '0'; result.decimalSeparator = '.'; result.groupingSeparator = ','; result.patternSeparator = ' '; result.percent = '%'; result.perMill = '\u2030'; result.monetarySeparator = ' '; result.minusSign = '-'; result.exponentSeparator = "e"; result.infinity = "\u221E"; result.NaN = "NaN"; // Also used by Currency. result.currencySymbol = "$"; result.internationalCurrencySymbol = "USD"; // Used by DecimalFormat and NumberFormat. result.numberPattern = "%f"; result.integerPattern = "%d"; result.currencyPattern = "%s"; result.percentPattern = "%f"; return true; } } tools/layoutlib/bridge/tests/com/android/layoutlib/bridge/TestDelegates.java +12 −1 Original line number Diff line number Diff line Loading @@ -56,8 +56,9 @@ public class TestDelegates extends TestCase { // extract the class name String className = methodName.substring(0, methodName.indexOf('#')); String targetClassName = className.replace('$', '_') + "_Delegate"; loadAndCompareClasses(className, className + "_Delegate"); loadAndCompareClasses(className, targetClassName); } } Loading Loading @@ -98,6 +99,16 @@ public class TestDelegates extends TestCase { parameters = newParameters; } // if the original class is an inner class that's not static, then // we add this on the enclosing class at the beginning if (originalClass.getEnclosingClass() != null && (originalClass.getModifiers() & Modifier.STATIC) == 0) { Class<?>[] newParameters = new Class<?>[parameters.length + 1]; newParameters[0] = originalClass.getEnclosingClass(); System.arraycopy(parameters, 0, newParameters, 1, parameters.length); parameters = newParameters; } try { // try to load the method with the given parameter types. Method delegateMethod = delegateClass.getDeclaredMethod(originalMethod.getName(), Loading Loading
tools/layoutlib/bridge/src/android/content/res/Resources_Theme_Delegate.java 0 → 100644 +62 −0 Original line number Diff line number Diff line /* * Copyright (C) 2011 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.content.res; import com.android.layoutlib.bridge.impl.RenderSessionImpl; import android.content.res.Resources.NotFoundException; import android.content.res.Resources.Theme; import android.util.AttributeSet; import android.util.TypedValue; /** * Delegate used to provide new implementation of a select few methods of {@link Theme} * * Through the layoutlib_create tool, the original methods of Theme have been replaced * by calls to methods of the same name in this delegate class. * */ public class Resources_Theme_Delegate { /*package*/ static TypedArray obtainStyledAttributes( Resources thisResources, Theme thisTheme, int[] attrs) { return RenderSessionImpl.getCurrentContext().obtainStyledAttributes(attrs); } /*package*/ static TypedArray obtainStyledAttributes( Resources thisResources, Theme thisTheme, int resid, int[] attrs) throws NotFoundException { return RenderSessionImpl.getCurrentContext().obtainStyledAttributes(resid, attrs); } /*package*/ static TypedArray obtainStyledAttributes( Resources thisResources, Theme thisTheme, AttributeSet set, int[] attrs, int defStyleAttr, int defStyleRes) { return RenderSessionImpl.getCurrentContext().obtainStyledAttributes( set, attrs, defStyleAttr, defStyleRes); } /*package*/ static boolean resolveAttribute( Resources thisResources, Theme thisTheme, int resid, TypedValue outValue, boolean resolveRefs) { return RenderSessionImpl.getCurrentContext().resolveThemeAttribute( resid, outValue, resolveRefs); } }
tools/layoutlib/bridge/src/com/android/layoutlib/bridge/android/BridgeContext.java +47 −3 Original line number Diff line number Diff line Loading @@ -56,6 +56,7 @@ import android.os.Handler; import android.os.Looper; import android.util.AttributeSet; import android.util.DisplayMetrics; import android.util.TypedValue; import android.view.LayoutInflater; import android.view.View; Loading @@ -77,7 +78,6 @@ import java.util.Map.Entry; public final class BridgeContext extends Activity { private Resources mSystemResources; private Theme mTheme; private final HashMap<View, Object> mViewKeyMap = new HashMap<View, Object>(); private final Object mProjectKey; private final DisplayMetrics mMetrics; Loading @@ -87,7 +87,7 @@ public final class BridgeContext extends Activity { private final Map<Object, Map<String, String>> mDefaultPropMaps = new IdentityHashMap<Object, Map<String,String>>(); // maps for dynamically generated id representing style objects (IStyleResourceValue) // maps for dynamically generated id representing style objects (StyleResourceValue) private Map<Integer, StyleResourceValue> mDynamicIdToStyleMap; private Map<StyleResourceValue, Integer> mStyleToDynamicIdMap; private int mDynamicIdGenerator = 0x01030000; // Base id for framework R.style Loading Loading @@ -222,6 +222,50 @@ public final class BridgeContext extends Activity { return mParserStack.get(mParserStack.size() - 2); } public boolean resolveThemeAttribute(int resid, TypedValue outValue, boolean resolveRefs) { Pair<ResourceType, String> resourceInfo = Bridge.resolveResourceId(resid); if (resourceInfo == null) { resourceInfo = mProjectCallback.resolveResourceId(resid); } if (resourceInfo == null) { return false; } ResourceValue value = mRenderResources.findItemInTheme(resourceInfo.getSecond()); if (resolveRefs) { value = mRenderResources.resolveResValue(value); } // check if this is a style resource if (value instanceof StyleResourceValue) { // get the id that will represent this style. outValue.resourceId = getDynamicIdByStyle((StyleResourceValue)value); return true; } int a; // if this is a framework value. if (value.isFramework()) { // look for idName in the android R classes. // use 0 a default res value as it's not a valid id value. a = getFrameworkResourceValue(value.getResourceType(), value.getName(), 0 /*defValue*/); } else { // look for idName in the project R class. // use 0 a default res value as it's not a valid id value. a = getProjectResourceValue(value.getResourceType(), value.getName(), 0 /*defValue*/); } if (a != 0) { outValue.resourceId = a; return true; } return false; } // ------------- Activity Methods @Override Loading Loading @@ -275,7 +319,7 @@ public final class BridgeContext extends Activity { @Override public final TypedArray obtainStyledAttributes(int resid, int[] attrs) throws Resources.NotFoundException { // get the IStyleResourceValue based on the resId; // get the StyleResourceValue based on the resId; StyleResourceValue style = getStyleByDynamicId(resid); if (style == null) { Loading
tools/layoutlib/bridge/src/com/android/layoutlib/bridge/impl/RenderSessionImpl.java +3 −0 Original line number Diff line number Diff line Loading @@ -334,7 +334,10 @@ public class RenderSessionImpl extends FrameworkResourceIdProvider { Bridge.setLog(null); mContext.getRenderResources().setFrameworkResourceIdProvider(null); mContext.getRenderResources().setLogger(null); } public static BridgeContext getCurrentContext() { return sCurrentContext; } /** Loading
tools/layoutlib/bridge/src/libcore/icu/ICU_Delegate.java 0 → 100644 +163 −0 Original line number Diff line number Diff line /* * Copyright (C) 2011 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 libcore.icu; import java.util.Locale; /** * Delegate implementing the native methods of libcore.icu.ICU * * Through the layoutlib_create tool, the original native methods of ICU have been replaced * by calls to methods of the same name in this delegate class. * */ public class ICU_Delegate { /*package*/ static String toLowerCase(String s, String localeName) { return s.toLowerCase(); } /*package*/ static String toUpperCase(String s, String localeName) { return s.toUpperCase(); } // --- Native methods accessing ICU's database. /*package*/ static String[] getAvailableBreakIteratorLocalesNative() { return new String[0]; } /*package*/ static String[] getAvailableCalendarLocalesNative() { return new String[0]; } /*package*/ static String[] getAvailableCollatorLocalesNative() { return new String[0]; } /*package*/ static String[] getAvailableDateFormatLocalesNative() { return new String[0]; } /*package*/ static String[] getAvailableLocalesNative() { return new String[0]; } /*package*/ static String[] getAvailableNumberFormatLocalesNative() { return new String[0]; } /*package*/ static String getCurrencyCodeNative(String locale) { return ""; } /*package*/ static int getCurrencyFractionDigitsNative(String currencyCode) { return 0; } /*package*/ static String getCurrencySymbolNative(String locale, String currencyCode) { return ""; } /*package*/ static String getDisplayCountryNative(String countryCode, String locale) { return ""; } /*package*/ static String getDisplayLanguageNative(String languageCode, String locale) { return ""; } /*package*/ static String getDisplayVariantNative(String variantCode, String locale) { return ""; } /*package*/ static String getISO3CountryNative(String locale) { return ""; } /*package*/ static String getISO3LanguageNative(String locale) { return ""; } /*package*/ static String[] getISOLanguagesNative() { return Locale.getISOLanguages(); } /*package*/ static String[] getISOCountriesNative() { return Locale.getISOCountries(); } /*package*/ static boolean initLocaleDataImpl(String locale, LocaleData result) { // Used by Calendar. result.firstDayOfWeek = Integer.valueOf(1); result.minimalDaysInFirstWeek = Integer.valueOf(1); // Used by DateFormatSymbols. result.amPm = new String[] { "AM", "PM" }; result.eras = new String[] { "BC", "AD" }; result.longMonthNames = new String[] { "January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December" }; result.shortMonthNames = new String[] { "Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec" }; result.longStandAloneMonthNames = result.longMonthNames; result.shortStandAloneMonthNames = result.shortMonthNames; result.longWeekdayNames = new String[] { "Monday" ,"Tuesday", "Wednesday", "Thursday", "Friday", "Saturday", "Sunday" }; result.shortWeekdayNames = new String[] { "Mon" ,"Tue", "Wed", "Thu", "Fri", "Sat", "Sun" }; result.longStandAloneWeekdayNames = result.longWeekdayNames; result.shortStandAloneWeekdayNames = result.shortWeekdayNames; result.fullTimeFormat = ""; result.longTimeFormat = ""; result.mediumTimeFormat = ""; result.shortTimeFormat = ""; result.fullDateFormat = ""; result.longDateFormat = ""; result.mediumDateFormat = ""; result.shortDateFormat = ""; // Used by DecimalFormatSymbols. result.zeroDigit = '0'; result.digit = '0'; result.decimalSeparator = '.'; result.groupingSeparator = ','; result.patternSeparator = ' '; result.percent = '%'; result.perMill = '\u2030'; result.monetarySeparator = ' '; result.minusSign = '-'; result.exponentSeparator = "e"; result.infinity = "\u221E"; result.NaN = "NaN"; // Also used by Currency. result.currencySymbol = "$"; result.internationalCurrencySymbol = "USD"; // Used by DecimalFormat and NumberFormat. result.numberPattern = "%f"; result.integerPattern = "%d"; result.currencyPattern = "%s"; result.percentPattern = "%f"; return true; } }
tools/layoutlib/bridge/tests/com/android/layoutlib/bridge/TestDelegates.java +12 −1 Original line number Diff line number Diff line Loading @@ -56,8 +56,9 @@ public class TestDelegates extends TestCase { // extract the class name String className = methodName.substring(0, methodName.indexOf('#')); String targetClassName = className.replace('$', '_') + "_Delegate"; loadAndCompareClasses(className, className + "_Delegate"); loadAndCompareClasses(className, targetClassName); } } Loading Loading @@ -98,6 +99,16 @@ public class TestDelegates extends TestCase { parameters = newParameters; } // if the original class is an inner class that's not static, then // we add this on the enclosing class at the beginning if (originalClass.getEnclosingClass() != null && (originalClass.getModifiers() & Modifier.STATIC) == 0) { Class<?>[] newParameters = new Class<?>[parameters.length + 1]; newParameters[0] = originalClass.getEnclosingClass(); System.arraycopy(parameters, 0, newParameters, 1, parameters.length); parameters = newParameters; } try { // try to load the method with the given parameter types. Method delegateMethod = delegateClass.getDeclaredMethod(originalMethod.getName(), Loading