From 0a4a092d12372f1db72a1f971174c4535869f510 Mon Sep 17 00:00:00 2001 From: chrox Date: Mon, 26 May 2014 23:38:51 +0800 Subject: [PATCH] initial commit for android port of koreader This PR just shows how far we have went to the android port. There is still a few steps before a running android port. --- .gitmodules | 3 +++ Makefile | 19 ++++++++++++++----- android/luajit-launcher | 1 + frontend/dbg.lua | 13 ++++++++++--- frontend/ui/device.lua | 2 +- frontend/ui/input.lua | 38 ++++++++++++++++---------------------- koreader-base | 2 +- 7 files changed, 46 insertions(+), 32 deletions(-) create mode 160000 android/luajit-launcher diff --git a/.gitmodules b/.gitmodules index f7891087a..a2d3e4ab2 100644 --- a/.gitmodules +++ b/.gitmodules @@ -1,3 +1,6 @@ [submodule "koreader-base"] path = koreader-base url = git://github.com/koreader/koreader-base.git +[submodule "android/luajit-launcher"] + path = android/luajit-launcher + url = https://github.com/hwhw/android-luajit-launcher.git diff --git a/Makefile b/Makefile index 1c06b9821..77a4c516a 100644 --- a/Makefile +++ b/Makefile @@ -14,6 +14,8 @@ export PATH:=$(CURDIR)/$(KOR_BASE)/toolchain/android-toolchain/bin:$(PATH) MACHINE?=$(shell PATH=$(PATH) $(CC) -dumpmachine 2>/dev/null) INSTALL_DIR=koreader-$(MACHINE) +ANDROID_LAUNCHER_DIR:=android/luajit-launcher + # files to link from main directory INSTALL_FILES=reader.lua frontend resources defaults.lua l10n \ git-rev README.md COPYING @@ -97,7 +99,8 @@ kindleupdate: all zip -9 -r \ ../koreader-kindle-$(MACHINE)-$(VERSION).zip \ extensions koreader launchpad \ - -x "koreader/resources/fonts/*" "koreader/resources/icons/src/*" "koreader/spec/*" + -x "koreader/resources/fonts/*" \ + "koreader/resources/icons/src/*" "koreader/spec/*" # @TODO write an installation script for KUAL (houqp) koboupdate: all @@ -119,11 +122,17 @@ koboupdate: all zip -9 -r \ ../koreader-kobo-$(MACHINE)-$(VERSION).zip \ KoboRoot.tgz koreader koreader.png README_kobo.txt \ - -x "koreader/resources/fonts/*" "koreader/resources/icons/src/*" "koreader/spec/*" + -x "koreader/resources/fonts/*" \ + "koreader/resources/icons/src/*" "koreader/spec/*" -androidupdate: - cd $(INSTALL_DIR)/koreader && \ - 7z a -l -mx=5 ../koreader-g$(REVISION).7z * +androidupdate: all + mkdir -p $(ANDROID_LAUNCHER_DIR)/assets/module + -rm $(ANDROID_LAUNCHER_DIR)/assets/module/koreader-* + cd $(INSTALL_DIR)/koreader && 7z a -l -mx=3 \ + ../../$(ANDROID_LAUNCHER_DIR)/assets/module/koreader-g$(REVISION).7z * + +androiddev: androidupdate + $(MAKE) -C $(ANDROID_LAUNCHER_DIR) dev pot: $(XGETTEXT_BIN) reader.lua `find frontend -iname "*.lua"` \ diff --git a/android/luajit-launcher b/android/luajit-launcher new file mode 160000 index 000000000..48e3a1aa4 --- /dev/null +++ b/android/luajit-launcher @@ -0,0 +1 @@ +Subproject commit 48e3a1aa4fbe6919e452f2bfee8d620eb79c71d3 diff --git a/frontend/dbg.lua b/frontend/dbg.lua index 7b19fa2e6..948f82315 100644 --- a/frontend/dbg.lua +++ b/frontend/dbg.lua @@ -1,4 +1,5 @@ local DocSettings = require("docsettings") -- for dump method +local isAndroid, android = pcall(require, "android") local Dbg = { is_on = false, @@ -16,7 +17,11 @@ local function LvDEBUG(lv, ...) line = line .. " " .. tostring(v) end end - print("#"..line) + if isAndroid then + android.LOGI("#"..line) + else + print("#"..line) + end end function Dbg_mt.__call(dbg, ...) @@ -27,8 +32,10 @@ function Dbg:turnOn() self.is_on = true -- create or clear ev log file - os.execute("echo > ev.log") - self.ev_log = io.open("ev.log", "w") + if not isAndroid then + os.execute("echo > ev.log") + self.ev_log = io.open("ev.log", "w") + end end function Dbg:logEv(ev) diff --git a/frontend/ui/device.lua b/frontend/ui/device.lua index 2526b50c3..c83dd59a2 100644 --- a/frontend/ui/device.lua +++ b/frontend/ui/device.lua @@ -97,7 +97,7 @@ function Device:isKindle2() end function Device:isKobo() - return string.find(self:getModel(),"Kobo_") == 1 + return string.find(self:getModel() or "", "Kobo_") == 1 end function Device:hasNoKeyboard() diff --git a/frontend/ui/input.lua b/frontend/ui/input.lua index e35225b21..4f3de7012 100644 --- a/frontend/ui/input.lua +++ b/frontend/ui/input.lua @@ -4,7 +4,6 @@ local Event = require("ui/event") local TimeVal = require("ui/timeval") local Screen = require("ui/screen") local Math = require("optmath") -local Dbg = require("dbg") local DEBUG = require("dbg") local _ = require("gettext") @@ -286,11 +285,11 @@ function Input:init() input.open("fake_events") end if dev_mod == "KindlePaperWhite" then - print("Auto-detected Kindle PaperWhite") + DEBUG("Auto-detected Kindle PaperWhite") Device:setTouchInputDev("/dev/input/event0") input.open("/dev/input/event0") elseif dev_mod == "KindlePaperWhite2" then - print("Auto-detected Kindle PaperWhite") + DEBUG("Auto-detected Kindle PaperWhite") Device:setTouchInputDev("/dev/input/event1") input.open("/dev/input/event1") elseif dev_mod == "KindleTouch" then @@ -314,17 +313,11 @@ function Input:init() end return ev end - print("Auto-detected Kindle Touch") - elseif Device:isKobo() then - local firm_rev = Device:getFirmVer() - input.open("/dev/input/event1") - Device:setTouchInputDev("/dev/input/event1") - input.open("/dev/input/event0") -- Light button and sleep slider - print("Auto-detected Kobo") - print("Device model=", dev_mod) - print("Firmware revision", firm_rev) - print("Screen width =", Screen:getWidth()) - print("Screen height =", Screen:getHeight()) + DEBUG("Auto-detected Kobo") + DEBUG("Device model=", dev_mod) + DEBUG("Firmware revision", firm_rev) + DEBUG("Screen width =", Screen:getWidth()) + DEBUG("Screen height =", Screen:getHeight()) self:adjustKoboEventMap() if dev_mod ~= 'Kobo_trilogy' then function Input:eventAdjustHook(ev) @@ -374,22 +367,23 @@ function Input:init() end end elseif dev_mod == "Kindle4" then - print("Auto-detected Kindle 4") + DEBUG("Auto-detected Kindle 4") input.open("/dev/input/event1") self:adjustKindle4EventMap() elseif dev_mod == "Kindle3" then - print("Auto-detected Kindle 3") + DEBUG("Auto-detected Kindle 3") input.open("/dev/input/event1") input.open("/dev/input/event2") elseif dev_mod == "KindleDXG" then - print("Auto-detected Kindle DXG") + DEBUG("Auto-detected Kindle DXG") input.open("/dev/input/event1") elseif dev_mod == "Kindle2" then - print("Auto-detected Kindle 2") + DEBUG("Auto-detected Kindle 2") input.open("/dev/input/event1") + elseif util.isAndroid() then + DEBUG("Auto-detected Android") else - print("Not supported device model!") - os.exit(-1) + DEBUG("Not supported device model!") end end @@ -711,8 +705,8 @@ function Input:waitEvent(timeout_us, timeout_s) end if ok and ev then - if Dbg.is_on and ev then - Dbg:logEv(ev) + if DEBUG.is_on and ev then + DEBUG:logEv(ev) end ev = self:eventAdjustHook(ev) if ev.type == EV_KEY then diff --git a/koreader-base b/koreader-base index 648148e30..0a3acc6bc 160000 --- a/koreader-base +++ b/koreader-base @@ -1 +1 @@ -Subproject commit 648148e3065a1019438f34c7c9b1b47653c0dab7 +Subproject commit 0a3acc6bc64fbe42b7072d5100724992faca1514