package Ġcom . jiang k ang . tools . widget Ċ Ċ import Ġandroid . Manifest Ċ import Ġandroid . content . Context Ċ import Ġandroid . graphics . PixelFormat Ċ import Ġandroid . os . Build Ċ import Ġandroid . view . Gravity Ċ import Ġandroid . view . LayoutInflater Ċ import Ġandroid . view . View Ċ import Ġandroid . view . WindowManager Ċ import Ġandroid . widget . TextView Ċ import Ġandroidx . annotation . Requires Permission Ċ import Ġcom . jiang k ang . tools . R Ċ Ċ /** Ċ Ġ* ĠCreated Ġby Ġji ang k ang Ġon Ġ 2 0 1 7 / 9 / 2 3 . Ċ Ġ*/ Ċ object ĠFloating Window Ġ{ ĊĠĠĠ Ġprivate Ġvar Ġs WindowManager : ĠWindow Manager ? Ġ= Ġnull ĊĠĠĠ Ġprivate Ġvar Ġs Window LayoutParams : ĠWindow Manager . LayoutParams ? Ġ= Ġnull ĊĠĠĠ Ġprivate Ġvar Ġs View : ĠView ? Ġ= Ġnull ĊĠĠĠ Ġfun Ġinit ( context : ĠContext ) Ġ{ ĊĠĠĠĠĠĠĠ Ġs WindowManager Ġ= Ġcontext . application Context . getSystem Service ( Context . WINDOW _ SERVICE ) Ġas ĠWindow Manager ĊĠĠĠĠĠĠĠ Ġs Window LayoutParams Ġ= ĠWindow Manager . LayoutParams ( ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ ĠWindow Manager . LayoutParams . WRAP _ CONTENT , ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ ĠWindow Manager . LayoutParams . WRAP _ CONTENT , ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġif Ġ( Build . VERSION . SDK _ INT Ġ> ĠBuild . VERSION _ CODES . N ) ĠWindow Manager . LayoutParams . TYPE _ APPLICATION _ OVER LAY Ġelse ĠWindow Manager . LayoutParams . TYPE _ TO AST , ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ ĠWindow Manager . LayoutParams . FLAG _ NOT _ FOCUS ABLE Ġor ĠWindow Manager . LayoutParams . FLAG _ NOT _ TO UCH _ MOD AL , ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ ĠPixel Format . TRANSL UC ENT ĊĠĠĠĠĠĠĠ Ġ) ĊĠĠĠĠĠĠĠ Ġs Window LayoutParams !!. gravity Ġ= ĠGr avity . TOP Ġ+ ĠGr avity . RIGHT ĊĠĠĠĠĠĠĠ Ġs View Ġ= ĠLayoutInflater . from ( context ). inflate ( R . layout . layout _ floating _ window , Ġnull ) ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġ@ Requires Permission ( all Of Ġ= Ġ[ Manifest . permission . SYSTEM _ ALERT _ WINDOW ]) ĊĠĠĠ Ġfun Ġshow ( context : ĠContext , Ġcontent : ĠString ?) Ġ{ ĊĠĠĠĠĠĠĠ Ġif Ġ( s WindowManager Ġ== Ġnull ) Ġ{ ĊĠĠĠĠĠĠĠĠĠĠĠ Ġinit ( context ) ĊĠĠĠĠĠĠĠ Ġ} ĊĠĠĠĠĠĠĠ Ġval Ġtv Content Ġ= Ġs View !!. findViewById < View >( R . id . tv _ window _ content ) Ġas ĠTextView ĊĠĠĠĠĠĠĠ Ġtv Content . text Ġ= Ġcontent ĊĠĠĠĠĠĠĠ Ġif Ġ(! s View !!. is Attached To Window ) Ġ{ ĊĠĠĠĠĠĠĠĠĠĠĠ Ġs WindowManager !!. addView ( s View , Ġs Window LayoutParams ) ĊĠĠĠĠĠĠĠ Ġ} ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġfun Ġdismiss () Ġ{ ĊĠĠĠĠĠĠĠ Ġif Ġ( s WindowManager Ġ!= Ġnull Ġ&& Ġs View Ġ!= Ġnull Ġ&& Ġs View !!. is Attached To Window ) Ġ{ ĊĠĠĠĠĠĠĠĠĠĠĠ Ġs WindowManager !!. remove View ( s View ) ĊĠĠĠĠĠĠĠ Ġ} ĊĠĠĠ Ġ} Ċ }