예제 #1
0
  private void generatePublicXml(ResPackage pkg, Directory out, XmlSerializer serial)
      throws AndrolibException {
    try {
      OutputStream outStream = out.getFileOutput("values/public.xml");
      serial.setOutput(outStream, null);
      serial.startDocument(null, null);
      serial.startTag(null, "resources");

      for (ResResSpec spec : pkg.listResSpecs()) {
        serial.startTag(null, "public");
        serial.attribute(null, "type", spec.getType().getName());
        serial.attribute(null, "name", spec.getName());
        serial.attribute(null, "id", String.format("0x%08x", spec.getId().id));
        serial.endTag(null, "public");
      }

      serial.endTag(null, "resources");
      serial.endDocument();
      serial.flush();
      outStream.close();
    } catch (IOException ex) {
      throw new AndrolibException("Could not generate public.xml file", ex);
    } catch (DirectoryException ex) {
      throw new AndrolibException("Could not generate public.xml file", ex);
    }
  }
예제 #2
0
  @Override
  public void serializeToResValuesXml(XmlSerializer serializer, ResResource res)
      throws IOException, AndrolibException {
    serializer.startTag(null, "style");
    serializer.attribute(null, "name", res.getResSpec().getName());
    if (!mParent.isNull() && !mParent.referentIsNull()) {
      serializer.attribute(null, "parent", mParent.encodeAsResXmlAttr());
    } else if (res.getResSpec().getName().indexOf('.') != -1) {
      serializer.attribute(null, "parent", "");
    }
    for (int i = 0; i < mItems.length; i++) {
      ResResSpec spec = mItems[i].m1.getReferent();

      if (spec == null) {
        continue;
      }

      String name = null;
      String value = null;

      String resource = spec.getDefaultResource().getValue().toString();
      // hacky-fix remove bad ReferenceVars
      if (resource.contains("ResReferenceValue@")) {
        continue;
      } else if (resource.contains("ResStringValue@")
          || resource.contains("ResStyleValue@")
          || resource.contains("ResBoolValue@")) {
        name = "@" + spec.getFullName(res.getResSpec().getPackage(), false);
      } else {
        ResAttr attr = (ResAttr) spec.getDefaultResource().getValue();
        value = attr.convertToResXmlFormat(mItems[i].m2);
        name = spec.getFullName(res.getResSpec().getPackage(), true);
      }

      if (value == null) {
        value = mItems[i].m2.encodeAsResXmlValue();
      }

      if (value == null) {
        continue;
      }

      serializer.startTag(null, "item");
      serializer.attribute(null, "name", name);
      serializer.text(value);
      serializer.endTag(null, "item");
    }
    serializer.endTag(null, "style");
  }