use of com.android.layoutlib.bridge.android.BridgeXmlBlockParser in project android_frameworks_base by crdroidandroid.
the class BridgePreferenceInflater method onCreateItem.
@Override
protected Preference onCreateItem(String name, AttributeSet attrs) throws ClassNotFoundException {
Object viewKey = null;
BridgeContext bc = null;
Context context = getContext();
if (context instanceof BridgeContext) {
bc = (BridgeContext) context;
}
if (attrs instanceof BridgeXmlBlockParser) {
viewKey = ((BridgeXmlBlockParser) attrs).getViewCookie();
}
Preference preference = super.onCreateItem(name, attrs);
if (viewKey != null && bc != null) {
bc.addCookie(preference, viewKey);
}
return preference;
}
use of com.android.layoutlib.bridge.android.BridgeXmlBlockParser in project android_frameworks_base by crdroidandroid.
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.layoutlib.bridge.android.BridgeXmlBlockParser in project android_frameworks_base by crdroidandroid.
the class Resources_Delegate method loadXmlResourceParser.
@LayoutlibDelegate
static XmlResourceParser loadXmlResourceParser(Resources resources, 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(resources, id, mPlatformResourceFlag);
File f = new File(file);
try {
XmlPullParser parser = ParserFactory.create(f);
return new BridgeXmlBlockParser(parser, resources.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;
}
}
use of com.android.layoutlib.bridge.android.BridgeXmlBlockParser in project android_frameworks_base by crdroidandroid.
the class Resources_Delegate method getXml.
@LayoutlibDelegate
static XmlResourceParser getXml(Resources resources, int id) throws NotFoundException {
Pair<String, ResourceValue> value = getResourceValue(resources, id, mPlatformResourceFlag);
if (value != null) {
String v = value.getSecond().getValue();
if (v != null) {
// check this is a file
File f = new File(v);
if (f.isFile()) {
try {
XmlPullParser parser = ParserFactory.create(f);
return new BridgeXmlBlockParser(parser, resources.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(resources, id);
// this is not used since the method above always throws
return null;
}
use of com.android.layoutlib.bridge.android.BridgeXmlBlockParser in project android_frameworks_base by crdroidandroid.
the class StatusBar method loadIcon.
@Override
protected void loadIcon(int index, String iconName, Density density) {
if (!iconName.endsWith(".xml")) {
super.loadIcon(index, iconName, density);
return;
}
View child = getChildAt(index);
if (child instanceof ImageView) {
ImageView imageView = (ImageView) child;
// The xml is stored only in xhdpi.
IconLoader iconLoader = new IconLoader(iconName, Density.XHIGH, mSimulatedPlatformVersion, null);
InputStream stream = iconLoader.getIcon();
if (stream != null) {
try {
BridgeXmlBlockParser parser = new BridgeXmlBlockParser(ParserFactory.create(stream, null), (BridgeContext) mContext, true);
imageView.setImageDrawable(Drawable.createFromXml(mContext.getResources(), parser));
} catch (XmlPullParserException e) {
Bridge.getLog().error(LayoutLog.TAG_BROKEN, "Unable to draw wifi icon", e, null);
} catch (IOException e) {
Bridge.getLog().error(LayoutLog.TAG_BROKEN, "Unable to draw wifi icon", e, null);
}
}
}
}
Aggregations