package Ġcom . example . clipboard _ monitor Ċ Ċ import Ġandroid . content . Clipboard Manager Ċ import Ġandroidx . annotation . NonNull Ċ Ċ import Ġio . flutter . embedding . engine . plugins . Flutter Plugin Ċ import Ġio . flutter . plugin . common . MethodCall Ċ import Ġio . flutter . plugin . common . Method Channel Ċ import Ġio . flutter . plugin . common . Method Channel . MethodCall Handler Ċ import Ġio . flutter . plugin . common . Method Channel . Result Ċ import Ġandroid . content . Context Ċ import Ġio . flutter . plugin . common . Binary Messenger ĊĊĊĊ Ċ /** ĠClip board Monitor Plugin Ġ*/ Ċ class ĠClip board Monitor Plugin : ĠFlutter Plugin , ĠMethod Call Handler Ġ{ ĊĊĊĠ Ġ/// ĠThe ĠMethod Channel Ġthat Ġwill Ġthe Ġcommunication Ġbetween ĠFlutter Ġand Ġnative ĠAndroid ĊĠ Ġ/// ĊĠ Ġ/// ĠThis Ġlocal Ġreference Ġserves Ġto Ġregister Ġthe Ġplugin Ġwith Ġthe ĠFlutter ĠEngine Ġand Ġunregister Ġit ĊĠ Ġ/// Ġwhen Ġthe ĠFlutter ĠEngine Ġis Ġdet ached Ġfrom Ġthe ĠActivity ĊĠ Ġprivate Ġlateinit Ġvar Ġchannel Ġ: ĠMethod Channel ĊĠ Ġprivate Ġlateinit Ġvar ĠmContext Ġ: ĠContext ĊĊĠ Ġprivate Ġval ĠCHAN NEL _ NAME Ġ= Ġ" clipboard _ monitor " ĊĊĠ Ġprivate Ġfun Ġsetup Channel ( messenger : ĠBinary Messenger , Ġcontext : ĠContext ) Ġ{ ĊĠĠĠ Ġchannel Ġ= ĠMethod Channel ( messenger , ĠCHAN NEL _ NAME ) ĊĠĠĠ ĠmContext Ġ= Ġcontext ĊĠĠĠ Ġchannel . set MethodCall Handler ( this ) ĊĠ Ġ} ĊĊĠ Ġoverride Ġfun Ġon Attached To Engine (@ NonNull Ġbinding : ĠFlutter Plugin . Flutter Plugin Binding ) Ġ{ ĊĠĠĠ Ġsetup Channel ( binding . binary Messenger , Ġbinding . application Context ); ĊĠ Ġ} ĊĊĠ Ġoverride Ġfun Ġon MethodCall (@ NonNull Ġcall : ĠMethod Call , Ġ@ NonNull Ġresult : ĠResult ) Ġ{ ĊĠĠĠ Ġif Ġ( call . method Ġ== Ġ" monitor Clipboard ") Ġ{ ĊĊĠĠĠĠĠ Ġval Ġclipboard Ġ= ĠmContext . getSystem Service ( Context . CLIP BOARD _ SERVICE ) Ġas ĠClip board Manager ĊĊĠĠĠĠĠ Ġclipboard . add Primary Clip Changed Listener Ġ{ ĊĠĠĠĠĠĠĠ Ġval Ġclip Ġ= Ġclipboard . primary Clip ĊĠĠĠĠĠĠĠ Ġif Ġ( clip ?. item Count Ġ== Ġ 1 ) Ġ{ ĊĠĠĠĠĠĠĠĠĠ Ġval Ġtext Ġ= Ġclip . getItem At ( 0 ). text ĊĠĠĠĠĠĠĠĠĠ Ġif Ġ( text . isNotEmpty ()) Ġ{ ĊĠĠĠĠĠĠĠĠĠĠĠ Ġchannel . invoke Method (" cli pt ext ", Ġtext ) ĊĠĠĠĠĠĠĠĠĠ Ġ} ĊĠĠĠĠĠĠĠ Ġ} ĊĠĠĠĠĠ Ġ} ĊĊĠĠĠĠĠ Ġresult . success ( true ) ĊĊĠĠĠ Ġ} Ġelse Ġ{ ĊĠĠĠĠĠ Ġresult . not Implemented () ĊĠĠĠ Ġ} ĊĠ Ġ} ĊĊĠ Ġoverride Ġfun Ġon Detached From Engine (@ NonNull Ġbinding : ĠFlutter Plugin . Flutter Plugin Binding ) Ġ{ ĊĠĠĠ Ġchannel . set MethodCall Handler ( null ) ĊĠ Ġ} Ċ } Ċ