Esempio n. 1
0
    def anotateIntenal(self, root, elementDataMap):
        top = int(
            XmlUtil.getDipValue(root, Constants.ATTRIBUTE_LAYOUT_MARGIN_TOP))
        left = int(
            XmlUtil.getDipValue(root, Constants.ATTRIBUTE_LAYOUT_MARGIN_LEFT))
        width = int(XmlUtil.getDipValue(root,
                                        Constants.ATTRIBUTE_LAYOUT_WIDTH))
        height = int(
            XmlUtil.getDipValue(root, Constants.ATTRIBUTE_LAYOUT_HEIGHT))

        data = ElementData(top, left, width, height)
        elementDataMap[root] = data
    def updateMargin(root, attributeLayoutPaddingName, attributeLayoutMarginName) :
#		@SuppressWarnings("unchecked")
        elements = [elem for elem in root.iter()]
        
        if (len(elements) == 0) :
            return
		
		# Check if all children have margin dip value
        for node in elements:
            element = Element (node)
            if (not XmlUtil.hasDipValue(element, attributeLayoutMarginName)) :
                return
			
		

        paddingValue = 0
        if (XmlUtil.hasDipValue(root, attributeLayoutPaddingName)) :
            paddingValue = XmlUtil.getDipValue(root, attributeLayoutPaddingName)
		
		# find min margin
        minMargin = sys.maxint
        for node in elements:
            element = Element(node)
            minMargin = min(minMargin, XmlUtil.getDipValue(element,attributeLayoutMarginName))
		
		# we add more margin to the parent
        paddingValue += paddingValue + minMargin

        if (paddingValue == 0) :
            return
		

        root.addAttribute(attributeLayoutPaddingName, paddingValue + Constants.UNIT_DIP)

		# we subtract margin from children
        for node in elements:
            element = Element(node)
            root.set(attributeLayoutMarginName, XmlUtil.getDipValue(element, attributeLayoutMarginName) - minMargin + Constants.UNIT_DIP)