@@ -5,7 +5,7 @@ This tutorial assumes you have the basic understanding of the Android GUI from
5
5
the [ crash course] ( https://github.com/termux/termux-gui ) .
6
6
The full source code can also be found in the tutorial folder.
7
7
8
- ## Basic structure
8
+ ## Loading the library
9
9
10
10
To use the library, you have 2 options:
11
11
- Use the shebang ` #!/bin/tgui-bash ` instead of ` #!/bin/bash ` . The library will initialize itself and then load your script.
@@ -19,6 +19,8 @@ The library exits when your script exits, and all remaining Activities are clean
19
19
```` bash
20
20
#! /bin/tgui-bash
21
21
22
+ set -u
23
+
22
24
# Parameters for the Activity, can be empty
23
25
declare -A aparams=()
24
26
# Array to store the Activity id and Task id in
@@ -42,3 +44,372 @@ tg_create_text "$aid" tparams
42
44
sleep 2
43
45
````
44
46
47
+ [ hello_world.sh] ( tutorial/hello_world.sh )
48
+
49
+
50
+ ## Events
51
+
52
+
53
+ In a GUI, you want to react to events caused by the user.
54
+ In this library you have the option to poll for events (not recommended) with ` tg_msg_recv_event `
55
+ and to wait for events with ` tg_msg_recv_event_blocking ` .
56
+ To process events, you have some functions and ` jq ` available to get the information you need.
57
+ Though for most of the events you only need to know that the ` . ` operator in jq accesses a value of an object.
58
+ With that, you can parse the events you need according to the [ protocol definition] ( https://github.com/termux/termux-gui/blob/main/Protocol.md#events ) .
59
+
60
+
61
+
62
+ ```` bash
63
+ #! /bin/tgui-bash
64
+
65
+ set -u
66
+
67
+ declare -A aparams=()
68
+ declare -a activity=()
69
+
70
+ tg_activity_new aparams activity
71
+
72
+ aid=" ${activity[0]} "
73
+
74
+ # Parameters for creating a Button, in this case the text.
75
+ declare -A bparams=([${tgc_create_text} ]=" Hello World!" )
76
+
77
+ # Create the Button and save the id
78
+ b=" $( tg_create_button " $aid " bparams) "
79
+
80
+ while true ; do
81
+ ev=" $( tg_msg_recv_event_blocking) "
82
+
83
+ # Print when the button is pressed
84
+ if [ " $( tg_event_type " $ev " ) " = " $tgc_ev_click " ] && [ " $( tg_event_id " $ev " ) " = " $b " ]; then
85
+ echo " Button pressed!"
86
+ fi
87
+
88
+ # Exit when the Activity is closed
89
+ if [ " $( tg_event_type " $ev " ) " = " $tgc_ev_destroy " ]; then
90
+ exit 0
91
+ fi
92
+ done
93
+ ````
94
+
95
+ [ events.sh] ( tutorial/events.sh )
96
+
97
+ ## Layout hierarchy
98
+
99
+ To arrange Views you need to use Layouts. The simplest one is LinearLayout.
100
+
101
+ ```` bash
102
+ #! /bin/tgui-bash
103
+
104
+ set -u
105
+
106
+ declare -A aparams=()
107
+ declare -a activity=()
108
+
109
+ tg_activity_new aparams activity
110
+
111
+ aid=" ${activity[0]} "
112
+
113
+
114
+ declare -A lparams=()
115
+
116
+ # Create the LinearLayout and save the id
117
+ layout=" $( tg_create_linear " $aid " lparams) "
118
+
119
+ # Create Buttons in the Layout
120
+ declare -A bparams=()
121
+ for i in {1..5}; do
122
+ bparams[$tgc_create_text ]=$i
123
+ tg_create_button " $aid " bparams " $layout " > /dev/null
124
+ done
125
+
126
+ while true ; do
127
+ ev=" $( tg_msg_recv_event_blocking) "
128
+ # Exit when the Activity is closed
129
+ if [ " $( tg_event_type " $ev " ) " = " $tgc_ev_destroy " ]; then
130
+ exit 0
131
+ fi
132
+ done
133
+ ````
134
+
135
+ [ linearlayout.sh] ( tutorial/linearlayout.sh )
136
+
137
+ ## Images and picture-in-picture
138
+
139
+ You can display images in PNG or JPEG format by base43-encoding them.
140
+ The ` base64 ` command is preinstalled in Termux.
141
+ To generate the image string you should use ` img="$(base64 -w 0 <filepath>)" ` .
142
+
143
+ Picture-in-picture mode allows you to show the Activity in a small overlay window.
144
+
145
+
146
+ ```` bash
147
+ #! /bin/tgui-bash
148
+
149
+ set -u
150
+
151
+ # Base64-encoded image of the Termux banner
152
+ banner="iVBORw0KGgoAAAANSUhEUgAAAUAAAAC0CAIAAABqhmJGAAAABmJLR0QA/wD/AP+gvaeTAAANFklEQVR4nO3dfVBU1f/A8cuTSAyLGfGQBCiV8aRAaaWkaTQ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AAAAAAAAAAAAAAAAAAAAAAAAADAlPkfRy4g+z/BZ4sAAAAASUVORK5CYII="
153
+
154
+ # Let the Activity start in picture-in-picture mode
155
+ declare -A aparams=([$tgc_actvivity_pip ]=" true" )
156
+ declare -a activity=()
157
+
158
+ tg_activity_new aparams activity
159
+
160
+ aid=" ${activity[0]} "
161
+
162
+ # set the aspect ratio to that of the image
163
+ tg_activity_pip_params " $aid " " 320" " 180"
164
+
165
+ declare -A imgparams=()
166
+
167
+ # Create an ImageView and save the id
168
+ img=" $( tg_create_image " $aid " imgparams) "
169
+
170
+ # Set the image
171
+ tg_view_image " $aid " " $img " " $banner "
172
+
173
+ while true ; do
174
+ ev=" $( tg_msg_recv_event_blocking) "
175
+ # Exit when the user leaves
176
+ if [ " $( tg_event_type " $ev " ) " = " $tgc_ev_stop " ]; then
177
+ exit 0
178
+ fi
179
+ done
180
+ ````
181
+
182
+ [ image.sh] ( tutorial/image.sh )
183
+
184
+ ## Dialogs & Inputs
185
+
186
+ An Activity can also be shown as a dialog.
187
+ This make for a great user experience with Termux, as exiting the dialog drops you right back into the terminal without animation.
188
+
189
+
190
+ ```` bash
191
+ #! /bin/tgui-bash
192
+
193
+ set -u
194
+
195
+
196
+ # Let the Activity start as a dialog
197
+ declare -A aparams=([$tgc_actvivity_dialog ]=" true" )
198
+ declare -a activity=()
199
+
200
+ tg_activity_new aparams activity
201
+
202
+ aid=" ${activity[0]} "
203
+
204
+ declare -A params=()
205
+
206
+ layout=" $( tg_create_linear " $aid " params) "
207
+
208
+ # EditText
209
+ et=" $( tg_create_edit " $aid " params " $layout " ) "
210
+
211
+ params[$tgc_create_text ]=" Click me!"
212
+ echo " ${params[@]} "
213
+ # Button
214
+ bt=" $( tg_create_button " $aid " params " $layout " ) "
215
+
216
+ # unset "params[$tgc_create_text]"
217
+ declare -a list=(" Option 1" " Option 2" " Option 3" " Option 4" )
218
+
219
+ # Spinner
220
+ sp=" $( tg_create_spinner " $aid " params " $layout " ) "
221
+ # Set the options
222
+ tg_view_list " $aid " " $sp " list
223
+
224
+ # Toggle
225
+ tg=" $( tg_create_toggle " $aid " params " $layout " ) "
226
+
227
+ params[$tgc_create_text ]=" Switch"
228
+
229
+ # Switch
230
+ sw=" $( tg_create_switch " $aid " params " $layout " ) "
231
+
232
+
233
+ params[$tgc_create_text ]=" Checkbox"
234
+ # CheckBox
235
+ cb=" $( tg_create_checkbox " $aid " params " $layout " ) "
236
+
237
+ # Group for RadioButtons
238
+ rg=" $( tg_create_radio_group " $aid " params " $layout " ) "
239
+
240
+ # Create some RadioButtons
241
+ # RadioButtons have to be in a RadioGroup to work
242
+ params[$tgc_create_text ]=" RadioButton 1"
243
+ rb1=" $( tg_create_radio " $aid " params " $rg " ) "
244
+
245
+ params[$tgc_create_text ]=" RadioButton 2"
246
+ rb2=" $( tg_create_radio " $aid " params " $rg " ) "
247
+
248
+ params[$tgc_create_text ]=" RadioButton 3"
249
+ rb3=" $( tg_create_radio " $aid " params " $rg " ) "
250
+
251
+
252
+ while true ; do
253
+ ev=" $( tg_msg_recv_event_blocking) "
254
+ # Exit when the user leaves
255
+ if [ " $( tg_event_type " $ev " ) " = " $tgc_ev_stop " ]; then
256
+ exit 0
257
+ fi
258
+ # Print out the EditText text when the Button gets clicked
259
+ if [ " $( tg_event_type " $ev " ) " = " $tgc_ev_click " ] && [ " $( tg_event_aid " $ev " ) " = " $aid " ] && [ " $( tg_event_id " $ev " ) " = " $bt " ]; then
260
+ echo " EditText text: '$( tg_view_get_text " $aid " " $et " ) '"
261
+ fi
262
+ # Print the RadioButton id that is selected
263
+ if [ " $( tg_event_type " $ev " ) " = " $tgc_ev_selected " ] && [ " $( tg_event_aid " $ev " ) " = " $aid " ] && [ " $( tg_event_id " $ev " ) " = " $rg " ]; then
264
+ echo " RadioButton pressed: $( echo " $ev " | jq -r ' .value.selected' ) "
265
+ fi
266
+ # Print the checked state of other button on click
267
+ if [ " $( tg_event_type " $ev " ) " = " $tgc_ev_click " ] && [ " $( tg_event_aid " $ev " ) " = " $aid " ] && [ " $( tg_event_id " $ev " ) " = " $cb " ]; then
268
+ echo " CheckBox pressed: $( echo " $ev " | jq -r ' .value.set' ) "
269
+ fi
270
+ if [ " $( tg_event_type " $ev " ) " = " $tgc_ev_click " ] && [ " $( tg_event_aid " $ev " ) " = " $aid " ] && [ " $( tg_event_id " $ev " ) " = " $sw " ]; then
271
+ echo " Switch pressed: $( echo " $ev " | jq -r ' .value.set' ) "
272
+ fi
273
+ if [ " $( tg_event_type " $ev " ) " = " $tgc_ev_click " ] && [ " $( tg_event_aid " $ev " ) " = " $aid " ] && [ " $( tg_event_id " $ev " ) " = " $tg " ]; then
274
+ echo " ToggleButton pressed: $( echo " $ev " | jq -r ' .value.set' ) "
275
+ fi
276
+ # Print the selected Spinner option
277
+ if [ " $( tg_event_type " $ev " ) " = " $tgc_ev_item_selected " ] && [ " $( tg_event_aid " $ev " ) " = " $aid " ] && [ " $( tg_event_id " $ev " ) " = " $sp " ]; then
278
+ echo " Spinner option: '$( echo " $ev " | jq -r ' .value.selected' ) '"
279
+ fi
280
+ done
281
+ ````
282
+
283
+ [ dialog.sh] ( tutorial/dialog.sh )
284
+
285
+
286
+
287
+ ## Nested Layouts & Scrolling
288
+
289
+ By default, LinearLayouts arrange their children vertically.
290
+ To create e.g. a bar at the top, you can override this with ` $tgc_create_vertical ` .
291
+ To create a bar however, you should also set the height of the nested layout to ` $tgc_view_wrap_content ` ,
292
+ and the layout weight to 0, so it only takes up the space of its children.
293
+ Nested layouts can also be used for content in NestedScrollViews, when you can't be sure if the content will fit on the screen.
294
+
295
+
296
+ ```` bash
297
+ #! /bin/tgui-bash
298
+
299
+ set -u
300
+
301
+
302
+ # Let the Activity start as a dialog
303
+ declare -A aparams=()
304
+ declare -a activity=()
305
+
306
+ tg_activity_new aparams activity
307
+
308
+ aid=" ${activity[0]} "
309
+
310
+ declare -A params=()
311
+
312
+ layout=" $( tg_create_linear " $aid " params) "
313
+
314
+
315
+ # Create a Horizontal LinearLayout
316
+ params[$tgc_create_vertical ]=false
317
+
318
+ bar=" $( tg_create_linear " $aid " params " $layout " ) "
319
+
320
+ unset " params[$tgc_create_vertical ]"
321
+
322
+ # Set the height no the minimum needed
323
+ tg_view_height " $aid " " $bar " " $tgc_view_wrap_content "
324
+ # Don't let it expand to unused space
325
+ tg_view_linear " $aid " " $bar " 0
326
+
327
+ # Create 2 Buttons in the bar
328
+ params[$tgc_create_text ]=" Bar button 1"
329
+ bt1=" $( tg_create_button " $aid " params " $bar " ) "
330
+
331
+ params[$tgc_create_text ]=" Bar button 2"
332
+ bt2=" $( tg_create_button " $aid " params " $bar " ) "
333
+
334
+ unset " params[$tgc_create_text ]"
335
+
336
+
337
+ # Create a NestedScrollView and a LinearLayout in it
338
+ sc=" $( tg_create_nested_scroll " $aid " params " $layout " ) "
339
+ scl=" $( tg_create_linear " $aid " params " $sc " ) "
340
+
341
+ # Create Buttons in the NestedScrollView
342
+ for i in {1..30}; do
343
+ params[$tgc_create_text ]=" Button $i "
344
+ tg_create_button " $aid " params " $scl " > /dev/null
345
+ done
346
+
347
+
348
+ while true ; do
349
+ ev=" $( tg_msg_recv_event_blocking) "
350
+ if [ " $( tg_event_type " $ev " ) " = " $tgc_ev_destroy " ]; then
351
+ exit 0
352
+ fi
353
+ done
354
+ ````
355
+
356
+ [ scroll.sh] ( tutorial/scroll.sh )
357
+
358
+
359
+ ## Widgets
360
+
361
+ Termux: GUI allows you to create widgets which programs can fill.
362
+ The methods for widgets are slightly different, because Android doesn't support as much functionality for widgets.
363
+
364
+
365
+ ```` bash
366
+ #! /bin/tgui-bash
367
+
368
+ set -u
369
+
370
+
371
+ # Let the Activity start as a dialog
372
+ declare -A aparams=()
373
+ declare -a activity=()
374
+
375
+ tg_activity_new aparams activity
376
+
377
+ aid=" ${activity[0]} "
378
+
379
+ declare -A params=()
380
+
381
+ layout=" $( tg_create_linear " $aid " params) "
382
+
383
+
384
+ widfield=" $( tg_create_edit " $aid " params " $layout " ) "
385
+
386
+ textfield=" $( tg_create_edit " $aid " params " $layout " ) "
387
+
388
+
389
+ params[$tgc_create_text ]=" Set widget text"
390
+
391
+ b=" $( tg_create_button " $aid " params " $layout " ) "
392
+
393
+
394
+ while true ; do
395
+ ev=" $( tg_msg_recv_event_blocking) "
396
+ if [ " $( tg_event_type " $ev " ) " = " $tgc_ev_destroy " ]; then
397
+ exit 0
398
+ fi
399
+ if [ " $( tg_event_type " $ev " ) " = " $tgc_ev_click " ] && [ " $( tg_event_id " $ev " ) " = " $b " ]; then
400
+ # Get the widget id
401
+ wid=" $( tg_view_get_text " $aid " " $widfield " ) "
402
+ text=" $( tg_view_get_text " $aid " " $textfield " ) "
403
+ # Create a remote layout and TextView
404
+ rl=" $( tg_remote_create_layout) "
405
+ rt=" $( tg_remote_create_text " $rl " ) "
406
+ # Set the text
407
+ tg_remote_text " $rl " " $rt " " $text "
408
+ # Set the widget layout and destroy the remote layout again
409
+ tg_widget_layout " $rl " " $wid "
410
+ tc_remote_delete_layout " $rl "
411
+ fi
412
+ done
413
+ ````
414
+
415
+
0 commit comments