Faking landscape orientation in Activity when locked in portrait - android

The camera app on Android locks its orientation to portrait, and fakes an orientation change when you turn to landscape. The screen never re-orients itself (you don't see the screen reload or shift at all), but the icons turns to make it seem like it changed the orientation. How are they achieving this?
Let's say I did this. So I'm locked in landscape mode, and I rotate the phone so I'm in portrait (at least that's what it looks like to the user). Now if I have any dialog that pop up on top of this Activity, I'd want them to pop up in portrait orientation. How would I achieve this?

Related

Force landscape when pressing button - like youtube full screen button

Hey i'm trying to create a behavior like YouTube full screen button.
I have a button that will force rotate from portrait to landscape.
And it should stay in landscape till the user rotates the device to landscape and back to portrait.
My problem is that when i use getActivity().setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE)
And the phone is in portrait the view rotates to landscape for a second and Straight back to portrait.

Keeping the current orientation

My app does the following:
I take a picture
The picture is displayed in a DialogFragment
If I take the picture in landscape mode, I want the orientation of the DialogFragment which is showing my image to be locked to landscape mode.
If I take the image in portrait mode, I would like the orientation of the DialogFragment be locked to portrait mode.
Is that possible?
Check the width and height of your image, that should be enough to tell you wether it was taken in portrait or landscape mode. Set your orientation with
getActivity().setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);
or
getActivity().setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
And if you want to re-enable your auto-rotate functions at a later time just use
getActivity().setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_SENSOR);

How do I prevent my app from rotating /prevent the orientation switch once I lock the screen?

I am trying to prevent myy app orientation to landscape to portrait or vice versa when I lock the screen by clicking screen rotation to off.I saw that once I deselect screen rotation, the entire screen locks up including the screen of the apps I have on my device except for my app where orientation change still triggers landscape portrait recognition even when locked.How do I go around it? DoI need to set something in android manifest to make it work in accordance with the screen rotation ?
Thanks!
You can set either add android:screenOrientation="portrait" or android:screenOrientation="landscape" parameter to your AndroidManifest.xml.
edit:
You can also "lock" screen orientation programmatically using setRequestedOrientation (int requestedOrientation)
If you want to lock orientation when user locks it in the system you need to add android:screenOrientation="user" in your activity tag

How to go back to same orientation as it was after my acitivity closes?

I have this scenario where my activity launches in portrait mode (irrespective of current display's orientation) After my activity is closed, the device's display still remains in the same portrait orientation..
Is there a way to set it to the original (i.e. if the screen was in landscape, after my activity closes, it should go back to landscape) or should the Android System take care of this?
(And an important condition is that, my application's UI comes and goes off without any user interaction on screen)
I am facing this in ICS..

It is possible to lock the screen orientation of the phone only when you want? (dynamically)

I have an application that can be viewed with landscape and portrait mode. I'm not using onConfigurationChanged() and android:configChanges="orientation|keyboardHidden" and the screen orientation change is working perfectly.
But now, i have a small problem. I want to learn to lock the screen orientation change of the screen. I mean that for example, when the user press a "lock" button, the screen orientation must be locked and it must not change, and when the user press again that button, the screen orientation must get unlocked
¿how can i lock the screen orientation dinamically?
For locking,
activity.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_NOSENSOR);
For unlocking,
activity.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_SENSOR);
where "activity" is your current Activity, in which you want to lock.

Categories

Resources