How to set desired landscape orientation - android

I know you can set orientation using android:screenOrientation statically and setRequestedOrientation programatically. However the problem is that if I use either of these to set the screen orientation I do not get to choose which landscape or which portrait I want. To wit, flipping the phone 180 degrees does not rotate the view but rather just appears upside down to the user. I cannot use screenOrientation="sensor", because in some cases I would only want the view to be landscape OR portrait and seldom both. This seems insignificant until you consider external hardware.
If I developed an app and set the layout to android:screenOrientation="landscape", the app would only display correctly if the left side of the droid were sitting on a desk. Unforunately the left side is where the usb port is, so the phone would not sit very well on that side if it were plugged in. Unless of course they used a docking station but that is not the kind of help I am looking for. If the right side of the phone is sitting on the desk to allow for the cord, the display appears upside down. I tried posting an image but being a new user I was not able to do so.
What I would like to know is how to programmatically choose which landscape (Surface.ROTATION_90,Surface.ROTATION_270) or portrait (Surface.ROTATION_0,Surface.ROTATION_180) orientation I wish the user to see, but more importantly allow them to do so in the app's settings activity. I have googled for quite awhile and all I can find are sensors that tell you when the orientation/rotation has changed and to what, but none show how to programmatically set either.

Related

Android 9 Screen Rotation Approach

Our team has recently updated a system application (installed in priv-app) from Android 5 to Android 9. This seems to have broken the previously working (and relatively well documented approach) of programmatically flipping the device orientation.
We had been using this approach and it had worked at globablly flipping the device orientation 180 degrees:
Settings.System.putInt( context.getApplicationContext().getContentResolver(), Settings.System.USER_ROTATION, 2)
We check each time to make sure the accelerometer rotation is disabled also. The setting does in fact stick as when interrogate the settings provider and can see the value being updated, the screen is simply not reacting, even after a reboot etc..
I'm trying to understand if Android 9 introduced any further gotchas that can prevent a screen rotation from happening, would be grateful if anyone had any insight on this particular issue?
You can instead use Activity.setRequestedOrientation() if its a particular Activity your want to change. This can be set explicitly to portrait, reverse portrait, landscape, reverse landscape, etc... It will then lock to the orientation you set. You can use the various sensor values if you want it to be flexible for the user.
If you want to know what your current orientation is (including reverse orientations) it can be complicated but I just answered my own question here about how to do it - Android sensor orientation problems with edge-to-edge insets
If you want to change the system rotation
You need to ensure ACCELEROMETER_ROTATION is off and then the value you use needs to come from the surface rotation constants (which are relative to your displays natural orientation) - https://developer.android.com/reference/android/view/Surface#ROTATION_0
Another quick edit - any Activity can override this setting (including a launcher) for themselves. So it may be that whatever you are running is actually what changed to lock or allow certain orientations.

Change screen orientation in a Unity Google Cardboard project

I'm just starting a cardboard project as it's really joyful to experiment VR without any huge hardware, but I have a little problem which sounds really basic : the screen orientation. I just would have my game playable in Landscape Right instead of Left as I'm developing on my Xperia Z.
Usually screen orientation's problems are solved by forcing the orientation through the Player's Settings in the Build Menu. But here, the fact is that when I tick the "Landscape Right" box instead of the left one (which is the default setting of the Cardboard API) it correctly inverts my display but my camera stays at the same orientation as before.
From this results that my gyroscope works in reverse and that the ground is seen on the top, with all the texts reversed as well.
I've already done what Eldir tried here (Google cardboard device orientation) but as it wasn't the same problem I'm having, it wasn't efficient.
Do you have any ideas that if the API allows a quick change for this, or if I have to modify the whole parameters of the gyroscope ?
Thanks !

Android screen orientation according to mobile screen width

I'm creating an aplication with Phonegap. The point is if I can put a limit for screen orientation namly I want that the device can't change orientation to landscape unless the device screen width is more than 480px.
As far as I know, this is not possible. You have either screen rotation, or off. Not conditionally on. You can change your GUI of your app, depending on screen rotation and size.
Your question is to general to give a specific answer. But if you want to see an example, check out my repo jpHolo. It features an interface for smartphones and tablets and you can add code for screen changes easily.
https://github.com/teusinkorg/jpHolo

Android Images not appearing until device is rotated

I'm designing for Mobile Web and have an image/button in a mobile site, (positioned by percentages) that shows up correctly on an iPhone (in portrait and landscape).
However, when tried on most Android phones, the image does not show up until the phone is rotated to a landscape position, and then will show up in the correct position in portrait. It will not load in portrait mode with the button showing.
I've tried positioning, z-index and that doesn't seem to be what is causing it.
Any help is greatly appreciated, thanks!
I'm not sure if I'm able to comment yet so I will just post this here and a mod can move it if they want.
Many browsers interpret css differently. I would make sure that you do not have overflow:hidden or overflow:inerit which is taking the form of "hidden." It's the only thing I can think that would lead to it being invisible until the screen is widened.

Use accelerometer in landscape mode

So I'm pretty new to Android programming and my current project involves moving a picture left and right by tilting. It works fine but I can't figure out how to make the accelerometer useful in landscape mode (forced landscape). I get good results if i hold the phone upright (it remains in landscape) but obviously that doesn't really fulfill my needs. Is there a quick fix for this I can use?

Categories

Resources