Mobile: implement follow mode
This commit is contained in:
parent
51064a29c4
commit
78f6e07457
@ -21,6 +21,7 @@
|
|||||||
window.plugin.userLocation = function() {};
|
window.plugin.userLocation = function() {};
|
||||||
|
|
||||||
window.plugin.userLocation.locationLayer = new L.LayerGroup();
|
window.plugin.userLocation.locationLayer = new L.LayerGroup();
|
||||||
|
window.plugin.userLocation.follow = false;
|
||||||
|
|
||||||
window.plugin.userLocation.setup = function() {
|
window.plugin.userLocation.setup = function() {
|
||||||
$('<style>').prop('type', 'text/css').html('@@INCLUDESTRING:mobile/plugins/user-location.css@@').appendTo('head');
|
$('<style>').prop('type', 'text/css').html('@@INCLUDESTRING:mobile/plugins/user-location.css@@').appendTo('head');
|
||||||
@ -59,10 +60,20 @@ window.plugin.userLocation.setup = function() {
|
|||||||
window.plugin.userLocation.circle = circle;
|
window.plugin.userLocation.circle = circle;
|
||||||
window.plugin.userLocation.icon = icon;
|
window.plugin.userLocation.icon = icon;
|
||||||
|
|
||||||
|
window.map.on('movestart', window.plugin.userLocation.onMoveStart);
|
||||||
window.map.on('zoomend', window.plugin.userLocation.onZoomEnd);
|
window.map.on('zoomend', window.plugin.userLocation.onZoomEnd);
|
||||||
window.plugin.userLocation.onZoomEnd();
|
window.plugin.userLocation.onZoomEnd();
|
||||||
};
|
};
|
||||||
|
|
||||||
|
window.plugin.userLocation.onMoveStart = function(e) {
|
||||||
|
if(window.plugin.userLocation.moving)
|
||||||
|
return;
|
||||||
|
|
||||||
|
window.plugin.userLocation.follow = false;
|
||||||
|
if(typeof android !== 'undefined' && android && android.setFollowMode)
|
||||||
|
android.setFollowMode(window.plugin.userLocation.follow);
|
||||||
|
};
|
||||||
|
|
||||||
window.plugin.userLocation.onZoomEnd = function() {
|
window.plugin.userLocation.onZoomEnd = function() {
|
||||||
if(window.map.getZoom() < 16)
|
if(window.map.getZoom() < 16)
|
||||||
window.plugin.userLocation.locationLayer.removeLayer(window.plugin.userLocation.circle);
|
window.plugin.userLocation.locationLayer.removeLayer(window.plugin.userLocation.circle);
|
||||||
@ -71,6 +82,13 @@ window.plugin.userLocation.onZoomEnd = function() {
|
|||||||
};
|
};
|
||||||
|
|
||||||
window.plugin.userLocation.locate = function(lat, lng, accuracy) {
|
window.plugin.userLocation.locate = function(lat, lng, accuracy) {
|
||||||
|
if(window.plugin.userLocation.follow) {
|
||||||
|
window.plugin.userLocation.follow = false;
|
||||||
|
if(typeof android !== 'undefined' && android && android.setFollowMode)
|
||||||
|
android.setFollowMode(window.plugin.userLocation.follow);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
var latlng = new L.LatLng(lat, lng);
|
var latlng = new L.LatLng(lat, lng);
|
||||||
|
|
||||||
var latAccuracy = 180 * accuracy / 40075017;
|
var latAccuracy = 180 * accuracy / 40075017;
|
||||||
@ -85,12 +103,22 @@ window.plugin.userLocation.locate = function(lat, lng, accuracy) {
|
|||||||
zoom = Math.min(zoom,17);
|
zoom = Math.min(zoom,17);
|
||||||
|
|
||||||
window.map.setView(latlng, zoom);
|
window.map.setView(latlng, zoom);
|
||||||
|
|
||||||
|
window.plugin.userLocation.follow = true;
|
||||||
|
if(typeof android !== 'undefined' && android && android.setFollowMode)
|
||||||
|
android.setFollowMode(window.plugin.userLocation.follow);
|
||||||
}
|
}
|
||||||
|
|
||||||
window.plugin.userLocation.onLocationChange = function(lat, lng) {
|
window.plugin.userLocation.onLocationChange = function(lat, lng) {
|
||||||
var latlng = new L.LatLng(lat, lng);
|
var latlng = new L.LatLng(lat, lng);
|
||||||
window.plugin.userLocation.marker.setLatLng(latlng);
|
window.plugin.userLocation.marker.setLatLng(latlng);
|
||||||
window.plugin.userLocation.circle.setLatLng(latlng);
|
window.plugin.userLocation.circle.setLatLng(latlng);
|
||||||
|
|
||||||
|
if(window.plugin.userLocation.follow) {
|
||||||
|
window.plugin.userLocation.moving = true;
|
||||||
|
window.map.setView(latlng);
|
||||||
|
window.plugin.userLocation.moving = false;
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
window.plugin.userLocation.onOrientationChange = function(direction) {
|
window.plugin.userLocation.onOrientationChange = function(direction) {
|
||||||
|
BIN
mobile/res/drawable-hdpi/ic_action_location_follow.png
Normal file
BIN
mobile/res/drawable-hdpi/ic_action_location_follow.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 646 B |
BIN
mobile/res/drawable-mdpi/ic_action_location_follow.png
Normal file
BIN
mobile/res/drawable-mdpi/ic_action_location_follow.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 451 B |
BIN
mobile/res/drawable-xhdpi/ic_action_location_follow.png
Normal file
BIN
mobile/res/drawable-xhdpi/ic_action_location_follow.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 820 B |
BIN
mobile/res/drawable-xxhdpi/ic_action_location_follow.png
Normal file
BIN
mobile/res/drawable-xxhdpi/ic_action_location_follow.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 1.2 KiB |
@ -189,4 +189,14 @@ public class IITC_JSInterface {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@JavascriptInterface
|
||||||
|
public void setFollowMode(final boolean follow) {
|
||||||
|
mIitc.runOnUiThread(new Runnable() {
|
||||||
|
@Override
|
||||||
|
public void run() {
|
||||||
|
mIitc.getUserLocation().setFollowMode(follow);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -400,17 +400,31 @@ public class IITC_Mobile extends Activity implements OnSharedPreferenceChangeLis
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean onPrepareOptionsMenu(Menu menu) {
|
public boolean onPrepareOptionsMenu(Menu menu) {
|
||||||
if (mNavigationHelper != null) {
|
boolean visible = false;
|
||||||
boolean visible = !mNavigationHelper.isDrawerOpened();
|
if (mNavigationHelper != null)
|
||||||
|
visible = !mNavigationHelper.isDrawerOpened();
|
||||||
|
|
||||||
for (int i = 0; i < menu.size(); i++)
|
for (int i = 0; i < menu.size(); i++) {
|
||||||
if (menu.getItem(i).getItemId() != R.id.action_settings) {
|
MenuItem item = menu.getItem(i);
|
||||||
// clear cookies is part of the advanced menu
|
|
||||||
if (menu.getItem(i).getItemId() == R.id.menu_clear_cookies) {
|
switch (item.getItemId()) {
|
||||||
menu.getItem(i).setVisible(mAdvancedMenu & visible);
|
case R.id.action_settings:
|
||||||
} else {
|
item.setVisible(true);
|
||||||
menu.getItem(i).setVisible(visible);
|
break;
|
||||||
}
|
|
||||||
|
case R.id.menu_clear_cookies:
|
||||||
|
item.setVisible(mAdvancedMenu && visible);
|
||||||
|
break;
|
||||||
|
|
||||||
|
case R.id.locate:
|
||||||
|
item.setVisible(visible);
|
||||||
|
item.setIcon(mUserLocation.isFollowing()
|
||||||
|
? R.drawable.ic_action_location_follow
|
||||||
|
: R.drawable.ic_action_location_found);
|
||||||
|
break;
|
||||||
|
|
||||||
|
default:
|
||||||
|
item.setVisible(visible);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -473,6 +487,7 @@ public class IITC_Mobile extends Activity implements OnSharedPreferenceChangeLis
|
|||||||
public void reloadIITC() {
|
public void reloadIITC() {
|
||||||
mNavigationHelper.reset();
|
mNavigationHelper.reset();
|
||||||
mMapSettings.reset();
|
mMapSettings.reset();
|
||||||
|
mUserLocation.reset();
|
||||||
mBackStack.clear();
|
mBackStack.clear();
|
||||||
// iitc starts on map after reload
|
// iitc starts on map after reload
|
||||||
mCurrentPane = Pane.MAP;
|
mCurrentPane = Pane.MAP;
|
||||||
@ -633,4 +648,8 @@ public class IITC_Mobile extends Activity implements OnSharedPreferenceChangeLis
|
|||||||
public IITC_MapSettings getMapSettings() {
|
public IITC_MapSettings getMapSettings() {
|
||||||
return mMapSettings;
|
return mMapSettings;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public IITC_UserLocation getUserLocation() {
|
||||||
|
return mUserLocation;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -25,6 +25,7 @@ public class IITC_UserLocation implements LocationListener, SensorEventListener
|
|||||||
private SensorManager mSensorManager = null;
|
private SensorManager mSensorManager = null;
|
||||||
private float[] mValuesGravity = null, mValuesGeomagnetic = null;
|
private float[] mValuesGravity = null, mValuesGeomagnetic = null;
|
||||||
private double mOrientation = 0;
|
private double mOrientation = 0;
|
||||||
|
private boolean mFollowing = false;
|
||||||
|
|
||||||
public IITC_UserLocation(IITC_Mobile iitc) {
|
public IITC_UserLocation(IITC_Mobile iitc) {
|
||||||
mIitc = iitc;
|
mIitc = iitc;
|
||||||
@ -95,6 +96,10 @@ public class IITC_UserLocation implements LocationListener, SensorEventListener
|
|||||||
return mLastLocation != null;
|
return mLastLocation != null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public boolean isFollowing() {
|
||||||
|
return mFollowing;
|
||||||
|
}
|
||||||
|
|
||||||
public void locate() {
|
public void locate() {
|
||||||
// do not touch the javascript while iitc boots
|
// do not touch the javascript while iitc boots
|
||||||
if (mIitc.isLoading()) return;
|
if (mIitc.isLoading()) return;
|
||||||
@ -122,6 +127,15 @@ public class IITC_UserLocation implements LocationListener, SensorEventListener
|
|||||||
updateListeners();
|
updateListeners();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void reset() {
|
||||||
|
setFollowMode(false);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setFollowMode(boolean follow) {
|
||||||
|
mFollowing = follow;
|
||||||
|
mIitc.invalidateOptionsMenu();
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* set the location mode to use. Available modes:
|
* set the location mode to use. Available modes:
|
||||||
* 0: don't show user's position
|
* 0: don't show user's position
|
||||||
|
Loading…
x
Reference in New Issue
Block a user