add new apis and samples
This commit is contained in:
@@ -8,10 +8,10 @@ end
|
||||
|
||||
function on_click(idx)
|
||||
if idx == 1 then
|
||||
system:send_message("text", "msg-receiver.lua")
|
||||
aio:send_message("text", "msg-receiver.lua")
|
||||
elseif idx == 2 then
|
||||
system:send_message(1)
|
||||
aio:send_message(1)
|
||||
else
|
||||
system:send_message{ "one", "two", "three" }
|
||||
aio:send_message{ "one", "two", "three" }
|
||||
end
|
||||
end
|
||||
|
||||
48
samples/screen-state-widget.lua
Normal file
48
samples/screen-state-widget.lua
Normal file
@@ -0,0 +1,48 @@
|
||||
-- name = "Screen state"
|
||||
|
||||
local json = require "json"
|
||||
|
||||
function on_resume()
|
||||
ui:show_buttons{
|
||||
"Save screen",
|
||||
"Restore screen",
|
||||
}
|
||||
end
|
||||
|
||||
function on_click(idx)
|
||||
if idx == 1 then
|
||||
save_state()
|
||||
else
|
||||
restore_state()
|
||||
end
|
||||
end
|
||||
|
||||
function save_state()
|
||||
local state = aio:get_active_widgets()
|
||||
local json_str = json.encode(state)
|
||||
|
||||
files:write("screen-state", json_str)
|
||||
ui:show_toast("Screen state saved!")
|
||||
end
|
||||
|
||||
function restore_state()
|
||||
local json_str = files:read("screen-state")
|
||||
local state = json.decode(json_str)
|
||||
|
||||
remove_all_widgets()
|
||||
|
||||
for k,v in pairs(state) do
|
||||
aio:add_widget(v.name, v.position)
|
||||
end
|
||||
|
||||
ui:show_toast("Screen state restored!")
|
||||
end
|
||||
|
||||
function remove_all_widgets()
|
||||
local curr_state = aio:get_active_widgets()
|
||||
for k,v in pairs(curr_state) do
|
||||
if (v.name ~= "screen-state-widget.lua") then
|
||||
aio:remove_widget(v.position)
|
||||
end
|
||||
end
|
||||
end
|
||||
@@ -1,11 +1,26 @@
|
||||
function on_resume()
|
||||
ui:show_buttons({ "Add clock widget", "Remove clock widget" })
|
||||
ui:show_lines{
|
||||
"Add clock widget",
|
||||
"Add clock widget (position 1)",
|
||||
"Add clock widget (position 5)",
|
||||
"Remove clock widget",
|
||||
"Swap first and third widgets",
|
||||
"Swap back",
|
||||
}
|
||||
end
|
||||
|
||||
function on_click(idx)
|
||||
if idx == 1 then
|
||||
aio:add_widget("clock")
|
||||
else
|
||||
elseif idx == 2 then
|
||||
aio:add_widget("clock", 1)
|
||||
elseif idx == 3 then
|
||||
aio:add_widget("clock", 5)
|
||||
elseif idx == 4 then
|
||||
aio:remove_widget("clock")
|
||||
elseif idx == 5 then
|
||||
aio:move_widget(1, 3)
|
||||
elseif idx == 6 then
|
||||
aio:move_widget(3, 1)
|
||||
end
|
||||
end
|
||||
|
||||
28
samples/widgets-sample.lua
Normal file
28
samples/widgets-sample.lua
Normal file
@@ -0,0 +1,28 @@
|
||||
local fmt = require "fmt"
|
||||
|
||||
function on_resume()
|
||||
local widgets = aio:get_active_widgets()
|
||||
local tab = {}
|
||||
|
||||
for k,v in pairs(widgets) do
|
||||
table.insert(tab, { fmt.bold(v.name), "(un)fold", "remove" })
|
||||
end
|
||||
|
||||
ui:show_table(tab)
|
||||
end
|
||||
|
||||
function on_click(idx)
|
||||
local widget_num = math.ceil(idx / 3)
|
||||
local action = idx % 3
|
||||
|
||||
if action == 0 then
|
||||
aio:remove_widget(widget_num)
|
||||
elseif action == 2 then
|
||||
aio:fold_widget(widget_num)
|
||||
end
|
||||
end
|
||||
|
||||
function on_widget_action(action, name)
|
||||
ui:show_toast(name.." "..action)
|
||||
on_resume()
|
||||
end
|
||||
13
samples/widgets-sample2.lua
Normal file
13
samples/widgets-sample2.lua
Normal file
@@ -0,0 +1,13 @@
|
||||
local fmt = require "fmt"
|
||||
|
||||
function on_resume()
|
||||
local widgets = aio:get_available_widgets()
|
||||
local tab = {}
|
||||
|
||||
for k,v in pairs(widgets) do
|
||||
table.insert(tab, { fmt.bold(v.name), v.type })
|
||||
end
|
||||
|
||||
ui:show_table(tab)
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user