2020-07-01 20:17:41 +00:00
local Device = require ( " device " )
local Event = require ( " ui/event " )
local FileManager = require ( " apps/filemanager/filemanager " )
local UIManager = require ( " ui/uimanager " )
2020-11-29 09:18:59 +00:00
local _ = require ( " gettext " )
local C_ = _.pgettext
2020-07-01 20:17:41 +00:00
local Screen = Device.screen
return {
text = _ ( " Rotation " ) ,
sub_item_table_func = function ( )
local rotation_table = { }
2022-12-21 14:50:39 +00:00
if Device : hasGSensor ( ) then
2020-07-01 20:17:41 +00:00
table.insert ( rotation_table , {
text = _ ( " Ignore accelerometer rotation events " ) ,
2020-07-09 17:11:44 +00:00
help_text = _ ( " This will inhibit automatic rotations triggered by your device's gyro. " ) ,
2020-07-01 20:17:41 +00:00
checked_func = function ( )
return G_reader_settings : isTrue ( " input_ignore_gsensor " )
end ,
callback = function ( )
2020-07-12 18:47:49 +00:00
UIManager : broadcastEvent ( Event : new ( " ToggleGSensor " ) )
2020-07-01 20:17:41 +00:00
end ,
} )
end
2020-07-09 17:11:44 +00:00
if Device : hasGSensor ( ) then
table.insert ( rotation_table , {
text = _ ( " Lock auto rotation to current orientation " ) ,
help_text = _ ( [ [
When checked , the gyro will only be honored when switching between the two inverse variants of your current rotation ,
i.e . , Portrait <-> Inverted Portrait OR Landscape <-> Inverted Landscape .
Switching between ( Inverted ) Portrait and ( Inverted ) Landscape will be inhibited .
If you need to do so , you ' ll have to use the UI toggles.]]),
enabled_func = function ( )
return G_reader_settings : nilOrFalse ( " input_ignore_gsensor " )
end ,
checked_func = function ( )
return G_reader_settings : isTrue ( " input_lock_gsensor " )
end ,
callback = function ( )
G_reader_settings : flipNilOrFalse ( " input_lock_gsensor " )
Device : lockGSensor ( G_reader_settings : isTrue ( " input_lock_gsensor " ) )
end ,
} )
end
2020-07-01 20:17:41 +00:00
table.insert ( rotation_table , {
2020-07-09 17:11:44 +00:00
text = _ ( " Keep current rotation across views " ) ,
help_text = _ ( [ [
When checked , the current rotation will be kept when switching between the file browser and the reader , in both directions , and that no matter what the document ' s saved rotation or the default reader or file browser rotation may be.
This means that nothing will ever sneak a rotation behind your back , you choose your device ' s rotation, and it stays that way.
When unchecked , the default rotation of the file browser and the default / saved reader rotation will not affect each other ( i.e . , they will be honored ) , and may very well be different . ] ] ) ,
2020-07-01 20:17:41 +00:00
checked_func = function ( )
return G_reader_settings : isTrue ( " lock_rotation " )
end ,
callback = function ( )
G_reader_settings : flipNilOrFalse ( " lock_rotation " )
end ,
separator = true ,
} )
if FileManager.instance then
table.insert ( rotation_table , {
text_func = function ( )
2020-11-29 09:18:59 +00:00
local text = C_ ( " Rotation " , " ⤹ 90° " )
2022-12-21 14:50:39 +00:00
if G_reader_settings : readSetting ( " fm_rotation_mode " ) == Screen.DEVICE_ROTATED_COUNTER_CLOCKWISE then
2020-07-01 20:17:41 +00:00
text = text .. " ★ "
end
return text
end ,
checked_func = function ( )
2022-12-21 14:50:39 +00:00
return Screen : getRotationMode ( ) == Screen.DEVICE_ROTATED_COUNTER_CLOCKWISE
2020-07-01 20:17:41 +00:00
end ,
2022-02-01 19:56:28 +00:00
radio = true ,
2020-07-01 20:17:41 +00:00
callback = function ( touchmenu_instance )
2022-12-21 14:50:39 +00:00
UIManager : broadcastEvent ( Event : new ( " SetRotationMode " , Screen.DEVICE_ROTATED_COUNTER_CLOCKWISE ) )
2020-07-01 20:17:41 +00:00
if touchmenu_instance then touchmenu_instance : closeMenu ( ) end
end ,
hold_callback = function ( touchmenu_instance )
2022-12-21 14:50:39 +00:00
G_reader_settings : saveSetting ( " fm_rotation_mode " , Screen.DEVICE_ROTATED_COUNTER_CLOCKWISE )
2020-07-01 20:17:41 +00:00
if touchmenu_instance then touchmenu_instance : updateItems ( ) end
end ,
} )
table.insert ( rotation_table , {
text_func = function ( )
2020-11-29 09:18:59 +00:00
local text = C_ ( " Rotation " , " ↑ 0° " )
2022-12-21 14:50:39 +00:00
if G_reader_settings : readSetting ( " fm_rotation_mode " ) == Screen.DEVICE_ROTATED_UPRIGHT then
2020-07-01 20:17:41 +00:00
text = text .. " ★ "
end
return text
end ,
checked_func = function ( )
2022-12-21 14:50:39 +00:00
return Screen : getRotationMode ( ) == Screen.DEVICE_ROTATED_UPRIGHT
2020-07-01 20:17:41 +00:00
end ,
2022-02-01 19:56:28 +00:00
radio = true ,
2020-07-01 20:17:41 +00:00
callback = function ( touchmenu_instance )
2022-12-21 14:50:39 +00:00
UIManager : broadcastEvent ( Event : new ( " SetRotationMode " , Screen.DEVICE_ROTATED_UPRIGHT ) )
2020-07-01 20:17:41 +00:00
if touchmenu_instance then touchmenu_instance : closeMenu ( ) end
end ,
hold_callback = function ( touchmenu_instance )
2022-12-21 14:50:39 +00:00
G_reader_settings : saveSetting ( " fm_rotation_mode " , Screen.DEVICE_ROTATED_UPRIGHT )
2020-07-01 20:17:41 +00:00
if touchmenu_instance then touchmenu_instance : updateItems ( ) end
end ,
} )
table.insert ( rotation_table , {
text_func = function ( )
2020-11-29 09:18:59 +00:00
local text = C_ ( " Rotation " , " ⤸ 90° " )
2022-12-21 14:50:39 +00:00
if G_reader_settings : readSetting ( " fm_rotation_mode " ) == Screen.DEVICE_ROTATED_CLOCKWISE then
2020-07-01 20:17:41 +00:00
text = text .. " ★ "
end
return text
end ,
checked_func = function ( )
2022-12-21 14:50:39 +00:00
return Screen : getRotationMode ( ) == Screen.DEVICE_ROTATED_CLOCKWISE
2020-07-01 20:17:41 +00:00
end ,
2022-02-01 19:56:28 +00:00
radio = true ,
2020-07-01 20:17:41 +00:00
callback = function ( touchmenu_instance )
2022-12-21 14:50:39 +00:00
UIManager : broadcastEvent ( Event : new ( " SetRotationMode " , Screen.DEVICE_ROTATED_CLOCKWISE ) )
2020-07-01 20:17:41 +00:00
if touchmenu_instance then touchmenu_instance : closeMenu ( ) end
end ,
hold_callback = function ( touchmenu_instance )
2022-12-21 14:50:39 +00:00
G_reader_settings : saveSetting ( " fm_rotation_mode " , Screen.DEVICE_ROTATED_CLOCKWISE )
2020-07-01 20:17:41 +00:00
if touchmenu_instance then touchmenu_instance : updateItems ( ) end
end ,
} )
table.insert ( rotation_table , {
text_func = function ( )
2020-11-29 09:18:59 +00:00
local text = C_ ( " Rotation " , " ↓ 180° " )
2022-12-21 14:50:39 +00:00
if G_reader_settings : readSetting ( " fm_rotation_mode " ) == Screen.DEVICE_ROTATED_UPSIDE_DOWN then
2020-07-01 20:17:41 +00:00
text = text .. " ★ "
end
return text
end ,
checked_func = function ( )
2022-12-21 14:50:39 +00:00
return Screen : getRotationMode ( ) == Screen.DEVICE_ROTATED_UPSIDE_DOWN
2020-07-01 20:17:41 +00:00
end ,
2022-02-01 19:56:28 +00:00
radio = true ,
2020-07-01 20:17:41 +00:00
callback = function ( touchmenu_instance )
2022-12-21 14:50:39 +00:00
UIManager : broadcastEvent ( Event : new ( " SetRotationMode " , Screen.DEVICE_ROTATED_UPSIDE_DOWN ) )
2020-07-01 20:17:41 +00:00
if touchmenu_instance then touchmenu_instance : closeMenu ( ) end
end ,
hold_callback = function ( touchmenu_instance )
2022-12-21 14:50:39 +00:00
G_reader_settings : saveSetting ( " fm_rotation_mode " , Screen.DEVICE_ROTATED_UPSIDE_DOWN )
2020-07-01 20:17:41 +00:00
if touchmenu_instance then touchmenu_instance : updateItems ( ) end
end ,
} )
end
return rotation_table
end ,
}