Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

android screen orientation: lock only parts of the layout

I am building a camera app which makes use of the camera preview. In order to use the full screen for the preview, I locked the activity with

setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);

Now I have following problem: whenever I render a form or I have to show a dialog, it always shows up in landscape mode, even when the user is using his/her device in portrait mode. I tried to rotate edittext views by using transform animations, and they are correctly rotated, but still I am not able to focus them any more, and the keyboard always shows up in landscape too :(

Do you know ANY way of finding a way round here?

IMPORTANT: detecting orientation is NOT the issue here. The question is: how do I rotate the forms/views/viewgroups and keyboard in a way that they are still usable.

I know that it has to be possible somehow: samsung's camera app (which comes with the galaxy S3) is able to rotate views without rotating the preview, so it has to be possible! see:

http://www.letsgomobile.org/images/reviews/0186/galaxy-s3-camera.jpg

http://cdn2.mos.techradar.futurecdn.net//art/mobile_phones/Samsung/GalaxyS3/Galaxy%20Fire/Samsung_Galaxy_S3_25-580-100.JPG

like image 215
stoefln Avatar asked Dec 18 '12 14:12

stoefln


2 Answers

The Samsung Camera Application is using an Orientation change Listener with the orientation sensor. If the user block the device rotation from settings the rotation still happen.

You will need a create your full custom widgets, so you cannot use build in Dialog, you have to show a CustomDialog ....

The basic idea is to use OrientationEventListener, and SensorManager. On the Device Rotation you have to updates your UI and rotate views with the new orientation. Here is a tutorial on using OrientationEventListener How to use OrientationEventListener On most camera app, the activity is still blocked on LANDSCAPE. All camera application do this trick to ease the handling of the SurfaceView size change with the rotation.

like image 194
Anis BEN NSIR Avatar answered Sep 20 '22 07:09

Anis BEN NSIR


By setting this property

setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);

You are locking your screen to LANDSCAPE only, after this even if user is holding device in portrait mode, it won't be rotated to portrait mode. You can do one thing as per my understanding of your problem.

android:configChanges="orientation"

In menifest file add this above property to your Activity. And in Activity class override onConfigurationChange method, Where you can handle orientation changes according to your need, instead of locking Activity to Landscape.

If i understood your problem in correct way then it may help you.

like image 25
Suresh Avatar answered Sep 18 '22 07:09

Suresh