I want to implement device rotation in my flash game running on AIR and Android. I use Starling, and when i rotate my device, Starling reinitializes the OpenGL device/context, this will destroy all textures and load them again after reinitialization, and time in which stage is rotated is too big, at least this is what i think it do.
The question is: how can i improve the time in which my stage is rotated ?
I think i can listen to StageOrientationEvent.ORIENTATION_CHANGING to prevent it from default behaviour, and rotate manually my game (rotate main sprite). But if i do this, and for example rotate my device from default orientation to left, then i can't rotate them back to default because the orientation state remains on default and event isn't dispatched. Can i somehow set the orientation state without actually orient the stage?
Did you tried to use:
Starling.handleLostContext = true
to handle lost Context?
This option should be enabled before you launch your Starling instance and it is the easiest way to automatically handle lost context.
Related
Please note: This question is about Qt C++ framework, not normal Java API. In Java, this question has already been answered.
In the main menu of my application, I really don't want to worry about different kinds of screen rotation. I would like to disable screen rotation until user goes to other views where screen rotation is meaningful. For main menu, I want to use portrait view only.
How to achieve that? How to control app screen rotation?
You can set the orientation using
QAndroidJniObject activity = QtAndroid::androidActivity();
activity.callMethod<void>("setRequestedOrientation", "(I)V", orientation);
where orientation is an int representing the orientation. You can copy the codes provided in the documentation (e.g., 0 to lock landscape, 1 to lock portrait and -1 to unlock any rotation), but I recommend to use, e.g.,
QAndroidJniObject::getStaticField<int>("android.content.pm.ActivityInfo", "SCREEN_ORIENTATION_LANDSCAPE");
to get the code values.
This answer is based on https://stackoverflow.com/a/38947312/4248972. The difference is that this answer also explains how to unlock rotation again and provides a sample to show how to get the orientation codes without manual copying.
I am struggling with a quite rare problem.
Here it goes:
I have a SurfaceView and there is a JNI-side thread that handling the rendering operations on it (Let say Render-thread). For "some" reason I need to rotate my drawings by myself inside the render-thread. To achieve this, the render thread queries the rotation status from the android framework. And I can see the rotated screen whenever the device is rotated, but there is a problem: if I rotate the device, the screen rendered by Render-Thread is rotated, but Android UIs (such as notification bar, toast message, etc) are not rotated (Of course!). To resolve this problem, I use setRequestedOrientation function to tell the Android to rotate my Activity. Then I can also see the properly rotated Android UIs. At this moment, my real problem happens: The race between Render-Thread and Android's screen rotation stuff (I guess surface flinger?).
Apparently, if I call setRequestedOrientation function, Android framework rotates the screen by itself, while my Render-thread is also drawing the rotated screen. And this results in a glitch.
My question here is that:
Is there a way to tell Android framework not to rotate the SurfaceView while I'm still calling setRequestedOrientation?
Sorry for my bad english.
I develop a game in which will be implemented autoOrientation, but when i rotate device and stage orientation is changed, then reinitialization process take too long time (because i use GPU to render game content), therefore i decided to disable autoOrientation and manually calculate the orientation of the device from accelerometer data, and then rotate the main game sprite accordingly to calculated orientation...and it works, but SystemBar remains static in its first position when game was launched. The question is how to set SystemBar position in Android, something like this
SetBarPosition(TOP / BOTTOM / RIGHT / LEFT);
In this case you should handle the orientation change yourself instead of disabling it. On android you should implement onConfigurationChanged() method and add to manifest that you handle orientation changes.
I try to use a Camera inside my app and I have a problem with proper handling of configuration changes. I know the proper way of handling configuration changes in a typical Activity (onSaveInstanceState etc...), but it's not the case here.
Think of my Activity as a fullscreen camera preview with an overlay shutter button and a frame which will be used to crop the image
What I'm trying to achieve (preview of a stock HTC Sense camera): http://youtu.be/uzfUJUNHY68
That is: the camera preview which is on TextureView should not be recreated on rotation, but the Activity should be orientation-aware, to position elements.
I'm pretty sure I don't want the Activity to be recreated on rotation. So I tried the android:configChanges approach. The problem is that onSurfaceTextureSizeChanged() is still called and the camera preview is rotated and the whole experience is not smooth (the preview lags for a moment and gets "recreated" or something).
I tried locking my Activity to landscape via android:screenOrientation="landscape", but this way onConfigurationChanged() is not called and I don't know how to position other views like in the video above. I guess I could listen to some accelerator events, but I'm pretty sure there is a better way. Is there?
Android camera source.
Lock activity rotation. On method onOrientationChanged of MyOrientationEventListener you can rotate, change positions of views etc. I think it's a best way.
Try with this option.
android:configChanges="keyboardHidden|orientation|screenSize"
I have an activity that is showing a compass, and I need to know the orientation of the screen to properly rotate the needle. I need to distinguish between 90° and 270° degree rotation to properly handle this.
When I rotate the screen (on my Nexus S at least) the activity's onCreate gets called, e.g. when I rotate from portrait to landscape mode. When I rotate from one landscape mode to the other with the top edge raised, onCreate() gets called twice (once for portrait orientation and once for the target landscape mode).
However, when I rotate with the bottom edge up, the screen rotates 180° and onCreate is not getting called. Is there an event that gets fired in this case?
You are correct that at a 180 degree rotation you will not get restarted or get a configuration change, because the configuration has not actually changed. (It is still in landscape or portrait, and everything else is the same.)
However if you are showing a compass, that must mean you are updating it from sensor events. Thus you can just call Display.getRotation() each time you get a sensor update to get the current rotation of the screen. In fact that you need is rotation of interpreting sensor events (or actually how your drawing of them will be modified when it gets to the screen), not just the orientation.
I found a relevant blog post that is well worth reading.
Be sure to read the SDK documentation.
Also check out the discussion about using Display.getRotation() to correctly remap sensor coordinates.
The helper class OrientationEventListener makes it very easy to get call backs on rotation. I would suggest you give it a try.
Just take a look at the SensorManager Documentation, there you can get the best examples and explanations of how to use the accelerometer to get the most precise informations. Instead of making the things just by detecting the phone orientation, with that API you can get the exactly rotation, just like used by racing games like Asphalt and Need For Speed.
As Monchote said, in order to make your needle rotate as expected on the compass, it's better to lock your UI to portrait or landscape, and change your needle angle according to the device rotation angle, which can be gained easily from OrientationListener.
In this way, no matter the auto rotation feature is opened or not by user, you can always get rotation angle change notification. Here's a good example for your reference.
Have a look at the OnConfigurationChanged method to track down the orientation change and re-arrange your UI as needed.
See some sample code