Exemplo n.º 1
0
    public View inflate(Context context, View parent) throws Exception {
      View view = create(context, (ViewGroup) parent);

      for (ViewNode child : children) {
        child.inflate(context, view);
      }

      invokeOnFinishInflate(view);
      return view;
    }
Exemplo n.º 2
0
 @Override
 protected void processResourceXml(File xmlFile, Document document, boolean isSystem)
     throws Exception {
   ViewNode topLevelNode = new ViewNode("top-level", new HashMap<String, String>(), isSystem);
   processChildren(document.getChildNodes(), topLevelNode);
   String layoutName =
       xmlFile.getParentFile().getName() + "/" + xmlFile.getName().replace(".xml", "");
   if (isSystem) {
     layoutName = "android:" + layoutName;
   }
   viewNodesByLayoutName.put(layoutName, topLevelNode.getChildren().get(0));
 }
Exemplo n.º 3
0
 private View inflateView(
     Context context, String layoutName, Map<String, String> attributes, View parent) {
   ViewNode viewNode = getViewNodeByLayoutName(layoutName);
   if (viewNode == null) {
     throw new RuntimeException("Could not find layout " + layoutName);
   }
   try {
     if (attributes != null) {
       for (Map.Entry<String, String> entry : attributes.entrySet()) {
         if (!entry.getKey().equals("layout")) {
           viewNode.attributes.put(entry.getKey(), entry.getValue());
         }
       }
     }
     return viewNode.inflate(context, parent);
   } catch (I18nException e) {
     throw e;
   } catch (Exception e) {
     throw new RuntimeException("error inflating " + layoutName, e);
   }
 }
Exemplo n.º 4
0
  private void processNode(Node node, ViewNode parent) {
    String name = node.getNodeName();
    NamedNodeMap attributes = node.getAttributes();
    Map<String, String> attrMap = new HashMap<String, String>();
    if (attributes != null) {
      int length = attributes.getLength();
      for (int i = 0; i < length; i++) {
        Node attr = attributes.item(i);
        attrMap.put(attr.getNodeName(), attr.getNodeValue());
      }
    }

    if (name.equals("requestFocus")) {
      parent.attributes.put("android:focus", "true");
      parent.requestFocusOverride = true;
    } else if (!name.startsWith("#")) {
      ViewNode viewNode = new ViewNode(name, attrMap, parent.isSystem);
      if (parent != null) parent.addChild(viewNode);

      processChildren(node.getChildNodes(), viewNode);
    }
  }