ArrayJoinUtil definition = new ArrayJoinUtil(); //定义数组 public override string handler(ElementEntity tnode) { foreach (var item in XmlTreeHandler.getAllElement(tnode, XmlTreeHandler.elementStatus.hasId)) { String resultDeclaration = ""; String resultdefinition = ""; String id = item.id; if (isUpper)//首字母是否大写 { id = item.id.firstToUpper(); } switch (type) { case javaTypeEnum.standard: resultDeclaration = String.Format("" + modifier + " {0} " + prefix + "{1}" + subffix + ";\n", item.type, id); resultdefinition = String.Format("" + prefix + "{0}=({1}) findViewById(R.id.{2});\n", id, item.type, item.id); break; case javaTypeEnum.annotations: resultDeclaration = String.Format(@" @ViewById {2} {0} {1};", item.type, item.id, modifier); break; case javaTypeEnum.xutils: resultDeclaration = String.Format(@" @ViewInject(R.id.{0}) " + modifier + " {1} " + prefix + "{2};" + subffix + "", item.id, item.type, id); break; } declaration.add(resultDeclaration); definition.add(resultdefinition); } return(""); }
public override string handler(ElementEntity tnode) { List <ElementEntity> list = XmlTreeHandler.getAllElement(tnode, XmlTreeHandler.elementStatus.hasId); //生成getViewItem中的部分代码 StringBuilder builder = new StringBuilder(); builder.Append("\n\n\n"); //生成viewHolder对象 builder.Append(getViewHoler(list)); return(builder.ToString()); }
/// <summary> /// 递归加载树结构 /// </summary> /// <param name="root"></param> /// <param name="rootNode"></param> private void searchThree(XmlNode root, TreeNode rootNode, ElementEntity element) { foreach (XmlNode item in root.ChildNodes) { //初始化当前结点 TreeNode tNode = new TreeNode(); tNode.Text = item.Name; //处理布局元素对象 ElementEntity elementitem = XmlTreeHandler.XmlNodeToElement(item); element.addElement(elementitem); tNode.Tag = elementitem;//树里面放布局元素对象 rootNode.Nodes.Add(tNode); //处理该结点的子节点 searchThree(item, tNode, elementitem); } }
public override string handler(ElementEntity tnode) { StringBuilder builder = new StringBuilder(); foreach (var item in XmlTreeHandler.getAllElement(tnode)) { if (item.hasAttribute("android:onClick") && item.hasAttribute("android:text")) { builder.Append(string.Format("\t\t\t/**\n\t\t\t* {0}\n\t\t\t* @param view\n\t\t\t*/\n\t\t\t", item.getAttribute("android:text"))); } if (item.hasAttribute("android:onClick")) { builder.Append(string.Format("public void {0}(View view){{\n\t\n\t\t\t}}\n", item.getAttribute("android:onClick"))); } } return(builder.ToString()); }
public override string handler(ElementEntity tnode) { var styleBuilder = new StringBuilder(); var oldArributeText = new StringBuilder(); foreach (var itemNode in XmlTreeHandler.getAllElement(tnode)) { if (itemNode.type == null) { continue; } oldArributeText.Append("<" + itemNode.type + "\n"); //========生成style======== styleBuilder.Append("/*样式代码*/\n\n"); //头处理 styleBuilder.Append(string.Format("<style name=\"{0}_style\">\n", styleName)); //处理当前结点 foreach (var item in itemNode.getAttributes()) { //不需要执行的跳过 if (Regex.IsMatch(item.Key, RegexStr)) { oldArributeText.Append(String.Format("{0}=\"{1}\"\n", item.Key, item.Value)); continue; } if (Regex.IsMatch(item.Value, textRegexStr)) { oldArributeText.Append(String.Format("{0}=\"{1}\"\n", item.Key, item.Value)); continue; } styleBuilder.Append(string.Format("<item name=\"{0}\">{1}</item>\n", item.Key, item.Value)); } //尾处理 styleBuilder.Append("</style>\n\n"); oldArributeText.Append(string.Format("android:style=\"@style/{0}_style\" />", styleName)); styleBuilder.Append("\n\n"); styleBuilder.Append("/*原来的xml元素代码*/\n\n"); } return(styleBuilder.Append(oldArributeText).ToString()); }