Skip to content

Commit

Permalink
Android: guard getStateCount() with correct VERSION.SDK_INT
Browse files Browse the repository at this point in the history
The call getStateCount() was introduced in 29, so cases for
lower API should be handled.

(Cherry picked from commit 538c785)

 Conflicts:
	src/android/jar/src/org/qtproject/qt/android/ExtractStyle.java

Change-Id: Ic1b9d018e1a0ec6a72a394bd14d3566b7fdb5258
Reviewed-by: Assam Boudjelthia <[email protected]>
  • Loading branch information
Issam-b authored and jaheikk committed Aug 26, 2021
1 parent f90c1a2 commit b496064
Showing 1 changed file with 7 additions and 4 deletions.
11 changes: 7 additions & 4 deletions src/android/jar/src/org/qtproject/qt/android/ExtractStyle.java
Original file line number Diff line number Diff line change
Expand Up @@ -508,10 +508,13 @@ private JSONObject getStateListDrawable(Object drawable, String filename)
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);
Expand Down

0 comments on commit b496064

Please sign in to comment.