Skip to content

Commit

Permalink
Fixed bug 4319 - Android remove reflection for PointerIcon
Browse files Browse the repository at this point in the history
Sylvain

Since SDL2 min requirement is Android SDK 26, and PointerIcon is 24. We don't need reflection to access it.
  • Loading branch information
slouken committed Nov 3, 2018
1 parent 47fb450 commit 67a9489
Showing 1 changed file with 24 additions and 24 deletions.
48 changes: 24 additions & 24 deletions android-project/app/src/main/java/org/libsdl/app/SDLActivity.java
Expand Up @@ -86,7 +86,7 @@ public enum NativeState {
protected static boolean mScreenKeyboardShown;
protected static ViewGroup mLayout;
protected static SDLClipboardHandler mClipboardHandler;
protected static Hashtable<Integer, Object> mCursors;
protected static Hashtable<Integer, PointerIcon> mCursors;
protected static int mLastCursorID;
protected static SDLGenericMotionListener_API12 mMotionListener;
protected static HIDDeviceManager mHIDDeviceManager;
Expand Down Expand Up @@ -176,7 +176,7 @@ public static void initialize() {
mTextEdit = null;
mLayout = null;
mClipboardHandler = null;
mCursors = new Hashtable<Integer, Object>();
mCursors = new Hashtable<Integer, PointerIcon>();
mLastCursorID = 0;
mSDLThread = null;
mExitCalledFromJava = false;
Expand Down Expand Up @@ -1379,13 +1379,14 @@ public static void clipboardSetText(String string) {
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);
++mLastCursorID;
// This requires API 24, so use reflection to implement this
try {
Class PointerIconClass = Class.forName("android.view.PointerIcon");
Class[] arg_types = new Class[] { Bitmap.class, float.class, float.class };
Method create = PointerIconClass.getMethod("create", arg_types);
mCursors.put(mLastCursorID, create.invoke(null, bitmap, hotSpotX, hotSpotY));
} catch (Exception e) {

if (Build.VERSION.SDK_INT >= 24) {
try {
mCursors.put(mLastCursorID, PointerIcon.create(bitmap, hotSpotX, hotSpotY));
} catch (Exception e) {
return 0;
}
} else {
return 0;
}
return mLastCursorID;
Expand All @@ -1395,12 +1396,14 @@ public static int createCustomCursor(int[] colors, int width, int height, int ho
* This method is called by SDL using JNI.
*/
public static boolean setCustomCursor(int cursorID) {
// This requires API 24, so use reflection to implement this
try {
Class PointerIconClass = Class.forName("android.view.PointerIcon");
Method setPointerIcon = SDLSurface.class.getMethod("setPointerIcon", PointerIconClass);
setPointerIcon.invoke(mSurface, mCursors.get(cursorID));
} catch (Exception e) {

if (Build.VERSION.SDK_INT >= 24) {
try {
mSurface.setPointerIcon(mCursors.get(cursorID));
} catch (Exception e) {
return false;
}
} else {
return false;
}
return true;
Expand Down Expand Up @@ -1449,15 +1452,12 @@ public static boolean setSystemCursor(int cursorID) {
cursor_type = 1002; //PointerIcon.TYPE_HAND;
break;
}
// This requires API 24, so use reflection to implement this
try {
Class PointerIconClass = Class.forName("android.view.PointerIcon");
Class[] arg_types = new Class[] { Context.class, int.class };
Method getSystemIcon = PointerIconClass.getMethod("getSystemIcon", arg_types);
Method setPointerIcon = SDLSurface.class.getMethod("setPointerIcon", PointerIconClass);
setPointerIcon.invoke(mSurface, getSystemIcon.invoke(null, SDL.getContext(), cursor_type));
} catch (Exception e) {
return false;
if (Build.VERSION.SDK_INT >= 24) {
try {
mSurface.setPointerIcon(PointerIcon.getSystemIcon(SDL.getContext(), cursor_type));
} catch (Exception e) {
return false;
}
}
return true;
}
Expand Down

0 comments on commit 67a9489

Please sign in to comment.