use of com.android.ide.common.rendering.api.ResourceValue in project android_frameworks_base by ResurrectionRemix.
the class Resources_Delegate method getBoolean.
@LayoutlibDelegate
static boolean getBoolean(Resources resources, int id) throws NotFoundException {
Pair<String, ResourceValue> value = getResourceValue(resources, id, mPlatformResourceFlag);
if (value != null) {
ResourceValue resValue = value.getSecond();
if (resValue != null) {
String v = resValue.getValue();
if (v != null) {
return Boolean.parseBoolean(v);
}
}
}
// id was not found or not resolved. Throw a NotFoundException.
throwException(resources, id);
// this is not used since the method above always throws
return false;
}
use of com.android.ide.common.rendering.api.ResourceValue in project android_frameworks_base by ResurrectionRemix.
the class Resources_Delegate method getLayout.
@LayoutlibDelegate
static XmlResourceParser getLayout(Resources resources, int id) throws NotFoundException {
Pair<String, ResourceValue> v = getResourceValue(resources, id, mPlatformResourceFlag);
if (v != null) {
ResourceValue value = v.getSecond();
XmlPullParser parser = null;
try {
// check if the current parser can provide us with a custom parser.
if (!mPlatformResourceFlag[0]) {
parser = resources.mLayoutlibCallback.getParser(value);
}
// create a new one manually if needed.
if (parser == 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
parser = ParserFactory.create(xml, true);
}
}
if (parser != null) {
return new BridgeXmlBlockParser(parser, resources.mContext, mPlatformResourceFlag[0]);
}
} catch (XmlPullParserException e) {
Bridge.getLog().error(LayoutLog.TAG_BROKEN, "Failed to configure parser for " + value.getValue(), e, null);
// 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(resources, id);
// this is not used since the method above always throws
return null;
}
use of com.android.ide.common.rendering.api.ResourceValue in project android_frameworks_base by ResurrectionRemix.
the class Resources_Delegate method getStringArray.
@LayoutlibDelegate
static String[] getStringArray(Resources resources, int id) throws NotFoundException {
ResourceValue resValue = getArrayResourceValue(resources, id);
if (resValue == null) {
// Error already logged by getArrayResourceValue.
return new String[0];
} else if (!(resValue instanceof ArrayResourceValue)) {
return new String[] { resolveReference(resources, resValue.getValue(), resValue.isFramework()) };
}
ArrayResourceValue arv = ((ArrayResourceValue) resValue);
return fillValues(resources, arv, new String[arv.getElementCount()]);
}
use of com.android.ide.common.rendering.api.ResourceValue in project android_frameworks_base by ResurrectionRemix.
the class Resources_Delegate method getDimension.
@LayoutlibDelegate
static float getDimension(Resources resources, int id) throws NotFoundException {
Pair<String, ResourceValue> value = getResourceValue(resources, id, mPlatformResourceFlag);
if (value != null) {
ResourceValue resValue = value.getSecond();
assert resValue != null;
if (resValue != null) {
String v = resValue.getValue();
if (v != null) {
if (v.equals(BridgeConstants.MATCH_PARENT) || v.equals(BridgeConstants.FILL_PARENT)) {
return LayoutParams.MATCH_PARENT;
} else if (v.equals(BridgeConstants.WRAP_CONTENT)) {
return LayoutParams.WRAP_CONTENT;
}
TypedValue tmpValue = new TypedValue();
if (ResourceHelper.parseFloatAttribute(value.getFirst(), v, tmpValue, true) && tmpValue.type == TypedValue.TYPE_DIMENSION) {
return tmpValue.getDimension(resources.getDisplayMetrics());
}
}
}
}
// id was not found or not resolved. Throw a NotFoundException.
throwException(resources, id);
// this is not used since the method above always throws
return 0;
}
use of com.android.ide.common.rendering.api.ResourceValue in project android_frameworks_base by ResurrectionRemix.
the class Resources_Delegate method getIntArray.
@LayoutlibDelegate
static int[] getIntArray(Resources resources, int id) throws NotFoundException {
ResourceValue rv = getArrayResourceValue(resources, id);
if (rv == null) {
// Error already logged by getArrayResourceValue.
return new int[0];
} else if (!(rv instanceof ArrayResourceValue)) {
// This is an older IDE that can only give us the first element of the array.
String firstValue = resolveReference(resources, rv.getValue(), rv.isFramework());
try {
return new int[] { getInt(firstValue) };
} catch (NumberFormatException e) {
Bridge.getLog().error(LayoutLog.TAG_RESOURCES_FORMAT, "Integer resource array contains non-integer value: " + firstValue, null);
return new int[1];
}
}
ArrayResourceValue resValue = ((ArrayResourceValue) rv);
int[] values = new int[resValue.getElementCount()];
int i = 0;
for (Iterator<String> iterator = resValue.iterator(); iterator.hasNext(); i++) {
String element = resolveReference(resources, iterator.next(), resValue.isFramework());
try {
values[i] = getInt(element);
} catch (NumberFormatException e) {
Bridge.getLog().error(LayoutLog.TAG_RESOURCES_FORMAT, "Integer resource array contains non-integer value: " + element, null);
}
}
return values;
}
Aggregations