facebook

Example – vibrate at user defined interval

  1. MobiOne Archive
  2.  > 
  3. Examples, HOW-TOs
Viewing 4 posts - 1 through 4 (of 4 total)
  • Author
    Posts
  • #333319 Reply

    support-michael
    Keymaster

    edited: Jan 9, 2013, fixed issue with attached project. Note the project requires MobiOne 2.3 or greater.
    Vibrate Example

    The following example project demonstrates how to vibrate the device at a user defined interval using the Cordova/PhoneGap vibrate api. You must create an app from the project for the device api to function; this project will not run in the Test Center as it does not emulate the Cordova api.

    The app UI consists of a SelectListMenu(spinner) for setting the frequency that the device should vibrate and a Start and Stop button. The Start and Stop buttons have attached OnClick(RunJS) actions that respectively run custom start() and stop() javascript functions that I have created (see code below). The start() function starts a javascript timer (setInterval() js function) that runs at the frequency in seconds specified in the SelectListMenu. The stop() function clears the timer using the clearInterval() function.The Start button also serves as a restart action if the timer is already running.

    The mobione design file for this app is attached at the bottom.

    See attachment vibrate-ss.png

    The app javascript is available in the vibrate_custom.js file.

    
    //-----------------------------------
    timerId = -1;
    frequency = 1; //seconds
    isRunning = false;
    showNoCordovaMsg = true;
    VIBRATE_DURATION = 250; //milliseconds
    COLOR_GREEN = '#007000';
    COLOR_RED = '#E10000';
    
    function start() {
      if (showNoCordovaMsg && !phoneui.cordovaAvailable ()) {
         alert('Vibrate feature is only available for \nHTML5 apps. ');
         showNoCordovaMsg = false;
      }
      if (isRunning) { //restart
        stop();
        start();
        return;
      }
      isRunning = true;
      showStatus('Running...',COLOR_GREEN);
      frequency = $('select[name="frequency"]').val()
      timerId = setInterval(
                  function() {
                    if (phoneui.cordovaAvailable ()){
                      navigator.notification.vibrate(VIBRATE_DURATION);
                    }
                  },
                  frequency * 1000 + VIBRATE_DURATION);
    }
    
    function stop() {
      if (!isRunning) return;
      
      isRunning = false;
      clearInterval(timerId);
      showStatus('Stopped',COLOR_RED);
    }
    
    ....
    

    See the following guides if you need assistance creating either an iOS application or an Android application from this project.

    Source Code See attachment vibrate.zip

    Attachments:
    You must be logged in to view attached files.
    #333953 Reply

    johnnyboy
    Member

    I cant get this example to vibrate…

    I have tested it on both Iphone4 and Ipad

    Berfore updating to 2.3.0 (=today) I could not even see the GUI.

    After the upodate I was able to see and run the application.

    Is there somthing I need to do to get the PhoneGap functionality to work.

    (I have also tested the BarCodeReader Demo.. I can see and run the App in 2.3.0 but it seams not to be working ;-(

    help me to get the examples and PhoneGap functions to work

    Regards

    #333960 Reply

    support-michael
    Keymaster

    @johnnyboy

    Please see the edited article above. I completely goofed originally and did not upload the entire project. I have fixed the problem. Download the zip, build an ios or android app and give it a go.

    #334688 Reply

    Unknown Author
    Participant

    How about vibrating twice (or more) in a row, one right after the other? I’m interested for an iOS app and don’t know if that violates some iOS rule.

    -1TC

Viewing 4 posts - 1 through 4 (of 4 total)
Reply To: Example – vibrate at user defined interval

You must be logged in to post in the forum log in