package Ġcom . st f alcon . sample . features . demo . rotation Ċ Ċ import Ġandroid . os . Bundle Ċ import Ġandroid . widget . ImageView Ċ import Ġcom . st f alcon . image viewer . St f alcon Image Viewer Ċ import Ġcom . st f alcon . sample . R Ċ import Ġcom . st f alcon . sample . common . extensions . get Drawable Compat Ċ import Ġcom . st f alcon . sample . common . models . Demo Ċ import Ġcom . st f alcon . sample . common . models . Post er Ċ import Ġcom . st f alcon . sample . common . ui . base . Base Activity Ċ import Ġkotlinx . android . synt hetic . main . activity _ demo _ rotation .* Ċ Ċ class ĠRotation Demo Activity Ġ: ĠBase Activity () Ġ{ ĊĊĠĠĠ Ġcompanion Ġobject Ġ{ ĊĠĠĠĠĠĠĠ Ġprivate Ġconst Ġval ĠKEY _ IS _ DIALOG _ SHO WN Ġ= Ġ" IS _ DIALOG _ SHO WN " ĊĠĠĠĠĠĠĠ Ġprivate Ġconst Ġval ĠKEY _ CURRENT _ POSITION Ġ= Ġ" CURRENT _ POSITION " ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġprivate Ġvar Ġis Dialog Shown Ġ= Ġfalse ĊĠĠĠ Ġprivate Ġvar Ġcurrent Position : ĠInt Ġ= Ġ 0 ĊĊĠĠĠ Ġprivate Ġlateinit Ġvar Ġviewer : ĠSt f alcon Image Viewer < Post er > ĊĊĠĠĠ Ġoverride Ġfun ĠonCreate ( savedInstanceState : ĠBundle ?) Ġ{ ĊĠĠĠĠĠĠĠ Ġsuper . onCreate ( savedInstanceState ) ĊĠĠĠĠĠĠĠ ĠsetContentView ( R . layout . activity _ demo _ rotation ) ĊĊĠĠĠĠĠĠĠ Ġrotation Demo Image . setOnClickListener Ġ{ Ġopen Viewer ( 0 ) Ġ} ĊĠĠĠĠĠĠĠ Ġload Post er Image ( rotation Demo Image , ĠDemo . post ers [ 0 ]) ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġoverride Ġfun Ġon Pause () Ġ{ ĊĠĠĠĠĠĠĠ Ġsuper . on Pause () ĊĠĠĠĠĠĠĠ Ġviewer . dismiss () ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġoverride Ġfun Ġon Restore InstanceState ( savedInstanceState : ĠBundle ) Ġ{ ĊĠĠĠĠĠĠĠ Ġsuper . on Restore InstanceState ( savedInstanceState ) ĊĠĠĠĠĠĠĠ Ġis Dialog Shown Ġ= ĠsavedInstanceState . getBoolean ( KEY _ IS _ DIALOG _ SHO WN ) ĊĠĠĠĠĠĠĠ Ġcurrent Position Ġ= ĠsavedInstanceState . getInt ( KEY _ CURRENT _ POSITION ) ĊĊĠĠĠĠĠĠĠ Ġif Ġ( is Dialog Shown ) Ġ{ ĊĠĠĠĠĠĠĠĠĠĠĠ Ġopen Viewer ( current Position ) ĊĠĠĠĠĠĠĠ Ġ} ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġoverride Ġfun Ġon Save InstanceState ( out State : ĠBundle ) Ġ{ ĊĠĠĠĠĠĠĠ Ġout State . put Boolean ( KEY _ IS _ DIALOG _ SHO WN , Ġis Dialog Shown ) ĊĠĠĠĠĠĠĠ Ġout State . put Int ( KEY _ CURRENT _ POSITION , Ġcurrent Position ) ĊĠĠĠĠĠĠĠ Ġsuper . on Save InstanceState ( out State ) ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġprivate Ġfun Ġopen Viewer ( start Position : ĠInt ) Ġ{ ĊĠĠĠĠĠĠĠ Ġviewer Ġ= ĠSt f alcon Image Viewer . Builder ( this , ĠDemo . post ers , Ġ:: load Post er Image ) ĊĠĠĠĠĠĠĠĠĠĠĠ Ġ. with Transition From ( get Transition Target ( start Position )) ĊĠĠĠĠĠĠĠĠĠĠĠ Ġ. with Start Position ( start Position ) ĊĠĠĠĠĠĠĠĠĠĠĠ Ġ. with Image ChangeListener Ġ{ ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġcurrent Position Ġ= Ġit ĊĠĠĠĠĠĠĠĠĠĠĠĠĠĠĠ Ġviewer . update Transition Image ( get Transition Target ( it )) ĊĠĠĠĠĠĠĠĠĠĠĠ Ġ} ĊĠĠĠĠĠĠĠĠĠĠĠ Ġ. with Dismiss Listener Ġ{ Ġis Dialog Shown Ġ= Ġfalse Ġ} ĊĠĠĠĠĠĠĠĠĠĠĠ Ġ. show (! is Dialog Shown ) ĊĊĠĠĠĠĠĠĠ Ġcurrent Position Ġ= ĠstartPosition ĊĠĠĠĠĠĠĠ Ġis Dialog Shown Ġ= Ġtrue ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġoverride Ġfun Ġload Post er Image ( imageView : ĠImageView , Ġposter : ĠPost er ?) Ġ{ ĊĠĠĠĠĠĠĠ ĠimageView . background Ġ= Ġget Drawable Compat ( R . drawable . shape _ placeholder ) ĊĠĠĠĠĠĠĠ Ġsuper . load Post er Image ( imageView , Ġposter ) ĊĠĠĠ Ġ} ĊĊĠĠĠ Ġprivate Ġfun Ġget Transition Target ( position : ĠInt ) Ġ= ĊĠĠĠĠĠĠĠ Ġif Ġ( position Ġ== Ġ 0 ) Ġrotation Demo Image Ġelse Ġnull Ċ }