Add preference to show debug information on main screen.

This commit is contained in:
voussoir 2023-04-02 16:13:56 -07:00
parent eff08eb375
commit 531ff36ed0
7 changed files with 52 additions and 13 deletions

View file

@ -61,6 +61,7 @@ object Keys {
const val PREF_LOCATION_GPS: String = "prefLocationGPS" const val PREF_LOCATION_GPS: String = "prefLocationGPS"
const val PREF_OMIT_RESTS: String = "prefOmitRests" const val PREF_OMIT_RESTS: String = "prefOmitRests"
const val PREF_ALLOW_SLEEP: String = "prefAllowSleep" const val PREF_ALLOW_SLEEP: String = "prefAllowSleep"
const val PREF_SHOW_DEBUG: String = "prefShowDebug"
const val PREF_DEVICE_ID: String = "prefDeviceID" const val PREF_DEVICE_ID: String = "prefDeviceID"
const val PREF_DATABASE_DIRECTORY: String = "prefDatabaseDirectory" const val PREF_DATABASE_DIRECTORY: String = "prefDatabaseDirectory"
@ -106,6 +107,7 @@ object Keys {
const val DEFAULT_ZOOM_LEVEL: Double = 16.0 const val DEFAULT_ZOOM_LEVEL: Double = 16.0
const val DEFAULT_OMIT_RESTS: Boolean = true const val DEFAULT_OMIT_RESTS: Boolean = true
const val DEFAULT_ALLOW_SLEEP: Boolean = true const val DEFAULT_ALLOW_SLEEP: Boolean = true
const val DEFAULT_SHOW_DEBUG: Boolean = false
// notification // notification
const val TRACKER_SERVICE_NOTIFICATION_ID: Int = 1 const val TRACKER_SERVICE_NOTIFICATION_ID: Int = 1

View file

@ -63,6 +63,7 @@ class MapFragment : Fragment()
var continuous_auto_center: Boolean = true var continuous_auto_center: Boolean = true
private var trackerService: TrackerService? = null private var trackerService: TrackerService? = null
private lateinit var database_changed_listener: DatabaseChangedListener private lateinit var database_changed_listener: DatabaseChangedListener
var show_debug: Boolean = false
var thismapfragment: MapFragment? = null var thismapfragment: MapFragment? = null
lateinit var rootView: View lateinit var rootView: View
@ -226,6 +227,8 @@ class MapFragment : Fragment()
mapView.controller.setZoom(mapView.zoomLevelDouble - 0.5) mapView.controller.setZoom(mapView.zoomLevelDouble - 0.5)
} }
show_debug = PreferencesHelper.loadShowDebug()
requireActivity().window.addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON) requireActivity().window.addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON)
handler.post(redraw_runnable) handler.post(redraw_runnable)
return rootView return rootView
@ -360,6 +363,10 @@ class MapFragment : Fragment()
} }
private val sharedPreferenceChangeListener = SharedPreferences.OnSharedPreferenceChangeListener { sharedPreferences, key -> private val sharedPreferenceChangeListener = SharedPreferences.OnSharedPreferenceChangeListener { sharedPreferences, key ->
if (key == Keys.PREF_SHOW_DEBUG)
{
show_debug = sharedPreferences.getBoolean(Keys.PREF_SHOW_DEBUG, Keys.DEFAULT_SHOW_DEBUG)
}
redraw() redraw()
} }
@ -632,7 +639,6 @@ class MapFragment : Fragment()
redraw() redraw()
// register listener for changes in shared preferences // register listener for changes in shared preferences
PreferencesHelper.registerPreferenceChangeListener(sharedPreferenceChangeListener) PreferencesHelper.registerPreferenceChangeListener(sharedPreferenceChangeListener)
// start listening for location updates
} }
override fun onServiceDisconnected(arg0: ComponentName) override fun onServiceDisconnected(arg0: ComponentName)
{ {
@ -662,7 +668,22 @@ class MapFragment : Fragment()
centerMap(tracker.currentBestLocation) centerMap(tracker.currentBestLocation)
} }
map_current_time.text = iso8601_local_noms(tracker.currentBestLocation.time) if (show_debug)
{
map_current_time.text = """
now: ${iso8601_local_noms(System.currentTimeMillis())}
location: ${iso8601_local_noms(tracker.currentBestLocation.time)}
listeners: ${iso8601_local_noms(tracker.listeners_enabled_at)}
motion: ${iso8601_local_noms(tracker.last_significant_motion)}
watchdog: ${iso8601_local_noms(tracker.last_watchdog)}
died: ${iso8601_local_noms(tracker.gave_up_at)}
power: ${tracker.device_is_charging}
""".trimIndent()
}
else
{
map_current_time.text = iso8601_local_noms(tracker.currentBestLocation.time)
}
mapView.invalidate() mapView.invalidate()
} }

View file

@ -139,6 +139,17 @@ class SettingsFragment : PreferenceFragmentCompat()
preferenceCategoryGeneral.contains(prefAllowSleep) preferenceCategoryGeneral.contains(prefAllowSleep)
screen.addPreference(prefAllowSleep) screen.addPreference(prefAllowSleep)
val prefShowDebug = SwitchPreferenceCompat(activity as Context)
prefShowDebug.isSingleLineTitle = false
prefShowDebug.title = "Show debug info"
prefShowDebug.setIcon(R.drawable.ic_bar_chart_24)
prefShowDebug.key = Keys.PREF_SHOW_DEBUG
prefShowDebug.summaryOn = "Debug info shown on map screen."
prefShowDebug.summaryOff = "Debug info hidden."
prefShowDebug.setDefaultValue(Keys.DEFAULT_SHOW_DEBUG)
preferenceCategoryGeneral.contains(prefShowDebug)
screen.addPreference(prefShowDebug)
val preferenceDeviceID = EditTextPreference(activity as Context) val preferenceDeviceID = EditTextPreference(activity as Context)
preferenceDeviceID.title = getString(R.string.pref_device_id) preferenceDeviceID.title = getString(R.string.pref_device_id)
preferenceDeviceID.setIcon(R.drawable.ic_smartphone_24dp) preferenceDeviceID.setIcon(R.drawable.ic_smartphone_24dp)

View file

@ -21,15 +21,8 @@
package net.voussoir.trkpt package net.voussoir.trkpt
import android.Manifest import android.Manifest
import android.app.Notification import android.app.*
import android.app.NotificationChannel import android.content.*
import android.app.NotificationManager
import android.app.PendingIntent
import android.app.Service
import android.app.TaskStackBuilder
import android.content.Context
import android.content.Intent
import android.content.SharedPreferences
import android.content.pm.PackageManager import android.content.pm.PackageManager
import android.hardware.* import android.hardware.*
import android.location.Location import android.location.Location
@ -61,6 +54,8 @@ class TrackerService: Service()
var lastCommit: Long = 0 var lastCommit: Long = 0
var listeners_enabled_at: Long = 0 var listeners_enabled_at: Long = 0
var last_significant_motion: Long = 0 var last_significant_motion: Long = 0
var last_watchdog: Long = 0
var gave_up_at: Long = 0
var arrived_at_home: Long = 0 var arrived_at_home: Long = 0
var location_interval: Long = 0 var location_interval: Long = 0
val TIME_UNTIL_SLEEP: Long = 2 * Keys.ONE_MINUTE_IN_MILLISECONDS val TIME_UNTIL_SLEEP: Long = 2 * Keys.ONE_MINUTE_IN_MILLISECONDS
@ -718,6 +713,7 @@ class TrackerService: Service()
Log.i("VOUSSOIR", "TrackerService.background_watchdog") Log.i("VOUSSOIR", "TrackerService.background_watchdog")
handler.postDelayed(this, WATCHDOG_INTERVAL) handler.postDelayed(this, WATCHDOG_INTERVAL)
val now = System.currentTimeMillis() val now = System.currentTimeMillis()
last_watchdog = now
if ( if (
allow_sleep && allow_sleep &&
has_motion_sensor && has_motion_sensor &&
@ -730,6 +726,7 @@ class TrackerService: Service()
) )
{ {
reset_location_listeners(Keys.LOCATION_INTERVAL_GIVE_UP) reset_location_listeners(Keys.LOCATION_INTERVAL_GIVE_UP)
gave_up_at = now
} }
} }
} }

View file

@ -22,6 +22,10 @@ fun iso8601_local(timestamp: Long): String
fun iso8601_local_noms(timestamp: Long): String fun iso8601_local_noms(timestamp: Long): String
{ {
if (timestamp == 0L)
{
return "0"
}
val iso8601_format = SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss") val iso8601_format = SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss")
return iso8601_format.format(timestamp) return iso8601_format.format(timestamp)
} }

View file

@ -105,6 +105,10 @@ object PreferencesHelper
return sharedPreferences.getBoolean(Keys.PREF_ALLOW_SLEEP, Keys.DEFAULT_ALLOW_SLEEP) return sharedPreferences.getBoolean(Keys.PREF_ALLOW_SLEEP, Keys.DEFAULT_ALLOW_SLEEP)
} }
fun loadShowDebug(): Boolean {
return sharedPreferences.getBoolean(Keys.PREF_SHOW_DEBUG, Keys.DEFAULT_SHOW_DEBUG)
}
/* Loads the state of a map */ /* Loads the state of a map */
fun loadCurrentBestLocation(): Location { fun loadCurrentBestLocation(): Location {
val provider: String = sharedPreferences.getString(Keys.PREF_CURRENT_BEST_LOCATION_PROVIDER, LocationManager.NETWORK_PROVIDER) ?: LocationManager.NETWORK_PROVIDER val provider: String = sharedPreferences.getString(Keys.PREF_CURRENT_BEST_LOCATION_PROVIDER, LocationManager.NETWORK_PROVIDER) ?: LocationManager.NETWORK_PROVIDER

View file

@ -92,11 +92,11 @@
android:layout_width="wrap_content" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_marginTop="16dp" android:layout_marginTop="16dp"
android:gravity="right"
app:fontFamily="monospace" app:fontFamily="monospace"
app:layout_constraintEnd_toEndOf="parent" app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent" app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" app:layout_constraintTop_toTopOf="parent" />
/>
<!-- GROUPS --> <!-- GROUPS -->