/
PViewsArea.java
975 lines (878 loc) · 26.9 KB
/
PViewsArea.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
/*
* Part of Phonk http://www.phonk.io
* A prototyping platform for Android devices
*
* Copyright (C) 2013 - 2017 Victor Diaz Barrales @victordiaz (Protocoder)
* Copyright (C) 2017 - Victor Diaz Barrales @victordiaz (Phonk)
*
* Phonk is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Phonk is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with Phonk. If not, see <http://www.gnu.org/licenses/>.
*
*/
package io.phonk.runner.apprunner.api;
import android.content.Context;
import android.graphics.Color;
import android.text.InputType;
import android.view.Gravity;
import android.view.View;
import android.view.ViewGroup;
import android.widget.FrameLayout;
import android.widget.RelativeLayout;
import androidx.fragment.app.FragmentTransaction;
import java.util.ArrayList;
import io.phonk.runner.apidoc.annotation.PhonkClass;
import io.phonk.runner.apidoc.annotation.PhonkField;
import io.phonk.runner.apidoc.annotation.PhonkMethod;
import io.phonk.runner.apidoc.annotation.PhonkMethodParam;
import io.phonk.runner.apidoc.annotation.PhonkObject;
import io.phonk.runner.apprunner.AppRunner;
import io.phonk.runner.apprunner.api.media.PCamera;
import io.phonk.runner.apprunner.api.other.PProcessing;
import io.phonk.runner.apprunner.api.widgets.PAbsoluteLayout;
import io.phonk.runner.apprunner.api.widgets.PButton;
import io.phonk.runner.apprunner.api.widgets.PCustomView;
import io.phonk.runner.apprunner.api.widgets.PImage;
import io.phonk.runner.apprunner.api.widgets.PImageButton;
import io.phonk.runner.apprunner.api.widgets.PInput;
import io.phonk.runner.apprunner.api.widgets.PKnob;
import io.phonk.runner.apprunner.api.widgets.PLinearLayout;
import io.phonk.runner.apprunner.api.widgets.PList;
import io.phonk.runner.apprunner.api.widgets.PMap;
import io.phonk.runner.apprunner.api.widgets.PMatrix;
import io.phonk.runner.apprunner.api.widgets.PNumberPicker;
import io.phonk.runner.apprunner.api.widgets.PPlot;
import io.phonk.runner.apprunner.api.widgets.PLoader;
import io.phonk.runner.apprunner.api.widgets.PRadioButtonGroup;
import io.phonk.runner.apprunner.api.widgets.PScrollView;
import io.phonk.runner.apprunner.api.widgets.PSlider;
import io.phonk.runner.apprunner.api.widgets.PSpinner;
import io.phonk.runner.apprunner.api.widgets.PText;
import io.phonk.runner.apprunner.api.widgets.PTextList;
import io.phonk.runner.apprunner.api.widgets.PToggle;
import io.phonk.runner.apprunner.api.widgets.PToolbar;
import io.phonk.runner.apprunner.api.widgets.PTouchPad;
import io.phonk.runner.apprunner.api.widgets.PViewPager;
import io.phonk.runner.apprunner.api.widgets.PWebView;
import io.phonk.runner.base.gui.CameraTexture;
import io.phonk.runner.base.utils.MLog;
@PhonkClass
public class PViewsArea extends ProtoBase {
protected final AppRunner mAppRunner;
protected Context mContext;
// contains a reference of all views added to the absolute layout
private ArrayList<View> viewArray = new ArrayList<>();
// UI
private boolean isScrollEnabled = false;
protected PAbsoluteLayout uiAbsoluteLayout;
private RelativeLayout uiHolderLayout;
private PScrollView uiScrollView;
public PViewsArea(AppRunner appRunner) {
super(appRunner);
mAppRunner = appRunner;
mContext = appRunner.getAppContext();
}
public View initMainLayout() {
ViewGroup.LayoutParams layoutParams = new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT);
// this is the structure of the layout
// uiHolderLayout (background color)
// [scrollview] (isScrollEnabled)
// [uiAbsoluteLayout]
// set the holder
uiHolderLayout = new RelativeLayout(getContext());
uiHolderLayout.setLayoutParams(layoutParams);
// We need to let the view scroll, so we're creating a scrollview
uiScrollView = new PScrollView(getContext(), false);
uiScrollView.setLayoutParams(layoutParams);
// uiScrollView.setFillViewport(true);
allowScroll(isScrollEnabled);
// Create the main layout. This is where all the items actually go
uiAbsoluteLayout = new PAbsoluteLayout(getAppRunner());
uiAbsoluteLayout.setLayoutParams(layoutParams);
uiScrollView.addView(uiAbsoluteLayout);
uiHolderLayout.addView(uiScrollView);
return uiHolderLayout;
}
public PAbsoluteLayout newAbsoluteLayout() {
ViewGroup.LayoutParams layoutParams = new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT);
PAbsoluteLayout pAbsoluteLayout = new PAbsoluteLayout(getAppRunner());
pAbsoluteLayout.setLayoutParams(layoutParams);
return pAbsoluteLayout;
}
/**
* Changes the position cornerMode.
* By default, Phonk places the widgets using normalized coordinates (0 to 1)
* Sometimes we need a bit more control on how to create layouts so we can specify that the
* views will lay out using pixel or dp (density independent pixels) units
*
* @param type pixels/dp/normalized
* @exampleLink /examples/User Interface/Absolute Positioning
* @advanced
* @status OK
*/
@PhonkMethod
public void positionMode(String type) {
uiAbsoluteLayout.mode(type);
}
/**
* Adds a view created with new (newButton, newSlider, newText, etc) to the layout
*
* @param v view
* @param x
* @param y
* @param w
* @param h
* @status TODO_EXAMPLE
* @advanced
*/
@PhonkMethod
protected View addViewAbsolute(View v, Object x, Object y, Object w, Object h) {
v.setAlpha(0);
viewArray.add(v);
uiAbsoluteLayout.addView(v, x, y, w, h);
v.animate().alpha(1).setDuration(300).setStartDelay(100 * (1 + viewArray.size())).start();
return v;
}
/**
* Remove all views in the layout
*
* @advanced
* @status TODO_EXAMPLE
*/
@PhonkMethod
public void removeAllViews() {
uiAbsoluteLayout.removeAllViews();
viewArray.clear();
}
@PhonkMethod
public void removeView(View v) {
uiAbsoluteLayout.removeView(v);
}
/**
* Allows the main interface to scroll up and down.
* It's quite handy to lay out many widgets that cannot fit in a screen.
*
* @param scroll
* @staus TODO_EXAMPLE
*/
@PhonkMethod
public void allowScroll(boolean scroll) {
uiScrollView.setScrollingEnabled(scroll);
isScrollEnabled = scroll;
}
/**
* blablba
*
* @status TODO
*/
@PhonkField
public PToolbar toolbar;
/**
* Changes the background color using grayscale
*
* @param gray
* @status TODO_EXAMPLE
*/
@PhonkMethod
public void background(int gray) {
uiHolderLayout.setBackgroundColor(Color.rgb(gray, gray, gray));
}
/**
* Changes the background color using RGB
*
* @param red
* @param green
* @param blue
* @status TODO_EXAMPLE
*/
@PhonkMethod
public void background(int red, int green, int blue) {
uiHolderLayout.setBackgroundColor(Color.rgb(red, green, blue));
}
/**
* Changes the background color using RGB
*
* @param red
* @param green
* @param blue
* @param alpha
* @status TODO_EXAMPLE
*/
@PhonkMethod
public void background(int red, int green, int blue, int alpha) {
uiHolderLayout.setBackgroundColor(Color.argb(alpha, red, green, blue));
}
/**
* Changes the background color using Hexadecimal color
*
* @param c
* @status TODO_EXAMPLE
*/
@PhonkMethod
public void background(String c) {
uiHolderLayout.setBackgroundColor(Color.parseColor(c));
}
/**
* Adds a button to the main screen
*
* @param label Text that appears in the button
* @param x Horizontal position
* @param y Vertical position
* @param w Width
* @param h Height
* @return
* @exampleLink /examples/User Interface/Basic Views
* @status OK
*/
@PhonkMethod
public PButton addButton(String label, Object x, Object y, Object w, Object h) {
PButton b = (PButton) newView("button");
b.text(label);
addViewAbsolute(b, x, y, w, h);
return b;
}
@PhonkMethod
public PButton addButton(String label, Object x, Object y) {
PButton b = (PButton) newView("button");
b.text(label);
addViewAbsolute(b, x, y, -1, -1);
return b;
}
private float toFloat(Object o) {
return ((Number) o).floatValue();
}
/**
* Adds a button to the main screen
*
* @param style
* @return
* @status TODO
public PButton addButtonWithProperties(Map style) {
PButton b = newButton("hi");
b.setStyle(style);
addViewAbsolute(b, toFloat(style.get("x")), toFloat(style.get("y")), toFloat(style.get("width")), toFloat(style.get("height")));
return b;
}
*/
/**
* Adds an imageButton
*
* @param imagePath
* @param x
* @param y
* @param w
* @param h
* @return
* @exampleLink /examples/User Interface/Basic Views
* @status OK
*/
@PhonkMethod
public PImageButton addImageButton(String imagePath, Object x, Object y, Object w, Object h) {
PImageButton pImageButton = (PImageButton) newView("imageButton");
pImageButton.load(imagePath);
addViewAbsolute(pImageButton, x, y, w, h);
return pImageButton;
}
/**
* @param imagePath
* @param x
* @param y
* @return
* @exampleLink /examples/User Interface/Basic Views
* @status OK
*/
@PhonkMethod
public PImageButton addImageButton(String imagePath, Object x, Object y) {
PImageButton pImageButton = (PImageButton) newView("imageButton");
pImageButton.load(imagePath);
addViewAbsolute(pImageButton, x, y, -1, -1);
return pImageButton;
}
/**
* Adds a text box.
* If only x and y are provided, the bounding box will be as large as the text.
* If x, y, w, h are provided, the text will accommodate to the bounding box defined.
*
* @param x
* @param y
* @return
* @exampleLink /examples/User Interface/Basic Views
* @status OK
*/
@PhonkMethod(description = "", example = "")
@PhonkMethodParam(params = {"label", "x", "y"})
public PText addText(Object x, Object y) {
PText tv = (PText) newView("text");
addViewAbsolute(tv, x, y, -1, -1);
return tv;
}
@PhonkMethod
public PText addText(Object x, Object y, Object w, Object h) {
PText tv = (PText) newView("text");
addViewAbsolute(tv, x, y, w, h);
return tv;
}
@PhonkMethod
public PText addText(String text, Object x, Object y) {
PText tv = (PText) newView("text");
tv.setText(text);
addViewAbsolute(tv, x, y, -1, -1);
return tv;
}
@PhonkMethod
public PText addText(String label, Object x, Object y, Object w, Object h) {
PText tv = (PText) newView("text");
tv.setText(label);
addViewAbsolute(tv, x, y, w, h);
return tv;
}
/**
* Adds a text input
*
* @param x
* @param y
* @param w
* @param h
* @return
* @exampleLink /examples/User Interface/Basic Views
* @status OK
*/
@PhonkMethod
public PInput addInput(Object x, Object y, Object w, Object h) {
PInput et = (PInput) newView("input");
addViewAbsolute(et, x, y, w, h);
return et;
}
/**
* Add a text area (which is the same as an input but multiline
*/
@PhonkMethod
public PInput addTextArea(Object x, Object y, Object w, Object h) {
PInput et = (PInput) newView("textArea");
addViewAbsolute(et, x, y, w, h);
return et;
}
/**
* Adds a toggle
*
* @param text
* @param x
* @param y
* @param w
* @param h
* @return
* @exampleLink /examples/User Interface/Basic Views
* @status OK
*/
@PhonkMethod
public PToggle addToggle(final String[] text, Object x, Object y, Object w, Object h) {
PToggle t = (PToggle) newView("toggle");
if (text.length > 0) {
t.text(text[0]);
t.setTextOff(text[0]);
}
if (text.length > 1) {
// tb.text(label[0]);
t.setTextOn(text[1]);
}
addViewAbsolute(t, x, y, w, h);
return t;
}
@PhonkMethod
public PToggle addToggle(Object x, Object y, Object w, Object h) {
PToggle t = (PToggle) newView("toggle");
addViewAbsolute(t, x, y, w, h);
return t;
}
@PhonkMethod
public PToggle addToggle(String text, Object x, Object y, Object w, Object h) {
PToggle t = (PToggle) newView("toggle");
t.text(text);
t.setTextOn(text);
t.setTextOff(text);
addViewAbsolute(t, x, y, w, h);
return t;
}
/**
* Creates a pager that contain slidable views
*
* @return
* @status TODO
* @advanced
*/
@PhonkMethod(description = "Creates a new pager", example = "")
public PViewPager addPager(Object x, Object y, Object w, Object h) {
PViewPager pViewPager = (PViewPager) newView("pager");
addViewAbsolute(pViewPager, x, y, w, h);
return pViewPager;
}
public View getView() {
return uiHolderLayout;
}
/**
* Adds a slider. By default the range is [0, 1].
*
* @param x
* @param y
* @param w
* @param h
* @return
* @status TOREVIEW
*/
@PhonkMethod
public PSlider addSlider(Object x, Object y, Object w, Object h) {
PSlider slider = (PSlider) newView("slider");
addViewAbsolute(slider, x, y, w, h);
return slider;
}
/**
* Adds a knob
*
* @param x
* @param y
* @param w
* @param h
* @return
* @status TOREVIEW
*/
@PhonkMethod
public PKnob addKnob(Object x, Object y, Object w, Object h) {
PKnob slider = (PKnob) newView("knob");
addViewAbsolute(slider, x, y, w, h);
return slider;
}
/**
* Adds a matrix with M and N size. Useful when creating step sequencers and similar.
*
* @param x
* @param y
* @param w
* @param h
* @param m
* @param n
* @return
* @status TOREVIEW
*/
@PhonkMethod
public PMatrix addMatrix(Object x, Object y, Object w, Object h, int m, int n) {
PMatrix matrix = (PMatrix) newView("matrix");
matrix.size(m, n);
addViewAbsolute(matrix, x, y, w, h);
return matrix;
}
/**
* Add a loader
*
* @param x
* @param y
* @param w
* @param h
* @return
* @status TOREVIEW
*/
@PhonkMethod
public PLoader addLoader(Object x, Object y, Object w, Object h) {
PLoader pb = (PLoader) newView("loader");
addViewAbsolute(pb, x, y, w, -1);
return pb;
}
/**
* Adds a radio button group
*
* @param x
* @param y
* @return
* @status TOREVIEW
*/
@PhonkMethod
public PRadioButtonGroup addRadioButtonGroup(Object x, Object y) {
PRadioButtonGroup rbg = (PRadioButtonGroup) newView("radioButtonGroup");
addViewAbsolute(rbg, x, y, -1, -1);
return rbg;
}
@PhonkMethod
public PRadioButtonGroup addRadioButtonGroup(Object x, Object y, Object w, Object h) {
PRadioButtonGroup rbg = (PRadioButtonGroup) newView("radioButtonGroup");
addViewAbsolute(rbg, x, y, w, h);
return rbg;
}
/**
* Adds an image
*
* @param x
* @param y
* @return
* @status TOREVIEW
*/
@PhonkMethod
public PImage addImage(Object x, Object y) {
final PImage iv = (PImage) newView("image");
addViewAbsolute(iv, x, y, -1, -1);
return iv;
}
@PhonkMethod
public PImage addImage(Object x, Object y, Object w, Object h) {
PImage iv = (PImage) newView("image");
addViewAbsolute(iv, x, y, w, h);
return iv;
}
@PhonkMethod
public PImage addImage(String imagePath, Object x, Object y) {
PImage iv = (PImage) newView("image");
iv.load(imagePath);
addViewAbsolute(iv, x, y, -1, -1);
return iv;
}
@PhonkMethod
public PImage addImage(String imagePath, Object x, Object y, Object w, Object h) {
PImage iv = (PImage) newView("image");
iv.load(imagePath);
addViewAbsolute(iv, x, y, w, h);
return iv;
}
/**
* Add a choice box
*
* @param array
* @param x
* @param y
* @param w
* @param h
* @return
* @status TOREVIEW
*/
@PhonkMethod
public PSpinner addChoiceBox(final String[] array, Object x, Object y, Object w, Object h) {
PSpinner pSpinner = (PSpinner) newView("choiceBox");
pSpinner.setData(array);
// pSpinner.setPrompt("qq");
addViewAbsolute(pSpinner, x, y, w, h);
return pSpinner;
}
/**
* Adds a numberpicker
*
* @param x
* @param y
* @param w
* @param h
* @return
* @status TOREVIEW
*/
@PhonkMethod
public PNumberPicker addNumberPicker(Object x, Object y, Object w, Object h) {
PNumberPicker pNumberPicker = (PNumberPicker) newView("numberPicker");
addViewAbsolute(pNumberPicker, x, y, w, h);
return pNumberPicker;
}
/**
* Creates a new camera view
*
* @param type "front" or "back"
* @return
* @advanced
*/
@PhonkMethod
public Object newCameraView(String type) {
int camNum = -1;
switch (type) {
case "front":
camNum = CameraTexture.MODE_CAMERA_FRONT;
break;
case "back":
camNum = CameraTexture.MODE_CAMERA_BACK;
break;
}
return new PCamera(getAppRunner(), camNum);
}
/**
* Add camera view
*
* @param type "front" or "back
* @param x
* @param y
* @param w
* @param h
* @return
* @status TOREVIEW
*/
@PhonkMethod
public Object addCameraView(String type, Object x, Object y, Object w, Object h) {
Object pCamera = newCameraView(type);
addViewAbsolute((View) pCamera, x, y, w, h);
return pCamera;
}
/*
public Object addCam(Object x, Object y, Object w, Object h) {
PCameraXOne cameraX = new PCameraXOne(getAppRunner());
// cameraX.start();
// addViewAbsolute((View) cameraX, x, y, w, h);
// return cameraX;
FrameLayout fl = new FrameLayout(getContext());
fl.setLayoutParams(new FrameLayout.LayoutParams(FrameLayout.LayoutParams.MATCH_PARENT, FrameLayout.LayoutParams.MATCH_PARENT));
fl.setId(200 + (int) (200 * Math.random()));
// Add the view
addViewAbsolute(fl, x, y, w, h);
// PCameraX p = new PCameraX();
FragmentTransaction ft = getActivity().getSupportFragmentManager().beginTransaction();
ft.add(fl.getId(), cameraX, String.valueOf(fl.getId()));
ft.commit();
// return p;
return null;
}
*/
/**
* Adds a webview
*
* @param x
* @param y
* @param w
* @param h
* @return
* @status TOREVIEW
*/
@PhonkMethod
public PWebView addWebView(Object x, Object y, Object w, Object h) {
PWebView webView = (PWebView) newView("webView");
addViewAbsolute(webView, x, y, w, h);
return webView;
}
/**
* Adds a plot, by default the range is [0, 1]
*
* @param x
* @param y
* @param w
* @param h
* @return
* @status TOREVIEW
*/
@PhonkMethod
public PPlot addPlot(Object x, Object y, Object w, Object h) {
PPlot pPlot = (PPlot) newView("plot");
addViewAbsolute(pPlot, x, y, w, h);
return pPlot;
}
/**
* Creates a new touch pad
*
* @param x
* @param y
* @param w
* @param h
* @return
* @status TOREVIEW
*/
@PhonkMethod
public PTouchPad addTouchPad(Object x, Object y, Object w, Object h) {
PTouchPad taV = (PTouchPad) newView("touchPad");
addViewAbsolute(taV, x, y, w, h);
return taV;
}
/**
* Adds a canvas view
*
* @param x
* @param y
* @param w
* @param h
* @return
* @status TOREVIEW
*/
@PhonkMethod
public PCustomView addCanvas(Object x, Object y, Object w, Object h) {
final PCustomView canvasView = (PCustomView) newView("canvas"); // (int) w, (int) h);
addViewAbsolute(canvasView, x, y, w, h);
return canvasView;
}
/**
* Adds a map widget using OpenStreetMap
*
* @param x
* @param y
* @param w
* @param h
* @return
* @status TOREVIEW
*/
@PhonkMethod(description = "", example = "")
@PhonkMethodParam(params = {"x", "y", "w", "h"})
public PMap addMap(Object x, Object y, Object w, Object h) {
PMap mapView = (PMap) newView("map");
addViewAbsolute(mapView, x, y, w, h);
return mapView;
}
/**
* @param x
* @param y
* @param w
* @param h
* @return
* @status TOREVIEW
*/
@PhonkMethod
public PList addGrid(Object x, Object y, Object w, Object h, int numCols) {
PList list = (PList) newView("list");
list.numColumns(numCols);
addViewAbsolute(list, x, y, w, h);
return list;
}
/**
* Adds a list of views
*
* @param x
* @param y
* @param w
* @param h
* @return
* @status TOREVIEW
*/
@PhonkMethod
public PList addList(Object x, Object y, Object w, Object h) {
PList list = (PList) newView("list");
list.numColumns(1);
addViewAbsolute(list, x, y, w, h);
return list;
}
public PTextList addTextList(Object x, Object y, Object w, Object h) {
PTextList pTextList = new PTextList(mAppRunner);
addViewAbsolute(pTextList, x, y, w, h);
return pTextList;
}
/**
* Adds a processing view.
* This Processing view acts quite similar to Processing.org for Android.
* In fact it is the same, although some things work a bit differently to play well with the rest of the framework.
* <p>
* - All the Processing functions prepend the Processing (p) object.
* p.fill(255); p.stroke(); p.rect();
*
* @param x
* @param y
* @param w
* @param h
* @return
* @exampleLink /examples/Others/Processing
*/
@PhonkMethod(description = "", example = "")
@PhonkMethodParam(params = {"x", "y", "w", "h"})
public PProcessing addProcessingCanvas(Object x, Object y, Object w, Object h) {
// Create the main layout. This is where all the items actually go
FrameLayout fl = new FrameLayout(getContext());
fl.setLayoutParams(new FrameLayout.LayoutParams(FrameLayout.LayoutParams.MATCH_PARENT, FrameLayout.LayoutParams.MATCH_PARENT));
fl.setId(200 + (int) (200 * Math.random()));
// Add the view
addViewAbsolute(fl, x, y, w, h);
PProcessing p = new PProcessing(getAppRunner());
// TOFIX
FragmentTransaction ft = getActivity().getSupportFragmentManager().beginTransaction();
// ft.add(fl.getId(), p, fl.getId());
ft.add(fl.getId(), p, String.valueOf(fl.getId()));
ft.commit();
return p;
}
/**
* Adds a linear layout
*
* @param x
* @param y
* @param w
* @param h
* @return
*/
@PhonkMethod
public PLinearLayout addLinearLayout(Object x, Object y) {
PLinearLayout pLinearLayout = (PLinearLayout) newView("linearLayout");
addViewAbsolute(pLinearLayout, x, y, -1, -1);
return pLinearLayout;
}
@PhonkMethod
public PLinearLayout addLinearLayout(Object x, Object y, Object w, Object h) {
PLinearLayout pLinearLayout = (PLinearLayout) newView("linearLayout");
addViewAbsolute(pLinearLayout, x, y, w, h);
return pLinearLayout;
}
/**
* Adds a view created with newView
*
* @param v
* @param x
* @param y
* @param w
* @param h
* @return
* @advanced
*/
@PhonkMethod
public View add(View v, Object x, Object y, Object w, Object h) {
addViewAbsolute(v, x, y, w, h);
return v;
}
public View newView(String viewName) {
switch (viewName) {
case "linearLayout":
return new PLinearLayout(mAppRunner);
case "list":
return new PList(mAppRunner);
case "map":
return new PMap(mAppRunner);
case "canvas":
return new PCustomView(mAppRunner);
case "touchPad":
return new PTouchPad(mAppRunner);
case "plot":
return new PPlot(mAppRunner);
case "webView":
return new PWebView(mAppRunner);
case "numberPicker":
return new PNumberPicker(mAppRunner);
case "choiceBox":
return new PSpinner(mAppRunner);
case "image":
return new PImage(mAppRunner);
case "radioButtonGroup":
return new PRadioButtonGroup(mAppRunner);
case "loader":
return new PLoader(mAppRunner);
case "matrix":
return new PMatrix(mAppRunner);
case "knob":
return new PKnob(mAppRunner);
case "slider":
return new PSlider(mAppRunner);
case "pager":
return new PViewPager(mAppRunner);
case "toggle":
return new PToggle(mAppRunner);
case "input":
PInput input = new PInput(mAppRunner);
input.setMaxLines(1);
input.setInputType(InputType.TYPE_CLASS_TEXT);
return input;
case "textArea":
PInput textArea = new PInput(mAppRunner);
textArea.setGravity(Gravity.TOP | Gravity.LEFT);
return textArea;
case "text":
return new PText(mAppRunner);
case "button":
return new PButton(mAppRunner);
case "imageButton":
return new PImageButton(mAppRunner);
default:
return null;
}
}
@Override
public void __stop() {
}
}