mirror of
https://github.com/koreader/koreader
synced 2024-11-16 06:12:56 +00:00
[Android]: Native light dialog (#6426)
* Adds support for Tolino Epos 2 warmth light
This commit is contained in:
parent
0511cb1d48
commit
a6763465b4
@ -184,7 +184,7 @@ function ReaderGesture:init()
|
||||
hold_bottom_right_corner = "ignore",
|
||||
one_finger_swipe_left_edge_down = Device:hasFrontlight() and "decrease_frontlight" or "ignore",
|
||||
one_finger_swipe_left_edge_up = Device:hasFrontlight() and "increase_frontlight" or "ignore",
|
||||
one_finger_swipe_right_edge_down = Device:hasNaturalLight() and "decrease_frontlight_warmth" or "ignore",
|
||||
one_finger_swipe_right_edge_down = Device:hasNaturalLight() and "decrease_frontlight_warmth" or "ignore",
|
||||
one_finger_swipe_right_edge_up = Device:hasNaturalLight() and "increase_frontlight_warmth" or "ignore",
|
||||
one_finger_swipe_top_edge_right = "ignore",
|
||||
one_finger_swipe_top_edge_left = "ignore",
|
||||
|
@ -72,6 +72,7 @@ local Device = Generic:new{
|
||||
hasEinkScreen = function() return android.isEink() end,
|
||||
hasColorScreen = function() return not android.isEink() end,
|
||||
hasFrontlight = yes,
|
||||
hasNaturalLight = android.isWarmthDevice,
|
||||
hasLightLevelFallback = yes,
|
||||
canRestart = no,
|
||||
canSuspend = no,
|
||||
@ -244,11 +245,13 @@ function Device:init()
|
||||
android.setBackButtonIgnored(true)
|
||||
end
|
||||
|
||||
--- @todo remove fl_last_level and revert hasLightFallback if frontlightwidget
|
||||
|
||||
-- check if we enable a custom light level for this activity
|
||||
local last_value = G_reader_settings:readSetting("fl_last_level")
|
||||
if type(last_value) == "number" and last_value >= 0 then
|
||||
Device:setScreenBrightness(last_value)
|
||||
end
|
||||
--local last_value = G_reader_settings:readSetting("fl_last_level")
|
||||
--if type(last_value) == "number" and last_value >= 0 then
|
||||
-- Device:setScreenBrightness(last_value)
|
||||
--end
|
||||
|
||||
Generic.init(self)
|
||||
end
|
||||
@ -375,6 +378,31 @@ function Device:canExecuteScript(file)
|
||||
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
|
||||
usleep(25000) -- sleep 25ms before next check if dialog was quit
|
||||
until (android.lights.dialogState() ~= C.ALIGHTS_DIALOG_OPENED)
|
||||
local action = android.lights.dialogState()
|
||||
if action == C.ALIGHTS_DIALOG_OK then
|
||||
self.powerd.fl_intensity = self.powerd:frontlightIntensityHW()
|
||||
logger.dbg("Dialog OK, brightness: " .. self.powerd.fl_intensity)
|
||||
if android.isWarmthDevice() then
|
||||
self.powerd.fl_warmth = self.powerd:getWarmth()
|
||||
logger.dbg("Dialog OK, warmth: " .. self.powerd.fl_warmth)
|
||||
end
|
||||
elseif action == C.ALIGHTS_DIALOG_CANCEL then
|
||||
logger.dbg("Dialog Cancel, brightness: " .. self.powerd.fl_intensity)
|
||||
self.powerd:setIntensityHW(self.powerd.fl_intensity)
|
||||
if android.isWarmthDevice() then
|
||||
logger.dbg("Dialog Cancel, warmth: " .. self.powerd.fl_warmth)
|
||||
self.powerd:setWarmth(self.powerd.fl_warmth)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
android.LOGI(string.format("Android %s - %s (API %d) - flavor: %s",
|
||||
android.prop.version, getCodename(), Device.firmware_rev, android.prop.flavor))
|
||||
|
||||
|
@ -2,16 +2,34 @@ local BasePowerD = require("device/generic/powerd")
|
||||
local _, android = pcall(require, "android")
|
||||
|
||||
local AndroidPowerD = BasePowerD:new{
|
||||
fl_min = 0, fl_max = 25,
|
||||
fl_intensity = 10,
|
||||
fl_min = 0,
|
||||
fl_max = 100,
|
||||
}
|
||||
|
||||
function AndroidPowerD:frontlightIntensityHW()
|
||||
return math.floor(android.getScreenBrightness() / 255 * self.fl_max)
|
||||
return math.floor(android.getScreenBrightness() / self.bright_diff * self.fl_max)
|
||||
end
|
||||
|
||||
function AndroidPowerD:setIntensityHW(intensity)
|
||||
android.setScreenBrightness(math.floor(255 * intensity / self.fl_max))
|
||||
self.fl_intensity = intensity
|
||||
android.setScreenBrightness(math.floor(intensity * self.bright_diff / self.fl_max))
|
||||
end
|
||||
|
||||
function AndroidPowerD:init()
|
||||
self.bright_diff = android:getScreenMaxBrightness() - android:getScreenMinBrightness()
|
||||
if self.device:hasNaturalLight() then
|
||||
self.warm_diff = android:getScreenMaxWarmth() - android:getScreenMinWarmth()
|
||||
self.fl_warmth = self:getWarmth()
|
||||
end
|
||||
end
|
||||
|
||||
function AndroidPowerD:setWarmth(warmth)
|
||||
self.fl_warmth = warmth
|
||||
android.setScreenWarmth(warmth / self.warm_diff)
|
||||
end
|
||||
|
||||
function AndroidPowerD:getWarmth()
|
||||
return android.getScreenWarmth() * self.warm_diff
|
||||
end
|
||||
|
||||
function AndroidPowerD:getCapacityHW()
|
||||
|
@ -201,6 +201,14 @@ if Device:isAndroid() then
|
||||
local isAndroid, android = pcall(require, "android")
|
||||
if not isAndroid then return end
|
||||
|
||||
-- overwrite generic frontlight with a native Dialog
|
||||
common_settings.frontlight = {
|
||||
text = _("Frontlight"),
|
||||
callback = function()
|
||||
Device:showLightDialog()
|
||||
end,
|
||||
}
|
||||
|
||||
-- screen timeout options, disabled if device needs wakelocks.
|
||||
common_settings.screen_timeout = require("ui/elements/screen_android"):getTimeoutMenuTable()
|
||||
|
||||
|
@ -1 +1 @@
|
||||
Subproject commit ae933822402a5300c927757db410cb0faf098021
|
||||
Subproject commit e3d58c6432ba06d43bdd609c38e6315367825d7e
|
Loading…
Reference in New Issue
Block a user