nitlanguage
/
nit.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
examples: annotate examples
[nit.git]
/
lib
/
android
/
examples
/
src
/
ui_test.nit
diff --git
a/lib/android/examples/src/ui_test.nit
b/lib/android/examples/src/ui_test.nit
index
f6c2a1b
..
c6316ad
100644
(file)
--- a/
lib/android/examples/src/ui_test.nit
+++ b/
lib/android/examples/src/ui_test.nit
@@
-16,48
+16,42
@@
# Test for app.nit's UI services
module ui_test is
# Test for app.nit's UI services
module ui_test is
- app_name("app.nit UI test")
+ example
+ app_name "app.nit UI test"
app_version(0, 1, git_revision)
app_version(0, 1, git_revision)
- java_package("org.nitlanguage.ui_test")
+ app_namespace "org.nitlanguage.ui_test"
android_manifest_activity """android:theme="@android:style/Theme.Light""""
android_manifest_activity """android:theme="@android:style/Theme.Light""""
+ android_api_target 15
end
end
-import android
import android::ui
import android::toast
import android::notification
redef class App
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
do
+ self.window = new Window
super
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
end
+ # Action when pressing `but_notif`
fun act_notif
do
var notif = self.notif
fun act_notif
do
var notif = self.notif
@@
-72,14
+66,16
@@
redef class App
end
end
end
end
+ # Action when pressing `but_toast`
fun act_toast
do
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
end
- redef fun catch_event(event)
+ redef fun on_event(event)
do
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
var sender = event.sender
if sender == but_notif then
act_notif