Get phone orientation but fix screen orientation to portrait

Here is a multi-purpose class for easily managing screen orientation changes: public class OrientationManager extends OrientationEventListener { public enum ScreenOrientation { REVERSED_LANDSCAPE, LANDSCAPE, PORTRAIT, REVERSED_PORTRAIT } public ScreenOrientation screenOrientation; private OrientationListener listener; public OrientationManager(Context context, int rate, OrientationListener listener) { super(context, rate); setListener(listener); } public OrientationManager(Context context, int rate) { super(context, rate); } public OrientationManager(Context … Read more

Detecting if a device is able to change orientation in JavaScript

Detecting mobile devices: Simple browser sniffing if (/mobile/i.test(navigator.userAgent)) {…} jQuery.browser.mobile plug-in (exhaustive browser sniffing) Simple test for touch events if (‘ontouchstart’ in window) {…} Advanced test for touch events: if ((‘ontouchstart’ in window) || // Advanced test for touch events (window.DocumentTouch && document instanceof DocumentTouch) || ((hash[‘touch’] && hash[‘touch’].offsetTop) === 9)) {…} Optionally use onorientationchange … Read more

How to stop changing the orientation when a progress bar is spinning in android

This is happening because when screen orientation rotates the Activity gets re-started. In this case you can add configChanges attribute in your tag in the AndroidManifest file to stop the re-creation of the Activity. <activity android:name=”.Activity_name” android:configChanges=”orientation|keyboardHidden”> By, this your orientation can change will the progress bar is working and also it won’t stop though … Read more

Mobile viewport height after orientation change

Use the resize event The resize event will include the appropriate width and height after an orientationchange, but you do not want to listen for all resize events. Therefore, we add a one-off resize event listener after an orientation change: Javascript: window.addEventListener(‘orientationchange’, function() { // After orientationchange, add a one-time resize event var afterOrientationChange = … Read more

How to detect orientation change?

Here’s how I got it working: In AppDelegate.swift inside the didFinishLaunchingWithOptions function I put: NotificationCenter.default.addObserver(self, selector: #selector(AppDelegate.rotated), name: UIDevice.orientationDidChangeNotification, object: nil) and then inside the AppDelegate class I put the following function: func rotated() { if UIDeviceOrientationIsLandscape(UIDevice.current.orientation) { print(“Landscape”) } if UIDeviceOrientationIsPortrait(UIDevice.current.orientation) { print(“Portrait”) } } Hope this helps anyone else! Thanks!