Search code examples
tizen

Whether Longpress supported in tizen wearable app?


I used mousedown and mouseup events to identify long click. But that is not working in Tizen emulator for me. But the same code is working fine in browsers. Tau provided by tizen supports only swipe.

The code below works fine in browsers:

var timeOut;
$("button").mouseup(function(event){
     
    clearTimeout(timeOut);
});
$("button").mousedown(function(event){
    
    timeOut = setTimeout(function(){
        
        alert('you hold your mouse more than 2 seconds.!');
      
    },2000);
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<button>click me</button>

Referred this fiddle too

But nothing works in tizen wearable emulator. So any other suggestion I can try??


Solution

  • You can use 'touchstart' and 'touchend' instead of 'mousedown' and 'mouseup'.

    I tested below code now with Basic Web Template. It working well! :)

    main.js

    window.onload = function() {
    // TODO:: Do your initialization job
    
    // add eventListener for tizenhwkey
    document.addEventListener('tizenhwkey', function(e) {
        if (e.keyName === "back") {
            try {
                tizen.application.getCurrentApplication().exit();
            } catch (ignore) {}
        }
    });
    
    // Sample code
    var mainPage = document.querySelector('#main');
    
    var timeOut;
    var cnt = 0;
    mainPage.addEventListener("touchend", function() {
        var contentText = document.querySelector('#content-text');
        console.log("timer clear!");
        clearTimeout(timeOut);
    });
    
    mainPage.addEventListener("touchstart", function() {
        var contentText = document.querySelector('#content-text');
        console.log("touchstart!");
        timeOut = setTimeout(function(){
            console.log("long!");
            contentText.innerHTML = "Long!" + cnt;
            cnt++;
        },2000);
    });
    

    };