-
Notifications
You must be signed in to change notification settings - Fork 0
/
android-21-22.diff
69 lines (64 loc) · 3.03 KB
/
android-21-22.diff
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
diff --git a/src/android/jar/src/org/qtproject/qt5/android/ExtractStyle.java b/src/android/jar/src/org/qtproject/qt5/android/ExtractStyle.java
index 9dba7f2..85a7027 100644
--- a/src/android/jar/src/org/qtproject/qt5/android/ExtractStyle.java
+++ b/src/android/jar/src/org/qtproject/qt5/android/ExtractStyle.java
@@ -88,6 +88,7 @@ import java.io.FileOutputStream;
import java.io.IOException;
import java.io.OutputStreamWriter;
import java.lang.reflect.Field;
+import java.lang.reflect.Method;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
@@ -903,11 +904,28 @@ public class ExtractStyle {
}
return json;
}
+
+ private ContextThemeWrapper getContextThemeWrapper()
+ {
+ if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M)
+ return new ContextThemeWrapper(m_context, m_theme);
+
+ int themeResId = 0;
+ try {
+ Class<?> clazz = ContextThemeWrapper.class;
+ Method method = clazz.getMethod("getThemeResId");
+ method.setAccessible(true);
+ themeResId = (Integer)method.invoke(m_context);
+ } catch (Exception e) {
+ Log.e(QtNative.QtTAG, "Failed to get theme resource ID", e);
+ }
+ return new ContextThemeWrapper(m_context, themeResId);
+ }
private TypedArray obtainStyledAttributes(int styleName, int[] attributes)
{
TypedValue typedValue = new TypedValue();
- Context ctx = new ContextThemeWrapper(m_context, m_theme);
+ Context ctx = getContextThemeWrapper();
ctx.getTheme().resolveAttribute(styleName, typedValue, true);
return ctx.obtainStyledAttributes(typedValue.data, attributes);
}
@@ -926,7 +944,7 @@ public class ExtractStyle {
public void extractViewInformation(int styleName, JSONObject json, String qtClassName, AttributeSet attributeSet) {
try {
TypedValue typedValue = new TypedValue();
- Context ctx = new ContextThemeWrapper(m_context, m_theme);
+ Context ctx = getContextThemeWrapper();
ctx.getTheme().resolveAttribute(styleName, typedValue, true);
int[] attributes = new int[]{
@@ -1120,7 +1138,7 @@ public class ExtractStyle {
try {
TypedValue typedValue = new TypedValue();
- Context ctx = new ContextThemeWrapper(m_context, m_theme);
+ Context ctx = getContextThemeWrapper();
ctx.getTheme().resolveAttribute(styleName, typedValue, true);
// Get textAppearance values
@@ -1391,7 +1409,7 @@ public class ExtractStyle {
JSONObject json = extractTextAppearanceInformation(styleName, qtClass);
TypedValue typedValue = new TypedValue();
- Context ctx = new ContextThemeWrapper(m_context, m_theme);
+ Context ctx = getContextThemeWrapper();
ctx.getTheme().resolveAttribute(styleName, typedValue, true);
final int[] attributes = new int[]{android.R.attr.button};
TypedArray array = ctx.obtainStyledAttributes(typedValue.data, attributes);