package Ġuk . ac . not t . m rl . open food Ċ Ċ import Ġandroid . Manifest Ċ import Ġandroid . bluetooth . Bluetooth Adapter Ċ import Ġandroid . bluetooth . Bluetooth Manager Ċ import Ġandroid . content . Component Name Ċ import Ġandroid . content . Context Ċ import Ġandroid . content . Intent Ċ import Ġandroid . content . Service Connection Ċ import Ġandroid . content . pm . PackageManager Ċ import Ġandroid . os . Bundle Ċ import Ġandroid . os . Handler Ċ import Ġandroid . os . IB inder Ċ import Ġandroid . os . Looper Ċ import Ġandroid . util . Log Ċ import Ġandroid . view . MenuItem Ċ import Ġandroid . view . View Ċ import Ġandroid . view . WindowManager Ċ import Ġandroid . widget . EditText Ċ import Ġandroidx . appcompat . app . ActionBar Drawer Toggle Ċ import Ġandroidx . appcompat . app . AlertDialog Ċ import Ġandroidx . appcompat . app . AppCompatActivity Ċ import Ġandroidx . core . app . Activity Compat Ċ import Ġandroidx . core . content . Context Compat Ċ import Ġandroidx . core . content . edit Ċ import Ġandroidx . core . view . Gravity Compat Ċ import Ġandroidx . fragment . app . transaction Ċ import Ġcom . google . android . material . navigation . Navigation View Ċ import Ġcom . mb ient lab . met aw ear . android . B tle Service Ċ import Ġcom . mb ient lab . met aw ear . data . Acceleration Ċ import Ġcom . mb ient lab . met aw ear . data . Angular Velocity Ċ import Ġcom . mb ient lab . met aw ear . module .* Ċ import Ġcom . mb ient lab . met aw ear . module . Timer Ċ import Ġkotlinx . android . synt hetic . main . activity _ navigation .* Ċ import Ġuk . ac . not t . m rl . open food . logging . Device Logger Ċ import Ġuk . ac . not t . m rl . open food . logging . Log List Fragment Ċ import Ġuk . ac . not t . m rl . open food . playback . Playback Creator Activity Ċ import Ġuk . ac . not t . m rl . open food . sensor . Sensor Ċ import Ġuk . ac . not t . m rl . open food . sensor . Sensor ListAdapter Ċ import Ġuk . ac . not t . m rl . open food . sensor . Sensor ListAdapter Holder Ċ import Ġuk . ac . not t . m rl . open food . sensor . Sensor List Fragment Ċ import Ġjava . io . File Ċ import Ġjava . util .* Ċ Ċ class ĠNavigation Activity Ġ: ĠAppCompatActivity (), ĠNavigation View . On Navigation ItemSelected Listener , ĠService Connection , ĠSensor ListAdapter Holder Ġ{ Ċ ĉ comp anion Ġobject Ġ{ Ċĉ ĉ const Ġval ĠP REF _ ID Ġ= Ġ" OF - LOG - PRE FS " Ċĉ ĉ const Ġval ĠP REF _ LOG GED Ġ= Ġ" LOG GED _ ADD RES SES " Ċĉ ĉ const Ġval ĠP REF _ PLAY BACK Ġ= Ġ" PLAY BACK _ ADD RES SES " Ċĉ ĉ const Ġval ĠP REF _ VIDEO Ġ= Ġ" PLAY BACK _ VIDEO " Ċĉ ĉ private Ġconst Ġval ĠREQUEST _ PERMISSION _ CODE Ġ= Ġ 4 5 7 2 Ċĉ ĉ private Ġconst Ġval ĠREQUEST _ BL U ETO OTH _ CODE Ġ= Ġ 4 5 7 4 Ċĉ ĉ private Ġconst Ġval ĠTEMP _ SAMPLE _ PERIOD Ġ= Ġ 1 0 0 Ċĉ ĉ private Ġval ĠTAG Ġ= ĠNavigation Activity :: class . java . simple Name Ċ ĉ } ĊĊ ĉ private Ġvar Ġbluetooth LE Service : ĠB tle Service . Local Binder ? Ġ= Ġnull Ċ ĉ private Ġval Ġlogger Ġ= ĠDevice Logger () Ċ ĉ private Ġvar Ġaction Ġ= Ġ"" Ċ ĉ override Ġval Ġadapter Ġ= ĠSensor ListAdapter () Ċ ĉ private Ġval Ġconnected Han l der Ġ= ĠHandler ( Looper . get Main Looper ()) Ċ ĉ private Ġval Ġconnected Runnable Ġ= ĠRunnable Ġ{ Ċĉ ĉ check Connected () Ċ ĉ } ĊĊ ĉ override Ġfun Ġon Service Connected ( name : ĠComponent Name ?, Ġservice : ĠI Binder ?) Ġ{ Ċĉ ĉ bluetooth LE Service Ġ= Ġservice Ġas ĠB tle Service . Local Binder Ċĉ ĉ logging Button . isEnabled Ġ= Ġtrue Ċ ĉ } ĊĊ ĉ override Ġfun Ġon Service Disconnected ( name : ĠComponent Name ?) Ġ{ Ċĉ ĉ bluetooth LE Service Ġ= Ġnull Ċĉ ĉ logging Button . isEnabled Ġ= Ġfalse Ċ ĉ } ĊĊ ĉ override Ġfun ĠonCreate ( savedInstanceState : ĠBundle ?) Ġ{ Ċĉ ĉ super . onCreate ( savedInstanceState ) Ċĉ ĉ set ContentView ( R . layout . activity _ navigation ) Ċĉ ĉ set Support ActionBar ( toolbar ) ĊĊĉ ĉ logging Button . setOnClickListener Ġ{ Ċĉĉ ĉ if Ġ( logger . is Logging ) Ġ{ Ċĉĉĉ ĉ stop Logging () Ċĉĉ ĉ } Ġelse Ġ{ Ċĉĉĉ ĉ start Logging () Ċĉĉ ĉ } Ċĉ ĉ } Ċĉ ĉ adapter . click Listener Ġ= Ġ{ Ġsensor Ġ-> Ċĉĉ ĉ get SharedPreferences ( PRE F _ ID , Ġ 0 ). edit Ġ{ Ċĉĉĉ ĉ putString Set ( PRE F _ LOG GED , Ġadapter . getSelected ()) Ċĉĉ ĉ } Ċĉĉ ĉ if Ġ( logger . is Logging ) Ġ{ Ċĉĉĉ ĉ if Ġ( sensor . selected ) Ġ{ Ċĉĉĉĉ ĉ connect Sensor ( sensor ) Ċĉĉĉ ĉ } Ġelse Ġ{ Ċĉĉĉĉ ĉ disconnect Sensor ( sensor ) Ċĉĉĉ ĉ } Ċĉĉ ĉ } Ċĉ ĉ } Ċĉ ĉ adapter . long ClickListener Ġ= Ġ{ Ġsensor Ġ-> Ċĉĉ ĉ if Ġ( sensor . board ?. isConnected Ġ!= Ġtrue ) Ġ{ Ċĉĉĉ ĉ if Ġ( sensor . board Ġ== Ġnull ) Ġ{ Ċĉĉĉĉ ĉ val Ġbluetooth Manager Ġ= Ġget System Service ( Context . BL U ETO OTH _ SERVICE ) Ġas ĠBluetooth Manager Ċĉĉĉĉ ĉ val Ġble Device Ġ= Ġbluetooth Manager . adapter . get Remote Device ( sensor . address ) Ċĉĉĉĉ ĉ sensor . board Ġ= Ġbluetooth LE Service ?. get Meta W ear Board ( ble Device ) Ċĉĉĉ ĉ } ĊĊĉĉĉ ĉ sensor . board ?. let Ġ{ Ċĉĉĉĉ ĉ it . connect Async (). continue With Ġ{ Ġtask Ġ-> Ċĉĉĉĉĉ ĉ if Ġ( task . is Fault ed ) Ġ{ Ċĉĉĉĉĉĉ ĉ Log . i ( TAG , Ġsensor . address Ġ+ Ġ" Ġconnection Ġfailed : Ġ" Ġ+ Ġtask . error . localized Message ) Ċĉĉĉĉĉ ĉ } Ġelse Ġ{ Ċĉĉĉĉĉĉ ĉ Log . i ( TAG , Ġsensor . address Ġ+ Ġ" Ġconnected ") Ċĉĉĉĉĉĉ ĉ val Ġled Ġ= Ġit . getModule ( Led :: class . java ) Ċĉĉĉĉĉĉ ĉ led . edit Pattern ( Led . Color . RED , ĠLed . Pattern Preset . BL INK ). commit () Ċĉĉĉĉĉĉ ĉ led . play () Ċĉĉĉĉĉ ĉ } Ċĉĉĉĉ ĉ } ĊĊĉĉĉĉ ĉ val Ġbuilder Ġ= ĠAlertDialog . Builder ( this @ Navigation Activity ) Ċĉĉĉĉ ĉ val Ġview Ġ= Ġlayout Inflater . inflate ( R . layout . edit _ name , Ġnull , Ġfalse ) Ċĉĉĉĉ ĉ val Ġinput Ġ= Ġview . findViewById < EditText >( R . id . edit _ name ) Ċĉĉĉĉ ĉ input . append ( sensor . name ) Ċĉĉĉĉ ĉ val Ġdialog Ġ= Ġbuilder . setTitle ( getString ( R . string . rename _ dialog _ title , Ġsensor . name )) Ċĉĉĉĉĉĉ ĉ . setMessage ( getString ( R . string . rename _ dialog _ message , Ġsensor . address )) Ċĉĉĉĉĉĉ ĉ . setView ( view ) Ċĉĉĉĉĉĉ ĉ . set Positive Button ( R . string . rename _ dialog _ rename ) Ġ{ Ġdialog , Ġ_ Ġ-> Ċĉĉĉĉĉĉĉ ĉ it . getModule ( Settings :: class . java ) Ċĉĉĉĉĉĉĉĉĉ ĉ . edit B le Ad Config () Ċĉĉĉĉĉĉĉĉĉ ĉ . device Name ( input . text . toString ()) Ċĉĉĉĉĉĉĉĉĉ ĉ . commit () ĊĊĉĉĉĉĉĉĉ ĉ dialog . dismiss () Ċĉĉĉĉĉĉ ĉ } Ċĉĉĉĉĉĉ ĉ . set Negative Button ( R . string . ran ame _ dialog _ cancel ) Ġ{ Ġdialog , Ġ_ Ġ-> Ċĉĉĉĉĉĉĉ ĉ dialog . cancel () Ċĉĉĉĉĉĉ ĉ } Ċĉĉĉĉĉĉ ĉ . setOn Dismiss Listener Ġ{ Ċĉĉĉĉĉĉĉ ĉ disconnect Sensor ( sensor ) Ċĉĉĉĉĉĉ ĉ } Ċĉĉĉĉĉĉ ĉ . create () Ċĉĉĉĉ ĉ dialog . window . set Soft Input Mode ( WindowManager . LayoutParams . SOFT _ INPUT _ STATE _ VISIBLE ) Ċĉĉĉĉ ĉ dialog . show () Ċĉĉĉ ĉ } Ċĉĉ ĉ } Ċĉ ĉ } ĊĊĉ ĉ val Ġtoggle Ġ= ĠAction Bar Drawer Toggle ( this , Ġdrawer , Ġtoolbar , ĠR . string . navigation _ drawer _ open , ĠR . string . navigation _ drawer _ close ) Ċĉ ĉ drawer . add Drawer Listener ( toggle ) Ċĉ ĉ toggle . sync State () ĊĊĉ ĉ logger . directory Ġ= ĠFile ( files Dir , Ġ" logs ") ĊĊĉ ĉ navigation . set Navigation ItemSelected Listener ( this ) Ċ ĉ } ĊĊ ĉ override Ġfun Ġon Back Pressed () Ġ{ Ċĉ ĉ if Ġ( drawer . is Drawer Open ( Gravity Compat . START )) Ġ{ Ċĉĉ ĉ drawer . close Drawer ( Gravity Compat . START ) Ċĉ ĉ } Ġelse Ġ{ Ċĉĉ ĉ super . on Back Pressed () Ċĉ ĉ } Ċ ĉ } ĊĊ ĉ override Ġfun ĠonStart () Ġ{ Ċĉ ĉ super . onStart () Ċĉ ĉ bind Service ( Intent ( this , ĠB tle Service :: class . java ), Ġthis , ĠContext . BIND _ AUTO _ CREATE ) Ċĉ ĉ adapter . setSelected ( get SharedPreferences ( PRE F _ ID , Ġ 0 ). getString Set ( PRE F _ LOG GED , Ġmutable Set Of ())) Ċĉ ĉ permission Requests () Ċ ĉ } ĊĊ ĉ private Ġfun Ġpermission Requests () Ġ{ Ċĉ ĉ if Ġ( Context Compat . check Self Permission ( this , ĠManifest . permission . ACCESS _ F INE _ LOCATION ) Ġ!= ĠPackage Manager . PERMISSION _ GRAN TED ) Ġ{ Ċĉĉ ĉ Log . i ( TAG , Ġ" Request Ġpermission ") Ċĉĉ ĉ Activity Compat . request Permissions ( this , ĠarrayOf ( Manifest . permission . ACCESS _ F INE _ LOCATION ), ĠREQUEST _ PERMISSION _ CODE ) Ċĉ ĉ } Ġelse Ġ{ Ċĉĉ ĉ val Ġbluetooth Manager Ġ= Ġget System Service ( Context . BL U ETO OTH _ SERVICE ) Ġas ĠBluetooth Manager Ċĉĉ ĉ if Ġ(! bluetooth Manager . adapter . isEnabled ) Ġ{ Ċĉĉĉ ĉ val Ġintent Bt Enabled Ġ= ĠIntent ( Bluetooth Adapter . ACTION _ REQUEST _ ENABLE ) Ċĉĉĉ ĉ startActivity For Result ( intent Bt Enabled , ĠREQUEST _ BL U ETO OTH _ CODE ) Ċĉĉ ĉ } Ġelse Ġ{ Ċĉĉĉ ĉ navigate To ( R . id . nav _ logging ) Ċĉĉ ĉ } Ċĉ ĉ } Ċ ĉ } ĊĊ ĉ override Ġfun Ġon Stop () Ġ{ Ċĉ ĉ super . on Stop () Ċĉ ĉ if Ġ( bluetooth LE Service Ġ!= Ġnull ) Ġ{ Ċĉĉ ĉ unbind Service ( this ) Ċĉ ĉ } Ċ ĉ } ĊĊ ĉ override Ġfun Ġon Navigation ItemSelected ( item : ĠMenuItem ): ĠBoolean Ġ{ Ċĉ ĉ item . isEnabled Ġ= Ġtrue Ċĉ ĉ when Ġ( item . itemId ) Ġ{ Ċĉĉ ĉ R . id . nav _ action _ none Ġ-> Ġaction Ġ= Ġ"" Ċĉĉ ĉ R . id . nav _ action _ dr ink Ġ-> Ġaction Ġ= Ġ" dr ink " Ċĉĉ ĉ R . id . nav _ action _ held Ġ-> Ġaction Ġ= Ġ" held " Ċĉĉ ĉ R . id . nav _ action _ rest Ġ-> Ġaction Ġ= Ġ" rest " Ċĉĉ ĉ else Ġ-> Ġnavigate To ( item . itemId ) Ċĉ ĉ } ĊĊĉ ĉ return Ġtrue Ċ ĉ } ĊĊ ĉ override Ġfun Ġon Request Permissions Result ( request Code : ĠInt , Ġpermissions : ĠArray < String >, Ġgrant Results : ĠInt Array ) Ġ{ Ċĉ ĉ permission Requests () Ċ ĉ } ĊĊ ĉ private Ġfun Ġstart Logging () Ġ{ Ċĉ ĉ val Ġselected Ġ= Ġadapter . getSelected Devices () Ċĉ ĉ if Ġ(! selected . isEmpty ()) Ġ{ Ċĉĉ ĉ Log . i ( TAG , Ġ" Starting Ġlogging ") Ċĉĉ ĉ window . add Flags ( WindowManager . LayoutParams . FLAG _ KEEP _ SCREEN _ ON ) Ċĉĉ ĉ logger . start () Ċĉĉ ĉ logging Button . setImage Resource ( R . drawable . ic _ stop _ black _ 2 4 dp ) Ċĉĉ ĉ logging Progress . visibility Ġ= ĠView . VISIBLE ĊĊĉĉ ĉ for Ġ( sensor Ġin Ġselected ) Ġ{ Ċĉĉĉ ĉ connect Sensor ( sensor ) Ċĉĉ ĉ } Ċĉ ĉ } Ċ ĉ } ĊĊ ĉ private Ġfun Ġstop Logging () Ġ{ Ċĉ ĉ Log . i ( TAG , Ġ" Stopping Ġlogging ") Ċĉ ĉ logger . stop () Ċĉ ĉ logging Button . setImage Resource ( R . drawable . ic _ play _ arrow _ black _ 2 4 dp ) Ċĉ ĉ logging Progress . visibility Ġ= ĠView . IN VISIBLE ĊĊĉ ĉ for Ġ( device Ġin Ġadapter . sensors ) Ġ{ Ċĉĉ ĉ disconnect Sensor ( device ) Ċĉ ĉ } Ċĉ ĉ connected Han l der . remove Callbacks ( connected Runnable ) Ċĉ ĉ window . clear Flags ( WindowManager . LayoutParams . FLAG _ KEEP _ SCREEN _ ON ) Ċ ĉ } ĊĊ ĉ private Ġfun Ġupdate Sensor ( sensor : ĠSensor ) Ġ{ Ċĉ ĉ run On Ui Thread Ġ{ Ċĉĉ ĉ adapter . update Sensor ( sensor ) Ċĉ ĉ } Ċ ĉ } ĊĊ ĉ private Ġfun Ġconnect Sensor ( sensor : ĠSensor ) Ġ{ Ċĉ ĉ Log . i ( TAG , Ġ" Connecting Ġto Ġ" Ġ+ Ġsensor . address ) Ċĉ ĉ if Ġ(! logger . is Logging Ġ|| Ġsensor . isConnected ()) Ġ{ Ċĉĉ ĉ return Ċĉ ĉ } Ċĉ ĉ if Ġ( sensor . board Ġ== Ġnull ) Ġ{ Ċĉĉ ĉ val Ġbluetooth Manager Ġ= Ġget System Service ( Context . BL U ETO OTH _ SERVICE ) Ġas ĠBluetooth Manager Ċĉĉ ĉ val Ġble Device Ġ= Ġbluetooth Manager . adapter . get Remote Device ( sensor . address ) Ċĉĉ ĉ sensor . board Ġ= Ġbluetooth LE Service ?. get Meta W ear Board ( ble Device ) Ċĉ ĉ } ĊĊĉ ĉ sensor . board ?. let Ġ{ Ċĉĉ ĉ sensor . connecting Ġ= Ġtrue Ċĉĉ ĉ update Sensor ( sensor ) Ċĉĉ ĉ it . connect Async (). continue With Ġ{ Ġtask Ġ-> Ċĉĉĉ ĉ if Ġ(! logger . is Logging Ġ|| Ġ! sensor . selected ) Ġ{ Ċĉĉĉĉ ĉ disconnect Sensor ( sensor ) Ċĉĉĉ ĉ } Ġelse Ġif Ġ( task . is Fault ed ) Ġ{ Ċĉĉĉĉ ĉ Log . i ( TAG , Ġ" Failed Ġto Ġconnect Ġto Ġmet aw ear ") Ċĉĉĉĉ ĉ Log . i ( TAG , Ġtask . error . localized Message ) Ċĉĉĉĉ ĉ connect Sensor ( sensor ) Ċĉĉĉ ĉ } Ġelse Ġ{ Ċĉĉĉĉ ĉ sensor . connecting Ġ= Ġfalse Ċĉĉĉĉ ĉ update Sensor ( sensor ) Ċĉĉĉĉ ĉ check Connected () Ċĉĉĉĉ ĉ Log . i ( TAG , Ġ" Connected Ġto Ġ" Ġ+ Ġsensor . address ) Ċĉĉĉĉ ĉ val Ġaccel erometer Ġ= Ġit . getModule ( Accel erometer :: class . java ) Ċĉĉĉĉ ĉ accel erometer . configure () Ċĉĉĉĉĉĉ ĉ . od r ( 1 0 f ) Ċĉĉĉĉĉĉ ĉ . commit () Ċĉĉĉĉ ĉ accel erometer . acceleration () Ċĉĉĉĉĉĉ ĉ . add Route Async Ġ{ Ċĉĉĉĉĉĉĉ ĉ it . stream Ġ{ Ġdata , Ġenv Ġ-> Ċĉĉĉĉĉĉĉĉ ĉ val Ġcast ed Ġ= Ġdata . value ( Acceleration :: class . java ) Ċĉĉĉĉĉĉĉĉ ĉ val Ġnow Ġ= ĠSystem . currentTimeMillis () Ċĉĉĉĉĉĉĉĉ ĉ val Ġtimed out Ġ= Ġsensor . has Timed Out ( now ) Ċĉĉĉĉĉĉĉĉ ĉ sensor . timestamp Ġ= Ġnow Ċĉĉĉĉĉĉĉĉ ĉ logger . log ( String . format ( Locale . US , Ġ"% s ,% s ,% s ,% s ,% . 4 f ,% . 4 f ,% . 4 f ,% s % n ", Ċĉĉĉĉĉĉĉĉĉĉ ĉ data . formatted Timestamp (), Ċĉĉĉĉĉĉĉĉĉĉ ĉ env [ 0 ]. toString (), Ċĉĉĉĉĉĉĉĉĉĉ ĉ action , Ċĉĉĉĉĉĉĉĉĉĉ ĉ " accel ", Ċĉĉĉĉĉĉĉĉĉĉ ĉ cast ed . x (), Ġcast ed . y (), Ġcast ed . z (), Ċĉĉĉĉĉĉĉĉĉĉ ĉ " g ")) Ċĉĉĉĉĉĉĉĉ ĉ if Ġ( timed out ) Ġ{ Ċĉĉĉĉĉĉĉĉĉ ĉ update Sensor ( sensor ) Ċĉĉĉĉĉĉĉĉ ĉ } Ċĉĉĉĉĉĉĉ ĉ } Ċĉĉĉĉĉĉ ĉ } Ċĉĉĉĉĉĉ ĉ . continue With Ġ{ Ċĉĉĉĉĉĉĉ ĉ it . result . set Environment ( 0 , Ġsensor . address ) Ċĉĉĉĉĉĉĉ ĉ accel erometer . packed Acceleration (). start () Ċĉĉĉĉĉĉĉ ĉ accel erometer . start () Ċĉĉĉĉĉĉ ĉ } ĊĊĉĉĉĉ ĉ val Ġgyro Ġ= Ġit . getModule ( G yro B mi 1 6 0 :: class . java ) Ċĉĉĉĉ ĉ gyro . configure () Ċĉĉĉĉĉĉ ĉ . od r ( G yro B mi 1 6 0 . Output Data Rate . O DR _ 2 5 _ HZ ) Ċĉĉĉĉĉĉ ĉ . commit () Ċĉĉĉĉ ĉ gyro . packed Angular Velocity () Ċĉĉĉĉĉĉ ĉ . add Route Async Ġ{ Ċĉĉĉĉĉĉĉ ĉ it . stream Ġ{ Ġdata , Ġenv Ġ-> Ċĉĉĉĉĉĉĉĉ ĉ val Ġcast ed Ġ= Ġdata . value ( Angular Velocity :: class . java ) Ċĉĉĉĉĉĉĉĉ ĉ val Ġnow Ġ= ĠSystem . currentTimeMillis () Ċĉĉĉĉĉĉĉĉ ĉ val Ġtimed out Ġ= Ġsensor . has Timed Out ( now ) Ċĉĉĉĉĉĉĉĉ ĉ sensor . timestamp Ġ= Ġnow Ċĉĉĉĉĉĉĉĉ ĉ logger . log ( String . format ( Locale . US , Ġ"% s ,% s ,% s ,% s ,% . 4 f ,% . 4 f ,% . 4 f ,% s % n ", Ċĉĉĉĉĉĉĉĉĉĉ ĉ data . formatted Timestamp (), Ċĉĉĉĉĉĉĉĉĉĉ ĉ env [ 0 ]. toString (), Ċĉĉĉĉĉĉĉĉĉĉ ĉ action , Ċĉĉĉĉĉĉĉĉĉĉ ĉ " gyro ", Ċĉĉĉĉĉĉĉĉĉĉ ĉ cast ed . x (), Ġcast ed . y (), Ġcast ed . z (), Ċĉĉĉĉĉĉĉĉĉĉ ĉ "\ u 0 0 B 0 / s ")) Ċĉĉĉĉĉĉĉĉ ĉ if Ġ( timed out ) Ġ{ Ċĉĉĉĉĉĉĉĉĉ ĉ update Sensor ( sensor ) Ċĉĉĉĉĉĉĉĉ ĉ } Ċĉĉĉĉĉĉĉ ĉ } Ċĉĉĉĉĉĉ ĉ } Ċĉĉĉĉĉĉ ĉ . continue With Ġ{ Ċĉĉĉĉĉĉĉ ĉ it . result . set Environment ( 0 , Ġsensor . address ) Ċĉĉĉĉĉĉĉ ĉ gyro . packed Angular Velocity (). start () Ċĉĉĉĉĉĉĉ ĉ gyro . start () Ċĉĉĉĉĉĉ ĉ } ĊĊĉĉĉĉ ĉ val Ġtimer Ġ= Ġit . getModule ( Timer :: class . java ) Ċĉĉĉĉ ĉ val Ġtemp Ġ= Ġit . getModule ( Temperature :: class . java ) Ċĉĉĉĉ ĉ val Ġtemp Sensor Ġ= Ġtemp . find Sensors ( Temperature . Sensor Type . PRE SET _ THER M IST OR )?. get ( 0 ) Ċĉĉĉĉ ĉ temp Sensor Ċĉĉĉĉĉĉ ĉ ?. add Route Async Ġ{ Ċĉĉĉĉĉĉĉ ĉ it . stream Ġ{ Ġdata , Ġenv Ġ-> Ċĉĉĉĉĉĉĉĉ ĉ val Ġnow Ġ= ĠSystem . currentTimeMillis () Ċĉĉĉĉĉĉĉĉ ĉ val Ġtimed out Ġ= Ġsensor . has Timed Out ( now ) Ċĉĉĉĉĉĉĉĉ ĉ sensor . timestamp Ġ= Ġnow Ċĉĉĉĉĉĉĉĉ ĉ logger . log ( String . format ( Locale . US , Ġ"% s ,% s ,% s ,% s ,% . 4 f ,, ,% s % n ", Ċĉĉĉĉĉĉĉĉĉĉ ĉ data . formatted Timestamp (), Ċĉĉĉĉĉĉĉĉĉĉ ĉ env [ 0 ]. toString (), Ċĉĉĉĉĉĉĉĉĉĉ ĉ action , Ċĉĉĉĉĉĉĉĉĉĉ ĉ " temp ", Ċĉĉĉĉĉĉĉĉĉĉ ĉ data . value ( Float :: class . java ObjectType ), Ċĉĉĉĉĉĉĉĉĉĉ ĉ "\ u 0 0 B 0 C ")) Ċĉĉĉĉĉĉĉĉ ĉ if Ġ( timed out ) Ġ{ Ċĉĉĉĉĉĉĉĉĉ ĉ update Sensor ( sensor ) Ċĉĉĉĉĉĉĉĉ ĉ } Ċĉĉĉĉĉĉĉ ĉ } Ċĉĉĉĉĉĉ ĉ } Ċĉĉĉĉĉĉ ĉ ?. continue With Ġ{ Ċĉĉĉĉĉĉĉ ĉ it . result . set Environment ( 0 , Ġsensor . address ) Ċĉĉĉĉĉĉĉ ĉ timer . schedule Async ( TEMP _ SAMPLE _ PERIOD , Ġfalse , Ġtemp Sensor :: read ). continue With Ġ{ Ċĉĉĉĉĉĉĉĉ ĉ it . result . start () Ċĉĉĉĉĉĉĉ ĉ } Ċĉĉĉĉĉĉ ĉ } ĊĊĉĉĉĉ ĉ val Ġled Ġ= Ġit . getModule ( Led :: class . java ) Ċĉĉĉĉ ĉ led . edit Pattern ( Led . Color . BLUE , ĠLed . Pattern Preset . P UL SE ). commit () Ċĉĉĉĉ ĉ led . edit Pattern ( Led . Color . GREEN , ĠLed . Pattern Preset . P UL SE ). commit () Ċĉĉĉĉ ĉ led . play () Ċĉĉĉ ĉ } Ċĉĉ ĉ } Ċĉ ĉ } Ċ ĉ } ĊĊ ĉ private Ġfun Ġdisconnect Sensor ( sensor : ĠSensor ) Ġ{ Ċĉ ĉ if Ġ( sensor . board ?. isConnected Ġ== Ġtrue ) Ġ{ Ċĉĉ ĉ Log . i ( TAG , Ġ" Disconnect ing Ġfrom Ġ" Ġ+ Ġsensor . address ) Ċĉĉ ĉ sensor . board ?. te ar Down () Ċĉĉ ĉ sensor . board ?. getModule ( Led :: class . java )?. stop ( true ) Ċĉĉ ĉ sensor . board ?. disconnect Async ()?. continue With Ġ{ Ċĉĉĉ ĉ update Sensor ( sensor ) Ċĉĉ ĉ } Ċĉĉ ĉ sensor . board Ġ= Ġnull Ċĉ ĉ } Ċĉ ĉ sensor . connecting Ġ= Ġfalse Ċĉ ĉ update Sensor ( sensor ) Ċ ĉ } ĊĊ ĉ private Ġfun Ġcheck Connected () Ġ{ Ċĉ ĉ for Ġ( sensor Ġin Ġadapter . sensors ) Ġ{ Ċĉĉ ĉ val Ġnow Ġ= ĠSystem . currentTimeMillis () Ċĉĉ ĉ if Ġ( sensor . board ?. isConnected Ġ== Ġtrue ) Ġ{ Ċĉĉĉ ĉ if Ġ( sensor . has Timed Out ( now )) Ġ{ Ċĉĉĉĉ ĉ update Sensor ( sensor ) Ċĉĉĉ ĉ } Ċĉĉ ĉ } Ġelse Ġif Ġ( sensor . selected Ġ&& Ġ! sensor . connecting ) Ġ{ Ċĉĉĉ ĉ connect Sensor ( sensor ) Ċĉĉ ĉ } Ċĉ ĉ } Ċĉ ĉ connected Han l der . post Delayed ( connected Runnable , Ġ 1 0 0 0 ) Ċ ĉ } ĊĊ ĉ private Ġfun Ġnavigate To ( id : ĠInt ) Ġ{ Ċĉ ĉ when Ġ( id ) Ġ{ Ċĉĉ ĉ R . id . nav _ logging Ġ-> Ġ{ Ċĉĉĉ ĉ support FragmentManager . transaction Ġ{ Ċĉĉĉĉ ĉ replace ( R . id . content , ĠSensor List Fragment ()) Ċĉĉĉ ĉ } Ċĉĉ ĉ } Ċĉĉ ĉ R . id . nav _ logs Ġ-> Ġ{ Ċĉĉĉ ĉ support FragmentManager . transaction Ġ{ Ċĉĉĉĉ ĉ replace ( R . id . content , ĠLog List Fragment ()) Ċĉĉĉ ĉ } Ċĉĉ ĉ } Ċĉĉ ĉ R . id . nav _ playback Ġ-> Ġ{ Ċĉĉĉ ĉ if Ġ( logger . is Logging ) Ġ{ Ċĉĉĉĉ ĉ val Ġbuilder Ġ= ĠAlertDialog . Builder ( this ) Ċĉĉĉĉ ĉ builder . setTitle ( R . string . log _ warn _ dialog _ title ) Ċĉĉĉĉĉĉ ĉ . setMessage ( R . string . log _ warn _ dialog _ message ) Ċĉĉĉĉĉĉ ĉ . set Positive Button ( R . string . log _ warn _ dialog _ leave ) Ġ{ Ġdialog , Ġ_ Ġ-> Ċĉĉĉĉĉĉĉ ĉ stop Logging () Ċĉĉĉĉĉĉĉ ĉ startActivity ( Intent ( this , ĠPlay back Creator Activity :: class . java )) Ċĉĉĉĉĉĉĉ ĉ dialog . dismiss () Ċĉĉĉĉĉĉ ĉ } Ċĉĉĉĉĉĉ ĉ . set Negative Button ( R . string . log _ warn _ dialog _ cancel ) Ġ{ Ġdialog , Ġ_ Ġ-> Ċĉĉĉĉĉĉĉ ĉ dialog . cancel () Ċĉĉĉĉĉĉ ĉ } Ċĉĉĉĉĉĉ ĉ . show () Ċĉĉĉ ĉ } Ġelse Ġ{ Ċĉĉĉĉ ĉ startActivity ( Intent ( this , ĠPlay back Creator Activity :: class . java )) Ċĉĉĉ ĉ } Ċĉĉ ĉ } Ċĉ ĉ } Ċĉ ĉ drawer . close Drawer ( Gravity Compat . START ) Ċ ĉ } Ċ } Ċ