2014-10-30 18:42:18 +00:00
|
|
|
local Generic = require("device/generic/device")
|
2016-02-16 07:10:07 +00:00
|
|
|
local _, android = pcall(require, "android")
|
2014-10-30 18:42:18 +00:00
|
|
|
local ffi = require("ffi")
|
2018-06-02 16:10:55 +00:00
|
|
|
local C = ffi.C
|
2016-12-29 08:10:38 +00:00
|
|
|
local logger = require("logger")
|
2014-10-30 18:42:18 +00:00
|
|
|
|
|
|
|
local function yes() return true end
|
2015-09-27 14:29:59 +00:00
|
|
|
local function no() return false end
|
2014-10-30 18:42:18 +00:00
|
|
|
|
|
|
|
local Device = Generic:new{
|
|
|
|
model = "Android",
|
2015-03-29 00:59:51 +00:00
|
|
|
hasKeys = yes,
|
2015-09-27 14:29:59 +00:00
|
|
|
hasDPad = no,
|
2014-10-30 18:42:18 +00:00
|
|
|
isAndroid = yes,
|
2016-06-23 17:50:24 +00:00
|
|
|
hasFrontlight = yes,
|
2014-10-30 18:42:18 +00:00
|
|
|
firmware_rev = "none",
|
2017-09-23 21:58:34 +00:00
|
|
|
display_dpi = android.lib.AConfiguration_getDensity(android.app.config),
|
2018-02-16 20:44:10 +00:00
|
|
|
hasClipboard = yes,
|
2017-10-01 21:48:53 +00:00
|
|
|
hasColorScreen = yes,
|
2018-10-06 05:55:35 +00:00
|
|
|
hasOTAUpdates = yes,
|
2014-10-30 18:42:18 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
function Device:init()
|
2016-12-29 08:10:38 +00:00
|
|
|
self.screen = require("ffi/framebuffer_android"):new{device = self, debug = logger.dbg}
|
2014-10-30 18:42:18 +00:00
|
|
|
self.powerd = require("device/android/powerd"):new{device = self}
|
|
|
|
self.input = require("device/input"):new{
|
|
|
|
device = self,
|
|
|
|
event_map = require("device/android/event_map"),
|
2016-04-03 04:52:30 +00:00
|
|
|
handleMiscEv = function(this, ev)
|
2016-12-29 08:10:38 +00:00
|
|
|
logger.dbg("Android application event", ev.code)
|
2018-06-02 16:10:55 +00:00
|
|
|
if ev.code == C.APP_CMD_SAVE_STATE then
|
2014-10-30 18:42:18 +00:00
|
|
|
return "SaveState"
|
2018-06-02 16:10:55 +00:00
|
|
|
elseif ev.code == C.APP_CMD_GAINED_FOCUS then
|
2016-04-03 04:52:30 +00:00
|
|
|
this.device.screen:refreshFull()
|
2018-06-02 16:10:55 +00:00
|
|
|
elseif ev.code == C.APP_CMD_WINDOW_REDRAW_NEEDED then
|
2016-04-03 04:52:30 +00:00
|
|
|
this.device.screen:refreshFull()
|
2014-10-30 18:42:18 +00:00
|
|
|
end
|
|
|
|
end,
|
2018-02-16 20:44:10 +00:00
|
|
|
hasClipboardText = function()
|
|
|
|
return android.hasClipboardText()
|
|
|
|
end,
|
|
|
|
getClipboardText = function()
|
|
|
|
return android.getClipboardText()
|
|
|
|
end,
|
|
|
|
setClipboardText = function(text)
|
|
|
|
return android.setClipboardText(text)
|
|
|
|
end,
|
2014-10-30 18:42:18 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
-- check if we have a keyboard
|
2017-09-23 21:58:34 +00:00
|
|
|
if android.lib.AConfiguration_getKeyboard(android.app.config)
|
2018-06-02 16:10:55 +00:00
|
|
|
== C.ACONFIGURATION_KEYBOARD_QWERTY
|
2014-10-30 18:42:18 +00:00
|
|
|
then
|
|
|
|
self.hasKeyboard = yes
|
|
|
|
end
|
|
|
|
-- check if we have a touchscreen
|
2017-09-23 21:58:34 +00:00
|
|
|
if android.lib.AConfiguration_getTouchscreen(android.app.config)
|
2018-06-02 16:10:55 +00:00
|
|
|
~= C.ACONFIGURATION_TOUCHSCREEN_NOTOUCH
|
2014-10-30 18:42:18 +00:00
|
|
|
then
|
|
|
|
self.isTouchDevice = yes
|
|
|
|
end
|
|
|
|
|
2014-11-24 08:52:01 +00:00
|
|
|
Generic.init(self)
|
2014-10-30 18:42:18 +00:00
|
|
|
end
|
|
|
|
|
2017-10-21 20:27:09 +00:00
|
|
|
function Device:initNetworkManager(NetworkMgr)
|
|
|
|
NetworkMgr.turnOnWifi = function()
|
|
|
|
android.setWifiEnabled(true)
|
|
|
|
end
|
|
|
|
|
|
|
|
NetworkMgr.turnOffWifi = function()
|
|
|
|
android.setWifiEnabled(false)
|
|
|
|
end
|
2017-10-28 15:51:34 +00:00
|
|
|
NetworkMgr.isWifiOn = function()
|
|
|
|
return android.isWifiEnabled()
|
|
|
|
end
|
2017-10-21 20:27:09 +00:00
|
|
|
end
|
|
|
|
|
2014-10-30 18:42:18 +00:00
|
|
|
return Device
|