display user location on iitcm (see #179)
This commit is contained in:
parent
1048ce28eb
commit
28233b8118
14
build.py
14
build.py
@ -205,12 +205,24 @@ if buildMobile:
|
|||||||
if buildMobile not in ['debug','release']:
|
if buildMobile not in ['debug','release']:
|
||||||
raise Exception("Error: buildMobile must be 'debug' or '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:
|
try:
|
||||||
os.makedirs("mobile/assets")
|
os.makedirs("mobile/assets")
|
||||||
except:
|
except:
|
||||||
pass
|
pass
|
||||||
shutil.copy(os.path.join(outDir,"total-conversion-build.user.js"), "mobile/assets/iitc.js")
|
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
|
# also copy plugins
|
||||||
try:
|
try:
|
||||||
|
@ -1,8 +1,8 @@
|
|||||||
<?xml version="1.0" encoding="utf-8"?>
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
|
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
package="com.cradle.iitc_mobile"
|
package="com.cradle.iitc_mobile"
|
||||||
android:versionCode="12"
|
android:versionCode="13"
|
||||||
android:versionName="0.3.1" >
|
android:versionName="0.3.2" >
|
||||||
|
|
||||||
<uses-sdk
|
<uses-sdk
|
||||||
android:minSdkVersion="14"
|
android:minSdkVersion="14"
|
||||||
|
@ -36,6 +36,8 @@
|
|||||||
<string name="pref_plugins_title">Available plugins</string>
|
<string name="pref_plugins_title">Available plugins</string>
|
||||||
<string name="pref_force_desktop">Force desktop mode</string>
|
<string name="pref_force_desktop">Force desktop mode</string>
|
||||||
<string name="pref_force_desktop_sum">Nice for tablets, looks awful on smartphones</string>
|
<string name="pref_force_desktop_sum">Nice for tablets, looks awful on smartphones</string>
|
||||||
|
<string name="pref_user_loc">Display user location</string>
|
||||||
|
<string name="pref_user_loc_sum">Show users position on map</string>
|
||||||
<string name="pref_developer_options">Developer options</string>
|
<string name="pref_developer_options">Developer options</string>
|
||||||
<string name="pref_select_iitc">IITC source</string>
|
<string name="pref_select_iitc">IITC source</string>
|
||||||
|
|
||||||
|
@ -17,6 +17,11 @@
|
|||||||
android:title="@string/pref_force_desktop"
|
android:title="@string/pref_force_desktop"
|
||||||
android:summary="@string/pref_force_desktop_sum"
|
android:summary="@string/pref_force_desktop_sum"
|
||||||
android:defaultValue="false" />
|
android:defaultValue="false" />
|
||||||
|
<CheckBoxPreference
|
||||||
|
android:key="pref_user_loc"
|
||||||
|
android:title="@string/pref_user_loc"
|
||||||
|
android:summary="@string/pref_user_loc_sum"
|
||||||
|
android:defaultValue="false" />
|
||||||
<MultiSelectListPreference
|
<MultiSelectListPreference
|
||||||
android:key="pref_plugins"
|
android:key="pref_plugins"
|
||||||
android:title="@string/pref_plugins"
|
android:title="@string/pref_plugins"
|
||||||
|
@ -4,6 +4,9 @@ import java.io.IOException;
|
|||||||
|
|
||||||
import com.cradle.iitc_mobile.R;
|
import com.cradle.iitc_mobile.R;
|
||||||
|
|
||||||
|
import android.location.Location;
|
||||||
|
import android.location.LocationListener;
|
||||||
|
import android.location.LocationManager;
|
||||||
import android.net.ConnectivityManager;
|
import android.net.ConnectivityManager;
|
||||||
import android.net.NetworkInfo;
|
import android.net.NetworkInfo;
|
||||||
import android.net.Uri;
|
import android.net.Uri;
|
||||||
@ -29,6 +32,9 @@ public class IITC_Mobile extends Activity {
|
|||||||
private boolean desktop = false;
|
private boolean desktop = false;
|
||||||
private OnSharedPreferenceChangeListener listener;
|
private OnSharedPreferenceChangeListener listener;
|
||||||
private String intel_url = "https://www.ingress.com/intel";
|
private String intel_url = "https://www.ingress.com/intel";
|
||||||
|
private boolean user_loc = false;
|
||||||
|
private LocationManager loc_mngr = null;
|
||||||
|
private LocationListener loc_listener = null;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void onCreate(Bundle savedInstanceState) {
|
protected void onCreate(Bundle savedInstanceState) {
|
||||||
@ -45,11 +51,38 @@ public class IITC_Mobile extends Activity {
|
|||||||
public void onSharedPreferenceChanged(SharedPreferences sharedPreferences, String key) {
|
public void onSharedPreferenceChanged(SharedPreferences sharedPreferences, String key) {
|
||||||
if (key.equals("pref_force_desktop"))
|
if (key.equals("pref_force_desktop"))
|
||||||
desktop = sharedPreferences.getBoolean("pref_force_desktop", false);
|
desktop = sharedPreferences.getBoolean("pref_force_desktop", false);
|
||||||
|
if (key.equals("pref_user_loc")) {
|
||||||
|
user_loc = sharedPreferences.getBoolean("pref_user_loc", false);
|
||||||
|
}
|
||||||
IITC_Mobile.this.loadUrl(intel_url);
|
IITC_Mobile.this.loadUrl(intel_url);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
sharedPref.registerOnSharedPreferenceChangeListener(listener);
|
sharedPref.registerOnSharedPreferenceChangeListener(listener);
|
||||||
|
|
||||||
|
// Acquire a reference to the system Location Manager
|
||||||
|
loc_mngr = (LocationManager) this.getSystemService(Context.LOCATION_SERVICE);
|
||||||
|
|
||||||
|
// Define a listener that responds to location updates
|
||||||
|
loc_listener = new LocationListener() {
|
||||||
|
public void onLocationChanged(Location location) {
|
||||||
|
// Called when a new location is found by the network location provider.
|
||||||
|
drawMarker(location);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void onStatusChanged(String provider, int status, Bundle extras) {}
|
||||||
|
|
||||||
|
public void onProviderEnabled(String provider) {}
|
||||||
|
|
||||||
|
public void onProviderDisabled(String provider) {}
|
||||||
|
};
|
||||||
|
|
||||||
|
user_loc = sharedPref.getBoolean("pref_user_loc", false);
|
||||||
|
if (user_loc == true) {
|
||||||
|
// Register the listener with the Location Manager to receive location updates
|
||||||
|
loc_mngr.requestLocationUpdates(LocationManager.NETWORK_PROVIDER, 0, 0, loc_listener);
|
||||||
|
loc_mngr.requestLocationUpdates(LocationManager.GPS_PROVIDER, 0, 0, loc_listener);
|
||||||
|
}
|
||||||
|
|
||||||
// load new iitc web view with ingress intel page
|
// load new iitc web view with ingress intel page
|
||||||
Intent intent = getIntent();
|
Intent intent = getIntent();
|
||||||
String action = intent.getAction();
|
String action = intent.getAction();
|
||||||
@ -78,6 +111,12 @@ public class IITC_Mobile extends Activity {
|
|||||||
Log.d("iitcm", "resuming...setting reset idleTimer");
|
Log.d("iitcm", "resuming...setting reset idleTimer");
|
||||||
iitc_view.loadUrl("javascript: window.idleTime = 0");
|
iitc_view.loadUrl("javascript: window.idleTime = 0");
|
||||||
iitc_view.loadUrl("javascript: window.renderUpdateStatus()");
|
iitc_view.loadUrl("javascript: window.renderUpdateStatus()");
|
||||||
|
|
||||||
|
if (user_loc == true) {
|
||||||
|
// Register the listener with the Location Manager to receive location updates
|
||||||
|
loc_mngr.requestLocationUpdates(LocationManager.NETWORK_PROVIDER, 0, 0, loc_listener);
|
||||||
|
loc_mngr.requestLocationUpdates(LocationManager.GPS_PROVIDER, 0, 0, loc_listener);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -107,6 +146,10 @@ public class IITC_Mobile extends Activity {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
Log.d("iitcm", "stopping iitcm");
|
Log.d("iitcm", "stopping iitcm");
|
||||||
|
|
||||||
|
if (user_loc == true)
|
||||||
|
loc_mngr.removeUpdates(loc_listener);
|
||||||
|
|
||||||
super.onStop();
|
super.onStop();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -185,6 +228,7 @@ public class IITC_Mobile extends Activity {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// vp=f enables desktop mode...vp=m is the defaul mobile view
|
||||||
private String addUrlParam(String url) {
|
private String addUrlParam(String url) {
|
||||||
SharedPreferences sharedPref = PreferenceManager.getDefaultSharedPreferences(this);
|
SharedPreferences sharedPref = PreferenceManager.getDefaultSharedPreferences(this);
|
||||||
this.desktop = sharedPref.getBoolean("pref_force_desktop", false);
|
this.desktop = sharedPref.getBoolean("pref_force_desktop", false);
|
||||||
@ -195,6 +239,8 @@ public class IITC_Mobile extends Activity {
|
|||||||
return (url + "?vp=m");
|
return (url + "?vp=m");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// inject the iitc-script and load the intel url
|
||||||
|
// plugins are injected onPageFinished
|
||||||
public void loadUrl(String url) {
|
public void loadUrl(String url) {
|
||||||
url = addUrlParam(url);
|
url = addUrlParam(url);
|
||||||
Log.d("iitcm", "injecting js...");
|
Log.d("iitcm", "injecting js...");
|
||||||
@ -202,4 +248,16 @@ public class IITC_Mobile extends Activity {
|
|||||||
Log.d("iitcm", "loading url: " + url);
|
Log.d("iitcm", "loading url: " + url);
|
||||||
iitc_view.loadUrl(url);
|
iitc_view.loadUrl(url);
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
// update the user location marker on the map
|
||||||
|
public void drawMarker(Location loc) {
|
||||||
|
Log.d("iitcm", "update location..." + loc.toString());
|
||||||
|
// throw away all positions with accuracy > 100 meters
|
||||||
|
// should avoid gps glitches
|
||||||
|
if (loc.getAccuracy() < 100) {
|
||||||
|
iitc_view.loadUrl("javascript: " +
|
||||||
|
"window.plugin.userLocation.updateLocation( " +
|
||||||
|
loc.getLatitude() + ", " + loc.getLongitude() + ");");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -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
|
// Check every external resource if it’s okay to load it and maybe replace it
|
||||||
|
64
mobile/user-location.user.js
Normal file
64
mobile/user-location.user.js
Normal file
@ -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);
|
||||||
|
|
Loading…
x
Reference in New Issue
Block a user