示例#1
0
    def addChildrenLayout(self, element, rectView, parentLeft, parentTop,
                          rectViewElementInfoMap):
        # Setting background
        if (self.useTransparentBackground(rectView)):
            XmlUtil.addBackgroundColor(element,
                                       ColorUtil.toInt(0, 255, 255, 255),
                                       self.mColorWriter)
#        elif (RectViewTypes.isContanerView(rectView)) :
# We always want to genenate background regard less of the respect
# ratioand Environment.get().getValue(Environment.KEY_KEEP_ASPECT_RATIO) == Boolean.TRUE
# We will not do this if ratio is between input image and output is the same
#            bound = ImageUtil.getImageFromRect(self.mImage, rectView)
#            # We remove children here using 4 layer channel So we have to make sure that when we save it we will not Adding anymore layer
#            newImageBackground = ImageUtil.removeChildren(bound, rectView)
#            drawableId = self.mDrawableWriter.addResourceDirectly(newImageBackground, rectView)
#            XmlUtil.addBackroundImage(element, drawableId)

        else:
            XmlUtil.addBackgroundColor(element, rectView.mColor,
                                       self.mColorWriter)

        for childRectView in rectView.mChildren:
            _id = ""
            # list view has it own index
            if (childRectView.mType == RectViewTypes.VIEW_TYPE_LIST):
                _id = childRectView.mListInfo.xmlId
            else:
                _id = self.getId(LayoutHelper.FRAMELAYOUT_ELEMENT,
                                 childRectView)

            marginLeft = childRectView.x - parentLeft
            marginTop = childRectView.y - parentTop
            childElement = None
            if (self.useTransparentBackground(childRectView)):
                childElement = XmlUtil.addElement(
                    self.mDipCalculator, element,
                    self.getElementTypeForRect(childRectView), childRectView,
                    marginLeft, marginTop, _id)
            else:
                childElement = XmlUtil.addElement(
                    self.mDipCalculator, element,
                    self.getElementTypeForRect(childRectView), childRectView,
                    marginLeft, marginTop, _id, self.mColorWriter)

            rectViewElementInfoMap[childRectView] = ElementInfo(
                childElement, _id)
            self.addChildrenLayout(childElement, childRectView,
                                   childRectView.x, childRectView.y,
                                   rectViewElementInfoMap)

        # image view
        if (rectView.mType == RectViewTypes.VIEW_TYPE_IMAGE):
            drawableId = self.interestedIcons.get(rectView.mImageInfo.iconInfo)
            element.tag = Constants.ELEMENT_IMAGE_VIEW
            XmlUtil.addImageDrawable(element, drawableId)
            # override attributes
            XmlUtil.removeAttribute(element, Constants.ATTRIBUTE_BACKGROUND)
            _id = self.getId(Constants.ELEMENT_IMAGE_VIEW, rectView)
            XmlUtil.addId(element, _id)
            XmlUtil.addScaleType(element, "fitXY")
            rectViewElementInfoMap[rectView] = ElementInfo(element, _id)
        elif (rectView.mType == RectViewTypes.VIEW_TYPE_TEXT):

            textWrapper = rectView.mTextInfo.textWrapper
            stringId = self.mWriter.addResource(textWrapper.text)
            rectView.mTextInfo._id = stringId
            element.tag = Constants.ELEMENT_TEXT_VIEW
            if (Environment.getValue(
                    Environment.KEY_TEXT_WIDTH_WRAP_CONTENT) == True):
                XmlUtil.addSize(self.mDipCalculator, element,
                                Constants.ATTRIBUTE_WRAP_CONTENT,
                                rectView.height)
            else:
                XmlUtil.addSize(self.mDipCalculator, element, rectView.width,
                                rectView.height)

            XmlUtil.addBackgroundColor(element, rectView.mColor,
                                       self.mColorWriter)
            element.set(Constants.ATTRIBUTE_TEXT,
                        XmlUtil.getReferenceResourceId(stringId))
            _id = self.getId(Constants.ELEMENT_TEXT_VIEW, rectView)
            XmlUtil.addId(element, _id)
            textAttributes = textWrapper.getTextAttributes(
                self.mOcr, rectView.height)
            XmlUtil.addTextColor(element, rectView.textColor,
                                 self.mColorWriter)
            stypeId = self.mStyleWriter.addResource(textAttributes)
            element.set(Constants.ATTRIBUTE_STYLE,
                        XmlUtil.getReferenceStyleId(stypeId))
            rectViewElementInfoMap[rectView] = ElementInfo(element, _id)
示例#2
0
    def addChildrenLayout(self, element, rectView, parentLeft, parentTop,
                          rectViewElementInfoMap):
        # Setting background

        for childRectView in rectView.mChildren:
            _id = ""
            # list view has it own index

            _id = self.getId(LayoutHelper.FRAMELAYOUT_ELEMENT)
            marginLeft = childRectView.x
            marginTop = childRectView.y
            childElement = None
            childElement = XmlUtil.addElement(
                self.mDipCalculator, element,
                self.getElementTypeForRect(childRectView), childRectView,
                marginLeft, marginTop, _id, self.mColorWriter)

            rectViewElementInfoMap[childRectView] = ElementInfo(
                childElement, _id)
            self.addChildrenLayout(childElement, childRectView,
                                   childRectView.x, childRectView.y,
                                   rectViewElementInfoMap)

        XmlUtil.addBackgroundColor(element, rectView.mColor, self.mColorWriter)

        if (rectView == self.mRootView):
            pass

        # if children is icon add this attributes for code generation
        elif (rectView.isIconButton()):
            iconButtonName = rectView.getIconName()
            elementID = rectView.getElementID()
            element.tag = Constants.ELEMENT_IMAGE_BUTTON
            XmlUtil.addImageDrawable(element, iconButtonName)
            _id = self.getId(Constants.ELEMENT_IMAGE_BUTTON)

            # fit it to center
            XmlUtil.addAdditionalAttribute(element, "android:scaleType",
                                           "fitCenter")

            # add press animation
            XmlUtil.addAdditionalAttribute(element, "android:background",
                                           "@drawable/oniconpress")

            rectViewElementInfoMap[rectView] = ElementInfo(element, elementID)

        # if children is text add this attributes for code generation
        elif (rectView.isText()):
            # default text hello text
            helloText = "Hello Text"
            stringId = self.mWriter.addResource(helloText)
            element.tag = Constants.ELEMENT_TEXT_VIEW

            XmlUtil.addSize(self.mDipCalculator, element, rectView.width,
                            rectView.height)

            XmlUtil.addBackgroundColor(element, rectView.mColor,
                                       self.mColorWriter)
            element.set(Constants.ATTRIBUTE_TEXT,
                        XmlUtil.getReferenceResourceId(stringId))
            _id = self.getId(Constants.ELEMENT_TEXT_VIEW)
            XmlUtil.addId(element, _id)
            color = ColorUtil.cColortoInt(CColor.Black)
            XmlUtil.addTextColor(element, color, self.mColorWriter)
            # Set the auto text size property
            element.set(Constants.ATTRIBUTE_AUTOSIZE_TEXT_TYPE, "uniform")
            rectViewElementInfoMap[rectView] = ElementInfo(element, _id)

        # for all other UI elements
        else:
            # for checkbox
            if (rectView.isCheckbox()):
                _id = self.getId(Constants.ELEMENT_CHECK_BOX)
                element.tag = Constants.ELEMENT_CHECK_BOX
                # set checkbox default to uncheck
                XmlUtil.addAdditionalAttribute(element, "android:button",
                                               "@null")
                XmlUtil.addAdditionalAttribute(element, "app:theme",
                                               "@style/CheckboxStyle")
                XmlUtil.addAdditionalAttribute(
                    element, "android:background",
                    "?android:attr/listChoiceIndicatorMultiple")

                # for Toggle
            elif (rectView.isToogle()):
                element.tag = Constants.ELEMENT_SWITCH
                _id = self.getId(Constants.ELEMENT_SWITCH)
                minWidthDp = str(
                    self.mDipCalculator.pxToWidthDip(rectView.width) -
                    12) + Constants.UNIT_DIP
                XmlUtil.addAttribute(element, "android:switchMinWidth",
                                     minWidthDp)

            # for Slider
            elif (rectView.isSlider()):
                element.tag = Constants.ELEMENT_SEEK_BAR
                color = ColorUtil.cColortoInt(CColor.Black)
                XmlUtil.addAttributeColor(element, "android:progressTint",
                                          color, self.mColorWriter)
                XmlUtil.addAttributeColor(element, "android:thumbTint", color,
                                          self.mColorWriter)
                _id = self.getId(Constants.ELEMENT_SEEK_BAR)
                XmlUtil.addBackgroundColor(element, rectView.mColor,
                                           self.mColorWriter)

            # for star convert it to raing
            elif (rectView.isRating()):

                element.tag = Constants.ELEMENT_RATING_BAR
                XmlUtil.addAttribute(element, "android:layout_width",
                                     "wrap_content")
                XmlUtil.addAttribute(element, "android:layout_height",
                                     "wrap_content")
                XmlUtil.addAttribute(element, "android:theme",
                                     "@style/RatingBar")
                # based on the width of the element set number of star in rating
                widthOfStar = int(
                    self.mDipCalculator.pxToWidthDip(rectView.width) / 50)
                _id = self.getId(Constants.ELEMENT_RATING_BAR)
                XmlUtil.addAttribute(element, "android:numStars",
                                     str(widthOfStar))

            # for Searchbar
            elif (rectView.isSearchBar()):
                element.tag = Constants.ELEMENT_SEARCH_BAR
                _id = self.getId(Constants.ELEMENT_SEARCH_BAR)
                XmlUtil.addBackgroundColor(element, rectView.mColor,
                                           self.mColorWriter)

            # for Searchbar
            elif (rectView.isUserImage()):
                element.tag = Constants.ELEMENT_IMAGE_VIEW
                iconButtonName = "userimage"
                XmlUtil.addImageDrawable(element, iconButtonName)
                _id = self.getId(Constants.ELEMENT_IMAGE_VIEW)

                # for Container
            elif (rectView.isContainer()):
                XmlUtil.addAttribute(element, "android:background",
                                     "@drawable/border")
                _id = self.getId(LayoutHelper.FRAMELAYOUT_ELEMENT)

                # for Dropdown
            elif (rectView.isDropDown()):
                element.tag = Constants.ELEMENT_SPINNER
                XmlUtil.addAdditionalAttribute(element,
                                               "android:drawSelectorOnTop",
                                               "true")
                arrayId = self.mWriter.addArrayResource("default")
                # create a dummy array for the dropdown
                element.set(Constants.ATTRIBUTE_DROPDOWN_ENTRIES,
                            XmlUtil.getArrayReferenceResourceId(arrayId))
                _id = self.getId(Constants.ELEMENT_SPINNER)
                element.attrib.pop("android:background", None)

                # for Text Button
            elif (rectView.isButtonText()):
                element.tag = Constants.ELEMENT_BUTTON
                XmlUtil.addAdditionalAttribute(element, "android:text",
                                               "Button")
                _id = self.getId(Constants.ELEMENT_BUTTON)
                XmlUtil.addAdditionalAttribute(element, "android:background",
                                               "@drawable/oniconpress")

            XmlUtil.addId(element, _id)

            rectViewElementInfoMap[rectView] = ElementInfo(element, _id)