mirror of
https://github.com/koreader/koreader
synced 2024-11-10 01:10:34 +00:00
217a73f3c0
* Rejig frontlight warmth API to more closely match the existing API, and, hopefully, clarify some of its quirks, and reduce boilerplate and duplicate code in platform implementations. * Tweak Kindle:setDateTime to prefer using the platform's custom script, as in interacts better with the stock UI. And make the fallbacks handle old busybox versions better. * Add Kindle PW5 support ;). * Add warmth support to the Kindle platform. * Random TextBoxWidget cleanups: make sure we immediately free destroyed instances. * FrontLightWidget: Refactor to make it slightly less obnoxious to grok and update; i.e., separate layout from update, and properly separate brightness from warmth handling. Move to simpler widgets instead of reinventing the wheel. * TextBoxWidgets: Implement `setText` to match TextWidget's API, as some callers may be using the two interchangeably (i.e., Button). * NaturalLightWidget: Make sure we pass a string to InputText * InputText: Add debug guards to catch bad callers not passing strings ;).
87 lines
2.5 KiB
Lua
87 lines
2.5 KiB
Lua
local BasePowerD = require("device/generic/powerd")
|
|
local _, android = pcall(require, "android")
|
|
|
|
local AndroidPowerD = BasePowerD:new{
|
|
fl_min = 0,
|
|
fl_max = 100,
|
|
}
|
|
|
|
-- Let the footer know of the change
|
|
local function broadcastLightChanges()
|
|
if package.loaded["ui/uimanager"] ~= nil then
|
|
local Event = require("ui/event")
|
|
local UIManager = require("ui/uimanager")
|
|
UIManager:broadcastEvent(Event:new("FrontlightStateChanged"))
|
|
end
|
|
end
|
|
|
|
function AndroidPowerD:frontlightIntensityHW()
|
|
return math.floor(android.getScreenBrightness() / self.bright_diff * self.fl_max)
|
|
end
|
|
|
|
function AndroidPowerD:setIntensityHW(intensity)
|
|
-- if frontlight switch was toggled of, turn it on
|
|
android.enableFrontlightSwitch()
|
|
|
|
self.fl_intensity = intensity
|
|
android.setScreenBrightness(math.floor(intensity * self.bright_diff / self.fl_max))
|
|
end
|
|
|
|
function AndroidPowerD:init()
|
|
local min_bright = android.getScreenMinBrightness()
|
|
self.bright_diff = android.getScreenMaxBrightness() - min_bright
|
|
|
|
-- if necessary scale fl_min:
|
|
-- do not use fl_min==0 if getScreenMinBrightness!=0,
|
|
-- because intenstiy==0 would mean to use system intensity
|
|
if min_bright ~= self.fl_min then
|
|
self.fl_min = math.ceil(min_bright * self.bright_diff / self.fl_max)
|
|
end
|
|
|
|
if self.device:hasNaturalLight() then
|
|
self.fl_warmth_min = android.getScreenMinWarmth()
|
|
self.fl_warmth_max = android.getScreenMaxWarmth()
|
|
self.warm_diff = self.fl_warmth_max - self.fl_warmth_min
|
|
end
|
|
end
|
|
|
|
function AndroidPowerD:setWarmthHW(warmth)
|
|
android.setScreenWarmth(warmth)
|
|
end
|
|
|
|
function AndroidPowerD:frontlightWarmthHW()
|
|
return android.getScreenWarmth() * self.warm_diff
|
|
end
|
|
|
|
function AndroidPowerD:getCapacityHW()
|
|
return android.getBatteryLevel()
|
|
end
|
|
|
|
function AndroidPowerD:isChargingHW()
|
|
return android.isCharging()
|
|
end
|
|
|
|
function AndroidPowerD:turnOffFrontlightHW()
|
|
if not self:isFrontlightOnHW() then
|
|
return
|
|
end
|
|
android.setScreenBrightness(self.fl_min)
|
|
self.is_fl_on = false
|
|
broadcastLightChanges()
|
|
end
|
|
|
|
function AndroidPowerD:turnOnFrontlightHW()
|
|
if self:isFrontlightOn() and self:isFrontlightOnHW() then
|
|
return
|
|
end
|
|
-- on devices with a software frontlight switch (e.g Tolinos), enable it
|
|
android.enableFrontlightSwitch()
|
|
|
|
android.setScreenBrightness(math.floor(self.fl_intensity * self.bright_diff / self.fl_max))
|
|
|
|
self.is_fl_on = true
|
|
broadcastLightChanges()
|
|
end
|
|
|
|
return AndroidPowerD
|