package Ġorg . kin . eco system . app reci ation . options . menu . ui Ċ Ċ import Ġandroid . animation . Animator Set Ċ import Ġandroid . animation . Object Animator Ċ import Ġandroid . animation . Value Animator Ċ import Ġandroid . content . Context Ċ import Ġandroid . graphics . Color Ċ import Ġandroid . graphics . Paint Ċ import Ġandroid . graphics . Port er D uff Ċ import Ġandroid . support . annotation . Color Int Ċ import Ġandroid . support . constraint . Constraint Layout Ċ import Ġandroid . support . v 7 . app . AppCompat Delegate Ċ import Ġandroid . text . Sp ann able String Ċ import Ġandroid . text . Sp anned Ċ import Ġandroid . text . style . ForegroundColor Span Ċ import Ġandroid . util . Attribute Set Ċ import Ġandroid . view . LayoutInflater Ċ import Ġandroid . view . View Ċ import Ġandroid . view . animation . Alpha Animation Ċ import Ġandroid . view . animation . Ant icip ate Interpolator Ċ import Ġandroid . view . animation . Ant icip ate Over shoot Interpolator Ċ import Ġandroid . widget . ImageView Ċ import Ġandroid . widget . TextView Ċ import Ġcom . kin . eco system . base . Theme Util Ċ import Ġcom . kin . eco system . base . widget . with End Action ĊĊ Ċ internal Ġclass ĠG ift Option View Ġ@ Jvm Over loads Ġconstructor ( context : ĠContext , ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġattrs : ĠAttributeSet ? Ġ= Ġnull , ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġdef Style Attr : ĠInt Ġ= Ġ 0 ) Ġ: Ċ ĉ Constraint Layout ( context , Ġattrs , Ġdef Style Attr ) Ġ{ ĊĊ ĉ private Ġval Ġtitle View : ĠTextView Ċ ĉ private Ġval Ġamount View : ĠTextView Ċ ĉ private Ġval Ġitem Background View : ĠImageView Ċ ĉ private Ġval Ġconf et ti View : ĠImageView Ċ ĉ private Ġval Ġkin Logo View : ĠImageView Ċ ĉ private Ġvar Ġanimation Listener : ĠAnimation Listener ? Ġ= Ġnull ĊĊ ĉ @ Color Int Ċ ĉ private Ġval Ġcolor Disabled : ĠInt Ċ ĉ private Ġvar Ġis Anim ating Thank You Ġ= Ġfalse ĊĊ ĉ init Ġ{ Ċĉ ĉ AppCompat Delegate . set Compat Vector From Resources Enabled ( true ) Ċĉ ĉ LayoutInflater . from ( context ). inflate ( R . layout . king ifting _ option _ item , Ġthis , Ġtrue ) Ċĉ ĉ title View Ġ= ĠfindViewById ( R . id . text ) Ċĉ ĉ amount View Ġ= ĠfindViewById ( R . id . amount ) Ċĉ ĉ item Background View Ġ= ĠfindViewById ( R . id . item _ background ) Ċĉ ĉ conf et ti View Ġ= ĠfindViewById ( R . id . conf et ti ) Ċĉ ĉ kin Logo View Ġ= ĠfindViewById ( R . id . kin _ logo ) Ċĉ ĉ color Disabled Ġ= ĠTheme Util . theme Attribute To Color ( Ċĉĉ ĉ context , ĠR . attr . disabled Color , ĠR . color . k ine co system _ light _ red Ċĉ ĉ ) Ċĉ ĉ clip To Padding Ġ= Ġfalse Ċĉ ĉ clip Children Ġ= Ġfalse Ċ ĉ } ĊĊ ĉ fun ĠsetTitle ( text : ĠString ) Ġ{ Ċĉ ĉ title View . text Ġ= Ġtext Ċ ĉ } ĊĊ ĉ fun Ġset Amount ( amount : ĠInt ) Ġ{ Ċĉ ĉ amount View . text Ġ= Ġamount . toString () Ċ ĉ } ĊĊ ĉ fun Ġset Animation Listener ( on Slider Completed : Ġ() Ġ-> ĠUnit , Ġon Animation Ended : Ġ() Ġ-> ĠUnit ) Ġ{ Ċĉ ĉ set Animation Listener ( object Ġ: ĠAnimation Listener Ġ{ Ċĉĉ ĉ override Ġfun Ġon Slider Completed () Ġ{ Ċĉĉĉ ĉ on Slider Completed . invoke () Ċĉĉ ĉ } ĊĊĉĉ ĉ override Ġfun Ġon Animation Ended () Ġ{ Ċĉĉĉ ĉ on Animation Ended . invoke () Ċĉĉ ĉ } Ċĉ ĉ }) Ċ ĉ } ĊĊ ĉ private Ġfun Ġset Animation Listener ( listener : ĠAnimation Listener ) Ġ{ Ċĉ ĉ animation Listener Ġ= Ġlistener Ċ ĉ } ĊĊ ĉ fun Ġstart On Selected Animation () Ġ{ Ċĉ ĉ disable Click s () Ċĉ ĉ item Background View . visibility Ġ= ĠView . VISIBLE Ċĉ ĉ val Ġhalf Width Ġ= Ġtitle View . width Ġ/ Ġ 2 Ċĉ ĉ val Ġthank You Text Ġ= Ġcontext . getString ( R . string . king ifting _ th ank _ you ) Ċĉ ĉ val Ġtext Width Ġ= ĠPaint (). measure Text ( th ank You Text ) Ċĉ ĉ Value Animator . of Int ( 0 , Ġtitle View . width ). apply Ġ{ Ċĉĉ ĉ duration Ġ= ĠAN IM _ DURATION _ SL IDE _ LOAD Ċĉĉ ĉ interpol ator Ġ= ĠAnt icip ate Interpolator () Ċĉĉ ĉ add Update Listener Ġ{ Ġvalue Animator Ġ-> Ċĉĉĉ ĉ val Ġnew Width Ġ= Ġvalue Animator . animated Value Ġas ĠInt Ċĉĉĉ ĉ val Ġparams Ġ= Ġitem Background View . layout Params Ċĉĉĉ ĉ params . width Ġ= Ġnew Width Ċĉĉĉ ĉ item Background View . layout Params Ġ= Ġparams Ċĉĉĉ ĉ if Ġ(( new Width Ġ>= Ġhalf Width Ġ- Ġ( text Width Ġ* Ġ 2 )) Ġ&& Ġ! is Anim ating Thank You ) Ġ{ Ċĉĉĉĉ ĉ is Anim ating Thank You Ġ= Ġtrue Ċĉĉĉĉ ĉ start Thank You Anim () Ċĉĉĉ ĉ } Ċĉĉ ĉ } Ċĉĉ ĉ with End Action Ġ{ Ċĉĉĉ ĉ amount View . visibility Ġ= ĠG ONE Ċĉĉĉ ĉ kin Logo View . visibility Ġ= ĠG ONE Ċĉĉĉ ĉ show Conf et ti () Ċĉĉĉ ĉ animation Listener ?. on Slider Completed () ĊĊĉĉ ĉ } Ċĉĉ ĉ start () Ċĉ ĉ } Ċ ĉ } ĊĊ ĉ private Ġfun Ġstart Thank You Anim () Ġ{ Ċĉ ĉ Alpha Animation ( 1 F , Ġ 0 F ). apply Ġ{ Ċĉĉ ĉ duration Ġ= ĠAN IM _ DURATION _ FA DE _ OUT _ TEXT Ċĉĉ ĉ fill After Ġ= Ġfalse Ċĉĉ ĉ title View . start Animation ( this ) Ċĉ ĉ } Ċĉ ĉ val Ġthank You Text Ġ= Ġcontext . getString ( R . string . king ifting _ th ank _ you ) Ċĉ ĉ Value Animator . of Float ( 0 F , Ġ 0 F ). apply Ġ{ Ċĉĉ ĉ duration Ġ= Ġ(( th ank You Text . length Ġ* ĠAN IM _ DURATION _ FA DE _ IN _ LET TER ). to Long ()) Ċĉĉ ĉ add Update Listener Ġ{ Ċĉĉĉ ĉ val ĠtextView String Ġ= ĠSp ann able String ( th ank You Text ) Ċĉĉĉ ĉ th ank You Text . forEach Indexed Ġ{ Ġindex , Ġ_ Ġ-> Ċĉĉĉĉ ĉ val Ġdelta Ġ= ĠMath . max ( Math . min (( current Play Time Ġ- Ġindex Ġ* ĠAN IM _ DURATION _ FA DE _ IN _ LET TER ), ĠAN IM _ DURATION _ FA DE _ IN _ LET TER ), Ġ 0 F ) Ċĉĉĉĉ ĉ val Ġalpha Ġ= Ġdelta Ġ/ ĠAN IM _ DURATION _ FA DE _ IN _ LET TER Ċĉĉĉĉ ĉ val Ġcolor Ġ= Ġget Color ( alpha , ĠColor . WHITE ) Ċĉĉĉĉ ĉ textView String . set Span ( ForegroundColor Span ( color ), Ġindex , Ġif Ġ( index Ġ< Ġthank You Text . length ) Ġindex Ġ+ Ġ 1 Ġelse Ġindex , ĠSp anned . SPAN _ EXCL USIVE _ EXCL USIVE ) Ċĉĉĉ ĉ } Ċĉĉĉ ĉ title View . text Ġ= ĠtextView String Ċĉĉ ĉ } Ċĉĉ ĉ start () Ċĉ ĉ } Ċ ĉ } ĊĊ ĉ private Ġfun Ġget Color ( alpha : ĠFloat , Ġreal Color : ĠInt ) Ġ= Ġ(( 0 xFF Ġ* Ġalpha ). toInt () Ġshl Ġ 2 4 ) Ġor Ġ( real Color Ġand Ġ 0 x 0 0 FFFFFF ) ĊĊ ĉ private Ġfun Ġshow Conf et ti () Ġ{ Ċĉ ĉ conf et ti View . visibility Ġ= ĠView . VISIBLE Ċĉ ĉ val Ġscale X Ġ= ĠObject Animator . of Float ( conf et ti View , Ġ" scale X ", Ġ 0 f , Ġ 1 f ). apply Ġ{ Ċĉĉ ĉ with End Action Ġ{ Ġanimation Listener ?. on Animation Ended () Ġ} Ċĉ ĉ } Ċĉ ĉ val Ġscale Y Ġ= ĠObject Animator . of Float ( conf et ti View , Ġ" scale Y ", Ġ 0 f , Ġ 1 f ) Ċĉ ĉ Animator Set (). apply Ġ{ Ċĉĉ ĉ duration Ġ= ĠAN IM _ DURATION _ SCALE _ CONF ET TI Ċĉĉ ĉ interpol ator Ġ= ĠAnt icip ate Over shoot Interpolator () Ċĉĉ ĉ play To gether ( scale X , Ġscale Y ) Ċĉĉ ĉ start () Ċĉ ĉ } Ċ ĉ } ĊĊ ĉ fun Ġdisable () Ġ{ Ċĉ ĉ disable Click s () Ċĉ ĉ amount View . setTextColor ( color Disabled ) Ċĉ ĉ title View . setTextColor ( color Disabled ) Ċĉ ĉ title View . apply Ġ{ Ċĉĉ ĉ background . setColor Filter ( color Disabled , ĠPort er D uff . Mode . SRC _ AT OP ) Ċĉ ĉ } Ċĉ ĉ findViewById < ImageView >( R . id . kin _ logo ). apply Ġ{ Ċĉĉ ĉ setImage Resource ( R . drawable . king ifting _ ic _ kin _ logo _ disabled ) Ċĉ ĉ } Ċ ĉ } ĊĊ ĉ private Ġfun Ġdisable Click s () Ġ{ Ċĉ ĉ isEnabled Ġ= Ġfalse Ċĉ ĉ is Clickable Ġ= Ġfalse Ċ ĉ } ĊĊ ĉ comp anion Ġobject Ġ{ Ċĉ ĉ private Ġconst Ġval ĠAN IM _ DURATION _ FA DE _ IN _ LET TER = Ġ 5 0 F Ċĉ ĉ private Ġconst Ġval ĠAN IM _ DURATION _ FA DE _ OUT _ TEXT Ġ= Ġ 1 0 0 L Ċĉ ĉ private Ġconst Ġval ĠAN IM _ DURATION _ SL IDE _ LOAD Ġ= Ġ 7 0 0 L Ċĉ ĉ private Ġconst Ġval ĠAN IM _ DURATION _ SCALE _ CONF ET TI Ġ= Ġ 6 0 0 L Ċ ĉ } ĊĊ ĉ interface ĠAnimation Listener Ġ{ Ċĉ ĉ fun Ġon Slider Completed () ĊĊĉ ĉ fun Ġon Animation Ended () Ċ ĉ } Ċ } Ċ