Mobile: implement follow mode
This commit is contained in:
parent
51064a29c4
commit
78f6e07457
@ -21,6 +21,7 @@
|
||||
window.plugin.userLocation = function() {};
|
||||
|
||||
window.plugin.userLocation.locationLayer = new L.LayerGroup();
|
||||
window.plugin.userLocation.follow = false;
|
||||
|
||||
window.plugin.userLocation.setup = function() {
|
||||
$('<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.icon = icon;
|
||||
|
||||
window.map.on('movestart', window.plugin.userLocation.onMoveStart);
|
||||
window.map.on('zoomend', 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() {
|
||||
if(window.map.getZoom() < 16)
|
||||
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) {
|
||||
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 latAccuracy = 180 * accuracy / 40075017;
|
||||
@ -85,12 +103,22 @@ window.plugin.userLocation.locate = function(lat, lng, accuracy) {
|
||||
zoom = Math.min(zoom,17);
|
||||
|
||||
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) {
|
||||
var latlng = new L.LatLng(lat, lng);
|
||||
window.plugin.userLocation.marker.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) {
|
||||
|
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
|
||||
public boolean onPrepareOptionsMenu(Menu menu) {
|
||||
if (mNavigationHelper != null) {
|
||||
boolean visible = !mNavigationHelper.isDrawerOpened();
|
||||
boolean visible = false;
|
||||
if (mNavigationHelper != null)
|
||||
visible = !mNavigationHelper.isDrawerOpened();
|
||||
|
||||
for (int i = 0; i < menu.size(); i++)
|
||||
if (menu.getItem(i).getItemId() != R.id.action_settings) {
|
||||
// clear cookies is part of the advanced menu
|
||||
if (menu.getItem(i).getItemId() == R.id.menu_clear_cookies) {
|
||||
menu.getItem(i).setVisible(mAdvancedMenu & visible);
|
||||
} else {
|
||||
menu.getItem(i).setVisible(visible);
|
||||
}
|
||||
for (int i = 0; i < menu.size(); i++) {
|
||||
MenuItem item = menu.getItem(i);
|
||||
|
||||
switch (item.getItemId()) {
|
||||
case R.id.action_settings:
|
||||
item.setVisible(true);
|
||||
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() {
|
||||
mNavigationHelper.reset();
|
||||
mMapSettings.reset();
|
||||
mUserLocation.reset();
|
||||
mBackStack.clear();
|
||||
// iitc starts on map after reload
|
||||
mCurrentPane = Pane.MAP;
|
||||
@ -633,4 +648,8 @@ public class IITC_Mobile extends Activity implements OnSharedPreferenceChangeLis
|
||||
public IITC_MapSettings getMapSettings() {
|
||||
return mMapSettings;
|
||||
}
|
||||
|
||||
public IITC_UserLocation getUserLocation() {
|
||||
return mUserLocation;
|
||||
}
|
||||
}
|
||||
|
@ -25,6 +25,7 @@ public class IITC_UserLocation implements LocationListener, SensorEventListener
|
||||
private SensorManager mSensorManager = null;
|
||||
private float[] mValuesGravity = null, mValuesGeomagnetic = null;
|
||||
private double mOrientation = 0;
|
||||
private boolean mFollowing = false;
|
||||
|
||||
public IITC_UserLocation(IITC_Mobile iitc) {
|
||||
mIitc = iitc;
|
||||
@ -95,6 +96,10 @@ public class IITC_UserLocation implements LocationListener, SensorEventListener
|
||||
return mLastLocation != null;
|
||||
}
|
||||
|
||||
public boolean isFollowing() {
|
||||
return mFollowing;
|
||||
}
|
||||
|
||||
public void locate() {
|
||||
// do not touch the javascript while iitc boots
|
||||
if (mIitc.isLoading()) return;
|
||||
@ -122,6 +127,15 @@ public class IITC_UserLocation implements LocationListener, SensorEventListener
|
||||
updateListeners();
|
||||
}
|
||||
|
||||
public void reset() {
|
||||
setFollowMode(false);
|
||||
}
|
||||
|
||||
public void setFollowMode(boolean follow) {
|
||||
mFollowing = follow;
|
||||
mIitc.invalidateOptionsMenu();
|
||||
}
|
||||
|
||||
/**
|
||||
* set the location mode to use. Available modes:
|
||||
* 0: don't show user's position
|
||||
|
Loading…
x
Reference in New Issue
Block a user