<?xml version="1.0" encoding="UTF-8"?>
-<widget xmlns:tizen="http://tizen.org/ns/widgets" xmlns="http://www.w3.org/ns/widgets" id="http://sample-web-application.tizen.org/compass" version="2.0.0" viewmodes="fullscreen">
- <icon src="icon.png"/>
+<widget xmlns="http://www.w3.org/ns/widgets" xmlns:tizen="http://tizen.org/ns/widgets" id="http://sample-web-application.tizen.org/compass" version="2.1.0" viewmodes="fullscreen">
+ <tizen:application id="2dKf9wyV6t.Compass" package="2dKf9wyV6t" required_version="2.1"/>
<content src="index.html"/>
+ <icon src="icon.png"/>
+ <name>Compass</name>
<tizen:privilege name="http://tizen.org/privilege/application.read"/>
<tizen:privilege name="http://tizen.org/privilege/systeminfo"/>
- <tizen:privilege name="http://tizen.org/privilege/tizen"/>
- <name>Compass</name>
- <tizen:application id="8hcnf3vfws" required_version="1.0"/>
- <tizen:setting screen-orientation="portrait"/>
+ <tizen:setting screen-orientation="portrait" context-menu="disable" background-support="enable" encryption="disable" install-location="auto"/>
</widget>
<meta name="viewport" content="user-scalable=no, width=480">
<title>Compass</title>
<link rel="stylesheet" href="./css/style.css" />
-<script type="text/javascript" src="./js/jquery-1.7.1.min.js"></script>
-<script src="./js/main.js"></script>
+<script type="text/javascript" src="./js/jquery-1.7.1.min.js" defer="defer"></script>
+<script src="./js/main.js" defer="defer"></script>
</head>
-
<body>
<div id="application">
<div id="rotation"><canvas id="canvas" width="392" height="392"></canvas></div>
<div id="shadow"></div>
- <div id="direction">NORTHWEST</div>
- <div id="angle">329<sup>o</sup></div>
- <div class="exit_button normal" id="exit_button"/></div>
+ <div id="direction"></div>
+ <div id="angle"></div>
+ <div class="exit_button normal" id="exit_button"></div>
</div>
</body>
-
</html>
\ No newline at end of file
* limitations under the License.
*/
-/*jslint browser: true, devel: true */
-/*global tizen, $*/
+/*global document, window, tizen, $*/
-var angleMemory = 0,
- $direction = null,
+var angleMemory = -1,
rotation = 0;
function onDeviceOrientation(dataEvent) {
"use strict";
- var angle = dataEvent.alpha,
- deltaAngle;
-
- if (angle <= 22) {
- $direction.html('NORTH');
- } else if (angle <= 68) {
- $direction.html('NORTHEAST');
- } else if (angle <= 112) {
- $direction.html('EAST');
- } else if (angle <= 158) {
- $direction.html('SOUTHEAST');
- } else if (angle <= 202) {
- $direction.html('SOUTH');
- } else if (angle <= 248) {
- $direction.html('SOUTHWEST');
- } else if (angle <= 292) {
- $direction.html('WEST');
- } else if (angle <= 338) {
- $direction.html('NORTHWEST');
- } else {
- $direction.html('NORTH');
- }
-
- deltaAngle = angleMemory - angle;
+ if (dataEvent.alpha !== angleMemory) {
+ var angle = dataEvent.alpha,
+ deltaAngle, text = '';
+
+ if (angle < 68 || angle > 292) {
+ text += 'NORTH';
+ } else if (angle > 112 && angle < 248) {
+ text += 'SOUTH';
+ }
+ if (angle > 22 && angle < 158) {
+ text += 'EAST';
+ } else if (angle > 202 && angle < 338) {
+ text += 'WEST';
+ }
- if (Math.abs(deltaAngle) > 180) {
- if (deltaAngle > 0) {
- rotation -= ((360 - angleMemory) + angle);
+ deltaAngle = angleMemory - angle;
+ if (Math.abs(deltaAngle) > 180) {
+ if (deltaAngle > 0) {
+ rotation -= ((360 - angleMemory) + angle);
+ } else {
+ rotation += (angleMemory + (360 - angle));
+ }
} else {
- rotation += (angleMemory + (360 - angle));
+ rotation += deltaAngle;
}
- } else {
- rotation += deltaAngle;
- }
- $("#angle").html(Math.round(angle) + "<sup>o</sup>");
- $('#rotation').css('-webkit-transform', 'rotate(' + (rotation) + 'deg)');
+ angleMemory = angle;
- angleMemory = angle;
+ $('#direction').text(text);
+ $("#angle").html(Math.round(angle) + "<sup>o</sup>");
+ $('#rotation').css('-webkit-transform', 'rotate(' + rotation + 'deg)');
+ }
}
function startSensor() {
window.addEventListener("deviceorientation", onDeviceOrientation, false);
}
-function init() {
+function exitButton() {
"use strict";
-
- var button = $('#exit_button');
- $direction = $('#direction');
-
- button.ontouchstart = function ontouchstart() {
- $(this).removeClass('normal').addClass('pushed');
- };
-
- button.ontouchend = function ontouchend() {
- $(this).removeClass('pushed').addClass('normal');
+ $('#exit_button').on('click', function () {
+ window.removeEventListener("deviceorientation", onDeviceOrientation, false);
tizen.application.getCurrentApplication().exit();
- };
-
- button
- .on('touchstart', button.ontouchstart)
- .on('touchend', button.ontouchend);
+ });
+}
+function init() {
+ "use strict";
+ exitButton();
startSensor();
}