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);
Related
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.
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
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
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?
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?