examples: intro app.nit Android UI test
authorAlexis Laferrière <alexis.laf@xymus.net>
Mon, 4 Aug 2014 19:29:50 +0000 (15:29 -0400)
committerAlexis Laferrière <alexis.laf@xymus.net>
Wed, 26 Nov 2014 03:53:15 +0000 (22:53 -0500)
Signed-off-by: Alexis Laferrière <alexis.laf@xymus.net>

lib/android/examples/Makefile [new file with mode: 0644]
lib/android/examples/art/icon.svg [new file with mode: 0644]
lib/android/examples/src/ui_test.nit [new file with mode: 0644]

diff --git a/lib/android/examples/Makefile b/lib/android/examples/Makefile
new file mode 100644 (file)
index 0000000..5255657
--- /dev/null
@@ -0,0 +1,11 @@
+android:
+       mkdir -p bin/ res/
+       ../../../contrib/inkscape_tools/bin/svg_to_icons art/icon.svg --android --out res/
+       ../../../bin/nitg --dir bin/ src/ui_test.nit
+       adb install -r bin/ui_test.apk
+
+install: android
+       adb install -r bin/ui.apk
+
+clean:
+       rm -rf bin
diff --git a/lib/android/examples/art/icon.svg b/lib/android/examples/art/icon.svg
new file mode 100644 (file)
index 0000000..fb46e63
--- /dev/null
@@ -0,0 +1,101 @@
+<?xml version="1.0" encoding="UTF-8" standalone="no"?>
+<!-- Created with Inkscape (http://www.inkscape.org/) -->
+
+<svg
+   xmlns:dc="http://purl.org/dc/elements/1.1/"
+   xmlns:cc="http://creativecommons.org/ns#"
+   xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
+   xmlns:svg="http://www.w3.org/2000/svg"
+   xmlns="http://www.w3.org/2000/svg"
+   xmlns:sodipodi="http://sodipodi.sourceforge.net/DTD/sodipodi-0.dtd"
+   xmlns:inkscape="http://www.inkscape.org/namespaces/inkscape"
+   width="512"
+   height="512"
+   id="svg2"
+   version="1.1"
+   inkscape:version="0.48.5 r10040"
+   sodipodi:docname="icon.svg">
+  <defs
+     id="defs4" />
+  <sodipodi:namedview
+     id="base"
+     pagecolor="#000000"
+     bordercolor="#666666"
+     borderopacity="1.0"
+     inkscape:pageopacity="0"
+     inkscape:pageshadow="2"
+     inkscape:zoom="0.98994949"
+     inkscape:cx="309.32788"
+     inkscape:cy="302.66563"
+     inkscape:document-units="px"
+     inkscape:current-layer="layer1"
+     showgrid="false"
+     inkscape:window-width="1311"
+     inkscape:window-height="960"
+     inkscape:window-x="3037"
+     inkscape:window-y="440"
+     inkscape:window-maximized="0" />
+  <metadata
+     id="metadata7">
+    <rdf:RDF>
+      <cc:Work
+         rdf:about="">
+        <dc:format>image/svg+xml</dc:format>
+        <dc:type
+           rdf:resource="http://purl.org/dc/dcmitype/StillImage" />
+        <dc:title />
+      </cc:Work>
+    </rdf:RDF>
+  </metadata>
+  <g
+     inkscape:label="Layer 1"
+     inkscape:groupmode="layer"
+     id="layer1"
+     transform="translate(0,-540.36218)">
+    <path
+       style="font-size:320.10992432px;font-style:normal;font-variant:normal;font-weight:normal;font-stretch:normal;line-height:125%;letter-spacing:-55.78796005px;word-spacing:0px;fill:#ffffff;fill-opacity:1;stroke:none;font-family:Droid Sans;-inkscape-font-specification:Droid Sans"
+       d="M 116.09375,542.95593 C 95.970238,546.76157 75.866352,550.69664 55.75,554.54968 37.271066,654.48453 18.600595,754.38392 0.1875,854.33093 c 4.5670667,-0.0224 11.88925,-3.92217 14.989244,-1.88564 2.348097,12.30965 6.527711,24.13426 7.951802,36.55472 4.55774,23.64215 8.603147,47.44405 14.058954,70.86217 20.446729,-3.97475 40.892439,-7.95532 61.34375,-11.90625 0.806348,-6.01877 0.340643,-13.9623 0.6875,-18.84375 5.52874,12.6291 21.06261,15.98721 33.375,12.9375 18.4814,-4.95238 37.89007,-7.63966 56.75,-11.59375 -0.61826,-2.8783 4.8827,-0.79167 7.02749,-1.68038 14.16686,-1.03878 27.37606,-6.02271 41.41001,-7.38212 46.67851,-52.63829 -1.21449,-16.83212 30.65625,78.40625 17.19389,35.71392 58.70592,54.88142 97.40613,52.07812 21.55059,0.3486 43.28622,-5.5501 61.25012,-17.3281 0,7.9479 0,15.8958 0,23.8437 12.8637,-12.8518 32.06959,-10.4444 48.6875,-10.5625 12.08275,-0.4504 26.74579,-3.3417 33.09375,-14.75 2.84788,-8.0897 -0.35571,-16.9124 0.875,-25.25 0,-68.40622 0,-136.81247 0,-205.21872 -12.80081,2.58433 -25.80422,3.15955 -39,2.65625 -4.49542,-0.0745 -2.70343,-6.71819 -9.375,-2.8125 -14.41967,4.34039 -29.68137,2.22535 -44.53125,3.3125 -1.97068,-10.5394 -3.89878,-21.08667 -5.875,-31.625 43.54527,5.39974 90.52353,-22.98463 100.5,-66.625 11.74182,-45.53602 0.57063,-96.29858 -28.34375,-133 -18.76502,-21.52312 -47.96855,-34.21533 -76.77629,-30.338 -17.82405,1.69881 -35.28672,8.34732 -49.69246,18.74425 -12.97547,-7.86574 -27.99494,0.14323 -41.46466,1.78058 -8.5847,1.6356 -17.16935,3.2715 -25.75409,4.90692 2.25786,4.53438 -2.9589,1.63366 -5.28125,1.90625 -24.37251,-2.08163 -49.75835,4.12727 -69.28125,18.9375 -12.98942,-8.01584 -28.14096,-0.0134 -41.65179,1.65749 -7.26996,1.39739 -14.54254,2.78105 -21.81696,4.15501 C 140.087,578.41196 128.739,560.57354 117.4375,542.70593 l -0.98313,0.18291 z"
+       id="path3034"
+       inkscape:connector-curvature="0"
+       sodipodi:nodetypes="ccccccccccccccccccccccccccccccccccccc" />
+    <text
+       transform="matrix(1.0172511,-0.19643198,0.1830023,0.94770357,0,0)"
+       sodipodi:linespacing="125%"
+       id="text2999"
+       y="843.55823"
+       x="-121.33073"
+       style="font-size:338.93121338px;font-style:normal;font-weight:normal;line-height:125%;letter-spacing:-0.06177186px;word-spacing:0px;fill:#000000;fill-opacity:1;stroke:none;font-family:Sans"
+       xml:space="preserve"><tspan
+         style="font-style:normal;font-variant:normal;font-weight:normal;font-stretch:normal;letter-spacing:-59.06808853px;font-family:Droid Sans;-inkscape-font-specification:Droid Sans"
+         y="843.55823"
+         x="-121.33073"
+         id="tspan3001"
+         sodipodi:role="line">App</tspan></text>
+    <text
+       transform="matrix(1.0172511,-0.19643198,0.1830023,0.94770357,0,0)"
+       xml:space="preserve"
+       style="font-size:171.81326294px;font-style:normal;font-weight:normal;line-height:125%;letter-spacing:0px;word-spacing:0px;fill:#000000;fill-opacity:1;stroke:none;font-family:Sans"
+       x="-132.6741"
+       y="958.20111"
+       id="text3003"
+       sodipodi:linespacing="125%"><tspan
+         style="letter-spacing:-22.57948303px"
+         sodipodi:role="line"
+         id="tspan3005"
+         x="-132.6741"
+         y="958.20111">nit</tspan></text>
+    <text
+       transform="scale(1.0360431,0.96521081)"
+       sodipodi:linespacing="125%"
+       id="text3007"
+       y="1056.8173"
+       x="253.55678"
+       style="font-size:265.30044556px;font-style:normal;font-weight:normal;line-height:125%;letter-spacing:0px;word-spacing:0px;fill:#000000;fill-opacity:1;stroke:none;font-family:Sans"
+       xml:space="preserve"><tspan
+         y="1056.8173"
+         x="253.55678"
+         id="tspan3009"
+         sodipodi:role="line"
+         style="letter-spacing:-34.865448px">UI</tspan></text>
+  </g>
+</svg>
diff --git a/lib/android/examples/src/ui_test.nit b/lib/android/examples/src/ui_test.nit
new file mode 100644 (file)
index 0000000..f6c2a1b
--- /dev/null
@@ -0,0 +1,91 @@
+# This file is part of NIT ( http://www.nitlanguage.org ).
+#
+# Copyright 2014 Alexis Laferrière <alexis.laf@xymus.net>
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+#     http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
+# Test for app.nit's UI services
+module ui_test is
+       app_name("app.nit UI test")
+       app_version(0, 1, git_revision)
+       java_package("org.nitlanguage.ui_test")
+       android_manifest_activity """android:theme="@android:style/Theme.Light""""
+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
+       do
+               super
+
+               if inited then return
+               inited = true
+
+               # Setup UI
+               var context = native_activity
+               var layout = new NativeLinearLayout(context)
+               layout.set_vertical
+
+               but_notif = new Button
+               but_notif.text = "Show Notification"
+               layout.add_view but_notif.native
+
+               but_toast = new Button
+               but_toast.text = "Show Toast"
+               layout.add_view but_toast.native
+
+               context.content_view = layout
+       end
+
+       fun act_notif
+       do
+               var notif = self.notif
+               if notif == null then
+                       notif = new Notification("From app.nit", "Some content...")
+                       notif.ticker = "Ticker text..."
+                       notif.show
+                       self.notif = notif
+               else
+                       notif.cancel
+                       self.notif = null
+               end
+       end
+
+       fun act_toast
+       do
+               toast("Sample toast from app.nit at {get_time}", false)
+       end
+
+       redef fun catch_event(event)
+       do
+               if event isa ClickEvent then
+                       var sender = event.sender
+                       if sender == but_notif then
+                               act_notif
+                       else if sender == but_toast then
+                               act_toast
+                       end
+               end
+       end
+end