diff options
author | Eskil Abrahamsen Blomfeldt <eskil.abrahamsen-blomfeldt@qt.io> | 2020-01-16 09:06:06 +0100 |
---|---|---|
committer | Eskil Abrahamsen Blomfeldt <eskil.abrahamsen-blomfeldt@qt.io> | 2020-03-30 13:03:49 +0100 |
commit | a35a7fcb5a713956e97bc87ccbd273737c7418df (patch) | |
tree | 14aca562752c4b2444243b589fe6b5c53913a24c /src/plugins/platforms/android/androidjnimain.cpp | |
parent | 3f73995a03c4b40e2648cb9af5d3e7ca393bf597 (diff) |
Android: Implement MaximizeUsingFullscreenGeometryHint
(This reintroduces c17a5cec1901dd23f4c39ec2ae47a060fbb06895,
which was reverted in Qt 5 because it requires API level 23.)
This flag tells the app to use as much of the screen as possible
while still keeping system UI visible, and can be supported on Android
by using translucent system UI, similar to iOS.
What this does:
1. It changes the current fullscreen/not-fullscreen logic to
allow three states: fullscreen, fullscreen with translucent
decorations and not-fullscreen.
2. In order for it to work, we have to send the actual
screen geometry and available geometry, at least in the case
where the user needs to know the available geometry to
know the safe area of the window. So we get the real screen
metrics and pass these to the QPA plugin (API level 17, so
we can do that now that the minimum version is 21.)
3. Note that getting the insets and calculating the useable
area does not work for non-fullscreen windows, since Android
is quite inconsistent in this respect. So in this case we
just use the window size and origin of 0,0 for the available
geometry.
4. Since we are touching this code anyway, this patch also tries to use
more consistent wording (calling it "available geometry" everywhere
instead of desktop geometry in some places and just geometry in
others, etc.)
[ChangeLog][Android] Qt::MaximizeUsingFullscreenGeometryHint window
flag is now supported, and will make the window fullscreen, but keep
the system UI on-screen, with a translucent background color.
Fixes: QTBUG-74202
Change-Id: I4cc5ef9cc2a3bd22d4d8d2bb767c6ff8a3aa75c0
Reviewed-by: Assam Boudjelthia <assam.boudjelthia@qt.io>
Reviewed-by: Christian Strømme <christian.stromme@qt.io>
Diffstat (limited to 'src/plugins/platforms/android/androidjnimain.cpp')
-rw-r--r-- | src/plugins/platforms/android/androidjnimain.cpp | 69 |
1 files changed, 27 insertions, 42 deletions
diff --git a/src/plugins/platforms/android/androidjnimain.cpp b/src/plugins/platforms/android/androidjnimain.cpp index 1c7800358f..3f41ead818 100644 --- a/src/plugins/platforms/android/androidjnimain.cpp +++ b/src/plugins/platforms/android/androidjnimain.cpp @@ -111,8 +111,8 @@ static int m_surfaceId = 1; static QAndroidPlatformIntegration *m_androidPlatformIntegration = nullptr; -static int m_desktopWidthPixels = 0; -static int m_desktopHeightPixels = 0; +static int m_availableWidthPixels = 0; +static int m_availableHeightPixels = 0; static double m_scaledDensity = 0; static double m_density = 1.0; @@ -155,14 +155,14 @@ namespace QtAndroid : 0; } - int desktopWidthPixels() + int availableWidthPixels() { - return m_desktopWidthPixels; + return m_availableWidthPixels; } - int desktopHeightPixels() + int availableHeightPixels() { - return m_desktopHeightPixels; + return m_availableHeightPixels; } double scaledDensity() @@ -200,22 +200,9 @@ namespace QtAndroid return m_serviceObject; } - void showStatusBar() + void setSystemUiVisibility(SystemUiVisibility uiVisibility) { - if (m_statusBarShowing) - return; - - QJNIObjectPrivate::callStaticMethod<void>(m_applicationClass, "setFullScreen", "(Z)V", false); - m_statusBarShowing = true; - } - - void hideStatusBar() - { - if (!m_statusBarShowing) - return; - - QJNIObjectPrivate::callStaticMethod<void>(m_applicationClass, "setFullScreen", "(Z)V", true); - m_statusBarShowing = false; + QJNIObjectPrivate::callStaticMethod<void>(m_applicationClass, "setSystemUiVisibility", "(I)V", jint(uiVisibility)); } jobject createBitmap(QImage img, JNIEnv *env) @@ -620,35 +607,33 @@ static void setSurface(JNIEnv *env, jobject /*thiz*/, jint id, jobject jSurface, } static void setDisplayMetrics(JNIEnv */*env*/, jclass /*clazz*/, - jint widthPixels, jint heightPixels, - jint desktopWidthPixels, jint desktopHeightPixels, + jint screenWidthPixels, jint screenHeightPixels, + jint availableLeftPixels, jint availableTopPixels, + jint availableWidthPixels, jint availableHeightPixels, jdouble xdpi, jdouble ydpi, jdouble scaledDensity, jdouble density) { - // Android does not give us the correct screen size for immersive mode, but - // the surface does have the right size - - widthPixels = qMax(widthPixels, desktopWidthPixels); - heightPixels = qMax(heightPixels, desktopHeightPixels); - - m_desktopWidthPixels = desktopWidthPixels; - m_desktopHeightPixels = desktopHeightPixels; + m_availableWidthPixels = availableWidthPixels; + m_availableHeightPixels = availableHeightPixels; m_scaledDensity = scaledDensity; m_density = density; QMutexLocker lock(&m_platformMutex); if (!m_androidPlatformIntegration) { - QAndroidPlatformIntegration::setDefaultDisplayMetrics(desktopWidthPixels, - desktopHeightPixels, - qRound(double(widthPixels) / xdpi * 25.4), - qRound(double(heightPixels) / ydpi * 25.4), - widthPixels, - heightPixels); + QAndroidPlatformIntegration::setDefaultDisplayMetrics(availableLeftPixels, + availableTopPixels, + availableWidthPixels, + availableHeightPixels, + qRound(double(screenWidthPixels) / xdpi * 25.4), + qRound(double(screenHeightPixels) / ydpi * 25.4), + screenWidthPixels, + screenHeightPixels); } else { - m_androidPlatformIntegration->setDisplayMetrics(qRound(double(widthPixels) / xdpi * 25.4), - qRound(double(heightPixels) / ydpi * 25.4)); - m_androidPlatformIntegration->setScreenSize(widthPixels, heightPixels); - m_androidPlatformIntegration->setDesktopSize(desktopWidthPixels, desktopHeightPixels); + m_androidPlatformIntegration->setPhysicalSize(qRound(double(screenWidthPixels) / xdpi * 25.4), + qRound(double(screenHeightPixels) / ydpi * 25.4)); + m_androidPlatformIntegration->setScreenSize(screenWidthPixels, screenHeightPixels); + m_androidPlatformIntegration->setAvailableGeometry(QRect(availableLeftPixels, availableTopPixels, + availableWidthPixels, availableHeightPixels)); } } @@ -774,7 +759,7 @@ static JNINativeMethod methods[] = { {"quitQtCoreApplication", "()V", (void *)quitQtCoreApplication}, {"terminateQt", "()V", (void *)terminateQt}, {"waitForServiceSetup", "()V", (void *)waitForServiceSetup}, - {"setDisplayMetrics", "(IIIIDDDD)V", (void *)setDisplayMetrics}, + {"setDisplayMetrics", "(IIIIIIDDDD)V", (void *)setDisplayMetrics}, {"setSurface", "(ILjava/lang/Object;II)V", (void *)setSurface}, {"updateWindow", "()V", (void *)updateWindow}, {"updateApplicationState", "(I)V", (void *)updateApplicationState}, |