-
Notifications
You must be signed in to change notification settings - Fork 15
/
Copy pathColinTreeListView.java
1392 lines (1249 loc) · 49.6 KB
/
ColinTreeListView.java
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
package cn.colintree.aix.ColinTreeListView;
import java.io.IOException;
import java.lang.reflect.InvocationTargetException;
import java.util.ArrayList;
import java.util.HashMap;
import com.google.appinventor.components.annotations.DesignerComponent;
import com.google.appinventor.components.annotations.DesignerProperty;
import com.google.appinventor.components.annotations.PropertyCategory;
import com.google.appinventor.components.annotations.SimpleEvent;
import com.google.appinventor.components.annotations.SimpleFunction;
import com.google.appinventor.components.annotations.SimpleObject;
import com.google.appinventor.components.annotations.SimpleProperty;
import com.google.appinventor.components.annotations.UsesPermissions;
import com.google.appinventor.components.common.ComponentCategory;
import com.google.appinventor.components.common.ComponentConstants;
import com.google.appinventor.components.common.PropertyTypeConstants;
import com.google.appinventor.components.runtime.AndroidNonvisibleComponent;
import com.google.appinventor.components.runtime.AndroidViewComponent;
import com.google.appinventor.components.runtime.ButtonBase;
import com.google.appinventor.components.runtime.Component;
import com.google.appinventor.components.runtime.ComponentContainer;
import com.google.appinventor.components.runtime.EventDispatcher;
import com.google.appinventor.components.runtime.Form;
import com.google.appinventor.components.runtime.HVArrangement;
import com.google.appinventor.components.runtime.HorizontalArrangement;
import com.google.appinventor.components.runtime.Label;
import com.google.appinventor.components.runtime.VerticalArrangement;
import com.google.appinventor.components.runtime.VerticalScrollArrangement;
import com.google.appinventor.components.runtime.util.AsyncCallbackPair;
import com.google.appinventor.components.runtime.util.MediaUtil;
import com.google.appinventor.components.runtime.util.ViewUtil;
import com.google.appinventor.components.runtime.util.YailList;
import android.graphics.drawable.BitmapDrawable;
import android.os.Handler;
import android.util.Log;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.View.OnLongClickListener;
import android.view.View.OnTouchListener;
import android.widget.ScrollView;
import android.view.MotionEvent;
@DesignerComponent(version = ColinTreeListView.VERSION,
category = ComponentCategory.EXTENSION,
nonVisible = true,
iconName = "aiwebres/icon.png",
helpUrl = "http://aix.colintree.cn/en/extensions/ColinTreeListView.html")
@SimpleObject(external = true)
@UsesPermissions(permissionNames = "android.permission.INTERNET," +
"android.permission.ACCESS_NETWORK_STATE," +
"android.permission.READ_EXTERNAL_STORAGE")
public class ColinTreeListView extends AndroidNonvisibleComponent implements Component {
// VERSION 2:
// First version to be released
// VERSION 3:
// Adapted to new Appinventor (since 2017.12.27, Companion 2.45) (Fixed NoSuchMethodError)
// Added properties related to image loading - AsyncImageLoad & CacheImage (that in a same path)
// Added property - ScrollBottomAfterAdd
// VERSION 4:
// Adapted to all platforms (ai2.appinventor.mit.edu , thunkable , etc.)
// There should not more NoSuchMethodError at anywhere.
// VERSION 5:
// Added icon text related properties
// Added lastClickedElement & lastClickedIcon
// VERSION 6:
// Added properties of text height (both main- & sub-text)
// VERSION 7:
// Fixed that lastClickedElement starts from 0
// Fixed that images that cached by a same path would act wired when one of them is clicked
// Added a extra button
// VERSION 8:
// Fixed extraButtonEnabled not implemented
// Added support of direct(static) handlers in ColinTreeListViewElement
// VERSION 9:
// Fixed Error of Visiblility
// Added ClearCache() & ClearAllCache() -- still in test, it should works
// VERSION 10:
// Added Get by @10MINT
// Added LastLongClickedElement by @10MINT
// Fixes Label cannot click on some platforms
// VERSION 11:
// Added Translations (need platform supporting)
// Fixed a Get method bug (#11)
// Added ExtraButtonImage in ColinTreeListViewElement
// Removed flag deprecated from all blocks
public static final int VERSION = 11;
private static final String LOG_TAG = "ColinTreeListView";
private final ArrayList<Element> elementList = new ArrayList<Element>();
private HVArrangement vaContainer = null;
private int currentListSize = 0;
private final Handler handler = new Handler();
private int lastClickedElement = 0;
private int lastLongClickedElement = 0;
private int lastClickedIcon = 0;
private int lastClickedExtraButton = 0;
// Appearance
private int elementHeight = 57;
private int elementTouchDownColor = COLOR_DEFAULT;
private int elementWidthBeforeIcon = 7;
private int elementWidthAfterIcon = 5;
private int elementIconWidth = 40;
private int elementIconHeight = 40;
private int elementIconShape = BUTTON_SHAPE_ROUNDED;
private int elementIconBgColor = COLOR_DEFAULT;
private int elementIconTextColor = COLOR_DEFAULT;
private float elementIconTextFontSize = 24;
private boolean elementIconTextFontBold = true;
private boolean elementIconMultiParams = false;
private int elementIconPaddings = 0;
private int elementTextColor = COLOR_BLACK;
private float elementTextFontSize = 14f;
private boolean elementTextFontBold = false;
private int elementTextHeight = 18;
private int elementSubTextColor = COLOR_LTGRAY;
private float elementSubTextFontSize = 12;
private boolean elementSubTextFontBold = false;
private int elementSubTextHeight = 18;
private int elementWidthBeforeExtraButton = 2;
private String elementExtraButtonText = "";
private float elementExtraButtonTextFontSize = 12;
private boolean elementExtraButtonTextFontBold = false;
private int elementExtraButtonWidth = 20;
private int elementExtraButtonHeight = 20;
private int elementExtraButtonPaddings = 0;
private int elementExtraButtonBgColor = COLOR_LTGRAY;
private int elementExtraButtonShape = BUTTON_SHAPE_OVAL;
private String elementExtraButtonImage = "";
private int elementUnderlineColor = COLOR_LTGRAY;
private int elementUnderlineWidth = 1;
// Behaviour
private boolean scrollBottomAfterAdd = false;
private boolean asyncImageLoad = false;
private boolean cacheImage = false;
private boolean extraButtonEnabled = false;
private HashMap<String, CachedImage> iconMap = new HashMap<String, CachedImage>();
private final Form form;
private static final YailList makeYailList(Object... obj) {
return YailList.makeList(obj);
}
public ColinTreeListView(ComponentContainer container) {
super(container.$form());
form = container.$form();
Log.d(LOG_TAG, "ColinTreeListView Created");
}
@SimpleFunction
public void Initialize(VerticalArrangement verticalArrangement) {
vaContainer = verticalArrangement;
vaContainer.AlignHorizontal(ComponentConstants.GRAVITY_CENTER_HORIZONTAL);
}
@SimpleFunction
public void Initialize_Scroll(VerticalScrollArrangement verticalScrollArrangement) {
vaContainer = verticalScrollArrangement;
vaContainer.AlignHorizontal(ComponentConstants.GRAVITY_CENTER_HORIZONTAL);
}
@SimpleFunction
public void Clear() {
Set(YailList.makeEmptyList());
}
@SimpleFunction
public void Set(YailList list) {
int size = list.size();
Object sublistElement;
// Set the new list elements
for (int i = 0; i < size; i++) {
sublistElement = list.getObject(i);
if (sublistElement instanceof YailList) {
if (currentListSize > i) {
SetElement(i+1, (YailList)sublistElement);
// Calling the function that is shown in bky, so the index start from 1
} else {
AddElement((YailList)sublistElement);
}
} else {
if (currentListSize > i) {
SetElement(i+1, makeYailList(sublistElement));
// Calling the function that is shown in bky, so the index start from 1
} else {
AddElement(makeYailList(sublistElement));
}
}
}
// Hide the elements that is created but not uesd
for (int i = list.size(); i < currentListSize; i++) {
getElement(i + 1).hide();
}
currentListSize = list.size();
}
//added by @10MINT
//returns the list of the listview
@SimpleFunction
public YailList Get() {
ArrayList<YailList> stringRepresentation = new ArrayList<YailList>();
for (int i = 1; i <= this.currentListSize; i++) {
stringRepresentation.add(GetElement(i));
}
return YailList.makeList(stringRepresentation);
}
@SimpleFunction
public void AddElement(YailList element) {
int elementListSize = elementList.size();
if (currentListSize < elementListSize && elementListSize > 0) {
getElement(currentListSize + 1)
.show()
.set(element);
} else {
final int elementIndex = currentListSize;
elementList.add(new Element(vaContainer, element) {
@Override
public void onElementClick() {
ElementClick(elementIndex);
}
@Override
public boolean onElementLongClick() {
return ElementLongClick(elementIndex);
}
@Override
public void onElementTouchDown() {
ElementTouchDown(elementIndex);
}
@Override
public void onElementTouchUp() {
ElementTouchUp(elementIndex);
}
@Override
public void onIconClick() {
IconClick(elementIndex);
}
@Override
public boolean onIconLongClick() {
return IconLongClick(elementIndex);
}
@Override
public void onIconTouchDown() {
IconTouchDown(elementIndex);
}
@Override
public void onIconTouchUp() {
IconTouchUp(elementIndex);
}
@Override
public void onExtraButtonClick() {
ExtraButtonClick(elementIndex);
}
@Override
public boolean onExtraButtonLongClick() {
return ExtraButtonLongClick(elementIndex);
}
@Override
public void onExtraButtonTouchDown() {
ExtraButtonTouchDown(elementIndex);
}
@Override
public void onExtraButtonTouchUp() {
ExtraButtonTouchUp(elementIndex);
}
});
}
currentListSize++;
if (scrollBottomAfterAdd && (vaContainer.getView() instanceof ScrollView)) {
handler.postDelayed(new Runnable() {
@Override
public void run() {
((ScrollView)vaContainer.getView()).fullScroll(ScrollView.FOCUS_DOWN);
}
}, 20);
}
}
@SimpleFunction
public void AddEmptyElement() {
AddElement(YailList.makeEmptyList());
}
private void checkIndex(int elementIndex) throws IndexOutOfBoundsException {
if (elementIndex < 1 || elementIndex > currentListSize) {
throw new IndexOutOfBoundsException();
}
}
@SimpleFunction
public void SetElement(int elementIndex, YailList element) {
checkIndex(elementIndex);
getElement(elementIndex).show().set(element);
}
@SimpleFunction
public void SetElementText(int elementIndex, String text) {
checkIndex(elementIndex);
getElement(elementIndex).setText(text);
}
@SimpleFunction
public void SetElementMainText(int elementIndex, String mainText) {
checkIndex(elementIndex);
getElement(elementIndex).setMainText(mainText);
}
@SimpleFunction
public void SetElementSubText(int elementIndex, String subText) {
checkIndex(elementIndex);
getElement(elementIndex).setSubText(subText);
}
@SimpleFunction
public void SetElementIcon(int elementIndex, String path) {
checkIndex(elementIndex);
getElement(elementIndex).setIcon(path);
}
@SimpleFunction
public YailList GetElement(int elementIndex) {
return getElement(elementIndex).toYailList();
}
public Element getElement(int elementIndex) {
return elementList.get(elementIndex-1);
}
@SimpleFunction
public void RemoveElement(int elementIndex) {
checkIndex(elementIndex);
for (int i = elementIndex-1; i < currentListSize-1; i++) {
copyElement(i+1, i);
}
getElement(currentListSize).hide();
currentListSize--;
}
private void copyElement(int indexFrom, int indexTo) {
SetElement(
indexTo+1,
makeYailList(GetElement(indexFrom + 1).toArray())
// Trun into object[] first, avoiding object confusing. (means that make a new object)
);
}
@SimpleFunction
public void ClearAllCache() {
for (HashMap.Entry<String, CachedImage> entry : iconMap.entrySet()) {
entry.getValue().releaseMemory();
iconMap.remove(entry.getKey());
}
System.gc();
}
@SimpleFunction
public void ClearCache(String path) {
CachedImage ci = iconMap.get(path);
if (ci != null) {
ci.releaseMemory();
iconMap.remove(path);
}
System.gc();
}
@SimpleEvent
public void ElementClick(int elementIndex) {
lastClickedElement = elementIndex + 1;
EventDispatcher.dispatchEvent(this, "ElementClick", elementIndex + 1);
}
@SimpleEvent
public boolean ElementLongClick(int elementIndex) {
lastLongClickedElement = elementIndex + 1;
return EventDispatcher.dispatchEvent(this, "ElementLongClick", elementIndex + 1);
}
@SimpleEvent
public boolean ElementTouchDown(int elementIndex) {
return EventDispatcher.dispatchEvent(this, "ElementTouchDown", elementIndex + 1);
}
@SimpleEvent
public boolean ElementTouchUp(int elementIndex) {
return EventDispatcher.dispatchEvent(this, "ElementTouchUp", elementIndex + 1);
}
@SimpleEvent
public void IconClick(int elementIndex) {
lastClickedIcon = elementIndex + 1;
EventDispatcher.dispatchEvent(this, "IconClick", elementIndex + 1);
}
@SimpleEvent
public boolean IconLongClick(int elementIndex) {
return EventDispatcher.dispatchEvent(this, "IconLongClick", elementIndex + 1);
}
@SimpleEvent
public void IconTouchDown(int elementIndex) {
EventDispatcher.dispatchEvent(this, "IconTouchDown", elementIndex + 1);
}
@SimpleEvent
public void IconTouchUp(int elementIndex) {
EventDispatcher.dispatchEvent(this, "IconTouchUp", elementIndex + 1);
}
@SimpleEvent
public void ExtraButtonClick(int elementIndex) {
lastClickedExtraButton = elementIndex + 1;
EventDispatcher.dispatchEvent(this, "ExtraButtonClick", elementIndex + 1);
}
@SimpleEvent
public boolean ExtraButtonLongClick(int elementIndex) {
return EventDispatcher.dispatchEvent(this, "ExtraButtonLongClick", elementIndex + 1);
}
@SimpleEvent
public void ExtraButtonTouchDown(int elementIndex) {
EventDispatcher.dispatchEvent(this, "ExtraButtonTouchDown", elementIndex + 1);
}
@SimpleEvent
public void ExtraButtonTouchUp(int elementIndex) {
EventDispatcher.dispatchEvent(this, "ExtraButtonTouchUp", elementIndex + 1);
}
@SimpleProperty(category = PropertyCategory.BEHAVIOR)
public int LastClickedElement() {
return lastClickedElement;
}
@SimpleProperty(category = PropertyCategory.BEHAVIOR)
public int LastLongClickedElement() {
return lastLongClickedElement;
}
@SimpleProperty(category = PropertyCategory.BEHAVIOR)
public int LastClickedIcon() {
return lastClickedIcon;
}
@SimpleProperty(category = PropertyCategory.BEHAVIOR)
public int LastClickedExtraButton() {
return lastClickedExtraButton;
}
@SimpleProperty(category = PropertyCategory.APPEARANCE)
public int ElementHeight() {
return elementHeight;
}
@SimpleProperty
@DesignerProperty(editorType = PropertyTypeConstants.PROPERTY_TYPE_NON_NEGATIVE_INTEGER, defaultValue = "57")
public void ElementHeight(int height) {
elementHeight = height;
refreshElementProperties();
}
@SimpleProperty(category = PropertyCategory.APPEARANCE)
public int TouchDownColor() {
return elementTouchDownColor;
}
@SimpleProperty
@DesignerProperty(editorType = PropertyTypeConstants.PROPERTY_TYPE_COLOR,
defaultValue = DEFAULT_VALUE_COLOR_DEFAULT)
public void TouchDownColor(int argb) {
elementTouchDownColor = argb;
refreshElementProperties();
}
@SimpleProperty(category = PropertyCategory.APPEARANCE)
public int WidthBeforeIcon() {
return elementWidthBeforeIcon;
}
@SimpleProperty
@DesignerProperty(editorType = PropertyTypeConstants.PROPERTY_TYPE_NON_NEGATIVE_INTEGER, defaultValue = "7")
public void WidthBeforeIcon(int width) {
elementWidthBeforeIcon = width;
refreshElementProperties();
}
@SimpleProperty(category = PropertyCategory.APPEARANCE)
public int WidthAfterIcon() {
return elementWidthAfterIcon;
}
@SimpleProperty
@DesignerProperty(editorType = PropertyTypeConstants.PROPERTY_TYPE_NON_NEGATIVE_INTEGER, defaultValue = "5")
public void WidthAfterIcon(int width) {
elementWidthAfterIcon = width;
refreshElementProperties();
}
@SimpleProperty(category = PropertyCategory.APPEARANCE)
public int IconWidth() {
return elementIconWidth;
}
@SimpleProperty
@DesignerProperty(editorType = PropertyTypeConstants.PROPERTY_TYPE_NON_NEGATIVE_INTEGER, defaultValue = "40")
public void IconWidth(int width) {
elementIconWidth = width;
refreshElementProperties();
}
@SimpleProperty(category = PropertyCategory.APPEARANCE)
public int IconHeight() {
return elementIconHeight;
}
@SimpleProperty
@DesignerProperty(editorType = PropertyTypeConstants.PROPERTY_TYPE_NON_NEGATIVE_INTEGER, defaultValue = "40")
public void IconHeight(int height) {
elementIconHeight = height;
refreshElementProperties();
}
@SimpleProperty(category = PropertyCategory.APPEARANCE)
public int IconShape() {
return elementIconShape;
}
@SimpleProperty
@DesignerProperty(editorType = PropertyTypeConstants.PROPERTY_TYPE_BUTTON_SHAPE,
defaultValue = ""+BUTTON_SHAPE_ROUNDED)
public void IconShape(int shape) {
elementIconShape = shape;
refreshElementProperties();
}
@SimpleProperty(category = PropertyCategory.APPEARANCE)
public int IconBgColor() {
return elementIconBgColor;
}
@SimpleProperty
@DesignerProperty(editorType = PropertyTypeConstants.PROPERTY_TYPE_COLOR,
defaultValue = DEFAULT_VALUE_COLOR_DEFAULT)
public void IconBgColor(int argb) {
elementIconBgColor = argb;
refreshElementProperties();
}
@SimpleProperty(category = PropertyCategory.APPEARANCE)
public int IconTextColor() {
return elementIconTextColor;
}
@SimpleProperty
@DesignerProperty(editorType = PropertyTypeConstants.PROPERTY_TYPE_COLOR,
defaultValue = DEFAULT_VALUE_COLOR_DEFAULT)
public void IconTextColor(int argb) {
elementIconTextColor = argb;
refreshElementProperties();
}
@SimpleProperty(category = PropertyCategory.APPEARANCE)
public float IconTextFontSize() {
return elementIconTextFontSize;
}
@SimpleProperty
@DesignerProperty(editorType = PropertyTypeConstants.PROPERTY_TYPE_NON_NEGATIVE_FLOAT, defaultValue = "24")
public void IconTextFontSize(float size) {
elementIconTextFontSize = size;
refreshElementProperties();
}
@SimpleProperty(category = PropertyCategory.APPEARANCE)
public boolean IconTextFontBold() {
return elementIconTextFontBold;
}
@SimpleProperty
@DesignerProperty(editorType = PropertyTypeConstants.PROPERTY_TYPE_BOOLEAN, defaultValue = "True")
public void IconTextFontBold(boolean bold) {
elementIconTextFontBold = bold;
refreshElementProperties();
}
@SimpleProperty(category = PropertyCategory.APPEARANCE)
public boolean IconMultiParams() {
return elementIconMultiParams;
}
@SimpleProperty
@DesignerProperty(editorType = PropertyTypeConstants.PROPERTY_TYPE_BOOLEAN, defaultValue = "False")
public void IconMultiParams(boolean multiParams) {
elementIconMultiParams = multiParams;
refreshElementProperties();
}
@SimpleProperty(category = PropertyCategory.APPEARANCE)
public int IconPaddings() {
return elementIconPaddings;
}
@SimpleProperty
@DesignerProperty(editorType = PropertyTypeConstants.PROPERTY_TYPE_NON_NEGATIVE_INTEGER, defaultValue = "0")
public void IconPaddings(int paddings) {
elementIconPaddings = Math.round(paddings * form.deviceDensity());
refreshElementProperties();
}
@SimpleProperty(category = PropertyCategory.APPEARANCE)
public int TextColor() {
return elementTextColor;
}
@SimpleProperty
@DesignerProperty(editorType = PropertyTypeConstants.PROPERTY_TYPE_COLOR,
defaultValue = DEFAULT_VALUE_COLOR_BLACK)
public void TextColor(int argb) {
elementTextColor = argb;
refreshElementProperties();
}
@SimpleProperty(category = PropertyCategory.APPEARANCE)
public float TextFontSize() {
return elementTextFontSize;
}
@SimpleProperty
@DesignerProperty(editorType = PropertyTypeConstants.PROPERTY_TYPE_NON_NEGATIVE_FLOAT, defaultValue = "14")
public void TextFontSize(float size) {
elementTextFontSize = size;
refreshElementProperties();
}
@SimpleProperty(category = PropertyCategory.APPEARANCE)
public boolean TextFontBold() {
return elementTextFontBold;
}
@SimpleProperty
@DesignerProperty(editorType = PropertyTypeConstants.PROPERTY_TYPE_BOOLEAN, defaultValue = "False")
public void TextFontBold(boolean bold) {
elementTextFontBold = bold;
refreshElementProperties();
}
@SimpleProperty(category = PropertyCategory.APPEARANCE)
public float TextHeight() {
return elementTextHeight;
}
@SimpleProperty
@DesignerProperty(editorType = PropertyTypeConstants.PROPERTY_TYPE_NON_NEGATIVE_INTEGER, defaultValue = "18")
public void TextHeight(int height) {
elementTextHeight = height;
refreshElementProperties();
}
@SimpleProperty(category = PropertyCategory.APPEARANCE)
public int SubTextColor() {
return elementSubTextColor;
}
@SimpleProperty
@DesignerProperty(editorType = PropertyTypeConstants.PROPERTY_TYPE_COLOR,
defaultValue = DEFAULT_VALUE_COLOR_LTGRAY)
public void SubTextColor(int argb) {
elementSubTextColor = argb;
refreshElementProperties();
}
@SimpleProperty(category = PropertyCategory.APPEARANCE)
public float SubTextFontSize() {
return elementSubTextFontSize;
}
@SimpleProperty
@DesignerProperty(editorType = PropertyTypeConstants.PROPERTY_TYPE_NON_NEGATIVE_FLOAT, defaultValue = "12")
public void SubTextFontSize(float size) {
elementSubTextFontSize = size;
refreshElementProperties();
}
@SimpleProperty(category = PropertyCategory.APPEARANCE)
public boolean SubTextFontBold() {
return elementSubTextFontBold;
}
@SimpleProperty
@DesignerProperty(editorType = PropertyTypeConstants.PROPERTY_TYPE_BOOLEAN, defaultValue = "False")
public void SubTextFontBold(boolean bold) {
elementSubTextFontBold = bold;
refreshElementProperties();
}
@SimpleProperty(category = PropertyCategory.APPEARANCE)
public float SubTextHeight() {
return elementSubTextHeight;
}
@SimpleProperty
@DesignerProperty(editorType = PropertyTypeConstants.PROPERTY_TYPE_NON_NEGATIVE_INTEGER, defaultValue = "18")
public void SubTextHeight(int height) {
elementSubTextHeight = height;
refreshElementProperties();
}
@SimpleProperty(category = PropertyCategory.APPEARANCE)
public float WidthBeforeExtraButton() {
return elementWidthBeforeExtraButton;
}
@SimpleProperty
@DesignerProperty(editorType = PropertyTypeConstants.PROPERTY_TYPE_NON_NEGATIVE_INTEGER, defaultValue = "2")
public void WidthBeforeExtraButton(int width) {
elementWidthBeforeExtraButton = width;
refreshElementProperties();
}
@SimpleProperty(category = PropertyCategory.APPEARANCE)
public String ExtraButtonText() {
return elementExtraButtonText;
}
@SimpleProperty
@DesignerProperty(editorType = PropertyTypeConstants.PROPERTY_TYPE_TEXT, defaultValue = "")
public void ExtraButtonText(String text) {
elementExtraButtonText = text;
refreshElementProperties();
}
@SimpleProperty(category = PropertyCategory.APPEARANCE)
public float ExtraButtonTextFontSize() {
return elementExtraButtonTextFontSize;
}
@SimpleProperty
@DesignerProperty(editorType = PropertyTypeConstants.PROPERTY_TYPE_NON_NEGATIVE_FLOAT, defaultValue = "12")
public void ExtraButtonTextFontSize(float size) {
elementExtraButtonTextFontSize = size;
refreshElementProperties();
}
@SimpleProperty(category = PropertyCategory.APPEARANCE)
public boolean ExtraButtonTextFontBold() {
return elementExtraButtonTextFontBold;
}
@SimpleProperty
@DesignerProperty(editorType = PropertyTypeConstants.PROPERTY_TYPE_BOOLEAN, defaultValue = "False")
public void ExtraButtonTextFontBold(boolean bold) {
elementExtraButtonTextFontBold = bold;
refreshElementProperties();
}
@SimpleProperty(category = PropertyCategory.APPEARANCE)
public float ExtraButtonWidth() {
return elementExtraButtonWidth;
}
@SimpleProperty
@DesignerProperty(editorType = PropertyTypeConstants.PROPERTY_TYPE_NON_NEGATIVE_INTEGER, defaultValue = "20")
public void ExtraButtonWidth(int width) {
elementExtraButtonWidth = width;
refreshElementProperties();
}
@SimpleProperty(category = PropertyCategory.APPEARANCE)
public float ExtraButtonHeight() {
return elementExtraButtonHeight;
}
@SimpleProperty
@DesignerProperty(editorType = PropertyTypeConstants.PROPERTY_TYPE_NON_NEGATIVE_INTEGER, defaultValue = "20")
public void ExtraButtonHeight(int height) {
elementExtraButtonHeight = height;
refreshElementProperties();
}
@SimpleProperty(category = PropertyCategory.APPEARANCE)
public float ExtraButtonPaddings() {
return elementExtraButtonPaddings;
}
@SimpleProperty
@DesignerProperty(editorType = PropertyTypeConstants.PROPERTY_TYPE_NON_NEGATIVE_INTEGER, defaultValue = "0")
public void ExtraButtonPaddings(int paddings) {
elementExtraButtonPaddings = paddings;
refreshElementProperties();
}
@SimpleProperty(category = PropertyCategory.APPEARANCE)
public int ExtraButtonBgColor() {
return elementExtraButtonBgColor;
}
@SimpleProperty
@DesignerProperty(editorType = PropertyTypeConstants.PROPERTY_TYPE_COLOR,
defaultValue = DEFAULT_VALUE_COLOR_LTGRAY)
public void ExtraButtonBgColor(int argb) {
elementExtraButtonBgColor = argb;
refreshElementProperties();
}
@SimpleProperty(category = PropertyCategory.APPEARANCE)
public int ExtraButtonShape() {
return elementExtraButtonShape;
}
@SimpleProperty
@DesignerProperty(editorType = PropertyTypeConstants.PROPERTY_TYPE_BUTTON_SHAPE,
defaultValue = ""+BUTTON_SHAPE_OVAL)
public void ExtraButtonShape(int shape) {
elementExtraButtonShape = shape;
refreshElementProperties();
}
@SimpleProperty(category = PropertyCategory.APPEARANCE)
public String ExtraButtonImage() {
return elementExtraButtonImage;
}
@SimpleProperty
@DesignerProperty(editorType = PropertyTypeConstants.PROPERTY_TYPE_ASSET, defaultValue = "")
public void ExtraButtonImage(String path) {
elementExtraButtonImage = path;
refreshElementProperties();
}
@SimpleProperty(category = PropertyCategory.APPEARANCE)
public int UnderlineColor() {
return elementUnderlineColor;
}
@SimpleProperty
@DesignerProperty(editorType = PropertyTypeConstants.PROPERTY_TYPE_COLOR,
defaultValue = DEFAULT_VALUE_COLOR_LTGRAY)
public void UnderlineColor(int argb) {
elementUnderlineColor = argb;
refreshElementProperties();
}
@SimpleProperty(category = PropertyCategory.APPEARANCE)
public int UnderlineWidth() {
return elementUnderlineWidth;
}
@SimpleProperty
@DesignerProperty(editorType = PropertyTypeConstants.PROPERTY_TYPE_NON_NEGATIVE_INTEGER, defaultValue = "1")
public void UnderlineWidth(int lineWidth) {
elementUnderlineWidth = lineWidth;
refreshElementProperties();
}
private void refreshElementProperties() {
for (int i = 0; i < currentListSize; i++) {
getElement(i + 1).refreshProperties();
}
}
@SimpleProperty(category = PropertyCategory.BEHAVIOR)
public boolean ScrollBottomAfterAdd() {
return scrollBottomAfterAdd;
}
@SimpleProperty
@DesignerProperty(editorType = PropertyTypeConstants.PROPERTY_TYPE_BOOLEAN, defaultValue = "False")
public void ScrollBottomAfterAdd(boolean scroll) {
scrollBottomAfterAdd = scroll;
}
@SimpleProperty(category = PropertyCategory.BEHAVIOR)
public boolean AsyncImageLoad() {
return asyncImageLoad;
}
@SimpleProperty
@DesignerProperty(editorType = PropertyTypeConstants.PROPERTY_TYPE_BOOLEAN, defaultValue = "False")
public void AsyncImageLoad(boolean async) {
asyncImageLoad = async;
}
@SimpleProperty(category = PropertyCategory.BEHAVIOR)
public boolean CacheImage() {
return cacheImage;
}
@SimpleProperty
@DesignerProperty(editorType = PropertyTypeConstants.PROPERTY_TYPE_BOOLEAN, defaultValue = "False")
public void CacheImage(boolean cache) {
cacheImage = cache;
}
@SimpleProperty(category = PropertyCategory.BEHAVIOR)
public boolean ExtraButtonEnabled() {
return extraButtonEnabled;
}
@SimpleProperty
@DesignerProperty(editorType = PropertyTypeConstants.PROPERTY_TYPE_BOOLEAN, defaultValue = "False")
public void ExtraButtonEnabled(boolean enable) {
extraButtonEnabled = enable;
}
abstract class Element implements OnClickListener, OnLongClickListener, OnTouchListener {
private ComponentContainer container;
public static final String NOTICE = "Welcome to improve this extension with plugins :P";
public final HorizontalArrangement ha;
public final Label labelBeforeIcon;
public final ButtonBase icon;
public final Label labelAfterIcon;
public final Label size2Label;
public final VerticalArrangement size3Va;
public final Label size3MainText;
public final Label size3SubText;
public final Label labelBeforeExtraButton;
public final ButtonBase extraButton;
public final Label labelAfterText;
public final Label underline;
private String iconValue = "";
private String extraImagePath = "";
private int currentSize;
private boolean refreshLock = false;
public Element(ComponentContainer container, YailList list) {
this.container = container;
ha = new HorizontalArrangement(container);
ha.getView().setOnClickListener(this);
ha.getView().setOnLongClickListener(this);
ha.getView().setOnTouchListener(this);
ha.AlignVertical(ComponentConstants.GRAVITY_CENTER_VERTICAL);
ha.Width(LENGTH_FILL_PARENT);
labelBeforeIcon = new Label(ha);
labelBeforeIcon.Text("");
labelBeforeIcon.getView().setOnClickListener(this);
labelBeforeIcon.getView().setOnLongClickListener(this);
labelBeforeIcon.getView().setOnTouchListener(this);
icon = new ButtonBase(ha) {
@Override
public void click() {
onIconClick();
}
@Override
public boolean longClick() {
return onIconLongClick();
}
@Override
public void TouchDown() {
onIconTouchDown();
}
@Override
public void TouchUp() {
onIconTouchUp();
}
};
labelAfterIcon = new Label(ha);
labelAfterIcon.Text("");
labelAfterIcon.getView().setOnClickListener(this);
labelAfterIcon.getView().setOnLongClickListener(this);
labelAfterIcon.getView().setOnTouchListener(this);
size2Label = new Label(ha);
size2Label.Width(LENGTH_FILL_PARENT);
size2Label.Text("Element Text");
size2Label.TextAlignment(ALIGNMENT_NORMAL);
size2Label.BackgroundColor(COLOR_NONE);
size2Label.getView().setOnClickListener(this);
size2Label.getView().setOnLongClickListener(this);
size2Label.getView().setOnTouchListener(this);
size3Va = new VerticalArrangement(ha);
size3Va.AlignVertical(ComponentConstants.GRAVITY_CENTER_VERTICAL);
size3Va.AlignHorizontal(ComponentConstants.GRAVITY_LEFT);
size3Va.Width(LENGTH_FILL_PARENT);
size3MainText = new Label(size3Va);
size3MainText.Text("Element Main Text");
size3MainText.TextAlignment(ALIGNMENT_NORMAL);
size3MainText.getView().setOnClickListener(this);
size3MainText.getView().setOnLongClickListener(this);
size3MainText.getView().setOnTouchListener(this);
size3SubText = new Label(size3Va);
size3SubText.Text("Element Sub Text");
size3SubText.TextAlignment(ALIGNMENT_NORMAL);
size3SubText.getView().setOnClickListener(this);
size3SubText.getView().setOnLongClickListener(this);
size3SubText.getView().setOnTouchListener(this);
labelBeforeExtraButton = new Label(ha);
labelBeforeExtraButton.Text("");
labelBeforeExtraButton.Width(2);
labelBeforeExtraButton.getView().setOnClickListener(this);
labelBeforeExtraButton.getView().setOnLongClickListener(this);
labelBeforeExtraButton.getView().setOnTouchListener(this);
extraButton = new ButtonBase(ha) {
@Override
public void click() {
onExtraButtonClick();
}
@Override
public boolean longClick() {
return onExtraButtonLongClick();
}
@Override
public void TouchDown() {
onExtraButtonTouchDown();
}
@Override
public void TouchUp() {
onExtraButtonTouchUp();
}
};
labelAfterText = new Label(ha);
labelAfterText.Text("");
labelAfterText.Width(10);
labelAfterText.getView().setOnClickListener(this);
labelAfterText.getView().setOnLongClickListener(this);
labelAfterText.getView().setOnTouchListener(this);
underline = new Label(container);
underline.Width(LENGTH_FILL_PARENT);