Add preference "Allow sleep at homepoints and in deadzones".
This commit is contained in:
parent
eec0caf59d
commit
a0e1fb8d8b
4 changed files with 30 additions and 5 deletions
|
@ -56,6 +56,7 @@ object Keys {
|
|||
const val PREF_LOCATION_NETWORK: String = "prefLocationNetwork"
|
||||
const val PREF_LOCATION_GPS: String = "prefLocationGPS"
|
||||
const val PREF_OMIT_RESTS: String = "prefOmitRests"
|
||||
const val PREF_ALLOW_SLEEP: String = "prefAllowSleep"
|
||||
const val PREF_DEVICE_ID: String = "prefDeviceID"
|
||||
const val PREF_DATABASE_DIRECTORY: String = "prefDatabaseDirectory"
|
||||
|
||||
|
@ -104,6 +105,7 @@ object Keys {
|
|||
const val DEFAULT_THRESHOLD_DISTANCE: Float = 15f // 15 meters
|
||||
const val DEFAULT_ZOOM_LEVEL: Double = 16.0
|
||||
const val DEFAULT_OMIT_RESTS: Boolean = true
|
||||
const val DEFAULT_ALLOW_SLEEP: Boolean = true
|
||||
const val ALTITUDE_MEASUREMENT_ERROR_THRESHOLD = 10 // altitude changes of 10 meter or more (per 15 seconds) are being discarded
|
||||
|
||||
// notification
|
||||
|
|
|
@ -22,8 +22,6 @@ package net.voussoir.trkpt
|
|||
|
||||
import YesNoDialog
|
||||
import android.app.Activity
|
||||
import android.content.ClipData
|
||||
import android.content.ClipboardManager
|
||||
import android.content.Context
|
||||
import android.content.Intent
|
||||
import android.net.Uri
|
||||
|
@ -34,7 +32,6 @@ import android.provider.DocumentsContract
|
|||
import android.provider.Settings
|
||||
import android.util.Log
|
||||
import android.view.View
|
||||
import android.widget.Toast
|
||||
import androidx.activity.result.contract.ActivityResultContracts
|
||||
import androidx.preference.EditTextPreference
|
||||
import androidx.preference.ListPreference
|
||||
|
@ -132,6 +129,17 @@ class SettingsFragment : PreferenceFragmentCompat(), YesNoDialog.YesNoDialogList
|
|||
preferenceCategoryGeneral.contains(preferenceOmitRests)
|
||||
screen.addPreference(preferenceOmitRests)
|
||||
|
||||
val prefAllowSleep = SwitchPreferenceCompat(activity as Context)
|
||||
prefAllowSleep.isSingleLineTitle = false
|
||||
prefAllowSleep.title = "Allow sleep at homepoints and in deadzones"
|
||||
prefAllowSleep.setIcon(R.drawable.ic_sleep_24dp)
|
||||
prefAllowSleep.key = Keys.PREF_ALLOW_SLEEP
|
||||
prefAllowSleep.summaryOn = "trkpt will fall asleep near homepoints or when location fixes are completely unavailable. The motion sensor will wake it."
|
||||
prefAllowSleep.summaryOff = "trkpt will never fall asleep, tracking will always run at full power."
|
||||
prefAllowSleep.setDefaultValue(Keys.DEFAULT_ALLOW_SLEEP)
|
||||
preferenceCategoryGeneral.contains(prefAllowSleep)
|
||||
screen.addPreference(prefAllowSleep)
|
||||
|
||||
val preferenceDeviceID = EditTextPreference(activity as Context)
|
||||
preferenceDeviceID.title = getString(R.string.pref_device_id)
|
||||
preferenceDeviceID.setIcon(R.drawable.ic_smartphone_24dp)
|
||||
|
|
|
@ -60,6 +60,7 @@ class TrackerService: Service()
|
|||
var trackingState: Int = Keys.STATE_TRACKING_STOPPED
|
||||
var useImperial: Boolean = false
|
||||
var omitRests: Boolean = true
|
||||
var allow_sleep: Boolean = true
|
||||
var device_id: String = random_device_id()
|
||||
var currentBestLocation: Location = getDefaultLocation()
|
||||
var lastCommit: Long = 0
|
||||
|
@ -282,7 +283,7 @@ class TrackerService: Service()
|
|||
// that immediately fetches a new location.
|
||||
// If we cannot rely on the motion sensor, then don't sleep!
|
||||
}
|
||||
else if ((System.currentTimeMillis() - arrived_at_home) > Keys.ONE_MINUTE_IN_MILLISECONDS)
|
||||
else if (allow_sleep && (System.currentTimeMillis() - arrived_at_home) > Keys.ONE_MINUTE_IN_MILLISECONDS)
|
||||
{
|
||||
Log.i("VOUSSOIR", "Staying at home, sleeping.")
|
||||
reset_location_listeners(interval=LOCATION_INTERVAL_SLEEP)
|
||||
|
@ -497,6 +498,7 @@ class TrackerService: Service()
|
|||
device_id = PreferencesHelper.load_device_id()
|
||||
useImperial = PreferencesHelper.loadUseImperialUnits()
|
||||
omitRests = PreferencesHelper.loadOmitRests()
|
||||
allow_sleep = PreferencesHelper.loadAllowSleep()
|
||||
locationManager = getSystemService(Context.LOCATION_SERVICE) as LocationManager
|
||||
notificationManager = getSystemService(Context.NOTIFICATION_SERVICE) as NotificationManager
|
||||
notification_builder = NotificationCompat.Builder(this, Keys.NOTIFICATION_CHANNEL_RECORDING)
|
||||
|
@ -627,6 +629,14 @@ class TrackerService: Service()
|
|||
{
|
||||
omitRests = PreferencesHelper.loadOmitRests()
|
||||
}
|
||||
Keys.PREF_ALLOW_SLEEP ->
|
||||
{
|
||||
allow_sleep = PreferencesHelper.loadAllowSleep()
|
||||
if (! allow_sleep && location_interval != LOCATION_INTERVAL_FULL_POWER)
|
||||
{
|
||||
reset_location_listeners(LOCATION_INTERVAL_FULL_POWER)
|
||||
}
|
||||
}
|
||||
Keys.PREF_DEVICE_ID ->
|
||||
{
|
||||
device_id = PreferencesHelper.load_device_id()
|
||||
|
@ -651,6 +661,7 @@ class TrackerService: Service()
|
|||
struggletime = 4 * Keys.ONE_MINUTE_IN_MILLISECONDS
|
||||
}
|
||||
if (
|
||||
allow_sleep &&
|
||||
trackingState == Keys.STATE_TRACKING_ACTIVE &&
|
||||
location_interval != LOCATION_INTERVAL_GIVE_UP &&
|
||||
significant_motion_sensor != null &&
|
||||
|
|
|
@ -98,7 +98,11 @@ object PreferencesHelper
|
|||
}
|
||||
|
||||
fun loadOmitRests(): Boolean {
|
||||
return sharedPreferences.getBoolean(Keys.PREF_OMIT_RESTS, true)
|
||||
return sharedPreferences.getBoolean(Keys.PREF_OMIT_RESTS, Keys.DEFAULT_OMIT_RESTS)
|
||||
}
|
||||
|
||||
fun loadAllowSleep(): Boolean {
|
||||
return sharedPreferences.getBoolean(Keys.PREF_ALLOW_SLEEP, Keys.DEFAULT_ALLOW_SLEEP)
|
||||
}
|
||||
|
||||
/* Loads the state of a map */
|
||||
|
|
Loading…
Reference in a new issue