2018-07-28 18:18:31 +00:00
|
|
|
local ConfirmBox = require("ui/widget/confirmbox")
|
2015-10-03 06:18:47 +00:00
|
|
|
local DataStorage = require("datastorage")
|
2018-07-28 18:18:31 +00:00
|
|
|
local GestureRange = require("ui/gesturerange")
|
|
|
|
local InputContainer = require("ui/widget/container/inputcontainer")
|
2013-10-18 20:38:07 +00:00
|
|
|
local UIManager = require("ui/uimanager")
|
2015-10-03 06:18:47 +00:00
|
|
|
local Screen = require("device").screen
|
2014-11-28 13:10:37 +00:00
|
|
|
local T = require("ffi/util").template
|
|
|
|
local _ = require("gettext")
|
2013-03-06 14:36:51 +00:00
|
|
|
|
2016-01-03 08:47:01 +00:00
|
|
|
local Screenshoter = InputContainer:new{
|
|
|
|
prefix = 'Screenshot',
|
2014-11-05 08:58:09 +00:00
|
|
|
}
|
2013-03-06 14:36:51 +00:00
|
|
|
|
2016-01-03 08:47:01 +00:00
|
|
|
function Screenshoter:init()
|
|
|
|
local screenshots_dir = DataStorage:getDataDir() .. "/screenshots/"
|
|
|
|
self.screenshot_fn_fmt = screenshots_dir .. self.prefix .. "_%Y-%b-%d_%H%M%S.png"
|
2014-03-13 13:52:43 +00:00
|
|
|
local diagonal = math.sqrt(
|
|
|
|
math.pow(Screen:getWidth(), 2) +
|
|
|
|
math.pow(Screen:getHeight(), 2)
|
|
|
|
)
|
|
|
|
self.ges_events = {
|
2014-06-17 13:12:42 +00:00
|
|
|
TapDiagonal = {
|
2014-03-13 13:52:43 +00:00
|
|
|
GestureRange:new{
|
|
|
|
ges = "two_finger_tap",
|
2014-11-20 22:07:39 +00:00
|
|
|
scale = {diagonal - Screen:scaleBySize(200), diagonal},
|
2014-03-13 13:52:43 +00:00
|
|
|
rate = 1.0,
|
|
|
|
}
|
|
|
|
},
|
2014-06-17 13:12:42 +00:00
|
|
|
SwipeDiagonal = {
|
|
|
|
GestureRange:new{
|
|
|
|
ges = "swipe",
|
2014-11-20 22:07:39 +00:00
|
|
|
scale = {diagonal - Screen:scaleBySize(200), diagonal},
|
2014-06-17 13:12:42 +00:00
|
|
|
rate = 1.0,
|
|
|
|
}
|
|
|
|
},
|
2014-03-13 13:52:43 +00:00
|
|
|
}
|
2013-03-06 14:36:51 +00:00
|
|
|
end
|
|
|
|
|
2016-01-03 08:47:01 +00:00
|
|
|
function Screenshoter:onScreenshot(filename)
|
|
|
|
local screenshot_name = filename or os.date(self.screenshot_fn_fmt)
|
2018-08-19 18:21:03 +00:00
|
|
|
Screen:shot(screenshot_name)
|
2018-07-28 18:18:31 +00:00
|
|
|
local widget = ConfirmBox:new{
|
2018-08-19 18:21:03 +00:00
|
|
|
text = T( _("Saved screenshot to %1.\nWould you like to set it as screensaver?"), screenshot_name),
|
2018-07-28 18:18:31 +00:00
|
|
|
ok_text = _("Yes"),
|
|
|
|
ok_callback = function()
|
|
|
|
G_reader_settings:saveSetting("screensaver_type", "image_file")
|
|
|
|
G_reader_settings:saveSetting("screensaver_image", screenshot_name)
|
|
|
|
end,
|
|
|
|
cancel_text = _("No"),
|
|
|
|
}
|
|
|
|
UIManager:show(widget)
|
2014-11-30 00:12:00 +00:00
|
|
|
-- trigger full refresh
|
|
|
|
UIManager:setDirty(nil, "full")
|
2014-03-13 13:52:43 +00:00
|
|
|
return true
|
2013-03-06 14:36:51 +00:00
|
|
|
end
|
|
|
|
|
2016-01-03 08:47:01 +00:00
|
|
|
function Screenshoter:onTapDiagonal()
|
2014-06-17 13:12:42 +00:00
|
|
|
return self:onScreenshot()
|
|
|
|
end
|
|
|
|
|
2016-01-03 08:47:01 +00:00
|
|
|
function Screenshoter:onSwipeDiagonal()
|
2014-06-17 13:12:42 +00:00
|
|
|
return self:onScreenshot()
|
|
|
|
end
|
|
|
|
|
2016-01-03 08:47:01 +00:00
|
|
|
return Screenshoter
|