mirror of
https://github.com/koreader/koreader.git
synced 2025-08-10 00:52:38 +00:00
fullscreen toggle for Jelly Bean devices
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
local Generic = require("device/generic/device")
|
||||
local A, android = pcall(require, "android") -- luacheck: ignore
|
||||
local Geom = require("ui/geometry")
|
||||
local ffi = require("ffi")
|
||||
local C = ffi.C
|
||||
local lfs = require("libs/libkoreader-lfs")
|
||||
@@ -132,6 +133,11 @@ function Device:init()
|
||||
android.setWakeLock(true)
|
||||
end
|
||||
|
||||
-- check if we disable fullscreen support
|
||||
if G_reader_settings:isTrue("disable_android_fullscreen") then
|
||||
self:toggleFullscreen()
|
||||
end
|
||||
|
||||
Generic.init(self)
|
||||
end
|
||||
|
||||
@@ -165,6 +171,34 @@ function Device:retrieveNetworkInfo()
|
||||
end
|
||||
end
|
||||
|
||||
function Device:setViewport(x,y,w,h)
|
||||
logger.info(string.format("Switching viewport to new geometry [x=%d,y=%d,w=%d,h=%d]",x, y, w, h))
|
||||
local viewport = Geom:new{x=x, y=y, w=w, h=h}
|
||||
self.screen:setViewport(viewport)
|
||||
end
|
||||
|
||||
function Device:toggleFullscreen()
|
||||
local api = android.app.activity.sdkVersion
|
||||
if api >= 19 then
|
||||
logger.dbg("ignoring fullscreen toggle, reason: always in immersive mode")
|
||||
elseif api < 19 and api >= 17 then
|
||||
local width = android.getScreenWidth()
|
||||
local height = android.getScreenHeight()
|
||||
local available_height = android.getScreenAvailableHeight()
|
||||
local is_fullscreen = android.isFullscreen()
|
||||
android.setFullscreen(not is_fullscreen)
|
||||
G_reader_settings:saveSetting("disable_android_fullscreen", is_fullscreen)
|
||||
is_fullscreen = android.isFullscreen()
|
||||
if is_fullscreen then
|
||||
self:setViewport(0, 0, width, height)
|
||||
else
|
||||
self:setViewport(0, 0, width, available_height)
|
||||
end
|
||||
else
|
||||
logger.dbg("ignoring fullscreen toggle, reason: legacy api " .. api)
|
||||
end
|
||||
end
|
||||
|
||||
function Device:info()
|
||||
local is_eink, eink_platform = android.isEink()
|
||||
|
||||
|
||||
@@ -181,8 +181,8 @@ if Device:isAndroid() then
|
||||
}
|
||||
end
|
||||
|
||||
-- fullscreen toggle on devices with compatible fullscreen methods (apis 14-16)
|
||||
if Device.firmware_rev <= 16 then
|
||||
-- fullscreen toggle on devices with compatible fullscreen methods (apis 14-18)
|
||||
if Device.firmware_rev < 19 then
|
||||
common_settings.fullscreen = {
|
||||
text = _("Fullscreen"),
|
||||
checked_func = function() return android.isFullscreen() end,
|
||||
|
||||
@@ -2,6 +2,7 @@ local isAndroid, android = pcall(require, "android")
|
||||
local Device = require("device")
|
||||
local Geom = require("ui/geometry")
|
||||
local logger = require("logger")
|
||||
local _ = require("gettext")
|
||||
local Input = Device.input
|
||||
local Screen = Device.screen
|
||||
|
||||
@@ -9,8 +10,23 @@ if not isAndroid then return end
|
||||
|
||||
local ScreenHelper = {}
|
||||
|
||||
-- toggle android status bar visibility
|
||||
function ScreenHelper:toggleFullscreen()
|
||||
local api = Device.firmware_rev
|
||||
|
||||
if api < 19 and api >= 17 then
|
||||
Device:toggleFullscreen()
|
||||
local UIManager = require("ui/uimanager")
|
||||
local InfoMessage = require("ui/widget/infomessage")
|
||||
UIManager:show(InfoMessage:new{
|
||||
text = _("This will take effect on next restart.")
|
||||
})
|
||||
elseif api < 17 then
|
||||
self:toggleFullscreenLegacy()
|
||||
end
|
||||
end
|
||||
|
||||
-- toggle android status bar visibility -- Legacy function for Apis 14 - 16
|
||||
function ScreenHelper:toggleFullscreenLegacy()
|
||||
-- toggle android status bar visibility
|
||||
local is_fullscreen = android.isFullscreen()
|
||||
android.setFullscreen(not is_fullscreen)
|
||||
|
||||
Reference in New Issue
Block a user