Skip to content

Satellite tracker and pass predictor for Android, inspired by Gpredict

Setting up the androidx preference library SettingsFragment

Arty Bishop4e4256bc3f00
diff --git a/app/src/main/java/com/rtbishop/lookingsat/ui/SettingsFragment.kt b/app/src/main/java/com/rtbishop/lookingsat/ui/SettingsFragment.kt
new file mode 100644
index 00000000..ff1844e6
--- /dev/null
+++ b/app/src/main/java/com/rtbishop/lookingsat/ui/SettingsFragment.kt
@@ -0,0 +1,11 @@
+package com.rtbishop.lookingsat.ui
+
+import android.os.Bundle
+import androidx.preference.PreferenceFragmentCompat
+import com.rtbishop.lookingsat.R
+
+class SettingsFragment : PreferenceFragmentCompat() {
+ override fun onCreatePreferences(savedInstanceState: Bundle?, rootKey: String?) {
+ setPreferencesFromResource(R.xml.preference, rootKey)
+ }
+}
\ No newline at end of file
diff --git a/app/src/main/res/drawable/ic_settings.xml b/app/src/main/res/drawable/ic_settings.xml
new file mode 100644
index 00000000..cbdab599
--- /dev/null
+++ b/app/src/main/res/drawable/ic_settings.xml
@@ -0,0 +1,9 @@
+<vector xmlns:android="http://schemas.android.com/apk/res/android"
+ android:width="32dp"
+ android:height="32dp"
+ android:viewportWidth="24"
+ android:viewportHeight="24">
+ <path
+ android:fillColor="#FF000000"
+ android:pathData="M19.1,12.9a2.8,2.8 0,0 0,0.1 -0.9,2.8 2.8,0 0,0 -0.1,-0.9l2.1,-1.6a0.7,0.7 0,0 0,0.1 -0.6L19.4,5.5a0.7,0.7 0,0 0,-0.6 -0.2l-2.4,1a6.5,6.5 0,0 0,-1.6 -0.9l-0.4,-2.6a0.5,0.5 0,0 0,-0.5 -0.4H10.1a0.5,0.5 0,0 0,-0.5 0.4L9.3,5.4a5.6,5.6 0,0 0,-1.7 0.9l-2.4,-1a0.4,0.4 0,0 0,-0.5 0.2l-2,3.4c-0.1,0.2 0,0.4 0.2,0.6l2,1.6a2.8,2.8 0,0 0,-0.1 0.9,2.8 2.8,0 0,0 0.1,0.9L2.8,14.5a0.7,0.7 0,0 0,-0.1 0.6l1.9,3.4a0.7,0.7 0,0 0,0.6 0.2l2.4,-1a6.5,6.5 0,0 0,1.6 0.9l0.4,2.6a0.5,0.5 0,0 0,0.5 0.4h3.8a0.5,0.5 0,0 0,0.5 -0.4l0.3,-2.6a5.6,5.6 0,0 0,1.7 -0.9l2.4,1a0.4,0.4 0,0 0,0.5 -0.2l2,-3.4c0.1,-0.2 0,-0.4 -0.2,-0.6ZM12,15.6A3.6,3.6 0,1 1,15.6 12,3.6 3.6,0 0,1 12,15.6Z" />
+</vector>
diff --git a/app/src/main/res/menu/drawer_menu.xml b/app/src/main/res/menu/drawer_menu.xml
index f5cb3149..f46d2622 100644
--- a/app/src/main/res/menu/drawer_menu.xml
+++ b/app/src/main/res/menu/drawer_menu.xml
@@ -13,12 +13,16 @@
android:icon="@drawable/ic_map"
android:title="@string/menu_map" />
<item
- android:id="@+id/nav_credits"
- android:icon="@drawable/ic_credits"
- android:title="@string/menu_credits" />
+ android:id="@+id/nav_settings"
+ android:icon="@drawable/ic_settings"
+ android:title="@string/menu_settings" />
<item
android:id="@+id/nav_about"
android:icon="@drawable/ic_about"
android:title="@string/menu_about" />
+ <item
+ android:id="@+id/nav_credits"
+ android:icon="@drawable/ic_credits"
+ android:title="@string/menu_credits" />
</group>
</menu>
diff --git a/app/src/main/res/navigation/nav_graph.xml b/app/src/main/res/navigation/nav_graph.xml
index 5177e6cf..1783d10b 100644
--- a/app/src/main/res/navigation/nav_graph.xml
+++ b/app/src/main/res/navigation/nav_graph.xml
@@ -43,4 +43,9 @@
android:label="@string/menu_credits"
tools:layout="@layout/fragment_credits" />
+ <fragment
+ android:id="@+id/nav_settings"
+ android:name="com.rtbishop.lookingsat.ui.SettingsFragment"
+ android:label="@string/menu_settings" />
+
</navigation>
\ No newline at end of file
diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml
index 2c12f9a9..d780b73b 100644
--- a/app/src/main/res/values/strings.xml
+++ b/app/src/main/res/values/strings.xml
@@ -64,4 +64,5 @@
<string name="map_content">Nasa Map</string>
<string name="placeholder">Placeholder</string>
+ <string name="menu_settings">Settings</string>
</resources>
diff --git a/app/src/main/res/xml/preference.xml b/app/src/main/res/xml/preference.xml
new file mode 100644
index 00000000..e968c100
--- /dev/null
+++ b/app/src/main/res/xml/preference.xml
@@ -0,0 +1,48 @@
+<?xml version="1.0" encoding="utf-8"?>
+<PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android">
+ <PreferenceCategory android:title="Ground station location settings">
+ <EditTextPreference
+ android:defaultValue="0.0"
+ android:key="lat"
+ android:selectAllOnFocus="true"
+ android:singleLine="true"
+ android:title="Latitude" />
+ <EditTextPreference
+ android:defaultValue="0.0"
+ android:key="lon"
+ android:selectAllOnFocus="true"
+ android:singleLine="true"
+ android:title="Longitude" />
+ <EditTextPreference
+ android:defaultValue="0.0"
+ android:key="alt"
+ android:selectAllOnFocus="true"
+ android:singleLine="true"
+ android:title="Altitude" />
+ </PreferenceCategory>
+ <PreferenceCategory android:title="Satellite pass settings">
+ <EditTextPreference
+ android:defaultValue="8"
+ android:key="hours"
+ android:selectAllOnFocus="true"
+ android:singleLine="true"
+ android:summary="Show passes that occur within this time window"
+ android:title="Hours ahead" />
+ <EditTextPreference
+ android:defaultValue="16"
+ android:key="minEl"
+ android:selectAllOnFocus="true"
+ android:singleLine="true"
+ android:summary="Show passes with maximum elevation above"
+ android:title="Minimum elevation" />
+ </PreferenceCategory>
+ <PreferenceCategory android:title="Other settings">
+ <EditTextPreference
+ android:defaultValue="3000"
+ android:key="updateFreq"
+ android:selectAllOnFocus="true"
+ android:singleLine="true"
+ android:summary="RadarView and MapView update frequency, ms"
+ android:title="View update interval" />
+ </PreferenceCategory>
+</PreferenceScreen>
\ No newline at end of file