Fixed bug 4319 - Android remove reflection for PointerIcon
Sylvain Since SDL2 min requirement is Android SDK 26, and PointerIcon is 24. We don't need reflection to access it.
parent
47fb450beb
commit
67a94893c0
|
@ -86,7 +86,7 @@ public class SDLActivity extends Activity implements View.OnSystemUiVisibilityCh
|
||||||
protected static boolean mScreenKeyboardShown;
|
protected static boolean mScreenKeyboardShown;
|
||||||
protected static ViewGroup mLayout;
|
protected static ViewGroup mLayout;
|
||||||
protected static SDLClipboardHandler mClipboardHandler;
|
protected static SDLClipboardHandler mClipboardHandler;
|
||||||
protected static Hashtable<Integer, Object> mCursors;
|
protected static Hashtable<Integer, PointerIcon> mCursors;
|
||||||
protected static int mLastCursorID;
|
protected static int mLastCursorID;
|
||||||
protected static SDLGenericMotionListener_API12 mMotionListener;
|
protected static SDLGenericMotionListener_API12 mMotionListener;
|
||||||
protected static HIDDeviceManager mHIDDeviceManager;
|
protected static HIDDeviceManager mHIDDeviceManager;
|
||||||
|
@ -176,7 +176,7 @@ public class SDLActivity extends Activity implements View.OnSystemUiVisibilityCh
|
||||||
mTextEdit = null;
|
mTextEdit = null;
|
||||||
mLayout = null;
|
mLayout = null;
|
||||||
mClipboardHandler = null;
|
mClipboardHandler = null;
|
||||||
mCursors = new Hashtable<Integer, Object>();
|
mCursors = new Hashtable<Integer, PointerIcon>();
|
||||||
mLastCursorID = 0;
|
mLastCursorID = 0;
|
||||||
mSDLThread = null;
|
mSDLThread = null;
|
||||||
mExitCalledFromJava = false;
|
mExitCalledFromJava = false;
|
||||||
|
@ -1379,13 +1379,14 @@ public class SDLActivity extends Activity implements View.OnSystemUiVisibilityCh
|
||||||
public static int createCustomCursor(int[] colors, int width, int height, int hotSpotX, int hotSpotY) {
|
public static int createCustomCursor(int[] colors, int width, int height, int hotSpotX, int hotSpotY) {
|
||||||
Bitmap bitmap = Bitmap.createBitmap(colors, width, height, Bitmap.Config.ARGB_8888);
|
Bitmap bitmap = Bitmap.createBitmap(colors, width, height, Bitmap.Config.ARGB_8888);
|
||||||
++mLastCursorID;
|
++mLastCursorID;
|
||||||
// This requires API 24, so use reflection to implement this
|
|
||||||
try {
|
if (Build.VERSION.SDK_INT >= 24) {
|
||||||
Class PointerIconClass = Class.forName("android.view.PointerIcon");
|
try {
|
||||||
Class[] arg_types = new Class[] { Bitmap.class, float.class, float.class };
|
mCursors.put(mLastCursorID, PointerIcon.create(bitmap, hotSpotX, hotSpotY));
|
||||||
Method create = PointerIconClass.getMethod("create", arg_types);
|
} catch (Exception e) {
|
||||||
mCursors.put(mLastCursorID, create.invoke(null, bitmap, hotSpotX, hotSpotY));
|
return 0;
|
||||||
} catch (Exception e) {
|
}
|
||||||
|
} else {
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
return mLastCursorID;
|
return mLastCursorID;
|
||||||
|
@ -1395,12 +1396,14 @@ public class SDLActivity extends Activity implements View.OnSystemUiVisibilityCh
|
||||||
* This method is called by SDL using JNI.
|
* This method is called by SDL using JNI.
|
||||||
*/
|
*/
|
||||||
public static boolean setCustomCursor(int cursorID) {
|
public static boolean setCustomCursor(int cursorID) {
|
||||||
// This requires API 24, so use reflection to implement this
|
|
||||||
try {
|
if (Build.VERSION.SDK_INT >= 24) {
|
||||||
Class PointerIconClass = Class.forName("android.view.PointerIcon");
|
try {
|
||||||
Method setPointerIcon = SDLSurface.class.getMethod("setPointerIcon", PointerIconClass);
|
mSurface.setPointerIcon(mCursors.get(cursorID));
|
||||||
setPointerIcon.invoke(mSurface, mCursors.get(cursorID));
|
} catch (Exception e) {
|
||||||
} catch (Exception e) {
|
return false;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
|
@ -1449,15 +1452,12 @@ public class SDLActivity extends Activity implements View.OnSystemUiVisibilityCh
|
||||||
cursor_type = 1002; //PointerIcon.TYPE_HAND;
|
cursor_type = 1002; //PointerIcon.TYPE_HAND;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
// This requires API 24, so use reflection to implement this
|
if (Build.VERSION.SDK_INT >= 24) {
|
||||||
try {
|
try {
|
||||||
Class PointerIconClass = Class.forName("android.view.PointerIcon");
|
mSurface.setPointerIcon(PointerIcon.getSystemIcon(SDL.getContext(), cursor_type));
|
||||||
Class[] arg_types = new Class[] { Context.class, int.class };
|
} catch (Exception e) {
|
||||||
Method getSystemIcon = PointerIconClass.getMethod("getSystemIcon", arg_types);
|
return false;
|
||||||
Method setPointerIcon = SDLSurface.class.getMethod("setPointerIcon", PointerIconClass);
|
}
|
||||||
setPointerIcon.invoke(mSurface, getSystemIcon.invoke(null, SDL.getContext(), cursor_type));
|
|
||||||
} catch (Exception e) {
|
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue