From e35f942fd4f24f40e63dba728af5f98c35339f4f Mon Sep 17 00:00:00 2001 From: =?utf8?q?Alexis=20Laferri=C3=A8re?= Date: Mon, 28 Apr 2014 12:22:38 -0400 Subject: [PATCH] lib: intro android::vibration MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Signed-off-by: Alexis Laferrière --- lib/android/vibration.nit | 54 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 54 insertions(+) create mode 100644 lib/android/vibration.nit diff --git a/lib/android/vibration.nit b/lib/android/vibration.nit new file mode 100644 index 0000000..abff40f --- /dev/null +++ b/lib/android/vibration.nit @@ -0,0 +1,54 @@ +# This file is part of NIT ( http://www.nitlanguage.org ). +# +# Copyright 2014 Alexis Laferrière +# +# 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. + +# Vibration services for Android +# +# Importing this module will trigger the use of the VIBRATE permission +module vibration is + android_manifest("""""") +end + +import native_app_glue + +# Handle to an Android vibrator +extern class Vibrator in "Java" `{ android.os.Vibrator `} + super JavaObject + redef type SELF: Vibrator + + # Vibrate for `n` miliseconds + fun vibrate(n: Int) in "Java" `{ recv.vibrate(n); `} + + # Does this devices has a vibrator + # + # TODO activate in API 11 + #fun exists: Bool in "Java" `{ return recv.hasVibrator(); `} + + # Turn off the vibration + fun cancel in "Java" `{ recv.cancel(); `} +end + +redef class App + # Get the handle to this device vibrator as a global ref + fun vibrator: Vibrator is cached do + var v = vibrator_native(native_activity) + return v.new_global_ref + end + private fun vibrator_native(context: NativeActivity): Vibrator in "Java" `{ + android.os.Vibrator v = (android.os.Vibrator) + context.getSystemService(android.content.Context.VIBRATOR_SERVICE); + return v; + `} +end -- 1.7.9.5