diff options
author | Paul Olav Tvete <paul.tvete@digia.com> | 2013-09-13 13:11:45 +0200 |
---|---|---|
committer | The Qt Project <gerrit-noreply@qt-project.org> | 2013-09-20 12:02:58 +0200 |
commit | 74d2249e37ba8cdefba8d90345a620dc6adfa411 (patch) | |
tree | 99252bce8f4d058b6a03b9af2c6a5a9f4e432030 /src/android | |
parent | dd6b053b6c40feeca845b89af08d026d8d487426 (diff) |
Android: handle inverted orientations
Add logic to detect InvertedPortrait and InvertedLandscape orientations
and implement QPlatformScreen::nativeOrientation() for Android.
Task-number: QTBUG-32144
Change-Id: I294506714ea0faa9eacd7a15e1cfc45342659964
Reviewed-by: BogDan Vatra <bogdan@kde.org>
Diffstat (limited to 'src/android')
-rw-r--r-- | src/android/jar/src/org/qtproject/qt5/android/QtActivityDelegate.java | 25 | ||||
-rw-r--r-- | src/android/jar/src/org/qtproject/qt5/android/QtNative.java | 2 |
2 files changed, 19 insertions, 8 deletions
diff --git a/src/android/jar/src/org/qtproject/qt5/android/QtActivityDelegate.java b/src/android/jar/src/org/qtproject/qt5/android/QtActivityDelegate.java index 8dc804cce4..dff437c3d8 100644 --- a/src/android/jar/src/org/qtproject/qt5/android/QtActivityDelegate.java +++ b/src/android/jar/src/org/qtproject/qt5/android/QtActivityDelegate.java @@ -70,6 +70,7 @@ import android.view.View; import android.view.ViewGroup; import android.view.WindowManager; import android.view.inputmethod.InputMethodManager; +import android.view.Surface; public class QtActivityDelegate { @@ -93,7 +94,8 @@ public class QtActivityDelegate private static String m_environmentVariables = null; private static String m_applicationParameters = null; - private int m_currentOrientation = Configuration.ORIENTATION_UNDEFINED; + private int m_currentRotation = -1; // undefined + private int m_nativeOrientation = Configuration.ORIENTATION_UNDEFINED; private String m_mainLib; private long m_metaState; @@ -587,7 +589,17 @@ public class QtActivityDelegate m_layout.bringChildToFront(m_surface); m_activity.registerForContextMenu(m_layout); - m_currentOrientation = m_activity.getResources().getConfiguration().orientation; + int orientation = m_activity.getResources().getConfiguration().orientation; + int rotation = m_activity.getWindowManager().getDefaultDisplay().getRotation(); + boolean rot90 = (rotation == Surface.ROTATION_90 || rotation == Surface.ROTATION_270); + boolean currentlyLandscape = (orientation == Configuration.ORIENTATION_LANDSCAPE); + if ((currentlyLandscape && !rot90) || (!currentlyLandscape && rot90)) + m_nativeOrientation = Configuration.ORIENTATION_LANDSCAPE; + else + m_nativeOrientation = Configuration.ORIENTATION_PORTRAIT; + + QtNative.handleOrientationChanged(rotation, m_nativeOrientation); + m_currentRotation = rotation; } public void onConfigurationChanged(Configuration configuration) @@ -597,13 +609,12 @@ public class QtActivityDelegate } catch (Exception e) { e.printStackTrace(); } - - if (configuration.orientation != m_currentOrientation - && m_currentOrientation != Configuration.ORIENTATION_UNDEFINED) { - QtNative.handleOrientationChanged(configuration.orientation); + int rotation = m_activity.getWindowManager().getDefaultDisplay().getRotation(); + if (rotation != m_currentRotation) { + QtNative.handleOrientationChanged(rotation, m_nativeOrientation); } - m_currentOrientation = configuration.orientation; + m_currentRotation = rotation; } public void onDestroy() diff --git a/src/android/jar/src/org/qtproject/qt5/android/QtNative.java b/src/android/jar/src/org/qtproject/qt5/android/QtNative.java index 51f00a73c6..244654786d 100644 --- a/src/android/jar/src/org/qtproject/qt5/android/QtNative.java +++ b/src/android/jar/src/org/qtproject/qt5/android/QtNative.java @@ -553,7 +553,7 @@ public class QtNative double XDpi, double YDpi, double scaledDensity); - public static native void handleOrientationChanged(int newOrientation); + public static native void handleOrientationChanged(int newRotation, int nativeOrientation); // screen methods // pointer methods |