add get_colors function
This commit is contained in:
@@ -25,9 +25,8 @@ For most network scripts `on_alarm()` should be used.
|
||||
* `ui:show_toast(string)` - shows informational message in Android style;
|
||||
* `ui:get_default_title()` - returns the standard widget title (set in the `name` metadata);
|
||||
* `ui:set_title()` - changes the title of the widget, should be called before the data display function (empty line - reset to the standard title);
|
||||
* `ui:get_primary_text_color()` - returns the color of the theme text in #XXXXXX format;
|
||||
* `ui:get_secondary_text_color()` - returns the secondary text color (usually gray) in #XXXXXX format;
|
||||
* `ui:set_folding_flag(boolean)` - sets or clears the flag of the folded mode of the widget, the function should be called before the data display functions;
|
||||
* `ui:get_colors()` - returns table with current theme colors;
|
||||
|
||||
When you click on any element of the interface, the `on_click(number)` callback will be executed, where number is the ordinal number of the element. A long click calls `on_long_click(number)`. For example, if you use `ui:show_buttons` to show three buttons, then clicking the first button will call `on_click` with argument 1, the second with arguments 2, and so on. If there is only one element on the screen, the argument will always be equal to one and can be omitted.
|
||||
|
||||
|
||||
@@ -25,9 +25,8 @@
|
||||
* `ui:show_toast(string)` - показывает информационное сообщение в стиле Android;
|
||||
* `ui:get_default_title()` - возвращает стандартный заголовок виджета (задается в метаданных `name`);
|
||||
* `ui:set_title()` - изменяет заголовок виджета, функцию следует вызывать до функции отображения данных (пустая строка - сброс до стандартного заголовка);
|
||||
* `ui:get_primary_text_color()` - возвращает цвет текста темы в формате #XXXXXX;
|
||||
* `ui:get_secondary_text_color()` - возвращает цвет вторичного текста (обычно серый) в формате #XXXXXX;
|
||||
* `ui:set_folding_flag(boolean)` - устанавливает или снимает флаг свернутого режима виджета, функцию следует вызывать до функций отображения данных;
|
||||
* `ui:get_colors()` - возвращает таблицу текущих цветов темы;
|
||||
|
||||
При нажатии на любой элемент интерфейса будет выполнен колбек `on_click(number)`, где number - это порядковый номер элемента. Долгое нажатие вызывает `on_long_click(number)`. Например, если вы используете `ui:show_buttons` для показа трех кнопок, то при нажатии первой кнопки будет вызван `on_click` с аргументом 1, второй - с аргументов 2, и так далее. Если элемент на экране всего один - аргумент всегда будет равен единице и его можно будет опустить.
|
||||
|
||||
|
||||
@@ -4,10 +4,10 @@
|
||||
-- author = "Evgeny Zobnin (zobnin@gmail.com)"
|
||||
-- version = "1.0"
|
||||
|
||||
equals = "<font color=\""..ui:get_secondary_text_color().."\"> = </font>"
|
||||
equals = "<font color=\""..ui:get_color().secondary_text.."\"> = </font>"
|
||||
|
||||
function on_alarm()
|
||||
http:get("https://api.blockchain.info/ticker")
|
||||
http:get("https://api.blockchain.info/ticker")
|
||||
end
|
||||
|
||||
function on_network_result(result)
|
||||
|
||||
@@ -8,7 +8,7 @@
|
||||
|
||||
local json = require "json"
|
||||
local color = require "md_colors"
|
||||
local text_color = ui:get_secondary_text_color()
|
||||
local text_color = ui:get_colors().secondary_text
|
||||
local equals = "<font color=\""..text_color.."\"> = </font>"
|
||||
|
||||
-- константы --
|
||||
|
||||
@@ -8,13 +8,13 @@
|
||||
local joke = ""
|
||||
local txt = ""
|
||||
|
||||
function urlencode(str)
|
||||
if (str) then
|
||||
function urlencode(str)
|
||||
if (str) then
|
||||
str = string.gsub(str, "\n", "\r\n")
|
||||
str = string.gsub(str, "([^%w _ %- . ~])", function (c) return string.format ("%%%02X", string.byte(c)) end)
|
||||
str = string.gsub(str, " ", "+")
|
||||
end
|
||||
return str
|
||||
str = string.gsub(str, " ", "+")
|
||||
end
|
||||
return str
|
||||
end
|
||||
|
||||
function urldecode(str)
|
||||
@@ -24,12 +24,12 @@ function urldecode(str)
|
||||
end
|
||||
|
||||
function on_alarm()
|
||||
http:get("http://api.icndb.com/jokes/random")
|
||||
http:get("http://api.icndb.com/jokes/random")
|
||||
end
|
||||
|
||||
function on_network_result(result)
|
||||
local first_letter = string.sub(result, 1, 1)
|
||||
local textColor = ui:get_secondary_text_color()
|
||||
local textColor = ui:get_colors().secondary_text
|
||||
|
||||
joke = ajson:get_value(result, "object object:value string:joke")
|
||||
local id = ajson:get_value(result, "object object:value string:id")
|
||||
|
||||
@@ -5,7 +5,7 @@
|
||||
-- author = "Evgeny Zobnin (zobnin@gmail.com)"
|
||||
-- version = "1.0"
|
||||
|
||||
equals = "<font color=\""..ui:get_secondary_text_color().."\"> = </font>"
|
||||
equals = "<font color=\""..ui:get_colors().secondary_text.."\"> = </font>"
|
||||
|
||||
function on_alarm()
|
||||
http:get("https://api.covid19api.com/summary")
|
||||
@@ -16,7 +16,7 @@ function on_network_result(result)
|
||||
local total = ajson:get_value(result, "object object:Global int:TotalConfirmed")
|
||||
local newDeaths = ajson:get_value(result, "object object:Global int:NewDeaths")
|
||||
local totalDeaths = ajson:get_value(result, "object object:Global int:TotalDeaths")
|
||||
|
||||
|
||||
ui:show_lines({
|
||||
"<b>Disease</b> | total"..equals..comma_value(total).." | new"..equals..comma_value(new),
|
||||
"<b>Deaths</b> | total"..equals..comma_value(totalDeaths).." | new"..equals..comma_value(newDeaths)
|
||||
|
||||
@@ -12,7 +12,7 @@ json = require "json"
|
||||
-- constants
|
||||
local red_color = "#f44336"
|
||||
local green_color = "#48ad47"
|
||||
local text_color = ui:get_secondary_text_color()
|
||||
local text_color = ui:get_colors().secondary_text
|
||||
local equals = "<font color=\""..text_color.."\"> = </font>"
|
||||
|
||||
-- global vars
|
||||
|
||||
@@ -14,8 +14,8 @@ local tab = {}
|
||||
local line = ""
|
||||
local text = ""
|
||||
|
||||
local pr_text_color = ui:get_primary_text_color()
|
||||
local sec_text_color = ui:get_secondary_text_color()
|
||||
local pr_text_color = ui:get_colors().primary_text
|
||||
local sec_text_color = ui:get_colors().secondary_text
|
||||
local year = os.date("*t").year
|
||||
local month = os.date("*t").month
|
||||
local day = os.date("*t").day
|
||||
@@ -206,7 +206,7 @@ function format_day(d,k)
|
||||
end
|
||||
return dd
|
||||
end
|
||||
|
||||
|
||||
function check_date(date)
|
||||
local m, Y = date:match("(%d+).(%d+)")
|
||||
local time = os.time{day=1, month=m or 0, year=Y or 0}
|
||||
|
||||
17
samples/colors-sample.lua
Normal file
17
samples/colors-sample.lua
Normal file
@@ -0,0 +1,17 @@
|
||||
function on_resume()
|
||||
local colors = ui:get_colors()
|
||||
local colors_strings = stringify_table(colors)
|
||||
|
||||
ui:show_lines(colors_strings)
|
||||
end
|
||||
|
||||
function stringify_table(tab)
|
||||
local new_tab = {}
|
||||
|
||||
for k,v in pairs(tab) do
|
||||
table.insert(new_tab, k..": "..tostring(v))
|
||||
end
|
||||
|
||||
return new_tab
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user