Merge "Make TimePicker/DatePicker/CalendarView render in Eclipse." into honeycomb

This commit is contained in:
Xavier Ducrohet
2011-02-02 14:15:39 -08:00
committed by Android (Google) Code Review
6 changed files with 290 additions and 7 deletions

View File

@@ -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);
}
}

View File

@@ -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;
@@ -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;
@@ -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
@@ -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
@@ -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) {

View File

@@ -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;
}
/**

View File

@@ -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;
}
}

View File

@@ -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);
}
}
@@ -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(),

View File

@@ -95,13 +95,14 @@ public final class CreateInfo implements ICreateInfo {
*/
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 @@ public final class CreateInfo implements ICreateInfo {
"android.graphics.Xfermode",
"android.os.SystemClock",
"android.util.FloatMath",
"libcore.icu.ICU",
};
/**
@@ -154,8 +156,6 @@ public final class CreateInfo implements ICreateInfo {
* "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",
};
/**