Make TimePicker/DatePicker/CalendarView render in Eclipse.
Change-Id: Id5313a6f0f53bf45f6eaabc0e10fcf0660eeac08
diff --git a/tools/layoutlib/bridge/src/android/content/res/Resources_Theme_Delegate.java b/tools/layoutlib/bridge/src/android/content/res/Resources_Theme_Delegate.java
new file mode 100644
index 0000000..03f3980
--- /dev/null
+++ b/tools/layoutlib/bridge/src/android/content/res/Resources_Theme_Delegate.java
@@ -0,0 +1,62 @@
+/*
+ * 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);
+ }
+}
diff --git a/tools/layoutlib/bridge/src/com/android/layoutlib/bridge/android/BridgeContext.java b/tools/layoutlib/bridge/src/com/android/layoutlib/bridge/android/BridgeContext.java
index 037ad23..4220ddd 100644
--- a/tools/layoutlib/bridge/src/com/android/layoutlib/bridge/android/BridgeContext.java
+++ b/tools/layoutlib/bridge/src/com/android/layoutlib/bridge/android/BridgeContext.java
@@ -56,6 +56,7 @@
import android.os.Looper;
import android.util.AttributeSet;
import android.util.DisplayMetrics;
+import android.util.TypedValue;
import android.view.LayoutInflater;
import android.view.View;
@@ -77,7 +78,6 @@
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;
@@ -87,7 +87,7 @@
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
@@ -222,6 +222,50 @@
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
@@ -275,7 +319,7 @@
@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) {
diff --git a/tools/layoutlib/bridge/src/com/android/layoutlib/bridge/impl/RenderSessionImpl.java b/tools/layoutlib/bridge/src/com/android/layoutlib/bridge/impl/RenderSessionImpl.java
index d816d18..fa04697 100644
--- a/tools/layoutlib/bridge/src/com/android/layoutlib/bridge/impl/RenderSessionImpl.java
+++ b/tools/layoutlib/bridge/src/com/android/layoutlib/bridge/impl/RenderSessionImpl.java
@@ -334,7 +334,10 @@
Bridge.setLog(null);
mContext.getRenderResources().setFrameworkResourceIdProvider(null);
mContext.getRenderResources().setLogger(null);
+ }
+ public static BridgeContext getCurrentContext() {
+ return sCurrentContext;
}
/**
diff --git a/tools/layoutlib/bridge/src/libcore/icu/ICU_Delegate.java b/tools/layoutlib/bridge/src/libcore/icu/ICU_Delegate.java
new file mode 100644
index 0000000..ab01a394
--- /dev/null
+++ b/tools/layoutlib/bridge/src/libcore/icu/ICU_Delegate.java
@@ -0,0 +1,163 @@
+/*
+ * 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;
+ }
+}
diff --git a/tools/layoutlib/bridge/tests/com/android/layoutlib/bridge/TestDelegates.java b/tools/layoutlib/bridge/tests/com/android/layoutlib/bridge/TestDelegates.java
index 0ff1925..a4140e3 100644
--- a/tools/layoutlib/bridge/tests/com/android/layoutlib/bridge/TestDelegates.java
+++ b/tools/layoutlib/bridge/tests/com/android/layoutlib/bridge/TestDelegates.java
@@ -56,8 +56,9 @@
// extract the class name
String className = methodName.substring(0, methodName.indexOf('#'));
+ String targetClassName = className.replace('$', '_') + "_Delegate";
- loadAndCompareClasses(className, className + "_Delegate");
+ loadAndCompareClasses(className, targetClassName);
}
}
@@ -98,6 +99,16 @@
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(),
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 55e9e48..291f076d 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
@@ -95,13 +95,14 @@
*/
private final static String[] DELEGATE_METHODS = new String[] {
"android.app.Fragment#instantiate", //(Landroid/content/Context;Ljava/lang/String;Landroid/os/Bundle;)Landroid/app/Fragment;",
+ "android.content.res.Resources$Theme#obtainStyledAttributes",
+ "android.content.res.Resources$Theme#resolveAttribute",
"android.os.Handler#sendMessageAtTime",
"android.os.Build#getString",
"android.view.LayoutInflater#rInflate",
"android.view.View#isInEditMode",
"com.android.internal.util.XmlUtils#convertValueToInt",
// TODO: comment out once DelegateClass is working
- // "android.content.res.Resources$Theme#obtainStyledAttributes",
};
/**
@@ -147,6 +148,7 @@
"android.graphics.Xfermode",
"android.os.SystemClock",
"android.util.FloatMath",
+ "libcore.icu.ICU",
};
/**
@@ -154,8 +156,6 @@
* "package.package.OuterClass$InnerClass#MethodName".
*/
private final static String[] OVERRIDDEN_METHODS = new String[] {
- // TODO: remove once DelegateClass is working
- "android.content.res.Resources$Theme#obtainStyledAttributes",
};
/**