SystemBar/BottomBar in Android - android

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.

Related

Temporarily, programmatically disable screen rotation in Qt

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.

Is there a device and interface orientation in Android (like in iOS)?

Is there a way to get the device orientation in Android even if the interface orientation remains the same? I turn the device 180 degrees, the UI is upside down. But I still want to be notified.
You should set up an OrientationEventListener in the Activity you want to be notified of changes in.
Then you will have to specify the desired ScreenOrientation in the manifest for that Activity to prevent the screen from rotating.

stage orientation in flash

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.

Is there a way to do a "setRotation()" either with a method or code?

So I want my app to always lock onto the natural orientation of the device. So basically, I want to force the rotation to 0 degrees. There's a getRotation() method here:
http://developer.android.com/reference/android/view/Display.html
However, there is no setRotation(int rotation) that would accept one of the Surface.ROTATION_X parameters found here:
http://developer.android.com/reference/android/view/Surface.html
So, is there some way to do this with a single line of code that will always work? Or would this have to be done with some code?
The only thing I can think of as a manual solution is the following, but I have some concerns about it.
I can use the display.getRotation(). Then I'll check if it's 0 or 180 degrees, after that I'll get the display height and width, and see which one is longer than the other. If it appears I'm in landscape mode, then I'll know that the device's natural orientation is landscape so I could set it to landscape. However if the rotation was 270 or 90, then I would know the natural orientation is portrait, and I could set it to portrait.
However, my concern is where to do this such that it always works. Let's say the user is rotating the screen as this piece of code is executing, if the device changes orientation in between the time I use the getRotation() method, and check the width against the height with some if statements and what not, I think it could throw everything off. What happens if I put this in onCreate() or onResume()? Is it possible that things can get out of wack?
Is it possible for a the onCreate() or onResume() to be interrupted by a screen re-orientation due to the user turn the device around? The other issue is that if you flip the device by 180 degrees, the activity is never destroyed, so I think the behavior of this situation could very whether it's a 90 degree turn, or a 180 degree turn.
You can "set" the screen orientation in the manifest. See here: http://developer.android.com/guide/topics/manifest/activity-element.html#screen
<activity
android:name=".Activity"
android:screenOrientation="portrait"
android:theme="#style/Theme.D1"
android:label="#string/title_activity"/>
The value you're probably looking for is; "user" The user's current preferred orientation. However, I would test this on several test cases to be sure. HTH!

How do I detect screen rotation

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

Categories

Resources