Commit 74a8db24 authored by John David Taylor's avatar John David Taylor Committed by GitHub

Make using the gyro the default for phones that support it. (#150)

* Made use gyro the default for phones that support it.

* Missed committing the value

* Fixed typo in strings.
parent 391d4348
......@@ -40,7 +40,7 @@ public class ApplicationConstants {
// Preference that keeps track of whether or not the user accepted the ToS for this version
public static final String READ_TOS_PREF_VERSION = "read_tos_version";
public static final String READ_WHATS_NEW_PREF_VERSION = "read_whats_new_version";
public static final String SHARED_PREFERENCE_EXPERIMENTAL_USE_GYRO = "experimental_use_gyro";
public static final String SHARED_PREFERENCE_DISABLE_GYRO = "disable_gyro";
// Attention - the following strings must match those in strings.xml and notranslate-arrays.xml.
public static final String SENSOR_SPEED_HIGH = "FAST";
public static final String SENSOR_SPEED_SLOW = "SLOW";
......
......@@ -173,8 +173,6 @@ public class StardroidApplication extends Application {
/**
* Schedules this runnable to run as soon as possible on a background
* thread.
*
* @param runnable
*/
// TODO(johntaylor): the idea, and I'm not sure yet whether it's a good one,
// is to centralize the management of background threads so we don't have
......@@ -220,8 +218,10 @@ public class StardroidApplication extends Application {
}
// Check for a particularly strange combo
boolean hasRotationSensor = false;
if (hasDefaultSensor(Sensor.TYPE_ROTATION_VECTOR)) {
if (hasDefaultSensor(Sensor.TYPE_ACCELEROMETER) && hasDefaultSensor(Sensor.TYPE_MAGNETIC_FIELD)) {
hasRotationSensor = true;
analytics.trackEvent(
Analytics.SENSOR_CATEGORY, Analytics.ROT_SENSOR_AVAILABILITY, "OK", 1);
} else {
......@@ -233,6 +233,12 @@ public class StardroidApplication extends Application {
Analytics.SENSOR_CATEGORY, Analytics.ROT_SENSOR_AVAILABILITY, "No rotation", 0);
}
// Enable Gyro if available and user hasn't already disabled it.
if (!preferences.contains(ApplicationConstants.SHARED_PREFERENCE_DISABLE_GYRO)) {
preferences.edit().putBoolean(
ApplicationConstants.SHARED_PREFERENCE_DISABLE_GYRO, !hasRotationSensor).apply();
}
// Do we at least have defaults for the main ones?
int[] importantSensorTypes = {Sensor.TYPE_ACCELEROMETER, Sensor.TYPE_GYROSCOPE,
Sensor.TYPE_MAGNETIC_FIELD, Sensor.TYPE_LIGHT, Sensor.TYPE_ROTATION_VECTOR,
......
......@@ -562,8 +562,6 @@ public class DynamicStarMapActivity extends InjectableActivity
}
setAutoMode(autoMode);
break;
case ApplicationConstants.SHARED_PREFERENCE_EXPERIMENTAL_USE_GYRO:
// Do nothing - the sensor controller will take care of it.
default:
return;
}
......@@ -635,8 +633,6 @@ public class DynamicStarMapActivity extends InjectableActivity
SkyRenderer renderer = new SkyRenderer(getResources());
skyView.setRenderer(renderer);
sharedPreferences.getBoolean(ApplicationConstants.SHARED_PREFERENCE_EXPERIMENTAL_USE_GYRO, false);
rendererController = new RendererController(renderer, skyView);
// The renderer will now call back every frame to get model updates.
rendererController.addUpdateClosure(
......
......@@ -97,18 +97,18 @@ public class EditSettingsActivity extends PreferenceActivity {
});
Preference gyroPreference = preferenceFragment.findPreference(
ApplicationConstants.SHARED_PREFERENCE_EXPERIMENTAL_USE_GYRO);
ApplicationConstants.SHARED_PREFERENCE_DISABLE_GYRO);
gyroPreference.setOnPreferenceChangeListener(new Preference.OnPreferenceChangeListener() {
public boolean onPreferenceChange(Preference preference, Object newValue) {
Log.d(TAG, "Toggling gyro preference " + newValue);
enableNonGyroSensorPrefs(!((Boolean) newValue));
enableNonGyroSensorPrefs(((Boolean) newValue));
return true;
}
});
enableNonGyroSensorPrefs(
!sharedPreferences.getBoolean(ApplicationConstants.SHARED_PREFERENCE_EXPERIMENTAL_USE_GYRO,
sharedPreferences.getBoolean(ApplicationConstants.SHARED_PREFERENCE_DISABLE_GYRO,
false));
}
......@@ -127,10 +127,10 @@ public class EditSettingsActivity extends PreferenceActivity {
private void enableNonGyroSensorPrefs(boolean enabled) {
// These settings aren't compatible with the gyro.
preferenceFragment.findPreference(
"sensor_prefs").setEnabled(enabled);
preferenceFragment.findPreference(
ApplicationConstants.SENSOR_SPEED_PREF_KEY).setEnabled(enabled);
preferenceFragment.findPreference(
ApplicationConstants.SENSOR_DAMPING_PREF_KEY).setEnabled(enabled);
preferenceFragment.findPreference(
ApplicationConstants.REVERSE_MAGNETIC_Z_PREFKEY).setEnabled(enabled);
}
......
......@@ -87,11 +87,12 @@ public class SensorOrientationController extends AbstractController
PlainSmootherModelAdaptor modelAdaptor = modelAdaptorProvider.get();
if (manager != null) {
if (sharedPreferences.getBoolean(ApplicationConstants.SHARED_PREFERENCE_EXPERIMENTAL_USE_GYRO,
if (!sharedPreferences.getBoolean(ApplicationConstants.SHARED_PREFERENCE_DISABLE_GYRO,
false)) {
Log.d(TAG, "Using rotation sensor");
manager.registerListener(this, rotationSensor, SensorManager.SENSOR_DELAY_GAME);
} else {
// TODO(jontayler): remove this code once enough it's used in few enough phones.
Log.d(TAG, "Using classic sensors");
Log.d(TAG, "Exponentially weighted smoothers used");
String dampingPreference = sharedPreferences.getString(
......
......@@ -39,9 +39,9 @@
<string name="show_horizon_pref">Horizon</string>
<string name="show_sky_gradient" translation_description="This is a shading of the color of the sky used for effect">Sky Gradient</string>
<string name="show_meteors_pref">Meteor Showers</string>
<string name="sensor_prefs">Sensor Settings</string>
<string name="sensor_speed" translation_description="How quickly the sensor should send us data">Sensor Speed</string>
<string name="sensor_damping" translation_description="The amount of smoothing applied to the sensor outputs.">Damping</string>
<string name="sensor_prefs">Sensor Settings (experts)</string>
<string name="sensor_speed" translation_description="Old, non gyro sensors only: How quickly the sensor should send us data">Sensor Speed</string>
<string name="sensor_damping" translation_description="Old, non gyro sensors only: The amount of smoothing applied to the sensor outputs.">Damping</string>
<string name="ecliptic">Ecliptic</string>
<!-- Just in case we decide to have such a layer for the 4/24 launch -->
<string name="show_hubble_layer_pref">Hubble Images</string>
......@@ -473,6 +473,6 @@
<string name="sensor_reverse_preference_title">Reverse Magnetic Z</string>
<string name="sensor_reverse_preference_summary">Fix for phones with incorrectly implemented sensors - requires restart</string>
<string name="whats_new_dialog_title">What\'s new</string>
<string name="use_gyro_preference_title">Use gyro (experimental)</string>
<string name="use_gyro_preference_summary">Makes map motion smoother. Not all phones have a gyro.</string>
<string name="disable_gyro_preference_title">Disable gyroscope</string>
<string name="disable_gyro_preference_summary">Not all devices have a gyro - if yours does then you\'ll get better results with it enabled and this box unchecked. On the other hand if your device does not have a gyro then Sky Map will probably not work if you uncheck this box.</string>
</resources>
......@@ -2,33 +2,6 @@
xmlns:android="http://schemas.android.com/apk/res/android"
android:key="stardroid.preferences">
<PreferenceCategory>
<CheckBoxPreference
android:defaultValue="false"
android:title="@string/use_gyro_preference_title"
android:summary="@string/use_gyro_preference_summary"
android:key="experimental_use_gyro"/>
<PreferenceScreen android:key="sensor_prefs" android:title="@string/sensor_prefs">
<PreferenceCategory>
<ListPreference
android:key="sensor_speed"
android:title="@string/sensor_speed"
android:entryValues="@array/sensor_speed_values"
android:entries="@array/sensor_speed"
android:defaultValue="STANDARD" />
<ListPreference
android:key="sensor_damping"
android:title="@string/sensor_damping"
android:entryValues="@array/sensor_damping_values"
android:entries="@array/sensor_damping"
android:defaultValue="EXTRA HIGH" />
<CheckBoxPreference
android:defaultValue="false"
android:title="@string/sensor_reverse_preference_title"
android:summary="@string/sensor_reverse_preference_summary"
android:key="reverse_magnetic_z"/>
</PreferenceCategory>
</PreferenceScreen>
<PreferenceScreen android:title="@string/location_prefs">
<PreferenceCategory>
<CheckBoxPreference
......@@ -82,4 +55,30 @@
android:summary="@string/enable_analytics_desc"
android:key="enable_analytics"/>
</PreferenceCategory>
<PreferenceScreen android:key="sensor_prefs" android:title="@string/sensor_prefs">
<PreferenceCategory>
<CheckBoxPreference
android:defaultValue="false"
android:title="@string/disable_gyro_preference_title"
android:summary="@string/disable_gyro_preference_summary"
android:key="disable_gyro"/>
<ListPreference
android:key="sensor_speed"
android:title="@string/sensor_speed"
android:entryValues="@array/sensor_speed_values"
android:entries="@array/sensor_speed"
android:defaultValue="STANDARD" />
<ListPreference
android:key="sensor_damping"
android:title="@string/sensor_damping"
android:entryValues="@array/sensor_damping_values"
android:entries="@array/sensor_damping"
android:defaultValue="EXTRA HIGH" />
<CheckBoxPreference
android:defaultValue="false"
android:title="@string/sensor_reverse_preference_title"
android:summary="@string/sensor_reverse_preference_summary"
android:key="reverse_magnetic_z"/>
</PreferenceCategory>
</PreferenceScreen>
</PreferenceScreen>
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment