def createListLayoutCode(self, listMetadata, index, listView): baseListItemMetadata = listMetadata.mListItemMetadatas[0] # document = XmlUtil.createDocument() rootView = RectView(baseListItemMetadata.bound, None) for rectView in baseListItemMetadata.baseViews: rootView.addChild(rectView) for rectView in baseListItemMetadata.additionalViews: rootView.addChild(rectView) rootView.mChildren.sort( key=cmp_to_key(RectUtil.getTopBottomComparator())) rootView.mChildren.sort( key=cmp_to_key(RectUtil.getLeftRightComparator())) rootElement = XmlUtil.createRoot(self.mDipCalculator, FRAMELAYOUT_ELEMENT, rootView, self.mColorWriter) _map = {} self.addChildrenLayout(rootElement, rootView, listView.x, listView.y, _map) rectViews = RectUtil.toRects(rootView) rectViews.remove(rootView) XmlUtil.writeDocument( rootView, self.mOutProjectFolder + Constants.DEFAULT_LAYOUT_PATH + "/" + Constants.DEFAULT_LAYOUT_LIST_PREFIX + index + ".xml")
def createListLayoutCode(self, listView, listMetadata, aditionalListViewItemData, index): if len(listMetadata.getListItemMetadatas()) == 0: return baseListItemMetadata = listMetadata.getListItemMetadatas()[0] # Document document = XmlUtil.createDocument() rootView = RectView(baseListItemMetadata.bound, None) for rectView in baseListItemMetadata.baseViews: rootView.addChild(rectView) for rectView in baseListItemMetadata.additionalViews: rootView.addChild(rectView) rootView.mChildren.sort( key=cmp_to_key(RectUtil.getTopBottomComparator())) rootView.mChildren.sort( key=cmp_to_key(RectUtil.getLeftRightComparator())) rootElement = XmlUtil.createRoot(self.mDipCalculator, self.FRAMELAYOUT_ELEMENT, rootView, self.mColorWriter) _map = {} self.addChildrenLayout(rootElement, rootView, listView.getX(), listView.getY(), _map) rectViews = RectUtil.toRects(rootView) rectViews.remove(rootView) viewIdMap = {} # For baseview for rectView in baseListItemMetadata.baseViews: elementInfo = _map[rectView] viewIdMap[rectView] = elementInfo._id # For additionview for rectViewWrapper in aditionalListViewItemData: elementInfo = _map[rectViewWrapper.view] viewIdMap[rectViewWrapper.view] = elementInfo.id # TODO: since we checked already (#getAditionalListViewItemData), all # base view should only image views resourceInfoMap = {} listItemMetadatas = listMetadata.getListItemMetadatas() for listItemMetadata in listItemMetadatas: for baseView in listItemMetadata.baseViews: resourceInfoMap[baseView] = self.getInfoResource(baseView) for rectViewWrapper in aditionalListViewItemData: for viewWrapper in rectViewWrapper.relativeViews: resourceInfoMap[viewWrapper.view] = self.getInfoResource( viewWrapper.view) listMetadata.generateCode(index, listView.getListInfo().xmlId, self.mOutProjectFolder, aditionalListViewItemData, viewIdMap, resourceInfoMap) # We need to store current x, y, w, h of element before we loss # them anotateMap = LayoutFilter.anotate(rootView) layoutFilter = RelativeLayoutFilter() layoutFilter.doFilter(rootView, anotateMap) XmlUtil.writeDocument( rootView, self.mOutProjectFolder + Constants.DEFAULT_LAYOUT_PATH + "/" + Constants.DEFAULT_LAYOUT_LIST_PREFIX + index + ".xml")