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 `}
30 # Vibrate for `n
` miliseconds
31 fun vibrate(n: Int) in "Java" `{ recv.vibrate(n); `}
33 # Does this devices has a vibrator
35 # TODO activate in API 11
36 #fun exists: Bool in "Java" `{ return recv.hasVibrator(); `}
38 # Turn off the vibration
39 fun cancel
in "Java" `{ recv.cancel(); `}
42 redef fun new_global_ref import sys, Sys.jni_env `{
43 Sys sys
= Vibrator_sys(recv
);
44 JNIEnv *env
= Sys_jni_env(sys
);
45 return (*env
)->NewGlobalRef(env
, recv
);
50 # Get the handle to this device vibrator as a global ref
51 fun vibrator: Vibrator is cached do
52 var v = vibrator_native(native_activity)
53 return v.new_global_ref
55 private fun vibrator_native(context: NativeActivity): Vibrator in "Java" `{
56 android
.os
.Vibrator v
= (android
.os
.Vibrator)
57 context
.getSystemService
(android
.content
.Context.VIBRATOR_SERVICE);