summaryrefslogtreecommitdiffstats
path: root/src/android/jar/src/org/qtproject/qt/android/ExtractStyle.java
diff options
context:
space:
mode:
Diffstat (limited to 'src/android/jar/src/org/qtproject/qt/android/ExtractStyle.java')
-rw-r--r--src/android/jar/src/org/qtproject/qt/android/ExtractStyle.java61
1 files changed, 44 insertions, 17 deletions
diff --git a/src/android/jar/src/org/qtproject/qt/android/ExtractStyle.java b/src/android/jar/src/org/qtproject/qt/android/ExtractStyle.java
index 672a2e28d3..6780634317 100644
--- a/src/android/jar/src/org/qtproject/qt/android/ExtractStyle.java
+++ b/src/android/jar/src/org/qtproject/qt/android/ExtractStyle.java
@@ -5,8 +5,10 @@
package org.qtproject.qt.android;
import android.annotation.SuppressLint;
+import android.app.Activity;
import android.content.Context;
import android.content.res.ColorStateList;
+import android.content.res.Configuration;
import android.content.res.Resources;
import android.content.res.TypedArray;
import android.content.res.XmlResourceParser;
@@ -34,7 +36,6 @@ import android.graphics.drawable.ScaleDrawable;
import android.graphics.drawable.StateListDrawable;
import android.graphics.drawable.VectorDrawable;
import android.os.Build;
-import android.os.Bundle;
import android.util.AttributeSet;
import android.util.Log;
import android.util.TypedValue;
@@ -60,7 +61,7 @@ import java.util.Map;
import java.util.Objects;
-public class ExtractStyle {
+class ExtractStyle {
// This used to be retrieved from android.R.styleable.ViewDrawableStates field via reflection,
// but since the access to that is restricted, we need to have hard-coded here.
@@ -136,26 +137,56 @@ public class ExtractStyle {
Context m_context;
private final HashMap<String, DrawableCache> m_drawableCache = new HashMap<>();
- private static final String EXTRACT_STYLE_KEY = "extract.android.style";
- private static final String EXTRACT_STYLE_MINIMAL_KEY = "extract.android.style.option";
-
private static boolean m_missingNormalStyle = false;
private static boolean m_missingDarkStyle = false;
private static String m_stylePath = null;
private static boolean m_extractMinimal = false;
- public static void setup(Bundle loaderParams) {
- if (loaderParams.containsKey(EXTRACT_STYLE_KEY)) {
- m_stylePath = loaderParams.getString(EXTRACT_STYLE_KEY);
+ private static final String QtTAG = "QtExtractStyle";
+
+ private static boolean isUiModeDark(Configuration config)
+ {
+ return (config.uiMode & Configuration.UI_MODE_NIGHT_MASK) == Configuration.UI_MODE_NIGHT_YES;
+ }
+
+ public static String setup(Context context, String extractOption, int dpi) {
+
+ String dataDir = context.getApplicationInfo().dataDir;
+ m_stylePath = dataDir + "/qt-reserved-files/android-style/" + dpi + "/";
+
+ if (extractOption.equals("none"))
+ return m_stylePath;
- boolean darkModeFileMissing = !(new File(m_stylePath + "darkUiMode/style.json").exists());
- m_missingDarkStyle = Build.VERSION.SDK_INT > 28 && darkModeFileMissing;
+ if (extractOption.isEmpty())
+ extractOption = "minimal";
- m_missingNormalStyle = !(new File(m_stylePath + "style.json").exists());
+ if (!extractOption.equals("default") && !extractOption.equals("full")
+ && !extractOption.equals("minimal") && !extractOption.equals("none")) {
+ Log.e(QtTAG, "Invalid extract_android_style option \"" + extractOption
+ + "\", defaulting to \"minimal\"");
+ extractOption = "minimal";
+ }
- m_extractMinimal = loaderParams.containsKey(EXTRACT_STYLE_MINIMAL_KEY) &&
- loaderParams.getBoolean(EXTRACT_STYLE_MINIMAL_KEY);
+ // QTBUG-69810: The extraction code will trigger compatibility warnings on Android
+ // SDK version >= 28 when the target SDK version is set to something lower then 28,
+ // so default to "none" and issue a warning if that is the case.
+ if (extractOption.equals("default")) {
+ int targetSdk = context.getApplicationInfo().targetSdkVersion;
+ if (targetSdk < 28 && Build.VERSION.SDK_INT >= 28) {
+ Log.e(QtTAG, "extract_android_style option set to \"none\" when " +
+ "targetSdkVersion is less then 28");
+ extractOption = "none";
+ }
}
+
+ boolean darkModeFileMissing = !(new File(m_stylePath + "darkUiMode/style.json").exists());
+ m_missingDarkStyle = Build.VERSION.SDK_INT > 28 && darkModeFileMissing;
+ m_missingNormalStyle = !(new File(m_stylePath + "style.json").exists());
+ m_extractMinimal = extractOption.equals("minimal");
+
+ ExtractStyle.runIfNeeded(context, isUiModeDark(context.getResources().getConfiguration()));
+
+ return m_stylePath;
}
public static void runIfNeeded(Context context, boolean extractDarkMode) {
@@ -1104,10 +1135,6 @@ public class ExtractStyle {
return json;
}
- public JSONObject extractTextAppearanceInformation(int styleName, String qtClass, AttributeSet attributeSet) {
- return extractTextAppearanceInformation(styleName, qtClass, android.R.attr.textAppearance, attributeSet);
- }
-
public JSONObject extractTextAppearanceInformation(int styleName, String qtClass) {
return extractTextAppearanceInformation(styleName, qtClass, android.R.attr.textAppearance, null);
}