honoring rotation lock in android - java

I am trying to honor the android rotation lock setting - I want my app to display in whatever orientation the home screen is locked in. I found the following knobs:
Settings.System.ACCELEROMETER_ROTATION - determine if the screen orientation is locked.
Display.getRotation() - determine if the device is rotated from it's "natural" orientation, which may be portrait or landscape.
Display.getWidth()/getHeight() - determine the current orientation of the device.
I thought this would be simple to do, but I can't seem to find the right combination of the above to get this to work. The reported values seem inconsistent, especially during app startup (is onResume the right place to check these values?).
Note I don't want to simply always fix the orientation of my activity to portrait or landscape, I want to set it to the orientation the user has locked the screen in. For tablets this could be landscape or portrait. If the user sets the Auto-Rotate setting, I want my activity to operate in sensor mode.

after hours of debugging, it appears the answer is as simple as checking if rotation is locked and if so, calling setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_NOSENSOR). Now excuse me while I go step off the nearest bridge...

Related

Set different constraints for each orientation in Android Studio

The question sounds way harder than it is. Simply all I want to do is to be able to set a different layout for, I already added a landscape orientation, and recreated the whole design the way I desire in landscape. However, the app restarts each time I rotate the phone, if I add android:configChanges="orientation" in manifest, it does save the state but not the way I set in landscape. The app is 4 layouts in each orientation. So if I could just make different constraints for landscape the doesn't interrupt the original portrait it could solve my problem.
sorry for the poor explanation. It's my first week with Android.
You are correct in designing different layouts for different orientations.
For the state, you should override the onSaveInstanceState() method in Java.
Using that, you can save the state of the application and then inflate the layout the way you like in Java.

Android Screen/Camera Orientation: Landscape Right/Left vs Portrait Up/Down

How to distinguish between Landscape (Right/Left) vs Portrait (Up/Down) on android? I tried:
getResources().getConfiguration().orientation
and it always returns Configuration.ORIENTATION_PORTRAIT.
also, I checked:
How to detect landscape left (normal) vs landscape right (reverse) with support for naturally landscape devices?
Check orientation on Android phone
I tried the onConfigurationChanged as well. I cannot get Right vs Left on landscape mode (up vs down on portrait).
Is there a clean way of finding this on Android 5.0+?
Note: My activity could be launched with any orientation. Capturing orientation changes using a listener may not be viable since I want the real orientation of the phone (even before I get a callback on orientation changes).
Also, by default:
android:screenOrientation="portrait"
Note: My activity responds to auto-rotate changes.

android-how to prevent screen from turning on in this case? [duplicate]

I have an activity that shows up when the phone screen goes to sleep/turns off ie turns black.
For some reason, the phone turns on when the volume buttons or the camera buttons are pressed. By turns on, I mean the screen wakes up or comes back from the black screen state.
I've tried using dispatchKeyEvent(KeyEvent event) and the buttons are disabled on the activity, but they still wake up the phone.
You could try overriding the onKeyDown(KeyEvent) method and change what happens for those keys. However, I'm not too optimistic as if you're running an activity, it will be in an inactive state when the display is off, and also it could be that the phone is hard wired to wake up on those buttons. It could be device specific. Hard to say. Try that out and let me know how it goes, I'm currious

Android. Change system screen brightness immediately

I am making a widget that changes system screen brightness on click.
I did it like on this post
Everything works well, but changings brightness takes approximately 1 second, but I want to change it immediately, like it does default android widget.
How can I do it?
I feel like this question is similar, correct me if I'm wrong
Changing screen brightness programmatically (as with the power widget)

Android amazon mp3 keyguard controls

Anyone have an idea how the Amazon mp3 app is displaying the player controls inside of the keyguard? I've been playing with some of the system alert and system overlay window parameters with now luck. The system alert will display over everything except the lock screen and the system overlay will display over the lock screen but in 4.0.3 and above you can not receive the touch events.
I have also seen options like WindowManager.LayoutParams.TYPE_KEYGUARD_DIALOG but it only seems to work for an activity; anything else I use it with gives me an exception that tells me that I can not use that flag with this type of window.
What I have noticed is that the player controls either replace or cover the keyguard clock and the player controls change size depending on the type of lock (like pattern lock or swipe lock). I've also noticed that the keyguard does not display my wallpaper anymore...
Any thoughts are welcome!

Categories

Resources