symcbean
symcbean

Reputation: 48357

Suppress / detect rotation in Android using Javascript

I'm trying to implement a wrapper around a modified VNC viewer applet (VNC = a remote display protocol) to provide an enhanced user experience (using javascript) but have run into problems with handling rotation.

The width/height of the applet are fixed (1) - so when the user rotates the device, the applet overlows the screen or is resized:

+------------+   +-------+         +-------+
|............|   |.......|...      |.......|
|.         X.|   |.      | X. or   |.    x.|
|.          .| > |.      |  .      |.......|
|............|   |.......|...      |       |
+------------+   |       |         |       |
                 |       |         |       |
                 +-------+  :(     +-------+ :(

But I want....

+------------+   +-------+
|............|   |.......|
|.         X.|   |.     .|
|.          .| > |.     .|
|............|   |.     .|
+------------+   |.    X.|
                 |.......|
                 +-------+  :)

While I can detect the autorotation from the change in screen dimenions in javascript, and, if it were written in Java, I could suppress the autorotation, neither of these achieves my desired result: specifically, that

I'm not totally averse to implementing the detection of rotation as a seperate applet exposed to the javascript / implementing the page via a webview but would prefer no to.

Is it possible to lock the orientation in a html app manifest file?

Is it possible to detect rotation using javascript when the orientation is locked?

Is there another way to solve this?

1 - this is a limitation of the underlying protocol, I'm already making changes to the Java applet, I don't really want to have to rewrite the server too!

Update

I'm aware that most versions of VNC (inclucding noVNC) have a problem with xrandr.

If someone can tell me how to suppress the automatic re-orientation of a browser page (without using an applet with a webview) that at least givers me part of the answer.

Upvotes: 1

Views: 378

Answers (2)

Ivan Bartsov
Ivan Bartsov

Reputation: 21036

Have a look at this, someone seems to have already solved this problem: https://stackoverflow.com/a/2307936/375929

UPD Afaik, you can't enforce orientation stuff from javascript, but you can detect rotations and react with a complementary rotation in your webapp - so orientation of your webapp remains the same to the user.

Upvotes: 0

Hamid
Hamid

Reputation: 4430

I'm not entirely sure if I might perhaps be missing your point here, but you can prevent the device from re-laying out on rotation or keyboard slide out by adding the following line to your manifest:

android:configChanges="keyboardHidden|orientation"

Then, if I understand correctly you can have your javascript simply rotate the text within the applet once the change happens.

This will provide the desired effect of maintaining the window in the direction and size you have indicated above, leaving it up to yourself to correct the text direction.

Upvotes: 1

Related Questions