summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAssam Boudjelthia <assam.boudjelthia@qt.io>2021-08-23 11:11:22 +0300
committerJani Heikkinen <jani.heikkinen@qt.io>2021-08-26 07:49:40 +0300
commitb496064efab47743fff4eb22f68e3acb3315fd9d (patch)
tree32b5436125bbaaf3c98a0f139be6fde5ec8a3b3e
parentf90c1a2b54b72a9455cf952ceb0250ffc7e0d648 (diff)
Android: guard getStateCount() with correct VERSION.SDK_INTv6.1.36.1.3
The call getStateCount() was introduced in 29, so cases for lower API should be handled. (Cherry picked from commit 538c7855e7d369a3d5aab9eb9815172847dd4e84) Conflicts: src/android/jar/src/org/qtproject/qt/android/ExtractStyle.java Change-Id: Ic1b9d018e1a0ec6a72a394bd14d3566b7fdb5258 Reviewed-by: Assam Boudjelthia <assam.boudjelthia@qt.io>
-rw-r--r--src/android/jar/src/org/qtproject/qt/android/ExtractStyle.java11
1 files changed, 7 insertions, 4 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 230895f0ba..9c569a5569 100644
--- a/src/android/jar/src/org/qtproject/qt/android/ExtractStyle.java
+++ b/src/android/jar/src/org/qtproject/qt/android/ExtractStyle.java
@@ -508,10 +508,13 @@ public class ExtractStyle {
JSONObject json = new JSONObject();
try {
StateListDrawable stateList = (StateListDrawable) drawable;
- final int numStates = (Integer) StateListDrawable.class.getMethod("getStateCount").invoke(stateList);
- JSONArray array =new JSONArray();
- for (int i = 0; i < numStates; i++)
- {
+ JSONArray array = new JSONArray();
+ final int numStates;
+ if (Build.VERSION.SDK_INT < Build.VERSION_CODES.Q)
+ numStates = (Integer) StateListDrawable.class.getMethod("getStateCount").invoke(stateList);
+ else
+ numStates = stateList.getStateCount();
+ for (int i = 0; i < numStates; i++) {
JSONObject stateJson = new JSONObject();
final Drawable d = (Drawable) StateListDrawable.class.getMethod("getStateDrawable", Integer.TYPE).invoke(stateList, i);
final int [] states = (int[]) StateListDrawable.class.getMethod("getStateSet", Integer.TYPE).invoke(stateList, i);