diff --git a/build.py b/build.py index 8d64942b..af6241d4 100755 --- a/build.py +++ b/build.py @@ -205,12 +205,24 @@ if buildMobile: if buildMobile not in ['debug','release']: raise Exception("Error: buildMobile must be 'debug' or 'release'") - # first, copy the IITC script into the mobile folder. create the folder if needed + # compile the user location script + fn = "user-location.user.js" + script = readfile("mobile/" + fn) + downloadUrl = distUrlBase and distUrlBase + '/' + fn.replace("\\","/") or 'none' + updateUrl = distUrlBase and downloadUrl.replace('.user.js', '.meta.js') or 'none' + script = doReplacements(script, downloadUrl=downloadUrl, updateUrl=updateUrl) + + metafn = fn.replace('.user.js', '.meta.js') + saveScriptAndMeta(script, os.path.join(outDir,fn), os.path.join(outDir,metafn)) + + # copy the IITC script into the mobile folder. create the folder if needed try: os.makedirs("mobile/assets") except: pass shutil.copy(os.path.join(outDir,"total-conversion-build.user.js"), "mobile/assets/iitc.js") + # copy the user location script into the mobile folder. + shutil.copy(os.path.join(outDir,"user-location.user.js"), "mobile/assets/user-location.user.js") # also copy plugins try: diff --git a/mobile/AndroidManifest.xml b/mobile/AndroidManifest.xml index 472be5e6..df3e6002 100644 --- a/mobile/AndroidManifest.xml +++ b/mobile/AndroidManifest.xml @@ -1,8 +1,8 @@ + android:versionCode="13" + android:versionName="0.3.2" > Available plugins Force desktop mode Nice for tablets, looks awful on smartphones + Display user location + Show users position on map Developer options IITC source diff --git a/mobile/res/xml/preferences.xml b/mobile/res/xml/preferences.xml index 2d72b3e1..e485de40 100644 --- a/mobile/res/xml/preferences.xml +++ b/mobile/res/xml/preferences.xml @@ -17,6 +17,11 @@ android:title="@string/pref_force_desktop" android:summary="@string/pref_force_desktop_sum" android:defaultValue="false" /> + 100 meters + // should avoid gps glitches + if (loc.getAccuracy() < 100) { + iitc_view.loadUrl("javascript: " + + "window.plugin.userLocation.updateLocation( " + + loc.getLatitude() + ", " + loc.getLongitude() + ");"); + } + } +} \ No newline at end of file diff --git a/mobile/src/com/cradle/iitc_mobile/IITC_WebViewClient.java b/mobile/src/com/cradle/iitc_mobile/IITC_WebViewClient.java index d2a62897..884076b8 100644 --- a/mobile/src/com/cradle/iitc_mobile/IITC_WebViewClient.java +++ b/mobile/src/com/cradle/iitc_mobile/IITC_WebViewClient.java @@ -124,6 +124,25 @@ public class IITC_WebViewClient extends WebViewClient { } } } + + // inject the user location script if enabled in settings + if (sharedPref.getBoolean("pref_user_loc", false)) + enableTracking(view); + } + + public void enableTracking(WebView view) { + Log.d("iitcm", "enable tracking..."); + AssetManager am = context.getAssets(); + Scanner s = null; + String src = ""; + try { + s = new Scanner(am.open("user-location.user.js")).useDelimiter("\\A"); + } catch (IOException e2) { + // TODO Auto-generated catch block + e2.printStackTrace(); + } + if (s != null) src = s.hasNext() ? s.next() : ""; + view.loadUrl("javascript:" + src); } // Check every external resource if it’s okay to load it and maybe replace it diff --git a/mobile/user-location.user.js b/mobile/user-location.user.js new file mode 100644 index 00000000..fe118b7f --- /dev/null +++ b/mobile/user-location.user.js @@ -0,0 +1,64 @@ +// ==UserScript== +// @id iitc-plugin-user-location@cradle +// @name IITC plugin: User Location +// @version 0.1.0.@@DATETIMEVERSION@@ +// @namespace https://github.com/jonatkins/ingress-intel-total-conversion +// @updateURL @@UPDATEURL@@ +// @downloadURL @@DOWNLOADURL@@ +// @description [@@BUILDNAME@@-@@BUILDDATE@@] Show user location marker on map +// @include https://www.ingress.com/intel* +// @include http://www.ingress.com/intel* +// @match https://www.ingress.com/intel* +// @match http://www.ingress.com/intel* +// ==/UserScript== + +function wrapper() { +// ensure plugin framework is there, even if iitc is not yet loaded +if(typeof window.plugin !== 'function') window.plugin = function() {}; + + +// PLUGIN START //////////////////////////////////////////////////////// + +window.plugin.userLocation = function() {}; + +window.plugin.userLocation.marker = {}; +window.plugin.userLocation.locationLayer = new L.LayerGroup(); + +window.plugin.userLocation.setup = function() { + + var iconImage = '@@INCLUDEIMAGE:images/marker-icon.png@@'; + var iconRetImage = '@@INCLUDEIMAGE:images/marker-icon_2x.png@@'; + + plugin.userLocation.icon = L.Icon.Default.extend({options: { + iconUrl: iconImage, + iconRetinaUrl: iconRetImage + }}); + + var marker = L.marker(window.map.getCenter(), {icon: new plugin.userLocation.icon()}); + plugin.userLocation.marker = marker; + marker.addTo(window.map); +}; + +window.plugin.userLocation.updateLocation = function(lat, lng) { + var latlng = new L.LatLng(lat, lng); + window.plugin.userLocation.marker.setLatLng(latlng); +} + +var setup = window.plugin.userLocation.setup; + +// PLUGIN END ////////////////////////////////////////////////////////// + +if(window.iitcLoaded && typeof setup === 'function') { + setup(); +} else { + if(window.bootPlugins) + window.bootPlugins.push(setup); + else + window.bootPlugins = [setup]; +} +} // wrapper end +// inject code into site context +var script = document.createElement('script'); +script.appendChild(document.createTextNode('('+ wrapper +')();')); +(document.body || document.head || document.documentElement).appendChild(script); +