Manually rotate screen - android

Hs there any chance to rotate the screen on Android programmatically for the whole system?
Background is that I'm using a CMPC-device which features a non-Android-supported rotation sensor, and as a quick fix, I'm planning to write a small app that changes orientation for the entire system.
Is there any function available for this purpose?
I couldn't find anything on the documentation :(

You can find what you want here :
http://www.anddev.org/rotate_screen_from_code_change_screen_orientation-t2687.html

App can't change orientation for entire system. I guess, you need to make custom build of Android for this purpose.

Related

Android 9 Screen Rotation Approach

Our team has recently updated a system application (installed in priv-app) from Android 5 to Android 9. This seems to have broken the previously working (and relatively well documented approach) of programmatically flipping the device orientation.
We had been using this approach and it had worked at globablly flipping the device orientation 180 degrees:
Settings.System.putInt( context.getApplicationContext().getContentResolver(), Settings.System.USER_ROTATION, 2)
We check each time to make sure the accelerometer rotation is disabled also. The setting does in fact stick as when interrogate the settings provider and can see the value being updated, the screen is simply not reacting, even after a reboot etc..
I'm trying to understand if Android 9 introduced any further gotchas that can prevent a screen rotation from happening, would be grateful if anyone had any insight on this particular issue?
You can instead use Activity.setRequestedOrientation() if its a particular Activity your want to change. This can be set explicitly to portrait, reverse portrait, landscape, reverse landscape, etc... It will then lock to the orientation you set. You can use the various sensor values if you want it to be flexible for the user.
If you want to know what your current orientation is (including reverse orientations) it can be complicated but I just answered my own question here about how to do it - Android sensor orientation problems with edge-to-edge insets
If you want to change the system rotation
You need to ensure ACCELEROMETER_ROTATION is off and then the value you use needs to come from the surface rotation constants (which are relative to your displays natural orientation) - https://developer.android.com/reference/android/view/Surface#ROTATION_0
Another quick edit - any Activity can override this setting (including a launcher) for themselves. So it may be that whatever you are running is actually what changed to lock or allow certain orientations.

How to make animations smoother in low refresh rate display android device?

this question is a general question.I just wanted to know if there is any way through.I am having a very low refresh rate display android device due to which all the animations are getting lagged.I am needing a scaling animation which shrinks and grows of which i am having code but the issue is the smoothness.Is there any possible way that i can make my animation smoother for scaling animation or any way which shows like the animation appears smoother?>
Thanks in advance.
I have faced a similar issue with abrupt animations. Actually, the problem is not with the refresh rate of the device, the application might not be using the full hardware capabilities of the Android device, so not much can really be done
Also add the following line in the application tag of the manifest android:hardwareAccelerated="true" to ensure HW acceleration is used

How to get device orientation

What is the best way to get the device orientation with cocos2d-x (c++)?
My Android/iOS application does support all 4 device orientations, and more important than knowing if it is landscape or portrait, I would like to know if it is upside down or not.
I will have to know from within a CCLayer.
UPDATE
I am trying to get events for right tilt and left tilt. To do so, I am calculating the angle at which the device is held. However, I need to know what orientation the device has, to be able to know if I am actually tilting left or right.
Though cocos2d-x is cross platform, few things are still very much platform dependent, for example, if you see the CCFileUtils, we have separate implementation files for iOS, Android etc, the cross platform is maintained with a single header,
Keeping that in mind,
In Android, you can get the device orientation by using the constants,
Surface.ROTATION_0 (no rotation)
Surface.ROTATION_90
Surface.ROTATION_180
Surface.ROTATION_270.
which you can get by calling Display.getRotation()
(It only rotate in all these directions if, android:screenOrientation:fullSensor is set)
And in iOS,
You can get the values with
UIDeviceOrientationPortrait
UIDeviceOrientationPortraitUpsideDown
UIDeviceOrientationLandscapeLeft
UIDeviceOrientationLandscapeRight
(It only rotates in all these directions if, supportedInterfaceOrientations method returns UIInterfaceOrientationMaskAll)
Note:
Its not a good practice to rotate a phone upside down in portrait mode, only on tablets its accepted.. (Apple might even reject your app for this reason)
Let me know if you want to know how to use it, but googling the keywords will give you the usage..
After a quick google search :
http://www.cocos2d-x.org/wiki/Device_Orientation
http://www.cocos2d-x.org/forums/6/topics/36414
UDPDATE:
I don't think you can determine the orientation the way you want to from cocos2d-x.
Then the only solution that I'm thinking of is to go into java through jni and use android's methods to determine the current orientation. Here's a
link
on how to determine all 4 orientations.
As for how to call java methods from c++, that's another ball game.

How to detect when device is oriented upside-down in libGDX

I'm starting to develop a game for Android using libGDX.
I noticed that some sample games for this library all have fixed screen orientation. I want my game to be landscape all the time, but I want to rotate the camera 180 degrees when the device is turned upside down (most well behaved Android apps do this automatically).
I'm looking at the docs and Googling, but can't find anything about it.
Basically, I'd like to know what to add to base libGDX app. that shows libGDX logo, to just react when phone is turned upside down?
The Android docs, list this functionality in getRotation function here:
http://developer.android.com/reference/android/view/Display.html#getRotation%28%29
This allows you to get 0/180 or 90/270 for rotation and thus detect how the device is turned.
But I don't see this exposed in libGDX?
Nevermind, I just found it. You need to change:
android:screenOrientation="landscape"
to:
android:screenOrientation="sensorLandscape"
and it works automagically. Maybe libGDX devs should make this the default.

How can I add shake functionality in my Android application?

I want to develop an application with some advance features like shake feature, orientation of images, zoom in/out, scrolling, etc. For instance, the
user can shake the phone in order to erase an entered text. Also, by rotating the phone
clockwise or anti-clockwise, the orientation of the underlying images will change.
How would I do that?
For shaking:
You will need to use the phone's accelerometer sensor. You can find many examples of this if you Google (for example: Android: I want to shake it)
For rotations:
When the phone detects an orientation change, Android will destroy and recreate your application. There are lifecycle methods (see http://developer.android.com/reference/android/app/Activity.html) that are called that allow you to save and restore your application's current state. Again, if you Google:
http://developer.android.com/guide/topics/resources/runtime-changes.html
http://www.androidguys.com/2008/10/14/rotational-forceson-your-android-app/

Categories

Resources