diff options
author | Assam Boudjelthia <assam.boudjelthia@qt.io> | 2021-08-23 11:11:22 +0300 |
---|---|---|
committer | Qt Cherry-pick Bot <cherrypick_bot@qt-project.org> | 2021-08-23 12:40:00 +0000 |
commit | 538c7855e7d369a3d5aab9eb9815172847dd4e84 (patch) | |
tree | 680ae161f1e30bc2b5fc29b2aa382234dbf35b08 /src/android/jar/src | |
parent | 09cae81bf7e0bcd8c1cfbeb38d0db7b363f2f165 (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/jar/src')
-rw-r--r-- | src/android/jar/src/org/qtproject/qt/android/ExtractStyle.java | 8 |
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 5d2d56010a..f60748dad6 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); |