Android: extract various constants into one common class

Various constant keys were duplicated in QtActivityDelegate,
QtServiceDelegate and QtLoader classes, and this de-duplicates that.

Task-number: QTBUG-115014
Task-number: QTBUG-114593
Change-Id: I3479fbb58293b26b7625f8653289c6b6d987a59f
Reviewed-by: Tinja Paavoseppä <tinja.paavoseppa@qt.io>
This commit is contained in:
Assam Boudjelthia 2022-10-01 03:42:56 +03:00
parent d9845e2ac8
commit 4102db752e
6 changed files with 38 additions and 42 deletions

View File

@ -24,6 +24,7 @@ set(java_sources
src/org/qtproject/qt/android/extras//QtAndroidBinder.java
src/org/qtproject/qt/android/extras/QtAndroidServiceConnection.java
src/org/qtproject/qt/android/extras/QtNative.java
src/org/qtproject/qt/android/QtConstants.java
)
qt_internal_add_jar(Qt${QtBase_VERSION_MAJOR}Android

View File

@ -66,6 +66,7 @@ import java.util.HashMap;
import java.util.Objects;
import org.qtproject.qt.android.accessibility.QtAccessibilityDelegate;
import static org.qtproject.qt.android.QtConstants.*;
public class QtActivityDelegate
{
@ -81,13 +82,6 @@ public class QtActivityDelegate
private Method m_super_dispatchGenericMotionEvent = null;
private Method m_super_onWindowFocusChanged = null;
private static final String NATIVE_LIBRARIES_KEY = "native.libraries";
private static final String BUNDLED_LIBRARIES_KEY = "bundled.libraries";
private static final String MAIN_LIBRARY_KEY = "main.library";
private static final String ENVIRONMENT_VARIABLES_KEY = "environment.variables";
private static final String APPLICATION_PARAMETERS_KEY = "application.parameters";
private static final String STATIC_INIT_CLASSES_KEY = "static.init.classes";
// Keep in sync with QtAndroid::SystemUiVisibility in androidjnimain.h
public static final int SYSTEM_UI_VISIBILITY_NORMAL = 0;
public static final int SYSTEM_UI_VISIBILITY_FULLSCREEN = 1;
@ -222,13 +216,6 @@ public class QtActivityDelegate
private final int EnterKeyNext = 6;
private final int EnterKeyPrevious = 7;
// application state
public static final int ApplicationSuspended = 0x0;
public static final int ApplicationHidden = 0x1;
public static final int ApplicationInactive = 0x2;
public static final int ApplicationActive = 0x4;
public boolean setKeyboardVisibility(boolean visibility, long timeStamp)
{
if (m_showHideTimeStamp > timeStamp)
@ -1037,12 +1024,12 @@ public class QtActivityDelegate
public void onPause()
{
if (Build.VERSION.SDK_INT < 24 || !m_activity.isInMultiWindowMode())
QtNative.setApplicationState(ApplicationInactive);
QtNative.setApplicationState(ApplicationState.ApplicationInactive);
}
public void onResume()
{
QtNative.setApplicationState(ApplicationActive);
QtNative.setApplicationState(ApplicationState.ApplicationActive);
if (m_started) {
QtNative.updateWindow();
updateFullScreen(); // Suspending the app clears the immersive mode, so we need to set it again.
@ -1068,7 +1055,7 @@ public class QtActivityDelegate
public void onStop()
{
QtNative.setApplicationState(ApplicationSuspended);
QtNative.setApplicationState(ApplicationState.ApplicationSuspended);
}
public Object onRetainNonConfigurationInstance()

View File

@ -0,0 +1,28 @@
// Copyright (C) 2023 The Qt Company Ltd.
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause
package org.qtproject.qt.android;
public class QtConstants {
public static final String ERROR_CODE_KEY = "error.code";
public static final String ERROR_MESSAGE_KEY = "error.message";
public static final String DEX_PATH_KEY = "dex.path";
public static final String LIB_PATH_KEY = "lib.path";
public static final String LOADER_CLASS_NAME_KEY = "loader.class.name";
public static final String NATIVE_LIBRARIES_KEY = "native.libraries";
public static final String ENVIRONMENT_VARIABLES_KEY = "environment.variables";
public static final String APPLICATION_PARAMETERS_KEY = "application.parameters";
public static final String BUNDLED_LIBRARIES_KEY = "bundled.libraries";
public static final String MAIN_LIBRARY_KEY = "main.library";
public static final String STATIC_INIT_CLASSES_KEY = "static.init.classes";
public static final String EXTRACT_STYLE_KEY = "extract.android.style";
public static final String EXTRACT_STYLE_MINIMAL_KEY = "extract.android.style.option";
// Application states
public static class ApplicationState {
public static final int ApplicationSuspended = 0x0;
public static final int ApplicationHidden = 0x1;
public static final int ApplicationInactive = 0x2;
public static final int ApplicationActive = 0x4;
}
}

View File

@ -27,22 +27,11 @@ import java.util.List;
import dalvik.system.DexClassLoader;
import static org.qtproject.qt.android.QtConstants.*;
public abstract class QtLoader {
static String QtTAG = "Qt";
public static final String ERROR_CODE_KEY = "error.code";
public static final String ERROR_MESSAGE_KEY = "error.message";
public static final String DEX_PATH_KEY = "dex.path";
public static final String LIB_PATH_KEY = "lib.path";
public static final String LOADER_CLASS_NAME_KEY = "loader.class.name";
public static final String NATIVE_LIBRARIES_KEY = "native.libraries";
public static final String ENVIRONMENT_VARIABLES_KEY = "environment.variables";
public static final String APPLICATION_PARAMETERS_KEY = "application.parameters";
public static final String BUNDLED_LIBRARIES_KEY = "bundled.libraries";
public static final String MAIN_LIBRARY_KEY = "main.library";
public static final String STATIC_INIT_CLASSES_KEY = "static.init.classes";
public static final String EXTRACT_STYLE_KEY = "extract.android.style";
private static final String EXTRACT_STYLE_MINIMAL_KEY = "extract.android.style.option";
// These parameters matter in case of deploying application as system (embedded into firmware)
public static final String SYSTEM_LIB_PATH = "/system/lib/";

View File

@ -338,7 +338,7 @@ public class QtNative
{
synchronized (m_mainActivityMutex) {
switch (state) {
case QtActivityDelegate.ApplicationActive:
case QtConstants.ApplicationState.ApplicationActive:
m_activityPaused = false;
Iterator<Runnable> itr = m_lostActions.iterator();
while (itr.hasNext())

View File

@ -50,19 +50,10 @@ import java.util.HashMap;
import java.util.Iterator;
import java.util.Objects;
import static org.qtproject.qt.android.QtConstants.*;
public class QtServiceDelegate
{
private static final String NATIVE_LIBRARIES_KEY = "native.libraries";
private static final String BUNDLED_LIBRARIES_KEY = "bundled.libraries";
private static final String MAIN_LIBRARY_KEY = "main.library";
private static final String ENVIRONMENT_VARIABLES_KEY = "environment.variables";
private static final String APPLICATION_PARAMETERS_KEY = "application.parameters";
private static final String STATIC_INIT_CLASSES_KEY = "static.init.classes";
private static final String APP_DISPLAY_METRIC_SCREEN_DESKTOP_KEY = "display.screen.desktop";
private static final String APP_DISPLAY_METRIC_SCREEN_XDPI_KEY = "display.screen.dpi.x";
private static final String APP_DISPLAY_METRIC_SCREEN_YDPI_KEY = "display.screen.dpi.y";
private static final String APP_DISPLAY_METRIC_SCREEN_DENSITY_KEY = "display.screen.density";
private String m_mainLib = null;
private Service m_service = null;
private static String m_applicationParameters = null;