diff --git a/frontend/device/android/device.lua b/frontend/device/android/device.lua index 3d7a8dc93..9101f939d 100644 --- a/frontend/device/android/device.lua +++ b/frontend/device/android/device.lua @@ -362,13 +362,41 @@ function Device:canExecuteScript(file) end end +--swallow all events +local function processEvents() + local events = ffi.new("int[1]") + local source = ffi.new("struct android_poll_source*[1]") + local poll_state = android.lib.ALooper_pollAll(-1, nil, events, ffi.cast("void**", source)) + if poll_state >= 0 then + if source[0] ~= nil then + if source[0].id == C.LOOPER_ID_MAIN then + local cmd = C.android_app_read_cmd(android.app) + C.android_app_pre_exec_cmd(android.app, cmd) + C.android_app_post_exec_cmd(android.app, cmd) + elseif source[0].id == C.LOOPER_ID_INPUT then + local event = ffi.new("AInputEvent*[1]") + while android.lib.AInputQueue_getEvent(android.app.inputQueue, event) >= 0 do + if android.lib.AInputQueue_preDispatchEvent(android.app.inputQueue, event[0]) == 0 then + android.lib.AInputQueue_finishEvent(android.app.inputQueue, event[0], 1) + end + end + end + end + end +end + function Device:showLightDialog() local usleep = require("ffi/util").usleep local title = android.isEink() and _("Frontlight settings") or _("Light settings") android.lights.showDialog(title, _("Brightness"), _("Warmth"), _("OK"), _("Cancel")) repeat + processEvents() -- swallow all events, including the last one usleep(25000) -- sleep 25ms before next check if dialog was quit until (android.lights.dialogState() ~= C.ALIGHTS_DIALOG_OPENED) + + local GestureDetector = require("device/gesturedetector") + GestureDetector:clearStates() + local action = android.lights.dialogState() if action == C.ALIGHTS_DIALOG_OK then self.powerd.fl_intensity = self.powerd:frontlightIntensityHW()