Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion app/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ android {
minSdk = 27
targetSdk = 36
versionCode = 1
versionName = "1.1.0"
versionName = "1.2.0"

testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner"
}
Expand Down
1 change: 1 addition & 0 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
<manifest xmlns:android="http://schemas.android.com/apk/res/android">

<uses-permission android:name="android.permission.VIBRATE" />
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"/>

<application
android:allowBackup="true"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,8 @@ private void setupRecyclerView() {
v -> showThemeSelectionDialog()));
items.add(new OptionItem(getString(R.string.item_haptic_feedback), null,
R.drawable.ic_vibration, v -> showHapticFeedbackSelectionDialog()));
items.add(new OptionItem(getString(R.string.item_north_reference), null,
R.drawable.ic_compass, v -> showNorthReferenceSelectionDialog()));

// Category: App
items.add(new OptionItem(getString(R.string.category_app)));
Expand Down Expand Up @@ -200,4 +202,57 @@ private void sendFeedbackEmail() {
openUrl("https://github.com/iso53/Nothing-Compass/issues");
}
}

private final androidx.activity.result.ActivityResultLauncher<String> requestPermissionLauncher = registerForActivityResult(
new androidx.activity.result.contract.ActivityResultContracts.RequestPermission(),
isGranted -> {
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(this);
if (isGranted) {
prefs.edit().putBoolean(PreferenceConstants.TRUE_NORTH, true).apply();
} else {
android.widget.Toast.makeText(this, R.string.access_location_permission_denied,
android.widget.Toast.LENGTH_SHORT).show();
}
});

private void showNorthReferenceSelectionDialog() {
String[] options = {getString(R.string.north_reference_true),
getString(R.string.north_reference_magnetic)};

SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(this);
boolean isTrueNorth = prefs.getBoolean(PreferenceConstants.TRUE_NORTH, false);

int checkedItem = isTrueNorth ? 0 : 1;

new MaterialAlertDialogBuilder(this)
.setTitle(R.string.item_north_reference)
.setSingleChoiceItems(options, checkedItem, (dialog, which) -> {
if (which == 0) {
// True North selected
if (androidx.core.content.ContextCompat.checkSelfPermission(this,
android.Manifest.permission.ACCESS_FINE_LOCATION) == android.content.pm.PackageManager.PERMISSION_GRANTED) {
prefs.edit().putBoolean(PreferenceConstants.TRUE_NORTH, true).apply();
} else {
requestPermissionLauncher.launch(android.Manifest.permission.ACCESS_FINE_LOCATION);
}
dialog.dismiss();
} else {
// Magnetic North selected
prefs.edit().putBoolean(PreferenceConstants.TRUE_NORTH, false).apply();
dialog.dismiss();
}
})
.setNeutralButton(R.string.north_reference_explanation_title,
(dialog, which) -> showNorthReferenceExplanationDialog())
.setNegativeButton(android.R.string.cancel, null)
.show();
}

private void showNorthReferenceExplanationDialog() {
new MaterialAlertDialogBuilder(this)
.setTitle(R.string.north_reference_explanation_title)
.setMessage(R.string.north_reference_explanation_message)
.setPositiveButton(android.R.string.ok, null)
.show();
}
}
10 changes: 10 additions & 0 deletions app/src/main/res/drawable/ic_compass.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="24dp"
android:height="24dp"
android:viewportWidth="960"
android:viewportHeight="960"
android:tint="?attr/colorControlNormal">
<path
android:fillColor="@android:color/white"
android:pathData="M300,660L580,580L660,300L380,380L300,660ZM480,540Q455,540 437.5,522.5Q420,505 420,480Q420,455 437.5,437.5Q455,420 480,420Q505,420 522.5,437.5Q540,455 540,480Q540,505 522.5,522.5Q505,540 480,540ZM480,880Q397,880 324,848.5Q251,817 197,763Q143,709 111.5,636Q80,563 80,480Q80,397 111.5,324Q143,251 197,197Q251,143 324,111.5Q397,80 480,80Q563,80 636,111.5Q709,143 763,197Q817,251 848.5,324Q880,397 880,480Q880,563 848.5,636Q817,709 763,763Q709,817 636,848.5Q563,880 480,880ZM480,800Q613,800 706.5,706.5Q800,613 800,480Q800,347 706.5,253.5Q613,160 480,160Q347,160 253.5,253.5Q160,347 160,480Q160,613 253.5,706.5Q347,800 480,800ZM480,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"/>
</vector>
7 changes: 7 additions & 0 deletions app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -65,5 +65,12 @@
<string name="item_haptic_feedback">Haptic feedback</string>
<string name="haptic_feedback_on">On</string>
<string name="haptic_feedback_off">Off</string>
<string name="item_north_reference">Compass Reference</string>
<string name="north_reference_true">True North</string>
<string name="north_reference_magnetic">Magnetic North</string>
<string name="north_reference_explanation_title">What is this?</string>
<string name="north_reference_explanation_message">True North points to the geographic North Pole.\n\nMagnetic North points to the Magnetic North Pole, which shifts over time.\n\nThe difference is the magnetic declination, which depends on your location.</string>
<string name="north_reference_permission_warning">Using True North requires location access to calculate the magnetic declination.</string>
<string name="north_reference_permission_button">Enable Location</string>
<string name="options">Options</string>
</resources>