From 75057f8c422ca3c5675fcdb2210f86e5463099aa Mon Sep 17 00:00:00 2001 From: Evgeny Date: Thu, 23 Feb 2023 13:20:34 +0400 Subject: [PATCH] Add new APIs --- README.md | 45 ++++++++++++++++++++++++++++++++----- samples/build_ui_sample.lua | 19 ++++++++++++++++ samples/search-test.lua | 2 +- samples/search-test2.lua | 2 +- samples/search-test3.lua | 19 ++++++++++++++++ samples/search-test4.lua | 20 +++++++++++++++++ samples/search-test5.lua | 20 +++++++++++++++++ 7 files changed, 119 insertions(+), 8 deletions(-) create mode 100644 samples/build_ui_sample.lua create mode 100644 samples/search-test3.lua create mode 100644 samples/search-test4.lua create mode 100644 samples/search-test5.lua diff --git a/README.md b/README.md index 146399f..65bf1f0 100644 --- a/README.md +++ b/README.md @@ -33,7 +33,8 @@ The type of script is determined by the line (meta tag) at the beginning of the * 4.5.5 - added `on_action` callback and `calendar:add_event` function; * 4.5.6 - `aio:active_widgets()` now returns also widget `label`, added `checks` module; * 4.5.7 - added "fold" and "unfold" actions to the `on_action` callback; -* 4.6.0 - added `system:request_location()` and `tasker:send_command()` functions. +* 4.6.0 - added `system:request_location()` and `tasker:send_command()` functions; +* 4.7.0 - added `ui:build()` and functions to display search results in different formats. # Widget scripts @@ -55,10 +56,10 @@ Unlike widget scripts, search scripts are launched only when you open the search The search script can use two functions to display search results: -* `search:show(strings, [colors])` - shows results BELOW all other results; -* `search:show_top(strings, [colors])` - shows results BEFORE all other results. - -Both functions take a table with search results strings as the first argument. Second optional parameter: table with colors of results in format `#XXXXXX`. +* `search:show_buttons(names, [colors], [top])` - show buttons in the search results, the first parameter is table of button names, second - table of button colors in format `#XXXXXX`, `top` - whether the results need to be shown at the top (false by default); +* `search:show_lines(lines, [colors], [top])` - show text lines in the search results; +* `search:show_progress(names, progresses, [colors], [top])` - show progress bars in the search results, the first parameter is a table of names, the second is a table of progress bars (from 1 to 100); +* `search:show_chart(points, format, [title], [show_grid], [top])` - show chart in the search results, parameters are analogous to `ui:show_chart()`. When user click on a result, one of the following functions will be executed: @@ -114,7 +115,7 @@ First line
Second line You can also use Markdown markup. To do this, add the prefix `%%mkd%%` to the beginning of the line. Or you can disable the formatting completely with the prefix `%%txt%%`. -The `ui:show_buttons()` function supports Fontawesome icons. Simply specify `fa:icon_name` as the button name, for example: `fa:play`. +The `ui:show_buttons()` function supports Fontawesome icons. Simply specify `fa:icon_name` as the button name, for example: `fa:play`. (Note: AIO only supports icons up to Fontawesome 5.12.) ## Dialogs @@ -189,6 +190,38 @@ Here `share`, `copy` and `trash` are the names of the icons, which can be found When you click on any menu item, the collback `on_context_menu_click(idx)` will be called, where `idx` is the index of the menu item. +## Build meta-widget + +_Avaialble from: 4.7.0_ + +* `ui:build(table)` - constructs a widget from pieces of other AIO widgets. + +The function takes a command table of this format as a parameter: + +``` +`battery` - battery progress bar; +`ram` - ram progress bar; +`nand` - nand progress bar; +`traffic` - traffic progress bar; +`screen` - screen time progress bar; +`alarm` - next alarm info; +`notes [NUM]` - last NUM notes; +`tasks [NUM]` - last NUM tasks; +`calendar [NUM]` - last NUM calendar events; +`exchage [NUM] [FROM] [TO]` - exchange rate FROM currency TO currency; +`player` - player controls; +`health` - health data; +`weather [NUM]` - weather forecast for NUM days; +`bitcoin` - bitcoin rate chart; +`worldclock [TIME_ZONE]` - time in the given TIME_ZONE; +`notify [NUM]` - last NUM notifications; +`dialogs [NUM]` - last NUM dialogs; +`text [TEXT]` - just shows TEXT; +`space [NUM]` - NUM of spaces. +``` + +[Sample](samples/build_ui_sample.lua). + ## System * `system:open_browser(url)` - opens the specified URL in a browser or application that can handle this type of URL; diff --git a/samples/build_ui_sample.lua b/samples/build_ui_sample.lua new file mode 100644 index 0000000..49fd0c1 --- /dev/null +++ b/samples/build_ui_sample.lua @@ -0,0 +1,19 @@ +function on_resume() + ui:build{ + "text This is a sample", + "space 2", + "text Battery level", + "space", + "battery", + "space 2", + "text Notes", + "space", + "notes 2", + "space 2", + "text Exchange rates", + "exchange 10 usd amd", + "space 2", + "text Timezones", + "worldclock new_york kiev bangkok", + } +end diff --git a/samples/search-test.lua b/samples/search-test.lua index 379ea91..12c2a51 100644 --- a/samples/search-test.lua +++ b/samples/search-test.lua @@ -4,7 +4,7 @@ local table = {} function on_search(input) - search:show({ input.." 1", input.." 2" }) + search:show_buttons({ input.." 1", input.." 2" }) end function on_click(idx) diff --git a/samples/search-test2.lua b/samples/search-test2.lua index 9824346..acace51 100644 --- a/samples/search-test2.lua +++ b/samples/search-test2.lua @@ -7,7 +7,7 @@ function on_search() local texts = { "text1", "text2", "text3" } local colors = { md_colors.purple_400, md_colors.purple_600, md_colors.purple_800 } - search:show(texts, colors) + search:show_buttons(texts, colors) end function on_click(idx) diff --git a/samples/search-test3.lua b/samples/search-test3.lua new file mode 100644 index 0000000..03c4c2f --- /dev/null +++ b/samples/search-test3.lua @@ -0,0 +1,19 @@ +-- name = "Script #3" +-- type = "search" + +md_colors = require("md_colors") + +function on_search() + local texts = { "Line one", "Line two", "Line three" } + local colors = { md_colors.purple_400, md_colors.purple_600, md_colors.purple_800 } + + search:show_lines(texts, colors) +end + +function on_click(idx) + if idx == 1 then + system:vibrate(100) + else + system:vibrate(300) + end +end diff --git a/samples/search-test4.lua b/samples/search-test4.lua new file mode 100644 index 0000000..7d32b5f --- /dev/null +++ b/samples/search-test4.lua @@ -0,0 +1,20 @@ +-- name = "Script #4" +-- type = "search" + +md_colors = require("md_colors") + +function on_search() + local texts = { "progress 1", "progress 2", "progress 3" } + local progresses = { 10, 50, 90 } + local colors = { md_colors.purple_400, md_colors.purple_600, md_colors.purple_800 } + + search:show_progress(texts, progresses, colors) +end + +function on_click(idx) + if idx == 1 then + system:vibrate(100) + else + system:vibrate(300) + end +end diff --git a/samples/search-test5.lua b/samples/search-test5.lua new file mode 100644 index 0000000..58969c9 --- /dev/null +++ b/samples/search-test5.lua @@ -0,0 +1,20 @@ +-- name = "Script #5" +-- type = "search" + +function on_search() + local points = { + { 1628501740654, 123456789 }, + { 1628503740654, 300000000 }, + { 1628505740654, 987654321 }, + } + + search:show_chart(points, "x:date y:number") +end + +function on_click(idx) + if idx == 1 then + system:vibrate(100) + else + system:vibrate(300) + end +end