examples/mnit_simple: test Android log and toasts
authorAlexis Laferrière <alexis.laf@xymus.net>
Sat, 15 Mar 2014 12:26:24 +0000 (08:26 -0400)
committerAlexis Laferrière <alexis.laf@xymus.net>
Fri, 25 Apr 2014 19:18:56 +0000 (15:18 -0400)
Signed-off-by: Alexis Laferrière <alexis.laf@xymus.net>

examples/mnit_simple/src/simple_android.nit

index 5ac07b2..ef10e0a 100644 (file)
@@ -19,4 +19,37 @@ module simple_android
 import simple
 import mnit_android
 
-super
+in "Java" `{
+       import android.content.Context;
+       import android.widget.Toast;
+`}
+
+redef class MyApp
+       redef fun input( ie )
+       do
+               if ie isa PointerEvent and ie.depressed then do_java_stuff
+
+               return super
+       end
+
+       fun do_java_stuff import native_activity in "Java" `{
+               // + Log (no context needed)
+               android.util.Log.d("mnit_simple", "Java within NIT!!!");
+
+               // - Context needed from now on
+               // NativeActivity is a Java sub-class of Context
+               final android.app.NativeActivity context = MyApp_native_activity(recv);
+
+               // - UI thread needed from now on
+               context.runOnUiThread(new Runnable() {
+                       @Override
+                       public void run()  {
+                               // + Toast
+                               CharSequence text = "Java within Nit!";
+                               int duration = Toast.LENGTH_SHORT;
+                               Toast toast = Toast.makeText(context, text, duration);
+                               toast.show();
+                       }
+               });
+       `}
+end