lib/android: update `ui_test` to the new Android UI
authorAlexis Laferrière <alexis.laf@xymus.net>
Tue, 12 May 2015 20:31:36 +0000 (16:31 -0400)
committerAlexis Laferrière <alexis.laf@xymus.net>
Tue, 19 May 2015 20:12:03 +0000 (16:12 -0400)
Signed-off-by: Alexis Laferrière <alexis.laf@xymus.net>

lib/android/examples/Makefile
lib/android/examples/src/ui_test.nit

index f0fd982..17fb8bf 100644 (file)
@@ -2,10 +2,9 @@ android:
        mkdir -p bin/ res/
        ../../../contrib/inkscape_tools/bin/svg_to_icons art/icon.svg --android --out res/
        ../../../bin/nitc --dir bin/ src/ui_test.nit
-       adb install -r bin/ui_test.apk
 
 install: android
-       adb install -r bin/ui.apk
+       adb install -r bin/ui_test.apk
 
 clean:
        rm -rf bin
index bdb06c5..4f63a92 100644 (file)
@@ -20,44 +20,37 @@ module ui_test is
        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 +65,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