+++ /dev/null
-default: linux
-
-linux:
- mkdir -p bin
- nitc -o bin/simple src/simple_linux.nit
-
-android:
- mkdir -p bin
- nitc -o bin/complete.apk src/complete_simple_android.nit --semi-global
- nitc -o bin/minimal.apk src/simple_android.nit --semi-global
-
-android-release:
- mkdir -p bin
- nitc -o bin/complete.apk src/complete_simple_android.nit --semi-global --release
- nitc -o bin/minimal.apk src/simple_android.nit --semi-global --release
-
-clean:
- rm -rf bin
+++ /dev/null
-<?xml version="1.0" encoding="utf-8"?>
-<resources>
- <bool name="test_bool">true</bool>
-</resources>
\ No newline at end of file
+++ /dev/null
-<?xml version="1.0" encoding="utf-8"?>
-<resources>
- <dimen name="test_dimen_1">25px</dimen>
- <dimen name="test_dimen_2">150px</dimen>
-</resources>
+++ /dev/null
-hello world
-
-Lorem ipsum dolor sit amet, consectetur adipiscing elit. Donec a diam lectus. Sed sit amet ipsum mauris. Maecenas congue ligula ac quam viverra nec consectetur ante hendrerit. Donec et mollis dolor. Praesent et diam eget libero egestas mattis sit amet vitae augue. Nam tincidunt congue enim, ut porta lorem lacinia consectetur. Donec ut libero sed arcu vehicula ultricies a non tortor. Lorem ipsum dolor sit amet, consectetur adipiscing elit. Aenean ut gravida lorem. Ut turpis felis, pulvinar a semper sed, adipiscing id dolor. Pellentesque auctor nisi id magna consequat sagittis. Curabitur dapibus enim sit amet elit pharetra tincidunt feugiat nisl imperdiet. Ut convallis libero in urna ultrices accumsan. Donec sed odio eros. Donec viverra mi quis quam pulvinar at malesuada arcu rhoncus. Cum sociis natoque penatibus et magnis dis parturient montes, nascetur ridiculus mus. In rutrum accumsan ultricies. Mauris vitae nisi at sem facilisis semper ac in est.
+++ /dev/null
-Categories:Nit
-License:Apache2
-Web Site:http://nitlanguage.org
-Source Code:http://nitlanguage.org/nit.git/tree/HEAD:/contrib/mnit_test
-Issue Tracker:https://github.com/nitlang/nit/issues
-
-Summary:Simple Demo for MNit
-Description:
-A useless application that test various API usage of the mnit framework on Android.
-.
+++ /dev/null
-Categories:Nit
-License:Apache2
-Web Site:http://nitlanguage.org
-Source Code:http://nitlanguage.org/nit.git/tree/HEAD:/contrib/mnit_test
-Issue Tracker:https://github.com/nitlang/nit/issues
-
-Summary:Minimal Demo for MNit
-Description:
-A useless application that test various basic API usage of the mnit framework on Android.
-.
+++ /dev/null
-[package]
-name=mnit_test
-tags=testing
-maintainer=Alexis Laferrière <alexis.laf@xymus.net>
-license=Apache-2.0
-[upstream]
-browse=https://github.com/nitlang/nit/tree/master/examples/mnit_simple/
-git=https://github.com/nitlang/nit.git
-git.directory=examples/mnit_simple/
-homepage=http://nitlanguage.org
-issues=https://github.com/nitlang/nit/issues
-apk=http://nitlanguage.org/fdroid/apk/test_all.apk
+++ /dev/null
-# This file is part of NIT ( http://www.nitlanguage.org ).
-#
-# Copyright 2014 Frédéric Vachon <fredvac@gmail.com>
-#
-# 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.
-
-# Entrypoint of an app with all the mnit tests for Android
-module complete_simple_android is
- app_name "mnit Complete"
- app_namespace "org.nitlanguage.test_all"
- android_api_target 19
-end
-
-import test_bundle
-import test_audio
-import test_shared_preferences
-import test_assets_and_resources
-import test_target_api
-import test_data_store
-import test_intent
+++ /dev/null
-# This file is part of NIT ( http://www.nitlanguage.org ).
-#
-# Copyright 2012-2013 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.
-
-# Very simple application
-module simple is
- app_name "mnit Minimal"
- app_version(0, 2, git_revision)
-end
-
-import mnit
-
-redef class App
-
- var img : nullable I = null
-
- redef fun on_create
- do
- super
-
- var txt = load_asset( "hello.txt" )
- if txt isa String then
- print txt.length
- print txt
- end
-
- img = load_image( "fighter.png" )
- end
-
- var r = 0.0 is writable
- var g = 0.0 is writable
- var b = 0.0 is writable
- redef fun frame_core( display )
- do
- b = b + 0.01
- if b > 1.0 then b = 0.0
-
- display.clear( r, g, b )
-
- var img = self.img
- if img != null then
- display.blit( img, 100, 100 )
- end
- end
-
- redef fun input( ie )
- do
- if ie isa QuitEvent then
- quit = true
- return true
- else if ie isa PointerEvent then
- r = ie.x/display.width.to_f
- g = ie.y/display.height.to_f
- return true
- else
- print "unknown input: {ie}"
- return false
- end
- end
-end
+++ /dev/null
-# This file is part of NIT ( http://www.nitlanguage.org ).
-#
-# Copyright 2012-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.
-
-module simple_android is
- app_namespace "org.nitlanguage.test_minimal"
- android_manifest """<uses-permission android:name="android.permission.VIBRATE" />"""
-end
-
-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
-
- redef fun to_s do return "({x}, {y})"
-end
+++ /dev/null
-# This file is part of NIT ( http://www.nitlanguage.org ).
-#
-# Copyright 2012-2013 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.
-
-module simple_linux
-
-import simple
-import mnit::linux
-
-import test_data_store
-
-super
+++ /dev/null
-# This file is part of NIT ( http://www.nitlanguage.org ).
-#
-# Copyright 2014 Romain Chanoir <romain.chanoir@viacesi.fr>
-#
-# 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 the asserts_and_resources module of App.nit framework
-module test_assets_and_resources
-
-import simple_android
-intrude import android::assets_and_resources
-
-redef class App
- redef fun input( ie )
- do
- if ie isa PointerEvent and ie.depressed then
- test_assets
- test_resources
- end
- return super
- end
-
- # Testing the assets manager
- fun test_assets
- do
- assert not asset_manager.open_fd("testsound.ogg").is_java_null
- end
-
- # Testing the resources manager
- fun test_resources do
- # FIXME test deactivated to use app_name which is incompatible
- # with a custom res/values/strings.xml
- #assert resource_manager.string("string_test") == "string test"
-
- assert resource_manager.boolean("test_bool") == true
- assert resource_manager.dimension("test_dimen_1") == 25
- assert resource_manager.dimension("test_dimen_2") == 150
- end
-end
+++ /dev/null
-# This file is part of NIT ( http://www.nitlanguage.org ).
-#
-# Copyright 2014 Romain Chanoir <romain.chanoir@viacesi.fr>
-#
-# 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 the audio module of App.nit framework
-module test_audio
-
-import simple_android
-import android::audio
-
-redef class App
- # Sound
- var soundsp: Sound is noinit
-
- # Music
- var soundmp: Music is noinit
-
- # Sound
- var easy_soundsp = new Sound("testsound")
-
- # Music
- var easy_soundmp = new Music("xylofon")
-
- # Read sounds from the assets folder?
- var test_assets = false
-
- # Read sounds from the resources folder?
- var test_ressources = true
-
- # Test the automatic way with `PlayableAudio::load`?
- var test_easy_sounds = false
-
- redef fun on_create
- do
- super
- default_mediaplayer.looping = true
- if test_assets then
- soundsp = new Sound("testsound.og")
- soundmp = new Music("xylofon.og")
- soundmp.play
- end
- if test_ressources then
- soundsp = load_sound_from_res("testsound")
- soundmp = load_music_from_res("xylofon")
- soundmp.play
- end
- if test_easy_sounds then
- easy_soundsp.load
- easy_soundmp.load
- easy_soundmp.play
- end
- end
-
- redef fun input( ie )
- do
- if ie isa PointerEvent and ie.depressed then
- if test_assets or test_ressources then
- soundsp.play
- else if test_easy_sounds then
- easy_soundsp.play
- end
- end
- return super
- end
-end
+++ /dev/null
-# This file is part of NIT ( http://www.nitlanguage.org ).
-#
-# Copyright 2014 Frédéric Vachon <fredvac@gmail.com>
-#
-# 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 the bundle module of App.nit framework
-module test_bundle
-
-import simple_android
-import android::bundle
-
-redef class App
- redef fun input ( ie )
- do
- if ie isa PointerEvent and ie.depressed then
- test_bundle
- end
- return super
- end
-
- fun test_bundle
- do
- var bundle = new Bundle
-
- bundle["anInt"] = 1
- bundle["aFloat"] = 1.1
- bundle["aString"] = "A string"
- bundle["aBool"] = true
-
- var int_array = new Array[Int]
- var bool_array = new Array[Bool]
-
- var value = true
-
- for i in [0..5] do
- int_array.add(i)
- bool_array.add(value)
- value = not value
- end
-
- bundle["anArrayOfInt"] = int_array
- bundle["anArrayOfBool"] = bool_array
-
- assert bundle.int("anInt", 0) == 1
- assert bundle.int("wrongInt", 0) == 0
- assert bundle.float("aFloat", 0.0) == 1.1
- assert bundle.float("wrongFloat", 0.0) == 0.0
- assert bundle.string("aString") == "A string"
- assert bundle.string("wrongString") == null
- assert bundle.bool("aBool", false)
- assert bundle.bool("wrongBool", false) == false
-
- var int_array_test = bundle.array_of_int("anArrayOfInt")
- var bool_array_test = bundle.array_of_bool("anArrayOfBool")
-
- value = true
-
- for i in [0..5] do
- assert int_array_test[i] == i
- assert bool_array_test[i] == value
- value = not value
- end
-
- assert bundle.size == 6
- assert bundle.has("aBool")
- assert not bundle.is_empty
-
- bundle.remove("aString")
- bundle.remove("anArrayOfBool")
-
- assert bundle.string("aString") == null
- assert bundle.array_of_bool("anArrayOfBool") == null
-
- # Serializable tests
- var p1 = new Point(10, 10)
- bundle["aPoint"] = p1
- var p2 = bundle.deserialize("aPoint")
-
- assert p1.to_s == p2.to_s
-
- var point_array = new Array[Point]
-
- for i in [0..5] do point_array.add(new Point(i, i))
-
- bundle["anArrayOfPoint"] = point_array
-
- var deserialized_point_array = bundle.deserialize_array("anArrayOfPoint")
-
- for i in [0..5] do
- var point = new Point(i, i)
- assert deserialized_point_array[i].to_s == point.to_s
- end
-
- bundle.clear
-
- assert bundle.keys.is_empty
- assert bundle.is_empty
- end
-end
+++ /dev/null
-# 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 the shared_preferences module of App.nit framework
-module test_data_store
-
-import simple
-import app::data_store
-
-redef class App
- redef fun on_create
- do
- super
-
- # load colors from data store
- var r = data_store["r"]
- if r isa Float then
- self.r = r
- print "r {r}"
- else assert r == null
-
- var g = data_store["g"]
- if g isa Float then
- self.g = g
- print "g {g}"
- else assert g == null
- end
-
- redef fun input(ie)
- do
- if ie isa PointerEvent then
- # save color for next execution
- data_store["r"] = r
- data_store["g"] = g
- end
-
- return super
- end
-end
+++ /dev/null
-# This file is part of NIT ( http://www.nitlanguage.org ).
-#
-# Copyright 2014 Frédéric Vachon <fredvac@gmail.com>
-#
-# 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 the intent module of App.nit framework
-module test_intent
-
-import simple_android
-import android::intent::intent_api19
-
-redef class App
- var intent: Intent
- redef fun input( ie )
- do
- if ie isa PointerEvent and ie.depressed then
- test_intent
- end
- return super
- end
-
- fun test_intent
- do
- intent = new Intent
- intent.action = intent_action.view.to_s
- intent.data = "content://contacts/people/"
-
- start_activity intent
- intent.destroy
-
- intent = new Intent
- var p1 = new Point(10, 20)
- intent["a_point"] = p1
- var p2 = intent["a_point"]
- assert p1.to_s == p2.to_s
-
- intent.action = intent_action.main.to_s
- assert intent.action == intent_action.main.to_s
-
- intent.add_flags intent_flag.activity_brought_to_front
- assert intent.flags == intent_flag.activity_brought_to_front
-
- var bool_array = new Array[Bool]
- for i in [0..5] do bool_array.add( i % 2 == 0 )
-
- intent.add_extra_array_of_bool("bools", bool_array)
- var bool_array2 = intent.extra_bool_array("bools")
- for i in [0..5] do assert bool_array2[i] == (i%2 ==0)
-
- var string_array = ["foo", "bar", "baz"]
- intent.add_extra_array_of_string("strings", string_array)
- var string_array2 = intent.extra_string_array("strings")
- for i in [0..string_array2.length[ do assert string_array[i] == string_array2[i]
-
- intent.add_extra_array_list_of_string("strings", string_array)
- string_array2 = intent.extra_string_array_list("strings")
- for i in [0..string_array2.length[ do assert string_array[i] == string_array2[i]
-
- intent.add_category intent_category.home.to_s
- var categories = intent.categories
- assert categories.first == intent_category.home.to_s
- assert intent.has_category(intent_category.home.to_s)
-
- intent.destroy
- end
-end
+++ /dev/null
-# This file is part of NIT ( http://www.nitlanguage.org ).
-#
-# Copyright 2014 Frédéric Vachon <fredvac@gmail.com>
-#
-# 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 the shared_preferences module of App.nit framework
-module test_shared_preferences
-
-import simple_android
-import android::shared_preferences
-
-redef class App
- redef fun input ( ie )
- do
- if ie isa PointerEvent and ie.depressed then
- test_shared_preferences
- end
- return super
- end
-
- fun test_shared_preferences
- do
- # Private mode tests
- var sp = new SharedPreferences.privately(self, "test")
- sp.add_bool("a_boolean", true)
- sp.add_float("a_float", 66.6)
- sp.add_int("an_int", 666)
- sp.add_int("a_second_int", 666777)
- sp.add_long("a_long", 6666666666)
- sp.add_string("a_string", "A string")
- sp["another_int"] = 85
- sp["yet_another_string"] = "Another string"
- sp.remove("a_second_int")
-
- # Serialized object test
- var my_point = new Point(10, 10)
- sp["a_point"] = my_point
- var my_deserialized_point = sp["a_point"]
- assert my_point.to_s == my_deserialized_point.to_s
-
- assert sp.bool("a_boolean", false) == true
- assert sp.bool("wrong_boolean", false) == false
- assert sp.float("a_float", 0.0) != 0.0
- assert sp.float("wrong_float", 0.0) == 0.0
- assert sp.int("an_int", 0) == 666
- assert sp.int("a_second_int", 0) == 0
-
- # FIXME getting long from Java on Android is broken
- # The C FFI (underlying the Java FFI) version of Int is a `long` which is on 32 bits on Android.
- #assert sp.long("a_long", 0) == 6666666666
-
- assert sp.long("wrong_long", 0) == 0
- assert sp.string("a_string", "ERROR!") == "A string"
- assert sp.string("wrong_string", "ERROR!") == "ERROR!"
- assert sp["another_int"] == 85
- assert sp["yet_another_string"] == "Another string"
- assert sp.has("an_int") == true
- assert sp.has("a_second_int") == false
-
- sp.clear
- assert sp.all == null
-
- sp.destroy
- end
-end
+++ /dev/null
-# This file is part of NIT ( http://www.nitlanguage.org ).
-#
-# Copyright 2014 Frédéric Vachon <fredvac@gmail.com>
-#
-# 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 the API level related annotations
-module test_target_api is
- android_api_min 10
- android_api_max 19
-end
-
-import simple_android
-#FIXME: Double quad to access lib/foo/goo/bar.nit is evil
-import android::shared_preferences::shared_preferences_api11
-
-redef class App
- redef fun input( ie )
- do
- if ie isa PointerEvent and ie.depressed then
- test_target_api
- end
- return super
- end
-
- fun test_target_api
- do
- var hash_set = new HashSet[JavaString]
- hash_set.add "foo".to_java_string
- hash_set.add "bar".to_java_string
-
- shared_preferences.add_string_set("test", hash_set)
-
- var hash_set2 = shared_preferences.string_set("test")
-
- var tab = ["foo", "bar"]
- var i = 0
-
- for entry in hash_set2 do
- assert entry == tab[i].to_java_string
- i+=1
- end
-
- end
-end