Touchgui/plugins/org.apache.cordova.vibration/src/blackberry10/index.js

Thu, 04 Jun 2015 14:50:33 +0200

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Thu, 04 Jun 2015 14:50:33 +0200
changeset 0
e8ccd40d0ef6
permissions
-rw-r--r--

Genesis of lecture sources for Droidcon Berlin 2015 in Postbahnhof.

     1 /*
     2  *
     3  * Licensed to the Apache Software Foundation (ASF) under one
     4  * or more contributor license agreements.  See the NOTICE file
     5  * distributed with this work for additional information
     6  * regarding copyright ownership.  The ASF licenses this file
     7  * to you under the Apache License, Version 2.0 (the
     8  * "License"); you may not use this file except in compliance
     9  * with the License.  You may obtain a copy of the License at
    10  *
    11  *   http://www.apache.org/licenses/LICENSE-2.0
    12  *
    13  * Unless required by applicable law or agreed to in writing,
    14  * software distributed under the License is distributed on an
    15  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
    16  * KIND, either express or implied.  See the License for the
    17  * specific language governing permissions and limitations
    18  * under the License.
    19  *
    20 */
    22 var vibration;
    24 module.exports = {
    25     vibrate: function (success, fail, args, env) {
    26         var result = new PluginResult(args, env),
    27             duration = args[0],
    28             response = vibration.getInstance().vibrate(duration);
    29         result.ok(response, false);
    30     }
    31 };
    33 ///////////////////////////////////////////////////////////////////
    34 // JavaScript wrapper for JNEXT plugin
    35 ///////////////////////////////////////////////////////////////////
    37 JNEXT.Vibration = function () {
    38     var self = this,
    39         hasInstance = false;
    41     self.vibrate = function (duration) {
    42         //This is how Javascript calls into native
    43         return JNEXT.invoke(self.m_id, "vibrate " + duration);
    44     };
    46     self.init = function () {
    47         //Checks that the jnext library is present and loads it
    48         if (!JNEXT.require("libVibration")) {
    49             return false;
    50         }
    52         //Creates the native object that this interface will call
    53         self.m_id = JNEXT.createObject("libVibration.Vibration");
    55         if (self.m_id === "") {
    56             return false;
    57         }
    59         //Registers for the JNEXT event loop
    60         JNEXT.registerEvents(self);
    61     };
    63     self.m_id = "";
    65     //Used by JNEXT library to get the ID
    66     self.getId = function () {
    67         return self.m_id;
    68     };
    70     //Not truly required but useful for instance management
    71     self.getInstance = function () {
    72         if (!hasInstance) {
    73             self.init();
    74             hasInstance = true;
    75         }
    76         return self;
    77     };
    78 };
    80 vibration = new JNEXT.Vibration();

mercurial