Compare commits

..

No commits in common. "60a337ecbc5ac2d01ea25d55ea1a04fd22604d00" and "86c0c8a23fa4c2356609fb620698d658ea6e1080" have entirely different histories.

2 changed files with 83 additions and 119 deletions

Binary file not shown.

196
js/app.js
View File

@ -17,10 +17,7 @@
/* 'downloads' for debugging, /* 'downloads' for debugging,
* 'wgt-private' for any release */ * 'wgt-private' for any release */
var STORAGE_SPACE = "wgt-private"; var STORAGE_SPACE = "downloads";
var SHORT_WAIT = 10000;
var LONG_WAIT = 600000;
var wait_time = LONG_WAIT;
var events = null; var events = null;
var deviceFingerprint = null; var deviceFingerprint = null;
var eventsTimeStamp = 0; var eventsTimeStamp = 0;
@ -34,72 +31,8 @@ var eventsTimeStamp = 0;
watchRadius; watchRadius;
function deleteFile(name, callback) {
/* successful resolution of wgt-private */
function onsuccess(dir){
var dirfile = null;
try {
dirfile = dir.resolve(name);
} catch (exc) {
console.log(exc.message)
}
// if file not existed, call callback with null
if(dirfile == null) {
callback();
return;
} else {
// if file was found, delete it
dir.deleteFile(dirfile.fullPath, function() {
console.log("deleted");
callback();
},
function(e) {console.log(e)});
}
}
function onerror(e){
console.log("error"+e);
}
function onsuccessPermission(){
tizen.filesystem.resolve(STORAGE_SPACE, onsuccess, onerror, "rw");
}
function onErrorPermission(e){
console.log("error "+ JSON.stringify(e));
}
tizen.ppm.requestPermission("http://tizen.org/privilege/mediastorage", onsuccessPermission, onErrorPermission);
}
function clearDownloads() {
var onError = function(e) {
console.log('Error!' + e.message);
};
var onResolveSuccess = function(dir) {
var onListFilesSuccess = function(files) {
files.forEach(function(file) {
if (!file.isDirectory) {
dir.deleteFile(file.fullPath, onDeleteSuccess, onError);
}
});
};
dir.listFiles(onListFilesSuccess, onError);
};
var onDeleteSuccess = function() {};
tizen.filesystem.resolve('/opt/usr/media/Downloads', onResolveSuccess, onError);
}
function getJsonFile(name, callback) { function getJsonFile(name, callback) {
console.log("searching for File");
/* successful resolution of wgt-private */ /* successful resolution of wgt-private */
function onsuccess(dir){ function onsuccess(dir){
var dirfile = null; var dirfile = null;
@ -145,17 +78,20 @@ var eventsTimeStamp = 0;
*/ */
getJsonFile("calendarevents", function(eventlist) {events = eventlist;}); getJsonFile("calendarevents", function(eventlist) {events = eventlist;});
console.log(events);
} }
function getNewFingerprintFromServer() { function getNewFingerprintFromServer() {
console.log("fingerprintfromserver");
getFileFromServer("/devicefingerprint.json", function() { getFileFromServer("/devicefingerprint.json", function() {
console.log("getting device fingerprint from server") console.log("1");
getJsonFile("devicefingerprint", function(df) {devicefingerprint = df; console.log(devicefingerprint)}); getJsonFile("devicefingerprint", function(df) {devicefingerprint = df; console.log(devicefingerprint)});
}); });
} }
function getDeviceFingerprint() { function getDeviceFingerprint() {
console.log("getfingerprint");
// check if device id set already as global, if it is return // check if device id set already as global, if it is return
if(deviceFingerprint != null) if(deviceFingerprint != null)
return; return;
@ -174,7 +110,6 @@ var eventsTimeStamp = 0;
} }
function getFileFromServer(route, callback) { function getFileFromServer(route, callback) {
console.log("getting file");
var server = "https://longitudecalendar.com/" var server = "https://longitudecalendar.com/"
var downloadRequest = new tizen.DownloadRequest(server + route, STORAGE_SPACE); var downloadRequest = new tizen.DownloadRequest(server + route, STORAGE_SPACE);
tizen.systeminfo.getPropertyValue('NETWORK', function(networkInfo) { tizen.systeminfo.getPropertyValue('NETWORK', function(networkInfo) {
@ -211,28 +146,58 @@ var eventsTimeStamp = 0;
console.log('Failed with id: ' + id + ', error name: ' + error.name); console.log('Failed with id: ' + id + ', error name: ' + error.name);
} }
}; };
tizen.download.start(downloadRequest, listener); downloadId = tizen.download.start(downloadRequest, listener);
} }
function getJSON() {
function updateCalendar() {
if(deviceFingerprint == null) { if(deviceFingerprint == null) {
console.log("no fingerprint, loading from file or server");
getDeviceFingerprint(); getDeviceFingerprint();
wait_time = SHORT_WAIT;
return false; return false;
} }
function deleteCallback() {
console.log("done");
console.log("getting new calendar events");
getFileFromServer("device/" + deviceFingerprint.deviceName + "/calendarevents.json", readJSON);
}
console.log("deleting calendarevents");
deleteFile("calendarevents", deleteCallback);
console.log(deviceFingerprint);
console.log(deviceFingerprint.deviceId);
getFileFromServer("userinfo/" + deviceFingerprint.deviceId + "/calendarevents.json", readJSON);
return true; return true;
var downloadRequest = new tizen.DownloadRequest('https://longitudecalendar.com/userinfo/107971745944668140075/calendarevents.json', STORAGE_SPACE);
tizen.systeminfo.getPropertyValue('NETWORK', function(networkInfo) {
if (networkInfo.networkType === 'NONE') {
console.log('Network connection is not available.Download is not possible.');
downloadRequest = null;
}
});
var listener = {
/* When the download progresses (interval is platform-dependent) */
onprogress: function(id, receivedSize, totalSize) {
console.log('progress for id: ' + id);
console.log('received: ' + receivedSize + ", total: " + totalSize);
},
/* When the user pauses the download */
onpaused: function(id) {
console.log('Paused with id: ' + id);
},
/* When the user cancels the download */
oncanceled: function(id) {
console.log('Canceled with id: ' + id);
},
/* When the download is completed */
oncompleted: function(id, fullPath) {
console.log('Completed with id: ' + id + ', full path: ' + fullPath);
readJSON();
},
/* When the download fails */
onfailed: function(id, error) {
console.log('Failed with id: ' + id + ', error name: ' + error.name);
}
};
downloadId = tizen.download.start(downloadRequest, listener);
} }
/** /**
@ -388,8 +353,8 @@ var eventsTimeStamp = 0;
function renderEarth(date, minute, second) { function renderEarth(date, minute, second) {
var earthColor = "#0077BE"; earthColor = "#0077BE";
var earthDistance = document.body.clientWidth / 2 - 120; earthDistance = document.body.clientWidth / 2 - 120;
renderCircle(ctxContent, polToCart(earthDistance, minuteToAngle(minute + second / 60)), 10, earthColor); renderCircle(ctxContent, polToCart(earthDistance, minuteToAngle(minute + second / 60)), 10, earthColor);
} }
@ -421,7 +386,9 @@ var eventsTimeStamp = 0;
* @private * @private
*/ */
function drawWatchLayout() { function drawWatchLayout() {
var i, var grd,
angle,
i,
j; j;
// Clear canvas // Clear canvas
@ -475,35 +442,32 @@ var eventsTimeStamp = 0;
// Draw the minute needle // Draw the minute needle
renderEarth(ctxContent, minute, second); renderEarth(ctxContent, minute, second);
// renderNeedle(ctxContent, Math.PI * (((minute + second / 60) / 30) - 0.5), 0, 0.70, 3, "#454545");
// Draw the minute/hour circle
// renderCircle(ctxContent, center, 8, "#454545");
// Draw the second needle
// ctxContent.shadowOffsetX = 4;
// ctxContent.shadowOffsetY = 4;
// renderNeedle(ctxContent, Math.PI * ((second / 30) - 0.5), -0.10, 0.85, 1, "#c4c4c4");
// Draw the second circle
// ctxContent.shadowOffsetX = 0;
// ctxContent.shadowOffsetY = 0;
// renderCircle(ctxContent, center, 5, "#c4c4c4");
// Draw the center circle
// renderCircle(ctxContent, center, 2, "#454545");
// Draw the text for date
// renderText(ctxContent, date, center.x, center.y + (watchRadius * 0.5), 25, "#999999");
/* if no return from server yet */
if(events == null) if(events == null)
return; return;
/* if device not on server anymore */ thickness = 18;
if(events.kind == "not found") { edge = document.body.clientWidth / 2 - thickness / 2 - 2;
deviceFingerprint = null;
events = null;
deleteFile("devicefingerprint", function() {});
wait_time = SHORT_WAIT;
return;
}
/* if device not registered */
if(events.kind == "unregistered") {
wait_time = SHORT_WAIT;
if(deviceFingerprint === null) {
} else {
renderText(ctxContent, deviceFingerprint.deviceName, center.x, center.y, 20, "FF0000");
}
return;
}
console.log("switched to long wait");
wait_time = LONG_WAIT;
/* else: device registered and all events saved */
var thickness = 18;
var edge = document.body.clientWidth / 2 - thickness / 2 - 2;
for(var event in events.events){ for(var event in events.events){
var startedBeforeToday = false; var startedBeforeToday = false;
@ -557,11 +521,11 @@ var eventsTimeStamp = 0;
} }
function loopCalendar(offset_ms) { function updateCalendar(offset_ms) {
var d = new Date(); var d = new Date();
var currentTime = d.getTime(); var currentTime = d.getTime();
if(eventsTimeStamp + offset_ms < currentTime){ if(eventsTimeStamp + offset_ms < currentTime){
updateCalendar(); getJSON();
eventsTimeStamp = currentTime; eventsTimeStamp = currentTime;
} }
@ -611,7 +575,7 @@ var eventsTimeStamp = 0;
* @private * @private
*/ */
function init() { function init() {
// clearDownloads();
setDefaultVariables(); setDefaultVariables();
setDefaultEvents(); setDefaultEvents();
@ -622,7 +586,7 @@ var eventsTimeStamp = 0;
// Update the content of the watch every second // Update the content of the watch every second
setInterval(function() { setInterval(function() {
drawWatchContent(); drawWatchContent();
loopCalendar(wait_time); updateCalendar(5000); //60000 -> 10 minutes
}, 1000); }, 1000);
} }