mirror of
https://github.com/koreader/koreader.git
synced 2025-08-10 00:52:38 +00:00
Frontlight - Add checkbox use system settings (#5307)
See: https://github.com/koreader/koreader/issues/5205#issuecomment-526935357 Devices with `hasLightLevelFallback = true` (for now Android) has extra checkbutton `Use system settings`. Default unchecked.
This commit is contained in:
@@ -179,7 +179,9 @@ end
|
||||
|
||||
function ReaderFrontLight:onShowFlDialog()
|
||||
local FrontLightWidget = require("ui/widget/frontlightwidget")
|
||||
UIManager:show(FrontLightWidget:new{})
|
||||
UIManager:show(FrontLightWidget:new{
|
||||
use_system_fl = Device:hasLightLevelFallback()
|
||||
})
|
||||
end
|
||||
|
||||
function ReaderFrontLight:close()
|
||||
|
||||
@@ -8,6 +8,7 @@ local InfoMessage = require("ui/widget/infomessage")
|
||||
local InputContainer = require("ui/widget/container/inputcontainer")
|
||||
local InputDialog = require("ui/widget/inputdialog")
|
||||
local LuaData = require("luadata")
|
||||
local Notification = require("ui/widget/notification")
|
||||
local Screen = require("device").screen
|
||||
local UIManager = require("ui/uimanager")
|
||||
local T = require("ffi/util").template
|
||||
@@ -1196,6 +1197,10 @@ function ReaderGesture:registerGesture(ges, action, ges_type, zone, overrides, d
|
||||
})
|
||||
end
|
||||
|
||||
local function lightFrontlight()
|
||||
return Device:hasLightLevelFallback() and G_reader_settings:nilOrTrue("light_fallback")
|
||||
end
|
||||
|
||||
function ReaderGesture:gestureAction(action, ges)
|
||||
if action == "ignore" then
|
||||
return
|
||||
@@ -1302,6 +1307,14 @@ function ReaderGesture:gestureAction(action, ges)
|
||||
self.ui:handleEvent(Event:new("ShowFlDialog"))
|
||||
end
|
||||
elseif action == "increase_frontlight" then
|
||||
-- when using frontlight system settings
|
||||
if lightFrontlight() then
|
||||
UIManager:show(Notification:new{
|
||||
text = _("Frontlight controlled by system settings."),
|
||||
timeout = 2.5,
|
||||
})
|
||||
return true
|
||||
end
|
||||
if self.ges_mode == "gesture_fm" then
|
||||
local ReaderFrontLight = require("apps/reader/modules/readerfrontlight")
|
||||
ReaderFrontLight:onChangeFlIntensity(ges, 1)
|
||||
@@ -1309,6 +1322,14 @@ function ReaderGesture:gestureAction(action, ges)
|
||||
self.ui:handleEvent(Event:new("ChangeFlIntensity", ges, 1))
|
||||
end
|
||||
elseif action == "decrease_frontlight" then
|
||||
-- when using frontlight system settings
|
||||
if lightFrontlight() then
|
||||
UIManager:show(Notification:new{
|
||||
text = _("Frontlight controlled by system settings."),
|
||||
timeout = 2.5,
|
||||
})
|
||||
return true
|
||||
end
|
||||
if self.ges_mode == "gesture_fm" then
|
||||
local ReaderFrontLight = require("apps/reader/modules/readerfrontlight")
|
||||
ReaderFrontLight:onChangeFlIntensity(ges, -1)
|
||||
@@ -1332,6 +1353,14 @@ function ReaderGesture:gestureAction(action, ges)
|
||||
elseif action == "toggle_bookmark" then
|
||||
self.ui:handleEvent(Event:new("ToggleBookmark"))
|
||||
elseif action == "toggle_frontlight" then
|
||||
-- when using frontlight system settings
|
||||
if lightFrontlight() then
|
||||
UIManager:show(Notification:new{
|
||||
text = _("Frontlight controlled by system settings."),
|
||||
timeout = 2.5,
|
||||
})
|
||||
return true
|
||||
end
|
||||
Device:getPowerDevice():toggleFrontlight()
|
||||
self:onShowFLOnOff()
|
||||
elseif action == "toggle_gsensor" then
|
||||
@@ -1490,7 +1519,6 @@ function ReaderGesture:pageUpdate(page)
|
||||
end
|
||||
|
||||
function ReaderGesture:onShowFLOnOff()
|
||||
local Notification = require("ui/widget/notification")
|
||||
local powerd = Device:getPowerDevice()
|
||||
local new_text
|
||||
if powerd.is_fl_on then
|
||||
@@ -1506,7 +1534,6 @@ function ReaderGesture:onShowFLOnOff()
|
||||
end
|
||||
|
||||
function ReaderGesture:onGSensorToggle()
|
||||
local Notification = require("ui/widget/notification")
|
||||
local new_text
|
||||
if G_reader_settings:isTrue("input_ignore_gsensor") then
|
||||
new_text = _("Accelerometer rotation events will now be ignored.")
|
||||
|
||||
@@ -66,6 +66,7 @@ local Device = Generic:new{
|
||||
hasEinkScreen = function() return android.isEink() end,
|
||||
hasColorScreen = function() return not android.isEink() end,
|
||||
hasFrontlight = yes,
|
||||
hasLightLevelFallback = yes,
|
||||
canRestart = no,
|
||||
firmware_rev = android.app.activity.sdkVersion,
|
||||
display_dpi = android.lib.AConfiguration_getDensity(android.app.config),
|
||||
@@ -194,6 +195,12 @@ function Device:init()
|
||||
android.setVolumeKeysIgnored(true);
|
||||
end
|
||||
|
||||
-- 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
|
||||
|
||||
Generic.init(self)
|
||||
end
|
||||
|
||||
@@ -233,6 +240,10 @@ function Device:setViewport(x,y,w,h)
|
||||
self.screen:setViewport(viewport)
|
||||
end
|
||||
|
||||
function Device:setScreenBrightness(level)
|
||||
android.setScreenBrightness(level)
|
||||
end
|
||||
|
||||
function Device:toggleFullscreen()
|
||||
local api = android.app.activity.sdkVersion
|
||||
if api >= 19 then
|
||||
|
||||
@@ -27,6 +27,7 @@ local Device = {
|
||||
hasWifiManager = no,
|
||||
isTouchDevice = no,
|
||||
hasFrontlight = no,
|
||||
hasLightLevelFallback = no,
|
||||
hasNaturalLight = no, -- FL warmth implementation specific to NTX boards (Kobo, Cervantes)
|
||||
hasNaturalLightMixer = no, -- Same, but only found on newer boards
|
||||
needsTouchScreenProbe = no,
|
||||
@@ -292,6 +293,9 @@ function Device:saveSettings() end
|
||||
-- Device specific method for toggling the GSensor
|
||||
function Device:toggleGSensor(toggle) end
|
||||
|
||||
-- Device specific method for set custom light levels
|
||||
function Device:setScreenBrightness(level) end
|
||||
|
||||
--[[
|
||||
prepare for application shutdown
|
||||
--]]
|
||||
|
||||
@@ -31,9 +31,11 @@ local FrontLightWidget = InputContainer:new{
|
||||
height = nil,
|
||||
-- This should stay active during natural light configuration
|
||||
is_always_active = true,
|
||||
use_system_fl = false,
|
||||
}
|
||||
|
||||
function FrontLightWidget:init()
|
||||
self.light_fallback = self.use_system_fl and G_reader_settings:nilOrTrue("light_fallback")
|
||||
self.medium_font_face = Font:getFace("ffont")
|
||||
self.larger_font_face = Font:getFace("cfont")
|
||||
self.light_bar = {}
|
||||
@@ -76,7 +78,7 @@ function FrontLightWidget:init()
|
||||
margin = button_margin,
|
||||
padding = button_padding,
|
||||
bordersize = button_bordersize,
|
||||
enabled = true,
|
||||
enabled = not self.light_fallback,
|
||||
width = self.button_width,
|
||||
show_parent = self,
|
||||
}
|
||||
@@ -117,6 +119,7 @@ function FrontLightWidget:setProgress(num, step, num_warmth)
|
||||
local button_group_up = HorizontalGroup:new{ align = "center" }
|
||||
local fl_group = HorizontalGroup:new{ align = "center" }
|
||||
local vertical_group = VerticalGroup:new{ align = "center" }
|
||||
self.fl_prog_button.enabled = not self.light_fallback
|
||||
local set_fl
|
||||
local enable_button_plus = true
|
||||
local enable_button_minus = true
|
||||
@@ -136,6 +139,14 @@ function FrontLightWidget:setProgress(num, step, num_warmth)
|
||||
else
|
||||
self.powerd:setIntensity(set_fl)
|
||||
end
|
||||
|
||||
if not self.light_fallback and self.fl_cur >= 0 then
|
||||
G_reader_settings:saveSetting("fl_last_level", self.fl_cur * 10)
|
||||
elseif self.light_fallback then
|
||||
G_reader_settings:saveSetting("fl_last_level", nil)
|
||||
Device:setScreenBrightness(-1)
|
||||
end
|
||||
|
||||
-- get back the real level (different from set_fl if untoggle)
|
||||
self.fl_cur = self.powerd:frontlightIntensity()
|
||||
-- and update our step_num with it for accurate progress bar
|
||||
@@ -176,7 +187,7 @@ function FrontLightWidget:setProgress(num, step, num_warmth)
|
||||
text = "-1",
|
||||
margin = Size.margin.small,
|
||||
radius = 0,
|
||||
enabled = enable_button_minus,
|
||||
enabled = enable_button_minus and not self.light_fallback,
|
||||
width = self.screen_width * 0.20,
|
||||
show_parent = self,
|
||||
callback = function() self:setProgress(self.fl_cur - 1, step) end,
|
||||
@@ -185,7 +196,7 @@ function FrontLightWidget:setProgress(num, step, num_warmth)
|
||||
text = "+1",
|
||||
margin = Size.margin.small,
|
||||
radius = 0,
|
||||
enabled = enable_button_plus,
|
||||
enabled = enable_button_plus and not self.light_fallback,
|
||||
width = self.screen_width * 0.20,
|
||||
show_parent = self,
|
||||
callback = function() self:setProgress(self.fl_cur + 1, step) end,
|
||||
@@ -200,7 +211,7 @@ function FrontLightWidget:setProgress(num, step, num_warmth)
|
||||
text = _("Min"),
|
||||
margin = Size.margin.small,
|
||||
radius = 0,
|
||||
enabled = true,
|
||||
enabled = not self.light_fallback,
|
||||
width = self.screen_width * 0.20,
|
||||
show_parent = self,
|
||||
callback = function() self:setProgress(self.fl_min+1, step) end, -- min is 1 (use toggle for 0)
|
||||
@@ -209,7 +220,7 @@ function FrontLightWidget:setProgress(num, step, num_warmth)
|
||||
text = _("Max"),
|
||||
margin = Size.margin.small,
|
||||
radius = 0,
|
||||
enabled = true,
|
||||
enabled = not self.light_fallback,
|
||||
width = self.screen_width * 0.20,
|
||||
show_parent = self,
|
||||
callback = function() self:setProgress(self.fl_max, step) end,
|
||||
@@ -218,7 +229,7 @@ function FrontLightWidget:setProgress(num, step, num_warmth)
|
||||
text = _("Toggle"),
|
||||
margin = Size.margin.small,
|
||||
radius = 0,
|
||||
enabled = true,
|
||||
enabled = not self.light_fallback,
|
||||
width = self.screen_width * 0.20,
|
||||
show_parent = self,
|
||||
callback = function()
|
||||
@@ -247,6 +258,20 @@ function FrontLightWidget:setProgress(num, step, num_warmth)
|
||||
-- widgets below.
|
||||
table.insert(vertical_group, text_br)
|
||||
end
|
||||
local system_level_checkbutton
|
||||
system_level_checkbutton = CheckButton:new{
|
||||
text = _("Use system settings"),
|
||||
checked = self.light_fallback,
|
||||
callback = function()
|
||||
if system_level_checkbutton.checked then
|
||||
self.light_fallback = false
|
||||
else
|
||||
self.light_fallback = true
|
||||
end
|
||||
G_reader_settings:saveSetting("light_fallback", self.light_fallback)
|
||||
self:setProgress(self.fl_cur, step)
|
||||
end,
|
||||
}
|
||||
table.insert(button_group_up, button_table_up)
|
||||
table.insert(button_group_down, button_table_down)
|
||||
table.insert(vertical_group, padding_span)
|
||||
@@ -256,6 +281,10 @@ function FrontLightWidget:setProgress(num, step, num_warmth)
|
||||
table.insert(vertical_group, padding_span)
|
||||
table.insert(vertical_group, button_group_down)
|
||||
table.insert(vertical_group, padding_span)
|
||||
if self.use_system_fl then
|
||||
table.insert(vertical_group, system_level_checkbutton)
|
||||
table.insert(vertical_group, padding_span)
|
||||
end
|
||||
if self.natural_light then
|
||||
-- If the device supports natural light, add the widgets for 'warmth',
|
||||
-- as well as a 'Configure' button for devices *without* a mixer
|
||||
|
||||
Submodule platform/android/luajit-launcher updated: 4c8319700f...3750551c66
Reference in New Issue
Block a user