package Ġru . st ark soft . commons . ui Ċ Ċ import Ġandroid . app . Activity Ċ import Ġandroid . content . Context Ċ import Ġandroid . content . pm . Activity Info Ċ import Ġandroid . os . Build Ċ import Ġandroid . view .* Ċ import Ġandroidx . annotation . Int Def Ċ import Ġandroidx . core . content . Context Compat Ċ import Ġandroidx . core . view . Window Insets Compat Ċ import Ġdev . chr is ban es . in setter . ViewState Ċ import Ġdev . chr is ban es . in setter . do On Apply Window Insets Ċ Ċ private Ġvar Ġhas NavBar : ĠBoolean ? Ġ= Ġnull Ċ Ċ fun ĠActivity . setup Fullscreen () Ġ{ Ċ ĉ if Ġ( Build . VERSION . SDK _ INT Ġin Ġ 1 9 .. 2 0 ) Ġ{ Ċĉ ĉ window . apply Ġ{ Ċĉĉ ĉ add Flags ( WindowManager . LayoutParams . FLAG _ TRANSL UC ENT _ STATUS ) Ċĉĉ ĉ add Flags ( WindowManager . LayoutParams . FLAG _ TRANSL UC ENT _ NAV IG ATION ) Ċĉ ĉ } Ċ ĉ } Ċ ĉ if Ġ( Build . VERSION . SDK _ INT Ġ>= Ġ 1 9 ) Ġ{ Ċĉ ĉ val Ġchild At Ġ= Ġ( window . decor View Ġas ĠViewGroup ). getChild At ( 0 ) Ċĉ ĉ child At . system Ui Visibility Ġ= Ġget UI Show ed Flags () Ċ ĉ } Ċ ĉ if Ġ( Build . VERSION . SDK _ INT Ġ>= Ġ 2 1 ) Ġ{ Ċĉ ĉ window . apply Ġ{ Ċĉĉ ĉ clear Flags ( WindowManager . LayoutParams . FLAG _ TRANSL UC ENT _ STATUS ) Ċĉĉ ĉ clear Flags ( WindowManager . LayoutParams . FLAG _ TRANSL UC ENT _ NAV IG ATION ) Ċĉ ĉ } Ċ ĉ } Ċ ĉ if Ġ( Build . VERSION . SDK _ INT Ġ>= ĠBuild . VERSION _ CODES . P ) Ġ{ Ċĉ ĉ window . attributes . layout In Display Cut out Mode Ġ= ĠWindow Manager . LayoutParams . LAYOUT _ IN _ DISPLAY _ CUT OUT _ MODE _ SHORT _ ED GES ; Ċ ĉ } Ċ } Ċ Ċ fun ĠWindow . hide System UI () Ġ{ Ċ ĉ decor View . system Ui Visibility Ġ= Ċĉ ĉ ( View . SYSTEM _ UI _ FLAG _ IM MER SIVE Ċĉĉĉ ĉ or ĠView . SYSTEM _ UI _ FLAG _ LAYOUT _ ST ABLE Ċĉĉĉ ĉ or ĠView . SYSTEM _ UI _ FLAG _ LAYOUT _ HIDE _ NAV IG ATION Ċĉĉĉ ĉ or ĠView . SYSTEM _ UI _ FLAG _ LAYOUT _ FULL SCREEN Ċĉĉĉ ĉ or ĠView . SYSTEM _ UI _ FLAG _ FULL SCREEN ) Ċ } Ċ Ċ fun ĠWindow . show System UI () Ġ{ Ċ ĉ decor View . system Ui Visibility Ġ= Ġget UI Show ed Flags () Ċ } Ċ Ċ private Ġfun Ġget UI Show ed Flags (): ĠInt Ġ{ Ċ ĉ return ĠView . SYSTEM _ UI _ FLAG _ LAYOUT _ ST ABLE Ġor ĠView . SYSTEM _ UI _ FLAG _ LAYOUT _ FULL SCREEN Ġor ĠView . SYSTEM _ UI _ FLAG _ LAYOUT _ HIDE _ NAV IG ATION Ċ } Ċ Ċ fun Ġget StatusBar Height ( context : ĠContext ) Ġ= Ġget Dim en ( context , Ġ" status _ bar _ height ") Ċ Ċ fun Ġget NavBar Height ( context : ĠContext ) Ġ= Ġget Dim en ( context , Ġ" navigation _ bar _ height ") Ċ Ċ fun Ġget Dim en ( context : ĠContext , Ġresource String : ĠString ): ĠInt Ġ{ Ċ ĉ return Ġwith ( context . resources ) Ġ{ Ċĉ ĉ val Ġid Ġ= Ġget Identifier ( resource String , Ġ" dim en ", Ġ" android ") Ċĉ ĉ if Ġ( id Ġ> Ġ 0 ) Ġ{ Ċĉĉ ĉ get Dimension Pixel Size ( id ) Ċĉ ĉ } Ġelse Ġ{ Ċĉĉĉ 0 Ċĉ ĉ } Ċ ĉ } Ċ } Ċ Ċ fun Ġhas NavBar ( context : ĠContext ): ĠBoolean Ġ{ Ċ ĉ if Ġ( has NavBar Ġ!= Ġnull ) Ġ{ Ċĉ ĉ return Ġhas NavBar !! Ċ ĉ } Ċ ĉ val Ġres Ġ= Ġcontext . resources Ċ ĉ val Ġresource Id Ġ= Ġres . getIdentifier (" config _ show NavigationBar ", Ġ" bool ", Ġ" android ") Ċ ĉ if Ġ( resourceId Ġ!= Ġ 0 ) Ġ{ Ċĉ ĉ has NavBar Ġ= Ġres . getBoolean ( resourceId ) Ċ ĉ } Ġelse Ġ{ Ċĉ ĉ val Ġhas Menu Key Ġ= ĠView Configuration . get ( context ). has Permanent Menu Key () Ċĉ ĉ val Ġhas Back Key Ġ= ĠKey Character Map . device HasKey ( KeyEvent . KEYCODE _ BACK ) Ċĉ ĉ val Ġhas Home Key Ġ= ĠKey Character Map . device HasKey ( KeyEvent . KEYCODE _ HOME ) Ċĉ ĉ has NavBar Ġ= Ġ!( has Menu Key Ġ|| Ġhas Back Key Ġ&& Ġhas Home Key ) Ċ ĉ } Ċ ĉ return Ġhas NavBar !! Ċ } Ċ Ċ fun ĠView . setOn System Ui Visibility ChangeListener Ex ( callback : Ġ( show : ĠBoolean ) Ġ-> ĠUnit ) Ġ{ Ċ ĉ setOn System Ui Visibility ChangeListener Ġ{ Ġvisibility Ġ-> Ċĉ ĉ // ĠNote Ġthat Ġsystem Ġbars Ġwill Ġonly Ġbe Ġ" visible " Ġif Ġnone Ġof Ġthe Ċĉ ĉ // ĠLOW _ PROFILE , ĠH IDE _ NAV IG ATION , Ġor ĠFULL SCREEN Ġflags Ġare Ġset . Ċĉ ĉ if Ġ( visibility Ġand ĠView . SYSTEM _ UI _ FLAG _ FULL SCREEN Ġ== Ġ 0 ) Ġ{ Ċĉĉ ĉ // ĠTODO : ĠThe Ġsystem Ġbars Ġare Ġvisible . ĠMake Ġany Ġdesired Ċĉĉ ĉ // Ġadjust ments Ġto Ġyour ĠUI , Ġsuch Ġas Ġshowing Ġthe Ġaction Ġbar Ġor Ċĉĉ ĉ // Ġother Ġnavig ational Ġcontrols . Ċĉĉ ĉ callback ( true ) ĊĊĉ ĉ } Ġelse Ġ{ Ċĉĉ ĉ // ĠTODO : ĠThe Ġsystem Ġbars Ġare ĠNOT Ġvisible . ĠMake Ġany Ġdesired Ċĉĉ ĉ // Ġadjust ments Ġto Ġyour ĠUI , Ġsuch Ġas Ġhiding Ġthe Ġaction Ġbar Ġor Ċĉĉ ĉ // Ġother Ġnavig ational Ġcontrols . Ċĉĉ ĉ callback ( false ) Ċĉ ĉ } Ċ ĉ } Ċ } Ċ Ċ fun ĠView . do On Apply Window Insets Compat ( action : Ġ( view : ĠView , Ġin sets : ĠSystem Insets Wrapper , ĠinitialState : ĠView State ) Ġ-> ĠUnit ) Ġ{ Ċ ĉ if Ġ( Build . VERSION . SDK _ INT Ġin Ġ 1 9 .. 2 0 ) Ġ{ Ċĉ ĉ val Ġin sets Wrapper Ġ= Ġwhen Ġ( get Screen Orientation ( context )) Ġ{ Ċĉĉ ĉ Activity Info . SCREEN _ OR IENTATION _ POR TRA IT Ġ-> Ġ{ Ċĉĉĉ ĉ System Insets Wrapper ( top Ġ= Ġget StatusBar Height ( context ), Ġbottom Ġ= Ġget NavBar Height ( context )) Ċĉĉ ĉ } ĊĊĉĉ ĉ Activity Info . SCREEN _ OR IENTATION _ RE VERSE _ LAND SC APE Ġ-> Ġ{ Ċĉĉĉ ĉ System Insets Wrapper ( top Ġ= Ġget StatusBar Height ( context ), Ġright Ġ= Ġget NavBar Height ( context )) Ċĉĉ ĉ } Ċĉĉ ĉ Activity Info . SCREEN _ OR IENTATION _ LAND SC APE Ġ-> Ġ{ Ċĉĉĉ ĉ System Insets Wrapper ( top Ġ= Ġget StatusBar Height ( context ), Ġright Ġ= Ġget NavBar Height ( context )) Ċĉĉ ĉ } Ċĉĉ ĉ else Ġ-> ĠSystem Insets Wrapper ( 0 , Ġ 0 , Ġ 0 , Ġ 0 ) Ċĉ ĉ } ĊĊĉ ĉ action ( this , Ġin sets Wrapper , ĠView State ( this )) ĊĊ ĉ } Ġelse Ġ{ Ċĉ ĉ do On Apply Window Insets Ġ{ Ġview , Ġin sets , ĠinitialState Ġ-> Ġaction ( view , Ġin sets . map To System Insets Wrapper (), ĠinitialState ) Ġ} Ċ ĉ } Ċ } Ċ Ċ @ Screen Orientation Ċ fun Ġget Screen Orientation ( context : ĠContext ): ĠInt Ġ{ Ċ ĉ val Ġwindow Manager Ġ= ĠContext Compat . getSystem Service ( context , ĠWindow Manager :: class . java ) ĊĊ ĉ return Ġwhen Ġ( window Manager ?. default Display ?. rotation ) Ġ{ Ċĉ ĉ Surface . ROT ATION _ 9 0 Ġ-> ĠActivity Info . SCREEN _ OR IENTATION _ LAND SC APE Ċĉ ĉ Surface . ROT ATION _ 1 8 0 Ġ-> ĠActivity Info . SCREEN _ OR IENTATION _ RE VERSE _ POR TRA IT Ċĉ ĉ Surface . ROT ATION _ 2 7 0 Ġ-> ĠActivity Info . SCREEN _ OR IENTATION _ RE VERSE _ LAND SC APE Ċĉ ĉ Surface . ROT ATION _ 0 Ġ-> ĠActivity Info . SCREEN _ OR IENTATION _ POR TRA IT Ċĉ ĉ else Ġ-> ĠActivity Info . SCREEN _ OR IENTATION _ POR TRA IT Ċ ĉ } Ċ } Ċ Ċ @ Int Def ( Ċ ĉ Activity Info . SCREEN _ OR IENTATION _ LAND SC APE , Ċ ĉ Activity Info . SCREEN _ OR IENTATION _ POR TRA IT , Ċ ĉ Activity Info . SCREEN _ OR IENTATION _ RE VERSE _ LAND SC APE , Ċ ĉ Activity Info . SCREEN _ OR IENTATION _ RE VERSE _ POR TRA IT Ċ ) Ċ @ Retention ( Annotation Retention . SOURCE ) Ċ annotation Ġclass ĠScreen Orientation Ċ Ċ data Ġclass ĠSystem Insets Wrapper ( Ċ ĉ val Ġleft : ĠInt Ġ= Ġ 0 , Ċ ĉ val Ġtop : ĠInt Ġ= Ġ 0 , Ċ ĉ val Ġright : ĠInt Ġ= Ġ 0 , Ċ ĉ val Ġbottom : ĠInt Ġ= Ġ 0 Ċ ) Ċ Ċ fun ĠWindow Insets Compat . map To System Insets Wrapper (): ĠSystem Insets Wrapper Ġ{ Ċ ĉ return ĠSystem Insets Wrapper ( system Window Inset Left , Ġsystem Window Inset Top , Ġsystem Window Inset Right , Ġsystem Window Inset Bottom ) Ċ } Ċ