mirror of
https://github.com/koreader/koreader.git
synced 2025-08-10 00:52:38 +00:00
Merge pull request #611 from chrox/master
use android config interface to detect device keyboard and screen dpi
This commit is contained in:
1
.gitignore
vendored
1
.gitignore
vendored
@@ -17,6 +17,7 @@ spec/unit/data
|
||||
emu
|
||||
|
||||
koreader-*.zip
|
||||
koreader-*.apk
|
||||
|
||||
/.cproject
|
||||
/.project
|
||||
|
||||
Submodule android/luajit-launcher updated: 3cee0cff60...7a87eeb5f9
@@ -1,4 +1,5 @@
|
||||
local Geom = require("ui/geometry")
|
||||
local Blitbuffer = require("ffi/blitbuffer")
|
||||
local CreOptions = require("ui/data/creoptions")
|
||||
local Document = require("document/document")
|
||||
local Geom = require("ui/geometry")
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
local DrawContext = require("ffi/drawcontext")
|
||||
local Blitbuffer = require("ffi/blitbuffer")
|
||||
local Cache = require("cache")
|
||||
local CacheItem = require("cacheitem")
|
||||
local TileCacheItem = require("document/tilecacheitem")
|
||||
|
||||
@@ -104,12 +104,12 @@ local KoptOptions = {
|
||||
options = {
|
||||
{
|
||||
name = "font_size",
|
||||
item_text = {"Aa","Aa","Aa","Aa","Aa","Aa","Aa","Aa","Aa","Aa"},
|
||||
item_text = {"Aa","Aa","Aa","Aa","Aa","Aa","Aa","Aa"},
|
||||
item_align_center = 1.0,
|
||||
spacing = 15,
|
||||
height = 60,
|
||||
item_font_size = {22,24,28,32,34,36,38,42,46,50},
|
||||
values = {0.1, 0.2, 0.4, 0.6, 0.8, 1.0, 1.2, 1.6, 2.0, 4.0},
|
||||
item_font_size = {24,28,32,34,36,38,42,46},
|
||||
values = {0.2, 0.4, 0.6, 0.8, 1.0, 1.2, 1.6, 2.0},
|
||||
default_value = DKOPTREADER_CONFIG_FONT_SIZE,
|
||||
event = "FontSizeUpdate",
|
||||
},
|
||||
@@ -132,14 +132,14 @@ local KoptOptions = {
|
||||
{
|
||||
name = "contrast",
|
||||
name_text = S.CONTRAST,
|
||||
name_align_right = 0.2,
|
||||
item_text = {S.LIGHTEST , S.LIGHTER, S.DEFAULT, S.DARKER, S.DARKEST},
|
||||
name_align_right = 0.25,
|
||||
item_text = {S.LIGHTER, S.DEFAULT, S.DARKER, S.DARKEST},
|
||||
item_font_size = 18,
|
||||
item_align_center = 0.8,
|
||||
values = {2.0, 1.5, 1.0, 0.5, 0.2},
|
||||
item_align_center = 0.7,
|
||||
values = {1.5, 1.0, 0.5, 0.2},
|
||||
default_value = DKOPTREADER_CONFIG_CONTRAST,
|
||||
event = "GammaUpdate",
|
||||
args = {0.5, 0.8, 1.0, 2.0, 4.0},
|
||||
args = {0.8, 1.0, 2.0, 4.0},
|
||||
}
|
||||
}
|
||||
},
|
||||
|
||||
@@ -3,6 +3,8 @@ local KoboPowerD = require("ui/device/kobopowerd")
|
||||
local BasePowerD = require("ui/device/basepowerd")
|
||||
local Screen = require("ui/device/screen")
|
||||
local util = require("ffi/util")
|
||||
local ffi = require("ffi")
|
||||
local isAndroid, android = pcall(require, "android")
|
||||
-- lfs
|
||||
|
||||
local Device = {
|
||||
@@ -104,9 +106,14 @@ Device.isAndroid = util.isAndroid
|
||||
|
||||
function Device:hasNoKeyboard()
|
||||
if self.has_no_keyboard ~= nil then return self.has_no_keyboard end
|
||||
local model = self:getModel()
|
||||
self.has_no_keyboard = (model == "KindlePaperWhite") or (model == "KindlePaperWhite2")
|
||||
or (model == "KindleTouch") or self:isKobo() or self:isAndroid()
|
||||
if not isAndroid then
|
||||
local model = self:getModel()
|
||||
self.has_no_keyboard = (model == "KindlePaperWhite") or (model == "KindlePaperWhite2")
|
||||
or (model == "KindleTouch") or self:isKobo()
|
||||
else
|
||||
self.has_no_keyboard = ffi.C.AConfiguration_getKeyboard(android.app.config)
|
||||
~= ffi.C.ACONFIGURATION_KEYBOARD_QWERTY
|
||||
end
|
||||
return self.has_no_keyboard
|
||||
end
|
||||
|
||||
@@ -116,10 +123,14 @@ end
|
||||
|
||||
function Device:isTouchDevice()
|
||||
if self.is_touch_device ~= nil then return self.is_touch_device end
|
||||
local model = self:getModel()
|
||||
self.is_touch_device = (model == "KindlePaperWhite") or (model == "KindlePaperWhite2")
|
||||
or (model == "KindleTouch") or self:isKobo() or util.isEmulated()
|
||||
or util.isAndroid()
|
||||
if not isAndroid then
|
||||
local model = self:getModel()
|
||||
self.is_touch_device = (model == "KindlePaperWhite") or (model == "KindlePaperWhite2")
|
||||
or (model == "KindleTouch") or self:isKobo() or util.isEmulated()
|
||||
else
|
||||
self.is_touch_device = ffi.C.AConfiguration_getTouchscreen(android.app.config)
|
||||
~= ffi.C.ACONFIGURATION_TOUCHSCREEN_NOTOUCH
|
||||
end
|
||||
return self.is_touch_device
|
||||
end
|
||||
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
local Blitbuffer = require("ffi/blitbuffer")
|
||||
local Geom = require("ui/geometry")
|
||||
local DEBUG = require("dbg")
|
||||
|
||||
@@ -73,13 +74,17 @@ end
|
||||
function Screen:getDPI()
|
||||
if self.dpi ~= nil then return self.dpi end
|
||||
local model = self.device:getModel()
|
||||
if model == "KindlePaperWhite" or model == "KindlePaperWhite2"
|
||||
if model == "KindlePaperWhite" or model == "KindlePaperWhite2"
|
||||
or model == "Kobo_kraken" or model == "Kobo_phoenix" then
|
||||
self.dpi = 212
|
||||
elseif model == "Kobo_dragon" then
|
||||
self.dpi = 265
|
||||
elseif model == "Kobo_pixie" then
|
||||
self.dpi = 200
|
||||
elseif util.isAndroid() then
|
||||
local android = require("android")
|
||||
local ffi = require("ffi")
|
||||
self.dpi = ffi.C.AConfiguration_getDensity(android.app.config)
|
||||
else
|
||||
self.dpi = 167
|
||||
end
|
||||
|
||||
@@ -248,6 +248,21 @@ function ConfigOption:init()
|
||||
end
|
||||
end
|
||||
if self.options[c].item_text then
|
||||
local items_count = #self.options[c].item_text
|
||||
local middle_index = math.ceil(items_count/2)
|
||||
local middle_item = OptionTextItem:new{
|
||||
TextWidget:new{
|
||||
text = self.options[c].item_text[middle_index],
|
||||
face = Font:getFace(item_font_face,
|
||||
option_items_fixed and item_font_size[middle_index]
|
||||
or item_font_size),
|
||||
}
|
||||
}
|
||||
local max_item_spacing = (Screen:getWidth() * item_align -
|
||||
middle_item:getSize().w * items_count) / items_count
|
||||
local items_spacing = HorizontalSpan:new{
|
||||
width = math.min(max_item_spacing, Screen:scaleByDPI(item_spacing_with))
|
||||
}
|
||||
for d = 1, #self.options[c].item_text do
|
||||
local option_item = nil
|
||||
if option_items_fixed then
|
||||
@@ -285,6 +300,17 @@ function ConfigOption:init()
|
||||
end
|
||||
|
||||
if self.options[c].item_icons then
|
||||
local items_count = #self.options[c].item_icons
|
||||
local first_item = OptionIconItem:new{
|
||||
icon = ImageWidget:new{
|
||||
file = self.options[c].item_icons[1]
|
||||
}
|
||||
}
|
||||
local max_item_spacing = (Screen:getWidth() * item_align -
|
||||
first_item:getSize().w * items_count) / items_count
|
||||
local items_spacing = HorizontalSpan:new{
|
||||
width = math.min(max_item_spacing, Screen:scaleByDPI(item_spacing_with))
|
||||
}
|
||||
for d = 1, #self.options[c].item_icons do
|
||||
local option_item = OptionIconItem:new{
|
||||
icon = ImageWidget:new{
|
||||
@@ -293,12 +319,6 @@ function ConfigOption:init()
|
||||
padding = -2,
|
||||
color = d == current_item and 15 or 0,
|
||||
}
|
||||
local icons_count = #self.options[c].item_icons
|
||||
local min_item_spacing = (Screen:getWidth() * item_align -
|
||||
option_item:getSize().w * icons_count) / icons_count
|
||||
local items_spacing = HorizontalSpan:new{
|
||||
width = math.min(min_item_spacing, Screen:scaleByDPI(item_spacing_with))
|
||||
}
|
||||
option_items[d] = option_item
|
||||
option_item.items = option_items
|
||||
option_item.name = self.options[c].name
|
||||
@@ -315,8 +335,10 @@ function ConfigOption:init()
|
||||
end
|
||||
|
||||
if self.options[c].toggle then
|
||||
local max_toggle_width = Screen:getWidth() / 2
|
||||
local toggle_width = Screen:scaleByDPI(self.options[c].width or 216)
|
||||
local switch = ToggleSwitch:new{
|
||||
width = Screen:scaleByDPI(self.options[c].width or 216),
|
||||
width = math.min(max_toggle_width, toggle_width),
|
||||
name = self.options[c].name,
|
||||
toggle = self.options[c].toggle,
|
||||
alternate = self.options[c].alternate,
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
local Blitbuffer = require("ffi/blitbuffer")
|
||||
local Widget = require("ui/widget/widget")
|
||||
local RenderText = require("ui/rendertext")
|
||||
local Screen = require("ui/screen")
|
||||
@@ -71,7 +72,7 @@ However string.gmatch() has one significant disadvantage for me:
|
||||
You can't split a string while matching both the delimited
|
||||
strings and the delimiters themselves without tracking positions
|
||||
and substrings. The string.gsplit() function below takes care of
|
||||
this problem.
|
||||
this problem.
|
||||
Author: Peter Odding
|
||||
License: MIT/X11
|
||||
Source: http://snippets.luacode.org/snippets/String_splitting_130
|
||||
|
||||
Submodule koreader-base updated: 271d3dcede...dc61f9e2ca
Reference in New Issue
Block a user