android-project/app/src/main/java/org/libsdl/app/SDLActivity.java
changeset 12388 69af2eac84e9
parent 12348 09d04d83c3c1
child 12491 3b1f484500f0
equal deleted inserted replaced
12387:2f02c753a5dc 12388:69af2eac84e9
    84     protected static SDLSurface mSurface;
    84     protected static SDLSurface mSurface;
    85     protected static View mTextEdit;
    85     protected static View mTextEdit;
    86     protected static boolean mScreenKeyboardShown;
    86     protected static boolean mScreenKeyboardShown;
    87     protected static ViewGroup mLayout;
    87     protected static ViewGroup mLayout;
    88     protected static SDLClipboardHandler mClipboardHandler;
    88     protected static SDLClipboardHandler mClipboardHandler;
    89     protected static Hashtable<Integer, Object> mCursors;
    89     protected static Hashtable<Integer, PointerIcon> mCursors;
    90     protected static int mLastCursorID;
    90     protected static int mLastCursorID;
    91     protected static SDLGenericMotionListener_API12 mMotionListener;
    91     protected static SDLGenericMotionListener_API12 mMotionListener;
    92     protected static HIDDeviceManager mHIDDeviceManager;
    92     protected static HIDDeviceManager mHIDDeviceManager;
    93 
    93 
    94     // This is what SDL runs in. It invokes SDL_main(), eventually
    94     // This is what SDL runs in. It invokes SDL_main(), eventually
   174         mSingleton = null;
   174         mSingleton = null;
   175         mSurface = null;
   175         mSurface = null;
   176         mTextEdit = null;
   176         mTextEdit = null;
   177         mLayout = null;
   177         mLayout = null;
   178         mClipboardHandler = null;
   178         mClipboardHandler = null;
   179         mCursors = new Hashtable<Integer, Object>();
   179         mCursors = new Hashtable<Integer, PointerIcon>();
   180         mLastCursorID = 0;
   180         mLastCursorID = 0;
   181         mSDLThread = null;
   181         mSDLThread = null;
   182         mExitCalledFromJava = false;
   182         mExitCalledFromJava = false;
   183         mBrokenLibraries = false;
   183         mBrokenLibraries = false;
   184         mIsResumedCalled = false;
   184         mIsResumedCalled = false;
  1377      * This method is called by SDL using JNI.
  1377      * This method is called by SDL using JNI.
  1378      */
  1378      */
  1379     public static int createCustomCursor(int[] colors, int width, int height, int hotSpotX, int hotSpotY) {
  1379     public static int createCustomCursor(int[] colors, int width, int height, int hotSpotX, int hotSpotY) {
  1380         Bitmap bitmap = Bitmap.createBitmap(colors, width, height, Bitmap.Config.ARGB_8888);
  1380         Bitmap bitmap = Bitmap.createBitmap(colors, width, height, Bitmap.Config.ARGB_8888);
  1381         ++mLastCursorID;
  1381         ++mLastCursorID;
  1382         // This requires API 24, so use reflection to implement this
  1382 
  1383         try {
  1383         if (Build.VERSION.SDK_INT >= 24) {
  1384             Class PointerIconClass = Class.forName("android.view.PointerIcon");
  1384             try {
  1385             Class[] arg_types = new Class[] { Bitmap.class, float.class, float.class };
  1385                 mCursors.put(mLastCursorID, PointerIcon.create(bitmap, hotSpotX, hotSpotY));
  1386             Method create = PointerIconClass.getMethod("create", arg_types);
  1386             } catch (Exception e) {
  1387             mCursors.put(mLastCursorID, create.invoke(null, bitmap, hotSpotX, hotSpotY));
  1387                 return 0;
  1388         } catch (Exception e) {
  1388             }
       
  1389         } else {
  1389             return 0;
  1390             return 0;
  1390         }
  1391         }
  1391         return mLastCursorID;
  1392         return mLastCursorID;
  1392     }
  1393     }
  1393 
  1394 
  1394     /**
  1395     /**
  1395      * This method is called by SDL using JNI.
  1396      * This method is called by SDL using JNI.
  1396      */
  1397      */
  1397     public static boolean setCustomCursor(int cursorID) {
  1398     public static boolean setCustomCursor(int cursorID) {
  1398         // This requires API 24, so use reflection to implement this
  1399 
  1399         try {
  1400         if (Build.VERSION.SDK_INT >= 24) {
  1400             Class PointerIconClass = Class.forName("android.view.PointerIcon");
  1401             try {
  1401             Method setPointerIcon = SDLSurface.class.getMethod("setPointerIcon", PointerIconClass);
  1402                 mSurface.setPointerIcon(mCursors.get(cursorID));
  1402             setPointerIcon.invoke(mSurface, mCursors.get(cursorID));
  1403             } catch (Exception e) {
  1403         } catch (Exception e) {
  1404                 return false;
       
  1405             }
       
  1406         } else {
  1404             return false;
  1407             return false;
  1405         }
  1408         }
  1406         return true;
  1409         return true;
  1407     }
  1410     }
  1408 
  1411 
  1447             break;
  1450             break;
  1448         case SDL_SYSTEM_CURSOR_HAND:
  1451         case SDL_SYSTEM_CURSOR_HAND:
  1449             cursor_type = 1002; //PointerIcon.TYPE_HAND;
  1452             cursor_type = 1002; //PointerIcon.TYPE_HAND;
  1450             break;
  1453             break;
  1451         }
  1454         }
  1452         // This requires API 24, so use reflection to implement this
  1455         if (Build.VERSION.SDK_INT >= 24) {
  1453         try {
  1456             try {
  1454             Class PointerIconClass = Class.forName("android.view.PointerIcon");
  1457                 mSurface.setPointerIcon(PointerIcon.getSystemIcon(SDL.getContext(), cursor_type));
  1455             Class[] arg_types = new Class[] { Context.class, int.class };
  1458             } catch (Exception e) {
  1456             Method getSystemIcon = PointerIconClass.getMethod("getSystemIcon", arg_types);
  1459                 return false;
  1457             Method setPointerIcon = SDLSurface.class.getMethod("setPointerIcon", PointerIconClass);
  1460             }
  1458             setPointerIcon.invoke(mSurface, getSystemIcon.invoke(null, SDL.getContext(), cursor_type));
       
  1459         } catch (Exception e) {
       
  1460             return false;
       
  1461         }
  1461         }
  1462         return true;
  1462         return true;
  1463     }
  1463     }
  1464 }
  1464 }
  1465 
  1465