am 94ff3f1f
: Merge change 21063 into donut
Merge commit '94ff3f1f08805b68c5524b39024968aebcdc83ee' into eclair * commit '94ff3f1f08805b68c5524b39024968aebcdc83ee': Fix handling of reference XML file in layout files
This commit is contained in:
@ -53,6 +53,8 @@ public final class ServiceManager {
|
|||||||
* Return a list of all currently running services.
|
* Return a list of all currently running services.
|
||||||
*/
|
*/
|
||||||
public static String[] listServices() throws RemoteException {
|
public static String[] listServices() throws RemoteException {
|
||||||
|
// actual implementation returns null sometimes, so it's ok
|
||||||
|
// to return null instead of an empty list.
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -87,6 +87,8 @@ public final class AccessibilityManager {
|
|||||||
* @return An unmodifiable list with {@link ServiceInfo}s.
|
* @return An unmodifiable list with {@link ServiceInfo}s.
|
||||||
*/
|
*/
|
||||||
public List<ServiceInfo> getAccessibilityServiceList() {
|
public List<ServiceInfo> getAccessibilityServiceList() {
|
||||||
|
// normal implementation does this in some case, so let's do the same
|
||||||
|
// (unmodifiableList wrapped around null).
|
||||||
List<ServiceInfo> services = null;
|
List<ServiceInfo> services = null;
|
||||||
return Collections.unmodifiableList(services);
|
return Collections.unmodifiableList(services);
|
||||||
}
|
}
|
||||||
|
@ -43,14 +43,14 @@ import java.io.FileReader;
|
|||||||
import java.io.InputStream;
|
import java.io.InputStream;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
public final class BridgeResources extends Resources {
|
public final class BridgeResources extends Resources {
|
||||||
|
|
||||||
private BridgeContext mContext;
|
private BridgeContext mContext;
|
||||||
private IProjectCallback mProjectCallback;
|
private IProjectCallback mProjectCallback;
|
||||||
private boolean[] mPlatformResourceFlag = new boolean[1];
|
private boolean[] mPlatformResourceFlag = new boolean[1];
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This initializes the static field {@link Resources#mSystem} which is used
|
* This initializes the static field {@link Resources#mSystem} which is used
|
||||||
* by methods who get global resources using {@link Resources#getSystem()}.
|
* by methods who get global resources using {@link Resources#getSystem()}.
|
||||||
@ -59,7 +59,7 @@ public final class BridgeResources extends Resources {
|
|||||||
* <p/>
|
* <p/>
|
||||||
* {@link Bridge} calls this method after setting up a new bridge.
|
* {@link Bridge} calls this method after setting up a new bridge.
|
||||||
*/
|
*/
|
||||||
/*package*/ static Resources initSystem(BridgeContext context,
|
/*package*/ static Resources initSystem(BridgeContext context,
|
||||||
AssetManager assets,
|
AssetManager assets,
|
||||||
DisplayMetrics metrics,
|
DisplayMetrics metrics,
|
||||||
Configuration config,
|
Configuration config,
|
||||||
@ -73,7 +73,7 @@ public final class BridgeResources extends Resources {
|
|||||||
}
|
}
|
||||||
return Resources.mSystem;
|
return Resources.mSystem;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Clears the static {@link Resources#mSystem} to make sure we don't leave objects
|
* Clears the static {@link Resources#mSystem} to make sure we don't leave objects
|
||||||
* around that would prevent us from unloading the library.
|
* around that would prevent us from unloading the library.
|
||||||
@ -92,15 +92,15 @@ public final class BridgeResources extends Resources {
|
|||||||
mContext = context;
|
mContext = context;
|
||||||
mProjectCallback = projectCallback;
|
mProjectCallback = projectCallback;
|
||||||
}
|
}
|
||||||
|
|
||||||
public BridgeTypedArray newTypeArray(int numEntries, boolean platformFile) {
|
public BridgeTypedArray newTypeArray(int numEntries, boolean platformFile) {
|
||||||
return new BridgeTypedArray(this, mContext, numEntries, platformFile);
|
return new BridgeTypedArray(this, mContext, numEntries, platformFile);
|
||||||
}
|
}
|
||||||
|
|
||||||
private IResourceValue getResourceValue(int id, boolean[] platformResFlag_out) {
|
private IResourceValue getResourceValue(int id, boolean[] platformResFlag_out) {
|
||||||
// first get the String related to this id in the framework
|
// first get the String related to this id in the framework
|
||||||
String[] resourceInfo = Bridge.resolveResourceValue(id);
|
String[] resourceInfo = Bridge.resolveResourceValue(id);
|
||||||
|
|
||||||
if (resourceInfo != null) {
|
if (resourceInfo != null) {
|
||||||
platformResFlag_out[0] = true;
|
platformResFlag_out[0] = true;
|
||||||
return mContext.getFrameworkResource(resourceInfo[1], resourceInfo[0]);
|
return mContext.getFrameworkResource(resourceInfo[1], resourceInfo[0]);
|
||||||
@ -109,7 +109,7 @@ public final class BridgeResources extends Resources {
|
|||||||
// didn't find a match in the framework? look in the project.
|
// didn't find a match in the framework? look in the project.
|
||||||
if (mProjectCallback != null) {
|
if (mProjectCallback != null) {
|
||||||
resourceInfo = mProjectCallback.resolveResourceValue(id);
|
resourceInfo = mProjectCallback.resolveResourceValue(id);
|
||||||
|
|
||||||
if (resourceInfo != null) {
|
if (resourceInfo != null) {
|
||||||
platformResFlag_out[0] = false;
|
platformResFlag_out[0] = false;
|
||||||
return mContext.getProjectResource(resourceInfo[1], resourceInfo[0]);
|
return mContext.getProjectResource(resourceInfo[1], resourceInfo[0]);
|
||||||
@ -118,26 +118,26 @@ public final class BridgeResources extends Resources {
|
|||||||
|
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Drawable getDrawable(int id) throws NotFoundException {
|
public Drawable getDrawable(int id) throws NotFoundException {
|
||||||
IResourceValue value = getResourceValue(id, mPlatformResourceFlag);
|
IResourceValue value = getResourceValue(id, mPlatformResourceFlag);
|
||||||
|
|
||||||
if (value != null) {
|
if (value != null) {
|
||||||
return ResourceHelper.getDrawable(value.getValue(), mContext, value.isFramework());
|
return ResourceHelper.getDrawable(value.getValue(), mContext, value.isFramework());
|
||||||
}
|
}
|
||||||
|
|
||||||
// id was not found or not resolved. Throw a NotFoundException.
|
// id was not found or not resolved. Throw a NotFoundException.
|
||||||
throwException(id);
|
throwException(id);
|
||||||
|
|
||||||
// this is not used since the method above always throws
|
// this is not used since the method above always throws
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int getColor(int id) throws NotFoundException {
|
public int getColor(int id) throws NotFoundException {
|
||||||
IResourceValue value = getResourceValue(id, mPlatformResourceFlag);
|
IResourceValue value = getResourceValue(id, mPlatformResourceFlag);
|
||||||
|
|
||||||
if (value != null) {
|
if (value != null) {
|
||||||
try {
|
try {
|
||||||
return ResourceHelper.getColor(value.getValue());
|
return ResourceHelper.getColor(value.getValue());
|
||||||
@ -145,18 +145,18 @@ public final class BridgeResources extends Resources {
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// id was not found or not resolved. Throw a NotFoundException.
|
// id was not found or not resolved. Throw a NotFoundException.
|
||||||
throwException(id);
|
throwException(id);
|
||||||
|
|
||||||
// this is not used since the method above always throws
|
// this is not used since the method above always throws
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public ColorStateList getColorStateList(int id) throws NotFoundException {
|
public ColorStateList getColorStateList(int id) throws NotFoundException {
|
||||||
IResourceValue value = getResourceValue(id, mPlatformResourceFlag);
|
IResourceValue value = getResourceValue(id, mPlatformResourceFlag);
|
||||||
|
|
||||||
if (value != null) {
|
if (value != null) {
|
||||||
try {
|
try {
|
||||||
int color = ResourceHelper.getColor(value.getValue());
|
int color = ResourceHelper.getColor(value.getValue());
|
||||||
@ -165,33 +165,33 @@ public final class BridgeResources extends Resources {
|
|||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// id was not found or not resolved. Throw a NotFoundException.
|
// id was not found or not resolved. Throw a NotFoundException.
|
||||||
throwException(id);
|
throwException(id);
|
||||||
|
|
||||||
// this is not used since the method above always throws
|
// this is not used since the method above always throws
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public CharSequence getText(int id) throws NotFoundException {
|
public CharSequence getText(int id) throws NotFoundException {
|
||||||
IResourceValue value = getResourceValue(id, mPlatformResourceFlag);
|
IResourceValue value = getResourceValue(id, mPlatformResourceFlag);
|
||||||
|
|
||||||
if (value != null) {
|
if (value != null) {
|
||||||
return value.getValue();
|
return value.getValue();
|
||||||
}
|
}
|
||||||
|
|
||||||
// id was not found or not resolved. Throw a NotFoundException.
|
// id was not found or not resolved. Throw a NotFoundException.
|
||||||
throwException(id);
|
throwException(id);
|
||||||
|
|
||||||
// this is not used since the method above always throws
|
// this is not used since the method above always throws
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public XmlResourceParser getLayout(int id) throws NotFoundException {
|
public XmlResourceParser getLayout(int id) throws NotFoundException {
|
||||||
IResourceValue value = getResourceValue(id, mPlatformResourceFlag);
|
IResourceValue value = getResourceValue(id, mPlatformResourceFlag);
|
||||||
|
|
||||||
if (value != null) {
|
if (value != null) {
|
||||||
File xml = new File(value.getValue());
|
File xml = new File(value.getValue());
|
||||||
if (xml.isFile()) {
|
if (xml.isFile()) {
|
||||||
@ -201,7 +201,7 @@ public final class BridgeResources extends Resources {
|
|||||||
KXmlParser parser = new KXmlParser();
|
KXmlParser parser = new KXmlParser();
|
||||||
parser.setFeature(XmlPullParser.FEATURE_PROCESS_NAMESPACES, true);
|
parser.setFeature(XmlPullParser.FEATURE_PROCESS_NAMESPACES, true);
|
||||||
parser.setInput(new FileReader(xml));
|
parser.setInput(new FileReader(xml));
|
||||||
|
|
||||||
return new BridgeXmlBlockParser(parser, mContext, mPlatformResourceFlag[0]);
|
return new BridgeXmlBlockParser(parser, mContext, mPlatformResourceFlag[0]);
|
||||||
} catch (XmlPullParserException e) {
|
} catch (XmlPullParserException e) {
|
||||||
mContext.getLogger().error(e);
|
mContext.getLogger().error(e);
|
||||||
@ -215,22 +215,22 @@ public final class BridgeResources extends Resources {
|
|||||||
|
|
||||||
// id was not found or not resolved. Throw a NotFoundException.
|
// id was not found or not resolved. Throw a NotFoundException.
|
||||||
throwException(id);
|
throwException(id);
|
||||||
|
|
||||||
// this is not used since the method above always throws
|
// this is not used since the method above always throws
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public TypedArray obtainAttributes(AttributeSet set, int[] attrs) {
|
public TypedArray obtainAttributes(AttributeSet set, int[] attrs) {
|
||||||
return mContext.obtainStyledAttributes(set, attrs);
|
return mContext.obtainStyledAttributes(set, attrs);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public TypedArray obtainTypedArray(int id) throws NotFoundException {
|
public TypedArray obtainTypedArray(int id) throws NotFoundException {
|
||||||
throw new UnsupportedOperationException();
|
throw new UnsupportedOperationException();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public float getDimension(int id) throws NotFoundException {
|
public float getDimension(int id) throws NotFoundException {
|
||||||
IResourceValue value = getResourceValue(id, mPlatformResourceFlag);
|
IResourceValue value = getResourceValue(id, mPlatformResourceFlag);
|
||||||
@ -244,7 +244,7 @@ public final class BridgeResources extends Resources {
|
|||||||
} else if (v.equals(BridgeConstants.WRAP_CONTENT)) {
|
} else if (v.equals(BridgeConstants.WRAP_CONTENT)) {
|
||||||
return LayoutParams.WRAP_CONTENT;
|
return LayoutParams.WRAP_CONTENT;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (ResourceHelper.stringToFloat(v, mTmpValue) &&
|
if (ResourceHelper.stringToFloat(v, mTmpValue) &&
|
||||||
mTmpValue.type == TypedValue.TYPE_DIMENSION) {
|
mTmpValue.type == TypedValue.TYPE_DIMENSION) {
|
||||||
return mTmpValue.getDimension(mMetrics);
|
return mTmpValue.getDimension(mMetrics);
|
||||||
@ -254,7 +254,7 @@ public final class BridgeResources extends Resources {
|
|||||||
|
|
||||||
// id was not found or not resolved. Throw a NotFoundException.
|
// id was not found or not resolved. Throw a NotFoundException.
|
||||||
throwException(id);
|
throwException(id);
|
||||||
|
|
||||||
// this is not used since the method above always throws
|
// this is not used since the method above always throws
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
@ -276,7 +276,7 @@ public final class BridgeResources extends Resources {
|
|||||||
|
|
||||||
// id was not found or not resolved. Throw a NotFoundException.
|
// id was not found or not resolved. Throw a NotFoundException.
|
||||||
throwException(id);
|
throwException(id);
|
||||||
|
|
||||||
// this is not used since the method above always throws
|
// this is not used since the method above always throws
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
@ -298,7 +298,7 @@ public final class BridgeResources extends Resources {
|
|||||||
|
|
||||||
// id was not found or not resolved. Throw a NotFoundException.
|
// id was not found or not resolved. Throw a NotFoundException.
|
||||||
throwException(id);
|
throwException(id);
|
||||||
|
|
||||||
// this is not used since the method above always throws
|
// this is not used since the method above always throws
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
@ -306,7 +306,7 @@ public final class BridgeResources extends Resources {
|
|||||||
@Override
|
@Override
|
||||||
public int getInteger(int id) throws NotFoundException {
|
public int getInteger(int id) throws NotFoundException {
|
||||||
IResourceValue value = getResourceValue(id, mPlatformResourceFlag);
|
IResourceValue value = getResourceValue(id, mPlatformResourceFlag);
|
||||||
|
|
||||||
if (value != null && value.getValue() != null) {
|
if (value != null && value.getValue() != null) {
|
||||||
String v = value.getValue();
|
String v = value.getValue();
|
||||||
int radix = 10;
|
int radix = 10;
|
||||||
@ -320,10 +320,10 @@ public final class BridgeResources extends Resources {
|
|||||||
// return exception below
|
// return exception below
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// id was not found or not resolved. Throw a NotFoundException.
|
// id was not found or not resolved. Throw a NotFoundException.
|
||||||
throwException(id);
|
throwException(id);
|
||||||
|
|
||||||
// this is not used since the method above always throws
|
// this is not used since the method above always throws
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
@ -348,12 +348,12 @@ public final class BridgeResources extends Resources {
|
|||||||
String s = getString(id);
|
String s = getString(id);
|
||||||
if (s != null) {
|
if (s != null) {
|
||||||
return String.format(s, formatArgs);
|
return String.format(s, formatArgs);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// id was not found or not resolved. Throw a NotFoundException.
|
// id was not found or not resolved. Throw a NotFoundException.
|
||||||
throwException(id);
|
throwException(id);
|
||||||
|
|
||||||
// this is not used since the method above always throws
|
// this is not used since the method above always throws
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
@ -361,14 +361,14 @@ public final class BridgeResources extends Resources {
|
|||||||
@Override
|
@Override
|
||||||
public String getString(int id) throws NotFoundException {
|
public String getString(int id) throws NotFoundException {
|
||||||
IResourceValue value = getResourceValue(id, mPlatformResourceFlag);
|
IResourceValue value = getResourceValue(id, mPlatformResourceFlag);
|
||||||
|
|
||||||
if (value != null && value.getValue() != null) {
|
if (value != null && value.getValue() != null) {
|
||||||
return value.getValue();
|
return value.getValue();
|
||||||
}
|
}
|
||||||
|
|
||||||
// id was not found or not resolved. Throw a NotFoundException.
|
// id was not found or not resolved. Throw a NotFoundException.
|
||||||
throwException(id);
|
throwException(id);
|
||||||
|
|
||||||
// this is not used since the method above always throws
|
// this is not used since the method above always throws
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
@ -385,6 +385,11 @@ public final class BridgeResources extends Resources {
|
|||||||
if (ResourceHelper.stringToFloat(v, outValue)) {
|
if (ResourceHelper.stringToFloat(v, outValue)) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// else it's a string
|
||||||
|
outValue.type = TypedValue.TYPE_STRING;
|
||||||
|
outValue.string = v;
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -413,7 +418,7 @@ public final class BridgeResources extends Resources {
|
|||||||
KXmlParser parser = new KXmlParser();
|
KXmlParser parser = new KXmlParser();
|
||||||
parser.setFeature(XmlPullParser.FEATURE_PROCESS_NAMESPACES, true);
|
parser.setFeature(XmlPullParser.FEATURE_PROCESS_NAMESPACES, true);
|
||||||
parser.setInput(new FileReader(f));
|
parser.setInput(new FileReader(f));
|
||||||
|
|
||||||
return new BridgeXmlBlockParser(parser, mContext, mPlatformResourceFlag[0]);
|
return new BridgeXmlBlockParser(parser, mContext, mPlatformResourceFlag[0]);
|
||||||
} catch (XmlPullParserException e) {
|
} catch (XmlPullParserException e) {
|
||||||
NotFoundException newE = new NotFoundException();
|
NotFoundException newE = new NotFoundException();
|
||||||
@ -435,6 +440,33 @@ public final class BridgeResources extends Resources {
|
|||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public XmlResourceParser loadXmlResourceParser(String file, int id,
|
||||||
|
int assetCookie, String type) throws NotFoundException {
|
||||||
|
// even though we know the XML file to load directly, we still need to resolve the
|
||||||
|
// id so that we can know if it's a platform or project resource.
|
||||||
|
// (mPlatformResouceFlag will get the result and will be used later).
|
||||||
|
getResourceValue(id, mPlatformResourceFlag);
|
||||||
|
|
||||||
|
File f = new File(file);
|
||||||
|
try {
|
||||||
|
KXmlParser parser = new KXmlParser();
|
||||||
|
parser.setFeature(XmlPullParser.FEATURE_PROCESS_NAMESPACES, true);
|
||||||
|
parser.setInput(new FileReader(f));
|
||||||
|
|
||||||
|
return new BridgeXmlBlockParser(parser, mContext, mPlatformResourceFlag[0]);
|
||||||
|
} catch (XmlPullParserException e) {
|
||||||
|
NotFoundException newE = new NotFoundException();
|
||||||
|
newE.initCause(e);
|
||||||
|
throw newE;
|
||||||
|
} catch (FileNotFoundException e) {
|
||||||
|
NotFoundException newE = new NotFoundException();
|
||||||
|
newE.initCause(e);
|
||||||
|
throw newE;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public InputStream openRawResource(int id) throws NotFoundException {
|
public InputStream openRawResource(int id) throws NotFoundException {
|
||||||
IResourceValue value = getResourceValue(id, mPlatformResourceFlag);
|
IResourceValue value = getResourceValue(id, mPlatformResourceFlag);
|
||||||
@ -482,7 +514,7 @@ public final class BridgeResources extends Resources {
|
|||||||
if (resourceInfo == null && mProjectCallback != null) {
|
if (resourceInfo == null && mProjectCallback != null) {
|
||||||
resourceInfo = mProjectCallback.resolveResourceValue(id);
|
resourceInfo = mProjectCallback.resolveResourceValue(id);
|
||||||
}
|
}
|
||||||
|
|
||||||
String message = null;
|
String message = null;
|
||||||
if (resourceInfo != null) {
|
if (resourceInfo != null) {
|
||||||
message = String.format(
|
message = String.format(
|
||||||
@ -492,7 +524,7 @@ public final class BridgeResources extends Resources {
|
|||||||
message = String.format(
|
message = String.format(
|
||||||
"Could not resolve resource value: 0x%1$X.", id);
|
"Could not resolve resource value: 0x%1$X.", id);
|
||||||
}
|
}
|
||||||
|
|
||||||
throw new NotFoundException(message);
|
throw new NotFoundException(message);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user