summaryrefslogtreecommitdiffstats
path: root/src/android
diff options
context:
space:
mode:
authorAssam Boudjelthia <assam.boudjelthia@qt.io>2021-08-23 11:11:22 +0300
committerQt Cherry-pick Bot <cherrypick_bot@qt-project.org>2021-08-23 14:46:22 +0000
commit959adf0f386f4cd41abd55416093a0d7187ee380 (patch)
tree5918d91f97803ca693b36397a29c15ee296ff3c7 /src/android
parent783d0f3bc9f3ef4badde6a6c40efce3195ceaa2c (diff)
Android: guard getStateCount() with correct VERSION.SDK_INT
The call getStateCount() was introduced in 29, so cases for lower API should be handled. Change-Id: I7f58541c0b16fed91835e6f390afa89378a7af3e Reviewed-by: Ville Voutilainen <ville.voutilainen@qt.io> (cherry picked from commit 760e24e8676d52e2851ef8556770194a97eae831) Reviewed-by: Qt Cherry-pick Bot <cherrypick_bot@qt-project.org>
Diffstat (limited to 'src/android')
-rw-r--r--src/android/jar/src/org/qtproject/qt/android/ExtractStyle.java8
1 files changed, 7 insertions, 1 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 f5c2a6c6ac..8c391a7e7b 100644
--- a/src/android/jar/src/org/qtproject/qt/android/ExtractStyle.java
+++ b/src/android/jar/src/org/qtproject/qt/android/ExtractStyle.java
@@ -69,6 +69,7 @@ import android.graphics.drawable.RotateDrawable;
import android.graphics.drawable.ScaleDrawable;
import android.graphics.drawable.StateListDrawable;
import android.graphics.drawable.VectorDrawable;
+import android.os.Build;
import android.util.AttributeSet;
import android.util.Log;
import android.util.TypedValue;
@@ -413,7 +414,12 @@ public class ExtractStyle {
try {
StateListDrawable stateList = (StateListDrawable) drawable;
JSONArray array = new JSONArray();
- for (int i = 0; i < stateList.getStateCount(); i++) {
+ 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);