Move useless scripts to samples folder

This commit is contained in:
Evgeny
2024-04-18 14:47:18 +04:00
parent 3242d9c24f
commit 5eea6d8b91
8 changed files with 1 additions and 0 deletions

View File

@@ -1,360 +0,0 @@
-- name = "My apps"
-- description = "Simple apps widget"
-- type = "widget"
-- version = "1.0"
-- author = "Andrey Gavrilov"
local utf8 = require "utf8"
local dialog_id = ""
local app_idx = 0
function on_resume()
update_args()
local folding = false
if settings:get_kv()["folding"] == "true" then
folding = true
end
ui:set_folding_flag(folding)
redraw()
end
function on_alarm()
local args = settings:get_kv()
if next(args) == nil then
args["no_hidden"] = true
args["columns"] = 4
args["trim"] = 10
args["folding"] = false
args["1"] = "com.android.settings"
settings:set_kv(args)
redraw()
end
end
function on_settings()
dialog_id = "settings"
local tab = {"Applications list","No hidden setting","Columns number","Trim app name","Autofolding setting","Widget title"}
ui:show_radio_dialog("Settings",tab)
end
function on_dialog_action(data)
if data == -1 then
return
end
if dialog_id == "settings" then
if data == 1 then
dialog_id = "apps"
local tab = get_all_apps("abc",settings:get_kv()["no_hidden"])
ui:show_checkbox_dialog("Select apps",tab[2],args_to_idx(tab[1]))
return
elseif data == 2 then
dialog_id = "no_hidden"
local tab = {"Not show hidden applications"}
local tt = {}
if tostring(settings:get_kv()["no_hidden"]) == "true" then
tt = {1}
end
ui:show_checkbox_dialog("No hidden settings",tab,tt)
return
elseif data == 3 then
dialog_id = "columns"
ui:show_edit_dialog("Columns number","",settings:get_kv()["columns"])
return
elseif data == 4 then
dialog_id = "trim"
ui:show_edit_dialog("Trim app name","0 - not trim",settings:get_kv()["trim"])
return
elseif data == 5 then
dialog_id = "folding"
local tab = {"Autofolding"}
local tt = {}
if tostring(settings:get_kv()["folding"]) == "true" then
tt = {1}
end
ui:show_checkbox_dialog("Autofolding settings",tab,tt)
return
elseif data == 6 then
dialog_id = "name"
ui:show_edit_dialog("Set widget title","Empty - default title",ui:get_default_title())
return
end
elseif dialog_id == "no_hidden" then
local args = settings:get_kv()
if next(data) == nil then
args["no_hidden"] = false
else
args["no_hidden"] = true
end
settings:set_kv(args)
update_args()
redraw()
return
elseif dialog_id == "apps" then
settings:set_kv(idx_to_args(data))
redraw()
return
elseif dialog_id == "columns" then
if data == tostring(tonumber(data)) then
if tonumber(data) == 0 then
data = "1"
end
local args = settings:get_kv()
args["columns"] = math.floor(tonumber(data))
settings:set_kv(args)
update_args()
redraw()
end
return
elseif dialog_id == "trim" then
if data == tostring(tonumber(data)) then
local args = settings:get_kv()
args["trim"] = math.floor(tonumber(data))
settings:set_kv(args)
update_args()
redraw()
end
return
elseif dialog_id == "folding" then
local args = settings:get_kv()
if next(data) == nil then
args["folding"] = false
else
args["folding"] = true
end
settings:set_kv(args)
update_args()
redraw()
return
elseif dialog_id == "name" then
local title = ui:get_default_title()
if data ~= "" then
title = data
end
ui:set_title(title)
return
elseif dialog_id == "move" then
if data == tostring(tonumber(data)) then
local idx = math.floor(tonumber(data))
local args = settings:get_kv()
if idx < 1 then
idx = 1
elseif idx > max_key(args) then
idx = max_key(args)
end
local from = args[tostring(app_idx)]
local to = args[tostring(idx)]
args[tostring(app_idx)] = to
args[tostring(idx)] = from
settings:set_kv(args)
update_args()
redraw()
return
end
end
end
function on_context_menu_click(idx)
if idx == 4 then
apps:show_edit_dialog(settings:get_kv()[tostring(app_idx)])
elseif idx == 1 then
local args = settings:get_kv()
if app_idx == max_key(args) then
return
end
local from = args[tostring(app_idx)]
local to = args[tostring(app_idx+1)]
args[tostring(app_idx)] = to
args[tostring(app_idx+1)] = from
settings:set_kv(args)
update_args()
redraw()
return
elseif idx == 3 then
local args = settings:get_kv()
if app_idx == 1 then
return
end
local from = args[tostring(app_idx)]
local to = args[tostring(app_idx-1)]
args[tostring(app_idx)] = to
args[tostring(app_idx-1)] = from
settings:set_kv(args)
update_args()
redraw()
return
elseif idx == 2 then
local args = settings:get_kv()
local new_args = {}
for k,v in pairs(args) do
if k ~= tostring(app_idx) then
new_args[k] = v
end
end
settings:set_kv(new_args)
update_args()
redraw()
return
elseif idx == 5 then
dialog_id = "move"
local text = "Number from 1 to "..tostring(max_key(settings:get_kv()))
ui:show_edit_dialog("Set position",text,app_idx)
return
end
end
function redraw()
local cols = tonumber(settings:get_kv()["columns"])
if cols == 0 or cols == nil then
cols = 1
end
ui:show_table(table_to_tables(tab_from_args(), cols))
end
function on_click(idx)
apps:launch(settings:get_kv()[tostring(idx)])
end
function on_long_click(idx)
app_idx = idx
ui:show_context_menu({
{ "chevron-right", "Forward" },
{ "times", "Remove" },
{ "chevron-left", "Back" },
{ "edit", "Edit" },
{ "exchange", "Move" }
})
end
function tab_from_args()
local args = settings:get_kv()
local len = tonumber(args["trim"])
if len == nil then
len = 0
end
local tab = {}
for k,v in pairs(args) do
if k == tostring(tonumber(k)) then
tab[tonumber(k)] = get_formatted_name(v,len)
end
end
return tab
end
function get_formatted_name(pkg,len)
local str = apps:get_name(pkg)
if utf8.len(str) > len and len > 0 then
str = utf8.sub(str,1,len-1):gsub("[%. ]*$","").."."
end
return "<font color=\""..apps:get_color(pkg).."\">"..str.."</font>"
end
function table_to_tables(tab, num)
local out_tab = {}
local row = {}
for k,v in ipairs(tab) do
table.insert(row, v)
if k % num == 0 then
table.insert(out_tab, row)
row = {}
end
end
if row ~= {} then
table.insert(out_tab, row)
end
return out_tab
end
function get_all_apps(sort_by,no_hidden)
if tostring(no_hidden) == "true" then
no_hidden = true
else
no_hidden = false
end
local t = settings:get_kv()
local all_apps = apps:get_list(sort_by,no_hidden)
local apps_names = {}
for k,v in ipairs(all_apps) do
apps_names[k] = apps:get_name(v)
end
return {all_apps,apps_names}
end
function args_to_idx(tab)
local args = settings:get_kv()
local t = {}
for k,v in pairs(args) do
local idx = get_index(tab,v)
if idx > 0 then
table.insert(t,idx)
end
end
return t
end
function idx_to_args(tab)
local args = settings:get_kv()
local all_apps = get_all_apps("abc",args["no_hidden"])[1]
local new_args = {}
for i,v in ipairs(tab) do
if get_key(args,all_apps[tonumber(v)]) == 0 then
new_args[tostring(max_key(args)+i)] = all_apps[tonumber(v)]
else
new_args[get_key(args,all_apps[tonumber(v)])] = all_apps[tonumber(v)]
end
end
new_args = sort_by_key(new_args)
new_args["no_hidden"] = args["no_hidden"]
new_args["columns"] = args["columns"]
new_args["trim"] = args["trim"]
new_args["folding"] = args["folding"]
return new_args
end
function update_args()
local args = settings:get_kv()
local all_apps = get_all_apps("abc",args["no_hidden"])[1]
local new_args = {}
for k,v in pairs(args) do
if k == tostring(tonumber(k)) then
if get_index(all_apps,v) ~= 0 then
new_args[k] = v
end
end
end
new_args = sort_by_key(new_args)
new_args["no_hidden"] = args["no_hidden"]
new_args["columns"] = args["columns"]
new_args["trim"] = args["trim"]
new_args["folding"] = args["folding"]
settings:set_kv(new_args)
end
function sort_by_key(tab)
local t = {}
local tt = {}
for k,v in pairs(tab) do
table.insert(t,tonumber(k))
end
table.sort(t)
for i,v in ipairs(t) do
for kk,vv in pairs(tab) do
if kk == tostring(v) then
tt[tostring(i)] = vv
break
end
end
end
return tt
end
function max_key(tab)
local t = {}
for k,v in pairs(tab) do
if k == tostring(tonumber(k)) then
table.insert(t,k)
end
end
table.sort(t)
return #t
end

View File

@@ -1,16 +0,0 @@
-- name = "Bitcoin price"
-- description = "Current Bitcoin price (blockchain.info)"
-- type = "widget"
-- author = "Evgeny Zobnin (zobnin@gmail.com)"
-- version = "1.0"
equals = "<font color=\""..ui:get_colors().secondary_text.."\"> = </font>"
function on_alarm()
http:get("https://api.blockchain.info/ticker")
end
function on_network_result(result)
local price = ajson:get_value(result, "object object:USD string:last")
ui:show_text("1 BTC"..equals..price.." USD")
end

View File

@@ -1,25 +0,0 @@
-- name = "Calendar"
-- description = "Calendar search script"
-- author = "Evgeny Zobnin (zobnin@gmail.com)"
-- type = "search"
local events = calendar:events()
local results = {}
function on_search(str)
results = {}
buttons = {}
for _,event in pairs(events) do
if event.title:lower():find(str:lower()) ~= nil then
table.insert(results, event)
table.insert(buttons, event.title)
end
end
search:show(buttons)
end
function on_click(idx)
calendar:open_event(results[idx].id)
end

View File

@@ -1,77 +0,0 @@
-- name = "File Explorer"
-- description = "Dropbox file explorer. Shows only AIO Launcher subdirectory"
-- type = "widget"
-- version = "1.0"
-- author = "Andrey Gavrilov"
-- aio_version = "4.0.9"
local path,file,text = "","",""
local name = "home"
local paths,names,is_dirs,tab = {},{},{},{}
function on_alarm()
cloud:list_dir(path,"list")
end
function on_resume()
ui:show_lines(tab)
end
function on_cloud_result_list(res)
paths,names,is_dirs,tab = {},{},{},{}
if path == "" then
table.insert(tab,"&#x1f503 <b>"..name.."</b>")
else
table.insert(tab,"&#x2b06&#xfe0f <b>"..name.."</b>")
end
table.insert(paths,path)
table.insert(names,name)
table.insert(is_dirs,true)
if type(res) == "table" then
for i,v in ipairs(res) do
table.insert(paths,v.path)
table.insert(names,v.name)
table.insert(is_dirs,v.is_dir)
if v.is_dir then
table.insert(tab,"&#x1f4c1 "..v.name)
else
table.insert(tab,"&#x1f4c4 "..v.name)
end
end
end
ui:show_lines(tab)
end
function on_cloud_result_file(res,txt)
text = txt
ui:show_dialog(file,txt:gsub("\n","<br>"),"Cancel","Share")
end
function on_click(idx)
system:vibrate(10)
if idx == 1 then
local t = path:split("/")
path = ""
name = "home"
for i = 1,#t-1 do
path = path.."/"..t[i]
name = t[i]:gsub("/","")
end
cloud:list_dir(path,"list")
else
if is_dirs[idx] then
path = paths[idx]
name = names[idx]
cloud:list_dir(paths[idx],"list")
else
file = names[idx]
cloud:get_file(paths[idx],"file")
end
end
end
function on_dialog_action(idx)
if idx == 2 then
system:share_text(text)
end
end

View File

@@ -1,4 +1,5 @@
-- name = "Meta widget"
-- description = "Widget of widgets"
-- type = "widget"
-- author = "Andrey Gavrilov"
-- version = "1.0"

View File

@@ -1,123 +0,0 @@
-- name = "Notes"
-- description = "Notes widget"
-- type = "widget"
-- author = "Andrey Gavrilov"
-- version = "1.0"
local json = require "json"
local diag_id = ""
local id = 0
function on_alarm()
if files:read("notes") == nil then
files:write("notes",json.encode({}))
end
local notes = json.decode(files:read("notes"))
local buttons = {}
local colors = {}
for i,v in ipairs(notes) do
local utf8 = require "utf8"
local button = utf8.sub(v.text:match("^(.+)\n") or v.text,1,15)
table.insert(buttons,button)
table.insert(colors,v.color)
end
local color = ui:get_colors()
table.insert(buttons,"+")
table.insert(colors,color.secondary_text)
ui:show_buttons(buttons,colors)
end
function on_click(idx)
local notes = json.decode(files:read("notes"))
if idx > #notes then
ui:show_edit_dialog("New note")
diag_id = "new"
else
ui:show_dialog("Note", json.decode(files:read("notes"))[idx].text:replace("\n","<br>"), "Edit", "Delete")
diag_id = "read"
id = idx
end
end
function on_dialog_action(data)
if data ~= -1 then
if diag_id == "new" then
if data ~= "" then
local color = ui:get_colors()
local note = {}
note.text = data
note.color = color.button
local notes = json.decode(files:read("notes"))
table.insert(notes,note)
files:write("notes",json.encode(notes))
on_alarm()
end
elseif diag_id == "read" then
if data == 1 then
ui:show_edit_dialog("Edit","",json.decode(files:read("notes"))[id].text)
diag_id = "edit"
else
local notes = json.decode(files:read("notes"))
table.remove(notes,id)
files:write("notes",json.encode(notes))
on_alarm()
end
elseif diag_id == "edit" then
if data ~= "" then
local notes = json.decode(files:read("notes"))
notes[id].text = data
files:write("notes",json.encode(notes))
on_alarm()
end
end
end
end
function on_long_click(idx)
local notes = json.decode(files:read("notes"))
if idx > #notes then
return
end
id = idx
ui:show_context_menu({{"angle-left","Up"},{"share-alt","Share"},{"angle-right","Down"},{"circle","Default"},{"circle","Red"},{"circle","Blue"},{"circle","Green"}})
end
function on_context_menu_click(idx)
local md_color = require "md_colors"
local color = ui:get_colors()
if idx == 1 then
move(-1)
elseif idx == 2 then
system:share_text(json.decode(files:read("notes"))[id].text)
elseif idx == 3 then
move(1)
elseif idx == 4 then
update_color(color.button)
elseif idx == 5 then
update_color(md_color.red_500)
elseif idx == 6 then
update_color(md_color.blue_500)
elseif idx == 7 then
update_color(md_color.green_500)
end
end
function update_color(col)
local notes = json.decode(files:read("notes"))
notes[id].color = col
files:write("notes",json.encode(notes))
on_alarm()
end
function move(x)
local notes = json.decode(files:read("notes"))
if id+x < 1 or id+x > #notes then
return
end
local note = notes[id]
table.remove(notes,id)
table.insert(notes,id+x,note)
files:write("notes",json.encode(notes))
on_alarm()
end

View File

@@ -1,54 +0,0 @@
-- name = "News"
-- description = "Simple RSS news widget"
-- data_source = "https://rss-to-json-serverless-api.vercel.app/"
-- type = "widget"
-- author = "Andrey Gavrilov"
-- version = "1.0"
-- settings
local feed = "https://rss.nytimes.com/services/xml/rss/nyt/HomePage.xml"
local lines_num = 5
local auto_folding = false
local api_url = "https://rss-to-json-serverless-api.vercel.app/api?feedURL="
local titles = {}
local descs = {}
local urls = {}
local times = {}
local url = ""
local json = require "json"
function on_resume()
if auto_folding then
ui:set_folding_flag(true)
ui:show_lines(titles)
end
end
function on_alarm()
http:get(api_url..feed)
end
function on_network_result(result)
local t = json.decode(result)
local n = math.min(lines_num, #t.items)
for i = 1, n, 1 do
titles[i] = t.items[i].title
descs[i] = t.items[i].description
urls[i] = t.items[i].url
times[i] = os.date("%d.%m.%Y, %H:%M",t.items[i].created/1000)
end
ui:show_lines(titles)
end
function on_click(i)
url = urls[i]
ui:show_dialog(titles[i].." | "..times[i], descs[i], "open in browser")
end
function on_dialog_action(i)
if i == 1 then
system:open_browser(url)
end
end

View File

@@ -1,53 +0,0 @@
-- name = "Screen state"
-- type = "drawer"
local prefs = require "prefs"
function on_drawer_open()
if prefs.states == nil then
prefs.states = {}
end
update_screen()
end
function update_screen()
local state_names = {}
for k,v in pairs(prefs.states) do
table.insert(state_names, k)
end
table.insert(state_names, "Save new state")
drawer:show_list(state_names)
end
function on_click(idx)
if idx > #prefs.states then
save_state("State")
else
restore_state(name)
end
end
function save_state(name)
local state = aio:active_widgets()
prefs.states[name] = state
update_screen()
end
function restore_state(name)
remove_all_widgets()
for k,v in pairs(prefs.states[name]) do
aio:add_widget(v.name, v.position)
end
end
function remove_all_widgets()
local curr_state = aio:active_widgets()
for k,v in pairs(curr_state) do
aio:remove_widget(v.position)
end
end