Skip to content

[finished]Android fullscreen switcher #2938

Merged
Frenzie merged 23 commits intokoreader:masterfrom
mwoz123:Android_Fullscreen_switcher
Sep 17, 2017
Merged

[finished]Android fullscreen switcher #2938
Frenzie merged 23 commits intokoreader:masterfrom
mwoz123:Android_Fullscreen_switcher

Conversation

@mwoz123
Copy link
Copy Markdown
Contributor

@mwoz123 mwoz123 commented Jun 4, 2017

Require newest koreader/android-luajit-launcher#50

Marking this PR as w.i.p. (work in progress) as I wasn't able to test it.

Gives ability to see top menu bar in android (#2902)

Help appreciated.

@mwoz123 mwoz123 changed the title [w.i.p]Android fullscreen switcher - initial commit [w.i.p]Android fullscreen switcher Jun 4, 2017
require("ui/elements/screen_eink_opt_menu_table"),
require("ui/elements/screen_disable_double_tap_table"),
require("ui/elements/refresh_menu_table"),
require("ui/elements/refresh_menu_table")
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you keep the comma?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ok.

G_reader_settings:saveSetting("disable_fullscreen", not disabled)
android.setFullscreen(disabled)
UIManager:show(InfoMessage:new{
text = _("This will take effect on next restart."),
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's better to be specific. "The fullscreen setting (or whatever) will take effect…"

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ok

require("ui/elements/screen_eink_opt_menu_table"),
require("ui/elements/screen_disable_double_tap_table"),
require("ui/elements/refresh_menu_table"),
require("ui/elements/refresh_menu_table")
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please note that adding a comma at the end of the last element of a table is a convention especially with each element in one line. The reason is that if we add another element git diff only shows 1 line of change.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ok

@Frenzie
Copy link
Copy Markdown
Member

Frenzie commented Jun 4, 2017

You say it requires a luajit-launcher bump but you didn't include it?

@mwoz123
Copy link
Copy Markdown
Contributor Author

mwoz123 commented Jun 4, 2017

@Frenzie I thought Koreader's downloading latest master luajit.
Howto change version?

},
}
if Device:isAndroid() then
table.insert(common_settings.screen.sub_item_table, require("ui/elements/screen_fullscreen_menu_table"))
Copy link
Copy Markdown
Contributor Author

@mwoz123 mwoz123 Jun 4, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It seems there's a problem in that line.
I believe it's in common_settings.screen.sub_item_table could you help me get reference to above sub_item_table?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

On my phone atm and that seems to look okay but remember you can always quickly test simple things in a plain old Lua console.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you be a little more specific about "a problem"? The reference to common_settings.screen.sub_item_table seems fine in a quick test.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I did reset and its' working now (at least at my Ubuntu).

@Frenzie
Copy link
Copy Markdown
Member

Frenzie commented Jun 4, 2017

You go into the dir of the submodule and run git pull. Then you can commit that change.

Generic.init(self)
end


Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Stray newlines?

@mwoz123
Copy link
Copy Markdown
Contributor Author

mwoz123 commented Jun 6, 2017

Guys, how do you build working apk for android?

Do you have to add any parameters to the build?

I use ./kodev release android (as it's in https://github.com/koreader/koreader#for-android-devices)
APK file is successfully created.

I'm able to install it, but such created application never works on my phone.
It just display black screen (with circle a.k.a "please wait") & freezes.

I'm building it on Ubuntu 16.04 LTS.

@Frenzie
Copy link
Copy Markdown
Member

Frenzie commented Jun 6, 2017

Sorry, that's my fault (but I mostly blame Android itself). There is no such thing as an Android build that works on my phone, so I can only test if it builds. :-(

If you manually use base from just prior to koreader/koreader-base#482 and use the Docker Ubuntu 14.04 box it should work but I think/hope @chrox is really close to a proper fix.

@mwoz123
Copy link
Copy Markdown
Contributor Author

mwoz123 commented Jun 6, 2017

Is there a docker container I can download? - - - edit : ok. I thought I need special koreader setup on Ubuntu, but it seems you're saying I just need 14.04 Ubuntu version.
But I would prefer to have had it fixed.

Hopefully koreader/koreader-base#482 will be finished soon as it's a blocker.

@Frenzie
Copy link
Copy Markdown
Member

Frenzie commented Jun 6, 2017

There are Docker and Vagrant containers in https://github.com/koreader/virdevenv

},
}
if Device:isAndroid() then
table.insert(common_settings.screen.sub_item_table, require("ui/elements/screen_fullscreen_menu_table"))
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Frenzie Just to be sure if it's failing or not I changed the line 44 to if not Device:isAndroid() (to test on PC).
And it fails:

./luajit: frontend/device/android/device.lua:16: missing declaration for symbol 'AConfiguration_getDensity'
stack traceback:
[C]: in function '__index'
frontend/device/android/device.lua:16: in main chunk
[C]: in function 'require'
frontend/ui/elements/screen_fullscreen_menu_table.lua:4: in main chunk
[C]: in function 'require'
frontend/ui/elements/common_settings_menu_table.lua:45: in main chunk
[C]: in function 'require'
frontend/apps/filemanager/filemanagermenu.lua:161: in function 'old_method'
frontend/dbg.lua:43: in function 'setUpdateItemTable'
frontend/apps/filemanager/filemanagermenu.lua:327: in function 'onShowMenu'
frontend/apps/filemanager/filemanagermenu.lua:375: in function 'handler'
frontend/ui/widget/container/inputcontainer.lua:197: in function 'handleEvent'
frontend/ui/widget/container/widgetcontainer.lua:87: in function 'propagateEvent'
frontend/ui/widget/container/widgetcontainer.lua:105: in function 'handleEvent'
frontend/ui/uimanager.lua:446: in function 'sendEvent'
frontend/ui/uimanager.lua:42: in function 'default'
frontend/ui/uimanager.lua:722: in function 'handleInput'
frontend/ui/uimanager.lua:767: in function 'run'
./reader.lua:193: in main chunk
[C]: at 0x00404750

not sure what's wrong there.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

With koreader/koreader-base#493 and koreader/android-luajit-launcher#52 you should be able to test on real Android device. Init android device requires android specific functions like AConfiguration_getDensity which do not exist on other platforms.

Copy link
Copy Markdown
Contributor Author

@mwoz123 mwoz123 Jun 7, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@chrox I didn't know. Thanks.

So once those PR's are merged building android on Ubuntu 16.04 should work, right?

So it's just about code review before merge, right?
I think I'll hold on until then

Copy link
Copy Markdown
Contributor Author

@mwoz123 mwoz123 Jun 9, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@chrox so now fix (Koreader build @ubuntu16.04) is in master, right?
So as I did git merge upstream/master it should work on my ubuntu 16.04, right?
Or should I do anything more as it's again freezed after install?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

comment out of date. This problem's already solved.

@Frenzie
Copy link
Copy Markdown
Member

Frenzie commented Jun 9, 2017

You'll need to make sure base is at the right commit.

@mwoz123
Copy link
Copy Markdown
Contributor Author

mwoz123 commented Jun 29, 2017

Help needed. There's a problem:

I/KOReader( 2067): DEBUG frontend/ui/elements/screen_fullscreen_menu_table.lua: variable disabled= true
E/luajit-launcher( 2067): Failed to run script: [string "android.lua"]:1354: attempt to concatenate local 'fullscreen' (a nil value)
V/threaded_app( 2067): android_app_destroy!

Koreader frontend/ui/elements/screen_fullscreen_menu_table.lua :

   local disabled = G_reader_settings:readSetting("disable_fullscreen") ~= false
   G_reader_settings:saveSetting("disable_fullscreen", not disabled)
   logger.dbg("frontend/ui/elements/screen_fullscreen_menu_table.lua: variable disabled=", disabled)
   android.setFullscreen(disabled)

Lua-jit launcher, android.lua lines 1353 and 1354:

android.setFullscreen = function(fullscreen)
android.LOGI("set fullscreen "..fullscreen)

I guess that variable ("disabled") exist in Koreader (and equals "true"), but then when it's transfered to Lua-jit launcher it's missing (it's "nil"). Right?
Do I need to somehow translate this Koreader (boolean) "true" to Lua-jit boolean ? Or is something else the problem?

@Frenzie
Copy link
Copy Markdown
Member

Frenzie commented Jun 30, 2017

There's no such thing as a "KOReader boolean". :-P There is of course a possibility that you saved it as a string at some point, but even if you did there's no difference between "true" (string) ~= false and true ~= false. The result would always be true (boolean). Btw, I'm not sure why you'd save a setting right after reading it?

For checking if a key is true or false we have convenience functions like isTrue() and isFalse().

Glancing at the code I notice it's declared as final https://github.com/koreader/android-luajit-launcher/blob/cddd8ab65b78c87ec295ba789f6e92b59e92b58c/src/org/koreader/launcher/MainActivity.java#L106

@mwoz123
Copy link
Copy Markdown
Contributor Author

mwoz123 commented Jun 30, 2017

As "koreader boolean" I thought about converting boolean between lua and Java. But right, this part of Lua-jit is still lua code.

I used Greater:settings to read and store the full screen settings I thought it might be faster than calling android(java) code from lua to get that info. But maybe it's not?and should be replaced?

That Java "final" key word you highlighted just means once you passed the attribute to function it reference cannot be changed inside the function. In simple words function itself cannot change passed boolean. So shouldn't make difference unless there's something wrong with passing lua variable to Java final parameter..

@mwoz123
Copy link
Copy Markdown
Contributor Author

mwoz123 commented Jun 30, 2017

Oh I get what you mean that I "save a setting right after reading it". I'll fix that but the main problem is still to be solved..

callback = function()
local disabled = G_reader_settings:readSetting("disable_fullscreen") ~= false
G_reader_settings:saveSetting("disable_fullscreen", not disabled)
android.setFullscreen(disabled)
Copy link
Copy Markdown
Member

@Frenzie Frenzie Jun 30, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does it make a difference if you use : instead of .? Looking at the whole thing here rather than the sample you posted earlier I realized we were talking about the Device method rather than a direct reference. You might have to pass in a reference to the object if you do it this say. That'd be the less elegant android.setFullscreen(android, disabled).[1] In that case it'd think disabled is the object reference and fullscreen nil if you only pass android.setFullscreen(disabled).

[1] It'd also be the wrong android object as it's actually from Device.

@mwoz123
Copy link
Copy Markdown
Contributor Author

mwoz123 commented Aug 27, 2017

I played with Geom:new{ it seems to change the app resolution but not the starting point.

Comparision (hard coded values for tests):
local viewport = Geom:new{x=50, y=100, w=900, h=1600}
below:
x 50 y 100 w 900 h 1600
with
local viewport = Geom:new{x=0, y=0, w=900, h=1600}
below:
x 0 y 0 w 900 h 1600

The seems to have the same starting point.

I even tried with negative x & y values but then I had:
E luajit-launcher: Failed to run script: ffi/framebuffer.lua:137: bad viewport

Any ideas?

@Frenzie
Copy link
Copy Markdown
Member

Frenzie commented Aug 27, 2017

Sorry, I'm not sure what could be the matter. Have you tried it as part of the Device init instead of trying to set it through a function later? Here's a screenshot of EMULATE_READER_VIEWPORT="{x=100,w=950,y=50,h=790}" ./kodev run -w=1100 -h=1200

screenshot_2017-08-27_22-39-37-fs8

I even tried with negative x & y values

Yes, that's to be expected. :-)

@mwoz123
Copy link
Copy Markdown
Contributor Author

mwoz123 commented Aug 28, 2017

The EMULATE_READER_VIEWPORT is used only in generic device.lua in init() method:

local viewport = os.getenv("EMULATE_READER_VIEWPORT")
    if viewport then
        self.viewport = require("ui/geometry"):new(loadstring("return " .. viewport)())

I tried simple :

local viewport = "{x=50, y=100, w=900, h=1600}"
local Device = require("device")
Device.viewport = require("ui/geometry"):new(loadstring("return " .. viewport)())

but it doesn't make any changes to viewport. The same result for code below:
android.viewport = require("ui/geometry"):new(loadstring("return " .. viewport)())

I believe the android.screen:setViewport(viewport) must be used.

But there might be something missing in current implementation?
android.lua has width and height in screen object:

    android.screen = {}
    android.screen.width, android.screen.height =

but I didnt' spot screen.x and y ...

I found setViewport method in the same file I I had exception on for negative x & y (ffi/framebuffer.lua:137)
There's also framebuffer_android.lua which extends above FB :
return require("ffi/framebuffer"):extend(framebuffer)

In framebuffer_android.lua init() method doesn't have x & y; only height & width:
self.bb = BB.new(android.screen.width, android.screen.height)
BB is local BB = require("ffi/blitbuffer")

Searching for vieport in BB gave me result:
function BB_mt.__index:viewport(x, y, w, h)
so here's x & y..

But maybe the data is lost when passed from a lua file to another?
I'm above my ability to track it:(

@Frenzie
Copy link
Copy Markdown
Member

Frenzie commented Aug 28, 2017

The EMULATE_READER_VIEWPORT is used only in generic device.lua in init() method:

Sure, but besides being slightly easier to test on the fly it makes no difference. It's the same as just writing local viewport = {whatever you stick in the environment variable}

In framebuffer_android.lua init() method doesn't have x & y:

Right, as shown in my screenshot the viewport affects where on the framebuffer the picture is drawn. Since the problem seems to be that the statusbar overlays KOReader, my thinking is that it doesn't matter if the framebuffer is still the full size. All you need to do is push the KOReader viewport down slightly. I have no idea why that doesn't seem to be working, but I don't think it's related to the particular line you mention.

@Frenzie
Copy link
Copy Markdown
Member

Frenzie commented Aug 28, 2017

Testing Android is tremendously annoying.

Anyway, after some general inconvenience I can confirm that it just sticks it in the top left. The value I used for testing was self.viewport = require("ui/geometry"):new{x=50, y=100, w=300, h=500}

screenshot_20170828-223937

PS

sudo apt install openjdk-9-jre-headless openjdk-9-jdk-headless
keytool -genkey -keyalg rsa -keysize 2048 -alias jdkcert2048 #from http://www.grok2.com/blog/2010/09/14/keytool-jarsigner-oddity-on-ubuntu-with-openjdk-version-6/ just fill out some nonsense and a password of 123456
# remove META-INF folder
jarsigner ko.apk jdkcert2048

It's been like a decade since I've done Java and signing jars wasn't required. What's that Android emulator thing?

@mwoz123
Copy link
Copy Markdown
Contributor Author

mwoz123 commented Aug 29, 2017

Yes It's a pain.
Everytime I change code have to execute at least 2 commandline commends (1 more for logcat) + some manual actions (remove old Koreader). And cannot even run debugger, only viewing logs:(

Some time ago I asked for x86 build (#3046) so at least emulation would be faster.
Start time for arm emulator is around 3-5 min on my PC:/

But getting back to main problem:
I created a blocker for this PR #3148, It seems until resolved we cannot process with this feature.

ps: @Frenzie I use ./kodev release android IMHO seems easier that manually singing apk file.
BTW Java 9 is not released yet.

@Frenzie
Copy link
Copy Markdown
Member

Frenzie commented Aug 29, 2017

BTW Java 9 is not released yet.

Whatever it is, it's in the repos and I used it. :-P I doubt jarsigner changed much over the years; I simply got myself the stuff I needed with the latest version number.

IMHO seems easier that manually singing apk file.

Compilation tools are useful in general including on my laptop. Gigabytes of Android stuff are not at all (to me). I'd just as lief not have them on my desktop but there I have enough space to spare. :-)

@Frenzie
Copy link
Copy Markdown
Member

Frenzie commented Sep 16, 2017

@mwoz123 Do you know anything about Gradle? Google apparently wants everyone to switch to that moving forward, making build.xml incompatible with SDK 26.

@mwoz123
Copy link
Copy Markdown
Contributor Author

mwoz123 commented Sep 16, 2017

@Frenzie I should have gradle as build tool in next work project..
For now I know it's all about json.

@mwoz123 mwoz123 changed the title [w.i.p]Android fullscreen switcher [finished]Android fullscreen switcher Sep 16, 2017
@mwoz123
Copy link
Copy Markdown
Contributor Author

mwoz123 commented Sep 16, 2017

Android disabling/enabling fullscreen works.

Changing viewport has been extacted to #3148

Please review & merge.

@@ -0,0 +1,36 @@
local _ = require("gettext")
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The coding style says _ goes under those.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've glanced at https://github.com/koreader/koreader-base/wiki/Coding-style
but still don't understand what you mean.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

local Class = require("class")  -- Uppercase class
local Device = require("device")  -- Uppercase class
local func = require("func")  -- Lowercase function
local glob = require("glob")  -- Lowercase function
local _ = require("gettext")  -- Symbol
local T = require("ffi/util").template  -- One of the functions in a file
local V = require("utils2").version  -- The other function, ordered by ASCII.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Order changed as you wanted.

return {
text = _("Fullscreen"),
checked_func = function()
local disabled_fullscreen = G_reader_settings:readSetting("disabled_fullscreen") ~= false
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

local disabled_fullscreen = G_reader_settings:isTrue("disabled_fullscreen")

http://koreader.rocks/doc/modules/luasettings.html#LuaSettings:isTrue

end,
callback = function()
local disabled_fullscreen = G_reader_settings:readSetting("disabled_fullscreen") ~= false
local enabled_fullscreen = not disabled_fullscreen
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

local enabled_fullscreen = G_reader_settings:isFalse("disabled_fullscreen")

And skip the useless disabled_fullscreen a line above.

local screen_height = android.getScreenHeight()
logger.dbg("screen_fullscreen_menu_table.lua: Screen height: ", screen_height)

-- lines below should be uncommented once #3148 is resolved
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These lines can wait for the follow-up PR.

@@ -0,0 +1,36 @@
local _ = require("gettext")
local android = require("device/android/device")
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Perhaps local _, android = pcall(require, "android") and skip the Device stuff up there?

@Frenzie
Copy link
Copy Markdown
Member

Frenzie commented Sep 16, 2017

Looking pretty good. 👍

Generic.init(self)
end

function Device:isFullscreen()
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You still left these in. :-)

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't get it. Can you be more verbose?;)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Your use of local android = require("device/android/device") was confusing, because elsewhere that always means local _, android = pcall(require, "android").

Anyway, so either you should use Device properly or just stick with the specific Android stuff. Last night I made the judgment call that since this is all very Android-specific, there's probably no use in "littering" Device with it, plus it would be the easier change to make. But that means there's no need to add these methods to this file.

@@ -0,0 +1,27 @@
local _, android = pcall(require, "android")
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

My apologies (as I suggested this), but if you do it this way luacheck will complain.

Maybe a little safety check like this?

local isAndroid, android = pcall(require, "android")
if not isAndroid then return end

@mwoz123
Copy link
Copy Markdown
Contributor Author

mwoz123 commented Sep 17, 2017

@Frenzie I wasn't complaining about

local _, android = pcall(require, "android")

but now it does about :

frontend/ui/elements/screen_fullscreen_menu_table.lua:1:7: unused variable 'isAndroid'

can I get back to previous solution?

@Frenzie
Copy link
Copy Markdown
Member

Frenzie commented Sep 17, 2017

Then you'd still be upvalueing it, which is bad practice. (It might work but you shouldn't have to parse the code to know what a variable refers to.)

But one should expect it to complain about unused variables, because I suggested to use that variable:

local isAndroid, android = pcall(require, "android")
if not isAndroid then return end

@Frenzie
Copy link
Copy Markdown
Member

Frenzie commented Sep 17, 2017

But I suppose it'll do.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants