Skip to content

Commit f0ade8c

Browse files
authored
Merge pull request #12 from ISO53/high-precision
Add high-precision mode and update app version to 1.3.0
2 parents ad5c12f + f1c23e0 commit f0ade8c

8 files changed

Lines changed: 83 additions & 5 deletions

File tree

app/build.gradle.kts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,8 @@ android {
1313
applicationId = "io.github.iso53.nothingcompass"
1414
minSdk = 27
1515
targetSdk = 36
16-
versionCode = 2
17-
versionName = "1.2.0"
16+
versionCode = 3
17+
versionName = "1.3.0"
1818

1919
testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner"
2020
}

app/src/main/java/io/github/iso53/nothingcompass/OptionsActivity.java

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,8 @@ private void setupRecyclerView() {
6969
v -> showThemeSelectionDialog()));
7070
items.add(new OptionItem(getString(R.string.item_haptic_feedback), null,
7171
R.drawable.ic_vibration, v -> showHapticFeedbackSelectionDialog()));
72+
items.add(new OptionItem(getString(R.string.item_high_precision), null,
73+
R.drawable.precision, v -> showHighPrecisionSelectionDialog()));
7274
items.add(new OptionItem(getString(R.string.item_north_reference), null,
7375
R.drawable.ic_compass, v -> showNorthReferenceSelectionDialog()));
7476

@@ -152,6 +154,23 @@ private void showHapticFeedbackSelectionDialog() {
152154
}).show();
153155
}
154156

157+
private void showHighPrecisionSelectionDialog() {
158+
String[] options = {getString(R.string.high_precision_on),
159+
getString(R.string.high_precision_off)};
160+
161+
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(this);
162+
boolean currentHighPrecision = prefs.getBoolean(PreferenceConstants.HIGH_PRECISION, false);
163+
164+
int checkedItem = currentHighPrecision ? 0 : 1;
165+
166+
new MaterialAlertDialogBuilder(this).setTitle(R.string.item_high_precision)
167+
.setSingleChoiceItems(options, checkedItem, (dialog, which) -> {
168+
boolean enabled = (which == 0);
169+
prefs.edit().putBoolean(PreferenceConstants.HIGH_PRECISION, enabled).apply();
170+
dialog.dismiss();
171+
}).show();
172+
}
173+
155174
private void openPlayStore() {
156175
String packageName = getPackageName();
157176
try {

app/src/main/java/io/github/iso53/nothingcompass/fragment/InclinometerFragment.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,10 @@ public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle sa
4747
levelMeterView.setHapticFeedbackEnabled(enabled);
4848
});
4949

50+
preferenceStore.getHighPrecision().observe(getViewLifecycleOwner(), enabled -> {
51+
levelMeterView.setHighPrecisionEnabled(enabled);
52+
});
53+
5054
// Initially show inclinometer, hide level meter
5155
inclinometerView.setAlpha(1f);
5256
inclinometerView.setIsActive(true);

app/src/main/java/io/github/iso53/nothingcompass/preference/PreferenceConstants.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,4 +9,5 @@ private PreferenceConstants() {
99
public static final String APP_LAUNCH_COUNT = "app_launch_count";
1010
public static final String HAS_ASKED_FOR_REVIEW = "has_asked_for_review";
1111
public static final String THEME = "theme";
12+
public static final String HIGH_PRECISION = "high_precision";
1213
}

app/src/main/java/io/github/iso53/nothingcompass/preference/PreferenceStore.java

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,12 +17,14 @@ public class PreferenceStore {
1717

1818
private final MutableLiveData<Boolean> trueNorth = new MutableLiveData<>();
1919
private final MutableLiveData<Boolean> hapticFeedback = new MutableLiveData<>();
20+
private final MutableLiveData<Boolean> highPrecision = new MutableLiveData<>();
2021

2122
private final SharedPreferences sharedPreferences;
2223

2324
private final SharedPreferences.OnSharedPreferenceChangeListener sharedPreferenceChangeListener;
2425
private final Observer<Boolean> trueNorthObserver;
2526
private final Observer<Boolean> hapticFeedbackObserver;
27+
private final Observer<Boolean> highPrecisionObserver;
2628

2729
public PreferenceStore(@NonNull Context context, @NonNull Lifecycle lifecycle) {
2830
this.sharedPreferences = PreferenceManager.getDefaultSharedPreferences(context);
@@ -37,6 +39,9 @@ public PreferenceStore(@NonNull Context context, @NonNull Lifecycle lifecycle) {
3739
case PreferenceConstants.HAPTIC_FEEDBACK:
3840
updateHapticFeedback();
3941
break;
42+
case PreferenceConstants.HIGH_PRECISION:
43+
updateHighPrecision();
44+
break;
4045
}
4146
};
4247

@@ -50,14 +55,21 @@ public PreferenceStore(@NonNull Context context, @NonNull Lifecycle lifecycle) {
5055
Log.d(TAG, "Persisted hapticFeedback: " + value);
5156
};
5257

58+
this.highPrecisionObserver = value -> {
59+
sharedPreferences.edit().putBoolean(PreferenceConstants.HIGH_PRECISION, value).apply();
60+
Log.d(TAG, "Persisted highPrecision: " + value);
61+
};
62+
5363
updateTrueNorth();
5464
updateHapticFeedback();
65+
updateHighPrecision();
5566

5667
lifecycle.addObserver(new DefaultLifecycleObserver() {
5768
@Override
5869
public void onCreate(@NonNull LifecycleOwner owner) {
5970
trueNorth.observeForever(trueNorthObserver);
6071
hapticFeedback.observeForever(hapticFeedbackObserver);
72+
highPrecision.observeForever(highPrecisionObserver);
6173

6274
sharedPreferences.registerOnSharedPreferenceChangeListener(sharedPreferenceChangeListener);
6375
}
@@ -68,6 +80,7 @@ public void onDestroy(@NonNull LifecycleOwner owner) {
6880

6981
trueNorth.removeObserver(trueNorthObserver);
7082
hapticFeedback.removeObserver(hapticFeedbackObserver);
83+
highPrecision.removeObserver(highPrecisionObserver);
7184
}
7285
});
7386
}
@@ -80,6 +93,10 @@ public MutableLiveData<Boolean> getHapticFeedback() {
8093
return hapticFeedback;
8194
}
8295

96+
public MutableLiveData<Boolean> getHighPrecision() {
97+
return highPrecision;
98+
}
99+
83100
private void updateTrueNorth() {
84101
boolean storedValue = sharedPreferences.getBoolean(PreferenceConstants.TRUE_NORTH, false);
85102
if (!Boolean.valueOf(storedValue).equals(trueNorth.getValue())) {
@@ -93,4 +110,11 @@ private void updateHapticFeedback() {
93110
hapticFeedback.setValue(storedValue);
94111
}
95112
}
113+
114+
private void updateHighPrecision() {
115+
boolean storedValue = sharedPreferences.getBoolean(PreferenceConstants.HIGH_PRECISION, false);
116+
if (!Boolean.valueOf(storedValue).equals(highPrecision.getValue())) {
117+
highPrecision.setValue(storedValue);
118+
}
119+
}
96120
}

app/src/main/java/io/github/iso53/nothingcompass/view/LevelMeterView.java

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ public class LevelMeterView extends FrameLayout {
4949
private int lastVibrationDegree = 0;
5050
private boolean isActive = false;
5151
private boolean isHapticFeedbackEnabled = true;
52+
private boolean isHighPrecisionEnabled = false;
5253

5354
public LevelMeterView(Context c, AttributeSet a) {
5455
super(c, a);
@@ -220,6 +221,11 @@ public void setHapticFeedbackEnabled(boolean enabled) {
220221
this.isHapticFeedbackEnabled = enabled;
221222
}
222223

224+
public void setHighPrecisionEnabled(boolean enabled) {
225+
this.isHighPrecisionEnabled = enabled;
226+
invalidate();
227+
}
228+
223229
private void performHapticFeedback() {
224230
Vibrator vibrator = (Vibrator) getContext().getSystemService(Context.VIBRATOR_SERVICE);
225231
if (vibrator != null && vibrator.hasVibrator()) {
@@ -249,13 +255,24 @@ private void updateOrientation() {
249255
}
250256

251257
private void updateDegreeDisplay() {
252-
int displayDegree = calculateDisplayDegree();
258+
float degreeValue = calculateDegreeValue();
259+
String displayDegree;
260+
261+
if (isHighPrecisionEnabled) {
262+
if (Math.abs(degreeValue) < 0.005f) {
263+
degreeValue = 0f;
264+
}
265+
displayDegree = String.format(java.util.Locale.getDefault(), "%.2f", degreeValue);
266+
} else {
267+
displayDegree = String.valueOf(Math.round(degreeValue));
268+
}
269+
253270
degreeTextView.setTextColor(getDegreeTextColor());
254271
degreeTextView.setText(" " + displayDegree + "°");
255272
degreeTextView.setRotation(spin - 90f);
256273
}
257274

258-
private int calculateDisplayDegree() {
275+
private float calculateDegreeValue() {
259276
// Calculate angle relative to nearest 90-degree orientation (0, 90, 180, 270)
260277
float normalizedSpin = normalizeAngle(spin, 360f);
261278
float angleFromNearest90 = normalizedSpin % 90f;
@@ -268,7 +285,7 @@ private int calculateDisplayDegree() {
268285
degreeValue = angleFromNearest90 - 90f; // 45 to 90 becomes -45 to 0
269286
}
270287

271-
return Math.round(degreeValue);
288+
return degreeValue;
272289
}
273290

274291
// Color helper methods
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
<vector xmlns:android="http://schemas.android.com/apk/res/android"
2+
android:width="24dp"
3+
android:height="24dp"
4+
android:viewportWidth="960"
5+
android:viewportHeight="960"
6+
android:tint="?attr/colorControlNormal">
7+
<path
8+
android:fillColor="@android:color/white"
9+
android:pathData="M200,840Q167,840 143.5,816.5Q120,793 120,760L120,600L200,600L200,760Q200,760 200,760Q200,760 200,760L360,760L360,840L200,840ZM600,840L600,760L760,760Q760,760 760,760Q760,760 760,760L760,600L840,600L840,760Q840,793 816.5,816.5Q793,840 760,840L600,840ZM120,360L120,200Q120,167 143.5,143.5Q167,120 200,120L360,120L360,200L200,200Q200,200 200,200Q200,200 200,200L200,360L120,360ZM760,360L760,200Q760,200 760,200Q760,200 760,200L600,200L600,120L760,120Q793,120 816.5,143.5Q840,167 840,200L840,360L760,360ZM338.5,621.5Q280,563 280,480Q280,397 338.5,338.5Q397,280 480,280Q563,280 621.5,338.5Q680,397 680,480Q680,563 621.5,621.5Q563,680 480,680Q397,680 338.5,621.5ZM565,565Q600,530 600,480Q600,430 565,395Q530,360 480,360Q430,360 395,395Q360,430 360,480Q360,530 395,565Q430,600 480,600Q530,600 565,565ZM480,480Q480,480 480,480Q480,480 480,480Q480,480 480,480Q480,480 480,480Q480,480 480,480Q480,480 480,480Q480,480 480,480Q480,480 480,480Z"/>
10+
</vector>

app/src/main/res/values/strings.xml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,9 @@
6565
<string name="item_haptic_feedback">Haptic feedback</string>
6666
<string name="haptic_feedback_on">On</string>
6767
<string name="haptic_feedback_off">Off</string>
68+
<string name="item_high_precision">High precision</string>
69+
<string name="high_precision_on">On</string>
70+
<string name="high_precision_off">Off</string>
6871
<string name="item_north_reference">Compass Reference</string>
6972
<string name="north_reference_true">True North</string>
7073
<string name="north_reference_magnetic">Magnetic North</string>

0 commit comments

Comments
 (0)