diff --git a/app/build.gradle b/app/build.gradle index 2597c46d0..c19a5a55f 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -9,8 +9,8 @@ android { applicationId "com.google.android.stardroid" minSdkVersion 15 targetSdkVersion 23 - versionCode 1427 - versionName "1.8.4.1" + versionCode 1428 + versionName "1.8.5 - alpha1" buildConfigField 'String', 'GOOGLE_ANALYTICS_CODE', '""' } signingConfigs { diff --git a/app/src/main/assets/constellations.binary b/app/src/main/assets/constellations.binary index 7ccf01b31..5d05ab482 100644 Binary files a/app/src/main/assets/constellations.binary and b/app/src/main/assets/constellations.binary differ diff --git a/app/src/main/java/com/google/android/stardroid/control/SensorOrientationController.java b/app/src/main/java/com/google/android/stardroid/control/SensorOrientationController.java index 78436d5ac..cdbea8c8a 100644 --- a/app/src/main/java/com/google/android/stardroid/control/SensorOrientationController.java +++ b/app/src/main/java/com/google/android/stardroid/control/SensorOrientationController.java @@ -29,6 +29,7 @@ import com.google.android.stardroid.util.smoothers.PlainSmootherModelAdaptor; import javax.inject.Inject; +import javax.inject.Provider; /** * Sets the direction of view from the orientation sensors. @@ -81,22 +82,24 @@ public SensorDampingSettings(float damping, int exponent) { private SensorManager manager; private SensorListener accelerometerSmoother; private SensorListener compassSmoother; - private PlainSmootherModelAdaptor modelAdaptor; + private Provider modelAdaptorProvider; private SensorAccuracyReporter accuracyReporter; private SharedPreferences sharedPreferences; @Inject - SensorOrientationController(Context context, SensorAccuracyReporter accuracyReporter) { + SensorOrientationController(Context context, SensorAccuracyReporter accuracyReporter, + Provider modelAdaptorProvider) { manager = (SensorManager) context.getSystemService(Context.SENSOR_SERVICE); sharedPreferences = PreferenceManager.getDefaultSharedPreferences(context); sharedPreferences.registerOnSharedPreferenceChangeListener(this); this.accuracyReporter = accuracyReporter; + this.modelAdaptorProvider = modelAdaptorProvider; } @Override public void start() { - modelAdaptor = new PlainSmootherModelAdaptor(model); + PlainSmootherModelAdaptor modelAdaptor = modelAdaptorProvider.get(); Log.d(TAG, "Exponentially weighted smoothers used"); String dampingPreference = sharedPreferences.getString(SENSOR_DAMPING_PREF_KEY, diff --git a/app/src/main/java/com/google/android/stardroid/util/smoothers/PlainSmootherModelAdaptor.java b/app/src/main/java/com/google/android/stardroid/util/smoothers/PlainSmootherModelAdaptor.java index ecd841c6d..9bdd5c3ba 100644 --- a/app/src/main/java/com/google/android/stardroid/util/smoothers/PlainSmootherModelAdaptor.java +++ b/app/src/main/java/com/google/android/stardroid/util/smoothers/PlainSmootherModelAdaptor.java @@ -14,14 +14,17 @@ package com.google.android.stardroid.util.smoothers; +import android.content.SharedPreferences; +import android.hardware.SensorListener; +import android.hardware.SensorManager; +import android.util.Log; + import com.google.android.stardroid.ApplicationConstants; import com.google.android.stardroid.control.AstronomerModel; import com.google.android.stardroid.units.Vector3; import com.google.android.stardroid.util.MiscUtil; -import android.hardware.SensorListener; -import android.hardware.SensorManager; -import android.util.Log; +import javax.inject.Inject; /** * Adapts sensor output for use with the astronomer model. @@ -30,12 +33,16 @@ */ public class PlainSmootherModelAdaptor implements SensorListener { private static final String TAG = MiscUtil.getTag(PlainSmootherModelAdaptor.class); + private static final String REVERSE_MAGNETIC_Z_PREFKEY = "reverse_magnetic_z"; private Vector3 magneticValues = ApplicationConstants.INITIAL_SOUTH.copy(); private Vector3 acceleration = ApplicationConstants.INITIAL_DOWN.copy(); private AstronomerModel model; + private boolean reverseMagneticZaxis; - public PlainSmootherModelAdaptor(AstronomerModel model) { + @Inject + PlainSmootherModelAdaptor(AstronomerModel model, SharedPreferences sharedPreferences) { this.model = model; + reverseMagneticZaxis = sharedPreferences.getBoolean(REVERSE_MAGNETIC_Z_PREFKEY, false); } @Override @@ -48,9 +55,11 @@ public void onSensorChanged(int sensor, float[] values) { magneticValues.x = values[0]; magneticValues.y = values[1]; // The z direction for the mag magneticField sensor is in the opposite - // direction to that for accelerometer. - // TODO(johntaylor): this might not be the best place to reverse this. - magneticValues.z = -values[2]; + // direction to that for accelerometer, except on some phones that are doing it wrong. + // Yes that's right, the right thing to do is to invert it. So if we reverse that, + // we don't invert it. Got it? + // TODO(johntaylor): this might not be the best place to do this. + magneticValues.z = reverseMagneticZaxis ? values[2] : -values[2]; } else { Log.e(TAG, "Pump is receiving values that aren't accel or magnetic"); } diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 14c393239..a249e2efc 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -468,4 +468,6 @@ Compass - Do not show this again Your compass needs to be calibrated + Reverse Magnetic Z + Fix for phones with incorrectly implemented sensors - requires restart diff --git a/app/src/main/res/values/whatsnew.xml b/app/src/main/res/values/whatsnew.xml index 8c7a05bf8..0cec32a82 100644 --- a/app/src/main/res/values/whatsnew.xml +++ b/app/src/main/res/values/whatsnew.xml @@ -3,12 +3,7 @@ New in version %s - \t • The Mercury transit and two new solar eclipses in time travel mode
- \t • Made the planet motion in time travel smoother
- \t • Two new images in the gallery
- \t • Compass calibration assistance
- \t • Internal efficiency improvements to search (credit: tricao)
- \t • A new basic diagnostics page for debugging. + \t • Added option to reverse the magnetic sensor for the small number of phones (e.g. some OnePlusOnes) that have incorrectly implemented the sensor API
]]>
diff --git a/app/src/main/res/xml/preference_screen.xml b/app/src/main/res/xml/preference_screen.xml index 41ac9984c..77cf73a1e 100644 --- a/app/src/main/res/xml/preference_screen.xml +++ b/app/src/main/res/xml/preference_screen.xml @@ -2,10 +2,6 @@ xmlns:android="http://schemas.android.com/apk/res/android" android:key="stardroid.preferences"> - +