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?
Related
For my project requirement, I am using Google's camera2 api basic example and I don't want to restart my activity on orientation change. But, while doing this I face an issue that If i change my view from portrait to landscape mode camera preview is not redrawn and aspects of portrait are applied in landscape mode. Due to this when i capture image, Camera captures larger image then what is shown on preview in landscape mode.
Reproduction steps :
Pre condition :
Handle onOrientationChange in manifest file for the activity.
Steps:
1. Open camera in portrait mode and then rotate to landscape mode
2. Capture image
For this, I called closeCamera() and then openCamera() in onConfigurationChanged() but it is not a good solution beacuse it takes a lot of time to recreate everything. Is there any way I can redraw the preview surface ?
My application's orientation is fixed to portrait due to some functionalities that always in action.
I need to add to the main activity a fragment with a landscape orientation, so it's layout should be portrait, but rotated 90 degrees.
My problem is that a TextView won't fit the screen because it's width is longer than the screen's width. Also, rotating it (or anything else) won't work properly because the rotation is being done after it's being located.
Is there any library that can handle such thing? Or what can I do to handle that problem?
Assuming that the current android's activity is set to:
android:screenOrientation="sensorPortrait"
Is there any way to change the orientation only for buttons? So that the other childs stay in the same orientation, as stated in android manifest.
What I'm asking is related with a streching camera preview. As long as the android:screenOrientation is set to some value like landscape or portrait, then the switching to different orientations doesn't really affect the camera preview, the ratio and size is perfect. But when it comes to just remove this screenOrientation part in order to make the buttons rotate with the phone, so that they follow changing orientation....the landscape preview gets stretched like x2.5 time, making the preview look bad.
For all whom might look for the answer, concerning stated question, there are smart way to achieve this, just follow these topic above
Rotate an ImageButton on orientation change
How to rotate views on orientation change without recreating layout?
We are development an video related Android App. And we need to support both portrait and landscape mode. Because the UI is veriy complex, so we want the UI element rotate. And because we draw local preview on the surface view using opengl, and it will become very complex if the GLSurfaceView rotate.
So we want to lock the GLSurfaceView orientation while keep the overall UI change change orientation when rotate the device. We have used the similar solution on iOS.
We only find the solution to force Activity portrait instead of only some View in the activity. So is it possible to do that? and how can we do that?
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.