package Ġcom . ow ll ife . yout ub ebook mark . presentation . player Ċ Ċ import Ġandroid . content . pm . Activity Info Ċ import Ġandroid . content . pm . PackageManager Ċ import Ġandroid . os . Build Ċ import Ġandroid . widget . ImageView Ċ import Ġandroidx . core . content . Context Compat Ċ import Ġandroidx . fragment . app . Fragment Activity Ċ import Ġandroidx . lifecycle . Lifecycle Owner Ċ import Ġandroidx . lifecycle . LiveData Ċ import Ġandroidx . lifecycle . Observer Ċ import Ġcom . ow ll ife . yout ub ebook mark . R Ċ import Ġcom . pi er fr ances co so ff rit ti . android youtube player . core . player . listeners . YouTube Player FullScreen Listener Ċ import Ġcom . pi er fr ances co so ff rit ti . android youtube player . core . player . views . YouTube Player View Ċ Ċ /** Ċ Ġ* Ġ@ author Ġow ll ife . dev Ċ Ġ* Ġ@ since Ġ 2 0 . Ġ 6 . Ġ 2 2 Ċ Ġ*/ Ċ class ĠY outube Player View Manager ( ĊĠĠĠ Ġprivate Ġval Ġyou Tube Player View : ĠYouTube Player View , ĊĠĠĠ Ġprivate Ġval Ġactivity : ĠFragment Activity Ċ ) Ġ{ ĊĊĠĠĠ Ġprivate Ġvar Ġpicture In Picture Icon : ĠImageView Ġ= ĠImageView ( activity ) ĊĠĠĠ Ġprivate Ġvar Ġyou Tube Player FullScreen Listener : ĠYouTube Player FullScreen Listener Ġ= ĊĠĠĠĠĠĠĠ ĠYouTube Player FullScreen Listener Impl () ĊĊĠĠĠ Ġinit Ġ{ ĊĠĠĠĠĠĠĠ Ġactivity . lifecycle . add Observer ( you Tube Player View ) ĊĠĠĠĠĠĠĠ Ġpicture In Picture Icon . setImage Drawable ( ĊĠĠĠĠĠĠĠĠĠĠĠ ĠContext Compat . get Drawable ( activity , ĠR . drawable . ic _ pip _ 2 4 dp ) ĊĠĠĠĠĠĠĠ Ġ) ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġ@ Suppress (" DE PREC ATION ") ĊĠĠĠ Ġfun Ġinit Ui Buttons () Ġ{ ĊĠĠĠĠĠĠĠ Ġif Ġ(! support Pip Mode ()) Ġ{ ĊĠĠĠĠĠĠĠĠĠĠĠ Ġreturn ĊĠĠĠĠĠĠĠ Ġ} ĊĠĠĠĠĠĠĠ Ġpicture In Picture Icon . setOnClickListener Ġ{ ĊĠĠĠĠĠĠĠĠĠĠĠ Ġval Ġhas Feature Ġ= ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġactivity . package Manager . has System Feature ( PackageManager . FEATURE _ PI CTURE _ IN _ PI CTURE ) ĊĠĠĠĠĠĠĠĠĠĠĠ Ġif Ġ( has Feature ) Ġactivity . enter Picture In Picture Mode () ĊĠĠĠĠĠĠĠ Ġ} ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġ@ Suppress (" DE PREC ATION ") ĊĠĠĠ Ġfun Ġbind Pip LiveData ( lifecycle Owner : ĠLifecycle Owner , Ġlive Data : ĠLive Data < Boolean >) Ġ{ ĊĠĠĠĠĠĠĠ Ġif Ġ(! support Pip Mode ()) Ġ{ ĊĠĠĠĠĠĠĠĠĠĠĠ Ġreturn ĊĠĠĠĠĠĠĠ Ġ} ĊĠĠĠĠĠĠĠ Ġlive Data . observe ( lifecycle Owner , ĠObserver Ġ{ ĊĠĠĠĠĠĠĠĠĠĠĠ Ġif Ġ( it ) Ġ{ ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġactivity . enter Picture In Picture Mode () ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġyou Tube Player View . getPlayer Ui Controller (). addView ( picture In Picture Icon ) ĊĠĠĠĠĠĠĠĠĠĠĠ Ġ} Ġelse Ġ{ ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġyou Tube Player View . getPlayer Ui Controller (). remove View ( picture In Picture Icon ) ĊĠĠĠĠĠĠĠĠĠĠĠ Ġ} ĊĠĠĠĠĠĠĠ Ġ}) ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġfun Ġremove Observer s ( lifecycle Owner : ĠLifecycle Owner , Ġlive Data : ĠLive Data < Boolean >) Ġ{ ĊĠĠĠĠĠĠĠ Ġlive Data . remove Observer s ( lifecycle Owner ) ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġfun Ġinit FullScreen Listener () Ġ{ ĊĠĠĠĠĠĠĠ Ġyou Tube Player View . add FullScreen Listener ( you Tube Player FullScreen Listener ) ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġfun Ġremove FullScreen Listener () Ġ{ ĊĠĠĠĠĠĠĠ Ġyou Tube Player View . remove FullScreen Listener ( you Tube Player FullScreen Listener ) ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġfun Ġbind Ui Controller Visibility ( lifecycle Owner : ĠLifecycle Owner , Ġlive Data : ĠLive Data < Boolean >) Ġ{ ĊĠĠĠĠĠĠĠ Ġlive Data . observe ( lifecycle Owner , ĠObserver Ġ{ ĊĠĠĠĠĠĠĠĠĠĠĠ Ġyou Tube Player View . getPlayer Ui Controller (). show Ui ( it ) ĊĠĠĠĠĠĠĠ Ġ}) ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġprivate Ġfun Ġsupport Pip Mode (): ĠBoolean Ġ{ ĊĠĠĠĠĠĠĠ Ġreturn ĠBuild . VERSION . SDK _ INT Ġ>= ĠBuild . VERSION _ CODES . N ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġinner Ġclass ĠYouTube Player FullScreen Listener Impl Ġ: ĠYouTube Player FullScreen Listener Ġ{ ĊĊĠĠĠĠĠĠĠ Ġoverride Ġfun Ġon YouTube Player Enter FullScreen () Ġ{ ĊĠĠĠĠĠĠĠĠĠĠĠ Ġactivity . requested Orientation Ġ= ĠActivity Info . SCREEN _ OR IENTATION _ LAND SC APE ĊĠĠĠĠĠĠĠĠĠĠĠ Ġyou Tube Player View . enter FullScreen () ĊĠĠĠĠĠĠĠ Ġ} ĊĊĠĠĠĠĠĠĠ Ġoverride Ġfun Ġon YouTube Player Exit FullScreen () Ġ{ ĊĠĠĠĠĠĠĠĠĠĠĠ Ġactivity . requested Orientation Ġ= ĠActivity Info . SCREEN _ OR IENTATION _ POR TRA IT ĊĠĠĠĠĠĠĠĠĠĠĠ Ġyou Tube Player View . exit FullScreen () ĊĠĠĠĠĠĠĠ Ġ} ĊĠĠĠ Ġ} Ċ }