Methods Summary |
---|
static void | clearSystem()Clears the static {@link Resources#mSystem} to make sure we don't leave objects
around that would prevent us from unloading the library.
if (Resources.mSystem instanceof BridgeResources) {
((BridgeResources)(Resources.mSystem)).mContext = null;
((BridgeResources)(Resources.mSystem)).mProjectCallback = null;
}
Resources.mSystem = null;
|
public int | getColor(int id)
IResourceValue value = getResourceValue(id, mPlatformResourceFlag);
if (value != null) {
try {
return ResourceHelper.getColor(value.getValue());
} catch (NumberFormatException e) {
return 0;
}
}
// id was not found or not resolved. Throw a NotFoundException.
throwException(id);
// this is not used since the method above always throws
return 0;
|
public android.content.res.ColorStateList | getColorStateList(int id)
IResourceValue value = getResourceValue(id, mPlatformResourceFlag);
if (value != null) {
try {
int color = ResourceHelper.getColor(value.getValue());
return ColorStateList.valueOf(color);
} catch (NumberFormatException e) {
return null;
}
}
// id was not found or not resolved. Throw a NotFoundException.
throwException(id);
// this is not used since the method above always throws
return null;
|
public float | getDimension(int id)
IResourceValue value = getResourceValue(id, mPlatformResourceFlag);
if (value != null) {
String v = value.getValue();
if (v != null) {
if (v.equals(BridgeConstants.FILL_PARENT)) {
return LayoutParams.FILL_PARENT;
} else if (v.equals(BridgeConstants.WRAP_CONTENT)) {
return LayoutParams.WRAP_CONTENT;
}
if (ResourceHelper.stringToFloat(v, mTmpValue) &&
mTmpValue.type == TypedValue.TYPE_DIMENSION) {
return mTmpValue.getDimension(mMetrics);
}
}
}
// id was not found or not resolved. Throw a NotFoundException.
throwException(id);
// this is not used since the method above always throws
return 0;
|
public int | getDimensionPixelOffset(int id)
IResourceValue value = getResourceValue(id, mPlatformResourceFlag);
if (value != null) {
String v = value.getValue();
if (v != null) {
if (ResourceHelper.stringToFloat(v, mTmpValue) &&
mTmpValue.type == TypedValue.TYPE_DIMENSION) {
return TypedValue.complexToDimensionPixelOffset(mTmpValue.data, mMetrics);
}
}
}
// id was not found or not resolved. Throw a NotFoundException.
throwException(id);
// this is not used since the method above always throws
return 0;
|
public int | getDimensionPixelSize(int id)
IResourceValue value = getResourceValue(id, mPlatformResourceFlag);
if (value != null) {
String v = value.getValue();
if (v != null) {
if (ResourceHelper.stringToFloat(v, mTmpValue) &&
mTmpValue.type == TypedValue.TYPE_DIMENSION) {
return TypedValue.complexToDimensionPixelSize(mTmpValue.data, mMetrics);
}
}
}
// id was not found or not resolved. Throw a NotFoundException.
throwException(id);
// this is not used since the method above always throws
return 0;
|
public android.graphics.drawable.Drawable | getDrawable(int id)
IResourceValue value = getResourceValue(id, mPlatformResourceFlag);
if (value != null) {
return ResourceHelper.getDrawable(value.getValue(), mContext, value.isFramework());
}
// id was not found or not resolved. Throw a NotFoundException.
throwException(id);
// this is not used since the method above always throws
return null;
|
public int | getInteger(int id)
IResourceValue value = getResourceValue(id, mPlatformResourceFlag);
if (value != null && value.getValue() != null) {
String v = value.getValue();
int radix = 10;
if (v.startsWith("0x")) {
v = v.substring(2);
radix = 16;
}
try {
return Integer.parseInt(v, radix);
} catch (NumberFormatException e) {
// return exception below
}
}
// id was not found or not resolved. Throw a NotFoundException.
throwException(id);
// this is not used since the method above always throws
return 0;
|
public android.content.res.XmlResourceParser | getLayout(int id)
IResourceValue value = getResourceValue(id, mPlatformResourceFlag);
if (value != null) {
File xml = new File(value.getValue());
if (xml.isFile()) {
// we need to create a pull parser around the layout XML file, and then
// give that to our XmlBlockParser
try {
KXmlParser parser = new KXmlParser();
parser.setFeature(XmlPullParser.FEATURE_PROCESS_NAMESPACES, true);
parser.setInput(new FileReader(xml));
return new BridgeXmlBlockParser(parser, mContext, mPlatformResourceFlag[0]);
} catch (XmlPullParserException e) {
mContext.getLogger().error(e);
// we'll return null below.
} catch (FileNotFoundException e) {
// this shouldn't happen since we check above.
}
}
}
// id was not found or not resolved. Throw a NotFoundException.
throwException(id);
// this is not used since the method above always throws
return null;
|
public java.lang.String | getResourceEntryName(int resid)
throw new UnsupportedOperationException();
|
public java.lang.String | getResourceName(int resid)
throw new UnsupportedOperationException();
|
public java.lang.String | getResourceTypeName(int resid)
throw new UnsupportedOperationException();
|
private com.android.layoutlib.api.IResourceValue | getResourceValue(int id, boolean[] platformResFlag_out)
// first get the String related to this id in the framework
String[] resourceInfo = Bridge.resolveResourceValue(id);
if (resourceInfo != null) {
platformResFlag_out[0] = true;
return mContext.getFrameworkResource(resourceInfo[1], resourceInfo[0]);
}
// didn't find a match in the framework? look in the project.
if (mProjectCallback != null) {
resourceInfo = mProjectCallback.resolveResourceValue(id);
if (resourceInfo != null) {
platformResFlag_out[0] = false;
return mContext.getProjectResource(resourceInfo[1], resourceInfo[0]);
}
}
return null;
|
public java.lang.String | getString(int id, java.lang.Object formatArgs)
String s = getString(id);
if (s != null) {
return String.format(s, formatArgs);
}
// id was not found or not resolved. Throw a NotFoundException.
throwException(id);
// this is not used since the method above always throws
return null;
|
public java.lang.String | getString(int id)
IResourceValue value = getResourceValue(id, mPlatformResourceFlag);
if (value != null && value.getValue() != null) {
return value.getValue();
}
// id was not found or not resolved. Throw a NotFoundException.
throwException(id);
// this is not used since the method above always throws
return null;
|
public java.lang.CharSequence | getText(int id)
IResourceValue value = getResourceValue(id, mPlatformResourceFlag);
if (value != null) {
return value.getValue();
}
// id was not found or not resolved. Throw a NotFoundException.
throwException(id);
// this is not used since the method above always throws
return null;
|
public void | getValue(int id, android.util.TypedValue outValue, boolean resolveRefs)
IResourceValue value = getResourceValue(id, mPlatformResourceFlag);
if (value != null) {
String v = value.getValue();
if (v != null) {
if (ResourceHelper.stringToFloat(v, outValue)) {
return;
}
}
}
// id was not found or not resolved. Throw a NotFoundException.
throwException(id);
|
public void | getValue(java.lang.String name, android.util.TypedValue outValue, boolean resolveRefs)
throw new UnsupportedOperationException();
|
public android.content.res.XmlResourceParser | getXml(int id)
IResourceValue value = getResourceValue(id, mPlatformResourceFlag);
if (value != null) {
String v = value.getValue();
if (v != null) {
// check this is a file
File f = new File(value.getValue());
if (f.isFile()) {
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;
}
}
}
}
// id was not found or not resolved. Throw a NotFoundException.
throwException(id);
// this is not used since the method above always throws
return null;
|
static android.content.res.Resources | initSystem(BridgeContext context, android.content.res.AssetManager assets, android.util.DisplayMetrics metrics, android.content.res.Configuration config, com.android.layoutlib.api.IProjectCallback projectCallback)This initializes the static field {@link Resources#mSystem} which is used
by methods who get global resources using {@link Resources#getSystem()}.
They will end up using our bridge resources.
{@link Bridge} calls this method after setting up a new bridge.
/*package*/
if (!(Resources.mSystem instanceof BridgeResources)) {
Resources.mSystem = new BridgeResources(context,
assets,
metrics,
config,
projectCallback);
}
return Resources.mSystem;
|
public BridgeTypedArray | newTypeArray(int numEntries, boolean platformFile)
return new BridgeTypedArray(this, mContext, numEntries, platformFile);
|
public android.content.res.TypedArray | obtainAttributes(android.util.AttributeSet set, int[] attrs)
return mContext.obtainStyledAttributes(set, attrs);
|
public android.content.res.TypedArray | obtainTypedArray(int id)
throw new UnsupportedOperationException();
|
public java.io.InputStream | openRawResource(int id)
IResourceValue value = getResourceValue(id, mPlatformResourceFlag);
if (value != null) {
String v = value.getValue();
if (v != null) {
// check this is a file
File f = new File(value.getValue());
if (f.isFile()) {
try {
return new FileInputStream(f);
} catch (FileNotFoundException e) {
NotFoundException newE = new NotFoundException();
newE.initCause(e);
throw newE;
}
}
}
}
// id was not found or not resolved. Throw a NotFoundException.
throwException(id);
// this is not used since the method above always throws
return null;
|
public android.content.res.AssetFileDescriptor | openRawResourceFd(int id)
throw new UnsupportedOperationException();
|
private void | throwException(int id)Builds and throws a {@link Resources.NotFoundException} based on a resource id and a resource type.
// first get the String related to this id in the framework
String[] resourceInfo = Bridge.resolveResourceValue(id);
// if the name is unknown in the framework, get it from the custom view loader.
if (resourceInfo == null && mProjectCallback != null) {
resourceInfo = mProjectCallback.resolveResourceValue(id);
}
String message = null;
if (resourceInfo != null) {
message = String.format(
"Could not find %1$s resource matching value 0x%2$X (resolved name: %3$s) in current configuration.",
resourceInfo[1], id, resourceInfo[0]);
} else {
message = String.format(
"Could not resolve resource value: 0x%1$X.", id);
}
throw new NotFoundException(message);
|