add many new scripts

This commit is contained in:
Evgeny
2022-08-22 10:24:40 +03:00
parent a6e081c988
commit 329c7abc70
24 changed files with 617 additions and 40 deletions

View File

@@ -1,4 +1,6 @@
-- name = "Battery info" -- name = "Battery info"
-- description = "Simple battery info widget"
-- author = "Evgeny Zobnin (zobnin@gmail.com)"
ticks = -1 ticks = -1
@@ -13,7 +15,9 @@ function on_tick()
local batt_info = system:get_battery_info() local batt_info = system:get_battery_info()
local batt_strings = stringify_table(batt_info) local batt_strings = stringify_table(batt_info)
ui:show_lines(batt_strings) local folded_str = "Battery: "..batt_info.percent.."% | "..batt_info.temp.."° | "..batt_info.voltage.." mV"
ui:show_lines(batt_strings, nil, folded_str)
end end
function stringify_table(tab) function stringify_table(tab)

View File

@@ -1,3 +1,6 @@
-- name = "Dice widget"
-- description = "Roll the Dice"
-- author = "Evgeny Zobnin (zobnin@gmail.com)"
-- foldable = "false" -- foldable = "false"
local dices = { local dices = {

23
addons/facts-widget.lua Normal file
View File

@@ -0,0 +1,23 @@
-- name = "Random facts"
-- description = "Radom useless facts"
-- data_source = "https://uselessfacts.jsph.pl/"
-- type = "widget"
-- author = "Evgeny Zobnin (zobnin@gmail.com)"
-- version = "1.0"
-- foldable = "false"
function on_alarm()
http:get("https://uselessfacts.jsph.pl/random.json?language=en")
end
function on_network_result(result)
text = ajson:get_value(result, "object string:text")
ui:show_lines{ text }
end
function on_click()
if text ~= nil then
system:copy_to_clipboard(text)
end
end

View File

@@ -0,0 +1,30 @@
-- name = "Password generator"
-- description = "30-character password generator"
-- type = "search"
-- author = "Evgeny Zobnin (zobnin@gmail.com)"
local pass = ""
function on_search(str)
if str:lower():find(string.lower("password")) then
pass = gen_pass()
search:show{pass}
end
end
function gen_pass()
local chars = {'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V','W', 'X', 'Y', 'Z', 'a','b','c','d', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z', '!', '"','#','$','%','&',"'",'(',')','*','+',',','-','.','/','1','2','3','4','5','6','7','8','9','0',':',';','<','=','>','?','@','[',']','^','_','`','{','}'}
math.randomseed(os.clock()*100000000000)
pass = ""
for i=1, 30, 1 do
pass = pass..chars[math.random(1, #chars)]
end
return pass
end
function on_click()
system:copy_to_clipboard(pass)
end

View File

@@ -0,0 +1,21 @@
-- name = "What to do?"
-- description = "Let's find you something to do"
-- data_source = "https://www.boredapi.com/"
-- type = "widget"
-- author = "Evgeny Zobnin (zobnin@gmail.com)"
-- version = "1.0"
-- foldable = "false"
function on_resume()
ui:show_text("Tell me what to do?")
end
function on_click()
system:vibrate(100)
http:get("http://www.boredapi.com/api/activity/")
end
function on_network_result(result)
text = ajson:get_value(result, "object string:activity")
ui:show_text(text)
end

View File

@@ -0,0 +1,137 @@
ui:set_title("15 puzzle")
local json = require "json"
local folded = "15 puzzle"
function tab_create()
local tab_in = {"",1,2,3,4,5,6,7,8,9,10,11,12,13,14,15}
local tab_out = {}
repeat
local idx = math.random(1,#tab_in)
table.insert(tab_out,tab_in[idx])
table.remove(tab_in,idx)
until #tab_in == 0
return tab_out
end
function tab_to_tabs(tab)
local tab_in = tab
local tab_out = {}
local row = {}
for i,v in ipairs(tab_in) do
table.insert(row,v)
if #row == math.sqrt(#tab) then
table.insert(tab_out,row)
row = {}
end
end
return tab_out
end
function tabs_to_tab(tab)
local tab_in = tab
local tab_out = {}
for i,v in ipairs(tab_in) do
for ii,vv in ipairs(v) do
table.insert(tab_out,vv)
end
end
return tab_out
end
function tabs_to_desk(tab)
local t = tab
for i,v in ipairs(t) do
table.insert(v,1,"")
table.insert(v,3,"")
table.insert(v,5,"")
table.insert(v,7,"")
table.insert(v,9,"")
end
table.insert(t,1,{"","","","","","","","",""})
table.insert(t,3,{"","","","","","","","",""})
table.insert(t,5,{"","","","","","","","",""})
table.insert(t,7,{"","","","","","","","",""})
table.insert(t,9,{"","","","","","","","",""})
return t
end
function desk_to_tabs(tab)
local t = tab
table.remove(t,9)
table.remove(t,7)
table.remove(t,5)
table.remove(t,3)
table.remove(t,1)
for i,v in ipairs(t) do
table.remove(v,9)
table.remove(v,7)
table.remove(v,5)
table.remove(v,3)
table.remove(v,1)
end
return t
end
function on_alarm()
on_resume()
end
function on_resume()
if (not files:read("fifteen")) or (#json.decode(files:read("fifteen"))~=16) then
reload()
else
redraw()
end
end
function redraw()
local tab = tabs_to_desk(tab_to_tabs(json.decode(files:read("fifteen"))))
ui:show_table(tab, 0, true, folded)
end
function on_click(idx)
if idx == 0 then
ui:show_dialog("Select Action","","Cancel","Reload")
return
else
local tab = tabs_to_tab(tabs_to_desk(tab_to_tabs(json.decode(files:read("fifteen")))))
if type(tab[idx]) ~= "number" then
return
end
if tab[idx-2] == "" then
tab[idx-2] = tab[idx]
tab[idx] = ""
elseif tab[idx+2] == "" then
tab[idx+2] = tab[idx]
tab[idx] = ""
elseif (idx-18>0) and (tab[idx-18] == "") then
tab[idx-18] = tab[idx]
tab[idx] = ""
elseif (idx+18<#tab) and (tab[idx+18] == "") then
tab[idx+18] = tab[idx]
tab[idx] = ""
else
return
end
system:vibrate(10)
tab = tabs_to_tab(desk_to_tabs(tab_to_tabs(tab)))
files:write("fifteen",json.encode(tab))
redraw()
end
end
function on_settings()
end
function reload()
local tab = tab_create()
files:write("fifteen",json.encode(tab))
redraw()
end
function on_dialog_action(idx)
if idx == 2 then
reload()
end
end

View File

@@ -1,36 +0,0 @@
-- name = "GitHub Trending"
-- description = "GitHub trending repositories"
-- data_source = "trending-github.com"
-- type = "widget"
-- author = "Evgeny Zobnin (zobnin@gmail.com)"
-- version = "1.0"
function on_alarm()
http:get("https://api.trending-github.com/github/repositories")
end
function on_network_result(result)
local names = {
ajson:get_value(result, "array object:0 string:name"),
ajson:get_value(result, "array object:1 string:name"),
ajson:get_value(result, "array object:2 string:name"),
}
local descriptions = {
ajson:get_value(result, "array object:0 string:description"),
ajson:get_value(result, "array object:1 string:description"),
ajson:get_value(result, "array object:2 string:description"),
}
urls = {
ajson:get_value(result, "array object:0 string:url"),
ajson:get_value(result, "array object:1 string:url"),
ajson:get_value(result, "array object:2 string:url"),
}
ui:show_lines(names, descriptions)
end
function on_click(idx)
system:open_browser(urls[idx])
end

View File

@@ -0,0 +1,141 @@
-- name = "Автомобильные коды"
-- description = "Поиск по кодам автомобильных номеров России"
-- lang = "ru"
-- type = "search"
-- author = "Evgeny Zobnin (zobnin@gmail.com)
-- version = "1.0"
function on_search(str)
local code = str:match("^%d%d%d?$")
local region = codes[code]
if region ~= nil then
search:show{code.." - "..region}
end
end
codes = {
["01"] = "Республика Адыгея",
["02"] = "Республика Башкортостан",
["102"] = "Республика Башкортостан",
["03"] = "Республика Бурятия",
["04"] = "Республика Алтай (Горный Алтай)",
["05"] = "Республика Дагестан",
["06"] = "Республика Ингушетия",
["07"] = "Кабардино-Балкарская Республика",
["08"] = "Республика Калмыкия",
["09"] = "Республика Карачаево-Черкессия",
["10"] = "Республика Карелия",
["11"] = "Республика Коми",
["12"] = "Республика Марий Эл",
["13"] = "Республика Мордовия",
["113"] = "Республика Мордовия",
["14"] = "Республика Саха (Якутия)",
["15"] = "Республика Северная Осетия — Алания",
["16"] = "Республика Татарстан",
["116"] = "Республика Татарстан",
["17"] = "Республика Тыва",
["18"] = "Удмуртская Республика",
["19"] = "Республика Хакасия",
["21"] = "Чувашская Республика",
["121"] = "Чувашская Республика",
["22"] = "Алтайский край",
["23"] = "Краснодарский край",
["93"] = "Краснодарский край",
["123"] = "Краснодарский край",
["24"] = "Красноярский край",
["84"] = "Красноярский край",
["88"] = "Красноярский край",
["124"] = "Красноярский край",
["25"] = "Приморский край",
["125"] = "Приморский край",
["26"] = "Ставропольский край",
["27"] = "Хабаровский край",
["28"] = "Амурская область",
["29"] = "Архангельская область",
["30"] = "Астраханская область",
["31"] = "Белгородская область",
["32"] = "Брянская область",
["33"] = "Владимирская область",
["34"] = "Волгоградская область",
["134"] = "Волгоградская область",
["35"] = "Вологодская область",
["36"] = "Воронежская область",
["37"] = "Ивановская область",
["38"] = "Иркутская область",
["85"] = "Иркутская область",
["39"] = "Калининградская область",
["91"] = "Калининградская область",
["40"] = "Калужская область",
["41"] = "Камчатский край",
["42"] = "Кемеровская область",
["43"] = "Кировская область",
["44"] = "Костромская область",
["45"] = "Курганская область",
["46"] = "Курская область",
["47"] = "Ленинградская область",
["48"] = "Липецкая область",
["49"] = "Магаданская область",
["50"] = "Московская область",
["90"] = "Московская область",
["150"] = "Московская область",
["190"] = "Московская область",
["51"] = "Мурманская область",
["52"] = "Нижегородская область",
["152"] = "Нижегородская область",
["53"] = "Новгородская область",
["54"] = "Новосибирская область",
["55"] = "Омская область",
["56"] = "Оренбургская область",
["57"] = "Орловская область",
["58"] = "Пензенская область",
["59"] = "Пермский край",
["81"] = "Пермский край",
["159"] = "Пермский край",
["60"] = "Псковская область",
["61"] = "Ростовская область",
["161"] = "Ростовская область",
["62"] = "Рязанская область",
["63"] = "Самарская область",
["163"] = "Самарская область",
["64"] = "Саратовская область",
["164"] = "Саратовская область",
["65"] = "Сахалинская область",
["66"] = "Свердловская область",
["96"] = "Свердловская область",
["67"] = "Смоленская область",
["68"] = "Тамбовская область",
["69"] = "Тверская область",
["70"] = "Томская область",
["71"] = "Тульская область",
["72"] = "Тюменская область",
["73"] = "Ульяновская область",
["173"] = "Ульяновская область",
["74"] = "Челябинская область",
["174"] = "Челябинская область",
["75"] = "Забайкальский край",
["80"] = "Забайкальский край",
["76"] = "Ярославская область",
["77"] = "Москва",
["97"] = "Москва",
["99"] = "Москва",
["177"] = "Москва",
["197"] = "Москва",
["199"] = "Москва",
["777"] = "Москва",
["799"] = "Москва",
["78"] = "Санкт-Петербург",
["98"] = "Санкт-Петербург",
["178"] = "Санкт-Петербург",
["79"] = "Еврейская автономная область",
["82"] = "Республика Крым",
["83"] = "Ненецкий автономный округ",
["86"] = "Ханты-Мансийский автономный округ — Югра",
["186"] = "Ханты-Мансийский автономный округ — Югра",
["87"] = "Чукотский автономный округ",
["89"] = "Ямало-Ненецкий автономный округ",
["92"] = "Севастополь",
["94"] = "Территории, находящиеся за пределами РФ и обслуживаемые Департаментом режимных объектов МВД России",
["95"] = "Чеченская республика",
}

220
community/sudoku-widget.lua Normal file
View File

@@ -0,0 +1,220 @@
ui:set_title("Sudoku")
local json = require "json"
local folded = "Sudoku"
function tab_to_tabs(tab)
local tab_in = tab
local tab_out = {}
local row = {}
for i,v in ipairs(tab_in) do
table.insert(row,v)
if #row == 9 then
table.insert(tab_out,row)
row = {}
end
end
return tab_out
end
function tabs_to_tab(tab)
local tab_in = tab
local tab_out = {}
for i,v in ipairs(tab_in) do
for ii,vv in ipairs(v) do
table.insert(tab_out,vv)
end
end
return tab_out
end
function tabs_to_desk(tab)
local t = tab
for i,v in ipairs(t) do
table.insert(v,1,"")
table.insert(v,5,"")
table.insert(v,9,"")
table.insert(v,13,"")
end
table.insert(t,1,{"","","","","","","","","","","","",""})
table.insert(t,5,{"","","","","","","","","","","","",""})
table.insert(t,9,{"","","","","","","","","","","","",""})
table.insert(t,13,{"","","","","","","","","","","","",""})
return t
end
function desk_to_tabs(tab)
local t = tab
table.remove(t,13)
table.remove(t,9)
table.remove(t,5)
table.remove(t,1)
for i,v in ipairs(t) do
table.remove(v,13)
table.remove(v,9)
table.remove(v,5)
table.remove(v,1)
end
return t
end
function on_alarm()
on_resume()
end
function on_resume()
if (not files:read("sudoku")) or (not json.decode(files:read("sudoku")).mask) then
reload()
else
redraw()
end
end
function reload()
local sudoku = matrix_create()
files:write("sudoku",json.encode(sudoku))
redraw()
end
function validate()
local sudoku = json.decode(files:read("sudoku"))
local state = "Solved"
for i = 1, #sudoku.mask do
if (sudoku.matrix[i] ~= sudoku.mask[i]) and (sudoku.mask[i] ~= 0) then
state = "Wrong"
break
elseif sudoku.mask[i] == 0 then
state = "Unsolved"
end
end
ui:show_toast(state)
end
function solve()
local sudoku = json.decode(files:read("sudoku"))
sudoku.mask = sudoku.matrix
files:write("sudoku",json.encode(sudoku))
redraw()
end
function redraw()
local tab = tabs_to_desk(tab_to_tabs(json.decode(files:read("sudoku")).mask))
ui:show_table(tab, 0, true, folded)
end
function on_click(idx)
if idx == 0 then
dialog_id = "menu"
ui:show_radio_dialog("Select Action",{"Reload","Validate","Solve"})
return
end
x = math.ceil(idx/13)
y = idx%13
if y == 0 then y = 13 end
local tab = tabs_to_desk(tab_to_tabs(json.decode(files:read("sudoku")).mask))
if type(tab[x][y]) == "number" then
dialog_id = "number"
ui:show_radio_dialog("Select Number",{1,2,3,4,5,6,7,8,9},tab[x][y])
end
end
function on_settings()
end
function on_dialog_action(idx)
if idx == -1 then
return
end
if dialog_id == "number" then
local sudoku = json.decode(files:read("sudoku"))
local tab = tabs_to_desk(tab_to_tabs(sudoku.mask))
tab[x][y] = idx
local mask = tabs_to_tab(desk_to_tabs(tab))
sudoku.mask = mask
files:write("sudoku",json.encode(sudoku))
redraw()
elseif dialog_id == "menu" then
if idx == 1 then
reload()
elseif idx == 2 then
validate()
elseif idx == 3 then
solve()
end
end
end
function matrix_create()
local sudoku = {}
local t = {}
local m = {}
local tmp
for i = 1, 81 do
t[i] = 0
end
for i = 0, 8 do
for j = 1, 9 do
t[i * 9 + j] = (i * 3 + math.floor( i / 3 ) + ( j - 1) ) % 9 + 1
end
end
for i = 1, 42 do
local n1 = math.random( 9 )
local n2
repeat
n2 = math.random( 9 )
until n1 ~= n2
for row = 0, 8 do
for col = 1, 9 do
if t[row * 9 + col] == n1 then
t[row * 9 + col] = n2
elseif(t[row * 9 + col] == n2) then
t[row * 9 + col] = n1
end
end
end
end
for c = 1, 42 do
local s1 = math.random( 2 )
local s2 = math.random( 2 )
for row = 0, 8 do
tmp = t[row * 9 + (s1 * 3 + c % 3)]
t[row * 9 + (s1 * 3 + c % 3)] = t[row * 9 + (s2 * 3 + c % 3)]
t[row * 9 + (s2 * 3 + c % 3)] = tmp
end
end
for s = 1, 42 do
local c1 = math.random( 2 )
local c2 = math.random( 2 )
for row = 0, 8 do
tmp = t[row * 9 + (s % 3 * 3 + c1)]
t[row * 9 + (s % 3 * 3 + c1)] = t[row * 9 + (s % 3 * 3 + c2)]
t[row * 9 + (s % 3 * 3 + c2)] = tmp
end
end
for s = 1, 42 do
local r1 = math.random( 2 )
local r2 = math.random( 2 )
for col = 1, 9 do
tmp = t[(s % 3 * 3 + r1) * 9 + col]
t[(s % 3 * 3 + r1) * 9 + col] = t[(s % 3 * 3 + r2) * 9 + col]
t[(s % 3 * 3 + r2) * 9 + col] = tmp
end
end
for i = 1, 81 do
m[i] = t[i]
end
for i = 0, 2 do
for j = 1, 3 do
for k = 1, 5 do
local c
repeat
c = math.random( 9 ) - 1
until m[(i * 3 + math.floor(c / 3)) * 9 + j * 3 + c % 3] ~= 0
m[(i * 3 + math.floor(c / 3)) * 9 + j * 3 + c % 3] = 0
end
end
end
sudoku.matrix = t
sudoku.mask = m
return sudoku
end

View File

@@ -1,6 +1,6 @@
#!/bin/sh #!/bin/sh
REPOS="main ru samples community games" REPOS="main addons ru samples community"
SCRIPTS_DIR="/sdcard/Android/data/ru.execbit.aiolauncher/files/" SCRIPTS_DIR="/sdcard/Android/data/ru.execbit.aiolauncher/files/"
adb shell rm -rf $SCRIPTS_DIR/*.lua adb shell rm -rf $SCRIPTS_DIR/*.lua

26
main/calendar-search.lua Normal file
View File

@@ -0,0 +1,26 @@
-- name = "Calendar"
-- description = "Calendar search script"
-- author = "Evgeny Zobnin (zobnin@gmail.com)"
-- type = "search"
local events = calendar:get_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:show_event_dialog(results[idx].id)
calendar:open_event(results[idx].id)
end

View File

@@ -4,6 +4,7 @@
-- type = "widget" -- type = "widget"
-- author = "Evgeny Zobnin (zobnin@gmail.com)" -- author = "Evgeny Zobnin (zobnin@gmail.com)"
-- version = "1.0" -- version = "1.0"
-- foldable = "false"
function on_alarm() function on_alarm()
http:get("http://api.icndb.com/jokes/random") http:get("http://api.icndb.com/jokes/random")

View File

@@ -4,6 +4,7 @@
-- type = "widget" -- type = "widget"
-- author = "Evgeny Zobnin (zobnin@gmail.com)" -- author = "Evgeny Zobnin (zobnin@gmail.com)"
-- version = "1.0" -- version = "1.0"
-- foldable = "false"
function on_alarm() function on_alarm()
http:get("https://inspiration.goprogram.ai/") http:get("https://inspiration.goprogram.ai/")

View File

@@ -4,6 +4,7 @@
-- type = "widget" -- type = "widget"
-- author = "Evgeny Zobnin (zobnin@gmail.com)" -- author = "Evgeny Zobnin (zobnin@gmail.com)"
-- version = "1.0" -- version = "1.0"
-- foldable = "false"
function on_alarm() function on_alarm()
http:get("https://api.ipify.org") http:get("https://api.ipify.org")

View File

@@ -4,6 +4,7 @@
-- type = "widget" -- type = "widget"
-- author = "Evgeny Zobnin (zobnin@gmail.com)" -- author = "Evgeny Zobnin (zobnin@gmail.com)"
-- version = "1.0" -- version = "1.0"
-- foldable = "false"
function on_alarm() function on_alarm()
http:get("https://api.quotable.io/random") http:get("https://api.quotable.io/random")

View File

@@ -3,6 +3,7 @@
-- type = "widget" -- type = "widget"
-- author = "Evgeny Zobnin (zobnin@gmail.com)" -- author = "Evgeny Zobnin (zobnin@gmail.com)"
-- version = "1.0" -- version = "1.0"
-- foldable = "false"
current_output = "Click to enter command" current_output = "Click to enter command"

View File

@@ -3,6 +3,7 @@
-- type = "widget" -- type = "widget"
-- author = "Andrey Gavrilov" -- author = "Andrey Gavrilov"
-- version = "1.0" -- version = "1.0"
-- foldable = "false"
local dialog_id = "" local dialog_id = ""
local unit = "length" local unit = "length"

View File

@@ -4,6 +4,7 @@
-- type = "widget" -- type = "widget"
-- author = "Evgeny Zobnin (zobnin@gmail.com)" -- author = "Evgeny Zobnin (zobnin@gmail.com)"
-- version = "1.0" -- version = "1.0"
-- foldable = "false"
json = require "json" json = require "json"
url = require "url" url = require "url"

View File

@@ -3,6 +3,7 @@
-- type = "widget" -- type = "widget"
-- author = "Evgeny Zobnin (zobnin@gmail.com)" -- author = "Evgeny Zobnin (zobnin@gmail.com)"
-- version = "1.0" -- version = "1.0"
-- foldable = "false"
function on_resume() function on_resume()
local year_days = 365 local year_days = 365