Compare commits
No commits in common. "60a337ecbc5ac2d01ea25d55ea1a04fd22604d00" and "86c0c8a23fa4c2356609fb620698d658ea6e1080" have entirely different histories.
60a337ecbc
...
86c0c8a23f
Binary file not shown.
202
js/app.js
202
js/app.js
@ -17,10 +17,7 @@
|
||||
|
||||
/* 'downloads' for debugging,
|
||||
* 'wgt-private' for any release */
|
||||
var STORAGE_SPACE = "wgt-private";
|
||||
var SHORT_WAIT = 10000;
|
||||
var LONG_WAIT = 600000;
|
||||
var wait_time = LONG_WAIT;
|
||||
var STORAGE_SPACE = "downloads";
|
||||
var events = null;
|
||||
var deviceFingerprint = null;
|
||||
var eventsTimeStamp = 0;
|
||||
@ -33,73 +30,9 @@ var eventsTimeStamp = 0;
|
||||
center,
|
||||
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) {
|
||||
console.log("searching for File");
|
||||
|
||||
/* successful resolution of wgt-private */
|
||||
function onsuccess(dir){
|
||||
var dirfile = null;
|
||||
@ -145,17 +78,20 @@ var eventsTimeStamp = 0;
|
||||
*/
|
||||
|
||||
getJsonFile("calendarevents", function(eventlist) {events = eventlist;});
|
||||
console.log(events);
|
||||
}
|
||||
|
||||
function getNewFingerprintFromServer() {
|
||||
console.log("fingerprintfromserver");
|
||||
getFileFromServer("/devicefingerprint.json", function() {
|
||||
console.log("getting device fingerprint from server")
|
||||
console.log("1");
|
||||
getJsonFile("devicefingerprint", function(df) {devicefingerprint = df; console.log(devicefingerprint)});
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
function getDeviceFingerprint() {
|
||||
console.log("getfingerprint");
|
||||
// check if device id set already as global, if it is return
|
||||
if(deviceFingerprint != null)
|
||||
return;
|
||||
@ -174,7 +110,6 @@ var eventsTimeStamp = 0;
|
||||
}
|
||||
|
||||
function getFileFromServer(route, callback) {
|
||||
console.log("getting file");
|
||||
var server = "https://longitudecalendar.com/"
|
||||
var downloadRequest = new tizen.DownloadRequest(server + route, STORAGE_SPACE);
|
||||
tizen.systeminfo.getPropertyValue('NETWORK', function(networkInfo) {
|
||||
@ -211,28 +146,58 @@ var eventsTimeStamp = 0;
|
||||
console.log('Failed with id: ' + id + ', error name: ' + error.name);
|
||||
}
|
||||
};
|
||||
tizen.download.start(downloadRequest, listener);
|
||||
downloadId = tizen.download.start(downloadRequest, listener);
|
||||
}
|
||||
|
||||
function updateCalendar() {
|
||||
function getJSON() {
|
||||
|
||||
if(deviceFingerprint == null) {
|
||||
console.log("no fingerprint, loading from file or server");
|
||||
getDeviceFingerprint();
|
||||
wait_time = SHORT_WAIT;
|
||||
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;
|
||||
|
||||
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) {
|
||||
|
||||
var earthColor = "#0077BE";
|
||||
var earthDistance = document.body.clientWidth / 2 - 120;
|
||||
earthColor = "#0077BE";
|
||||
earthDistance = document.body.clientWidth / 2 - 120;
|
||||
renderCircle(ctxContent, polToCart(earthDistance, minuteToAngle(minute + second / 60)), 10, earthColor);
|
||||
}
|
||||
|
||||
@ -421,7 +386,9 @@ var eventsTimeStamp = 0;
|
||||
* @private
|
||||
*/
|
||||
function drawWatchLayout() {
|
||||
var i,
|
||||
var grd,
|
||||
angle,
|
||||
i,
|
||||
j;
|
||||
|
||||
// Clear canvas
|
||||
@ -475,35 +442,32 @@ var eventsTimeStamp = 0;
|
||||
// Draw the minute needle
|
||||
|
||||
renderEarth(ctxContent, minute, second);
|
||||
|
||||
/* if no return from server yet */
|
||||
// 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(events == null)
|
||||
return;
|
||||
|
||||
/* if device not on server anymore */
|
||||
if(events.kind == "not found") {
|
||||
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;
|
||||
|
||||
thickness = 18;
|
||||
edge = document.body.clientWidth / 2 - thickness / 2 - 2;
|
||||
|
||||
for(var event in events.events){
|
||||
var startedBeforeToday = false;
|
||||
@ -557,11 +521,11 @@ var eventsTimeStamp = 0;
|
||||
|
||||
}
|
||||
|
||||
function loopCalendar(offset_ms) {
|
||||
function updateCalendar(offset_ms) {
|
||||
var d = new Date();
|
||||
var currentTime = d.getTime();
|
||||
if(eventsTimeStamp + offset_ms < currentTime){
|
||||
updateCalendar();
|
||||
getJSON();
|
||||
eventsTimeStamp = currentTime;
|
||||
}
|
||||
|
||||
@ -611,7 +575,7 @@ var eventsTimeStamp = 0;
|
||||
* @private
|
||||
*/
|
||||
function init() {
|
||||
// clearDownloads();
|
||||
|
||||
setDefaultVariables();
|
||||
setDefaultEvents();
|
||||
|
||||
@ -622,7 +586,7 @@ var eventsTimeStamp = 0;
|
||||
// Update the content of the watch every second
|
||||
setInterval(function() {
|
||||
drawWatchContent();
|
||||
loopCalendar(wait_time);
|
||||
updateCalendar(5000); //60000 -> 10 minutes
|
||||
}, 1000);
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user