X-Git-Url: http://nitlanguage.org diff --git a/lib/android/native_app_glue.nit b/lib/android/native_app_glue.nit index 9e9aabf..826eef2 100644 --- a/lib/android/native_app_glue.nit +++ b/lib/android/native_app_glue.nit @@ -32,14 +32,18 @@ # is on the same thread as Nit and manages the synchronization with the # main Android thread. # -# * `NativeActivity` is implemented in Java by `android.app.NativeActivity`, +# * `NativeNativeActivity` is implemented in Java by `android.app.NativeActivity`, # which is a subclass of `Activity` and `Context` (in Java). It represent # main activity of the running application. Use it to get anything related # to the `Context` and as anchor to execute Java UI code. -module native_app_glue +module native_app_glue is + ldflags "-landroid" + android_activity "android.app.NativeActivity" +end import platform import log +import dalvik in "C header" `{ #include @@ -118,12 +122,16 @@ in "C body" `{ # # Can be used to get anything related to the `Context` of the activity in Java # and as anchor to execute Java UI code. -extern class NativeActivity in "Java" `{ android.app.NativeActivity `} - super JavaObject +extern class NativeNativeActivity in "Java" `{ android.app.NativeActivity `} + super NativeActivity +end + +redef class Sys + redef fun jvm do return app.native_app_glue.ndk_native_activity.vm end redef class App - redef init + redef fun setup do var native_app_glue = native_app_glue native_app_glue.user_data = self @@ -134,8 +142,7 @@ redef class App # The underlying implementation using the Android native_app_glue framework fun native_app_glue: NativeAppGlue `{ return native_app_glue_data; `} - # The main Java Activity of this application - fun native_activity: NativeActivity do return native_app_glue.ndk_native_activity.java_native_activity + redef fun native_activity do return native_app_glue.ndk_native_activity.java_native_activity # Set `native_app_glue` command handler to our C implementation which # will callback self. @@ -147,7 +154,7 @@ redef class App `} # Notification from the Android framework to generate a new saved state - # + # # You can use the `shared_preferences` module or `NativeAppGlue::saved_state`. fun save_state do end @@ -174,7 +181,7 @@ redef class App fun stop do end # Notification from the Android framework, `native_activity` is being destroyed - # + # # Clean up and exit. fun destroy do end @@ -196,7 +203,7 @@ redef class App fun input_changed do end # Notification from the Android framework, the window has been resized. - # + # # Please redraw with its new size. fun window_resized do end @@ -204,7 +211,7 @@ redef class App fun window_redraw_needed do end # Notification from the Android framework, the content area of the window has changed - # + # # Raised when the soft input window being shown or hidden, and similar events. fun content_rect_changed do end @@ -226,7 +233,7 @@ redef class App struct android_app *app_glue = App_native_app_glue(recv); struct android_poll_source* source = (struct android_poll_source*)data; - + // Process this event. if (source != NULL) source->process(app_glue, source); `} @@ -252,15 +259,15 @@ extern class NdkNativeActivity `{ ANativeActivity * `} # The `NativeActivity`, as in the Java object, associated to `self` fun java_native_activity: NativeActivity `{ return recv->clazz; `} - # Path to this application's internal data directory. + # Path to this application's internal data directory. fun internal_data_path: NativeString `{ return (char*)recv->internalDataPath; `} - + # Path to this application's external (removable/mountable) data directory. - fun external_data_path: NativeString `{ return (char*)recv->externalDataPath; `} - + fun external_data_path: NativeString `{ return (char*)recv->externalDataPath; `} + # The platform's SDK version code. fun sdk_version: Int `{ return recv->sdkVersion; `} - + # This is the native instance of the application. It is not used by # the framework, but can be set by the application to its own instance # state. @@ -291,7 +298,10 @@ extern class NativeAppGlue `{ struct android_app* `} # We use the `userData` field of the C structure to store an handle to # the associated App private fun user_data: App `{ return recv->userData; `} - private fun user_data=(val: App) `{ recv->userData = val; `} + private fun user_data=(val: App) `{ + App_incr_ref(val); + recv->userData = val; + `} # Fill this in with the function to process input events. At this point # the event has already been pre-dispatched, and it will be finished upon