-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathXmlContainerLinearLayout.java
More file actions
87 lines (75 loc) · 2.94 KB
/
XmlContainerLinearLayout.java
File metadata and controls
87 lines (75 loc) · 2.94 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
/*********************************************************************************
* (c) 2020 by TotalCross Global Mobile Platform LTDA
* SPDX-License-Identifier: LGPL-3.0-only
*********************************************************************************/
package com.totalcross.knowcode.ui;
import com.totalcross.knowcode.xml.NodeSax;
import totalcross.sys.InvalidNumberException;
import totalcross.ui.Container;
import totalcross.ui.gfx.Color;
import totalcross.ui.image.ImageException;
/**
* XmlContainerLinearLayout is responsible to parse a LinearLayout Android XML to a Container Totalcross.
* <p>
* This class specialize the super class XmlContainerLayout and it's responsible to create all Controls
* from the XML components of a LinearLayout.
* LinearLayout is a view group that aligns all children in a single direction, vertically or horizontally.
* <p>
* XmlContainerLinearLayout is instantiated automatically, the XmlContainerFactory class reads the type of XML layout and
* instantiates the corresponding layout class.
*/
public class XmlContainerLinearLayout extends XmlContainerLayout {
boolean isLayout = true;
String orientation = null;
int xpos = LEFT;
int ypos = TOP;
int widthPos = FILL;
int heightPos = FILL;
/**
* Responsible to add all components of a XML file on Container
* This method is call by <code>tagName</code> on the super class {@link XmlContainerLayout}
* who make the read of each tag of XML file
* @param node
* a node of a XML file
* */
public void addscreen(NodeSax node) throws totalcross.io.IOException, ImageException, InvalidNumberException {
if (isLayout) {
isLayout = false;
centralContainer = new Container();
String bckG = node.getBackgroundColor();
if (bckG != null) {
centralContainer.setBackColor(Color.getRGB(bckG));
}
orientation = node.getOrientation();
// FIXME: atualizar x e y de acordo com a orientação e atributos
add(centralContainer, xpos, ypos, widthPos, heightPos);
// FIXME: atualizar para quando existirem vários layouts em um mesmo xml
} else if (node.getAttributeName().equals("LinearLayout")) {
orientation = node.getOrientation();
} else {
if ((componentsMap.size() > 0) && (lastControl != null)) {
if (orientation.equals("horizontal")) {
xpos = xpos + lastControl.getWidth() + 3;
} else if ((orientation.equals("vertical"))) {
ypos = ypos + lastControl.getHeight() + 3;
}
xpos = node.getRelativeX();
widthPos = node.getW();
heightPos = node.getH();
} else {
// FIXME: ATUALIZAR!! Muita coisa faltando do LinearLayout
if (node.getLayout_gravity() == null) {
xpos = node.getRelativeX();
} else {
if (node.getLayout_gravity().equals("center")) {
xpos = CENTER;
}
}
ypos = node.getRelativeY();
widthPos = node.getW();
heightPos = node.getH();
}
centralContainer.add(createInstanceOf(node), xpos, ypos, widthPos, heightPos, lastControl);
}
}
}