1

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

  • the orientation of the display would not change when the device is rotated
  • that my javascript would detect that device has been rotated and re-orient the content of the applet (by sending an OOB message to run xrandr at the vncserver).

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.

Community
  • 1
  • 1
symcbean
  • 47,736
  • 6
  • 59
  • 94
  • 2
    I might be seriously misunderstanding what your current situation is so let me check, you say that you have an java applet running in an android browser? Cause as far as I knew that was impossible... or do you simply have a native javascript vnc client? – David Mulder Jul 02 '12 at 08:36

2 Answers2

1

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.

Hamid
  • 4,410
  • 10
  • 43
  • 72
  • Nah, if I understand it correctly, @symcbean is not developing an andorid app, but is rather trying to trick android's browsers into working with the web-based vnc applet. – Ivan Bartsov Jul 02 '12 at 18:13
  • Currently it's an HTML5 app - I'd prefer not to go down the java route, hence my question. – symcbean Jul 03 '12 at 10:07
  • Oh apologies, I thought you had created an Android app that simply displays a web view. That would allow you the control I mentioned above. – Hamid Jul 03 '12 at 10:23
0

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.

Community
  • 1
  • 1
Ivan Bartsov
  • 19,664
  • 7
  • 61
  • 59
  • No - the onorientationchange event is specific to iPhone - the code shown there falls back to using resize if the event is unavailable. – symcbean Jul 03 '12 at 10:10
  • well, doesn't that one work? It seems it should unless the screen is a perfect square. – Ivan Bartsov Jul 03 '12 at 10:36
  • Cart before horse - I don't want the *local* screen to rotate when the device rotates - but I want to notify the remote server that the device has been rotated. It's possible to suppress the local screen rotation in Java, not sure about javascript. Hence my question. – symcbean Jul 04 '12 at 23:13
  • oh. I see. No, 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. – Ivan Bartsov Jul 05 '12 at 09:22