@ -1 +1 @@
|
||||
Subproject commit b1eb0b5bc1e6f49536bce550e93342155494d78d
|
||||
Subproject commit f52fbec914e54ac24be68161951788e9fb12253c
|
@ -0,0 +1,52 @@
|
||||
local dump = require("dump")
|
||||
|
||||
local LuaSettings = {}
|
||||
|
||||
function LuaSettings:open(file_path)
|
||||
local new = {file=file_path}
|
||||
local ok, stored
|
||||
|
||||
ok, stored = pcall(dofile, new.file)
|
||||
if ok and stored then
|
||||
new.data = stored
|
||||
else
|
||||
new.data = {}
|
||||
end
|
||||
|
||||
return setmetatable(new, {__index = LuaSettings})
|
||||
end
|
||||
|
||||
function LuaSettings:readSetting(key)
|
||||
return self.data[key]
|
||||
end
|
||||
|
||||
function LuaSettings:saveSetting(key, value)
|
||||
self.data[key] = value
|
||||
end
|
||||
|
||||
function LuaSettings:delSetting(key)
|
||||
self.data[key] = nil
|
||||
end
|
||||
|
||||
function LuaSettings:flush()
|
||||
local f_out = io.open(self.file, "w")
|
||||
if f_out ~= nil then
|
||||
os.setlocale('C', 'numeric')
|
||||
f_out:write("-- we can read Lua syntax here!\nreturn ")
|
||||
f_out:write(dump(self.data))
|
||||
f_out:write("\n")
|
||||
f_out:close()
|
||||
end
|
||||
end
|
||||
|
||||
function LuaSettings:close()
|
||||
self:flush()
|
||||
end
|
||||
|
||||
function LuaSettings:purge()
|
||||
if self.file then
|
||||
os.remove(self.file)
|
||||
end
|
||||
end
|
||||
|
||||
return LuaSettings
|
@ -0,0 +1,113 @@
|
||||
local UIManager = require("ui/uimanager")
|
||||
local WpaClient = require('lj-wpaclient/wpaclient')
|
||||
local InfoMessage = require("ui/widget/infomessage")
|
||||
local sleep = require("ffi/util").sleep
|
||||
local _ = require("gettext")
|
||||
|
||||
local WpaSupplicant = {}
|
||||
|
||||
function WpaSupplicant:getNetworkList()
|
||||
local wcli, _ = WpaClient.new(self.wpa_supplicant.ctrl_interface)
|
||||
local list = wcli:scanThenGetResults()
|
||||
wcli:close()
|
||||
|
||||
local saved_networks = self:getAllSavedNetworks()
|
||||
local curr_network = self:getCurrentNetwork()
|
||||
|
||||
for _,network in ipairs(list) do
|
||||
network.signal_quality = network:getSignalQuality()
|
||||
local saved_nw = saved_networks:readSetting(network.ssid)
|
||||
if saved_nw and saved_nw.flags == network.flags then
|
||||
network.password = saved_nw.password
|
||||
end
|
||||
-- TODO: also verify bssid if it is not set to any
|
||||
if curr_network and curr_network.ssid == network.ssid then
|
||||
network.connected = true
|
||||
network.wpa_supplicant_id = curr_network.id
|
||||
end
|
||||
end
|
||||
return list
|
||||
end
|
||||
|
||||
function WpaSupplicant:authenticateNetwork(network)
|
||||
-- TODO: support passwordless network
|
||||
local err, wcli, nw_id
|
||||
wcli, err = WpaClient.new(self.wpa_supplicant.ctrl_interface)
|
||||
|
||||
if not wcli then
|
||||
return false, _("Failed to initialize network control client: ")..err
|
||||
end
|
||||
|
||||
nw_id, err = wcli:addNetwork()
|
||||
if err then return false, err end
|
||||
|
||||
wcli:setNetwork(nw_id, "ssid", network.ssid)
|
||||
wcli:setNetwork(nw_id, "psk", network.password)
|
||||
wcli:enableNetworkByID(nw_id)
|
||||
|
||||
wcli:attach()
|
||||
local cnt = 0
|
||||
local failure_cnt = 0
|
||||
local max_retry = 30
|
||||
local info = InfoMessage:new{text = _("Authenticating…")}
|
||||
local re, msg
|
||||
UIManager:show(info)
|
||||
UIManager:forceRePaint()
|
||||
while cnt < max_retry do
|
||||
local ev = wcli:readEvent()
|
||||
if ev ~= nil then
|
||||
if not ev:isScanEvent() then
|
||||
UIManager:close(info)
|
||||
info = InfoMessage:new{text = ev.msg}
|
||||
UIManager:show(info)
|
||||
UIManager:forceRePaint()
|
||||
end
|
||||
if ev:isAuthSuccessful() then
|
||||
network.wpa_supplicant_id = nw_id
|
||||
re = true
|
||||
break
|
||||
elseif ev:isAuthFailed() then
|
||||
failure_cnt = failure_cnt + 1
|
||||
if failure_cnt > 3 then
|
||||
re, msg = false, _('Failed to authenticate')
|
||||
break
|
||||
end
|
||||
end
|
||||
else
|
||||
sleep(1)
|
||||
cnt = cnt + 1
|
||||
end
|
||||
end
|
||||
if re ~= true then wcli:removeNetwork(nw_id) end
|
||||
wcli:close()
|
||||
UIManager:close(info)
|
||||
UIManager:forceRePaint()
|
||||
if cnt >= max_retry then
|
||||
re, msg = false, _('Timed out')
|
||||
end
|
||||
return re, msg
|
||||
end
|
||||
|
||||
function WpaSupplicant:disconnectNetwork(network)
|
||||
if not network.wpa_supplicant_id then return end
|
||||
local wcli, _ = WpaClient.new(self.wpa_supplicant.ctrl_interface)
|
||||
wcli:removeNetwork(network.wpa_supplicant_id)
|
||||
wcli:close()
|
||||
end
|
||||
|
||||
function WpaSupplicant:getCurrentNetwork()
|
||||
local wcli, _ = WpaClient.new(self.wpa_supplicant.ctrl_interface)
|
||||
local nw = wcli:getCurrentNetwork()
|
||||
wcli:close()
|
||||
return nw
|
||||
end
|
||||
|
||||
function WpaSupplicant.init(network_mgr, options)
|
||||
network_mgr.wpa_supplicant = {ctrl_interface = options.ctrl_interface}
|
||||
network_mgr.getNetworkList = WpaSupplicant.getNetworkList
|
||||
network_mgr.getCurrentNetwork = WpaSupplicant.getCurrentNetwork
|
||||
network_mgr.authenticateNetwork = WpaSupplicant.authenticateNetwork
|
||||
network_mgr.disconnectNetwork = WpaSupplicant.disconnectNetwork
|
||||
end
|
||||
|
||||
return WpaSupplicant
|
@ -0,0 +1,123 @@
|
||||
--[[--
|
||||
Widget compoent that handles pagination for a list of items.
|
||||
|
||||
Example:
|
||||
|
||||
local list_view = ListView:new{
|
||||
height = 400,
|
||||
width = 200,
|
||||
page_update_cb = function(curr_page_num, total_pages)
|
||||
-- This callback function will be called whenever there is a
|
||||
-- page turn event triggered. You can use it to update information
|
||||
-- on parent widget.
|
||||
end,
|
||||
items = {
|
||||
FrameContainer:new{
|
||||
bordersize = 0,
|
||||
background = Blitbuffer.COLOR_WHITE
|
||||
TextWidget:new{
|
||||
text = "foo",
|
||||
fact = Font:getFace("cfont"),
|
||||
}
|
||||
},
|
||||
FrameContainer:new{
|
||||
bordersize = 0,
|
||||
background = Blitbuffer.COLOR_LIGHT_GREY
|
||||
TextWidget:new{
|
||||
text = "bar",
|
||||
fact = Font:getFace("cfont"),
|
||||
}
|
||||
},
|
||||
-- You can add as many widgets as you want here...
|
||||
}
|
||||
}
|
||||
|
||||
Note that ListView is created mainly to be used as a building block for other
|
||||
widgets like NetworkSetting so they can share the same pagination code.
|
||||
]]
|
||||
|
||||
local InputContainer = require("ui/widget/container/inputcontainer")
|
||||
local FrameContainer = require("ui/widget/container/framecontainer")
|
||||
local VerticalGroup = require("ui/widget/verticalgroup")
|
||||
local GestureRange = require("ui/gesturerange")
|
||||
local Blitbuffer = require("ffi/blitbuffer")
|
||||
local Device = require("device")
|
||||
local Screen = Device.screen
|
||||
local Geom = require("ui/geometry")
|
||||
|
||||
local ListView = InputContainer:new{
|
||||
width = nil,
|
||||
height = nil,
|
||||
padding = nil,
|
||||
item_height = nil,
|
||||
itmes = nil,
|
||||
}
|
||||
|
||||
function ListView:init()
|
||||
self.show_page = 1
|
||||
self.dimen = Geom:new{w = self.width, h = self.height}
|
||||
|
||||
if Device:isTouchDevice() then
|
||||
self.ges_events.Swipe = {
|
||||
GestureRange:new{
|
||||
ges = "swipe",
|
||||
range = self.dimen,
|
||||
}
|
||||
}
|
||||
end
|
||||
|
||||
local padding = self.padding or Screen:scaleBySize(10)
|
||||
self.item_height = self.item_height or self.items[1]:getSize().h
|
||||
self.item_width = self.dimen.w - 2 * padding
|
||||
self.items_per_page = math.floor(self.height / self.item_height)
|
||||
self.main_content = VerticalGroup:new{}
|
||||
self:_populateItems()
|
||||
self[1] = FrameContainer:new{
|
||||
height = self.dimen.h,
|
||||
padding = padding,
|
||||
bordersize = 0,
|
||||
background = Blitbuffer.COLOR_WHITE,
|
||||
self.main_content,
|
||||
}
|
||||
end
|
||||
|
||||
-- make sure self.item_height are set before calling this
|
||||
function ListView:_populateItems()
|
||||
self.pages = math.ceil(#self.items / self.items_per_page)
|
||||
self.main_content:clear()
|
||||
local idx_offset = (self.show_page - 1) * self.items_per_page
|
||||
for idx = 1, self.items_per_page do
|
||||
local item = self.items[idx_offset + idx]
|
||||
if item == nil then break end
|
||||
table.insert(self.main_content, item)
|
||||
end
|
||||
self.page_update_cb(self.show_page, self.pages)
|
||||
end
|
||||
|
||||
function ListView:nextPage()
|
||||
local new_page = math.min(self.show_page+1, self.pages)
|
||||
if new_page > self.show_page then
|
||||
self.show_page = new_page
|
||||
self:_populateItems()
|
||||
end
|
||||
end
|
||||
|
||||
function ListView:prevPage()
|
||||
local new_page = math.max(self.show_page-1, 1)
|
||||
if new_page < self.show_page then
|
||||
self.show_page = new_page
|
||||
self:_populateItems()
|
||||
end
|
||||
end
|
||||
|
||||
function ListView:onSwipe(arg, ges_ev)
|
||||
if ges_ev.direction == "west" then
|
||||
self:nextPage()
|
||||
return true
|
||||
elseif ges_ev.direction == "east" then
|
||||
self:prevPage()
|
||||
return true
|
||||
end
|
||||
end
|
||||
|
||||
return ListView
|
@ -0,0 +1,466 @@
|
||||
--[[--
|
||||
Network setting widget.
|
||||
|
||||
Example:
|
||||
|
||||
local network_list = {
|
||||
{
|
||||
ssid = "foo",
|
||||
signal_level = -58,
|
||||
flags = "[WPA2-PSK-CCMP][ESS]",
|
||||
signal_quality = 84,
|
||||
password = "123abc",
|
||||
connected = true,
|
||||
},
|
||||
{
|
||||
ssid = "bar",
|
||||
signal_level = -258,
|
||||
signal_quality = 44,
|
||||
flags = "[WEP][ESS]",
|
||||
},
|
||||
}
|
||||
UIManager:show(require("ui/widget/networksetting"):new{
|
||||
network_list = network_list,
|
||||
connect_callback = function()
|
||||
-- connect_callback will be called when an connect/disconnect
|
||||
-- attempt has been made. you can update UI widgets in the
|
||||
-- callback.
|
||||
end,
|
||||
})
|
||||
|
||||
]]
|
||||
|
||||
local FrameContainer = require("ui/widget/container/framecontainer")
|
||||
local InputContainer = require("ui/widget/container/inputcontainer")
|
||||
local LeftContainer = require("ui/widget/container/leftcontainer")
|
||||
local CenterContainer = require("ui/widget/container/centercontainer")
|
||||
local RightContainer = require("ui/widget/container/rightcontainer")
|
||||
local HorizontalGroup = require("ui/widget/horizontalgroup")
|
||||
local HorizontalSpan = require("ui/widget/horizontalspan")
|
||||
local VerticalGroup = require("ui/widget/verticalgroup")
|
||||
local OverlapGroup = require("ui/widget/overlapgroup")
|
||||
local InfoMessage = require("ui/widget/infomessage")
|
||||
local InputDialog = require("ui/widget/inputdialog")
|
||||
local NetworkMgr = require("ui/network/manager")
|
||||
local ListView = require("ui/widget/listview")
|
||||
local ImageWidget = require("ui/widget/imagewidget")
|
||||
local Widget = require("ui/widget/widget")
|
||||
local TextWidget = require("ui/widget/textwidget")
|
||||
local GestureRange = require("ui/gesturerange")
|
||||
local Blitbuffer = require("ffi/blitbuffer")
|
||||
local UIManager = require("ui/uimanager")
|
||||
local Geom = require("ui/geometry")
|
||||
local Device = require("device")
|
||||
local Screen = Device.screen
|
||||
local Font = require("ui/font")
|
||||
local _ = require("gettext")
|
||||
|
||||
|
||||
local MinimalPaginator = Widget:new{
|
||||
width = nil,
|
||||
height = nil,
|
||||
progress = nil,
|
||||
}
|
||||
|
||||
function MinimalPaginator:getSize()
|
||||
return Geom:new{w = self.width, h = self.height}
|
||||
end
|
||||
|
||||
function MinimalPaginator:paintTo(bb, x, y)
|
||||
self.dimen = self:getSize()
|
||||
self.dimen.x, self.dimen.y = x, y
|
||||
-- paint background
|
||||
bb:paintRoundedRect(x, y,
|
||||
self.dimen.w, self.dimen.h,
|
||||
Blitbuffer.COLOR_LIGHT_GREY)
|
||||
-- paint percentage infill
|
||||
bb:paintRect(x, y,
|
||||
math.ceil(self.dimen.w*self.progress), self.dimen.h,
|
||||
Blitbuffer.COLOR_GREY)
|
||||
end
|
||||
|
||||
function MinimalPaginator:setProgress(progress) self.progress = progress end
|
||||
|
||||
|
||||
local NetworkItem = InputContainer:new{
|
||||
dimen = nil,
|
||||
height = Screen:scaleBySize(44),
|
||||
width = nil,
|
||||
info = nil,
|
||||
background = Blitbuffer.COLOR_WHITE,
|
||||
}
|
||||
|
||||
function NetworkItem:init()
|
||||
self.dimen = Geom:new{w = self.width, h = self.height}
|
||||
if not self.info.ssid then
|
||||
self.info.ssid = "[hidden]"
|
||||
end
|
||||
|
||||
local wifi_icon_path
|
||||
if string.find(self.info.flags, "WPA") then
|
||||
wifi_icon_path = "resources/icons/koicon.wifi.secure.%d.medium.png"
|
||||
else
|
||||
wifi_icon_path = "resources/icons/koicon.wifi.open.%d.medium.png"
|
||||
end
|
||||
if self.info.signal_quality == 0 or self.info.signal_quality == 100 then
|
||||
wifi_icon_path = string.format(wifi_icon_path, self.info.signal_quality)
|
||||
else
|
||||
wifi_icon_path = string.format(
|
||||
wifi_icon_path,
|
||||
self.info.signal_quality + 25 - self.info.signal_quality % 25)
|
||||
end
|
||||
local horizontal_space = HorizontalSpan:new{width = Screen:scaleBySize(8)}
|
||||
self.content_container = OverlapGroup:new{
|
||||
dimen = self.dimen:copy(),
|
||||
LeftContainer:new{
|
||||
dimen = self.dimen:copy(),
|
||||
HorizontalGroup:new{
|
||||
horizontal_space,
|
||||
ImageWidget:new{
|
||||
alpha = true,
|
||||
file = wifi_icon_path,
|
||||
},
|
||||
horizontal_space,
|
||||
TextWidget:new{
|
||||
text = self.info.ssid,
|
||||
face = Font:getFace("cfont"),
|
||||
},
|
||||
},
|
||||
}
|
||||
}
|
||||
self.btn_disconnect = nil
|
||||
self.btn_edit_nw = nil
|
||||
if self.info.connected then
|
||||
self.btn_disconnect = FrameContainer:new{
|
||||
bordersize = 0,
|
||||
padding = 0,
|
||||
TextWidget:new{
|
||||
text = _("disconnect"),
|
||||
face = Font:getFace("cfont"),
|
||||
}
|
||||
}
|
||||
|
||||
table.insert(self.content_container, RightContainer:new{
|
||||
dimen = self.dimen:copy(),
|
||||
HorizontalGroup:new{
|
||||
self.btn_disconnect,
|
||||
horizontal_space,
|
||||
}
|
||||
})
|
||||
elseif self.info.password then
|
||||
self.btn_edit_nw = FrameContainer:new{
|
||||
bordersize = 0,
|
||||
padding = 0,
|
||||
TextWidget:new{
|
||||
text = _("edit"),
|
||||
face = Font:getFace("cfont"),
|
||||
}
|
||||
}
|
||||
|
||||
table.insert(self.content_container, RightContainer:new{
|
||||
dimen = self.dimen:copy(),
|
||||
HorizontalGroup:new{
|
||||
self.btn_edit_nw,
|
||||
horizontal_space,
|
||||
}
|
||||
})
|
||||
end
|
||||
|
||||
self[1] = FrameContainer:new{
|
||||
padding = 0,
|
||||
margin = 0,
|
||||
background = self.background,
|
||||
bordersize = 0,
|
||||
width = self.width,
|
||||
self.content_container,
|
||||
}
|
||||
|
||||
if Device:isTouchDevice() then
|
||||
self.ges_events = {
|
||||
TapSelect = {
|
||||
GestureRange:new{
|
||||
ges = "tap",
|
||||
range = self.dimen,
|
||||
}
|
||||
}
|
||||
}
|
||||
end
|
||||
end
|
||||
|
||||
function NetworkItem:refresh()
|
||||
self:init()
|
||||
UIManager:setDirty(self.setting_ui, function() return "ui", self.dimen end)
|
||||
end
|
||||
|
||||
function NetworkItem:connect()
|
||||
local connected_item = self.setting_ui:getConnectedItem(self)
|
||||
if connected_item then connected_item:disconnect() end
|
||||
|
||||
local success, err_msg = NetworkMgr:authenticateNetwork(self.info)
|
||||
|
||||
local text
|
||||
if success then
|
||||
local info = InfoMessage:new{text = _("Obtaining IP address…")}
|
||||
UIManager:show(info)
|
||||
UIManager:forceRePaint()
|
||||
NetworkMgr:obtainIP()
|
||||
UIManager:close(info)
|
||||
self.info.connected = true
|
||||
self.setting_ui:setConnectedItem(self)
|
||||
text = _("Connected.")
|
||||
else
|
||||
text = err_msg
|
||||
end
|
||||
|
||||
if self.setting_ui.connect_callback then
|
||||
self.setting_ui.connect_callback()
|
||||
end
|
||||
UIManager:show(InfoMessage:new{text = text})
|
||||
end
|
||||
|
||||
function NetworkItem:disconnect()
|
||||
local info = InfoMessage:new{text = _("Disconnecting…")}
|
||||
UIManager:show(info)
|
||||
UIManager:forceRePaint()
|
||||
|
||||
NetworkMgr:disconnectNetwork(self.info)
|
||||
NetworkMgr:releaseIP()
|
||||
|
||||
UIManager:close(info)
|
||||
self.info.connected = nil
|
||||
self:refresh()
|
||||
if self.setting_ui.connect_callback then
|
||||
self.setting_ui.connect_callback()
|
||||
end
|
||||
end
|
||||
|
||||
function NetworkItem:saveAndConnectToNetwork(password_input)
|
||||
local new_passwd = password_input:getInputText()
|
||||
if new_passwd == nil or string.len(new_passwd) == 0 then
|
||||
UIManager:show(InfoMessage:new{
|
||||
text = _("Password cannot be empty."),
|
||||
})
|
||||
else
|
||||
if new_passwd ~= self.info.password then
|
||||
self.info.password = new_passwd
|
||||
NetworkMgr:saveNetwork(self.info)
|
||||
end
|
||||
self:connect()
|
||||
self:refresh()
|
||||
end
|
||||
|
||||
UIManager:close(password_input)
|
||||
end
|
||||
|
||||
function NetworkItem:onEditNetwork()
|
||||
local password_input
|
||||
password_input = InputDialog:new{
|
||||
title = self.info.ssid,
|
||||
input = self.info.password,
|
||||
input_hint = "password",
|
||||
input_type = "text",
|
||||
text_type = "password",
|
||||
buttons = {
|
||||
{
|
||||
{
|
||||
text = _("Cancel"),
|
||||
callback = function()
|
||||
UIManager:close(password_input)
|
||||
end,
|
||||
},
|
||||
{
|
||||
text = _("Forget"),
|
||||
callback = function()
|
||||
NetworkMgr:deleteNetwork(self.info)
|
||||
self.info.password = nil
|
||||
-- remove edit button
|
||||
table.remove(self.content_container, 2)
|
||||
UIManager:close(password_input)
|
||||
self:refresh()
|
||||
end,
|
||||
},
|
||||
{
|
||||
text = _("Connect"),
|
||||
is_enter_default = true,
|
||||
callback = function()
|
||||
self:saveAndConnectToNetwork(password_input)
|
||||
end,
|
||||
},
|
||||
},
|
||||
},
|
||||
}
|
||||
password_input:onShowKeyboard()
|
||||
UIManager:show(password_input)
|
||||
return true
|
||||
end
|
||||
|
||||
function NetworkItem:onAddNetwork()
|
||||
local password_input
|
||||
password_input = InputDialog:new{
|
||||
title = self.info.ssid,
|
||||
input = "",
|
||||
input_hint = "password",
|
||||
input_type = "text",
|
||||
text_type = "password",
|
||||
buttons = {
|
||||
{
|
||||
{
|
||||
text = _("Cancel"),
|
||||
callback = function()
|
||||
UIManager:close(password_input)
|
||||
end,
|
||||
},
|
||||
{
|
||||
text = _("Connect"),
|
||||
is_enter_default = true,
|
||||
callback = function()
|
||||
self:saveAndConnectToNetwork(password_input)
|
||||
end,
|
||||
},
|
||||
},
|
||||
},
|
||||
}
|
||||
password_input:onShowKeyboard()
|
||||
UIManager:show(password_input)
|
||||
return true
|
||||
end
|
||||
|
||||
function NetworkItem:onTapSelect(arg, ges_ev)
|
||||
if not string.find(self.info.flags, "WPA") then
|
||||
UIManager:show(InfoMessage:new{
|
||||
text = _("Networks without WPA/WPA2 encryption are not supported.")
|
||||
})
|
||||
return
|
||||
end
|
||||
if self.btn_disconnect then
|
||||
-- noop if touch is not on disconnect button
|
||||
if ges_ev.pos:intersectWith(self.btn_disconnect.dimen) then
|
||||
self:disconnect()
|
||||
end
|
||||
elseif self.info.password then
|
||||
if self.btn_edit_nw and ges_ev.pos:intersectWith(self.btn_edit_nw.dimen) then
|
||||
self:onEditNetwork()
|
||||
else
|
||||
self:connect()
|
||||
self:refresh()
|
||||
end
|
||||
else
|
||||
self:onAddNetwork()
|
||||
end
|
||||
return true
|
||||
end
|
||||
|
||||
|
||||
local NetworkSetting = InputContainer:new{
|
||||
width = nil,
|
||||
height = nil,
|
||||
-- sample network_list entry: {
|
||||
-- bssid = "any",
|
||||
-- ssid = "foo",
|
||||
-- signal_level = -58,
|
||||
-- signal_quality = 84,
|
||||
-- frequency = 5660,
|
||||
-- flags = "[WPA2-PSK-CCMP][ESS]",
|
||||
-- }
|
||||
network_list = nil,
|
||||
connect_callback = nil,
|
||||
}
|
||||
|
||||
function NetworkSetting:init()
|
||||
self.width = self.width or Screen:getWidth() - Screen:scaleBySize(50)
|
||||
self.width = math.min(self.width, Screen:scaleBySize(600))
|
||||
|
||||
local gray_bg = Blitbuffer.gray(0.1)
|
||||
local items = {}
|
||||
table.sort(self.network_list,
|
||||
function(l, r) return l.signal_quality > r.signal_quality end)
|
||||
for idx,network in ipairs(self.network_list) do
|
||||
local bg
|
||||
if idx % 2 == 0 then
|
||||
bg = gray_bg
|
||||
else
|
||||
bg = Blitbuffer.COLOR_WHITE
|
||||
end
|
||||
table.insert(items, NetworkItem:new{
|
||||
width = self.width,
|
||||
info = network,
|
||||
background = bg,
|
||||
setting_ui = self,
|
||||
})
|
||||
end
|
||||
|
||||
self.status_text = TextWidget:new{
|
||||
text = "",
|
||||
face = Font:getFace("ffont"),
|
||||
}
|
||||
self.page_text = TextWidget:new{
|
||||
text = "",
|
||||
face = Font:getFace("ffont"),
|
||||
}
|
||||
|
||||
self.pagination = MinimalPaginator:new{
|
||||
width = self.width,
|
||||
height = Screen:scaleBySize(8),
|
||||
percentage = 0,
|
||||
}
|
||||
|
||||
self.height = self.height or math.min(Screen:getHeight()*3/4,
|
||||
Screen:scaleBySize(800))
|
||||
self.popup = FrameContainer:new{
|
||||
background = Blitbuffer.COLOR_WHITE,
|
||||
padding = 0,
|
||||
bordersize = 3,
|
||||
VerticalGroup:new{
|
||||
align = "left",
|
||||
self.pagination,
|
||||
ListView:new{
|
||||
padding = 0,
|
||||
items = items,
|
||||
width = self.width,
|
||||
height = self.height-self.pagination:getSize().h,
|
||||
page_update_cb = function(curr_page, total_pages)
|
||||
self.pagination:setProgress(curr_page/total_pages)
|
||||
-- self.page_text:setText(curr_page .. "/" .. total_pages)
|
||||
UIManager:setDirty(self, function()
|
||||
return "ui", self.dimen
|
||||
end)
|
||||
end
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
self[1] = CenterContainer:new{
|
||||
dimen = {w = Screen:getWidth(), h = Screen:getHeight()},
|
||||
self.popup,
|
||||
}
|
||||
|
||||
if Device:isTouchDevice() then
|
||||
self.ges_events.TapClose = {
|
||||
GestureRange:new{
|
||||
ges = "tap",
|
||||
range = Geom:new{
|
||||
x = 0, y = 0,
|
||||
w = Screen:getWidth(),
|
||||
h = Screen:getHeight(),
|
||||
}
|
||||
}
|
||||
}
|
||||
end
|
||||
end
|
||||
|
||||
function NetworkSetting:setConnectedItem(item)
|
||||
self.connected_item = item
|
||||
end
|
||||
|
||||
function NetworkSetting:getConnectedItem()
|
||||
return self.connected_item
|
||||
end
|
||||
|
||||
function NetworkSetting:onTapClose(arg, ges_ev)
|
||||
if ges_ev.pos:notIntersectWith(self.popup.dimen) then
|
||||
UIManager:close(self)
|
||||
return true
|
||||
end
|
||||
end
|
||||
|
||||
return NetworkSetting
|
After Width: | Height: | Size: 729 B |
After Width: | Height: | Size: 774 B |
After Width: | Height: | Size: 758 B |
After Width: | Height: | Size: 792 B |
After Width: | Height: | Size: 800 B |
After Width: | Height: | Size: 877 B |
After Width: | Height: | Size: 846 B |
After Width: | Height: | Size: 865 B |
After Width: | Height: | Size: 870 B |
After Width: | Height: | Size: 874 B |