Merge: Annotation lateinit
[nit.git] / examples / mnit_simple / src / simple_android.nit
index 5ac07b2..a451597 100644 (file)
 # See the License for the specific language governing permissions and
 # limitations under the License.
 
-module simple_android
+module simple_android is
+       android_manifest("""<uses-permission android:name="android.permission.VIBRATE" />""")
+end
 
-import simple
 import mnit_android
+import android::portrait
+import serialization
+
+import simple
+
+in "Java" `{
+       import android.content.Context;
+       import android.widget.Toast;
+`}
+
+redef class App
+       redef fun input( ie )
+       do
+               if ie isa PointerEvent and ie.depressed then 
+                       test_java_ffi
+               end
+               return super
+       end
+
+       fun test_java_ffi import native_activity in "Java" `{
+               // + Log (no context needed)
+               android.util.Log.d("mnit_simple", "Java within NIT!!!");
+
+               // - Context needed from now on
+               final android.app.Activity context = App_native_activity(self);
+
+               // Vibration
+               android.os.Vibrator v = (android.os.Vibrator)
+                       context.getSystemService(android.content.Context.VIBRATOR_SERVICE);
+               v.vibrate(500);
+
+               // - 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
+
+class Point
+       auto_serializable
+
+       var x: Int
+       var y: Int
+
+       init(x, y: Int)
+       do
+               self.x = x
+               self.y = y
+       end
 
-super
+       redef fun to_s do return "({x}, {y})"
+end