123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119 |
- /*
- Copyright (c) 2013 Mapo developpers and contributors <mapo.tizen@gmail.com>
- This file is part of Mapo.
- This program is free software: you can redistribute it and/or modify
- it under the terms of the GNU General Public License as published by
- the Free Software Foundation, either version 3 of the License, or
- (at your option) any later version.
- This program is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- GNU General Public License for more details.
- You should have received a copy of the GNU General Public License
- along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
- /*
- * Application Global variables
- */
- // The map of the application
- var map;
- // The boolean which provide the connection state of the application
- var isOnline = false;
- /*
- * Recording Global Variable
- */
- // Directory where the recording document is placed
- var docDir;
- // Name of the recording document
- var doc;
- // The file where the records are placed
- var file;
- // Boolean which provide the information if a file has been recorded
- var fileRecorded = false;
- /*
- * Set Manager
- */
- /**
- * Modify the latitude value
- * @param lat : new latitude value
- */
- function setLat(lat) {
- if (document.getElementById("lat").value != lat) {
- document.getElementById("lat").value = lat;
- }
- }
- /**
- * Modify the longitude value
- * @param lon : new longitude value
- */
- function setLon(lon) {
- if (document.getElementById("lon").value != lon) {
- document.getElementById("lon").value = lon;
- }
- }
- /*
- * Link Manager
- */
- /**
- * Get the OpenStreetMap link with the corresponding latitude and longitude
- * @returns url
- */
- function getLink(provider) {
- var lat = $("#lat").val();
- var lon = $("#lon").val();
- var url;
- switch(provider)
- {
- case 'OSM' :
- url =
- "http://www.openstreetmap.org/?&zoom=10&layers=mapnik&lat=${lat}&lon=${lon}";
- break;
- case 'GM' :
- url = "http://maps.google.com/maps?&z=10&ll=${lat},${lon}";
- break;
- case 'NOKIA' :
- url = "http://maps.nokia.com/${lat},${lon},16,0,0,normal.day";
- break;
- default :
- url = "http://www.openstreetmap.org/?&zoom=10&layers=mapnik&lat=${lat}&lon=${lon}";
- break;
- }
- url = url.replace("${lon}", lon);
- url = url.replace("${lat}", lat);
- return url;
- }
- /**
- * Use the Internet Application Control to go to OSM link with the browser
- */
- function goToURL(provider) {
- if (isOnline) {
- var appControl = new tizen.ApplicationControl(
- "http://tizen.org/appcontrol/operation/view",
- getLink(provider), null);
- var appControlReplyCallback = {
- onsuccess : function(data) {
- for ( var i = 0; i < data.length; i++) {
- console.log("#" + i + " key:" + data[i].key);
- for ( var j = 0; j < data[i].value.length; j++) {
- console.log(" value#" + j + ":" + data[i].value[j]);
- }
- }
- },
- onfailure : function() {
- console.log('The launch application control failed');
- }
- }
- tizen.application.launchAppControl(appControl, null, function() {
- console.log("launch internet application control succeed");
- }, function(e) {
- console.log("launch internet application control failed. reason: "
- + e.message);
- }, appControlReplyCallback);
- } else {
- alert("Please connect your application online in the settings"
- + " if you want to open a browser")
- }
- }
- /**
- * update links
- */
- //function updateLinks() {
- // $('#OSMLink').attr('href', getOSMLink());
- //}
- /*
- * Map Manager
- */
- /**
- * get the size of the map (width, height) according to the dimension of the screen
- * @returns [ width, height ]
- */
- function getMapSize() {
- var viewHeight = $(window).height();
- var viewWidth = $(window).width();
- var header = $("div[data-role='header']:visible:visible");
- var footer = $("div[data-role='footer']:visible:visible");
- var navbar = $("div[data-role='navbar']:visible:visible");
- var content = $("div[data-role='content']:visible:visible");
- var contentHeight = viewHeight - header.outerHeight()
- - navbar.outerHeight() - footer.outerHeight();
- var contentWidth = viewWidth - 30;
- return [ contentWidth, contentHeight ];
- }
- /**
- * Modify the dimension of the map according to getMapSize()
- */
- function setMapSize() {
- var mapSize = getMapSize();
- $('#myMap').css("width", mapSize[0]);
- $('#myMap').css("height", mapSize[1]);
- }
- function initIcon(){
- var size = new OpenLayers.Size(21,25);
- var offset = new OpenLayers.Pixel(-(size.w/2), -size.h);
-
- return new OpenLayers.Icon('http://www.openlayers.org/dev/img/marker.png', size, offset);
- }
- function chargeCourse(data){
- log("chargeCourse data : "+data['dates'][0]);
- var icon = initIcon();
-
- log("tab lons = "+data['lons']);
- log("tab lats = "+data['lats']);
- log("tab dates = "+data['dates']);
-
- for(var i= 0; i<data['dates'].length; i++){
- var lon = parseFloat(data['lons'][i]);
- var lat = parseFloat(data['lats'][i]);
- var date = data['dates'][i];
- log("data['dates']["+i+"] = "+date);
- log("data['lons']["+i+"] = "+lon);
- log("data['lat']["+i+"] = "+lat);
- log("lat before : "+lat);
- log("lon before : "+lon);
- var lonlat = new OpenLayers.LonLat(lon,lat).transform('EPSG:4326', 'EPSG:3857');
- var mark = new OpenLayers.Marker(lonlat,icon);
- course.addMarker(mark);
- }
- map.addLayer(course);
- log("finito");
- }
- /**
- * Charge the OpenLayers map with different OpenStreetMap and Google maps' layers
- */
- function chargeMap() {
- var latCenter = $("#lat").val();
- var lonCenter = $("#lon").val();
- map = new OpenLayers.Map('myMap', {
- projection : 'EPSG:3857',
- layers : [ new OpenLayers.Layer.OSM("OpenStreetMap"),
- new OpenLayers.Layer.Google("Google Streets",
- {numZoomLevels:20}),
- new OpenLayers.Layer.Google("Google Physical",
- {type : google.maps.MapTypeId.TERRAIN}),
- new OpenLayers.Layer.Google("Google Hybrid",
- {type : google.maps.MapTypeId.HYBRID,numZoomLevels : 20}),
- new OpenLayers.Layer.Google("Google Satellite",
- {type : google.maps.MapTypeId.SATELLITE,numZoomLevels : 22})
- ],
- center : new OpenLayers.LonLat(lonCenter, latCenter).transform('EPSG:4326', 'EPSG:3857'),
- zoom : 7
- });
- map.addControl(new OpenLayers.Control.LayerSwitcher());
-
- if(fileRecorded){ // TODO : Data vide : data([0])?.length!=0 or fileRecorded
-
- //var course = new OpenLayers.Layer.Markers( "Latest recorded course" );
- //map.removeLayer(course);
-
- var markers = map.getLayersByName("Last recorded course");
- if(markers.length!=0){
- var previousCourse = markers[0];
- log("course = "+previousCourse.name);
- previousCourse.destroy();
- }
-
- course = new OpenLayers.Layer.Markers("Last recorded course");
- //readFile().done(chargeCourse);
- readFile();
- // setTimeout(
- //// log("result 0 : "+result[0]);
- //// log("result 1 : "+result[1]);
- // chargeCourse
- // , 5000);
- }
- }
- /*
- * Coordinates transformation Manager
- */
- /**
- * Transform the latitude/longitude into DMS coordinate
- * @param lat : latitude
- * @param lon : longitude
- * @returns dms : DMS coordinate
- */
- function fromLatLonToDMS(lat, lon) {
- var latitude = lat;
- var longitude = lon;
- var dms="";
- var NS="";
- if (latitude >= 0) {
- NS += "N";
- } else {
- latitude = -latitude;
- NS += "S";
- }
- var dLat = parseInt(latitude, 10);
- var mLat = parseInt((latitude - dLat) * 60, 10);
- var sLat = parseInt((latitude-dLat)*60*60 - 60*mLat, 10);
- dms += NS+" "+dLat+"° "+mLat+"' "+sLat+"\" ";
- var EW="";
- if (longitude >= 0) {
- EW += "E";
- } else {
- EW += "W";
- longitude = -longitude;
- }
- var dLon = parseInt(longitude, 10);
- var mLon = parseInt((longitude - dLon) * 60, 10);
- var sLon = parseInt((longitude-dLon)*60*60 - 60*mLon, 10);
- dms += EW+" "+dLon+"° "+mLon+"' "+sLon+"\"";
- // text = NS+" "+d+"° "+m+"' "+s+"\" "+EW+" "+d+"° "+m+"' "+s+"\"";
- return dms;
- }
- /**
- * Transform the DMS into latitude/longitude coordinates
- * @param dms : DMS coordinate
- * @returns [ lat, lon ] : latitude and longitude coordinates
- */
- function fromDMSToLatLon(dms){
- var re =
- /^([NS])\s*([0-9.\-]+)\s*°\s*([0-9.\-]+)\s*\'\s*([0-9.\-]+)\s*\"\s*([EW])\s*([0-9.\-]+)\s*°\s*([0-9.\-]+)\s*\'\s*([0-9.\-]+)\s*\"\s*$/;
- if(re.test(dms)){
- var lat = (parseFloat(RegExp.$2)+parseFloat(RegExp.$3)/60+parseFloat(RegExp.$4)/(60*60)).toFixed(6);
- if(RegExp.$1=='S'){
- lat=-lat;
- }
- lat = lat.toString();
- setLat(lat);
- var lon = (parseFloat(RegExp.$6)+parseFloat(RegExp.$7)/60+parseFloat(RegExp.$8)/(60*60)).toFixed(6);
- if(RegExp.$5=='W'){
- lon=-lon;
- }
- lon = lon.toString();
- setLon(lon);
- }
- }
- /*
- * Coordinates Manager
- */
- /**
- * Modify the DMS value using the transformation's function fromLatLonToDMS
- */
- function setDMS() {
- $('#dms').val(fromLatLonToDMS($("#lat").val(), $("#lon").val()));
- }
- /**
- * Modify the latitude and longitude values using the transformation's function fromDMSToLatLon
- */
- function setLatLon(){
- var coordinates = fromDMSToLatLon($('#dms').val());
- }
- /**
- * Validate or not the DMS coordinate according to the form of the regular expression
- * @param dms : DMS coordinates
- * @returns Validation
- */
- function validateDMS(dms){
- var re =
- /^([NS])\s*([0-9.\-]+)\s*°\s*([0-9.\-]+)\s*\'\s*([0-9.\-]+)\s*\"\s*([EW])\s*([0-9.\-]+)\s*°\s*([0-9.\-]+)\s*\'\s*([0-9.\-]+)\s*\"\s*$/;
- if (re.test(dms)) {
- return true;
- } else {
- return false;
- }
- }
- /**
- * Validate or not the latitudes and longitudes coordinates according to the form of the regular expression
- * @param latOrLon
- * @returns Validation
- */
- function validateLatOrLon(latOrLon){
- if(/^[0-9.\-]+$/.test(latOrLon)){
- return true;
- } else {
- return false;
- }
- }
- /**
- * Function called when the latitude value changes
- * Calculate the new DMS coordinate
- */
- function changeLat(){
- var lat = $('#lat').val();
- if(validateLatOrLon(lat)){
- $('#lat').val(parseFloat($('#lat').val()).toFixed(6).toString());
- setDMS();
- storeData();
- } else {
- alert("Latitude coordinate invalid : "+lat);
- initData();
- }
- }
- /**
- * Function called when the longitude value changes
- * Calculate the new DMS coordinate
- */
- function changeLon(){
- var lon = $('#lon').val();
- if(validateLatOrLon(lon)){
- $('#lon').val(parseFloat($('#lon').val()).toFixed(6).toString());
- setDMS();
- storeData();
- } else {
- alert("Lontitude coordinate invalid : "+lon);
- initData();
- }
- }
- /**
- * Function called when the DMS value changes
- * Calculate the new latitude and longitude coordinates
- */
- function changeDMS(){
- var dms = $('#dms').val();
- if(validateDMS(dms)){
- setLatLon();
- storeData();
- } else {
- alert("DMS coordinate invalid : "+dms);
- initData();
- }
- }
- /*
- * Location Manager
- */
- /**
- * Function called when the getCurrentPosition succeded
- * Refresh the application
- */
- function handleShowLocation(position) {
- var lat = position.coords.latitude.toFixed(6).toString();
- var lon = position.coords.longitude.toFixed(6).toString();
- setLat(lat);
- setLon(lon);
- refresh();
- }
- /**
- * Function called when the getCurrentPosition failed
- * Show the error
- * @param error
- */
- function handleErrorLocation(error) {
- var errorInfo = document.getElementById("locationInfo");
- switch (error.code) {
- case error.PERMISSION_DENIED:
- errorInfo.innerHTML = "User denied the request for Geolocation.";
- break;
- case error.POSITION_UNAVAILABLE:
- errorInfo.innerHTML = "Location information is unavailable.";
- break;
- case error.TIMEOUT:
- errorInfo.innerHTML = "The request to get user location timed out.";
- break;
- case error.UNKNOWN_ERROR:
- errorInfo.innerHTML = "An unknown error occurred.";
- break;
- }
- }
- /**
- * Get the current position according to the GPS' device
- */
- function getLocation() {
- if (navigator.geolocation ) {
- navigator.geolocation.getCurrentPosition(handleShowLocation, handleErrorLocation,
- {enableHighAccuracy : $('#switchEnergy').val() == 'off'});
- } else {
- document.getElementById("locationInfo").innerHTML =
- "Geolocation is not supported by this browser.";
- }
- }
- /*
- * Recording manager
- */
- /**
- * Function called when the file resolution succeded
- * Create the recording file in the corresponding directory
- * @param dir : directory where the file is placed
- */
- function handleResolveSuccess(dir) {
- docDir = dir;
- var date = new Date();
- var dateFile = date.getDate().toString()+"."+date.getMonth().toString()+"."+date.getFullYear().toString()
- +"-"+date.getHours().toString()+":"+date.getMinutes().toString()+":"+date.getSeconds().toString();
- //log(dateFile);
- doc = 'MAPO_' + dateFile + ".txt";
- docDir.createFile(doc);
- $('#locationInfo').html("Course recording in the file:<br/>" + doc);
- }
- /**
- * Function called when the file resolution failed
- * Show the error
- * @param e : error
- */
- function handleResolveError(e) {
- console.log('message: ' + e.message);
- }
- /**
- * Resolve the file
- */
- function resolveFile() {
- try {
- file = docDir.resolve(doc);
- } catch (exc) {
- console.log('Could not resolve file: '+exc.message);
- // Stop in case of any errors
- return;
- }
- }
- /**
- * Function called when the record failed, writing or reading
- * Show the error
- * @param e : error
- */
- function handleRecordError(e) {
- var msg = '';
- switch (e.code) {
- case FileError.QUOTA_EXCEEDED_ERR:
- msg = 'QUOTA_EXCEEDED_ERR';
- break;
- case FileError.NOT_FOUND_ERR:
- msg = 'NOT_FOUND_ERR';
- break;
- case FileError.SECURITY_ERR:
- msg = 'SECURITY_ERR';
- break;
- case FileError.INVALID_MODIFICATION_ERR:
- msg = 'INVALID_MODIFICATION_ERR';
- break;
- case FileError.INVALID_STATE_ERR:
- msg = 'INVALID_STATE_ERR';
- break;
- default:
- msg = 'Unknown Error';
- break;
- }
- console.log('Error: ' + msg);
- }
- /**
- * Function called when the writing succeeded
- * Add the position at the end of the file
- * @param fileStream : Stream to write
- */
- function writeToStream(fileStream) {
- try {
- var date = new Date();
-
- var dateRecord = date.getDate().toString()+"."+date.getMonth().toString()+"."+date.getFullYear().toString()
- +"-"+date.getHours().toString()+":"+date.getMinutes().toString()+":"+date.getSeconds().toString();
-
- // var dateRecord = date.getDate().toString()+"."+date.getMonth().toString()+"."+date.getFullYear().toString()
- // +"-"+date.getHours().toString()+":"+date.getMinutes().toString()+":"+date.getSeconds().toString();
- var lat = $("#lat").val();
- var lon = $("#lon").val();
- //fileStream.write(dateRecord + ";lat:" + lat + ";lon:" + lon + "\r");
-
- fileStream.write("\r"+dateRecord+";"+lat+";"+lon);
- fileStream.close();
- } catch (exc) {
- console.log('Could not write to file: ' + exc.message);
- }
- }
- /**
- * Try to write the record into the file
- */
- function writeRecord() {
- try {
- file.openStream(
- // open for appending
- 'a',
- // success callback - add textarea's contents
- writeToStream,
- // error callback
- handleRecordError);
- } catch (exc) {
- console.log('Could not write to file: ' + exc.message);
- }
- }
- /**
- * Function called when the reading succeded
- * @param fileStream : Stream to read
- */
- function readFromStream(fileStream) {
- try {
- console.log('File size: ' + file.fileSize);
- var contents = fileStream.read(fileStream.bytesAvailable);
- fileStream.close();
- console.log('file contents: ' + contents);
- } catch (exc) {
- console.log('Could not read from file: ' + exc.message);
- }
- }
- /**
- * Try to read the file
- */
- function readRecord() {
- try {
- file.openStream(
- // open for reading
- 'r',
- // success callback - add textarea's contents
- readFromStream,
- // error callback
- handleRecordError);
- } catch (exc) {
- console.log('Could not write to file: ' + exc.message);
- }
- }
- /**
- * Function called when getPosition got successfully the position
- * Resolve the file, write and read the records
- * @param position
- */
- function handleRecordPosition(position) {
- if ($('#switchRecord').val() == "start") {
- handleShowLocation(position);
- resolveFile();
- writeRecord();
- readRecord();
- }
- }
- /**
- * Function called when getPosition failed to get the position
- * Show the error
- * @param error
- */
- function handleErrorPosition(error) {
- $('#switchRecord').val('stop').slider('refresh');
- var errorInfo = document.getElementById("locationInfo");
- switch (error.code) {
- case error.PERMISSION_DENIED:
- errorInfo.innerHTML = "User denied the request for Geolocation.";
- break;
- case error.POSITION_UNAVAILABLE:
- errorInfo.innerHTML = "Location information is unavailable.";
- break;
- case error.TIMEOUT:
- errorInfo.innerHTML = "The request to get user location timed out.";
- break;
- case error.UNKNOWN_ERROR:
- errorInfo.innerHTML = "An unknown error occurred.";
- break;
- }
- }
- /**
- * Get the recording position
- */
- function getPosition() {
- navigator.geolocation.getCurrentPosition(handleRecordPosition, handleErrorPosition,
- {enableHighAccuracy : $('#switchEnergy').val() == 'off'});
- }
- /**
- * Function called when the record of a course has been launched
- * Record the position whith a timeout predefined in the settings
- */
- function record() {
- if (navigator.geolocation) {
- var intervalID;
- if ($('#switchRecord').val() == "start") {
-
- tizen.filesystem.resolve('documents', handleResolveSuccess,
- handleResolveError, 'rw');
- getPosition();
- intervalID = setInterval(getPosition, $('#selectorTimeout').val() * 1000);
- } else {
- clearInterval(intervalID);
- $('#locationInfo').html("Course recorded in the file:<br/>" + doc);
- fileRecorded=true;
- }
- } else {
- document.getElementById("locationInfo").innerHTML =
- "Geolocation is not supported.";
- }
- }
- /**
- * Extract from a file composed by the last recorded course all the dates, latitudes and lontitudes
- * and place its in data
- */
- function readFile() {
- //var deferred = $.Deferred();
- try {
- file = docDir.resolve(doc);
- console.log('File size: ' + file.fileSize);
- } catch (exceptionResolve) {
- console.log('Could not resolve file: ' + exceptionResolve.message);
- // Stop in case of any errors
- return;
- }
- try {
- file.readAsText(
- // success callback - display the contents of the file
- function(contents) {
-
- //console.log('File contents:' + contents);
- var lines = contents.split("\r");
- var re = /^([0-9.:\-]+);([0-9.\-]+);([0-9.\-]+)$/;
-
- var data = [];
-
- var dates = [];
- var lats = [];
- var lons = [];
- var iData = 0;
-
- for(var iLines=0; iLines<lines.length; iLines++){
-
- if(re.test(lines[iLines])) {
- log("line "+iLines+": "+lines[iLines]);
- var parts = lines[iLines].split(";");
- for(var iParts=0; iParts<parts.length; iParts++){
- log(" part "+iParts+": "+parts[iParts]);
- if((iParts%3)==0){
- dates[iData]=parts[iParts];
- log(" date "+iData+": "+dates[iData]);
- } else if((iParts%3)==1) {
- lats[iData]=parts[iParts];
- log(" lat "+iData+": "+lats[iData]);
- } else {
- lons[iData]=parts[iParts];
- log(" lon "+iData+": "+lons[iData]);
- }
- }
- iData++;
- }
- }
- data['dates'] = dates;
- data['lats'] = lats;
- data['lons'] = lons;
-
- log("readfile data"+data['dates'][0]);
- chargeCourse(data);
- },
- // error callback
- handleRecordError
- );
- } catch (exceptionRead) {
- console.log("readAsText() exception:" + exceptionRead.message);
- }
- //deferred.resolve();
- //return deferred; // [data, referred]
- }
- /*
- * Social Manager
- */
- /**
- * Use the Email Application Control to share a position by Email
- */
- function sendEmail() {
- if (isOnline) {
- var message =
- "This is the position I want to show you from Mapo:" +
- "\nLatitute="+$("#lat").val()+
- "\nLongitude = "+$("#lon").val()+
- "\nIf you prefer in DMS, here it is: "+$('#dms').val()+
- "\nYou can see this position on OpenStreetMap: "+getLink('OSM')+
- "\nConnect you on Mapo for more details!";
- var appControl = new tizen.ApplicationControl(
- "http://tizen.org/appcontrol/operation/send", // compose or send
- "mailto:", null, null,
- [
- new tizen.ApplicationControlData(
- "http://tizen.org/appcontrol/data/subject", [ "Mapo" ]),
- new tizen.ApplicationControlData(
- "http://tizen.org/appcontrol/data/text", [ message ]),
- new tizen.ApplicationControlData(
- "http://tizen.org/appcontrol/data/to",
- [ "mapo.tizen@gmail.com" ])
- // TODO tizen.mapo@spamgourmet.com
- // new tizen.ApplicationControlData(
- // "http://tizen.org/appcontrol/data/path",
- // ["images/image1.jpg"])
- ]);
- tizen.application.launchAppControl(appControl, null,
- function() {console.log("launch service succeeded");},
- function(e) {
- console.log("launch service failed. Reason: " + e.name);});
- } else {
- alert("Please connect your application online in the settings"
- + " if you want to send an email");
- }
- }
- //function sendBluetooth(){
- // var appControl = new tizen.ApplicationControl(
- // "http://tizen.org/appcontrol/operation/pick",
- // null,
- // "image/jpeg",
- // null);
- //
- // tizen.application.launchAppControl(appControl, null,
- // function() {console.log("launch service succeeded");},
- // function(e) {
- // console.log("launch service failed. Reason: " + e.name);});
-
- // var appControlReplyCallback = {
- // // callee sent a reply
- // onsuccess: function(data) {
- // for (var i = 0; i < data.length; i++) {
- // if (data[i].key == "http://tizen.org/appcontrol/data/selected") {
- // console.log('Selected image is ' + data[i].value[0]);
- // }
- // }
- // },
- // // callee returned failure
- // onfailure: function() {
- // console.log('The launch application control failed');
- // }
- // }
- //
- // tizen.application.launchAppControl(
- // appControl,
- // null,
- // function() {console.log("launch application control succeed"); },
- // function(e) {console.log("launch application control failed. reason: "+e.message); },
- // appControlReplyCallback );
- // tizen.application.launch("tizen.bluetooth",
- // function(){console.log("launch service succeeded");},
- // function(e){console.log("launch service failed. Reason: " + e.name);});
- // var appControl = new
- // tizen.ApplicationControl("http://tizen.org/appcontrol/operation/bluetooth/pick",
- // "Phone/Images/image16.jpg");
- // tizen.application.launchAppControl(appControl, null,
- // function(){console.log("launch service succeeded");},
- // function(e){console.log("launch service failed. Reason: " + e.name);});
- //}
- function sendMessage(){
- var message =
- "This is the position I want to show you from Mapo:" +
- "\nLatitute="+$("#lat").val()+
- "\nLongitude = "+$("#lon").val()+
- "\nIf you prefer in DMS, here it is: "+$('#dms').val()+
- "\nYou can see this position on OpenStreetMap: "+getLink('OSM')+
- "\nConnect you on Mapo for more details!";
- var appControl = new tizen.ApplicationControl(
- "http://tizen.org/appcontrol/operation/compose",
- "tel:9988776655", // tizen.smsmessages
- null,
- null,
- [
- new tizen.ApplicationControlData("http://tizen.org/appcontrol/data/messagetype",["sms"]),
- new tizen.ApplicationControlData("http://tizen.org/appcontrol/data/text",[message]),
- new tizen.ApplicationControlData("http://tizen.org/appcontrol/data/to", ["2345678900"]),
- ]
- );
- tizen.application.launchAppControl(appControl, null,
- function() {console.log("launch service succeeded");},
- function(e) {console.log("launch service failed. Reason: "+e);});
- }
- function call(){
- var appControl = new tizen.ApplicationControl("http://tizen.org/appcontrol/operation/dial","tel:9988776655", null);
- tizen.application.launchAppControl(appControl,null,
- function(){console.log("launch appControl succeeded");},
- function(e){console.log("launch appControl failed. Reason: " + e.name);},
- null);
- }
- /*
- * Contact Manager
- */
- /**
- * Use the Contact Application Control to add a contact with the corresponding position
- */
- function createContact() {
- var appControl = new tizen.ApplicationControl(
- "http://tizen.org/appcontrol/operation/social/add",
- null,
- null,
- //TODO
- // null for the emulator
- // "vnd.tizen.item.type/vnd.tizen.contact" for the device
- "vnd.tizen.item.type/vnd.tizen.contact",
- [
- new tizen.ApplicationControlData(
- "http://tizen.org/appcontrol/data/social/item_type",
- [ "contact" ]),
- new tizen.ApplicationControlData(
- "http://tizen.org/appcontrol/data/social/email",
- [ "mapo.tizen+"+
- fromLatLonToDMS($('#lat').val(), $('#lon').val()) + "@gmail.com" ]),
- new tizen.ApplicationControlData(
- "http://tizen.org/appcontrol/data/social/url",
- [ getLink('OSM') ])
- ]);
- tizen.application.launchAppControl(appControl, null,
- function() {console.log("launch service succeeded");},
- function(e) {console.log(
- "launch service failed. Reason: " +e.name+e);});
- }
- /*
- * Calendar Manager
- */
- /**
- * Use the Contact Application Control to add an event in the calendar with the corresponding date
- */
- function createCalendarEvent(){
- var appControl = new tizen.ApplicationControl(
- "http://tizen.org/appcontrol/operation/social/edit",
- null,
- null,
- "tizen.calendar",
- [
- new tizen.ApplicationControlData(
- "http://tizen.org/appcontrol/data/social/item_type",
- [ "event" ])
- ]);
- tizen.application.launchAppControl(appControl, null,
- function() {console.log("launch service succeeded");},
- function(e) {console.log(
- "launch service failed. Reason: " +e.name+e);});
- }
- /*
- * Storage Manager
- */
- /**
- * Store the coordinates values in the local storage
- */
- function storeData(){
- localStorage.setItem('lat', $('#lat').val());
- localStorage.setItem('lon', $('#lon').val());
- localStorage.setItem('dms', $('#dms').val());
- }
- /**
- * Store the settings values in the local storage
- */
- function storeSettings() {
- localStorage.setItem('connection', $('#switchOnline').val());
- localStorage.setItem('energySaving', $('#switchEnergy').val());
- localStorage.setItem('timeout', $('#selectorTimeout').val());
- }
- function store() {
- var r = $.Deferred();
- storeData();
- storeSettings();
- for ( var i = 0; i < localStorage.length; i++) {
- log(i+" -- "+localStorage.key(i)+" : "+localStorage.getItem(localStorage.key(i)));
- }
- r.resolve();
- return r;
- }
- /*
- * Settings Manager
- */
- /**
- * Function called when the online swith is activated or desactived
- * Verify if the the device has a connection before connecting the application
- */
- function switchOnline() {
- if (!isOnline) {
- if (navigator.onLine) {
- isOnline = true;
- } else {
- $('#switchOnline').val('offline');
- $('#switchOnline').slider('refresh');
- alert("Can not connect");
- }
- } else {
- isOnline = false;
- }
- refresh();
- }
- /*
- * General Manager
- */
- /**
- * Refresh all the application according to the coordinates and the settings
- */
- function refresh() {
- log("{refresh");
- if (isOnline && !navigator.onLine) {
- $('#switchOnline').val('offline').slider('refresh');
- isOnline = false;
- alert("Connection lost");
- }
- //setDMS();
- $('#myMap').empty();
- log("isOnline = "+isOnline);
- if (isOnline) {
- setMapSize();
- chargeMap();
- } else {
- $('#myMap').html(
- "<p align='center'>" +
- "Please connect your application online in the settings" +
- " if you want to charge the map</p>");
- }
- log("refresh}");
- }
- /**
- * Quit the application
- */
- function exit() {
- tizen.application.getCurrentApplication().exit();
- }
- /**
- * Store the data before quitting the application
- */
- function quit() {
- log("{exit")
- store().done(exit);
- log("exit}");
- }
- /*
- * Initialization Manager
- */
- /**
- * Recover in the local storage the coordinates values from the preceding use
- */
- function initData(){
- if (localStorage.getItem('lat') != null) {
- $('#lat').val(localStorage.getItem('lat'));
- }
- if (localStorage.getItem('lon') != null) {
- $('#lon').val(localStorage.getItem('lon'));
- }
- if (localStorage.getItem('dms') != null) {
- $('#dms').val(localStorage.getItem('dms'));
- }
- storeData();
- }
- /**
- * Recover in the local storage the setting values from the preceding use
- */
- function initSettings() {
- if (localStorage.getItem('connection') == 'online') {
- $('#switchOnline').val(localStorage.getItem('connection'));
- isOnline = true;
- }
- if (localStorage.getItem('energySaving') != null) {
- $('#switchEnergy').val(localStorage.getItem('energySaving'));
- }
- if (localStorage.getItem('timeout') != null) {
- $('#selectorTimeout').attr('value', localStorage.getItem('timeout'));
- }
- storeSettings();
- }
- /**
- * Initialize the data from the preceding use
- */
- function init(){
- initData();
- initSettings();
- refresh();
- }
- /*
- * Schedule
- */
- /**
- * Show a message
- * @param message
- */
- function log(message) {
- if (!false) console.log("# "+message);
- }
- /**
- * Use the tactil swipe to change between every pages
- */
- function swipePage() {
- $('div.ui-page').live("swipeleft",
- function() {
- var nextpage = $(this).next('div[data-role="page"]');
- // swipe using id of next page if exists
- if (nextpage.length > 0) {
- $.mobile.changePage(nextpage,
- {transition : "slide", reverse : false});
- }});
- $('div.ui-page').live("swiperight",
- function() {
- var prevpage = $(this).prev('div[data-role="page"]');
- // swipe using id of next page if exists
- if (prevpage.length > 0) {
- $.mobile.changePage(prevpage,
- {transition : "slide", reverse : true});
- }});
- }
|