@Override public InputStream openRawResource(int id) throws NotFoundException { 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; }
@Override public float getDimension(int id) throws NotFoundException { 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; }
@Override public XmlResourceParser getLayout(int id) throws NotFoundException { 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; }
@Override public String getString(int id) throws NotFoundException { 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; }
@Override public Drawable getDrawable(int id) throws NotFoundException { 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; }
@Override public void getValue(int id, TypedValue outValue, boolean resolveRefs) throws NotFoundException { 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); }
@Override public int getColor(int id) throws NotFoundException { 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; }
@Override public int getDimensionPixelSize(int id) throws NotFoundException { 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; }
@Override public XmlResourceParser getXml(int id) throws NotFoundException { 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; }
@Override public int getInteger(int id) throws NotFoundException { 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; }