package Ġpl . d roid son roid s . gif . sample Ċ Ċ import Ġandroid . annotation . Suppress Lint Ċ import Ġandroid . graphics . drawable . Drawable Ċ import Ġandroid . graphics . drawable . State List Drawable Ċ import Ġandroid . os . Build Ċ import Ġandroid . os . Bundle Ċ import Ġandroid . view . LayoutInflater Ċ import Ġandroid . view . View Ċ import Ġandroid . view . ViewGroup Ċ import Ġandroidx . fragment . app . Fragment Ċ import Ġkotlinx . android . synt hetic . main . animated _ selector . view .* Ċ import Ġpl . d roid son roid s . gif . Gif Drawable Ċ Ċ class ĠAnimated Selector Fragment Ġ: ĠFragment () Ġ{ ĊĊ ĉ @ Suppress (" DE PREC ATION ") Ċ ĉ override Ġfun ĠonCreate View ( in flater : ĠLayoutInflater , Ġcontainer : ĠViewGroup ?, ĠsavedInstanceState : ĠBundle ?): ĠView ? Ġ{ Ċĉ ĉ val Ġroot View Ġ= Ġinflater . inflate ( R . layout . animated _ selector , Ġcontainer , Ġfalse ) Ċĉ ĉ root View . button Kotlin . setBackground Drawable ( kotlin Animated Background ) ĊĊĉ ĉ if Ġ( Build . VERSION . SDK _ INT Ġ< ĠBuild . VERSION _ CODES . N ) Ġ{ Ċĉĉ ĉ root View . button XML . setBackground Drawable ( xml Animated Background ) Ċĉ ĉ } ĊĊĉ ĉ return Ġroot View Ċ ĉ } ĊĊ ĉ private Ġval Ġxml Animated Background : ĠDrawable Ċĉ ĉ @ Suppress Lint (" ResourceType ") Ċĉ ĉ get () Ġ{ Ċĉĉ ĉ val Ġresource Parser Ġ= Ġresources . get Xml ( R . drawable . selector ) Ċĉĉ ĉ return ĠAnimated Selector Drawable Generator . get Drawable ( resources , Ġresource Parser ) Ċĉ ĉ } ĊĊ ĉ private Ġval Ġkotlin Animated Background : ĠDrawable Ċĉ ĉ get () Ġ{ Ċĉĉ ĉ val Ġstate List Drawable Ġ= ĠState List Drawable () Ċĉĉ ĉ state List Drawable . add State ( int ArrayOf ( android . R . attr . state _ pressed ), ĠG if Drawable . createFrom Resource ( resources , ĠR . drawable . anim _ flag _ ch ile )) Ċĉĉ ĉ state List Drawable . add State ( IntArray ( 0 ), ĠG if Drawable . createFrom Resource ( resources , ĠR . drawable . anim _ flag _ eng land )) Ċĉĉ ĉ return Ġstate List Drawable Ċĉ ĉ } Ċ Ċ } Ċ