package Ġcom . vm w . simple gps . mv vm i Ċ Ċ import Ġandroid . Manifest Ċ import Ġandroid . content . pm . PackageManager Ċ import Ġandroid . location . Location Ċ import Ġandroid . location . Location Manager Ċ import Ġandroidx . appcompat . app . AppCompatActivity Ċ import Ġandroid . os . Bundle Ċ import Ġandroid . util . Log Ċ import Ġandroid . view . View Ċ import Ġandroid . widget . Image Button Ċ import Ġandroid . widget . RadioButton Ċ import Ġandroid . widget . Radio Group Ċ import Ġandroid . widget . TextView Ċ import Ġandroidx . core . content . Context Compat Ċ import Ġandroidx . lifecycle . Observer Ċ import Ġcom . google . android . material . floating action button . Floating ActionButton Ċ import Ġcom . google . android . material . sn ackbar . Snackbar Ċ import Ġcom . vm w . simple gps . R Ċ import Ġcom . vm w . simple gps . location . Locator Manager Ċ import Ġkotlinx . coroutines .* Ċ import Ġjava . text . DateFormat Ċ Ċ private Ġconst Ġval ĠTAG Ġ= Ġ" Location Activity " Ċ Ċ class ĠLocation Activity Ġ: ĠAppCompatActivity (), ĠView . OnClickListener , ĠRadio Group . On Checked ChangeListener Ġ{ ĊĊĠĠĠ Ġprivate Ġlateinit Ġvar Ġget Location Btn : ĠFloating ActionButton ĊĠĠĠ Ġprivate Ġlateinit Ġvar Ġlocation Manager Last Known Status : ĠTextView ĊĠĠĠ Ġprivate Ġlateinit Ġvar Ġlocation Manager Last Known Location Txt : ĠTextView ĊĠĠĠ Ġprivate Ġlateinit Ġvar Ġlocation Manager Single Update Status : ĠTextView ĊĠĠĠ Ġprivate Ġlateinit Ġvar Ġlocation Manager Single Update Location Txt : ĠTextView ĊĠĠĠ Ġprivate Ġlateinit Ġvar Ġlocation Manager Multiple Update Status : ĠTextView ĊĠĠĠ Ġprivate Ġlateinit Ġvar Ġlocation Manager Multiple Update Location Txt : ĠTextView ĊĠĠĠ Ġprivate Ġlateinit Ġvar Ġfusion Provider Last Known Status : ĠTextView ĊĠĠĠ Ġprivate Ġlateinit Ġvar Ġfusion Provider Last Known Location Txt : ĠTextView ĊĠĠĠ Ġprivate Ġlateinit Ġvar Ġfusion Provider Multiple Update Status : ĠTextView ĊĠĠĠ Ġprivate Ġlateinit Ġvar Ġfusion Provider Multiple Update Location Txt : ĠTextView ĊĠĠĠ Ġprivate Ġlateinit Ġvar Ġlocation Provider Radio Group : ĠRadio Group ĊĠĠĠ Ġprivate Ġlateinit Ġvar Ġsync Provider Status Button : ĠImage Button ĊĠĠĠ Ġprivate Ġlateinit Ġvar Ġgps Provider RadioButton : ĠRadio Button ĊĠĠĠ Ġprivate Ġlateinit Ġvar Ġnetwork Provider RadioButton : ĠRadio Button ĊĠĠĠ Ġprivate Ġlateinit Ġvar Ġpassive Provider RadioButton : ĠRadio Button ĊĠĠĠ Ġprivate Ġlateinit Ġvar ĠviewModel : ĠLocation ViewModel ĊĠĠĠ Ġprivate Ġval Ġobserver Ġ= Ġget Observer () ĊĠĠĠ Ġprivate Ġval Ġjob Ġ= ĠJob () ĊĠĠĠ Ġprivate Ġval Ġcoroutine Scope Ġ= ĠCor outine Scope ( Dispatch ers . IO Ġ+ Ġjob ) ĊĠĠĠ Ġprivate Ġval Ġcoroutine ExceptionHandler Ġ= ĠCor outine ExceptionHandler Ġ{ Ġ_, Ġexception Ġ-> ĊĠĠĠĠĠĠĠ Ġval Ġsupp ressed Exception Ġ= Ġexception . sup pressed ?. let Ġ{ Ġ" with Ġsupp ressed Ġexception ( s ) Ġ${ it . content ToString () }" Ġ} Ġ?: Ġrun Ġ{ Ġ"" Ġ} ĊĠĠĠĠĠĠĠ Ġ@ Suppress (" NO _ REF LECTION _ IN _ CLASS _ PATH ") ĊĠĠĠĠĠĠĠ ĠLog . e ( TAG , Ġ"${ exception :: class . simple Name } Ġoccurred Ġin Ġbackground Ġ$ sup pressed Exception ", Ġexception ) ĊĠĠĠ Ġ} ĊĊĊĠĠĠ Ġoverride Ġfun ĠonCreate ( savedInstanceState : ĠBundle ?) Ġ{ ĊĠĠĠĠĠĠĠ Ġsuper . onCreate ( savedInstanceState ) ĊĠĠĠĠĠĠĠ ĠsetContentView ( R . layout . activity _ main ) ĊĊĠĠĠĠĠĠĠ Ġget Location Btn Ġ= ĠfindViewById ( R . id . get _ location _ btn ) ĊĠĠĠĠĠĠĠ Ġget Location Btn . setOnClickListener ( this ) ĊĊĠĠĠĠĠĠĠ Ġlocation Manager Last Known Status Ġ= ĠfindViewById ( R . id . location _ manager _ last _ known _ card _ status ) ĊĠĠĠĠĠĠĠ Ġlocation Manager Last Known Location Txt Ġ= ĠfindViewById ( R . id . location _ manager _ last _ known _ card _ location ) ĊĊĠĠĠĠĠĠĠ Ġlocation Manager Single Update Status Ġ= ĠfindViewById ( R . id . location _ manager _ single _ update _ card _ status ) ĊĠĠĠĠĠĠĠ Ġlocation Manager Single Update Location Txt Ġ= ĠfindViewById ( R . id . location _ manager _ single _ update _ card _ location ) ĊĊĠĠĠĠĠĠĠ Ġlocation Manager Multiple Update Status Ġ= ĠfindViewById ( R . id . location _ manager _ multiple _ updates _ card _ status ) ĊĠĠĠĠĠĠĠ Ġlocation Manager Multiple Update Location Txt Ġ= ĠfindViewById ( R . id . location _ manager _ multiple _ updates _ card _ location ) ĊĊĠĠĠĠĠĠĠ Ġfusion Provider Last Known Status Ġ= ĠfindViewById ( R . id . f used _ location _ provider _ last _ known _ card _ status ) ĊĠĠĠĠĠĠĠ Ġfusion Provider Last Known Location Txt Ġ= ĠfindViewById ( R . id . f used _ location _ provider _ last _ known _ card _ location ) ĊĊĠĠĠĠĠĠĠ Ġfusion Provider Multiple Update Status Ġ= ĠfindViewById ( R . id . f used _ location _ provider _ multiple _ updates _ card _ status ) ĊĠĠĠĠĠĠĠ Ġfusion Provider Multiple Update Location Txt Ġ= ĠfindViewById ( R . id . f used _ location _ provider _ multiple _ updates _ card _ location ) ĊĊĠĠĠĠĠĠĠ Ġlocation Provider Radio Group Ġ= ĠfindViewById ( R . id . provider _ radio _ grp ) ĊĠĠĠĠĠĠĠ Ġlocation Provider Radio Group . setOn Checked ChangeListener ( this ) ĊĊĠĠĠĠĠĠĠ Ġsync Provider Status Button Ġ= ĠfindViewById ( R . id . sync _ provider _ status _ btn ) ĊĠĠĠĠĠĠĠ Ġsync Provider Status Button . setOnClickListener ( this ) ĊĊĠĠĠĠĠĠĠ Ġgps Provider RadioButton Ġ= ĠfindViewById ( R . id . gps _ radio _ btn ) ĊĠĠĠĠĠĠĠ Ġgps Provider RadioButton . setTextColor ( application Context . getColor ( R . color . red )) ĊĊĠĠĠĠĠĠĠ Ġnetwork Provider RadioButton Ġ= ĠfindViewById ( R . id . network _ radio _ btn ) ĊĠĠĠĠĠĠĠ Ġnetwork Provider RadioButton . setTextColor ( application Context . getColor ( R . color . red )) ĊĊĠĠĠĠĠĠĠ Ġpassive Provider RadioButton Ġ= ĠfindViewById ( R . id . passive _ radio _ btn ) ĊĠĠĠĠĠĠĠ Ġpassive Provider RadioButton . setTextColor ( application Context . getColor ( R . color . red )) ĊĊĠĠĠĠĠĠĠ ĠviewModel Ġ= ĠLocation ViewModel ( application ) ĊĠĠĠĠĠĠĠ ĠviewModel . location LiveData . observe ( this , Ġobserver ) ĊĠĠĠ Ġ} ĊĊĊĠĠĠ Ġoverride Ġfun Ġon Resume () Ġ{ ĊĠĠĠĠĠĠĠ Ġsuper . on Resume () ĊĊĠĠĠĠĠĠĠ Ġ// ĠUpdate Ġstatus Ġof Ġlocation Ġproviders ĊĠĠĠĠĠĠĠ Ġcoroutine Scope . launch ( coroutine ExceptionHandler ) Ġ{ ĊĠĠĠĠĠĠĠĠĠĠĠ Ġupdate Location Provider Statuses () ĊĠĠĠĠĠĠĠ Ġ} ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġoverride Ġfun Ġon Destroy () Ġ{ ĊĠĠĠĠĠĠĠ ĠviewModel . location LiveData . remove Observer ( observer ) ĊĠĠĠĠĠĠĠ Ġsuper . on Destroy () ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġprivate Ġfun Ġget Observer () Ġ: ĠObserver < Location Model > Ġ= ĠObserver Ġ{ ĊĠĠĠĠĠĠĠ Ġit ?. let Ġ{ ĊĠĠĠĠĠĠĠĠĠĠĠ ĠLog . d ( TAG , Ġ"${ it . type }, Ġ${ it . latitude }, Ġ${ it . longitude }") ĊĠĠĠĠĠĠĠĠĠĠĠ Ġwhen ( it . type ) Ġ{ ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ ĠLoc ator Manager . LOCATION _ MANAGER _ LAST _ KNOWN Ġ-> Ġ{ ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġlocation Manager Last Known Status . text Ġ= ĠDate Format . getTime Instance (). format ( it . time ) ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġlocation Manager Last Known Location Txt . text Ġ= Ġif ( it . latitude Ġ== ĠLoc ator Manager . INVALID _ LOCATION ) Ġapplication Context . getString ( R . string . location _ not _ found ) Ġelse ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġ"${ Location . convert ( it . latitude , ĠLocation . FORMAT _ DE GRE ES )} Ġ${ Location . convert ( it . longitude , ĠLocation . FORMAT _ DE GRE ES )}" ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġ} ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ ĠLoc ator Manager . LOCATION _ MANAGER _ SINGLE _ UPDATE Ġ-> Ġ{ ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġlocation Manager Single Update Status . text Ġ= ĠDate Format . getTime Instance (). format ( it . time ) ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġlocation Manager Single Update Location Txt . text Ġ= Ġif ( it . latitude Ġ== ĠLoc ator Manager . INVALID _ LOCATION ) Ġapplication Context . getString ( R . string . location _ not _ found ) Ġelse ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġ"${ Location . convert ( it . latitude , ĠLocation . FORMAT _ DE GRE ES )} Ġ${ Location . convert ( it . longitude , ĠLocation . FORMAT _ DE GRE ES )}" ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġ} ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ ĠLoc ator Manager . LOCATION _ MANAGER _ MULTIPLE _ UPDATE Ġ-> Ġ{ ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġlocation Manager Multiple Update Status . text Ġ= ĠDate Format . getTime Instance (). format ( it . time ) ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġlocation Manager Multiple Update Location Txt . text Ġ= Ġif ( it . latitude Ġ== ĠLoc ator Manager . INVALID _ LOCATION ) Ġapplication Context . getString ( R . string . location _ not _ found ) Ġelse ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġ"${ Location . convert ( it . latitude , ĠLocation . FORMAT _ DE GRE ES )} Ġ${ Location . convert ( it . longitude , ĠLocation . FORMAT _ DE GRE ES )}" ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġ} ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ ĠLoc ator Manager . F US ION _ CLIENT _ LAST _ KNOWN Ġ-> Ġ{ ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġfusion Provider Last Known Status . text Ġ= ĠDate Format . getTime Instance (). format ( it . time ) ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġfusion Provider Last Known Location Txt . text Ġ= Ġif ( it . latitude Ġ== ĠLoc ator Manager . INVALID _ LOCATION ) Ġapplication Context . getString ( R . string . location _ not _ found ) Ġelse ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġ"${ Location . convert ( it . latitude , ĠLocation . FORMAT _ DE GRE ES )} Ġ${ Location . convert ( it . longitude , ĠLocation . FORMAT _ DE GRE ES )}" ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġ} ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ ĠLoc ator Manager . F US ION _ CLIENT _ MULTIPLE _ UPDATE Ġ-> Ġ{ ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġfusion Provider Multiple Update Status . text Ġ= ĠDate Format . getTime Instance (). format ( it . time ) ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġfusion Provider Multiple Update Location Txt . text Ġ= Ġif ( it . latitude Ġ== Locator Manager . INVALID _ LOCATION ) Ġapplication Context . getString ( R . string . location _ not _ found ) Ġelse ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġ"${ Location . convert ( it . latitude , ĠLocation . FORMAT _ DE GRE ES )} Ġ${ Location . convert ( it . longitude , ĠLocation . FORMAT _ DE GRE ES )}" ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġ} ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ ĠLoc ator Manager . LOCATION _ MANAGER _ PROVIDER _ STATUS _ MODI FIED Ġ-> Ġ{ ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġcoroutine Scope . launch ( coroutine ExceptionHandler ) Ġ{ ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġupdate Location Provider Statuses () ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġ} ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġ} ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġelse Ġ-> ĠLog . w ( TAG , Ġ" Invalid ĠLocation Ġmodel Ġtype Ġreceived Ġ(${ it . type }) ") ĊĠĠĠĠĠĠĠĠĠĠĠ Ġ} ĊĠĠĠĠĠĠĠ Ġ} ĊĠĠĠ Ġ} ĊĊĊĠĠĠ Ġoverride Ġfun ĠonClick ( v : ĠView ?) Ġ{ ĊĠĠĠĠĠĠĠ Ġwhen ( v ?. id ) Ġ{ ĊĠĠĠĠĠĠĠĠĠĠĠ ĠR . id . get _ location _ btn Ġ-> Ġ{ ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ ĠLog . i ( TAG , Ġ" Getting Ġlocation ") ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġreset Location () ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġupdate Location Status () ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġcoroutine Scope . launch ( coroutine ExceptionHandler ) Ġ{ ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġget Location () ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġupdate Location Provider Statuses () ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġ} ĊĠĠĠĠĠĠĠĠĠĠĠ Ġ} ĊĠĠĠĠĠĠĠĠĠĠĠ ĠR . id . sync _ provider _ status _ btn Ġ-> Ġ{ ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġ// ĠUpdate Ġstatus Ġof Ġlocation Ġproviders ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġcoroutine Scope . launch ( coroutine ExceptionHandler ) Ġ{ ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġupdate Location Provider Statuses () ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġ} ĊĠĠĠĠĠĠĠĠĠĠĠ Ġ} ĊĠĠĠĠĠĠĠ Ġ} ĊĠĠĠ Ġ} ĊĊĊĠĠĠ Ġoverride Ġfun Ġon CheckedChanged ( group : ĠRadio Group ?, Ġchecked Id : ĠInt ) Ġ{ ĊĠĠĠĠĠĠĠ Ġreset Location () ĊĠĠĠĠĠĠĠ Ġreset Location Status () ĊĠĠĠĠĠĠĠ Ġ// Ġstop Ġlocation Ġupdates ĊĠĠĠĠĠĠĠ Ġcoroutine Scope . launch ( coroutine ExceptionHandler ) Ġ{ ĊĠĠĠĠĠĠĠĠĠĠĠ ĠviewModel . stop Location Updates () ĊĠĠĠĠĠĠĠ Ġ} ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġprivate Ġfun Ġupdate Location Status () Ġ{ ĊĠĠĠĠĠĠĠ Ġlocation Manager Last Known Status . text Ġ= ĠgetString ( R . string . waiting _ for _ location ) ĊĠĠĠĠĠĠĠ Ġlocation Manager Single Update Status . text Ġ= ĠgetString ( R . string . waiting _ for _ location ) ĊĠĠĠĠĠĠĠ Ġlocation Manager Multiple Update Status . text Ġ= ĠgetString ( R . string . waiting _ for _ location ) ĊĠĠĠĠĠĠĠ Ġfusion Provider Last Known Status . text Ġ= ĠgetString ( R . string . waiting _ for _ location ) ĊĠĠĠĠĠĠĠ Ġfusion Provider Multiple Update Status . text Ġ= ĠgetString ( R . string . waiting _ for _ location ) ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġprivate Ġfun Ġreset Location () Ġ{ ĊĠĠĠĠĠĠĠ Ġlocation Manager Last Known Location Txt . text Ġ= ĠgetString ( R . string . default _ location _ txt ) ĊĠĠĠĠĠĠĠ Ġlocation Manager Single Update Location Txt . text Ġ= ĠgetString ( R . string . default _ location _ txt ) ĊĠĠĠĠĠĠĠ Ġlocation Manager Multiple Update Location Txt . text Ġ= ĠgetString ( R . string . default _ location _ txt ) ĊĠĠĠĠĠĠĠ Ġfusion Provider Last Known Location Txt . text Ġ= ĠgetString ( R . string . default _ location _ txt ) ĊĠĠĠĠĠĠĠ Ġfusion Provider Multiple Update Location Txt . text Ġ= ĠgetString ( R . string . default _ location _ txt ) ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġprivate Ġfun Ġreset Location Status () Ġ{ ĊĠĠĠĠĠĠĠ Ġlocation Manager Last Known Status . text Ġ= ĠgetString ( R . string . location _ not _ requested ) ĊĠĠĠĠĠĠĠ Ġlocation Manager Single Update Status . text Ġ= ĠgetString ( R . string . location _ not _ requested ) ĊĠĠĠĠĠĠĠ Ġlocation Manager Multiple Update Status . text Ġ= ĠgetString ( R . string . location _ not _ requested ) ĊĠĠĠĠĠĠĠ Ġfusion Provider Last Known Status . text Ġ= ĠgetString ( R . string . location _ not _ requested ) ĊĠĠĠĠĠĠĠ Ġfusion Provider Multiple Update Status . text Ġ= ĠgetString ( R . string . location _ not _ requested ) ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġprivate Ġfun Ġget Location () Ġ{ ĊĠĠĠĠĠĠĠ Ġif Ġ( Context Compat . check Self Permission ( application Context , ĠManifest . permission . ACCESS _ F INE _ LOCATION ) Ġ!= ĠPackage Manager . PERMISSION _ GRAN TED ĊĠĠĠĠĠĠĠĠĠĠĠ Ġ&& ĠContext Compat . check Self Permission ( application Context , ĠManifest . permission . ACCESS _ CO AR SE _ LOCATION ) Ġ!= ĠPackage Manager . PERMISSION _ GRAN TED ) Ġ{ ĊĠĠĠĠĠĠĠĠĠĠĠ Ġcoroutine Scope . launch ( coroutine ExceptionHandler ) Ġ{ ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġwith Context ( Dispatch ers . Main ) Ġ{ ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ ĠSn ackbar . make ( findViewById ( R . id . main Coordinator Layout ), ĠR . string . no _ location _ permission , ĠSn ackbar . LENGTH _ SHORT ). show () ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġ} ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġreturn @ launch ĊĠĠĠĠĠĠĠĠĠĠĠ Ġ} ĊĠĠĠĠĠĠĠ Ġ} Ġelse Ġ{ ĊĠĠĠĠĠĠĠĠĠĠĠ ĠviewModel . request Location ( get Ch osen Provider ()) ĊĠĠĠĠĠĠĠ Ġ} ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġprivate Ġfun Ġget Ch osen Provider (): ĠString Ġ{ ĊĠĠĠĠĠĠĠ Ġreturn Ġwhen Ġ{ ĊĠĠĠĠĠĠĠĠĠĠĠ Ġgps Provider RadioButton . isChecked Ġ-> ĠLocation Manager . GPS _ PROVIDER ĊĠĠĠĠĠĠĠĠĠĠĠ Ġnetwork Provider RadioButton . isChecked Ġ-> ĠLocation Manager . NETWORK _ PROVIDER ĊĠĠĠĠĠĠĠĠĠĠĠ Ġpassive Provider RadioButton . isChecked Ġ-> ĠLocation Manager . PAS SIVE _ PROVIDER ĊĠĠĠĠĠĠĠĠĠĠĠ Ġelse Ġ-> ĠLocation Manager . GPS _ PROVIDER ĊĠĠĠĠĠĠĠ Ġ} ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġprivate Ġfun Ġupdate Location Provider Statuses () Ġ{ ĊĠĠĠĠĠĠĠ Ġval Ġis G ps Provider Enabled Ġ= ĠviewModel . is Provider Enabled ( Location Manager . GPS _ PROVIDER ) ĊĠĠĠĠĠĠĠ Ġval Ġis Network Provider Enabled Ġ= ĠviewModel . is Provider Enabled ( Location Manager . NETWORK _ PROVIDER ) ĊĠĠĠĠĠĠĠ Ġval Ġis Pass ive Provider Enabled Ġ= ĠviewModel . is Provider Enabled ( Location Manager . PAS SIVE _ PROVIDER ) ĊĠĠĠĠĠĠĠ ĠLog . i ( TAG , Ġ" GPS : Ġ$ is G ps Provider Enabled ĠNetwork : Ġ$ is Network Provider Enabled ĠPass ive : Ġ$ is Pass ive Provider Enabled ") ĊĠĠĠĠĠĠĠ Ġ// ĠShow ĠStatus Ġin ĠUI ĊĠĠĠĠĠĠĠ Ġcoroutine Scope . launch ( coroutine ExceptionHandler ) Ġ{ ĊĠĠĠĠĠĠĠĠĠĠĠ Ġwith Context ( Dispatch ers . Main ) Ġ{ ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġgps Provider RadioButton . setTextColor ( if ( is G ps Provider Enabled ) Ġget Color ( R . color . green ) Ġelse Ġget Color ( R . color . red )) ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġnetwork Provider RadioButton . setTextColor ( if ( is Network Provider Enabled ) Ġget Color ( R . color . green ) Ġelse Ġget Color ( R . color . red )) ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġpassive Provider RadioButton . setTextColor ( if ( is Pass ive Provider Enabled ) Ġget Color ( R . color . green ) Ġelse Ġget Color ( R . color . red )) ĊĠĠĠĠĠĠĠĠĠĠĠ Ġ} ĊĠĠĠĠĠĠĠ Ġ} ĊĠĠĠ Ġ} Ċ } Ċ