made sensor orientation optional due to high cpu load

This commit is contained in:
Philipp Schaefer
2013-12-19 16:35:07 +01:00
parent 2361de0411
commit 2af53b4699
4 changed files with 28 additions and 9 deletions

View File

@ -85,6 +85,8 @@
<string name="pref_plugins_title">Available plugins</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">Fancier but eats battery packs for breakfast</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>

View File

@ -19,6 +19,12 @@
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"/>
<CheckBoxPreference
android:defaultValue="false"
android:key="pref_user_zoom"

View File

@ -89,7 +89,8 @@ public class IITC_Mobile extends Activity implements OnSharedPreferenceChangeLis
mIitcWebView.updateFullscreenStatus();
mUserLocation = new IITC_UserLocation(this);
mUserLocation.setEnabled(mSharedPrefs.getBoolean("pref_user_loc", false));
mUserLocation.setLocationEnabled(mSharedPrefs.getBoolean("pref_user_loc", false));
mUserLocation.setSensorEnabled(mSharedPrefs.getBoolean("pref_user_loc_sensor", true));
// pass ActionBar to helper because we deprecated getActionBar
mNavigationHelper = new IITC_NavigationHelper(this, super.getActionBar());
@ -112,7 +113,9 @@ public class IITC_Mobile extends Activity implements OnSharedPreferenceChangeLis
mDesktopMode = sharedPreferences.getBoolean("pref_force_desktop", false);
mNavigationHelper.onPrefChanged();
} else if (key.equals("pref_user_loc")) {
mUserLocation.setEnabled(sharedPreferences.getBoolean("pref_user_loc", false));
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_fullscreen")) {
mIitcWebView.updateFullscreenStatus();
mNavigationHelper.onPrefChanged();

View File

@ -12,7 +12,8 @@ import android.os.Bundle;
import android.view.Surface;
public class IITC_UserLocation implements LocationListener, SensorEventListener {
private boolean mEnabled = false;
private boolean mLocationEnabled = false;
private boolean mSensorEnabled = false;
private IITC_Mobile mIitc;
private Location mLastLocation = null;
private LocationManager mLocationManager;
@ -49,7 +50,7 @@ public class IITC_UserLocation implements LocationListener, SensorEventListener
e.printStackTrace();
}
if (mSensorAccelerometer != null && mSensorMagnetometer != null) {
if (mSensorAccelerometer != null && mSensorMagnetometer != null && mSensorEnabled) {
mSensorManager.registerListener(this, mSensorAccelerometer, SensorManager.SENSOR_DELAY_UI);
mSensorManager.registerListener(this, mSensorMagnetometer, SensorManager.SENSOR_DELAY_UI);
}
@ -61,7 +62,7 @@ public class IITC_UserLocation implements LocationListener, SensorEventListener
mLocationManager.removeUpdates(this);
if (mSensorAccelerometer != null && mSensorMagnetometer != null) {
if (mSensorAccelerometer != null && mSensorMagnetometer != null && mSensorEnabled) {
mSensorManager.unregisterListener(this, mSensorAccelerometer);
mSensorManager.unregisterListener(this, mSensorMagnetometer);
}
@ -69,7 +70,7 @@ public class IITC_UserLocation implements LocationListener, SensorEventListener
}
private void updateListeners() {
if (mRunning && mEnabled)
if (mRunning && mLocationEnabled)
registerListeners();
else
unregisterListeners();
@ -102,10 +103,17 @@ public class IITC_UserLocation implements LocationListener, SensorEventListener
updateListeners();
}
public void setEnabled(boolean enabled) {
if (enabled == mEnabled) return;
public void setLocationEnabled(boolean enabled) {
if (enabled == mLocationEnabled) return;
mEnabled = enabled;
mLocationEnabled = enabled;
updateListeners();
}
public void setSensorEnabled(boolean enabled) {
if (enabled == mSensorEnabled) return;
mSensorEnabled = enabled;
updateListeners();
}