Search code examples
backgroundgesturetizensony-smartwatch

tizen wearable invisible/background app (adding gestures)


I am wondering if it is possible to add some gestured to tizen wearable to make it possible to activate the screen using a specific gesture.

i already found some tutorials for the javascript code of the gestured (such as double tap). but what i want is following:

either just add the gesture to the os making it possible to choose the activation gesture in the settings menu (i think this will not be possible?) or make an app that only runs in the background (like a service in android, i know tizen cant have services but maybe it is possible somehow to run an app in the backround somehow). That app also should work when the screen is turned off, so i can activate it with the gesture.

i already saw the config line "backround-support=enable". will this help somehow? does the app also run while the screen is turned off then? if yes --> how to turn the screen on then

sorry for those million questions. i hope someone can help me :)

thanks for all your effords

EDIT: ok, i got a problem implementing this. I set the property in my config.xml but whenever i re-open (in task mgr) the app, it starts from new. Also it does not detect my gesture while the screen is turned off. here is my code: (i am using the hammer api to detect a double tap) config.xml:

    <?xml version="1.0" encoding="UTF-8"?>
<widget xmlns="http://www.w3.org/ns/widgets" xmlns:tizen="http://tizen.org/ns/widgets" id="http://yourdomain/DoubleTap" version="1.0.0" viewmodes="maximized">
    <tizen:application id="3orhQYRmuI.DoubleTap" package="3orhQYRmuI" required_version="2.2"/>
    <content src="index.html"/>
    <feature name="http://tizen.org/feature/screen.size.all"/>
    <icon src="icon.png"/>
    <name>DoubleTap</name>
    <tizen:setting background-support="enable" />
</widget>

main.js:

$(window).load(function(){
    document.addEventListener('tizenhwkey', function(e) {
        if(e.keyName == "back")
            tizen.application.getCurrentApplication().exit();
    });

    var element = document.getElementById('content');
    var mc = new Hammer.Manager(element, {tapHighlightColor: "green" , showTouches: true});

    // Tap recognizer with minimal 2 taps
    mc.add( new Hammer.Tap({ event: 'doubletap', taps: 2 }) );

    mc.get('doubletap').recognizeWith('singletap');

    mc.on("doubletap", function(ev) {
        //$('#textbox').html("gay");
        element.textContent += ev.type +" ";
        var isScreenOn = tizen.power.isScreenOn();
        if(!isScreenOn) {
            tizen.power.turnScreenOn();
        }
    });
});

and index.html:

<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8"/>
    <meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0">
    <meta name="description" content="A single-page template generated by Tizen Wearable Web IDE"/>

    <title>Tizen Wearable Web IDE - Tizen Wearable - jQuery</title>

    <script type="text/javascript" src="js/jquery-1.9.1.js"></script>
    <script type="text/javascript" src="js/hammer.js"></script>
    <script type="text/javascript" src="js/main.js"></script>
    <link rel="stylesheet" href="css/style.css" />
</head>
<body>
  <div class=contents id="content">
  </div>
</body>
</html>

the double tap recognition works perfectly and writes doubletap on the app screen. when i re-open the app the whole screen is empty again and starts to write new doubletap's. so its not really running in the background :/ also, it does not recognize my doubletaps when the app is in the background. neither when the app is in the foreground and the screen is turned off. do i need to use hide() first somehow or did i do a mistake in the code?


Solution

  • You can make your web app to run in background by setting background-support=enable property in config.xml file. When you set it, your app will be run even the screen is turned off and will be able to listen for devicemotion event, which helps you to recognize gestures.

    To set screen on you can use method from tizen power API.
    To control applications (to launch or hide) you shoud use Application API.

    You can't add your custom gestures to OS setting menu and you user should remember to launch you app back after each reboot.

    EDIT: You can't wake up your screen using touch gestures when app is hidden, because you don't have access to element that you are currently touch. When your app is in background, your document is not visible (other app is focused and covers yours).

    But you can activate your screen using motion gesture, f.e. listening a devicemotion events.

    function motionListener (e) {
        var acc = e.acceleration,
            x = Math.abs(Math.round(acc.x)),
            y = Math.abs(Math.round(acc.y)),
            z = Math.abs(Math.round(acc.z)),
            diff;
    
        if (x >= 5 || y >= 5 || z >= 5) {
            console.log("Shake!");
            tizen.power.turnScreenOn();
        }
    }
    
    window.addEventListener("devicemotion", motionListener, true);