Android.h 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133
  1. /******************************************************************************/
  2. #if EE_PRIVATE
  3. #if ANDROID
  4. /******************************************************************************/
  5. enum KEY_SOURCE
  6. {
  7. KEY_ANY ,
  8. KEY_CPP ,
  9. KEY_JAVA,
  10. };
  11. /******************************************************************************/
  12. struct JNI
  13. {
  14. operator JNIEnv*()C {return _;}
  15. JNIEnv* operator-> ()C {return _;}
  16. Str operator() (jstring str)C;
  17. void clear ();
  18. void del ();
  19. void attach();
  20. explicit JNI(JNIEnv *jni) {clear(); _=jni;}
  21. JNI( ) {clear(); attach();}
  22. ~JNI( ) {del();}
  23. private:
  24. JNIEnv *_;
  25. Bool attached;
  26. NO_COPY_CONSTRUCTOR(JNI);
  27. }extern
  28. Jni;
  29. struct JObject
  30. {
  31. operator Bool ()C {return _!=null;}
  32. operator jobject ()C {return _;}
  33. jobject operator()()C {return _;}
  34. JObject& clear (); // clear without deleting
  35. JObject& del ();
  36. JObject& makeGlobal();
  37. JObject& operator= (jobject j);
  38. ~JObject() {del();}
  39. JObject( jobject j=null) : _jni(Jni), _(j), _global(false) {}
  40. explicit JObject(JNI &jni, jobject j=null) : _jni(jni), _(j), _global(false) {}
  41. JObject(JObject &&temp) : _jni(temp._jni), _(temp._), _global(temp._global) {temp.clear();}
  42. protected:
  43. jobject _;
  44. JNI &_jni;
  45. Bool _global;
  46. NO_COPY_CONSTRUCTOR(JObject);
  47. };
  48. struct JClass : JObject
  49. {
  50. operator jclass()C {return (jclass)T();}
  51. JClass& operator=(CChar8 *name);
  52. JClass& operator=(jobject obj );
  53. JClass& operator=(jclass cls );
  54. JClass( CChar8 *name=null);
  55. JClass( jobject obj );
  56. JClass( jclass cls );
  57. explicit JClass(JNI &jni, CChar8 *name=null);
  58. explicit JClass(JNI &jni, jobject obj );
  59. explicit JClass(JNI &jni, jclass cls );
  60. JClass(JClass &&temp) : JObject(temp._jni, temp._) {_global=temp._global; temp.clear();}
  61. };
  62. struct JString : JObject
  63. {
  64. operator jstring()C {return (jstring)T();}
  65. Str str()C {return _jni(T);}
  66. JString& operator=(jobject j) {JObject::operator=(j); return T;}
  67. JString& operator=(CChar8 *t);
  68. JString& operator=(CChar *t);
  69. JString& operator=(C Str8 &s);
  70. JString& operator=(C Str &s);
  71. JString( jobject j=null) : JObject( j ) {}
  72. JString( CChar8 *t ) : JObject( null) {T=t;}
  73. JString( CChar *t ) : JObject( null) {T=t;}
  74. JString( C Str8 &s ) : JObject( null) {T=s;}
  75. JString( C Str &s ) : JObject( null) {T=s;}
  76. explicit JString(JNI &jni, jobject j=null) : JObject(jni, j ) {}
  77. explicit JString(JNI &jni, CChar8 *t ) : JObject(jni, null) {T=t;}
  78. explicit JString(JNI &jni, CChar *t ) : JObject(jni, null) {T=t;}
  79. explicit JString(JNI &jni, C Str8 &s ) : JObject(jni, null) {T=s;}
  80. explicit JString(JNI &jni, C Str &s ) : JObject(jni, null) {T=s;}
  81. JString(JString &&temp) : JObject(temp._jni, temp._) {_global=temp._global; temp.clear();}
  82. };
  83. struct JObjectArray : JObject
  84. {
  85. operator jobjectArray()C {return (jobjectArray)T();}
  86. Int elms ( )C;
  87. jobject operator[](Int i)C;
  88. JObjectArray& operator=(jobject j) {JObject::operator=(j); return T;}
  89. void set(Int i, CChar8 *t); // set i-th array element as 't' text
  90. JObjectArray( jobject j=null) : JObject( j) {}
  91. explicit JObjectArray(JNI &jni, jobject j=null) : JObject(jni, j) {}
  92. explicit JObjectArray(JNI &jni, int elms );
  93. JObjectArray(JObjectArray &&temp) : JObject(temp._jni, temp._) {_global=temp._global; temp.clear();}
  94. };
  95. typedef jmethodID JMethodID;
  96. typedef jfieldID JFieldID;
  97. /******************************************************************************/
  98. extern jobject Activity; // 'Activity' should not use 'JObject' because it's not dynamically obtained
  99. extern JClass ActivityClass, ClipboardManagerClass;
  100. extern JObject ClipboardManager, LocationManager, GPS_PROVIDER, NETWORK_PROVIDER, EsenthelLocationListener[2];
  101. extern JMethodID getLastKnownLocation, getLatitude, getLongitude, getAltitude, getAccuracy, getSpeed, getTime, requestLocationUpdates, removeUpdates;
  102. extern android_app *AndroidApp;
  103. extern Str8 AndroidPackageName;
  104. extern Str AndroidAppPath, AndroidAppDataPath, AndroidAppDataPublicPath, AndroidPublicPath, AndroidSDCardPath;
  105. extern Byte KeySource;
  106. extern Int AndroidSDK;
  107. extern AAssetManager *AssetManager;
  108. /******************************************************************************/
  109. #endif
  110. #endif
  111. /******************************************************************************/