Android: Implement MaximizeUsingFullscreenGeometryHint
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: I7a59a6c6fb51ebbdb86e7149e794726e67001279 Reviewed-by: Tor Arne Vestbø <tor.arne.vestbo@qt.io> Reviewed-by: BogDan Vatra <bogdan@kdab.com>
This commit is contained in:
parent
3e529369eb
commit
c17a5cec19
@ -121,6 +121,10 @@ public class QtActivityDelegate
|
||||
private static final String EXTRACT_STYLE_KEY = "extract.android.style";
|
||||
private static final String EXTRACT_STYLE_MINIMAL_KEY = "extract.android.style.option";
|
||||
|
||||
public static final int SYSTEM_UI_VISIBILITY_NORMAL = 0;
|
||||
public static final int SYSTEM_UI_VISIBILITY_FULLSCREEN = 1;
|
||||
public static final int SYSTEM_UI_VISIBILITY_TRANSLUCENT = 2;
|
||||
|
||||
private static String m_environmentVariables = null;
|
||||
private static String m_applicationParameters = null;
|
||||
|
||||
@ -131,7 +135,7 @@ public class QtActivityDelegate
|
||||
private long m_metaState;
|
||||
private int m_lastChar = 0;
|
||||
private int m_softInputMode = 0;
|
||||
private boolean m_fullScreen = false;
|
||||
private int m_systemUiVisibility = SYSTEM_UI_VISIBILITY_NORMAL;
|
||||
private boolean m_started = false;
|
||||
private HashMap<Integer, QtSurface> m_surfaces = null;
|
||||
private HashMap<Integer, View> m_nativeViews = null;
|
||||
@ -153,38 +157,51 @@ public class QtActivityDelegate
|
||||
private CursorHandle m_rightSelectionHandle;
|
||||
private EditPopupMenu m_editPopupMenu;
|
||||
|
||||
public void setFullScreen(boolean enterFullScreen)
|
||||
|
||||
public void setSystemUiVisibility(int systemUiVisibility)
|
||||
{
|
||||
if (m_fullScreen == enterFullScreen)
|
||||
if (m_systemUiVisibility == systemUiVisibility)
|
||||
return;
|
||||
|
||||
if (m_fullScreen = enterFullScreen) {
|
||||
m_activity.getWindow().addFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN);
|
||||
m_activity.getWindow().clearFlags(WindowManager.LayoutParams.FLAG_FORCE_NOT_FULLSCREEN);
|
||||
try {
|
||||
int flags = View.SYSTEM_UI_FLAG_HIDE_NAVIGATION;
|
||||
flags |= View.SYSTEM_UI_FLAG_LAYOUT_STABLE;
|
||||
flags |= View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION;
|
||||
flags |= View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN;
|
||||
flags |= View.SYSTEM_UI_FLAG_FULLSCREEN;
|
||||
flags |= View.class.getDeclaredField("SYSTEM_UI_FLAG_IMMERSIVE_STICKY").getInt(null);
|
||||
m_activity.getWindow().getDecorView().setSystemUiVisibility(flags | View.INVISIBLE);
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
} else {
|
||||
m_systemUiVisibility = systemUiVisibility;
|
||||
|
||||
int systemUiVisibilityFlags = 0;
|
||||
switch (m_systemUiVisibility) {
|
||||
case SYSTEM_UI_VISIBILITY_NORMAL:
|
||||
m_activity.getWindow().addFlags(WindowManager.LayoutParams.FLAG_FORCE_NOT_FULLSCREEN);
|
||||
m_activity.getWindow().clearFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN);
|
||||
m_activity.getWindow().getDecorView().setSystemUiVisibility(View.SYSTEM_UI_FLAG_VISIBLE);
|
||||
}
|
||||
systemUiVisibilityFlags = View.SYSTEM_UI_FLAG_VISIBLE;
|
||||
break;
|
||||
case SYSTEM_UI_VISIBILITY_FULLSCREEN:
|
||||
m_activity.getWindow().addFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN);
|
||||
m_activity.getWindow().clearFlags(WindowManager.LayoutParams.FLAG_FORCE_NOT_FULLSCREEN);
|
||||
systemUiVisibilityFlags = View.SYSTEM_UI_FLAG_HIDE_NAVIGATION
|
||||
| View.SYSTEM_UI_FLAG_LAYOUT_STABLE
|
||||
| View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION
|
||||
| View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN
|
||||
| View.SYSTEM_UI_FLAG_FULLSCREEN
|
||||
| View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY
|
||||
| View.INVISIBLE;
|
||||
break;
|
||||
case SYSTEM_UI_VISIBILITY_TRANSLUCENT:
|
||||
m_activity.getWindow().addFlags(WindowManager.LayoutParams.FLAG_FORCE_NOT_FULLSCREEN
|
||||
| WindowManager.LayoutParams.FLAG_TRANSLUCENT_NAVIGATION
|
||||
| WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS);
|
||||
m_activity.getWindow().clearFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN);
|
||||
systemUiVisibilityFlags = View.SYSTEM_UI_FLAG_VISIBLE;
|
||||
break;
|
||||
};
|
||||
|
||||
m_activity.getWindow().getDecorView().setSystemUiVisibility(systemUiVisibilityFlags);
|
||||
|
||||
m_layout.requestLayout();
|
||||
}
|
||||
|
||||
public void updateFullScreen()
|
||||
{
|
||||
if (m_fullScreen) {
|
||||
m_fullScreen = false;
|
||||
setFullScreen(true);
|
||||
if (m_systemUiVisibility == SYSTEM_UI_VISIBILITY_FULLSCREEN) {
|
||||
m_systemUiVisibility = SYSTEM_UI_VISIBILITY_NORMAL;
|
||||
setSystemUiVisibility(SYSTEM_UI_VISIBILITY_FULLSCREEN);
|
||||
}
|
||||
}
|
||||
|
||||
@ -943,7 +960,7 @@ public class QtActivityDelegate
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
outState.putBoolean("FullScreen", m_fullScreen);
|
||||
outState.putInt("SystemUiVisibility", m_systemUiVisibility);
|
||||
outState.putBoolean("Started", m_started);
|
||||
// It should never
|
||||
}
|
||||
|
@ -46,6 +46,7 @@ import android.util.AttributeSet;
|
||||
import android.util.DisplayMetrics;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.view.WindowInsets;
|
||||
|
||||
public class QtLayout extends ViewGroup
|
||||
{
|
||||
@ -69,10 +70,32 @@ public class QtLayout extends ViewGroup
|
||||
@Override
|
||||
protected void onSizeChanged (int w, int h, int oldw, int oldh)
|
||||
{
|
||||
DisplayMetrics metrics = new DisplayMetrics();
|
||||
((Activity) getContext()).getWindowManager().getDefaultDisplay().getMetrics(metrics);
|
||||
QtNative.setApplicationDisplayMetrics(metrics.widthPixels, metrics.heightPixels, w, h,
|
||||
metrics.xdpi, metrics.ydpi, metrics.scaledDensity, metrics.density);
|
||||
WindowInsets insets = getRootWindowInsets();
|
||||
|
||||
DisplayMetrics realMetrics = new DisplayMetrics();
|
||||
((Activity) getContext()).getWindowManager().getDefaultDisplay().getRealMetrics(realMetrics);
|
||||
|
||||
boolean isFullScreenView = h == realMetrics.heightPixels;
|
||||
|
||||
int insetLeft = isFullScreenView ? insets.getSystemWindowInsetLeft() : 0;
|
||||
int insetTop = isFullScreenView ? insets.getSystemWindowInsetTop() : 0;
|
||||
int insetRight = isFullScreenView ? insets.getSystemWindowInsetRight() : 0;
|
||||
int insetBottom = isFullScreenView ? insets.getSystemWindowInsetBottom() : 0;
|
||||
|
||||
int usableAreaWidth = w - insetLeft - insetRight;
|
||||
int usableAreaHeight = h - insetTop - insetBottom;
|
||||
|
||||
QtNative.setApplicationDisplayMetrics(realMetrics.widthPixels,
|
||||
realMetrics.heightPixels,
|
||||
insetLeft,
|
||||
insetTop,
|
||||
usableAreaWidth,
|
||||
usableAreaHeight,
|
||||
realMetrics.xdpi,
|
||||
realMetrics.ydpi,
|
||||
realMetrics.scaledDensity,
|
||||
realMetrics.density);
|
||||
|
||||
if (m_startApplicationRunnable != null) {
|
||||
m_startApplicationRunnable.run();
|
||||
m_startApplicationRunnable = null;
|
||||
|
@ -91,8 +91,10 @@ public class QtNative
|
||||
private static boolean m_started = false;
|
||||
private static int m_displayMetricsScreenWidthPixels = 0;
|
||||
private static int m_displayMetricsScreenHeightPixels = 0;
|
||||
private static int m_displayMetricsDesktopWidthPixels = 0;
|
||||
private static int m_displayMetricsDesktopHeightPixels = 0;
|
||||
private static int m_displayMetricsAvailableLeftPixels = 0;
|
||||
private static int m_displayMetricsAvailableTopPixels = 0;
|
||||
private static int m_displayMetricsAvailableWidthPixels = 0;
|
||||
private static int m_displayMetricsAvailableHeightPixels = 0;
|
||||
private static double m_displayMetricsXDpi = .0;
|
||||
private static double m_displayMetricsYDpi = .0;
|
||||
private static double m_displayMetricsScaledDensity = 1.0;
|
||||
@ -376,8 +378,10 @@ public class QtNative
|
||||
res[0] = startQtAndroidPlugin(qtParams, environment);
|
||||
setDisplayMetrics(m_displayMetricsScreenWidthPixels,
|
||||
m_displayMetricsScreenHeightPixels,
|
||||
m_displayMetricsDesktopWidthPixels,
|
||||
m_displayMetricsDesktopHeightPixels,
|
||||
m_displayMetricsAvailableLeftPixels,
|
||||
m_displayMetricsAvailableTopPixels,
|
||||
m_displayMetricsAvailableWidthPixels,
|
||||
m_displayMetricsAvailableHeightPixels,
|
||||
m_displayMetricsXDpi,
|
||||
m_displayMetricsYDpi,
|
||||
m_displayMetricsScaledDensity,
|
||||
@ -398,8 +402,10 @@ public class QtNative
|
||||
|
||||
public static void setApplicationDisplayMetrics(int screenWidthPixels,
|
||||
int screenHeightPixels,
|
||||
int desktopWidthPixels,
|
||||
int desktopHeightPixels,
|
||||
int availableLeftPixels,
|
||||
int availableTopPixels,
|
||||
int availableWidthPixels,
|
||||
int availableHeightPixels,
|
||||
double XDpi,
|
||||
double YDpi,
|
||||
double scaledDensity,
|
||||
@ -415,8 +421,10 @@ public class QtNative
|
||||
if (m_started) {
|
||||
setDisplayMetrics(screenWidthPixels,
|
||||
screenHeightPixels,
|
||||
desktopWidthPixels,
|
||||
desktopHeightPixels,
|
||||
availableLeftPixels,
|
||||
availableTopPixels,
|
||||
availableWidthPixels,
|
||||
availableHeightPixels,
|
||||
XDpi,
|
||||
YDpi,
|
||||
scaledDensity,
|
||||
@ -424,8 +432,10 @@ public class QtNative
|
||||
} else {
|
||||
m_displayMetricsScreenWidthPixels = screenWidthPixels;
|
||||
m_displayMetricsScreenHeightPixels = screenHeightPixels;
|
||||
m_displayMetricsDesktopWidthPixels = desktopWidthPixels;
|
||||
m_displayMetricsDesktopHeightPixels = desktopHeightPixels;
|
||||
m_displayMetricsAvailableLeftPixels = availableLeftPixels;
|
||||
m_displayMetricsAvailableTopPixels = availableTopPixels;
|
||||
m_displayMetricsAvailableWidthPixels = availableWidthPixels;
|
||||
m_displayMetricsAvailableHeightPixels = availableHeightPixels;
|
||||
m_displayMetricsXDpi = XDpi;
|
||||
m_displayMetricsYDpi = YDpi;
|
||||
m_displayMetricsScaledDensity = scaledDensity;
|
||||
@ -686,13 +696,13 @@ public class QtNative
|
||||
});
|
||||
}
|
||||
|
||||
private static void setFullScreen(final boolean fullScreen)
|
||||
private static void setSystemUiVisibility(final int systemUiVisibility)
|
||||
{
|
||||
runAction(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
if (m_activityDelegate != null) {
|
||||
m_activityDelegate.setFullScreen(fullScreen);
|
||||
m_activityDelegate.setSystemUiVisibility(systemUiVisibility);
|
||||
}
|
||||
updateWindow();
|
||||
}
|
||||
@ -1035,8 +1045,10 @@ public class QtNative
|
||||
// screen methods
|
||||
public static native void setDisplayMetrics(int screenWidthPixels,
|
||||
int screenHeightPixels,
|
||||
int desktopWidthPixels,
|
||||
int desktopHeightPixels,
|
||||
int availableLeftPixels,
|
||||
int availableTopPixels,
|
||||
int availableWidthPixels,
|
||||
int availableHeightPixels,
|
||||
double XDpi,
|
||||
double YDpi,
|
||||
double scaledDensity,
|
||||
|
@ -115,7 +115,7 @@ public class QtServiceDelegate
|
||||
QtNative.setService(m_service, this);
|
||||
QtNative.setClassLoader(classLoader);
|
||||
|
||||
QtNative.setApplicationDisplayMetrics(10, 10, 10, 10, 120, 120, 1.0, 1.0);
|
||||
QtNative.setApplicationDisplayMetrics(10, 10, 0, 0, 10, 10, 120, 120, 1.0, 1.0);
|
||||
|
||||
if (loaderParams.containsKey(STATIC_INIT_CLASSES_KEY)) {
|
||||
for (String className: loaderParams.getStringArray(STATIC_INIT_CLASSES_KEY)) {
|
||||
|
@ -247,8 +247,8 @@ namespace QtAndroidInput
|
||||
break;
|
||||
}
|
||||
|
||||
const int dw = desktopWidthPixels();
|
||||
const int dh = desktopHeightPixels();
|
||||
const int dw = availableWidthPixels();
|
||||
const int dh = availableHeightPixels();
|
||||
QWindowSystemInterface::TouchPoint touchPoint;
|
||||
touchPoint.id = id;
|
||||
touchPoint.pressure = pressure;
|
||||
|
@ -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},
|
||||
|
@ -77,8 +77,8 @@ namespace QtAndroid
|
||||
void bringChildToBack(int surfaceId);
|
||||
|
||||
QWindow *topLevelWindowAt(const QPoint &globalPos);
|
||||
int desktopWidthPixels();
|
||||
int desktopHeightPixels();
|
||||
int availableWidthPixels();
|
||||
int availableHeightPixels();
|
||||
double scaledDensity();
|
||||
double pixelDensity();
|
||||
JavaVM *javaVM();
|
||||
@ -88,8 +88,13 @@ namespace QtAndroid
|
||||
jobject activity();
|
||||
jobject service();
|
||||
|
||||
void showStatusBar();
|
||||
void hideStatusBar();
|
||||
// Keep synchronized with flags in ActivityDelegate.java
|
||||
enum SystemUiVisibility {
|
||||
SYSTEM_UI_VISIBILITY_NORMAL = 0,
|
||||
SYSTEM_UI_VISIBILITY_FULLSCREEN = 1,
|
||||
SYSTEM_UI_VISIBILITY_TRANSLUCENT = 2
|
||||
};
|
||||
void setSystemUiVisibility(SystemUiVisibility uiVisibility);
|
||||
|
||||
jobject createBitmap(QImage img, JNIEnv *env = 0);
|
||||
jobject createBitmap(int width, int height, QImage::Format format, JNIEnv *env);
|
||||
|
@ -76,12 +76,9 @@
|
||||
|
||||
QT_BEGIN_NAMESPACE
|
||||
|
||||
int QAndroidPlatformIntegration::m_defaultGeometryWidth = 320;
|
||||
int QAndroidPlatformIntegration::m_defaultGeometryHeight = 455;
|
||||
int QAndroidPlatformIntegration::m_defaultScreenWidth = 320;
|
||||
int QAndroidPlatformIntegration::m_defaultScreenHeight = 455;
|
||||
int QAndroidPlatformIntegration::m_defaultPhysicalSizeWidth = 50;
|
||||
int QAndroidPlatformIntegration::m_defaultPhysicalSizeHeight = 71;
|
||||
QSize QAndroidPlatformIntegration::m_defaultScreenSize = QSize(320, 455);
|
||||
QRect QAndroidPlatformIntegration::m_defaultAvailableGeometry = QRect(0, 0, 320, 455);
|
||||
QSize QAndroidPlatformIntegration::m_defaultPhysicalSize = QSize(50, 71);
|
||||
|
||||
Qt::ScreenOrientation QAndroidPlatformIntegration::m_orientation = Qt::PrimaryOrientation;
|
||||
Qt::ScreenOrientation QAndroidPlatformIntegration::m_nativeOrientation = Qt::PrimaryOrientation;
|
||||
@ -174,9 +171,9 @@ QAndroidPlatformIntegration::QAndroidPlatformIntegration(const QStringList ¶
|
||||
|
||||
m_primaryScreen = new QAndroidPlatformScreen();
|
||||
QWindowSystemInterface::handleScreenAdded(m_primaryScreen);
|
||||
m_primaryScreen->setPhysicalSize(QSize(m_defaultPhysicalSizeWidth, m_defaultPhysicalSizeHeight));
|
||||
m_primaryScreen->setSize(QSize(m_defaultScreenWidth, m_defaultScreenHeight));
|
||||
m_primaryScreen->setAvailableGeometry(QRect(0, 0, m_defaultGeometryWidth, m_defaultGeometryHeight));
|
||||
m_primaryScreen->setPhysicalSize(m_defaultPhysicalSize);
|
||||
m_primaryScreen->setSize(m_defaultScreenSize);
|
||||
m_primaryScreen->setAvailableGeometry(m_defaultAvailableGeometry);
|
||||
|
||||
m_mainThread = QThread::currentThread();
|
||||
|
||||
@ -266,6 +263,7 @@ bool QAndroidPlatformIntegration::hasCapability(Capability cap) const
|
||||
case ThreadedOpenGL: return !needsBasicRenderloopWorkaround() && QtAndroid::activity();
|
||||
case RasterGLSurface: return QtAndroid::activity();
|
||||
case TopStackedNativeChildWindows: return false;
|
||||
case MaximizeUsingFullscreenGeometry: return true;
|
||||
default:
|
||||
return QPlatformIntegration::hasCapability(cap);
|
||||
}
|
||||
@ -415,20 +413,19 @@ QPlatformTheme *QAndroidPlatformIntegration::createPlatformTheme(const QString &
|
||||
return 0;
|
||||
}
|
||||
|
||||
void QAndroidPlatformIntegration::setDefaultDisplayMetrics(int gw, int gh, int sw, int sh, int screenWidth, int screenHeight)
|
||||
void QAndroidPlatformIntegration::setDefaultDisplayMetrics(int availableLeft,
|
||||
int availableTop,
|
||||
int availableWidth,
|
||||
int availableHeight,
|
||||
int physicalWidth,
|
||||
int physicalHeight,
|
||||
int screenWidth,
|
||||
int screenHeight)
|
||||
{
|
||||
m_defaultGeometryWidth = gw;
|
||||
m_defaultGeometryHeight = gh;
|
||||
m_defaultPhysicalSizeWidth = sw;
|
||||
m_defaultPhysicalSizeHeight = sh;
|
||||
m_defaultScreenWidth = screenWidth;
|
||||
m_defaultScreenHeight = screenHeight;
|
||||
}
|
||||
|
||||
void QAndroidPlatformIntegration::setDefaultDesktopSize(int gw, int gh)
|
||||
{
|
||||
m_defaultGeometryWidth = gw;
|
||||
m_defaultGeometryHeight = gh;
|
||||
m_defaultAvailableGeometry = QRect(availableLeft, availableTop,
|
||||
availableWidth, availableHeight);
|
||||
m_defaultPhysicalSize = QSize(physicalWidth, physicalHeight);
|
||||
m_defaultScreenSize = QSize(screenWidth, screenHeight);
|
||||
}
|
||||
|
||||
void QAndroidPlatformIntegration::setScreenOrientation(Qt::ScreenOrientation currentOrientation,
|
||||
@ -440,10 +437,9 @@ void QAndroidPlatformIntegration::setScreenOrientation(Qt::ScreenOrientation cur
|
||||
|
||||
void QAndroidPlatformIntegration::flushPendingUpdates()
|
||||
{
|
||||
m_primaryScreen->setPhysicalSize(QSize(m_defaultPhysicalSizeWidth,
|
||||
m_defaultPhysicalSizeHeight));
|
||||
m_primaryScreen->setSize(QSize(m_defaultScreenWidth, m_defaultScreenHeight));
|
||||
m_primaryScreen->setAvailableGeometry(QRect(0, 0, m_defaultGeometryWidth, m_defaultGeometryHeight));
|
||||
m_primaryScreen->setPhysicalSize(m_defaultPhysicalSize);
|
||||
m_primaryScreen->setSize(m_defaultScreenSize);
|
||||
m_primaryScreen->setAvailableGeometry(m_defaultAvailableGeometry);
|
||||
}
|
||||
|
||||
#ifndef QT_NO_ACCESSIBILITY
|
||||
@ -453,13 +449,13 @@ QPlatformAccessibility *QAndroidPlatformIntegration::accessibility() const
|
||||
}
|
||||
#endif
|
||||
|
||||
void QAndroidPlatformIntegration::setDesktopSize(int width, int height)
|
||||
void QAndroidPlatformIntegration::setAvailableGeometry(const QRect &availableGeometry)
|
||||
{
|
||||
if (m_primaryScreen)
|
||||
QMetaObject::invokeMethod(m_primaryScreen, "setAvailableGeometry", Qt::AutoConnection, Q_ARG(QRect, QRect(0,0,width, height)));
|
||||
QMetaObject::invokeMethod(m_primaryScreen, "setAvailableGeometry", Qt::AutoConnection, Q_ARG(QRect, availableGeometry));
|
||||
}
|
||||
|
||||
void QAndroidPlatformIntegration::setDisplayMetrics(int width, int height)
|
||||
void QAndroidPlatformIntegration::setPhysicalSize(int width, int height)
|
||||
{
|
||||
if (m_primaryScreen)
|
||||
QMetaObject::invokeMethod(m_primaryScreen, "setPhysicalSize", Qt::AutoConnection, Q_ARG(QSize, QSize(width, height)));
|
||||
|
@ -91,8 +91,8 @@ public:
|
||||
QAndroidPlatformScreen *screen() { return m_primaryScreen; }
|
||||
QPlatformOffscreenSurface *createPlatformOffscreenSurface(QOffscreenSurface *surface) const override;
|
||||
|
||||
virtual void setDesktopSize(int width, int height);
|
||||
virtual void setDisplayMetrics(int width, int height);
|
||||
void setAvailableGeometry(const QRect &availableGeometry);
|
||||
void setPhysicalSize(int width, int height);
|
||||
void setScreenSize(int width, int height);
|
||||
bool isVirtualDesktop() { return true; }
|
||||
|
||||
@ -116,16 +116,17 @@ public:
|
||||
QStringList themeNames() const override;
|
||||
QPlatformTheme *createPlatformTheme(const QString &name) const override;
|
||||
|
||||
static void setDefaultDisplayMetrics(int gw, int gh, int sw, int sh, int width, int height);
|
||||
static void setDefaultDesktopSize(int gw, int gh);
|
||||
static void setDefaultDisplayMetrics(int availableLeft,
|
||||
int availableTop,
|
||||
int availableWidth,
|
||||
int availableHeight,
|
||||
int physicalWidth,
|
||||
int physicalHeight,
|
||||
int screenWidth,
|
||||
int screenHeight);
|
||||
static void setScreenOrientation(Qt::ScreenOrientation currentOrientation,
|
||||
Qt::ScreenOrientation nativeOrientation);
|
||||
|
||||
static QSize defaultDesktopSize()
|
||||
{
|
||||
return QSize(m_defaultGeometryWidth, m_defaultGeometryHeight);
|
||||
}
|
||||
|
||||
QTouchDevice *touchDevice() const { return m_touchDevice; }
|
||||
void setTouchDevice(QTouchDevice *touchDevice) { m_touchDevice = touchDevice; }
|
||||
|
||||
@ -143,12 +144,9 @@ private:
|
||||
|
||||
QThread *m_mainThread;
|
||||
|
||||
static int m_defaultGeometryWidth;
|
||||
static int m_defaultGeometryHeight;
|
||||
static int m_defaultPhysicalSizeWidth;
|
||||
static int m_defaultPhysicalSizeHeight;
|
||||
static int m_defaultScreenWidth;
|
||||
static int m_defaultScreenHeight;
|
||||
static QRect m_defaultAvailableGeometry;
|
||||
static QSize m_defaultPhysicalSize;
|
||||
static QSize m_defaultScreenSize;
|
||||
|
||||
static Qt::ScreenOrientation m_orientation;
|
||||
static Qt::ScreenOrientation m_nativeOrientation;
|
||||
|
@ -90,8 +90,8 @@ private:
|
||||
QAndroidPlatformScreen::QAndroidPlatformScreen()
|
||||
: QObject(), QPlatformScreen()
|
||||
{
|
||||
m_availableGeometry = QRect(0, 0, QAndroidPlatformIntegration::m_defaultGeometryWidth, QAndroidPlatformIntegration::m_defaultGeometryHeight);
|
||||
m_size = QSize(QAndroidPlatformIntegration::m_defaultScreenWidth, QAndroidPlatformIntegration::m_defaultScreenHeight);
|
||||
m_availableGeometry = QAndroidPlatformIntegration::m_defaultAvailableGeometry;
|
||||
m_size = QAndroidPlatformIntegration::m_defaultScreenSize;
|
||||
// Raster only apps should set QT_ANDROID_RASTER_IMAGE_DEPTH to 16
|
||||
// is way much faster than 32
|
||||
if (qEnvironmentVariableIntValue("QT_ANDROID_RASTER_IMAGE_DEPTH") == 16) {
|
||||
@ -101,8 +101,7 @@ QAndroidPlatformScreen::QAndroidPlatformScreen()
|
||||
m_format = QImage::Format_ARGB32_Premultiplied;
|
||||
m_depth = 32;
|
||||
}
|
||||
m_physicalSize.setHeight(QAndroidPlatformIntegration::m_defaultPhysicalSizeHeight);
|
||||
m_physicalSize.setWidth(QAndroidPlatformIntegration::m_defaultPhysicalSizeWidth);
|
||||
m_physicalSize = QAndroidPlatformIntegration::m_defaultPhysicalSize;
|
||||
connect(qGuiApp, &QGuiApplication::applicationStateChanged, this, &QAndroidPlatformScreen::applicationStateChanged);
|
||||
}
|
||||
|
||||
@ -294,7 +293,7 @@ void QAndroidPlatformScreen::topWindowChanged(QWindow *w)
|
||||
if (w != 0) {
|
||||
QAndroidPlatformWindow *platformWindow = static_cast<QAndroidPlatformWindow *>(w->handle());
|
||||
if (platformWindow != 0)
|
||||
platformWindow->updateStatusBarVisibility();
|
||||
platformWindow->updateSystemUiVisibility();
|
||||
}
|
||||
}
|
||||
|
||||
@ -334,7 +333,7 @@ void QAndroidPlatformScreen::doRedraw()
|
||||
}
|
||||
QMutexLocker lock(&m_surfaceMutex);
|
||||
if (m_id == -1 && m_rasterSurfaces) {
|
||||
m_id = QtAndroid::createSurface(this, m_availableGeometry, true, m_depth);
|
||||
m_id = QtAndroid::createSurface(this, geometry(), true, m_depth);
|
||||
AndroidDeadlockProtector protector;
|
||||
if (!protector.acquire())
|
||||
return;
|
||||
|
@ -67,25 +67,39 @@ void QAndroidPlatformWindow::lower()
|
||||
|
||||
void QAndroidPlatformWindow::raise()
|
||||
{
|
||||
updateStatusBarVisibility();
|
||||
updateSystemUiVisibility();
|
||||
platformScreen()->raise(this);
|
||||
}
|
||||
|
||||
QMargins QAndroidPlatformWindow::safeAreaMargins() const
|
||||
{
|
||||
if ((m_windowState & Qt::WindowMaximized) && (window()->flags() & Qt::MaximizeUsingFullscreenGeometryHint)) {
|
||||
QRect availableGeometry = platformScreen()->availableGeometry();
|
||||
return QMargins(availableGeometry.left(), availableGeometry.top(),
|
||||
availableGeometry.right(), availableGeometry.bottom());
|
||||
} else {
|
||||
return QPlatformWindow::safeAreaMargins();
|
||||
}
|
||||
}
|
||||
|
||||
void QAndroidPlatformWindow::setGeometry(const QRect &rect)
|
||||
{
|
||||
QPlatformWindow::setGeometry(rect);
|
||||
QWindowSystemInterface::handleGeometryChange(window(), rect);
|
||||
}
|
||||
|
||||
void QAndroidPlatformWindow::setVisible(bool visible)
|
||||
{
|
||||
if (visible)
|
||||
updateStatusBarVisibility();
|
||||
updateSystemUiVisibility();
|
||||
|
||||
if (visible) {
|
||||
if (m_windowState & Qt::WindowFullScreen)
|
||||
if ((m_windowState & Qt::WindowFullScreen)
|
||||
|| ((m_windowState & Qt::WindowMaximized) && (window()->flags() & Qt::MaximizeUsingFullscreenGeometryHint))) {
|
||||
setGeometry(platformScreen()->geometry());
|
||||
else if (m_windowState & Qt::WindowMaximized)
|
||||
} else if (m_windowState & Qt::WindowMaximized) {
|
||||
setGeometry(platformScreen()->availableGeometry());
|
||||
}
|
||||
}
|
||||
|
||||
if (visible)
|
||||
@ -107,7 +121,7 @@ void QAndroidPlatformWindow::setWindowState(Qt::WindowStates state)
|
||||
m_windowState = state;
|
||||
|
||||
if (window()->isVisible())
|
||||
updateStatusBarVisibility();
|
||||
updateSystemUiVisibility();
|
||||
}
|
||||
|
||||
void QAndroidPlatformWindow::setWindowFlags(Qt::WindowFlags flags)
|
||||
@ -143,15 +157,17 @@ void QAndroidPlatformWindow::requestActivateWindow()
|
||||
platformScreen()->topWindowChanged(window());
|
||||
}
|
||||
|
||||
void QAndroidPlatformWindow::updateStatusBarVisibility()
|
||||
void QAndroidPlatformWindow::updateSystemUiVisibility()
|
||||
{
|
||||
Qt::WindowFlags flags = window()->flags();
|
||||
bool isNonRegularWindow = flags & (Qt::Popup | Qt::Dialog | Qt::Sheet) & ~Qt::Window;
|
||||
if (!isNonRegularWindow) {
|
||||
if (m_windowState & Qt::WindowFullScreen)
|
||||
QtAndroid::hideStatusBar();
|
||||
QtAndroid::setSystemUiVisibility(QtAndroid::SYSTEM_UI_VISIBILITY_FULLSCREEN);
|
||||
else if (flags & Qt::MaximizeUsingFullscreenGeometryHint)
|
||||
QtAndroid::setSystemUiVisibility(QtAndroid::SYSTEM_UI_VISIBILITY_TRANSLUCENT);
|
||||
else
|
||||
QtAndroid::showStatusBar();
|
||||
QtAndroid::setSystemUiVisibility(QtAndroid::SYSTEM_UI_VISIBILITY_NORMAL);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -70,9 +70,11 @@ public:
|
||||
|
||||
QAndroidPlatformScreen *platformScreen() const;
|
||||
|
||||
QMargins safeAreaMargins() const override;
|
||||
|
||||
void propagateSizeHints() override;
|
||||
void requestActivateWindow() override;
|
||||
void updateStatusBarVisibility();
|
||||
void updateSystemUiVisibility();
|
||||
inline bool isRaster() const {
|
||||
if (isForeignWindow())
|
||||
return false;
|
||||
|
Loading…
Reference in New Issue
Block a user