Android screen rotation

564 views
Skip to first unread message

Alexander Taylor

unread,
Aug 15, 2013, 5:19:47 PM8/15/13
to kivy-...@googlegroups.com
I've just added a tablet mode to my app, toggled by an option in the settings panel, which rotates the screen by setting Window.rotation and rearranges some widgets. The problem with this is that it only rotates the app within the opengl frame, the android on-screen buttons and notification bar remain in portrait mode.

So...how do I properly tell android to switch to landscape mode? I tried copying the method of https://groups.google.com/forum/#!topic/kivy-dev/6oDoE3JCfrY (from https://gist.github.com/remip/5474086), which rotates the screen properly to landscape but then immediately crashes. Is this the right way to do it and I just have a bug, or is there a better way to do this nowadays?


Alexander

Alexander Taylor

unread,
Aug 15, 2013, 5:22:21 PM8/15/13
to kivy-...@googlegroups.com
Oh...forgot to say, the log of my crash after running `self.PythonActivity.mActivity.setRequestedOrientation(self.ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE)` is at https://gist.github.com/inclement/6244996 .

Ben Rousch

unread,
Aug 15, 2013, 5:48:05 PM8/15/13
to kivy-...@googlegroups.com

You should use orientation="sensor" in your build and let Android handle rotation.

--
You received this message because you are subscribed to the Google Groups "Kivy users support" group.
To unsubscribe from this group and stop receiving emails from it, send an email to kivy-users+...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.

Alexander Taylor

unread,
Aug 15, 2013, 5:57:28 PM8/15/13
to kivy-...@googlegroups.com
Thanks, but that isn't really what I want - I don't want any automatic changes, but for the user to set either portrait or landscape (upon which the change is made) but then for it to be stable.

I did just try orientation=all (seems 'all' is the right buildozer syntax rather than 'sensor'?), and actually this also crashes when the rotation is made, so I guess maybe my manual rotation code is right and there is a separate rotation problem...

Carsten Thielepape

unread,
Sep 10, 2014, 10:17:38 AM9/10/14
to kivy-...@googlegroups.com
Hello,I am starting with some rotation tasks as well.
 
So: Did you solve your problem?
 

 

Alexander Taylor

unread,
Sep 10, 2014, 10:22:39 AM9/10/14
to kivy-...@googlegroups.com
Yes, the solution (if you want to manage it manually) is to call the
android api via pyjnius.

I have an example of doing it at
https://github.com/inclement/pyjnius-api-wrappers/blob/master/orientation.py
, which includes functions for any of the available options.

I also have a pr to add something more basic to plyer, at
https://github.com/kivy/plyer , but that might not be merged in the very
near future.

You can also do as brousch said earlier in this thread and simply tell
python-for-android to rotate automatically, if that's enough for you.

On 10/09/14 15:17, Carsten Thielepape wrote:
> Hello,I am starting with some rotation tasks as well.
>
> So: Did you solve your problem?
>
>
>
>
> --
> You received this message because you are subscribed to a topic in the
> Google Groups "Kivy users support" group.
> To unsubscribe from this topic, visit
> https://groups.google.com/d/topic/kivy-users/TOkNuzPRM0g/unsubscribe.
> To unsubscribe from this group and all its topics, send an email to
> kivy-users+...@googlegroups.com
> <mailto:kivy-users+...@googlegroups.com>.
> For more options, visit https://groups.google.com/d/optout.

0x6DB9E52F.asc
signature.asc

Carsten Thielepape

unread,
Sep 16, 2014, 4:03:13 PM9/16/14
to kivy-...@googlegroups.com
Hello,

tested it out and it works fine. But :-)

I am detecting at appstart the screen metrics from
  kivy.core.window.Window.size or
  (kivy.app) ._app_window._size
which delivers the same

After rotating, those values will not be adjusted to the new values. So how I can get the new "application" screen size after the rotation? Flipping  width and height will not deliver the right values as the "Android Navigation Bar" will rotate as well.

Hints welcome. (preferred portable solutions...) :-)

Thanks

Carsten.



Alexander Taylor

unread,
Sep 16, 2014, 4:04:44 PM9/16/14
to kivy-...@googlegroups.com
The Window.size should reflect the current size, and update following
the rotation. You can simply bind a function to it to do whatever you want.
0x6DB9E52F.asc
signature.asc

Carsten Thielepape

unread,
Sep 16, 2014, 4:44:41 PM9/16/14
to kivy-...@googlegroups.com
Hi Alexander,

using

"EventLoop.window.bind(on_resize=self.On_Resize)"

"self.On_Resize" will be called properly, if I resize on MS-Windows. (using kivy.core.window.Window.size to emulate rotation)
But on Android, nothing will be triggered, if I call the "set_landscape(self,mode='normal', user=False)" function. It looks, like kivy is not getting aware of it.

Alexander Taylor

unread,
Sep 16, 2014, 4:45:51 PM9/16/14
to kivy-...@googlegroups.com
Don't bind to on_resize, try just binding to size.
> <https://groups.google.com/d/topic/kivy-users/TOkNuzPRM0g/unsubscribe>.
> > To unsubscribe from this group and all its topics, send an email to
> > kivy-users+...@googlegroups.com <javascript:>
> > <mailto:kivy-users+...@googlegroups.com <javascript:>>.
> > For more options, visit https://groups.google.com/d/optout
> <https://groups.google.com/d/optout>.
>
> --
> You received this message because you are subscribed to a topic in the
> Google Groups "Kivy users support" group.
> To unsubscribe from this topic, visit
> https://groups.google.com/d/topic/kivy-users/TOkNuzPRM0g/unsubscribe.
> To unsubscribe from this group and all its topics, send an email to
> kivy-users+...@googlegroups.com
> <mailto:kivy-users+...@googlegroups.com>.
0x6DB9E52F.asc
signature.asc

Carsten Thielepape

unread,
Sep 16, 2014, 5:04:24 PM9/16/14
to kivy-...@googlegroups.com

Hi Alexander,

this works, even it looks like, that it will be triggered very late, but this might be an application problem.

Thanks for your support
Reply all
Reply to author
Forward
0 new messages