Merge branch 'fkloft/user-location'
This commit is contained in:
commit
cb281151a2
@ -5,8 +5,11 @@
|
||||
.user-location .container {
|
||||
height: 32px;
|
||||
width: 32px;
|
||||
transform-origin: center;
|
||||
transform-origin: center;
|
||||
-webkit-transform-origin: center;
|
||||
transition: all 200ms linear;
|
||||
-moz-transition: all 200ms linear;
|
||||
-webkit-transition: all 200ms linear;
|
||||
}
|
||||
|
||||
.user-location .container .inner,
|
||||
|
@ -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;
|
||||
@ -84,6 +102,12 @@ window.plugin.userLocation.locate = function(lat, lng, accuracy) {
|
||||
// so limit to 17 (enough to see all portals)
|
||||
zoom = Math.min(zoom,17);
|
||||
|
||||
if(window.map.getCenter().distanceTo(latlng) < 10) {
|
||||
window.plugin.userLocation.follow = true;
|
||||
if(typeof android !== 'undefined' && android && android.setFollowMode)
|
||||
android.setFollowMode(window.plugin.userLocation.follow);
|
||||
}
|
||||
|
||||
window.map.setView(latlng, zoom);
|
||||
}
|
||||
|
||||
@ -91,16 +115,39 @@ 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) {
|
||||
// move map if marker moves more than 35% from the center
|
||||
// 100% - 2*15% = 70% → 35% from center in either direction
|
||||
if(map.getBounds().pad(-0.15).contains(latlng))
|
||||
return;
|
||||
|
||||
window.plugin.userLocation.moving = true;
|
||||
window.map.setView(latlng);
|
||||
window.plugin.userLocation.moving = false;
|
||||
}
|
||||
};
|
||||
|
||||
window.plugin.userLocation.onOrientationChange = function(direction) {
|
||||
$(".container", window.plugin.userLocation.marker._icon)
|
||||
.removeClass("circle")
|
||||
.addClass("arrow")
|
||||
.css({
|
||||
"transform": "rotate(" + direction + "deg)",
|
||||
"webkitTransform": "rotate(" + direction + "deg)"
|
||||
});
|
||||
var container = $(".container", window.plugin.userLocation.marker._icon);
|
||||
|
||||
if(direction === null) {
|
||||
container
|
||||
.removeClass("arrow")
|
||||
.addClass("circle")
|
||||
.css({
|
||||
"transform": "",
|
||||
"webkitTransform": ""
|
||||
});
|
||||
} else {
|
||||
container
|
||||
.removeClass("circle")
|
||||
.addClass("arrow")
|
||||
.css({
|
||||
"transform": "rotate(" + direction + "deg)",
|
||||
"webkitTransform": "rotate(" + direction + "deg)"
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
var setup = window.plugin.userLocation.setup;
|
||||
|
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 |
@ -83,11 +83,7 @@
|
||||
<string name="pref_tweaks_cat">Tweaks</string>
|
||||
<string name="pref_plugins">IITC Plugins</string>
|
||||
<string name="pref_plugins_title">Available plugins</string>
|
||||
<string name="pref_user_loc_screen">User location</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_user_loc_sensor">Use sensor orientation</string>
|
||||
<string name="pref_user_loc_sensor_sum">Experimental! Fancier but eats battery packs for breakfast</string>
|
||||
<string name="pref_user_location">Display user location on map</string>
|
||||
<string name="pref_user_zoom">Show zoom control</string>
|
||||
<string name="pref_user_zoom_sum">Shows +/- buttons even on multitouch capable devices.</string>
|
||||
<string name="pref_fullscreen">Hide in fullscreen mode</string>
|
||||
@ -128,6 +124,16 @@
|
||||
<item>8</item>
|
||||
<item>16</item>
|
||||
</string-array>
|
||||
<string-array name="pref_user_location_titles">
|
||||
<item>Don\'t show user position</item>
|
||||
<item>Show user position on map</item>
|
||||
<item>Show user position and orientation on map</item>
|
||||
</string-array>
|
||||
<string-array name="pref_user_location_values">
|
||||
<item>0</item>
|
||||
<item>1</item>
|
||||
<item>2</item>
|
||||
</string-array>
|
||||
|
||||
<string name="menu_clear_cookies">Clear Cookies</string>
|
||||
<string name="menu_search">Search</string>
|
||||
|
@ -14,33 +14,26 @@
|
||||
<PreferenceCategory
|
||||
android:key="pref_ui_cat"
|
||||
android:title="@string/pref_ui_cat">
|
||||
<PreferenceScreen
|
||||
android:key="pref_user_loc_screen"
|
||||
android:persistent="false"
|
||||
android:title="@string/pref_user_loc_screen">
|
||||
<CheckBoxPreference
|
||||
android:defaultValue="false"
|
||||
android:key="pref_user_loc"
|
||||
android:summary="@string/pref_user_loc_sum"
|
||||
android:title="@string/pref_user_loc"/>
|
||||
<CheckBoxPreference
|
||||
android:defaultValue="true"
|
||||
android:key="pref_user_loc_sensor"
|
||||
android:dependency="pref_user_loc"
|
||||
android:summary="@string/pref_user_loc_sensor_sum"
|
||||
android:title="@string/pref_user_loc_sensor"/>
|
||||
</PreferenceScreen>
|
||||
<ListPreference
|
||||
android:defaultValue="0"
|
||||
android:entries="@array/pref_user_location_titles"
|
||||
android:entryValues="@array/pref_user_location_values"
|
||||
android:key="pref_user_location_mode"
|
||||
android:title="@string/pref_user_location"/>
|
||||
|
||||
<CheckBoxPreference
|
||||
android:defaultValue="false"
|
||||
android:key="pref_user_zoom"
|
||||
android:summary="@string/pref_user_zoom_sum"
|
||||
android:title="@string/pref_user_zoom"/>
|
||||
|
||||
<MultiSelectListPreference
|
||||
android:entries="@array/pref_hide_fullscreen"
|
||||
android:entryValues="@array/pref_hide_fullscreen_vals"
|
||||
android:key="pref_fullscreen"
|
||||
android:summary="@string/pref_fullscreen_sum"
|
||||
android:title="@string/pref_fullscreen"
|
||||
android:entries="@array/pref_hide_fullscreen"
|
||||
android:entryValues="@array/pref_hide_fullscreen_vals"/>
|
||||
android:title="@string/pref_fullscreen"/>
|
||||
|
||||
<CheckBoxPreference
|
||||
android:defaultValue="false"
|
||||
android:key="pref_force_desktop"
|
||||
@ -50,7 +43,6 @@
|
||||
<PreferenceCategory
|
||||
android:key="pref_mics"
|
||||
android:title="@string/pref_misc_cat">
|
||||
|
||||
<PreferenceScreen
|
||||
android:fragment="com.cradle.iitc_mobile.fragments.PluginsFragment"
|
||||
android:key="pref_plugins"
|
||||
@ -67,15 +59,15 @@
|
||||
android:summary="@string/pref_force_https_sum"
|
||||
android:title="@string/pref_force_https"/>
|
||||
<CheckBoxPreference
|
||||
android:defaultValue="false"
|
||||
android:key="pref_external_storage"
|
||||
android:title="@string/pref_external_storage"
|
||||
android:summary="@string/pref_external_storage_sum"
|
||||
android:defaultValue="false" />
|
||||
android:title="@string/pref_external_storage"/>
|
||||
<CheckBoxPreference
|
||||
android:key="pref_press_twice_to_exit"
|
||||
android:title="@string/pref_press_twice_to_exit"
|
||||
android:summary="@string/pref_press_twice_to_exit_sum"
|
||||
android:defaultValue="false" />
|
||||
android:defaultValue="false"
|
||||
android:key="pref_press_twice_to_exit"
|
||||
android:summary="@string/pref_press_twice_to_exit_sum"
|
||||
android:title="@string/pref_press_twice_to_exit"/>
|
||||
</PreferenceCategory>
|
||||
<PreferenceCategory
|
||||
android:key="pref_developer_options"
|
||||
@ -121,4 +113,4 @@
|
||||
</PreferenceScreen>
|
||||
</PreferenceCategory>
|
||||
|
||||
</PreferenceScreen>
|
||||
</PreferenceScreen>
|
@ -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);
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
@ -88,8 +88,7 @@ public class IITC_Mobile extends Activity implements OnSharedPreferenceChangeLis
|
||||
mIitcWebView.updateFullscreenStatus();
|
||||
|
||||
mUserLocation = new IITC_UserLocation(this);
|
||||
mUserLocation.setLocationEnabled(mSharedPrefs.getBoolean("pref_user_loc", false));
|
||||
mUserLocation.setSensorEnabled(mSharedPrefs.getBoolean("pref_user_loc_sensor", true));
|
||||
mUserLocation.setLocationMode(Integer.parseInt(mSharedPrefs.getString("pref_user_location_mode", "0")));
|
||||
|
||||
// pass ActionBar to helper because we deprecated getActionBar
|
||||
mNavigationHelper = new IITC_NavigationHelper(this, super.getActionBar());
|
||||
@ -111,10 +110,11 @@ public class IITC_Mobile extends Activity implements OnSharedPreferenceChangeLis
|
||||
if (key.equals("pref_force_desktop")) {
|
||||
mDesktopMode = sharedPreferences.getBoolean("pref_force_desktop", false);
|
||||
mNavigationHelper.onPrefChanged();
|
||||
} else if (key.equals("pref_user_loc")) {
|
||||
mUserLocation.setLocationEnabled(sharedPreferences.getBoolean("pref_user_loc", false));
|
||||
} else if (key.equals("pref_user_loc_sensor")) {
|
||||
mUserLocation.setSensorEnabled(sharedPreferences.getBoolean("pref_user_loc_sensor", true));
|
||||
} else if (key.equals("pref_user_location_mode")) {
|
||||
int mode = Integer.parseInt(mSharedPrefs.getString("pref_user_location_mode", "0"));
|
||||
if (mUserLocation.setLocationMode(mode))
|
||||
mReloadNeeded = true;
|
||||
return;
|
||||
} else if (key.equals("pref_fullscreen")) {
|
||||
mIitcWebView.updateFullscreenStatus();
|
||||
mNavigationHelper.onPrefChanged();
|
||||
@ -247,43 +247,41 @@ public class IITC_Mobile extends Activity implements OnSharedPreferenceChangeLis
|
||||
protected void onStart() {
|
||||
super.onStart();
|
||||
|
||||
// enough idle...let's do some work
|
||||
Log.d("iitcm", "resuming...reset idleTimer");
|
||||
mUserLocation.onStart();
|
||||
|
||||
if (mReloadNeeded) {
|
||||
Log.d("iitcm", "preference had changed...reload needed");
|
||||
reloadIITC();
|
||||
} else {
|
||||
// iitc is not fully booted...timer will be reset by the script itself
|
||||
if (findViewById(R.id.imageLoading).getVisibility() == View.GONE) {
|
||||
// enough idle...let's do some work
|
||||
Log.d("iitcm", "resuming...reset idleTimer");
|
||||
mIitcWebView.loadUrl("javascript: window.idleReset();");
|
||||
}
|
||||
}
|
||||
|
||||
mUserLocation.onStart();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onResume() {
|
||||
super.onResume();
|
||||
mIitcWebView.resumeTimers();
|
||||
mIitcWebView.onResume();
|
||||
super.onResume();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onPause() {
|
||||
super.onPause();
|
||||
mIitcWebView.pauseTimers();
|
||||
mIitcWebView.onPause();
|
||||
super.onPause();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onStop() {
|
||||
super.onStop();
|
||||
Log.d("iitcm", "stopping iitcm");
|
||||
mIitcWebView.loadUrl("javascript: window.idleSet();");
|
||||
|
||||
mUserLocation.onStop();
|
||||
|
||||
super.onStop();
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -402,18 +400,32 @@ 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);
|
||||
}
|
||||
}
|
||||
|
||||
return super.onPrepareOptionsMenu(menu);
|
||||
@ -475,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;
|
||||
@ -635,4 +648,8 @@ public class IITC_Mobile extends Activity implements OnSharedPreferenceChangeLis
|
||||
public IITC_MapSettings getMapSettings() {
|
||||
return mMapSettings;
|
||||
}
|
||||
|
||||
public IITC_UserLocation getUserLocation() {
|
||||
return mUserLocation;
|
||||
}
|
||||
}
|
||||
|
@ -12,18 +12,20 @@ import android.os.Bundle;
|
||||
import android.view.Surface;
|
||||
|
||||
public class IITC_UserLocation implements LocationListener, SensorEventListener {
|
||||
private static final double SENSOR_DELAY_USER = 100*1e6;
|
||||
private boolean mLocationEnabled = false;
|
||||
private boolean mSensorEnabled = true;
|
||||
private static final double SENSOR_DELAY_USER = 100 * 1e6; // 100 milliseconds
|
||||
private int mMode = 0;
|
||||
private boolean mRunning = false;
|
||||
private boolean mLocationRegistered = false;
|
||||
private boolean mOrientationRegistered = false;
|
||||
private long mLastUpdate = 0;
|
||||
private IITC_Mobile mIitc;
|
||||
private Location mLastLocation = null;
|
||||
private LocationManager mLocationManager;
|
||||
private boolean mRegistered = false;
|
||||
private boolean mRunning = false;
|
||||
private Sensor mSensorAccelerometer, mSensorMagnetometer;
|
||||
private SensorManager mSensorManager = null;
|
||||
float[] mValuesGravity = null, mValuesGeomagnetic = null;
|
||||
private float[] mValuesGravity = null, mValuesGeomagnetic = null;
|
||||
private double mOrientation = 0;
|
||||
private boolean mFollowing = false;
|
||||
|
||||
public IITC_UserLocation(IITC_Mobile iitc) {
|
||||
mIitc = iitc;
|
||||
@ -35,54 +37,69 @@ public class IITC_UserLocation implements LocationListener, SensorEventListener
|
||||
mSensorMagnetometer = mSensorManager.getDefaultSensor(Sensor.TYPE_MAGNETIC_FIELD);
|
||||
}
|
||||
|
||||
private void registerListeners() {
|
||||
if (mRegistered) return;
|
||||
mRegistered = true;
|
||||
private void setOrientation(Double orientation) {
|
||||
// we have a transition defined for the rotation
|
||||
// changes to the orientation should always be less than 180°
|
||||
|
||||
try {
|
||||
mLocationManager.requestLocationUpdates(LocationManager.NETWORK_PROVIDER, 0, 0, this);
|
||||
} catch (IllegalArgumentException e) {
|
||||
// if the given provider doesn't exist
|
||||
e.printStackTrace();
|
||||
}
|
||||
try {
|
||||
mLocationManager.requestLocationUpdates(LocationManager.GPS_PROVIDER, 0, 0, this);
|
||||
} catch (IllegalArgumentException e) {
|
||||
// if the given provider doesn't exist
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
if (mSensorAccelerometer != null && mSensorMagnetometer != null && mSensorEnabled) {
|
||||
mSensorManager.registerListener(this, mSensorAccelerometer, SensorManager.SENSOR_DELAY_NORMAL);
|
||||
mSensorManager.registerListener(this, mSensorMagnetometer, SensorManager.SENSOR_DELAY_NORMAL);
|
||||
}
|
||||
}
|
||||
|
||||
private void unregisterListeners() {
|
||||
if (!mRegistered) return;
|
||||
mRegistered = false;
|
||||
|
||||
mLocationManager.removeUpdates(this);
|
||||
|
||||
if (mSensorAccelerometer != null && mSensorMagnetometer != null && mSensorEnabled) {
|
||||
mSensorManager.unregisterListener(this, mSensorAccelerometer);
|
||||
mSensorManager.unregisterListener(this, mSensorMagnetometer);
|
||||
if (orientation != null) {
|
||||
while (orientation < mOrientation - 180)
|
||||
orientation += 360;
|
||||
while (orientation > mOrientation + 180)
|
||||
orientation -= 360;
|
||||
mOrientation = orientation;
|
||||
} else {
|
||||
mOrientation = 0;
|
||||
}
|
||||
|
||||
mIitc.getWebView().loadJS("if(window.plugin && window.plugin.userLocation)"
|
||||
+ "window.plugin.userLocation.onOrientationChange(" + String.valueOf(orientation) + ");");
|
||||
}
|
||||
|
||||
private void updateListeners() {
|
||||
if (mRunning && mLocationEnabled)
|
||||
registerListeners();
|
||||
else
|
||||
unregisterListeners();
|
||||
boolean useLocation = mRunning && mMode != 0;
|
||||
boolean useOrientation = mRunning && mMode == 2;
|
||||
|
||||
if (useLocation && !mLocationRegistered) {
|
||||
try {
|
||||
mLocationManager.requestLocationUpdates(LocationManager.NETWORK_PROVIDER, 0, 0, this);
|
||||
} catch (IllegalArgumentException e) {
|
||||
// if the given provider doesn't exist
|
||||
e.printStackTrace();
|
||||
}
|
||||
try {
|
||||
mLocationManager.requestLocationUpdates(LocationManager.GPS_PROVIDER, 0, 0, this);
|
||||
} catch (IllegalArgumentException e) {
|
||||
// if the given provider doesn't exist
|
||||
e.printStackTrace();
|
||||
}
|
||||
mLocationRegistered = true;
|
||||
}
|
||||
if (!useLocation && mLocationRegistered) {
|
||||
mLocationManager.removeUpdates(this);
|
||||
mLocationRegistered = false;
|
||||
}
|
||||
|
||||
if (useOrientation && !mOrientationRegistered && mSensorAccelerometer != null && mSensorMagnetometer != null) {
|
||||
mSensorManager.registerListener(this, mSensorAccelerometer, SensorManager.SENSOR_DELAY_NORMAL);
|
||||
mSensorManager.registerListener(this, mSensorMagnetometer, SensorManager.SENSOR_DELAY_NORMAL);
|
||||
mOrientationRegistered = true;
|
||||
}
|
||||
if (!useOrientation && mOrientationRegistered && mSensorAccelerometer != null && mSensorMagnetometer != null) {
|
||||
mSensorManager.unregisterListener(this, mSensorAccelerometer);
|
||||
mSensorManager.unregisterListener(this, mSensorMagnetometer);
|
||||
mOrientationRegistered = false;
|
||||
}
|
||||
}
|
||||
|
||||
public boolean hasCurrentLocation() {
|
||||
if (!mRegistered) return false;
|
||||
if (!mLocationRegistered) return false;
|
||||
return mLastLocation != null;
|
||||
}
|
||||
|
||||
public boolean isFollowing() {
|
||||
return mFollowing;
|
||||
}
|
||||
|
||||
public void locate() {
|
||||
// do not touch the javascript while iitc boots
|
||||
if (mIitc.isLoading()) return;
|
||||
@ -98,6 +115,11 @@ public class IITC_UserLocation implements LocationListener, SensorEventListener
|
||||
public void onStart() {
|
||||
mRunning = true;
|
||||
updateListeners();
|
||||
|
||||
// in case we just switched from loc+sensor to loc-only, let javascript know
|
||||
if (mMode == 1) {
|
||||
setOrientation(null);
|
||||
}
|
||||
}
|
||||
|
||||
public void onStop() {
|
||||
@ -105,18 +127,87 @@ public class IITC_UserLocation implements LocationListener, SensorEventListener
|
||||
updateListeners();
|
||||
}
|
||||
|
||||
public void setLocationEnabled(boolean enabled) {
|
||||
if (enabled == mLocationEnabled) return;
|
||||
|
||||
mLocationEnabled = enabled;
|
||||
updateListeners();
|
||||
public void reset() {
|
||||
setFollowMode(false);
|
||||
}
|
||||
|
||||
public void setSensorEnabled(boolean enabled) {
|
||||
if (enabled == mSensorEnabled) return;
|
||||
public void setFollowMode(boolean follow) {
|
||||
mFollowing = follow;
|
||||
mIitc.invalidateOptionsMenu();
|
||||
}
|
||||
|
||||
mSensorEnabled = enabled;
|
||||
updateListeners();
|
||||
private static final int TWO_MINUTES = 1000 * 60 * 2;
|
||||
|
||||
/**
|
||||
* Determines whether one Location reading is better than the current Location fix
|
||||
* @param location The new Location that you want to evaluate
|
||||
* @param currentBestLocation The current Location fix, to which you want to compare the new one
|
||||
*
|
||||
* code copied from http://developer.android.com/guide/topics/location/strategies.html#BestEstimate
|
||||
*/
|
||||
protected boolean isBetterLocation(Location location, Location currentBestLocation) {
|
||||
if (currentBestLocation == null) {
|
||||
// A new location is always better than no location
|
||||
return true;
|
||||
}
|
||||
|
||||
// Check whether the new location fix is newer or older
|
||||
long timeDelta = location.getTime() - currentBestLocation.getTime();
|
||||
boolean isSignificantlyNewer = timeDelta > TWO_MINUTES;
|
||||
boolean isSignificantlyOlder = timeDelta < -TWO_MINUTES;
|
||||
boolean isNewer = timeDelta > 0;
|
||||
|
||||
// If it's been more than two minutes since the current location, use the new location
|
||||
// because the user has likely moved
|
||||
if (isSignificantlyNewer) {
|
||||
return true;
|
||||
// If the new location is more than two minutes older, it must be worse
|
||||
} else if (isSignificantlyOlder) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// Check whether the new location fix is more or less accurate
|
||||
int accuracyDelta = (int) (location.getAccuracy() - currentBestLocation.getAccuracy());
|
||||
boolean isLessAccurate = accuracyDelta > 0;
|
||||
boolean isMoreAccurate = accuracyDelta < 0;
|
||||
boolean isSignificantlyLessAccurate = accuracyDelta > 100;
|
||||
|
||||
// Check if the old and new location are from the same provider
|
||||
boolean isFromSameProvider = isSameProvider(location.getProvider(),
|
||||
currentBestLocation.getProvider());
|
||||
|
||||
// Determine location quality using a combination of timeliness and accuracy
|
||||
if (isMoreAccurate) {
|
||||
return true;
|
||||
} else if (isNewer && !isLessAccurate) {
|
||||
return true;
|
||||
} else if (isNewer && !isSignificantlyLessAccurate && isFromSameProvider) {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
// Checks whether two providers are the same
|
||||
private boolean isSameProvider(String provider1, String provider2) {
|
||||
if (provider1 == null) {
|
||||
return provider2 == null;
|
||||
}
|
||||
return provider1.equals(provider2);
|
||||
}
|
||||
|
||||
/**
|
||||
* set the location mode to use. Available modes:
|
||||
* 0: don't show user's position
|
||||
* 1: show user's position
|
||||
* 2: show user's position and orientation
|
||||
*
|
||||
* @return whether a reload is needed to reflect the changes made to the preferences
|
||||
*/
|
||||
public boolean setLocationMode(int mode) {
|
||||
boolean needsReload = (mode == 0 && mMode != 0) || (mode != 0 && mMode == 0);
|
||||
mMode = mode;
|
||||
|
||||
return needsReload;
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------
|
||||
@ -125,10 +216,9 @@ public class IITC_UserLocation implements LocationListener, SensorEventListener
|
||||
|
||||
@Override
|
||||
public void onLocationChanged(Location location) {
|
||||
mLastLocation = location;
|
||||
if (!isBetterLocation(location, mLastLocation)) return;
|
||||
|
||||
// throw away all positions with accuracy > 100 meters should avoid gps glitches
|
||||
if (location.getAccuracy() > 100) return;
|
||||
mLastLocation = location;
|
||||
|
||||
// do not touch the javascript while iitc boots
|
||||
if (mIitc.isLoading()) return;
|
||||
@ -140,12 +230,10 @@ public class IITC_UserLocation implements LocationListener, SensorEventListener
|
||||
|
||||
@Override
|
||||
public void onProviderDisabled(String provider) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onProviderEnabled(String provider) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -165,15 +253,15 @@ public class IITC_UserLocation implements LocationListener, SensorEventListener
|
||||
|
||||
@Override
|
||||
public void onSensorChanged(SensorEvent event) {
|
||||
// save some battery 10 updates per second should be enough
|
||||
if ((event.timestamp - mLastUpdate) < SENSOR_DELAY_USER) return;
|
||||
mLastUpdate = event.timestamp;
|
||||
|
||||
if (event.sensor.getType() == Sensor.TYPE_ACCELEROMETER)
|
||||
mValuesGravity = event.values;
|
||||
if (event.sensor.getType() == Sensor.TYPE_MAGNETIC_FIELD)
|
||||
mValuesGeomagnetic = event.values;
|
||||
|
||||
// save some battery, 10 updates per second should be enough
|
||||
if ((event.timestamp - mLastUpdate) < SENSOR_DELAY_USER) return;
|
||||
mLastUpdate = event.timestamp;
|
||||
|
||||
// do not touch the javascript while iitc boots
|
||||
if (mIitc.isLoading()) return;
|
||||
|
||||
@ -202,8 +290,7 @@ public class IITC_UserLocation implements LocationListener, SensorEventListener
|
||||
break;
|
||||
}
|
||||
|
||||
mIitc.getWebView().loadJS("if(window.plugin && window.plugin.userLocation)"
|
||||
+ "window.plugin.userLocation.onOrientationChange(" + direction + ");");
|
||||
setOrientation(direction);
|
||||
}
|
||||
|
||||
// </interface SensorEventListener>
|
||||
|
@ -2,7 +2,6 @@ package com.cradle.iitc_mobile;
|
||||
|
||||
import android.annotation.SuppressLint;
|
||||
import android.annotation.TargetApi;
|
||||
import android.app.Activity;
|
||||
import android.content.Context;
|
||||
import android.content.SharedPreferences;
|
||||
import android.net.ConnectivityManager;
|
||||
@ -13,9 +12,6 @@ import android.util.AttributeSet;
|
||||
import android.util.Log;
|
||||
import android.view.MotionEvent;
|
||||
import android.view.WindowManager;
|
||||
import android.webkit.ConsoleMessage;
|
||||
import android.webkit.GeolocationPermissions;
|
||||
import android.webkit.WebChromeClient;
|
||||
import android.webkit.WebSettings;
|
||||
import android.webkit.WebView;
|
||||
import android.widget.Toast;
|
||||
@ -70,17 +66,17 @@ public class IITC_WebView extends WebView {
|
||||
mNavHider = new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
if (isInFullscreen() && (getFullscreenStatus() & (FS_NAVBAR)) != 0) {
|
||||
int systemUiVisibility = SYSTEM_UI_FLAG_HIDE_NAVIGATION;
|
||||
// in immersive mode the user can interact with the app while the navbar is hidden
|
||||
// this mode is available since KitKat
|
||||
// you can leave this mode by swiping down from the top of the screen. this does only work
|
||||
// when the app is in total-fullscreen mode
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT && (mFullscreenStatus & FS_SYSBAR) != 0) {
|
||||
systemUiVisibility |= SYSTEM_UI_FLAG_IMMERSIVE;
|
||||
if (isInFullscreen() && (getFullscreenStatus() & (FS_NAVBAR)) != 0) {
|
||||
int systemUiVisibility = SYSTEM_UI_FLAG_HIDE_NAVIGATION;
|
||||
// in immersive mode the user can interact with the app while the navbar is hidden
|
||||
// this mode is available since KitKat
|
||||
// you can leave this mode by swiping down from the top of the screen. this does only work
|
||||
// when the app is in total-fullscreen mode
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT && (mFullscreenStatus & FS_SYSBAR) != 0) {
|
||||
systemUiVisibility |= SYSTEM_UI_FLAG_IMMERSIVE;
|
||||
}
|
||||
setSystemUiVisibility(systemUiVisibility);
|
||||
}
|
||||
setSystemUiVisibility(systemUiVisibility);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
@ -131,7 +127,7 @@ public class IITC_WebView extends WebView {
|
||||
}
|
||||
|
||||
// disable splash screen if a http error code is responded
|
||||
new CheckHttpResponse(mJsInterface, mIitc).execute(url);
|
||||
new CheckHttpResponse(mIitc).execute(url);
|
||||
Log.d("iitcm", "loading url: " + url);
|
||||
super.loadUrl(url);
|
||||
}
|
||||
|
@ -1,12 +1,10 @@
|
||||
package com.cradle.iitc_mobile.async;
|
||||
|
||||
import android.app.AlertDialog;
|
||||
import android.content.Context;
|
||||
import android.content.DialogInterface;
|
||||
import android.os.AsyncTask;
|
||||
import android.util.Log;
|
||||
|
||||
import com.cradle.iitc_mobile.IITC_JSInterface;
|
||||
import com.cradle.iitc_mobile.IITC_Mobile;
|
||||
|
||||
import org.apache.http.HttpResponse;
|
||||
@ -24,12 +22,10 @@ import java.io.IOException;
|
||||
*/
|
||||
public class CheckHttpResponse extends AsyncTask<String, Void, Boolean> {
|
||||
|
||||
private final IITC_JSInterface mJsInterface;
|
||||
private final Context mContext;
|
||||
private final IITC_Mobile mIitc;
|
||||
|
||||
public CheckHttpResponse(IITC_JSInterface jsInterface, Context c) {
|
||||
mContext = c;
|
||||
mJsInterface = jsInterface;
|
||||
public CheckHttpResponse(IITC_Mobile iitc) {
|
||||
mIitc = iitc;
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -43,11 +39,10 @@ public class CheckHttpResponse extends AsyncTask<String, Void, Boolean> {
|
||||
int code = response.getStatusLine().getStatusCode();
|
||||
if (code != HttpStatus.SC_OK) {
|
||||
Log.d("iitcm", "received error code: " + code);
|
||||
final IITC_Mobile iitc = (IITC_Mobile) mContext;
|
||||
iitc.runOnUiThread(new Runnable() {
|
||||
mIitc.runOnUiThread(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
iitc.setLoadingState(false);
|
||||
mIitc.setLoadingState(false);
|
||||
}
|
||||
});
|
||||
// TODO: remove when google login issue is fixed
|
||||
@ -68,7 +63,7 @@ public class CheckHttpResponse extends AsyncTask<String, Void, Boolean> {
|
||||
protected void onPostExecute(Boolean aBoolean) {
|
||||
if (aBoolean) {
|
||||
Log.d("iitcm", "google auth error, redirecting to work-around page");
|
||||
AlertDialog.Builder alertDialogBuilder = new AlertDialog.Builder(mContext);
|
||||
AlertDialog.Builder alertDialogBuilder = new AlertDialog.Builder(mIitc);
|
||||
|
||||
// set title
|
||||
alertDialogBuilder.setTitle("LOGIN FAILED!");
|
||||
@ -86,8 +81,7 @@ public class CheckHttpResponse extends AsyncTask<String, Void, Boolean> {
|
||||
@Override
|
||||
public void onClick(DialogInterface dialog, int which) {
|
||||
dialog.cancel();
|
||||
IITC_Mobile iitc_mobile = (IITC_Mobile) mContext;
|
||||
iitc_mobile.reloadIITC();
|
||||
mIitc.reloadIITC();
|
||||
}
|
||||
});
|
||||
|
||||
|
@ -6,6 +6,7 @@ import android.content.pm.PackageManager;
|
||||
import android.content.pm.PackageManager.NameNotFoundException;
|
||||
import android.os.Bundle;
|
||||
import android.preference.EditTextPreference;
|
||||
import android.preference.ListPreference;
|
||||
import android.preference.Preference;
|
||||
import android.preference.Preference.OnPreferenceChangeListener;
|
||||
import android.preference.PreferenceFragment;
|
||||
@ -54,6 +55,20 @@ public class MainSettings extends PreferenceFragment {
|
||||
// first init of summary
|
||||
String pref_iitc_source_sum = getString(R.string.pref_select_iitc_sum) + " " + pref_iitc_source.getText();
|
||||
pref_iitc_source.setSummary(pref_iitc_source_sum);
|
||||
|
||||
final ListPreference pref_user_location_mode = (ListPreference) findPreference("pref_user_location_mode");
|
||||
pref_user_location_mode.setOnPreferenceChangeListener(new OnPreferenceChangeListener() {
|
||||
@Override
|
||||
public boolean onPreferenceChange(Preference preference, Object newValue) {
|
||||
int mode = Integer.parseInt((String) newValue);
|
||||
preference.setSummary(getResources().getStringArray(R.array.pref_user_location_titles)[mode]);
|
||||
return true;
|
||||
}
|
||||
});
|
||||
|
||||
String value = getPreferenceManager().getSharedPreferences().getString("pref_user_location_mode", "0");
|
||||
int mode = Integer.parseInt(value);
|
||||
pref_user_location_mode.setSummary(getResources().getStringArray(R.array.pref_user_location_titles)[mode]);
|
||||
}
|
||||
|
||||
// we want a home button + HomeAsUpEnabled in nested preferences
|
||||
@ -63,8 +78,7 @@ public class MainSettings extends PreferenceFragment {
|
||||
@Override
|
||||
public boolean onPreferenceTreeClick(PreferenceScreen preferenceScreen, Preference preference) {
|
||||
if (preference.getTitle().toString().equals(getString(R.string.pref_advanced_options))
|
||||
|| preference.getTitle().toString().equals(getString(R.string.pref_about_title))
|
||||
|| preference.getTitle().toString().equals(getString(R.string.pref_user_loc_screen))) {
|
||||
|| preference.getTitle().toString().equals(getString(R.string.pref_about_title))) {
|
||||
initializeActionBar((PreferenceScreen) preference);
|
||||
}
|
||||
return super.onPreferenceTreeClick(preferenceScreen, preference);
|
||||
|
Loading…
x
Reference in New Issue
Block a user