Skip to content

Commit

Permalink
Merge pull request #436 from this-Aditya/location-broadcast
Browse files Browse the repository at this point in the history
LocalBroadcastManager will broadcast the location change
  • Loading branch information
this-Aditya authored Nov 1, 2023
2 parents 45f723d + f3265bd commit 8c6c6b7
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 0 deletions.
2 changes: 2 additions & 0 deletions plugins/radar-android-phone/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ description = 'Basic phone sensor plugin for RADAR passive remote monitoring app

dependencies {
api project(':radar-commons-android')
implementation 'androidx.localbroadcastmanager:localbroadcastmanager:1.1.0'
implementation project(path: ':radar-android-google-places')
}

apply from: "$rootDir/gradle/publishing.gradle"
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import android.location.LocationListener
import android.location.LocationManager
import android.os.Bundle
import android.os.Process
import androidx.localbroadcastmanager.content.LocalBroadcastManager
import org.radarbase.android.data.DataCache
import org.radarbase.android.source.AbstractSourceManager
import org.radarbase.android.source.BaseSourceState
Expand All @@ -32,6 +33,8 @@ import org.radarbase.android.util.BatteryStageReceiver
import org.radarbase.android.util.ChangeRunner
import org.radarbase.android.util.SafeHandler
import org.radarbase.android.util.StageLevels
import org.radarbase.android.util.send
import org.radarbase.passive.google.places.GooglePlacesManager.Companion.DEVICE_LOCATION_CHANGED
import org.radarbase.passive.phone.PhoneLocationService.Companion.LOCATION_GPS_INTERVAL_DEFAULT
import org.radarbase.passive.phone.PhoneLocationService.Companion.LOCATION_GPS_INTERVAL_REDUCED_DEFAULT
import org.radarbase.passive.phone.PhoneLocationService.Companion.LOCATION_NETWORK_INTERVAL_DEFAULT
Expand All @@ -55,6 +58,7 @@ class PhoneLocationManager(context: PhoneLocationService) : AbstractSourceManage
private val intervals = ChangeRunner(LocationPollingIntervals())
private var isStarted: Boolean = false
private var referenceId: Int = 0
private lateinit var broadcaster: LocalBroadcastManager
@Volatile
var isAbsoluteLocation: Boolean = false

Expand Down Expand Up @@ -101,6 +105,7 @@ class PhoneLocationManager(context: PhoneLocationService) : AbstractSourceManage
handler.start()

status = SourceStatusListener.Status.READY
broadcaster = LocalBroadcastManager.getInstance(service)

handler.execute {
isStarted = true
Expand Down Expand Up @@ -136,6 +141,7 @@ class PhoneLocationManager(context: PhoneLocationService) : AbstractSourceManage
altitude?.normalize(), accuracy?.normalize(), speed?.normalize(), bearing?.normalize())
send(locationTopic, value)

broadcaster.send(DEVICE_LOCATION_CHANGED)
logger.info("Location: {} {} {} {} {} {} {} {} {}", provider, eventTimestamp, latitude,
longitude, accuracy, altitude, speed, bearing, timestamp)
}
Expand Down

0 comments on commit 8c6c6b7

Please sign in to comment.