lib/android: extract activities from native_app_glue
authorAlexis Laferrière <alexis.laf@xymus.net>
Mon, 26 Jan 2015 11:55:28 +0000 (06:55 -0500)
committerAlexis Laferrière <alexis.laf@xymus.net>
Fri, 30 Jan 2015 13:44:41 +0000 (08:44 -0500)
Signed-off-by: Alexis Laferrière <alexis.laf@xymus.net>

lib/android/activities.nit [new file with mode: 0644]
lib/android/native_app_glue.nit

diff --git a/lib/android/activities.nit b/lib/android/activities.nit
new file mode 100644 (file)
index 0000000..e3e0e65
--- /dev/null
@@ -0,0 +1,40 @@
+# This file is part of NIT (http://www.nitlanguage.org).
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+#     http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
+# Android Activities wrapper
+module activities
+
+import platform
+
+# An Android activity context
+extern class NativeContext in "Java" `{ android.content.Context `}
+       super JavaObject
+end
+
+# A wrapper of context
+extern class NativeContextWrapper in "Java" `{ android.content.ContextWrapper `}
+       super NativeContext
+end
+
+# An activity, a single, focused thing a user can do on Android
+extern class NativeActivity in "Java" `{ android.app.Activity `}
+       super NativeContextWrapper
+
+       # HACK for bug #845
+       redef fun new_global_ref: SELF import sys, Sys.jni_env `{
+               Sys sys = NativeActivity_sys(recv);
+               JNIEnv *env = Sys_jni_env(sys);
+               return (*env)->NewGlobalRef(env, recv);
+       `}
+end
index 4ae4753..9017a29 100644 (file)
@@ -32,7 +32,7 @@
 #   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.
@@ -40,6 +40,7 @@ module native_app_glue is ldflags "-landroid"
 
 import platform
 import log
+import activities
 
 in "C header" `{
        #include <android_native_app_glue.h>
@@ -114,22 +115,12 @@ in "C body" `{
        }
 `}
 
-# An Android activity context
-extern class NativeContext in "Java" `{ android.content.Context `}
-       super JavaObject
-end
-
-# A wrapper of context
-extern class NativeContextWrapper in "Java" `{ android.content.ContextWrapper `}
-       super NativeContext
-end
-
 # Android SDK's `android.app.NativeActivity`.
 #
 # 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 NativeContextWrapper
+extern class NativeNativeActivity in "Java" `{ android.app.NativeActivity `}
+       super NativeActivity
 end
 
 redef class App