Update Google search and Quick actions scripts
This commit is contained in:
@@ -2,38 +2,96 @@
|
|||||||
-- description = "AIO wrapper for the Google search app widget"
|
-- description = "AIO wrapper for the Google search app widget"
|
||||||
-- type = "widget"
|
-- type = "widget"
|
||||||
-- author = "Theodor Galanis"
|
-- author = "Theodor Galanis"
|
||||||
-- version = "1.01"
|
-- version = "2.0"
|
||||||
-- foldable = "false"
|
-- foldable = "false"
|
||||||
-- uses_app: "com.google.android.googlequicksearchbox""
|
-- uses_app: "com.google.android.googlequicksearchbox"
|
||||||
|
|
||||||
local prefs = require "prefs"
|
local prefs = require "prefs"
|
||||||
prefs._name = "google"
|
|
||||||
|
|
||||||
local buttons_labels = {" G ", "fa:magnifying-glass", "fa:microphone", "fa:camera"}
|
|
||||||
local buttons_targets = {"image_7", "image_4", "image_9", "image_10"}
|
|
||||||
local w_bridge = nil
|
local w_bridge = nil
|
||||||
|
local gravs = {}
|
||||||
|
local indices = {}
|
||||||
|
|
||||||
function on_resume()
|
function on_alarm()
|
||||||
if not widgets:bound(prefs.wid) then
|
if not widgets:bound(prefs.wid) then
|
||||||
setup_app_widget()
|
setup_app_widget()
|
||||||
end
|
end
|
||||||
|
if not prefs.mode then
|
||||||
|
prefs.mode = 1
|
||||||
|
end
|
||||||
|
mode = prefs.mode
|
||||||
|
gravs = {"left", "right"}
|
||||||
|
indices = {1, 3, 5, 7}
|
||||||
|
if mode == 2 then
|
||||||
|
gravs= reverse(gravs)
|
||||||
|
indices = reverse(indices)
|
||||||
|
end
|
||||||
widgets:request_updates(prefs.wid)
|
widgets:request_updates(prefs.wid)
|
||||||
end
|
end
|
||||||
|
|
||||||
function on_app_widget_updated(bridge)
|
function on_app_widget_updated(bridge)
|
||||||
w_bridge = bridge
|
w_bridge = bridge
|
||||||
ui:show_buttons(buttons_labels)
|
local tab = {
|
||||||
|
{"button", " %%fa:magnifying-glass%% ", {gravity = gravs[1]}},
|
||||||
|
{"spacer", 2},
|
||||||
|
{"button", " %%fa:asterisk%% ", {gravity = gravs[2]}},
|
||||||
|
{"spacer", 2},
|
||||||
|
{"button", " %%fa:microphone%% "},
|
||||||
|
{"spacer", 2},
|
||||||
|
{"button", " %%fa:camera%% "}
|
||||||
|
}
|
||||||
|
|
||||||
|
if mode==1 then
|
||||||
|
my_gui = gui(tab)
|
||||||
|
else
|
||||||
|
my_gui =gui(reverse(tab))
|
||||||
|
end
|
||||||
|
|
||||||
|
my_gui.render()
|
||||||
end
|
end
|
||||||
|
|
||||||
function on_click(idx)
|
function on_click(idx)
|
||||||
w_bridge:click(buttons_targets[idx])
|
if idx == indices[1] then
|
||||||
|
w_bridge:click("image_4")
|
||||||
|
elseif idx == indices[2] then
|
||||||
|
w_bridge:click("image_7")
|
||||||
|
elseif idx == indices[3] then
|
||||||
|
w_bridge:click("image_9")
|
||||||
|
elseif idx == indices[4] then
|
||||||
|
w_bridge:click("image_10")
|
||||||
|
else return
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
function on_settings()
|
||||||
|
local tab = {"Left-handed mode", "Right-handed mode"}
|
||||||
|
ui:show_radio_dialog("Select mode", tab, mode)
|
||||||
|
end
|
||||||
|
|
||||||
|
function on_long_click(idx)
|
||||||
|
if idx == indices[1] then
|
||||||
|
ui:show_toast("Google search")
|
||||||
|
elseif idx == indices[2] then
|
||||||
|
ui:show_toast("Google discover")
|
||||||
|
elseif idx == indices[3] then
|
||||||
|
ui:show_toast("Google voice search")
|
||||||
|
elseif idx == indices[4] then
|
||||||
|
ui:show_toast("Google Lens")
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
function on_dialog_action(data)
|
||||||
|
if data == -1 then
|
||||||
|
return
|
||||||
|
end
|
||||||
|
prefs.mode = data
|
||||||
|
on_alarm()
|
||||||
end
|
end
|
||||||
|
|
||||||
function setup_app_widget()
|
function setup_app_widget()
|
||||||
local id = widgets:setup("com.google.android.googlequicksearchbox/com.google.android.googlequicksearchbox.SearchWidgetProvider")
|
local id = widgets:setup("com.google.android.googlequicksearchbox/com.google.android.googlequicksearchbox.SearchWidgetProvider")
|
||||||
|
|
||||||
if (id ~= nil) then
|
if (id ~= nil) then
|
||||||
prefs.wid = id
|
prefs.wid = id
|
||||||
else
|
else
|
||||||
ui:show_text("Can't add widget")
|
ui:show_text("Can't add widget")
|
||||||
|
|||||||
@@ -1,44 +1,49 @@
|
|||||||
-- name = "Quick Actions"
|
-- name = "Quick Actions"
|
||||||
-- type = "widget"
|
-- type = "widget"
|
||||||
-- description = "Launcher selected actions widget"
|
-- description = "Launcher selected actions widget - long click button for options, open widget settings for list of buttons"
|
||||||
-- arguments_help = "Long click button for options, open widget settings for list of buttons"
|
|
||||||
--foldable = "true"
|
--foldable = "true"
|
||||||
-- author = "Theodor Galanis"
|
-- author = "Theodor Galanis"
|
||||||
-- version = "2.5"
|
-- version = "3.0"
|
||||||
|
|
||||||
md_colors = require "md_colors"
|
prefs = require "prefs"
|
||||||
|
prefs._name = "quickactions"
|
||||||
|
|
||||||
local icons = { "fa:pen", "fa:edit", "fa:indent", "fa:bars", "fa:sliders-h", "fa:redo", "fa:power-off", "fa:bring-forward", "fa:eraser", "fa:tools", "fa:layer-minus", "fa:layer-group", "fa:user-shield", "fa:lock", "fa:chevron-down", "fa:chevron-up", "fa:notes-medical", "fa:circle-dot", "fa:envelope", "fa:square-full", "fa:microphone", "fa:hand", "fa:search"}
|
local actions = { "quick_menu", "settings", "apps_menu", "ui_settings", "headers", "quick_apps_menu", "refresh", "restart", "notify", "clear_notifications", "quick_settings", "show_recents", "private_mode", "screen_off", "fold", "unfold", "scroll_down", "scroll_up", "add_note", "add_task", "add_purchase", "shortcuts", "send_mail", "voice", "one_handed", "right_handed", "camera", "flashlight", "dialer", "search"}
|
||||||
|
|
||||||
local names = {"Quick menu", "Quick apps menu", "Applications menu", "Toggle headers", "Settings", "Screen refresh", "Restart AIO launcher", "Notifications panel", "Clear notifications", "Quick settings", "Fold all widgets", "Unfold all widgets", "Private mode", "Screen off", "Scroll down", "Scroll up", "Add note", "Start audio recording", "Send mail", "Recent apps", "Voice command", "One-handed mode", "Search"}
|
local icons = { "fa:ellipsis-vertical", "fa:sliders-h", "fa:indent", "fa:paintbrush", "fa:bars", "fa:share-from-square", "fa:redo", "fa:power-off", "fa:bring-forward", "fa:eraser", "fa:square-ellipsis", "fa:square-full", "fa:user-shield", "fa:lock", "fa:layer-minus", "fa:layer-group", "fa:chevron-down", "fa:chevron-up", "fa:notes-medical", "fa:list-check", "fa:tag", "fa:share", "fa:envelope", "fa:microphone", "fa:hand", "fa:right-to-bracket", "fa:camera", "fa:brightness", "fa:phone", "fa:search"}
|
||||||
|
|
||||||
local colors = { md_colors.purple_800, md_colors.purple_600, md_colors.amber_900, md_colors.orange_900, md_colors.blue_900, md_colors.deep_purple_800, md_colors.grey_600, md_colors.green_900, md_colors.green_900, md_colors.blue_800, md_colors.pink_300, md_colors.pink_A200, md_colors.green_600, md_colors.grey_800, md_colors.teal_700, md_colors.teal_800, md_colors.orange_700, md_colors.red_800, md_colors.red_900, md_colors.deep_purple_700, md_colors.blue_700, md_colors.amber_800, md_colors.blue_grey_700}
|
local cols = { "#6A1B9A", "#4527A0", "#8E24AA", "#FF6F00", "#E65100", "#0D47A1", "#546E7A", "#1B5E20", "#689F38", "#1565C0", "#F06292", "#0073DD", "#00796B", "#424242", "#3F51B5", "#3F51B5", "#AB47BC", "#AB47BC", "#D81B60", "#F57C00", "#9E9D24", "#00838F", "#B71C1C", "#512DA8", "#795548", "#5C6BC0", "#FF5252", "#FF8F00", "#B388FF", "#37474F"}
|
||||||
|
|
||||||
local actions = { "quick_menu", "quick_apps_menu", "apps_menu", "headers", "settings", "refresh", "restart", "notify", "clear_notifications", "quick_settings", "fold", "unfold", "private_mode", "screen_off", "scroll_down", "scroll_up", "add_note", "start_record", "send_mail", "show_recents", "voice", "one_handed", "search"}
|
|
||||||
|
|
||||||
local pos = 0
|
local pos = 0
|
||||||
|
local buttons,colors = {},{}
|
||||||
|
|
||||||
function on_resume()
|
function on_alarm()
|
||||||
if next(settings:get()) == nil then
|
args = get_args()
|
||||||
set_default_args()
|
if not prefs.args then
|
||||||
end
|
prefs.args = args.action
|
||||||
local buttons,colors = get_buttons()
|
end
|
||||||
ui:show_buttons(buttons, colors)
|
indexes = get_indexes(prefs.args, args.action)
|
||||||
|
ui:show_buttons(get_buttons())
|
||||||
end
|
end
|
||||||
|
|
||||||
function on_click(idx)
|
function on_click(idx)
|
||||||
pos = idx
|
if idx > #prefs.args then
|
||||||
redraw()
|
on_settings()
|
||||||
|
return
|
||||||
|
end
|
||||||
|
local action = prefs.args[idx]
|
||||||
|
aio:do_action(action)
|
||||||
|
on_alarm()
|
||||||
end
|
end
|
||||||
|
|
||||||
function on_long_click(idx)
|
function on_long_click(idx)
|
||||||
pos = idx
|
local label = ""
|
||||||
local tab = settings:get()
|
pos = idx
|
||||||
label = get_label(actions[get_checkbox_idx()[idx]])
|
if idx > #prefs.args then
|
||||||
if label == nil then
|
return
|
||||||
label = names[get_checkbox_idx()[idx]]
|
end
|
||||||
end
|
label = get_label(args.action[indexes[idx]])
|
||||||
ui:show_context_menu({{"angle-left",""},{"ban",""},{"angle-right",""},{icons[get_checkbox_idx()[idx]]:gsub("fa:",""),label}})
|
ui:show_context_menu({{"angle-left",""},{"ban",""},{"angle-right",""},{args.icon[indexes[idx]]:gsub("fa:",""),label}})
|
||||||
end
|
end
|
||||||
|
|
||||||
function on_context_menu_click(menu_idx)
|
function on_context_menu_click(menu_idx)
|
||||||
@@ -48,96 +53,92 @@ function on_context_menu_click(menu_idx)
|
|||||||
remove()
|
remove()
|
||||||
elseif menu_idx == 3 then
|
elseif menu_idx == 3 then
|
||||||
move(1)
|
move(1)
|
||||||
elseif menu_idx == 4 then
|
|
||||||
redraw()
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
function on_dialog_action(data)
|
function on_dialog_action(data)
|
||||||
if data == -1 then
|
if data == -1 then
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
settings:set(data)
|
local tab = {}
|
||||||
on_resume()
|
for i,v in ipairs(data) do
|
||||||
|
tab[i] = args.action[v]
|
||||||
|
end
|
||||||
|
prefs.args = tab
|
||||||
|
on_alarm()
|
||||||
end
|
end
|
||||||
|
|
||||||
function on_settings()
|
function on_settings()
|
||||||
axions = aio:actions()
|
local labels = {}
|
||||||
lab = {}
|
for i = 1, #icons do
|
||||||
for i = 1, #axions do
|
table.insert(labels, get_label(args.action[i]))
|
||||||
lav = get_label(actions[i])
|
end
|
||||||
if lav == nil then
|
ui:show_checkbox_dialog("Select actions", labels, indexes)
|
||||||
table.insert(lab,names[i])
|
|
||||||
else
|
|
||||||
table.insert(lab, lav)
|
|
||||||
end
|
|
||||||
end
|
|
||||||
ui:show_checkbox_dialog("Select actions", lab, get_checkbox_idx())
|
|
||||||
end
|
end
|
||||||
|
|
||||||
--utilities--
|
--utilities--
|
||||||
|
|
||||||
function redraw()
|
|
||||||
local buttons,colors = get_buttons()
|
|
||||||
local checkbox_idx = get_checkbox_idx()
|
|
||||||
local action = actions[checkbox_idx[pos]]
|
|
||||||
aio:do_action(action)
|
|
||||||
ui:show_buttons(buttons, colors)
|
|
||||||
end
|
|
||||||
|
|
||||||
function set_default_args()
|
|
||||||
local args = {}
|
|
||||||
for i = 1, #actions do
|
|
||||||
table.insert(args, i)
|
|
||||||
end
|
|
||||||
settings:set(args)
|
|
||||||
end
|
|
||||||
|
|
||||||
function get_checkbox_idx()
|
|
||||||
local tab = settings:get()
|
|
||||||
for i = 1, #tab do
|
|
||||||
tab[i] = tonumber(tab[i])
|
|
||||||
end
|
|
||||||
return tab
|
|
||||||
end
|
|
||||||
|
|
||||||
function get_buttons()
|
|
||||||
local buttons,bcolors = {},{}
|
|
||||||
local checkbox_idx = get_checkbox_idx()
|
|
||||||
for i = 1, #checkbox_idx do
|
|
||||||
table.insert(buttons, icons[checkbox_idx[i]])
|
|
||||||
table.insert(bcolors, colors[checkbox_idx[i]])
|
|
||||||
end
|
|
||||||
return buttons,bcolors
|
|
||||||
end
|
|
||||||
|
|
||||||
function move(x)
|
function move(x)
|
||||||
local tab = settings:get()
|
local tab = prefs.args
|
||||||
if (pos == 1 and x < 0) or (pos == #tab and x > 0) then
|
if (pos*x == -1) or (pos*x == #tab) then
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
local cur = tab[pos]
|
local cur = tab[pos]
|
||||||
local prev = tab[pos+x]
|
tab[pos] = tab[pos+x]
|
||||||
tab[pos+x] = cur
|
tab[pos+x] = cur
|
||||||
tab[pos] = prev
|
prefs.args = tab
|
||||||
settings:set(tab)
|
on_alarm()
|
||||||
local buttons,colors = get_buttons()
|
|
||||||
ui:show_buttons(buttons, colors)
|
|
||||||
end
|
end
|
||||||
|
|
||||||
function remove()
|
function remove()
|
||||||
local tab = settings:get()
|
local tab = prefs.args
|
||||||
table.remove(tab,pos)
|
table.remove(tab,pos)
|
||||||
settings:set(tab)
|
prefs.args = tab
|
||||||
local buttons,colors = get_buttons()
|
on_alarm()
|
||||||
ui:show_buttons(buttons, colors)
|
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
function get_label(name)
|
function get_label(name)
|
||||||
axions = aio:actions()
|
local lab=""
|
||||||
for _, action in ipairs(axions) do
|
local axions = aio:actions()
|
||||||
if action["name"] == name then
|
if name == "clear_notifications" then
|
||||||
return action["label"]
|
lab = aio:res_string("clear_notifications","Clear notifications")
|
||||||
|
else for _, action in ipairs(axions) do
|
||||||
|
if action["name"] == name then
|
||||||
|
lab = action["label"]
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
return lab
|
||||||
|
end
|
||||||
|
|
||||||
|
function get_args()
|
||||||
|
local tab = {}
|
||||||
|
tab.action = actions
|
||||||
|
tab.icon = icons
|
||||||
|
tab.color = cols
|
||||||
|
return tab
|
||||||
|
end
|
||||||
|
|
||||||
|
function get_buttons()
|
||||||
|
buttons,colors = {},{}
|
||||||
|
for i,v in ipairs(indexes) do
|
||||||
|
table.insert(buttons, args.icon[v])
|
||||||
|
table.insert(colors, args.color[v])
|
||||||
|
end
|
||||||
|
return buttons,colors
|
||||||
|
end
|
||||||
|
|
||||||
|
|
||||||
|
function get_indexes(tab1,tab2)
|
||||||
|
local tab = {}
|
||||||
|
for i1,v1 in ipairs(tab1) do
|
||||||
|
for i2,v2 in ipairs(tab2) do
|
||||||
|
if v1 == v2 then
|
||||||
|
tab[i1] = i2
|
||||||
|
break
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
return tab
|
||||||
end
|
end
|
||||||
Reference in New Issue
Block a user