From a7a6385dc1af599ca7877236e56859e8325cfd60 Mon Sep 17 00:00:00 2001 From: John Taylor Date: Fri, 29 Apr 2016 21:46:08 -0400 Subject: [PATCH 1/2] Option to reverse the polarity of the neutron flow. --- app/build.gradle | 4 +-- app/src/main/assets/constellations.binary | Bin 17271 -> 17271 bytes .../control/SensorOrientationController.java | 9 +++-- .../smoothers/PlainSmootherModelAdaptor.java | 19 +++++++---- app/src/main/res/values/strings.xml | 2 ++ app/src/main/res/values/whatsnew.xml | 7 +--- app/src/main/res/xml/preference_screen.xml | 9 ++--- tools/data/constellations.ascii | 32 +++++++++--------- 8 files changed, 45 insertions(+), 37 deletions(-) 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 7ccf01b315f10bb134b91c570a47115c207a1fbb..5d05ab482a1bf8f1cedde77b107299fc312b8411 100644 GIT binary patch delta 112 zcmey~#`wLBaf1pwWA|iLc2ywh%|4T{Z}L+hyKgf$M~52Y#K}|iR2e63-ldny%-BC! z!AO;{f3us>8fM0x$)8PC8GANMnjK_hoG|&exhms?&5Rc5ER0=~Gi_8EyEgaRBr-8} QPX1`8%GkMC+&+N?0DJT$>Hq)$ delta 112 zcmey~#`wLBaf1pwW9MX5c2ywh%|4T{XYx}ZyJs^uM~50?|Kurps*L@ccj=`vGxkna zFj8gg-Rx$xhMBQz@@G?3#;(nhW(OG=`zGHuS7q$m%xIC$!q_o6(?*rCV{^YvA`@f# P 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..ba66e6db8 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,9 @@ 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. + // direction to that for accelerometer, except on some phones that are doing it wrong. // TODO(johntaylor): this might not be the best place to reverse this. - magneticValues.z = -values[2]; + 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 37cd29da9..2222af219 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"> - + Date: Fri, 29 Apr 2016 21:53:36 -0400 Subject: [PATCH 2/2] swapped a few defaults --- .../util/smoothers/PlainSmootherModelAdaptor.java | 8 +++++--- app/src/main/res/xml/preference_screen.xml | 2 +- 2 files changed, 6 insertions(+), 4 deletions(-) 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 ba66e6db8..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 @@ -42,7 +42,7 @@ public class PlainSmootherModelAdaptor implements SensorListener { @Inject PlainSmootherModelAdaptor(AstronomerModel model, SharedPreferences sharedPreferences) { this.model = model; - reverseMagneticZaxis = !sharedPreferences.getBoolean(REVERSE_MAGNETIC_Z_PREFKEY, false); + reverseMagneticZaxis = sharedPreferences.getBoolean(REVERSE_MAGNETIC_Z_PREFKEY, false); } @Override @@ -56,8 +56,10 @@ public void onSensorChanged(int sensor, float[] values) { magneticValues.y = values[1]; // The z direction for the mag magneticField sensor is in the opposite // direction to that for accelerometer, except on some phones that are doing it wrong. - // TODO(johntaylor): this might not be the best place to reverse this. - magneticValues.z = reverseMagneticZaxis ? -values[2] : values[2]; + // 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/xml/preference_screen.xml b/app/src/main/res/xml/preference_screen.xml index 2222af219..6a585f98f 100644 --- a/app/src/main/res/xml/preference_screen.xml +++ b/app/src/main/res/xml/preference_screen.xml @@ -93,7 +93,7 @@ android:entries="@array/sensor_damping" android:defaultValue="EXTRA HIGH" />