reorganization

This commit is contained in:
Evgeny
2021-08-06 14:43:34 +03:00
parent 372ec8578d
commit 1e9b33eaea
52 changed files with 1044 additions and 20 deletions

View File

@@ -0,0 +1,11 @@
function on_resume()
apps_names = { "Telegram", "WhatsApp", "Google PLay" }
apps_pkgs = { "org.telegram.messenger.web", "com.whatsapp", "com.android.vending" }
apps_colors = { md_colors.light_blue_500, md_colors.green_500 }
ui:show_buttons(apps_names, apps_colors)
end
function on_click(idx)
system:open_app(apps_pkgs[idx])
end

12
samples/args-test.lua Normal file
View File

@@ -0,0 +1,12 @@
-- arguments_help = "The word recorded here will be displayed on the screen."
-- arguments_default = "Word"
function on_resume()
local args = aio:get_args()
if args == nil then
ui:show_text("args is empty")
else
ui:show_text("arg1: "..args[1])
end
end

View File

@@ -0,0 +1,4 @@
function on_resume()
ui:set_folding_flag(true)
ui:show_lines({"First line", "Second line", "Third line"})
end

9
samples/bad-script.lua Normal file
View File

@@ -0,0 +1,9 @@
function on_resume()
ui:show_text("Click to freeze launcher")
end
function on_click()
while true do
system:copy_to_clipboard("http://google.com")
end
end

5
samples/bad-script2.lua Normal file
View File

@@ -0,0 +1,5 @@
function on_resume()
while true do
ui:show_text("Haha")
end
end

2
samples/bad-script3.lua Normal file
View File

@@ -0,0 +1,2 @@
ui:show_toast("Hello")

5
samples/bad-script4.lua Normal file
View File

@@ -0,0 +1,5 @@
function on_tick()
while true do
ui:show_text("bad")
end
end

View File

@@ -0,0 +1,19 @@
buttons = { "Disabled", "Disabled", "Disabled" }
function on_resume()
redraw()
end
function on_click(idx)
if buttons[idx] == "Disabled" then
buttons[idx] = "Enabled"
else
buttons[idx] = "Disabled"
end
redraw()
end
function redraw()
ui:show_buttons(buttons)
end

View File

@@ -0,0 +1,16 @@
function on_resume()
ui:show_text("Open dialog")
end
function on_click()
dialog_items = { "One", "Two", "Three" }
ui:show_checkbox_dialog("Title", dialog_items, 2)
end
function on_dialog_action(idx)
if idx == -1 then
ui:show_toast("Dialog cancelled")
else
ui:show_toast("Checked: "..dialog_items[idx])
end
end

4
samples/clock-widget.lua Normal file
View File

@@ -0,0 +1,4 @@
function on_tick()
local time_str = os.date('%Y-%m-%d %H:%M:%S')
ui:show_text(time_str)
end

View File

@@ -0,0 +1,11 @@
local co = coroutine.create(function()
while true do
ui:show_text("Hello world!")
coroutine.yield()
end
end)
function on_resume()
ui:set_title(coroutine.status(co))
coroutine.resume(co)
end

27
samples/dialog_sample.lua Normal file
View File

@@ -0,0 +1,27 @@
function on_resume()
ui:show_lines({
"Click to open dialog",
"Click to open dialog with custom buttons",
"Click to open edit dialog",
})
end
function on_click(idx)
if idx == 1 then
ui:show_dialog("Dialog title", "This is dialog")
elseif idx == 2 then
ui:show_dialog("Dialog title", "This is dialog", "Button 1", "Button 2")
elseif idx == 3 then
ui:show_edit_dialog("Dialog title", "Write any text", "default text")
end
end
function on_dialog_action(value)
if value == 1 then
ui:show_toast("Button 1 clicked!")
elseif value == 2 then
ui:show_toast("Button 2 clicked!")
elseif type(value) == "string" then
ui:show_toast("Text: "..value)
end
end

View File

@@ -0,0 +1,3 @@
function on_resume()
ui:show_text("Hello world!")
end

3
samples/html_test.lua Normal file
View File

@@ -0,0 +1,3 @@
function on_resume()
ui:show_lines({ "This is <b>bold</b> text" })
end

View File

@@ -0,0 +1,20 @@
ip_service_url = "https://freegeoip.app/json/"
addr_service_url = "https://nominatim.openstreetmap.org/reverse?format=json"
function on_alarm()
http:get(ip_service_url, "ip")
end
function on_network_result_ip(result)
local location = {
ajson:get_value(result, "object string:latitude"),
ajson:get_value(result, "object string:longitude")
}
http:get(addr_service_url.."&lat="..location[1].."&lon=".. location[2].."&addressdetails=1", "addr")
end
function on_network_result_addr(result)
local adr = ajson:get_value(result, "object string:display_name")
ui:show_text(adr)
end

View File

@@ -0,0 +1,3 @@
function on_resume()
ui:show_text("Mail widget on the screen: " .. tostring(aio:is_widget_added("mail")))
end

6
samples/json-test.lua Normal file
View File

@@ -0,0 +1,6 @@
json = require "json"
function on_resume()
local t = json.decode('[1,2,3,{"x":10}]')
ui:show_text(t[4].x)
end

View File

@@ -0,0 +1,4 @@
function on_resume()
local location = system:get_location()
ui:show_text(location[1].." "..location[2])
end

7
samples/pl-tests.lua Normal file
View File

@@ -0,0 +1,7 @@
sx = require 'pl.stringx'
function on_resume()
local string = "String with spaces"
local s_list = sx.split(string, " ")
ui:show_text(s_list[3])
end

9
samples/place-widget.lua Normal file
View File

@@ -0,0 +1,9 @@
function on_alarm()
local location = system:get_location()
http:get("https://nominatim.openstreetmap.org/reverse?format=json&lat=".. location[1].."&lon=".. location[2].."&addressdetails=1")
end
function on_network_result(result)
local adr = ajson:get_value(result, "object string:display_name")
ui:show_text(adr)
end

5
samples/print-error.lua Normal file
View File

@@ -0,0 +1,5 @@
function print_hello()
print("HELLO")
end
print_hello()

View File

@@ -0,0 +1,7 @@
function on_resume()
http:get("https://google.com")
end
function on_network_result(body, code)
ui:show_text(code)
end

4
samples/title-sample.lua Normal file
View File

@@ -0,0 +1,4 @@
function on_resume()
ui:set_title("New title")
ui:show_text("Original title: "..ui:get_default_title())
end

5
samples/utils-sample.lua Normal file
View File

@@ -0,0 +1,5 @@
function on_resume()
local str = "one two three"
local tab = str:split(" ")
ui:show_text(tab[2])
end

View File

@@ -0,0 +1,11 @@
function on_resume()
ui:show_buttons({ "Add clock widget", "Remove clock widget" })
end
function on_click(idx)
if idx == 1 then
aio:add_widget("clock")
else
aio:remove_widget("clock")
end
end