summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGubolin <gubolin@fantasymail.de>2014-09-07 12:44:00 +0200
committerGubolin <gubolin@fantasymail.de>2014-09-07 12:44:00 +0200
commitf8b3ef7c27f09b6638b8d024512e8289b844e651 (patch)
tree9c3a640b49654d5f010b0ad2fc614ff85ec7252a
parent8e14ae00f1ec4d60727702df4265bf142856cebc (diff)
parent667aa5a56564d07c05182eeae7bba7567710a844 (diff)
downloadsnap-f8b3ef7c27f09b6638b8d024512e8289b844e651.tar.gz
snap-f8b3ef7c27f09b6638b8d024512e8289b844e651.zip
Merge branch 'location' into mobileapp
-rw-r--r--blocks.js19
-rw-r--r--gui.js3
-rwxr-xr-xmobile.sh1
-rw-r--r--objects.js16
-rw-r--r--threads.js72
5 files changed, 110 insertions, 1 deletions
diff --git a/blocks.js b/blocks.js
index 5f9bb29..735d36b 100644
--- a/blocks.js
+++ b/blocks.js
@@ -844,6 +844,25 @@ SyntaxElementMorph.prototype.labelPart = function (spec) {
);
part.setContents(['date']);
break;
+ case '%locations':
+ part = new InputSlotMorph(
+ null, // text
+ false, // non-numeric
+ {
+ 'all' : ['all'],
+ 'country' : ['country'],
+ 'state' : ['state'],
+ 'state district' : ['state district'],
+ 'suburb' : ['suburb'],
+ 'city' : ['city'],
+ 'road' : ['road'],
+ 'house number' : ['house number'],
+ 'licence': ['licence']
+ },
+ true // read-only
+ );
+ part.setContents(['all']);
+ break;
case '%delim':
part = new InputSlotMorph(
null, // text
diff --git a/gui.js b/gui.js
index 6af9137..4c9ee00 100644
--- a/gui.js
+++ b/gui.js
@@ -185,7 +185,7 @@ IDE_Morph.prototype.init = function (isAutoFill) {
MorphicPreferences.globalFontFamily = 'Helvetica, Arial';
// restore saved user preferences
- this.userLanguage = null; // user language preference for startup
+ this.userLanguage = null;
this.applySavedSettings();
// additional properties:
@@ -3417,6 +3417,7 @@ IDE_Morph.prototype.setLanguage = function (lang, callback) {
if (lang === 'en') {
return this.reflectLanguage('en', callback);
}
+ myself.userLanguage = lang;
translation = document.createElement('script');
translation.id = 'language';
translation.onload = function () {
diff --git a/mobile.sh b/mobile.sh
index cd41a86..656b7dc 100755
--- a/mobile.sh
+++ b/mobile.sh
@@ -17,4 +17,5 @@ cordova plugin add org.apache.cordova.plugin.softkeyboard
cordova plugin add org.apache.cordova.vibration
cordova plugin add org.apache.cordova.device-motion
cordova plugin add org.apache.cordova.device-orientation
+cordova plugin add org.apache.cordova.geolocation
cordova build android
diff --git a/objects.js b/objects.js
index 0913357..49fafb5 100644
--- a/objects.js
+++ b/objects.js
@@ -903,6 +903,16 @@ SpriteMorph.prototype.initBlocks = function () {
category: 'sensing',
spec: 'current acceleration along the z axes'
},
+ reportLanguage: {
+ type: 'reporter',
+ category: 'sensing',
+ spec: 'language'
+ },
+ reportLocation: {
+ type: 'reporter',
+ category: 'sensing',
+ spec: 'location %locations'
+ },
// Operators
reifyScript: {
@@ -1910,6 +1920,9 @@ SpriteMorph.prototype.blockTemplates = function (category) {
blocks.push('-');
blocks.push(block('reportDate'));
blocks.push('-');
+ blocks.push(block('reportLanguage'));
+ blocks.push(block('reportLocation'));
+ blocks.push('-');
blocks.push(block('doVibrate'));
blocks.push('-');
blocks.push(block('reportCompassHeading'));
@@ -5027,6 +5040,9 @@ StageMorph.prototype.blockTemplates = function (category) {
blocks.push('-');
blocks.push(block('reportDate'));
blocks.push('-');
+ blocks.push(block('reportLanguage'));
+ blocks.push(block('reportLocation'));
+ blocks.push('-');
blocks.push(block('doVibrate'));
blocks.push('-');
blocks.push(block('reportCompassHeading'));
diff --git a/threads.js b/threads.js
index 72a694f..3e50686 100644
--- a/threads.js
+++ b/threads.js
@@ -2572,6 +2572,78 @@ Process.prototype.reportTimer = function () {
return 0;
};
+Process.prototype.reportLanguage = function () {
+ var ide = this.homeContext.receiver.parentThatIsA(IDE_Morph);
+ if (ide) {
+ var lang = ide.userLanguage;
+ if (lang) {
+ return lang;
+ }
+ }
+ return 'en';
+};
+
+Process.prototype.reportLocation = function (name) {
+ var myself = this;
+
+ if (!myself.context.jsonpScript) {
+ if (!navigator.geolocation) {
+ myself.handleError({name: 'Location',
+ message: 'navigator.geolocation is not supported'});
+ }
+ window.OSM_JSONP_Callback = function (data) {
+ myself.context.json = data;
+ window.OSM_JSONP_Callback = undefined;
+ };
+ myself.context.jsonpScript = document.createElement('script');
+
+ navigator.geolocation.getCurrentPosition(
+ function (pos) {
+ var crd = pos.coords;
+
+ myself.context.jsonpScript.src =
+ 'https://nominatim.openstreetmap.org/reverse'
+ + '?format=json&json_callback=OSM_JSONP_Callback'
+ + '&zoom=18&addressdetails=1'
+ + '&lat='
+ + crd.latitude
+ + '&lon='
+ + crd.longitude;
+ document.getElementsByTagName('HEAD')[0]
+ .appendChild(myself.context.jsonpScript);
+ },
+ function (err) {
+ console.log(err);
+ myself.handleError({name: 'Location', message: err});
+ },
+ { enableHightAccuracy: true, timeout: 30000, maximumAge: 0}
+ );
+ } else {
+ if (myself.context.json) {
+ switch (myself.inputOption(name)) {
+ case 'all':
+ return myself.context.json.display_name;
+ case 'state district':
+ return myself.context.json.address.state_district;
+ case 'house number':
+ return myself.context.json.address.house_number;
+ case 'licence':
+ return myself.context.json.licence;
+ case 'country':
+ case 'state':
+ case 'suburb':
+ case 'city':
+ case 'road':
+ return myself.context.
+ json.address[myself.inputOption(name)];
+ }
+ }
+ }
+
+ this.pushContext('doYield');
+ this.pushContext();
+};
+
// Process Dates and times in Snap
// Map block options to built-in functions
var dateMap = {