-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathXmlContainerConstraintLayout.java
More file actions
81 lines (73 loc) · 3.38 KB
/
XmlContainerConstraintLayout.java
File metadata and controls
81 lines (73 loc) · 3.38 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
/*********************************************************************************
* (c) 2020 by TotalCross Global Mobile Platform LTDA
* SPDX-License-Identifier: LGPL-3.0-only
*********************************************************************************/
package com.totalcross.knowcode.parse;
import totalcross.sys.InvalidNumberException;
import totalcross.sys.Settings;
import totalcross.ui.Container;
import totalcross.ui.Control;
import totalcross.ui.ImageControl;
import totalcross.ui.font.Font;
import totalcross.ui.gfx.Color;
import totalcross.ui.image.Image;
import totalcross.ui.image.ImageException;
import totalcross.util.BigDecimal;
/**
* XmlContainerConstraintLayout is responsible to parse a ConstraintLayout Android XML to a Container Totalcross.
* <p>
* This class works together with the abstract class XmlContainerLayout and it is responsible to create all Controls
* from the XML components.
* ConstraintLayout can work with relative positioning components, where the positioning of the component depends
* on the screen size, or absolute positioning components, where the component's location is fixed on the screen
* <p>
* this class is instantiated automatically, the XmlContainerFactory class reads the type of xml layout and
* instantiates the corresponding layout class according to the nomenclature of the main tag.
*/
public class XmlContainerConstraintLayout extends XmlContainerLayout {
boolean isLayout = true;
/**
* 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 {
int xLocal = LEFT;
int yLocal = TOP;
int widLocal = PARENTSIZE;
int heiLocal = PARENTSIZE;
if (isLayout) {
isLayout = false;
setBackColor(Color.getRGB(node.getBackgroundColor()));
xLocal = LEFT + node.getPaddingLeft();
yLocal = TOP + node.getPaddingTop();
widLocal = FILL - node.getPaddingRight();
heiLocal = FILL - node.getPaddingBottom();
node.setWp();
node.setHp();
centralContainer = new Container();
String bg = node.getBackgroundImage();
if(bg!= null && !bg.contains("#"))
add(new ImageControl(new Image(bg).getHwScaledInstance(node.getW(), node.getH())),LEFT,TOP,FILL,FILL);
add(centralContainer, xLocal, yLocal, widLocal, heiLocal);
} else if (node.getAttributeName().equals("ProgressBar")&& node.getStyle() == null || node.getStyle().contains("Horizontal")) {
centralContainer.add(createInstanceOf(node), node.getRelativeX(), new BigDecimal(node.getRelativeY()).add(BigDecimal.valueOf(((float)node.getH()/2.0-((((float)Settings.screenHeight/200.0))*Float.parseFloat(node.getScaleY()))))).intValue (), node.getW(), (int) ((((float)Settings.screenHeight/100.0)) *Float.parseFloat(node.getScaleY())), getRelativeControl(node));
}
else{
centralContainer.add(createInstanceOf(node), node.getRelativeX(), node.getRelativeY(), node.getW(), node.getH(), getRelativeControl(node));
}
}
@Override
public void setWidthHeight(NodeSax node,int w,int h){
node.setHp(h);
node.setWp(w);
}
private Control getRelativeControl(NodeSax node) {
if (node.getRelative() != null) {
return getControlByID(node.getRelative());
} else
return lastControl;
}
}