-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathNodeSax.java
More file actions
1066 lines (973 loc) · 33.7 KB
/
NodeSax.java
File metadata and controls
1066 lines (973 loc) · 33.7 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
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/*********************************************************************************
* (c) 2020 by TotalCross Global Mobile Platform LTDA
* SPDX-License-Identifier: LGPL-3.0-only
*********************************************************************************/
package com.totalcross.knowcode.parse;
import static totalcross.ui.Control.*;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Map;
import java.util.Set;
import totalcross.io.IOException;
import totalcross.sys.InvalidNumberException;
import totalcross.sys.Settings;
import totalcross.sys.Vm;
import totalcross.ui.image.ImageException;
import totalcross.util.BigDecimal;
import totalcross.util.UnitsConverter;
/**
* NodeSax access the nodes and attributes of the XML file.
* Each method reads a specific tag and return its value.
*/
public class NodeSax {
private Map<String, String> attributesMap = new HashMap<String, String>();
private String attributeValue;
private String attributeName = new String();
private String id;
private boolean landscape = false;
private String relative;
private ArrayList<String> imgExtensions = new ArrayList<String>();
private float wp = 0, hp = 0;
/**
* Creates a NodeSax object
*
* @throws ImageException
* @throws IOException
*/
public NodeSax() throws IOException, ImageException {
}
/**
* Get the attribute name of tag
*
* @return attribute value of tag
*/
public String getAttributeName() {
return attributeName;
}
/**
* Get relative position set by <code>getRelativeX()</code> and <code>getRelativeY()</code>
*
* @return attribute value of tags related to relative positioning
*/
public String getRelative() {
if (relative != null && !relative.contains("@+")) {
relative = relative.replace("@", "@+");
}
return relative;
}
private String getValue(String a) {
return attributesMap.get(a);
}
/**
* Get attribute value of tag <code>"android:max"</code>
*
* @return attribute value of tag
*/
public String getMax() {
if (getValue("android:max") == null) {
return "100";
}
return getValue("android:max");
}
/**
* Get attribute value of tag <code>"android:progress"</code>
*
* @return attribute value of tag
*/
public String getProgress() {
if (getValue("android:progress") == null)
return "0";
return getValue("android:progress");
}
/**
* Get attribute value of tag <code>"android:textStyle"</code>
*
* @return attribute value of tag
*/
public String getStyle() {
if (getValue("style") != null)
return getValue("style");
if (getValue("android:textStyle") == null) {
return "normal";
}
return getValue("android:textStyle");
}
/**
* Get attribute value of tag <code>"android:id"</code>
*
* @return attribute value of tag
*/
public String getId() {
if (id == null) {
return getValue("android:id");
} else {
attributeValue = id;
}
id = null;
return attributeValue;
}
/**
* Get attribute value of tag <code>"android:textSize"</code>
* @return attribute value of tag
* @throws totalcross.sys.InvalidNumberException
*/
public int getTextsize() throws InvalidNumberException {
attributeValue = getValue("android:textSize");
if (attributeValue == null || "".equals(attributeValue)) {
return 14;
} else {
if (attributeValue.contains("dp")) {
attributeValue = attributeValue.replace("dp", "");
}
if (attributeValue.contains("sp")) {
attributeValue = attributeValue.replace("sp", "");
}
}
return new BigDecimal(UnitsConverter.toPixels(Integer.parseInt(attributeValue) - 5 + DP)).multiply(BigDecimal.valueOf(hp)).intValue();
}
/**
* Get attribute value of tag <code>"android:textStyle"</code>
*
* @return attribute value of tag
*/
public boolean getTextStyleBold() {
attributeValue = getValue("android:textStyle");
if (attributeValue == null || "".equals(attributeValue)) {
return false;
} else {
if (attributeValue.equals("bold"))
return true;
else
return false;
}
}
/**
* Get attribute value of tag <code>"android:background"</code> to color background
*
* @return attribute value of tag
*/
public String getBackgroundColor() {
attributeValue = getValue("android:background");
String attributeValue2 = getValue("app:srcCompat");
if (attributeValue == null && attributeValue2 == null || "".equals(attributeValue)) {
return null;
} else {
if (attributeValue == null && attributeValue2 != null) {
attributeValue = attributeValue2;
}
if ('#' == attributeValue.charAt(0)) {
attributeValue = attributeValue.substring(1);
}
}
return attributeValue;
}
/**
* Get attribute value of tags <code>"android:background"</code> and <code>"tools:background"</code> to image background
*
* @return attribute value of tag
*/
public String getBackgroundImage() {
attributeValue = getValue("android:background");
if(attributeValue==null)
attributeValue = getValue("tools:background");
if(attributeValue==null)
attributeValue = getValue("app:srcCompat");
if (attributeValue == null || "".equals(attributeValue) || attributeValue.contains("#")) {
return attributeValue;
} else {
if ('@' == attributeValue.charAt(0)) {
attributeValue = attributeValue.substring(1);
}
if (attributeValue.contains(".png") || attributeValue.contains(".jpg")) {
imgExtensions.add(attributeValue);
return attributeValue;
} if(imgExtensions.size()!=0){
for(int index = 0; index<imgExtensions.size();index++){
if(imgExtensions.get(index).contains(attributeValue)&&attributeValue.length()==imgExtensions.get(index).length())
return imgExtensions.get(index);
}
}
attributeValue = getImageExtension(attributeValue);
}
return attributeValue;
}
private String getImageExtension(String path) {
String[] extensoes = {".jpg", ".png", ".bmp", ".jpeg", ".gif",
".JPG", ".PNG", ".BMP", ".JPEG", ".GIF"};
byte[] xml = null;
for (int i = 0; i < extensoes.length; i++) {
xml = Vm.getFile(path + extensoes[i]);
if (xml != null) {
imgExtensions.add(path+ extensoes[i]);
return path + extensoes[i];
}
}
return path;
}
/**
* Get attribute value of tag <code>"android:textColor"</code>
*
* @return attribute value of tag
*/
public String getTextColor() {
attributeValue = getValue("android:textColor");
if (attributeValue == null || "".equals(attributeValue)) {
return null;
} else {
if ('#' == attributeValue.charAt(0)) {
attributeValue = attributeValue.substring(1);
}
return attributeValue;
}
}
/**
* Get attribute value of tag <code>"android:indeterminateTint"</code>
*
* @return attribute value of tag
*/
public String getTintColor() {
attributeValue = getValue("android:indeterminateTint");
if (attributeValue == null || "".equals(attributeValue)) {
return "FFFFFF";
} else {
if ('#' == attributeValue.charAt(0)) {
attributeValue = attributeValue.substring(1);
}
return attributeValue;
}
}
/**
* Get the height value converted to Pixel, checks the following tags <code>"android:layout_height"</code>
* and <code>"app:layout_constraintHeight_percent"</code>
*
* @return height value converted to Pixel
* @throws InvalidNumberException
*/
public int getH() throws InvalidNumberException {
attributeValue = getValue("app:layout_constraintHeight_percent");
if (attributeValue != null)
try {
return new BigDecimal(attributeValue).multiply(BigDecimal.valueOf(Settings.screenHeight)).intValue();
} catch (InvalidNumberException e) {
return 0;
}
attributeValue = getValue("android:layout_height");
if (attributeValue == null || "".equals(attributeValue)) {
attributeValue = getValue("app:layout_constraintHeight_percent");
if (attributeValue != null)
return new BigDecimal(attributeValue).multiply(BigDecimal.valueOf(Settings.screenHeight)).intValue();
return 0;
} else {
if (attributeValue.equals("wrap_content")) {
return PREFERRED;
} else {
if (attributeValue.contains("dp")) {
attributeValue = attributeValue.replace("dp", "");
}
}
}
return new BigDecimal(UnitsConverter.toPixels(Integer.parseInt(attributeValue)+DP)).multiply(BigDecimal.valueOf(hp)).intValue();
}
/**
* Get attribute value of tag <code>"app:srcCompat"</code>
*
* @return attribute value of tag
*/
public String getSrcCompat() {
attributeValue = getValue("app:srcCompat");
if (attributeValue == null || "".equals(attributeValue)) {
return null;
} else {
if ('@' == attributeValue.charAt(0)) {
attributeValue = attributeValue.substring(1);
}
if (attributeValue.contains(".png") || attributeValue.contains(".jpg")) {
return attributeValue;
}
attributeValue = getImageExtension(attributeValue);
return attributeValue;
}
}
/**
* Get attribute value of tag <code>"android:paddingTop"</code>
*
* @return attribute value of tag
*/
public int getPaddingTop() {
attributeValue = getValue("android:paddingTop");
if (attributeValue == null) {
return 0;
}
if (attributeValue.contains("dp")) {
attributeValue = attributeValue.replace("dp", "");
}
return UnitsConverter.toPixels(Integer.parseInt(attributeValue) + DP);
}
/**
* Get attribute value of tag <code>"android:paddingBottom"</code>
*
* @return attribute value of tag
*/
public int getPaddingBottom() {
attributeValue = getValue("android:paddingBottom");
if (attributeValue == null) {
return 0;
}
if (attributeValue.contains("dp")) {
attributeValue = attributeValue.replace("dp", "");
}
return UnitsConverter.toPixels(Integer.parseInt(attributeValue) + DP);
}
/**
* Get attribute value of tag <code>"android:paddingRight"</code>
*
* @return attribute value of tag
*/
public int getPaddingRight() {
attributeValue = getValue("android:paddingRight");
if (attributeValue == null) {
return 0;
}
if (attributeValue.contains("dp")) {
attributeValue = attributeValue.replace("dp", "");
}
return UnitsConverter.toPixels(Integer.parseInt(attributeValue) + DP);
}
/**
* Get attribute value of tag <code>"android:paddingLeft"</code>
*
* @return attribute value of tag
*/
public int getPaddingLeft() {
attributeValue = getValue("android:paddingLeft");
if (attributeValue == null) {
return 0;
}
if (attributeValue.contains("dp")) {
attributeValue = attributeValue.replace("dp", "");
}
return UnitsConverter.toPixels(Integer.parseInt(attributeValue) + DP);
}
/**
* Get the width value converted to Pixel, checks the following tags <code>"android:layout_width"</code>
* and <code>"app:layout_constraintWidth_percent"</code>
* @return width value converted to Pixel
* @throws totalcross.sys.InvalidNumberException
*/
public int getW() throws InvalidNumberException {
attributeValue = getValue("app:layout_constraintWidth_percent");
if (attributeValue != null)
try {
return new BigDecimal(attributeValue).multiply(BigDecimal.valueOf(Settings.screenWidth)).intValue();
} catch (InvalidNumberException e) {
return 0;
}
attributeValue = getValue("android:layout_width");
if (attributeValue == null || "".equals(attributeValue)) {
return 0;
} else {
if (attributeValue.equals("wrap_content")) {
return PREFERRED;
}
if (attributeValue.equals("match_parent") || attributeValue.equals("fill_parent")) {
return Settings.screenWidth;
}
if (attributeValue.equals("0dp")) {
return FIT;
} else {
if (attributeValue.contains("dp")) {
attributeValue = attributeValue.replace("dp", "");
}
}
}
return new BigDecimal(UnitsConverter.toPixels(Integer.parseInt(attributeValue)+DP)).multiply(BigDecimal.valueOf(wp)).intValue();
}
/**
* Get attribute value of tag <code>"android:layout_width"</code>
*
* @return attribute value of tag
*/
public String getLayout_width() {
attributeValue = getValue("android:layout_width");
if (attributeValue == null || "".equals(attributeValue)) {
return null;
}
return attributeValue;
}
/**
* Get attribute value of tag <code>"android:layout_height"</code>
*
* @return attribute value of tag
*/
public String getLayout_height() {
attributeValue = getValue("android:layout_height");
if (attributeValue == null || "".equals(attributeValue)) {
return null;
}
return attributeValue;
}
/**
* Get value of x axis converted to Pixel of tag <code>"tools:layout_editor_absoluteX"</code>
*
* @return attribute value of tag converted to Pixel
*/
public int getAbsoluteX() {
attributeValue = getValue("tools:layout_editor_absoluteX");
if (attributeValue == null || "".equals(attributeValue)) {
return 0;
} else {
if (attributeValue.equals("wrap_content"))
return PREFERRED;
else {
if (attributeValue.contains("dp"))
attributeValue = attributeValue.replace("dp", "");
}
return UnitsConverter.toPixels(Integer.parseInt(attributeValue) + DP);
}
}
/**
* Get value of y axis converted to Pixel of tag <code>"tools:layout_editor_absoluteY"</code>
*
* @return attribute value of tag converted to Pixel
*/
public int getAbsoluteY() {
attributeValue = getValue("tools:layout_editor_absoluteY");
if (attributeValue == null || "".equals(attributeValue)) {
return 0;
} else {
if (attributeValue.equals("wrap_content")) {
return PREFERRED;
} else {
if (attributeValue.contains("dp")) {
attributeValue = attributeValue.replace("dp", "");
}
}
return UnitsConverter.toPixels(Integer.parseInt(attributeValue) + DP);
}
}
/**
* Get orientation based on tag <code>"android:orientation"</code>
*
* @return attribute value of tag
*/
public String getOrientation() {
attributeValue = getValue("android:orientation");
if (attributeValue == null || "".equals(attributeValue)) {
return null;
} else {
return attributeValue;
}
}
/**
* Get the relative positioning of x axis.
* Checks the following tags:
* <code>"android:layout_alignParentLeft"</code>
* <code>"app:layout_constraintLeft_toLeftOf"</code>
* <code>"app:layout_constraintStart_toStartOf"</code>
* <code>"app:layout_constraintStart_toEndOf"</code>
* <code>"app:layout_constraintLeft_toRightOf"</code>
* <code>"app:layout_constraintEnd_toStartOf"</code>
* <code>"app:layout_constraintRight_toRightOf"</code>
* <code>"app:layout_constraintEnd_toEndOf"</code>
* <code>"android:layout_alignParentRight"</code>
* <code>"android:layout_alignParentEnd"</code>
* <code>"android:layout_alignParentStart"</code>
* <code>"android:layout_toEndOf"</code>
* <code>"android:layout_alignRight"</code>
* <code>"android:layout_alignLeft"</code>
* <code>"android:layout_alignEnd"</code>
* <code>"android:layout_toLeftof"</code>
* <code>"android:layout_toRightOf"</code>
* <code>"android:layout_toStartOf"</code>
* <code>"android:layout_centerInParent"</code>
* <code>"android:layout_centerHorizontal"</code>
* <code>"android:layout_editor_absoluteX"</code>
*
* @return totalcross positioning constant
* @throws totalcross.sys.InvalidNumberException
*/
public int getRelativeX() throws InvalidNumberException {
attributeValue = getValue("android:layout_alignParentLeft");
if (attributeValue != null) {
return LEFT;
}
attributeValue = getValue("app:layout_constraintLeft_toLeftOf");
if (attributeValue != null) {
if (attributeValue.equals("parent")) {
return LEFT;
} else {
relative = attributeValue;
return SAME;
}
}
attributeValue = getValue("app:layout_constraintStart_toStartOf");
if (attributeValue != null) {
if (attributeValue.equals("parent")) {
return LEFT;
} else {
relative = attributeValue;
return SAME;
}
}
attributeValue = getValue("app:layout_constraintStart_toEndOf");
if (attributeValue != null) {
if (attributeValue.equals("parent")) {
return LEFT;
} else {
relative = attributeValue;
return SAME;
}
}
attributeValue = getValue("app:layout_constraintLeft_toRightOf");
if (attributeValue != null) {
relative = attributeValue;
return AFTER;
}
attributeValue = getValue("app:layout_constraintRight_toLeftOf");
if (attributeValue != null) {
relative = attributeValue;
return BEFORE;
}
attributeValue = getValue("app:layout_constraintEnd_toStartOf");
if (attributeValue != null) {
relative = attributeValue;
return BEFORE;
}
attributeValue = getValue("app:layout_constraintRight_toRightOf");
if (attributeValue != null) {
if (attributeValue.equals("parent")) {
return RIGHT;
} else {
relative = attributeValue;
return RIGHT_OF;
}
}
attributeValue = getValue("app:layout_constraintEnd_toEndOf");
if (attributeValue != null) {
if (attributeValue.equals("parent")) {
return RIGHT;
} else {
relative = attributeValue;
return RIGHT_OF;
}
}
attributeValue = getValue("android:layout_alignParentRight");
if (attributeValue != null) {
return RIGHT;
}
attributeValue = getValue("android:layout_alignParentEnd");
if (attributeValue != null) {
return RIGHT;
}
attributeValue = getValue("android:layout_alignParentStart");
if (attributeValue != null) {
return LEFT;
}
attributeValue = getValue("android:layout_toEndOf");
if (attributeValue != null) {
relative = attributeValue;
return AFTER;
}
attributeValue = getValue("android:layout_alignRight");
if (attributeValue != null) {
relative = attributeValue;
return RIGHT_OF;
}
attributeValue = getValue("android:layout_alignLeft");
if (attributeValue != null) {
relative = attributeValue;
return SAME;
}
attributeValue = getValue("android:layout_alignLeft");
if (attributeValue != null) {
relative = attributeValue;
return SAME;
}
attributeValue = getValue("android:layout_alignEnd");
if (attributeValue != null) {
relative = attributeValue;
return RIGHT_OF;
}
attributeValue = getValue("android:layout_toLeftof");
if (attributeValue != null) {
relative = attributeValue;
return BEFORE;
}
attributeValue = getValue("android:layout_toRightOf");
if (attributeValue != null) {
relative = attributeValue;
return AFTER;
}
attributeValue = getValue("android:layout_toStartOf");
if (attributeValue != null) {
relative = attributeValue;
return BEFORE;
}
attributeValue = getValue("android:layout_centerInParent");
if (attributeValue != null) {
return CENTER;
}
attributeValue = getValue("android:layout_centerHorizontal");
if (attributeValue != null) {
return CENTER;
}
attributeValue = getValue("tools:layout_editor_absoluteX");
if (attributeValue == null) {
return LEFT;
}
if (attributeValue.equals("wrap_content")) {
return PREFERRED;
} else {
if (attributeValue.contains("dp")) {
attributeValue = attributeValue.replace("dp", "");
}
}
return new BigDecimal(UnitsConverter.toPixels(Integer.parseInt(attributeValue)+DP)).multiply(BigDecimal.valueOf(wp)).intValue();
}
/**
* Get the relative positioning of y axis.
* Checks the following tags:
* <code>"app:layout_constraintTop_toBottomOf"</code>
* <code>"app:layout_constraintTop_toTopOf"</code>
* <code>"app:constraintBottom_toTopOf"</code>
* <code>"app:layout_constraintBottom_toBottomOf"</code>
* <code>"app:layout_constraintBaseline_toBaselineOf"</code>
* <code>"app:layout_constraintRight_toRightOf"</code>
* <code>"android:layout_alignBaseline"</code>
* <code>"android:layout_alignTop"</code>
* <code>"android:layout_alignBottom"</code>
* <code>"android:layout_below"</code>
* <code>"android:layout_above"</code>
* <code>"android:layout_alignParentTop"</code>
* <code>"android:layout_alignParentBottom"</code>
* <code>"android:layout_centerVertical"</code>
* <code>"android:layout_toRightOf"</code>
* <code>"android:layout_toStartOf"</code>
* <code>"android:layout_centerInParent"</code>
* <code>"tools:layout_editor_absoluteY"</code>
*
* @return totalcross positioning constant
* @throws InvalidNumberException
*/
public int getRelativeY() throws InvalidNumberException {
attributeValue = getValue("app:layout_constraintTop_toBottomOf");
if (attributeValue != null) {
if (attributeValue.equals("parent"))
return TOP;
relative = attributeValue;
return AFTER;
}
attributeValue = getValue("app:layout_constraintTop_toTopOf");
if (attributeValue != null) {
if (attributeValue.equals("parent"))
return TOP;
relative = attributeValue;
return SAME;
}
attributeValue = getValue("app:constraintBottom_toTopOf");
if (attributeValue != null)
return BEFORE;
attributeValue = getValue("app:layout_constraintBottom_toBottomOf");
if (attributeValue != null)
if (attributeValue.equals("parent"))
return BOTTOM;
else {
relative = attributeValue;
return BOTTOM_OF;
}
attributeValue = getValue("layout_constraintBaseline_toBaselineOf");
if (attributeValue != null)
if (attributeValue.equals("parent"))
return CENTER_OF;
else {
relative = attributeValue;
return CENTER_OF;
}
attributeValue = getValue("app:layout_constraintRight_toRightOf");
if (attributeValue != null) {
if (attributeValue.equals("parent"))
return Settings.screenWidth - getW();
return RIGHT;
}
attributeValue = getValue("android:layout_alignBaseline");
if (attributeValue != null) {
relative = attributeValue;
return CENTER_OF;
}
attributeValue = getValue("android:layout_alignTop");
if (attributeValue != null) {
relative = attributeValue;
return SAME;
}
attributeValue = getValue("android:layout_alignBottom");
if (attributeValue != null) {
relative = attributeValue;
return BOTTOM_OF;
}
attributeValue = getValue("android:layout_below");
if (attributeValue != null) {
relative = attributeValue;
return AFTER;
}
attributeValue = getValue("android:layout_above");
if (attributeValue != null) {
relative = attributeValue;
return BEFORE;
}
attributeValue = getValue("android:layout_alignParentTop");
if (attributeValue != null) {
return TOP;
}
attributeValue = getValue("android:layout_alignParentBottom");
if (attributeValue != null) {
return BOTTOM;
}
attributeValue = getValue("android:layout_centerVertical");
if (attributeValue != null) {
return CENTER;
}
attributeValue = getValue("android:layout_centerInParent");
if (attributeValue != null) {
return CENTER;
}
attributeValue = getValue("tools:layout_editor_absoluteY");
if (attributeValue == null) {
return TOP;
}
if (attributeValue.equals("wrap_content")) {
return PREFERRED;
} else {
if (attributeValue.contains("dp")) {
attributeValue = attributeValue.replace("dp", "");
}
}
return new BigDecimal(UnitsConverter.toPixels(Integer.parseInt(attributeValue)+DP)).multiply(BigDecimal.valueOf(hp)).intValue();
}
/**
* Get Layout Gravity based on tag <code>"android:layout_gravity"</code>
*
* @return value of tag
*/
public String getLayout_gravity() {
attributeValue = getValue("android:layout_gravity");
if (attributeValue == null || "".equals(attributeValue)) {
return null;
} else {
return attributeValue;
}
}
/**
* Get gravity based on tags <code>"android:gravity"</code> and <code>"android:textAlignment"</code>
*
* @return constant of position
*/
public int getGravity() {
attributeValue = getValue("android:gravity");
if(attributeValue==null)
attributeValue = getValue("android:textAlignment");
if (attributeValue != null) {
if (attributeValue.equals("left")) {
return FILL;
}
if (attributeValue.equals("center"))
return CENTER;
if (attributeValue.equals("right"))
return RIGHT;
}
return LEFT;
}
/**
* Get wp
*
* @return value of wp
*/
public float getWp() {
return wp;
}
/**
* Get hp
*
* @return value of hp
*/
public float getHp() {
return hp;
}
/**
* Get text based on tag <code>"android:text"</code>
*
* @return value of the tag
*/
public String getText() {
if(getValue("android:text")!=null)
return getValue("android:text");
return "";
}
/**
* Get text based on tag <code>"android:scaleY"</code>
*
* @return value of the tag
*/
public String getScaleY() {
attributeValue = getValue("android:scaleY");
if (attributeValue == null || "".equals(attributeValue)) {
return "1";
}
return attributeValue;
}
/**
* Get text based on tag <code>"android:scaleY"</code>
*
* @return value of the tag
*/
public String getScaleX() {
attributeValue = getValue("android:scaleX");
if (attributeValue == null || "".equals(attributeValue)) {
return "1";
}
return attributeValue;
}
/**
* Get source of a image based on tag <code>"android:src"</code>
*
* @return value of the tag
*/
public String getSrc() {
attributeValue = getValue("android:src");
if (attributeValue == null || "".equals(attributeValue)) {
return null;
} else {
if ('@' == attributeValue.charAt(0)) {
attributeValue = attributeValue.substring(1);
}
if (attributeValue.contains(".png") || attributeValue.contains(".jpg")) {
return attributeValue;
} else {
attributeValue = getImageExtension(attributeValue);
}
}
return attributeValue;
}
/**
* Get information of the tag <code>"android:hint"</code>
*
* @return value of the tag
*/
public String getHint() {
attributeValue = getValue("android:hint");
if (attributeValue == null || "".equals(attributeValue)) {
return null;
}
return attributeValue;
}
/**
* Clear the attributesMap HashMap of the XML component
*/
public void reset() {
attributesMap.clear();
}
/**
* Get information if it is absolute layout based on tags <code>"tools:layout_editor_absoluteX"</code> and
* <code>"tools:layout_editor_absoluteY"</code>
*
* @return true or false
*/
public boolean isAbsoluteLayout() {
if (getValue("tools:layout_editor_absoluteX") != null
|| getValue("tools:layout_editor_absoluteY") != null) {
return true;
}
return false;
}
/**
* Inserts a item in a attributesMap HashMap
*
* @param name name of tag
* @param value value of tag
*/
public void inserts(String name, String value) {
attributesMap.put(name, value);
}
/**
* Set the id of a tag
*
* @param id id of XML component
*/
public void setId(String id) {
this.id = id;
}
/**
* set parameter width to try to resize a predefined screen size
* @throws InvalidNumberException
*/
public void setWp() throws InvalidNumberException {
attributeValue = getValue("android:layout_width");
if (attributeValue != null) {
if (attributeValue.equals("match_parent") || attributeValue.equals("fill_parent")) {
wp = Settings.screenWidth;
} else {
if (attributeValue.contains("dp")) {
attributeValue = attributeValue.replace("dp", "");
}
wp = UnitsConverter.toPixels(Integer.parseInt(attributeValue) + DP);
}
}
if(landscape&&Settings.screenHeight>Settings.screenWidth)
wp = Settings.screenHeight / wp;
else