Skip to content

armgit / krita

Public Imported from GitHub
0

Krita is a free and open source cross-platform application that offers an end-to-end solution for creating digital art files from scratch built on the KDE and Qt frameworks.

C++

[android] Handle full-screen mode directly

Carsten Hartenfelsa88f08bd14f9
diff --git a/libs/global/KisAndroidUtils.cpp b/libs/global/KisAndroidUtils.cpp
index b40852ef91..2a50e2b30f 100644
--- a/libs/global/KisAndroidUtils.cpp
+++ b/libs/global/KisAndroidUtils.cpp
@@ -69,4 +69,34 @@ void clearJniException(const QString &location)
}
}
+bool isInFullScreen()
+{
+ QJniObject activity = QJniObject::callStaticObjectMethod("org/qtproject/qt5/android/QtNative",
+ "activity",
+ "()Landroid/app/Activity;");
+ KisAndroidUtils::clearJniException(QStringLiteral("getting activity in isInFullScreen"));
+ if (activity.isValid()) {
+ bool fullScreen = activity.callMethod<jboolean>("isInFullScreen", "()Z");
+ KisAndroidUtils::clearJniException(QStringLiteral("calling isInFullScreen"));
+ return fullScreen;
+ } else {
+ qWarning("isInFullScreen: activity not valid");
+ return false;
+ }
+}
+
+void setFullScreen(bool fullScreen)
+{
+ QJniObject activity = QJniObject::callStaticObjectMethod("org/qtproject/qt5/android/QtNative",
+ "activity",
+ "()Landroid/app/Activity;");
+ KisAndroidUtils::clearJniException(QStringLiteral("getting activity in setFullScreen"));
+ if (activity.isValid()) {
+ activity.callMethod<void>("setFullScreenOnUiThread", "(Z)V", jboolean(fullScreen));
+ KisAndroidUtils::clearJniException(QStringLiteral("calling setFullScreenOnUiThread"));
+ } else {
+ qWarning("setFullScreen: activity not valid");
+ }
+}
+
} // namespace KisAndroidUtils
diff --git a/libs/global/KisAndroidUtils.h b/libs/global/KisAndroidUtils.h
index 0fd7eae88b..2f9976963a 100644
--- a/libs/global/KisAndroidUtils.h
+++ b/libs/global/KisAndroidUtils.h
@@ -28,6 +28,12 @@ KRITAGLOBAL_EXPORT bool isLowMemoryKillReportSupported();
// stuff, such as QDesktopServices, can throw JNI errors and don't clear them.
KRITAGLOBAL_EXPORT void clearJniException(const QString &location);
+// Checks whether we are in immersive mode, which is basically full-screen.
+KRITAGLOBAL_EXPORT bool isInFullScreen();
+
+// Enters or exits immersive mode if we're not in that state already.
+KRITAGLOBAL_EXPORT void setFullScreen(bool fullScreen);
+
} // namespace KisAndroidUtils
#endif // __KISANDROIDUTILS_H_
diff --git a/libs/ui/KisMainWindow.cpp b/libs/ui/KisMainWindow.cpp
index 7cf796a258..305066ca54 100644
--- a/libs/ui/KisMainWindow.cpp
+++ b/libs/ui/KisMainWindow.cpp
@@ -384,9 +384,6 @@ KisMainWindow::KisMainWindow(QUuid uuid)
connect(KisPart::instance(), SIGNAL(documentClosed(QString)), SLOT(updateWindowMenu()));
connect(KisPart::instance(), SIGNAL(documentOpened(QString)), SLOT(updateWindowMenu()));
connect(KisConfigNotifier::instance(), SIGNAL(configChanged()), this, SLOT(configChanged()));
-#ifdef Q_OS_ANDROID
- connect(this, &KisMainWindow::sigFullscreenOnShow, this, &KisMainWindow::viewFullscreen, Qt::QueuedConnection);
-#endif
actionCollection()->addAssociatedWidget(this);
KoPluginLoader::instance()->load("Krita/ViewPlugin", KoPluginLoader::PluginsConfig(), d->viewManager, false);
@@ -1641,7 +1638,6 @@ void KisMainWindow::showEvent(QShowEvent *event)
setMainWindowLayoutForCurrentMainWidget(d->widgetStack->currentIndex(), false);
}
#ifdef Q_OS_ANDROID
- Q_EMIT sigFullscreenOnShow(true); // Android defaults to fullscreen.
// The user can conceivably purchase a product from the splash screen while
// Krita is still loading. In that case, the "pending" flag will be set. The
// dialog in question will clear the flag.
@@ -2377,6 +2373,14 @@ void KisMainWindow::slotToolbarToggled(bool toggle)
void KisMainWindow::viewFullscreen(bool fullScreen)
{
+#ifdef Q_OS_ANDROID
+ // Full-screening on Android applies to the entire application, not this
+ // window in particular. Qt tries to paper over that matter, but it causes
+ // some pretty horrid flickering when the main window gets hidden. We just
+ // talk to the Android interface directly to get around that.
+ KisAndroidUtils::setFullScreen(fullScreen);
+ d->fullScreenMode->setChecked(fullScreen);
+#else
KisConfig cfg(false);
cfg.setFullscreenMode(fullScreen);
@@ -2386,6 +2390,7 @@ void KisMainWindow::viewFullscreen(bool fullScreen)
setWindowState(windowState() & ~Qt::WindowFullScreen); // reset
}
d->fullScreenMode->setChecked(isFullScreen());
+#endif
}
QDockWidget* KisMainWindow::createDockWidget(KoDockFactoryBase* factory)
@@ -3195,7 +3200,13 @@ void KisMainWindow::initializeGeometry()
move(x,y);
setGeometry(geometry().x(), geometry().y(), w, h);
}
- d->fullScreenMode->setChecked(isFullScreen());
+#ifdef Q_OS_ANDROID
+ // We handle full-screening differently on Android, see viewFullScreen.
+ bool fullScreen = KisAndroidUtils::isInFullScreen();
+#else
+ bool fullScreen = isFullScreen();
+#endif
+ d->fullScreenMode->setChecked(fullScreen);
}
void KisMainWindow::showManual()
diff --git a/libs/ui/KisMainWindow.h b/libs/ui/KisMainWindow.h
index c907d6a7ae..005a83c636 100644
--- a/libs/ui/KisMainWindow.h
+++ b/libs/ui/KisMainWindow.h
@@ -205,10 +205,6 @@ Q_SIGNALS:
/// emitted when the current view has changed
void activeViewChanged();
-#ifdef Q_OS_ANDROID
- void sigFullscreenOnShow(bool fullScreen);
-#endif
-
public Q_SLOTS:
diff --git a/packaging/android/apk/src/org/krita/android/MainActivity.java b/packaging/android/apk/src/org/krita/android/MainActivity.java
index d3d9af21d2..0083e02599 100644
--- a/packaging/android/apk/src/org/krita/android/MainActivity.java
+++ b/packaging/android/apk/src/org/krita/android/MainActivity.java
@@ -46,6 +46,7 @@ public class MainActivity extends QtActivity {
private static String applicationLoadingText = "";
private boolean haveLibsLoaded = false;
private boolean serviceStarted = false;
+ private boolean inFullScreen = false;
private DonationDialog mDonationDialog = null;
@Override
@@ -84,11 +85,7 @@ public class MainActivity extends QtActivity {
serviceStarted = true;
// Full-screening the application here instead of after the main window is shown avoids
// some ugly flicker as the Qt UI resizes itself.
- try {
- setFullScreen(true);
- } catch (Exception | UnsatisfiedLinkError e) {
- Log.e(TAG, "Failed to enter fullscreen", e);
- }
+ trySetFullScreen(true);
// Keep the service started so in an unfortunate case where we're not allowed to start a
// foreground service, we can try to continue without it.
Intent docSaverServiceIntent = new Intent(this, DocumentSaverService.class);
@@ -204,6 +201,25 @@ public class MainActivity extends QtActivity {
new ConfigsManager(this).handleAssets();
}
+ public boolean isInFullScreen() {
+ return inFullScreen;
+ }
+
+ public void setFullScreenOnUiThread(boolean fullScreen) {
+ if (fullScreen != inFullScreen) {
+ runOnUiThread(() -> trySetFullScreen(fullScreen));
+ }
+ }
+
+ private void trySetFullScreen(boolean fullScreen) {
+ try {
+ setFullScreen(fullScreen);
+ inFullScreen = fullScreen;
+ } catch (Exception | UnsatisfiedLinkError e) {
+ Log.e(TAG, "Failed to set fullscreen " + fullScreen, e);
+ }
+ }
+
public static int getLongPressTimeout() {
try {
return ViewConfiguration.get(QtNative.activity()).getLongPressTimeout();