examples: annotate examples
[nit.git] / lib / android / examples / src / ui_test.nit
index bdb06c5..c6316ad 100644 (file)
 
 # Test for app.nit's UI services
 module ui_test is
+       example
        app_name "app.nit UI test"
        app_version(0, 1, git_revision)
        app_namespace "org.nitlanguage.ui_test"
        android_manifest_activity """android:theme="@android:style/Theme.Light""""
+       android_api_target 15
 end
 
-import android
 import android::ui
 import android::toast
 import android::notification
 
 redef class App
-
-       var but_notif: Button
-       var but_toast: Button
-
-       var notif: nullable Notification = null
-
-       var inited = false
-       redef fun init_window
+       redef fun on_create
        do
+               self.window = new Window
                super
+       end
+end
 
-               if inited then return
-               inited = true
+redef class Window
 
-               # Setup UI
-               var context = native_activity
-               var layout = new NativeLinearLayout(context)
-               layout.set_vertical
+       private var layout = new VerticalLayout(parent=self)
 
-               but_notif = new Button
-               but_notif.text = "Show Notification"
-               layout.add_view but_notif.native
+       private var but_notif = new Button(parent=layout, text="Show Notification")
+       private var but_toast = new Button(parent=layout, text="Show Toast")
 
-               but_toast = new Button
-               but_toast.text = "Show Toast"
-               layout.add_view but_toast.native
+       private var notif: nullable Notification = null
 
-               context.content_view = layout
+       init
+       do
+               but_notif.observers.add self
+               but_toast.observers.add self
        end
 
+       # Action when pressing `but_notif`
        fun act_notif
        do
                var notif = self.notif
@@ -72,14 +66,16 @@ redef class App
                end
        end
 
+       # Action when pressing `but_toast`
        fun act_toast
        do
-               toast("Sample toast from app.nit at {get_time}", false)
+               app.toast("Sample toast from app.nit at {get_time}", false)
        end
 
-       redef fun catch_event(event)
+       redef fun on_event(event)
        do
-               if event isa ClickEvent then
+               print "on_event {event}"
+               if event isa ButtonPressEvent then
                        var sender = event.sender
                        if sender == but_notif then
                                act_notif