1 # This file is part of NIT ( http://www.nitlanguage.org ).
3 # Copyright 2014 Alexis Laferrière <alexis.laf@xymus.net>
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
9 # http://www.apache.org/licenses/LICENSE-2.0
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.
17 # Vibration services for Android
19 # Importing this module will trigger the use of the VIBRATE permission
21 android_manifest
("""<uses-permission android:name="android.permission.VIBRATE" />""")
24 import native_app_glue
26 # Handle to an Android vibrator
27 extern class Vibrator in "Java" `{ android.os.Vibrator `}
29 redef type SELF: Vibrator
31 # Vibrate for `n
` miliseconds
32 fun vibrate(n: Int) in "Java" `{ recv.vibrate(n); `}
34 # Does this devices has a vibrator
36 # TODO activate in API 11
37 #fun exists: Bool in "Java" `{ return recv.hasVibrator(); `}
39 # Turn off the vibration
40 fun cancel
in "Java" `{ recv.cancel(); `}
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
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);