Android changing video view to landscape - android

My application is in Portrait mode and it has one video view in it, on some events i want to rotate only the video view to landscape mode is it possible to do so?
From the code can we modify a single view to be of landscape mode as other will remain in portrait mode?
Also i have onOrientationChanged listener in my activity which provides orientation values as device orientation changes. how can i determine if device is in landscape or portrait mode from these values?

Yeap, it's possible.
You can get the orientation in runtime with this code:
Display display = ((WindowManager) getSystemService(WINDOW_SERVICE)).getDefaultDisplay();
//orientation will contain Configuration.ORIENTATION_PORTRAIT or Configuration.ORIENTATION_LANDSCAPE
int orientation = display.getOrientation();
So, if you want to make something when changing the orientation you can override the onConfigurationChanged method.
And if you want to change the orientation in runtime you can use this (in example, change to portrait):
setRequestedOrientation (ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
If want more details, read this

Related

How to get event notification on orientation change from Landscape Left to LandScape Right?

I have an Activity which override public void onConfigurationChanged(Configuration newConfig) method. It receive event when user change orientation from landscape to portrait or from portrait to landscape . But don't show any event when i change orientation Landscape Right to Landscape Left or Landscape Left to Landscape Right. Is there any way to get even while changing orientation Landscape to Landscape ??
You can detect rotation side with accelerometer. When you are certain of some orientation landscape/portrait set the current angle. If orientation is changed calculate the difference to see if its 90>(roughly) and if it is, obviously screen was rotated from portrait to potrait or landscape to landscape. With that calculation you could also detect was the rotation made by the left or the right side. You get the point. Also check these answers:
https://stackoverflow.com/a/10383164/5577679
how to detect orientation of android device?
Get rotation and display in degrees
And sensors overview:
https://developer.android.com/guide/topics/sensors/sensors_overview.html

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 to force change layouts in Android

I have my app's orientation forced via
setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
but when I want to change layout to landscape one (when device is rotated - i get the info via OrientationEventListener) it just doesnt render it as landscape. Is there any way how to force it? Just like imagine holding your device in portait mode but the layout is landscape. but not achieved via
setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);
or
android:screenOrientation="landscape" in manifest
I want to have it forced to portait because I'm building a camera app and it messes up the camera everytime and I want to have it like the default camera has it - no change, just the button orientation. If that makes sense.
A lot of camera apps achieve this by rotating Views and it's a good way to do it because you don't have to deal with Activity lifecycle as well as camera lifecycle. They have a locked orientation but they use accelerometer to get device rotation and then rotate Views accordingly.
Camera API gives you ability to set camera rotation as well as picture orientation. Picture orientation should be set to zero because Camera API is unreliable with this.
Use accelerometer to determine real device rotation and set EXIF rotation of the picture to a correct one.

Fastest way to update the activity for all the orientations

In my android Activity I need to update the camera preview orientation and the UI according to the device Orientation. And I need all orientations for my activity namelyPortrait,Landscape,Landscape reverseandportrait reverse`.
I use the Android API demo for the camera preview. I found that when I use fullSensor for orientation setting in my AndroidManifest.xml and call the setCameraDisplayOrientation() on surfaceChanged() method of the Preview class(I am referring to the CameraPreview.java in the API demo sources) I get the desired behavior.
But there is a big delay on each orientation switch. When I set the orientation to Landscape in the manifest the preview is smooth but the UI is not updating according to the device orientation. I need the orientation to be set to Landscape and the UI to change according to all the four orientations namely Portrait up, Landscape right, Landscape left and Portrait down. What is the optimal way of achieving the same with good performance?

Device Rotation on fixed orientation Android

I'm displaying a camera activity in Android 2.2 and I lock the screen orientation in landscape mode. Is there a way to get the device rotation?
I mean, getOrientation() always returns LANDSCAPE and getRotation() always returns 1. How can I get the actual rotation of the device even if I lock the orientation in landscape mode?
You can use the SensorManager class, see http://www.workingfromhere.com/blog/2009/03/30/orientation-sensor-tips-in-android/

Categories

Resources