mirror of
https://github.com/koreader/koreader.git
synced 2025-08-10 00:52:38 +00:00
Merge pull request #638 from chrox/master
use two finger swipe west/east to close TOC and bookmark respectively
This commit is contained in:
@@ -61,7 +61,8 @@ function FileManager:init()
|
||||
if DocumentRegistry:getProvider(filename) then
|
||||
return true
|
||||
end
|
||||
end
|
||||
end,
|
||||
close_callback = function() return self:onClose() end,
|
||||
}
|
||||
self.file_chooser = file_chooser
|
||||
|
||||
@@ -154,6 +155,7 @@ function FileManager:toggleHiddenFiles()
|
||||
end
|
||||
|
||||
function FileManager:onClose()
|
||||
DEBUG("close filemanager")
|
||||
UIManager:close(self)
|
||||
if self.onExit then
|
||||
self:onExit()
|
||||
|
||||
@@ -31,7 +31,7 @@ function FileManagerMenu:init()
|
||||
}
|
||||
self.registered_widgets = {}
|
||||
|
||||
if Device:hasKeyboard() then
|
||||
if Device:hasKeys() then
|
||||
self.key_events = {
|
||||
ShowMenu = { { "Menu" }, doc = "show menu" },
|
||||
}
|
||||
|
||||
@@ -7,6 +7,7 @@ local Geom = require("ui/geometry")
|
||||
local Screen = require("ui/screen")
|
||||
local UIManager = require("ui/uimanager")
|
||||
local Event = require("ui/event")
|
||||
local Font = require("ui/font")
|
||||
local DEBUG = require("dbg")
|
||||
local _ = require("gettext")
|
||||
|
||||
@@ -99,10 +100,21 @@ function ReaderBookmark:onShowBookmark()
|
||||
local bm_menu = Menu:new{
|
||||
title = "Bookmarks",
|
||||
item_table = self.bookmarks,
|
||||
is_borderless = true,
|
||||
width = Screen:getWidth(),
|
||||
height = Screen:getHeight(),
|
||||
show_parent = menu_container,
|
||||
is_borderless = true,
|
||||
cface = Font:getFace("cfont", 20),
|
||||
on_close_ges = {
|
||||
GestureRange:new{
|
||||
ges = "two_finger_swipe",
|
||||
range = Geom:new{
|
||||
x = 0, y = 0,
|
||||
w = Screen:getWidth(),
|
||||
h = Screen:getHeight(),
|
||||
},
|
||||
direction = "east"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
local menu_container = CenterContainer:new{
|
||||
@@ -130,6 +142,8 @@ function ReaderBookmark:onShowBookmark()
|
||||
UIManager:close(menu_container)
|
||||
end
|
||||
|
||||
bm_menu.show_parent = menu_container
|
||||
|
||||
UIManager:show(menu_container)
|
||||
return true
|
||||
end
|
||||
|
||||
@@ -12,13 +12,6 @@ local _ = require("gettext")
|
||||
local ReaderHighlight = InputContainer:new{}
|
||||
|
||||
function ReaderHighlight:init()
|
||||
if Device:hasKeyboard() then
|
||||
self.key_events = {
|
||||
ShowToc = {
|
||||
{ "." },
|
||||
doc = "highlight text" },
|
||||
}
|
||||
end
|
||||
self.ui.menu:registerToMainMenu(self)
|
||||
end
|
||||
|
||||
@@ -310,6 +303,7 @@ function ReaderHighlight:onHoldRelease(arg, ges)
|
||||
{
|
||||
{
|
||||
text = _("Translate"),
|
||||
enabled = false,
|
||||
callback = function()
|
||||
self:translate(self.selected_text)
|
||||
UIManager:close(self.highlight_dialog)
|
||||
|
||||
@@ -43,9 +43,10 @@ function ReaderMenu:init()
|
||||
}
|
||||
self.registered_widgets = {}
|
||||
|
||||
if Device:hasKeyboard() then
|
||||
if Device:hasKeys() then
|
||||
self.key_events = {
|
||||
ShowReaderMenu = { { "Menu" }, doc = "show menu" },
|
||||
Close = { { "Back" }, doc = "close menu" },
|
||||
}
|
||||
end
|
||||
end
|
||||
|
||||
@@ -25,7 +25,7 @@ local ReaderPaging = InputContainer:new{
|
||||
}
|
||||
|
||||
function ReaderPaging:init()
|
||||
if Device:hasKeyboard() then
|
||||
if Device:hasKeyboard() or Device:hasKeys() then
|
||||
self.key_events = {
|
||||
GotoNextPage = {
|
||||
{Input.group.PgFwd}, doc = "go to next page",
|
||||
|
||||
@@ -23,7 +23,7 @@ local ReaderRolling = InputContainer:new{
|
||||
}
|
||||
|
||||
function ReaderRolling:init()
|
||||
if Device:hasKeyboard() then
|
||||
if Device:hasKeyboard() or Device:hasKeys() then
|
||||
self.key_events = {
|
||||
GotoNextView = {
|
||||
{ Input.group.PgFwd },
|
||||
|
||||
@@ -7,6 +7,8 @@ local Screen = require("ui/screen")
|
||||
local Device = require("ui/device")
|
||||
local UIManager = require("ui/uimanager")
|
||||
local Event = require("ui/event")
|
||||
local Font = require("ui/font")
|
||||
local DEBUG = require("dbg")
|
||||
local _ = require("gettext")
|
||||
|
||||
local ReaderToc = InputContainer:new{
|
||||
@@ -122,9 +124,21 @@ function ReaderToc:onShowToc()
|
||||
title = _("Table of Contents"),
|
||||
item_table = self.toc,
|
||||
ui = self.ui,
|
||||
is_borderless = true,
|
||||
width = Screen:getWidth(),
|
||||
height = Screen:getHeight(),
|
||||
is_borderless = true,
|
||||
cface = Font:getFace("cfont", 20),
|
||||
on_close_ges = {
|
||||
GestureRange:new{
|
||||
ges = "two_finger_swipe",
|
||||
range = Geom:new{
|
||||
x = 0, y = 0,
|
||||
w = Screen:getWidth(),
|
||||
h = Screen:getHeight(),
|
||||
},
|
||||
direction = "west"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
local menu_container = CenterContainer:new{
|
||||
|
||||
@@ -70,7 +70,7 @@ function ReaderUI:init()
|
||||
self.dialog = self
|
||||
end
|
||||
|
||||
if Device:hasKeyboard() then
|
||||
if Device:hasKeys() then
|
||||
self.key_events.Back = {
|
||||
{ "Back" }, doc = "close document",
|
||||
event = "Close" }
|
||||
|
||||
@@ -104,21 +104,31 @@ end
|
||||
|
||||
Device.isAndroid = util.isAndroid
|
||||
|
||||
function Device:hasNoKeyboard()
|
||||
if self.has_no_keyboard ~= nil then return self.has_no_keyboard end
|
||||
-- device has qwerty keyboard
|
||||
function Device:hasKeyboard()
|
||||
if self.has_keyboard ~= nil then return self.has_keyboard end
|
||||
if not isAndroid then
|
||||
local model = self:getModel()
|
||||
self.has_no_keyboard = (model == "KindlePaperWhite") or (model == "KindlePaperWhite2")
|
||||
or (model == "KindleTouch") or self:isKobo()
|
||||
self.has_keyboard = (model == "Kindle2") or (model == "Kindle3")
|
||||
or util.isEmulated()
|
||||
else
|
||||
self.has_no_keyboard = ffi.C.AConfiguration_getKeyboard(android.app.config)
|
||||
~= ffi.C.ACONFIGURATION_KEYBOARD_QWERTY
|
||||
self.has_keyboard = ffi.C.AConfiguration_getKeyboard(android.app.config)
|
||||
== ffi.C.ACONFIGURATION_KEYBOARD_QWERTY
|
||||
end
|
||||
return self.has_no_keyboard
|
||||
return self.has_keyboard
|
||||
end
|
||||
|
||||
function Device:hasKeyboard()
|
||||
return not self:hasNoKeyboard()
|
||||
function Device:hasNoKeyboard()
|
||||
return not self:hasKeyboard()
|
||||
end
|
||||
|
||||
-- device has hardware keys for pagedown/pageup
|
||||
function Device:hasKeys()
|
||||
if self.has_keys ~= nil then return self.has_keys end
|
||||
local model = self:getModel()
|
||||
self.has_keys = (model ~= "KindlePaperWhite") and (model ~= "KindlePaperWhite2")
|
||||
and (model ~= "KindleTouch") and not self:isKobo()
|
||||
return self.has_keys
|
||||
end
|
||||
|
||||
function Device:isTouchDevice()
|
||||
|
||||
@@ -245,6 +245,35 @@ function Input:initKeyMap()
|
||||
[78] = "RPgFwd", -- normal PageDown
|
||||
[76] = "Del", -- Delete
|
||||
}
|
||||
self.android_event_map = {
|
||||
[29] = "A", [30] = "B", [31] = "C", [32] = "D", [33] = "E", [34] = "F",
|
||||
[35] = "G", [36] = "H", [37] = "I", [38] = "J", [39] = "K", [40] = "L",
|
||||
[41] = "M", [42] = "N", [43] = "O", [44] = "P", [45] = "Q", [46] = "R",
|
||||
[47] = "S", [48] = "T", [49] = "U", [50] = "V", [51] = "W", [52] = "X",
|
||||
[53] = "Y", [54] = "Z", [ 7] = "0", [ 8] = "1", [ 9] = "2", [10] = "3",
|
||||
[11] = "4", [12] = "5", [13] = "6", [14] = "7", [15] = "8", [16] = "9",
|
||||
|
||||
[4] = "Back", -- BACK
|
||||
[19] = "Up", -- DPAD_UP
|
||||
[20] = "Down", -- DPAD_UP
|
||||
[21] = "Left", -- DPAD_LEFT
|
||||
[22] = "Right", -- DPAD_RIGHT
|
||||
[23] = "Press", -- DPAD_CENTER
|
||||
[24] = "LPgBack", -- VOLUME_UP
|
||||
[25] = "LPgFwd", -- VOLUME_DOWN
|
||||
[56] = ".", -- PERIOD
|
||||
[59] = "Shift", -- SHIFT_LEFT
|
||||
[60] = "Shift", -- SHIFT_RIGHT
|
||||
[62] = " ", -- SPACE
|
||||
[63] = "Sym", -- SYM
|
||||
[66] = "Enter", -- ENTER
|
||||
[67] = "Del", -- DEL
|
||||
[76] = "/", -- SLASH
|
||||
[82] = "Menu", -- MENU
|
||||
[84] = "Search",--SEARCH
|
||||
[92] = "LPgBack", -- PAGE_UP
|
||||
[93] = "LPgFwd", -- PAGE_DOWN
|
||||
}
|
||||
|
||||
self.modifiers = {
|
||||
Alt = false,
|
||||
@@ -426,6 +455,7 @@ function Input:init()
|
||||
input.open("/dev/input/event1")
|
||||
elseif util.isAndroid() then
|
||||
DEBUG("Auto-detected Android")
|
||||
self.event_map = self.android_event_map
|
||||
self:adjustAndroidEventMap()
|
||||
function Input:handleMiscEv(ev)
|
||||
return Input:handleAndroidMiscEvent(ev)
|
||||
@@ -467,6 +497,9 @@ function Input:adjustKoboEventMap()
|
||||
end
|
||||
|
||||
function Input:adjustAndroidEventMap()
|
||||
self.event_map[104] = "LPgBack" -- T68 PageUp
|
||||
self.event_map[109] = "LPgFwd" -- T68 PageDown
|
||||
self.event_map[139] = "Menu" -- T68 Menu
|
||||
end
|
||||
|
||||
function Input:setTimeout(cb, tv_out)
|
||||
|
||||
@@ -16,10 +16,9 @@ local ButtonDialog = InputContainer:new{
|
||||
}
|
||||
|
||||
function ButtonDialog:init()
|
||||
if Device:hasKeyboard() then
|
||||
if Device:hasKeys() then
|
||||
self.key_events = {
|
||||
AnyKeyPressed = { { Input.group.Any },
|
||||
seqtext = "any key", doc = "close dialog" }
|
||||
Close = { {"Back"}, doc = "close button dialog" }
|
||||
}
|
||||
end
|
||||
if Device:isTouchDevice() then
|
||||
@@ -58,4 +57,9 @@ function ButtonDialog:onTapClose()
|
||||
return true
|
||||
end
|
||||
|
||||
function ButtonDialog:onClose()
|
||||
self:onTapClose()
|
||||
return true
|
||||
end
|
||||
|
||||
return ButtonDialog
|
||||
|
||||
@@ -459,7 +459,8 @@ function ConfigDialog:init()
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
end
|
||||
if Device:hasKeys() then
|
||||
-- set up keyboard events
|
||||
self.key_events.Close = { {"Back"}, doc = "close config menu" }
|
||||
-- we won't catch presses to "Right"
|
||||
@@ -551,4 +552,9 @@ function ConfigDialog:onTapCloseMenu(arg, ges_ev)
|
||||
end
|
||||
end
|
||||
|
||||
function ConfigDialog:onClose()
|
||||
self:closeDialog()
|
||||
return true
|
||||
end
|
||||
|
||||
return ConfigDialog
|
||||
|
||||
@@ -46,6 +46,11 @@ local DictQuickLookup = InputContainer:new{
|
||||
|
||||
function DictQuickLookup:init()
|
||||
self:changeToDefaultDict()
|
||||
if Device:hasKeys() then
|
||||
self.key_events = {
|
||||
Close = { {"Back"}, doc = "close quick lookup" }
|
||||
}
|
||||
end
|
||||
if Device:isTouchDevice() then
|
||||
self.ges_events = {
|
||||
TapCloseDict = {
|
||||
|
||||
@@ -26,7 +26,7 @@ local InfoMessage = InputContainer:new{
|
||||
}
|
||||
|
||||
function InfoMessage:init()
|
||||
if Device:hasKeyboard() then
|
||||
if Device:hasKeys() then
|
||||
self.key_events = {
|
||||
AnyKeyPressed = { { Input.group.Any },
|
||||
seqtext = "any key", doc = "close dialog" }
|
||||
|
||||
@@ -23,6 +23,7 @@ local Input = require("ui/input")
|
||||
local UIManager = require("ui/uimanager")
|
||||
local RenderText = require("ui/rendertext")
|
||||
local InfoMessage = require("ui/widget/infomessage")
|
||||
local DEBUG = require("dbg")
|
||||
local _ = require("gettext")
|
||||
|
||||
--[[
|
||||
@@ -152,7 +153,7 @@ function MenuItem:init()
|
||||
},
|
||||
}
|
||||
end
|
||||
if Device:hasKeyboard() then
|
||||
if Device:hasKeys() then
|
||||
self.active_key_events = {
|
||||
Select = { {"Press"}, doc = "chose selected item" },
|
||||
}
|
||||
@@ -276,7 +277,7 @@ local Menu = FocusManager:new{
|
||||
-- face for menu title
|
||||
tface = Font:getFace("tfont", 26),
|
||||
-- face for paging info display
|
||||
fface = Font:getFace("ffont", 16),
|
||||
fface = Font:getFace("ffont", 20),
|
||||
-- font for item shortcut
|
||||
sface = Font:getFace("scfont", 20),
|
||||
|
||||
@@ -446,8 +447,9 @@ function Menu:init()
|
||||
range = self.dimen,
|
||||
}
|
||||
}
|
||||
self.ges_events.Close = self.on_close_ges
|
||||
end
|
||||
if Device:hasKeyboard() then
|
||||
if Device:hasKeys() then
|
||||
-- set up keyboard events
|
||||
self.key_events.Close = { {"Back"}, doc = "close menu" }
|
||||
self.key_events.NextPage = {
|
||||
|
||||
@@ -22,7 +22,7 @@ local Notification = InputContainer:new{
|
||||
}
|
||||
|
||||
function Notification:init()
|
||||
if Device:hasKeyboard() then
|
||||
if Device:hasKeys() then
|
||||
self.key_events = {
|
||||
AnyKeyPressed = { { Input.group.Any }, seqtext = "any key", doc = "close dialog" }
|
||||
}
|
||||
|
||||
@@ -215,7 +215,7 @@ local TouchMenu = InputContainer:new{
|
||||
bordersize = Screen:scaleByDPI(2),
|
||||
padding = Screen:scaleByDPI(5),
|
||||
footer_height = Screen:scaleByDPI(50),
|
||||
fface = Font:getFace("ffont", 16),
|
||||
fface = Font:getFace("ffont", 20),
|
||||
width = nil,
|
||||
height = nil,
|
||||
page = 1,
|
||||
@@ -251,6 +251,8 @@ function TouchMenu:init()
|
||||
}
|
||||
}
|
||||
|
||||
self.key_events.Close = { {"Back"}, doc = "close touch menu" }
|
||||
|
||||
local icons = {}
|
||||
for _,v in ipairs(self.tab_item_table) do
|
||||
table.insert(icons, v.icon)
|
||||
@@ -498,4 +500,8 @@ function TouchMenu:onTapCloseAllMenus(arg, ges_ev)
|
||||
end
|
||||
end
|
||||
|
||||
function TouchMenu:onClose()
|
||||
self:closeMenu()
|
||||
end
|
||||
|
||||
return TouchMenu
|
||||
|
||||
Reference in New Issue
Block a user