Qt
Internal/Contributor docs for the Qt SDK. Note: These are NOT official API docs; those are found at https://doc.qt.io/
Loading...
Searching...
No Matches
QtActivityDelegateBase.java
Go to the documentation of this file.
1// Copyright (C) 2017 BogDan Vatra <bogdan@kde.org>
2// Copyright (C) 2023 The Qt Company Ltd.
3// Copyright (C) 2016 Olivier Goffart <ogoffart@woboq.com>
4// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
5
6package org.qtproject.qt.android;
7
8import android.app.Activity;
9import android.app.UiModeManager;
10import android.content.pm.ActivityInfo;
11import android.content.pm.PackageManager;
12import android.content.res.Configuration;
13import android.content.res.Resources;
14import android.graphics.Color;
15import android.os.Build;
16import android.view.Window;
17import android.view.WindowInsetsController;
18
19import java.util.HashMap;
20
21abstract class QtActivityDelegateBase
22{
23 protected final Activity m_activity;
24 protected final HashMap<Integer, QtWindow> m_topLevelWindows = new HashMap<>();
25 protected final QtDisplayManager m_displayManager;
26 protected final QtInputDelegate m_inputDelegate;
27 protected final QtAccessibilityDelegate m_accessibilityDelegate;
28
29 private boolean m_membersInitialized = false;
30 private boolean m_contextMenuVisible = false;
31
32 static native boolean canOverrideColorSchemeHint();
33 static native void updateUiContrast(float newUiContrast);
34
35 // Subclass must implement these
36 abstract void startNativeApplicationImpl(String appParams, String mainLib);
37
38 // With these we are okay with default implementation doing nothing
39 void setUpLayout() {}
40 void setUpSplashScreen(int orientation) {}
41 void hideSplashScreen(final int duration) {}
42 void setActionBarVisibility(boolean visible) {}
43
44 QtActivityDelegateBase(Activity activity)
45 {
46 m_activity = activity;
47 QtNative.setActivity(m_activity);
48 m_displayManager = new QtDisplayManager(m_activity);
49 m_inputDelegate = new QtInputDelegate(() -> {
50 QtWindowInsetsController.restoreFullScreenVisibility(m_activity);
51 });
52 m_accessibilityDelegate = new QtAccessibilityDelegate();
53 }
54
55 QtDisplayManager displayManager() {
56 return m_displayManager;
57 }
58
59 QtInputDelegate getInputDelegate() {
60 return m_inputDelegate;
61 }
62
63 void setContextMenuVisible(boolean contextMenuVisible)
64 {
65 m_contextMenuVisible = contextMenuVisible;
66 }
67
68 boolean isContextMenuVisible()
69 {
70 return m_contextMenuVisible;
71 }
72
73 void startNativeApplication(String appParams, String mainLib)
74 {
75 if (m_membersInitialized)
76 return;
77 initMembers();
78 startNativeApplicationImpl(appParams, mainLib);
79 }
80
81 void initMembers()
82 {
83 m_membersInitialized = true;
84 m_topLevelWindows.clear();
85 m_displayManager.registerDisplayListener();
86 m_inputDelegate.initInputMethodManager(m_activity);
87
88 try {
89 PackageManager pm = m_activity.getPackageManager();
90 ActivityInfo activityInfo = pm.getActivityInfo(m_activity.getComponentName(), 0);
91 m_inputDelegate.setSoftInputMode(activityInfo.softInputMode);
92 } catch (PackageManager.NameNotFoundException e) {
93 e.printStackTrace();
94 }
95
96 setUpLayout();
97 }
98
99 void hideSplashScreen()
100 {
101 hideSplashScreen(0);
102 }
103
104 void handleUiModeChange()
105 {
106 Resources resources = m_activity.getResources();
107 Configuration config = resources.getConfiguration();
108 int uiMode = config.uiMode & Configuration.UI_MODE_NIGHT_MASK;
109
110 if (QtWindowInsetsController.decorFitsSystemWindows(m_activity)) {
111 Window window = m_activity.getWindow();
112 QtWindowInsetsController.enableSystemBarsBackgroundDrawing(window);
113 int status = QtWindowInsetsController.getThemeDefaultStatusBarColor(m_activity);
114 QtWindowInsetsController.setStatusBarColor(window, status);
115 int nav = QtWindowInsetsController.getThemeDefaultNavigationBarColor(m_activity);
116 QtWindowInsetsController.setNavigationBarColor(window, nav);
117 }
118
119 // Don't override color scheme if the app has it set explicitly.
120 if (canOverrideColorSchemeHint()) {
121 boolean isLight = uiMode == Configuration.UI_MODE_NIGHT_NO;
122 QtWindowInsetsController.setStatusBarColorHint(m_activity, isLight);
123 QtWindowInsetsController.setNavigationBarColorHint(m_activity, isLight);
124 }
125
126 switch (uiMode) {
127 case Configuration.UI_MODE_NIGHT_NO:
128 ExtractStyle.runIfNeeded(m_activity, false);
129 QtDisplayManager.handleUiDarkModeChanged(0);
130 break;
131 case Configuration.UI_MODE_NIGHT_YES:
132 ExtractStyle.runIfNeeded(m_activity, true);
133 QtDisplayManager.handleUiDarkModeChanged(1);
134 break;
135 }
136
137 if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.UPSIDE_DOWN_CAKE) {
138 // FIXME: Handle contrast changes the same way as uiMode changes (QTBUG-140749).
139 UiModeManager uiModeManager =
140 (UiModeManager) m_activity.getSystemService(m_activity.UI_MODE_SERVICE);
141 updateUiContrast(uiModeManager.getContrast());
142 }
143 }
144}
Q_CORE_EXPORT QtJniTypes::Activity activity()
EGLConfig config
[3]
aWidget window() -> setWindowTitle("New Window Title")
[2]