package Ġdev . zv hir . android bluetooth serial Ċ Ċ import Ġio . reactivex . android . schedul ers . Android Schedulers Ċ import Ġio . reactivex . dis pos ables . Composite Disposable Ċ import Ġio . reactivex . schedul ers . Schedulers Ċ Ċ /** Ċ Ġ* ĠImplementation Ġof ĠSimple Bluetooth Device Interface , Ġpackage - private Ċ Ġ*/ Ċ internal Ġclass ĠSimple Bluetooth Device Interface Impl ( override Ġval Ġdevice : ĠBluetooth Serial Device Impl ) Ġ: ĠSimple Bluetooth Device Interface Ġ{ ĊĠĠĠ Ġprivate Ġval Ġcomposite Disposable Ġ= ĠComposite Disposable () ĊĊĠĠĠ Ġprivate Ġvar Ġmessage Received Listener : ĠSimple Bluetooth Device Interface . On Message Received Listener ? Ġ= Ġnull ĊĠĠĠ Ġprivate Ġvar Ġmessage Sent Listener : ĠSimple Bluetooth Device Interface . On Message Sent Listener ? Ġ= Ġnull ĊĠĠĠ Ġprivate Ġvar Ġerror Listener : ĠSimple Bluetooth Device Interface . OnError Listener ? Ġ= Ġnull ĊĊĠĠĠ Ġinit Ġ{ ĊĠĠĠĠĠĠĠ Ġcomposite Disposable . add ( device . open Message Stream () ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġ. subscribe On ( Schedulers . io ()) ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġ. observe On ( Android Schedulers . main Thread ()) ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġ. subscribe ({ Ġmessage Received Listener ?. on Message Received ( it ) Ġ}, Ġ{ Ġerror Listener ?. onError ( it ) Ġ})) ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġoverride Ġfun ĠsendMessage ( message : ĠString ) Ġ{ ĊĠĠĠĠĠĠĠ Ġdevice . check Not Closed () ĊĠĠĠĠĠĠĠ Ġcomposite Disposable . add ( device . send ( message ) ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġ. subscribe On ( Schedulers . io ()) ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġ. observe On ( Android Schedulers . main Thread ()) ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġ. subscribe ({ Ġmessage Sent Listener ?. on Message Sent ( message ) Ġ}, Ġ{ Ġerror Listener ?. onError ( it ) Ġ})) ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġoverride Ġfun Ġset Listeners ( message Received Listener : ĠSimple Bluetooth Device Interface . On Message Received Listener ?, ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġmessage Sent Listener : ĠSimple Bluetooth Device Interface . On Message Sent Listener ?, ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġerror Listener : ĠSimple Bluetooth Device Interface . OnError Listener ?) Ġ{ ĊĠĠĠĠĠĠĠ Ġthis . message Received Listener Ġ= Ġmessage Received Listener ĊĠĠĠĠĠĠĠ Ġthis . message Sent Listener Ġ= Ġmessage Sent Listener ĊĠĠĠĠĠĠĠ Ġthis . error Listener Ġ= Ġerror Listener ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġoverride Ġfun Ġset Message Received Listener ( listener : ĠSimple Bluetooth Device Interface . On Message Received Listener ?) Ġ{ ĊĠĠĠĠĠĠĠ Ġmessage Received Listener Ġ= Ġlistener ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġoverride Ġfun Ġset Message Sent Listener ( listener : ĠSimple Bluetooth Device Interface . On Message Sent Listener ?) Ġ{ ĊĠĠĠĠĠĠĠ Ġmessage Sent Listener Ġ= Ġlistener ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġoverride Ġfun ĠsetError Listener ( listener : ĠSimple Bluetooth Device Interface . OnError Listener ?) Ġ{ ĊĠĠĠĠĠĠĠ Ġerror Listener Ġ= Ġlistener ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġfun Ġclose () Ġ{ ĊĠĠĠĠĠĠĠ Ġcomposite Disposable . dispose () ĊĠĠĠ Ġ} Ċ } Ċ