add intents docs and samples
This commit is contained in:
27
README.md
27
README.md
@@ -25,7 +25,8 @@ The type of script is determined by the line (meta tag) at the beginning of the
|
|||||||
* 4.4.1 - rich text editor support;
|
* 4.4.1 - rich text editor support;
|
||||||
* 4.4.2 - added `fmt` and `html` utility modules;
|
* 4.4.2 - added `fmt` and `html` utility modules;
|
||||||
* 4.4.4 - added `tasker` module;
|
* 4.4.4 - added `tasker` module;
|
||||||
* 4.4.6 - added `csv` module.
|
* 4.4.6 - added `csv` module;
|
||||||
|
* 4.4.7 - added `intent` module and `system:send_message` function.
|
||||||
|
|
||||||
# Widget scripts
|
# Widget scripts
|
||||||
|
|
||||||
@@ -176,15 +177,33 @@ When you click on any menu item, the collback `on_context_menu_click(idx)` will
|
|||||||
* `system:get_lang()` - returns the language selected in the system;
|
* `system:get_lang()` - returns the language selected in the system;
|
||||||
* `system:get_tz_offset()` - returns TimeZone offset in seconds;
|
* `system:get_tz_offset()` - returns TimeZone offset in seconds;
|
||||||
* `system:get_battery_info()` - returns table with battery info;
|
* `system:get_battery_info()` - returns table with battery info;
|
||||||
* `system:get_system_info()` - returns table with system info.
|
* `system:get_system_info()` - returns table with system info;
|
||||||
|
* `system:send_message(value, [script_name])` - sends lua value to other script or scripts (_avaialble from: 4.4.7_).
|
||||||
|
|
||||||
The result of executing a shell command is sent to the `on_shell_result(string)` callback.
|
The result of executing a shell command is sent to the `on_shell_result(string)` callback.
|
||||||
|
|
||||||
|
To accept a value sent by the `send_message` function, the receiving script must implement a callback `on_message(value)`.
|
||||||
|
|
||||||
|
## Intens
|
||||||
|
|
||||||
|
* `intent:start_activity(table)` - starts activity with intent described in the table;
|
||||||
|
* `intent:send_broadcast(table)` - sends broadcast intent described in the table.
|
||||||
|
|
||||||
|
Intent table format (all fields are optional):
|
||||||
|
|
||||||
|
* `action` - general action to be performed;
|
||||||
|
* `category` - intent category;
|
||||||
|
* `package` - explicit application package name;
|
||||||
|
* `component` - Explicitly set the component to handle the intent;
|
||||||
|
* `type` - mime type;
|
||||||
|
* `data` - data this intent is operating on;
|
||||||
|
* `extras` - table of extra values in `key = value` format.
|
||||||
|
|
||||||
## Launcher control
|
## Launcher control
|
||||||
|
|
||||||
* `aio:do_action(string)` - performs an AIO action ([more](https://aiolauncher.app/api.html));
|
* `aio:do_action(string)` - performs an AIO action ([more](https://aiolauncher.app/api.html));
|
||||||
* `aio:add_widget(string)` - adds an embedded widget, script widget or clone of an existing widget to the screen;
|
* `aio:add_widget(string)` - adds an aio widget, script widget or clone of an existing widget to the screen;
|
||||||
* `aio:remove_widget(string)` - removes the built-in widget or script widget from the screen (note: additional widgets will also be removed);
|
* `aio:remove_widget(string)` - removes the widget from the screen (note: clones will also be removed);
|
||||||
* `aio:is_widget_added(string)` - checks if the widget is added to the screen;
|
* `aio:is_widget_added(string)` - checks if the widget is added to the screen;
|
||||||
|
|
||||||
## Application management
|
## Application management
|
||||||
|
|||||||
44
samples/intent-sample.lua
Normal file
44
samples/intent-sample.lua
Normal file
@@ -0,0 +1,44 @@
|
|||||||
|
function on_resume()
|
||||||
|
ui:show_lines{
|
||||||
|
"open browser",
|
||||||
|
"open market",
|
||||||
|
"open google feed",
|
||||||
|
"open player",
|
||||||
|
"send broadcast to launcher (open apps menu)",
|
||||||
|
}
|
||||||
|
end
|
||||||
|
|
||||||
|
function on_click(idx)
|
||||||
|
if idx == 1 then
|
||||||
|
intent:start_activity{
|
||||||
|
action = "android.intent.action.VIEW",
|
||||||
|
data = "https://aiolauncher.app",
|
||||||
|
}
|
||||||
|
elseif idx == 2 then
|
||||||
|
intent:start_activity{
|
||||||
|
action = "android.intent.action.MAIN",
|
||||||
|
category = "android.intent.category.APP_MARKET",
|
||||||
|
}
|
||||||
|
elseif idx == 3 then
|
||||||
|
intent:start_activity{
|
||||||
|
action = "com.google.android.googlequicksearchbox.GOOGLE_SEARCH",
|
||||||
|
extras = {
|
||||||
|
query = "AIO Launcher",
|
||||||
|
},
|
||||||
|
}
|
||||||
|
elseif idx == 4 then
|
||||||
|
intent:start_activity{
|
||||||
|
action = "android.intent.action.VIEW",
|
||||||
|
category = "android.intent.category.DEFAULT",
|
||||||
|
data = "file:///system/product/media/audio/ringtones/Atria.ogg",
|
||||||
|
type = "audio/ogg",
|
||||||
|
}
|
||||||
|
else
|
||||||
|
intent:send_broadcast{
|
||||||
|
action = "ru.execbit.aiolauncher.COMMAND",
|
||||||
|
extras = {
|
||||||
|
cmd = "apps_menu",
|
||||||
|
},
|
||||||
|
}
|
||||||
|
end
|
||||||
|
end
|
||||||
11
samples/msg-receiver.lua
Normal file
11
samples/msg-receiver.lua
Normal file
@@ -0,0 +1,11 @@
|
|||||||
|
function on_resume()
|
||||||
|
ui:show_text("empty")
|
||||||
|
end
|
||||||
|
|
||||||
|
function on_message(value)
|
||||||
|
if type(value) == "table" then
|
||||||
|
ui:show_text("table first element: "..value[1])
|
||||||
|
else
|
||||||
|
ui:show_text(value)
|
||||||
|
end
|
||||||
|
end
|
||||||
17
samples/msg-sender.lua
Normal file
17
samples/msg-sender.lua
Normal file
@@ -0,0 +1,17 @@
|
|||||||
|
function on_resume()
|
||||||
|
ui:show_lines{
|
||||||
|
"send text",
|
||||||
|
"send 123",
|
||||||
|
"send table",
|
||||||
|
}
|
||||||
|
end
|
||||||
|
|
||||||
|
function on_click(idx)
|
||||||
|
if idx == 1 then
|
||||||
|
system:send_message("text", "msg-receiver.lua")
|
||||||
|
elseif idx == 2 then
|
||||||
|
system:send_message(1)
|
||||||
|
else
|
||||||
|
system:send_message{ "one", "two", "three" }
|
||||||
|
end
|
||||||
|
end
|
||||||
26
samples/shttp-text.lua
Normal file
26
samples/shttp-text.lua
Normal file
@@ -0,0 +1,26 @@
|
|||||||
|
-- name = "Chuck Norris jokes (experimental)"
|
||||||
|
-- description = "icndb.com"
|
||||||
|
-- data_source = "icndb.com"
|
||||||
|
-- type = "widget"
|
||||||
|
-- author = "Evgeny Zobnin (zobnin@gmail.com)"
|
||||||
|
-- version = "1.0"
|
||||||
|
|
||||||
|
function on_alarm()
|
||||||
|
local response = shttp:get("http://api.icndb.com/jokes/random")
|
||||||
|
|
||||||
|
if response.error ~= nil then
|
||||||
|
ui:show_text(response.error)
|
||||||
|
return
|
||||||
|
end
|
||||||
|
|
||||||
|
if response.code >= 200 and response.code < 300 then
|
||||||
|
joke = ajson:get_value(response.body, "object object:value string:joke")
|
||||||
|
ui:show_text(joke)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
function on_click()
|
||||||
|
if joke ~= nil then
|
||||||
|
system:copy_to_clipboard(joke)
|
||||||
|
end
|
||||||
|
end
|
||||||
Reference in New Issue
Block a user