package Ġcom . github . ush ios an 2 3 . app . activities Ċ Ċ import Ġandroid . content . res . Configuration Ċ import Ġandroid . os . Bundle Ċ import Ġandroid . view . View Ċ import Ġandroid . widget . Toast Ċ import Ġandroidx . appcompat . app . AppCompat Delegate Ċ import Ġandroidx . appcompat . content . res . AppCompat Resources Ċ import Ġcom . github . ush ios an 2 3 . android _ utilities . android . activity . Activity Compat Binding Ċ import Ġcom . github . ush ios an 2 3 . android _ utilities . android . time . Time Units Ċ import Ġcom . github . ush ios an 2 3 . android _ utilities . android . time . Timer Task Ċ import Ġcom . github . ush ios an 2 3 . android _ utilities . extensions . make Sn ack Ċ import Ġcom . github . ush ios an 2 3 . android _ utilities . extensions . make Toast Ċ import Ġcom . github . ush ios an 2 3 . android _ utilities . extensions . resolve Class Ċ import Ġcom . github . ush ios an 2 3 . app . R Ċ import Ġcom . github . ush ios an 2 3 . app . databinding . Activity Main Binding Ċ import Ġcom . github . ush ios an 2 3 . app . dialogs . DeviceInfo Dialog Ċ import Ġcom . github . ush ios an 2 3 . app . dialogs . Example Dialog Ċ import Ġcom . google . android . material . sn ackbar . Snackbar Ċ Ċ class ĠActivity Main Ġ: ĠActivity Compat Binding < Activity Main Binding >() Ġ{ ĊĊ ĉ override Ġval Ġbinding Class : ĠClass < Activity Main Binding > Ġ= Ġresolve Class () ĊĊ ĉ override Ġfun Ġon Activity Loaded ( savedInstanceState : ĠBundle ?) Ġ{ Ċĉ ĉ binding . example Button . setOnClickListener ( this :: on Button Clicked ) Ċĉ ĉ binding . example Theme Toggle . setOnClickListener ( this :: on Toggle Theme Clicked ) Ċĉ ĉ binding . example Button Dialog . setOnClickListener ( this :: on Button Dialog Clicked ) Ċĉ ĉ binding . hardware Information Button . setOnClickListener ( this :: on Button Info Dialog Clicked ) Ċĉ ĉ binding . timer Task Button . setOnClickListener ( this :: on Button Timer Task Clicked ) ĊĊĉ ĉ // ĠChange Ġtheme Ċĉ ĉ val Ġcurrent Night Mode Ġ= Ġresources Ċĉĉ ĉ . configuration Ċĉĉ ĉ . ui Mode Ġand ĠConfiguration . UI _ MODE _ N IGHT _ MASK Ċĉ ĉ val Ġis Night Mode Active Ġ= Ġcurrent Night Mode Ġ== ĠConfiguration . UI _ MODE _ N IGHT _ YES Ċĉ ĉ val Ġdrawable Ġ= ĠAppCompat Resources . get Drawable ( Ċĉĉ ĉ this , Ċĉĉ ĉ if Ġ( is Night Mode Active ) ĠR . drawable . ic _ moon Ġelse ĠR . drawable . ic _ sun Ċĉ ĉ ) Ċĉ ĉ binding . example Theme Toggle . setImage Drawable ( drawable ) Ċ ĉ } ĊĊ ĉ /* Ġ------------------------------------------------ --------- Ċĉ Ġ* Ċĉ Ġ* ĠEvents Ċĉ Ġ* Ċĉ Ġ* Ġ------------------------------------------------ --------- Ġ*/ ĊĊ ĉ private Ġfun Ġon Button Clicked ( v : ĠView ) Ġ{ Ċĉ ĉ val Ġsn ack Ġ= Ġv . make Sn ack ( Ċĉĉ ĉ " Hello , ĠWorld !", Ċĉĉ ĉ Snackbar . LENGTH _ IN DEFIN ITE Ċĉ ĉ ) ĊĊĉ ĉ sn ack . setAction (" Ok ") Ġ{ Ċĉĉ ĉ sn ack . dismiss () Ċĉ ĉ }. show () Ċ ĉ } ĊĊ ĉ @ Suppress (" UNUSED _ PARAMETER ") Ċ ĉ private Ġfun Ġon Toggle Theme Clicked ( v : ĠView ) Ġ{ Ċĉ ĉ // ĠChange Ġtheme Ċĉ ĉ val Ġcurrent Night Mode Ġ= Ġresources Ċĉĉ ĉ . configuration Ċĉĉ ĉ . ui Mode Ġand ĠConfiguration . UI _ MODE _ N IGHT _ MASK Ċĉ ĉ val Ġis Night Mode Active Ġ= Ġcurrent Night Mode Ġ== ĠConfiguration . UI _ MODE _ N IGHT _ YES ĊĊĉ ĉ make Toast ( Ċĉĉ ĉ " Night ĠMode Ġ${ ! is Night Mode Active }", Ċĉĉ ĉ Toast . LENGTH _ SHORT Ċĉ ĉ ). show () ĊĊĊĉ ĉ AppCompat Delegate . setDefault Night Mode ( Ċĉĉ ĉ if Ġ( is Night Mode Active ) ĠAppCompat Delegate . MODE _ N IGHT _ NO Ġelse ĠAppCompat Delegate . MODE _ N IGHT _ YES Ċĉ ĉ ) Ċ ĉ } ĊĊ ĉ @ Suppress (" UNUSED _ PARAMETER ") Ċ ĉ private Ġfun Ġon Button Dialog Clicked ( v : ĠView ) Ġ{ Ċĉ ĉ val Ġdialog Ġ= ĠExample Dialog () Ċĉ ĉ dialog . show ( support FragmentManager , Ġ" Example Dialog ") Ċ ĉ } ĊĊ ĉ @ Suppress (" UNUSED _ PARAMETER ") Ċ ĉ private Ġfun Ġon Button Info Dialog Clicked ( v : ĠView ) Ġ{ Ċĉ ĉ val Ġdialog Ġ= ĠDevice Info Dialog () Ċĉ ĉ dialog . show ( support FragmentManager , Ġ" DeviceInfo Dialog ") Ċ ĉ } ĊĊ ĉ @ Suppress (" UNUSED _ PARAMETER ") Ċ ĉ private Ġfun Ġon Button Timer Task Clicked ( v : ĠView ) Ġ{ Ċĉ ĉ var Ġseconds Ġ= Ġ 1 Ċĉ ĉ var Ġtask : ĠTimer Task ? Ġ= Ġnull ĊĊĉ ĉ task Ġ= ĠTimer Task . generate Timer Task ( Time Units . get Seconds ( 3 )) Ġ{ Ċĉĉ ĉ if Ġ( seconds Ġ>= Ġ 3 ) Ċĉĉĉ ĉ task !!. stop () ĊĊĉĉ ĉ run On Ui Thread Ġ{ Ċĉĉĉ ĉ make Toast (" Timer ĠTask ", ĠToast . LENGTH _ SHORT ) Ċĉĉĉĉ ĉ . show () Ċĉĉ ĉ } Ċĉĉ ĉ seconds ++ Ċĉ ĉ } Ċĉ ĉ task . start ( false ) Ċ ĉ } Ċ Ċ } Ċ