mirror of
https://github.com/koreader/koreader.git
synced 2025-08-10 00:52:38 +00:00
[feat] Add haptic feedback (#5380)
References <https://github.com/koreader/koreader/issues/5374>.
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
local BookStatusWidget = require("ui/widget/bookstatuswidget")
|
||||
local ButtonDialogTitle = require("ui/widget/buttondialogtitle")
|
||||
local Device = require("device")
|
||||
local InfoMessage = require("ui/widget/infomessage")
|
||||
local InputContainer = require("ui/widget/container/inputcontainer")
|
||||
local UIManager = require("ui/uimanager")
|
||||
@@ -38,6 +39,7 @@ function ReaderStatus:addToMainMenu(menu_items)
|
||||
end
|
||||
|
||||
function ReaderStatus:onEndOfBook()
|
||||
Device:performHapticFeedback("CONTEXT_CLICK")
|
||||
local settings = G_reader_settings:readSetting("end_document_action")
|
||||
local choose_action
|
||||
local collate = true
|
||||
|
||||
@@ -1,3 +1,9 @@
|
||||
--[[--
|
||||
Generic device abstraction.
|
||||
|
||||
This module defines stubs for common methods.
|
||||
--]]
|
||||
|
||||
local logger = require("logger")
|
||||
local _ = require("gettext")
|
||||
|
||||
@@ -25,6 +31,7 @@ local Device = {
|
||||
hasDPad = no,
|
||||
hasWifiToggle = yes,
|
||||
hasWifiManager = no,
|
||||
isHapticFeedbackEnabled = no,
|
||||
isTouchDevice = no,
|
||||
hasFrontlight = no,
|
||||
hasLightLevelFallback = no,
|
||||
@@ -290,6 +297,13 @@ function Device:setDateTime(year, month, day, hour, min, sec) end
|
||||
-- Device specific method if any setting needs being saved
|
||||
function Device:saveSettings() end
|
||||
|
||||
--[[--
|
||||
Device specific method for performing haptic feedback.
|
||||
|
||||
@string type Type of haptic feedback. See <https://developer.android.com/reference/android/view/HapticFeedbackConstants.html>.
|
||||
--]]
|
||||
function Device:performHapticFeedback(type) end
|
||||
|
||||
-- Device specific method for toggling the GSensor
|
||||
function Device:toggleGSensor(toggle) end
|
||||
|
||||
|
||||
@@ -215,11 +215,21 @@ function Device:init()
|
||||
setClipboardText = function(text)
|
||||
return input.setClipboardText(text)
|
||||
end,
|
||||
gameControllerRumble = function(left_intensity, right_intensity, duration)
|
||||
return input.gameControllerRumble(left_intensity, right_intensity, duration)
|
||||
end,
|
||||
file_chooser = input.file_chooser,
|
||||
}
|
||||
|
||||
self.keyboard_layout = require("device/sdl/keyboard_layout")
|
||||
|
||||
if self.input.gameControllerRumble(0, 0, 0) then
|
||||
self.isHapticFeedbackEnabled = yes
|
||||
self.performHapticFeedback = function(type)
|
||||
self.input.gameControllerRumble()
|
||||
end
|
||||
end
|
||||
|
||||
if emulator and portrait then
|
||||
self.input:registerEventAdjustHook(self.input.adjustTouchSwitchXY)
|
||||
self.input:registerEventAdjustHook(
|
||||
|
||||
@@ -185,6 +185,7 @@ function VirtualKey:onUnfocus()
|
||||
end
|
||||
|
||||
function VirtualKey:onTapSelect(skip_flash)
|
||||
Device:performHapticFeedback("KEYBOARD_TAP")
|
||||
-- just in case it's not flipped to false on hold release where it's supposed to
|
||||
self.keyboard.ignore_first_hold_release = false
|
||||
if self.flash_keyboard and not skip_flash and not self.skiptap then
|
||||
@@ -203,6 +204,7 @@ function VirtualKey:onTapSelect(skip_flash)
|
||||
end
|
||||
|
||||
function VirtualKey:onHoldSelect()
|
||||
Device:performHapticFeedback("LONG_PRESS")
|
||||
if self.flash_keyboard and not self.skiphold then
|
||||
self[1].inner_bordersize = self.focused_bordersize
|
||||
self:update_keyboard(false, true)
|
||||
@@ -222,6 +224,7 @@ function VirtualKey:onHoldSelect()
|
||||
end
|
||||
|
||||
function VirtualKey:onSwipeKey(arg, ges)
|
||||
Device:performHapticFeedback("KEYBOARD_TAP")
|
||||
if self.flash_keyboard and not self.skipswipe then
|
||||
self[1].inner_bordersize = self.focused_bordersize
|
||||
self:update_keyboard(false, true)
|
||||
@@ -238,6 +241,7 @@ function VirtualKey:onSwipeKey(arg, ges)
|
||||
end
|
||||
|
||||
function VirtualKey:onHoldReleaseKey()
|
||||
Device:performHapticFeedback("LONG_PRESS")
|
||||
if self.keyboard.ignore_first_hold_release then
|
||||
self.keyboard.ignore_first_hold_release = false
|
||||
return true
|
||||
@@ -246,6 +250,7 @@ function VirtualKey:onHoldReleaseKey()
|
||||
end
|
||||
|
||||
function VirtualKey:onPanReleaseKey()
|
||||
Device:performHapticFeedback("LONG_PRESS")
|
||||
if self.keyboard.ignore_first_hold_release then
|
||||
self.keyboard.ignore_first_hold_release = false
|
||||
return true
|
||||
|
||||
Reference in New Issue
Block a user