tests: add a test for the extra_java_files phase
[nit.git] / lib / android / vibration.nit
1 # This file is part of NIT ( http://www.nitlanguage.org ).
2 #
3 # Copyright 2014 Alexis Laferrière <alexis.laf@xymus.net>
4 #
5 # Licensed under the Apache License, Version 2.0 (the "License");
6 # you may not use this file except in compliance with the License.
7 # You may obtain a copy of the License at
8 #
9 # http://www.apache.org/licenses/LICENSE-2.0
10 #
11 # Unless required by applicable law or agreed to in writing, software
12 # distributed under the License is distributed on an "AS IS" BASIS,
13 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 # See the License for the specific language governing permissions and
15 # limitations under the License.
16
17 # Vibration services for Android
18 #
19 # Importing this module will trigger the use of the VIBRATE permission
20 module vibration is
21 android_manifest("""<uses-permission android:name="android.permission.VIBRATE" />""")
22 end
23
24 import native_app_glue
25
26 # Handle to an Android vibrator
27 extern class Vibrator in "Java" `{ android.os.Vibrator `}
28 super JavaObject
29 redef type SELF: Vibrator
30
31 # Vibrate for `n` miliseconds
32 fun vibrate(n: Int) in "Java" `{ recv.vibrate(n); `}
33
34 # Does this devices has a vibrator
35 #
36 # TODO activate in API 11
37 #fun exists: Bool in "Java" `{ return recv.hasVibrator(); `}
38
39 # Turn off the vibration
40 fun cancel in "Java" `{ recv.cancel(); `}
41 end
42
43 redef class App
44 # Get the handle to this device vibrator as a global ref
45 fun vibrator: Vibrator is cached do
46 var v = vibrator_native(native_activity)
47 return v.new_global_ref
48 end
49 private fun vibrator_native(context: NativeActivity): Vibrator in "Java" `{
50 android.os.Vibrator v = (android.os.Vibrator)
51 context.getSystemService(android.content.Context.VIBRATOR_SERVICE);
52 return v;
53 `}
54 end