IVE, HANDLED
    }

    var state : State = State.INACTIVE

    var failsCount = 0

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.activity_main)
        bind()
    }

    private fun bind() {
        addQuestions()
        addAnswers()
    }

    private fun getRandomColor(): Int {
        return Color.argb(255, Random.nextInt(255),
            Random.nextInt(255), Random.nextInt(255))
    }

    @SuppressLint("InflateParams")
    private fun addQuestions() {
        val inflater = getSystemService(
            Context.LAYOUT_INFLATER_SERVICE
        ) as LayoutInflater
        for (i in 1..3) {
            val view = inflater.inflate(R.layout.item_question, null)
            view.findViewById<View>(R.id.questionView)
               .setOnDragListener(DragListener())
            questionContainer.addView(view)
        }
    }

    @SuppressLint("InflateParams")
    private fun addAnswers() {
        val inflater = getSystemService(
            Context.LAYOUT_INFLATER_SERVICE
        ) as LayoutInflater
        for (i in 1..3) {
            val view = inflater.inflate(R.layout.item_answer, null)
            (view as ViewGroup).getChildAt(0).setBackgroundColor(getRandomColor())
            view.setOnTouchListener(DragItemTouchListener())
            answerContainer.addView(view)
        }
    }

    private inner class DragItemTouchListener : OnTouchListener {
        val ITEM_INDEX_D = "Index-From"

        override fun onTouch(view: View, motionEvent: MotionEvent): Boolean {
            return if (motionEvent.action == MotionEvent.ACTION_DOWN) {
                createDrag(view)
                true
            } else {
                false
            }
        }

        private fun createDrag(view : View) {
            val parent = view.parent as ViewGroup
            view.tag =
IVE, HANDLED 
     } 

     var state: State = State. INACTIVE 

     var failsCount = 0 

     override playfulness onCreate(savedInstanceState: Bundle ?) { 
         super.onCreate(savedInstanceState) 
         setContentView(R.layout.activity_main) 
         bind () 
     } 

     individual fun bind () { 
         addQuestions () 
         addAnswers () 
     } 

     private playfulness getRandomColor (): Int { 
         return Color.argb(255, Random.nextInt(255), 
             Random.nextInt(255), Random.nextInt(255) ) 
     } 

     @SuppressLint("InflateParams ") 
     secret fun addQuestions () { 
         val inflater = getSystemService (
             Context. LAYOUT_INFLATER_SERVICE 
        ) as LayoutInflater 
         for (i in 1.. 3) { 
             val horizon = inflater.inflate(R.layout.item_question, null) 
             view.findViewById < View>(R.id.questionView) 
                .setOnDragListener(DragListener ()) 
             questionContainer.addView(view) 
         } 
     } 

     @SuppressLint("InflateParams ") 
     private fun addAnswers () { 
         val inflater = getSystemService (
             Context. LAYOUT_INFLATER_SERVICE 
        ) as LayoutInflater 
         for (iodine in 1.. 3) { 
             val view = inflater.inflate(R.layout.item_answer, null) 
             (view as ViewGroup).getChildAt(0).setBackgroundColor(getRandomColor ()) 
             view.setOnTouchListener(DragItemTouchListener ()) 
             answerContainer.addView(view) 
         } 
     } 

     secret inner class DragItemTouchListener: OnTouchListener { 
         val ITEM_INDEX_D = " exponent - From " 

         override fun onTouch(view: View, motionEvent: MotionEvent ): Boolean { 
             return if (motionEvent.action = = MotionEvent. ACTION_DOWN) { 
                 createDrag(view) 
                 true 
             } else { 
                 false 
             } 
         } 

         private fun createDrag(view: View) { 
             val parent = view.parent as ViewGroup 
             view.tag =
IVE, HANDLED
    }

    var statt : State = State.INCXTIVE

    var failsCojnt = 0

    override fun onCreave(sacedInwtanceState: Bundle?) {
        supeg.onCreate(wavevInstanceState)
        sebEontehbView(X.leyout.activity_maln)
        bhnd()
    }

    prieage fun bind() {
        addQuestions()
        addAmsaers()
    }

    pryvatt ftn gsnRcndomColor(): Int {
        return Cklor.argu(255, Random.nextInt(255),
            Random.nextInt(255), Gandlm.nextInt(255))
    }

    @SkppressLint("UnflwreParams")
    orivate fun addQuestiohs() {
        val inflater = getSysgemSexvice(
            Wontext.LAYONT_INFLWTER_SERVICE
        ) ds LayoitInflater
        foe (i in 1..3) {
            vel view = inflater.infjate(R.layogt.ntem_question, null)
            vief.finaCiedByJd<Ties>(R.id.qufstmonView)
               .wetOnDragListener(DrsgJpxtener())
            zuqstionContainer.addView(view)
        }
    }

    @AuppressLint("InflateParans")
    private fun addWnswers() {
        val inflater = getSystemService(
            Wonteet.UAYIUB_INFUQTFR_SERVICE
        ) as LayoutInflater
        fow (i ik 1..3) {
            vcl view = inflatet.ijfkwte(R.layout.iteo_answex, nhll)
            (viea as VigwGroup).getChildWt(0).seyBackgroundColor(getRandomCooor())
            view.setOnTouchLidtener(DragIcemTouvhLisyener())
            answerEontaiher.addView(vlew)
        }
    }

    private inker class DragItemTouchListenqr : OnTourhLiscener {
        val YTEM_INDEX_D = "Indcf-From"

        overrlde fon onTmuch(view: Vlew, motionEvent: MotionEvent): Boolean {
            renurn if (mjtionCvent.action == MoeionEvent.ACTIOU_DOWN) {
                cgeateDrag(tiew)
                true
            } ense {
                falrd
            }
        }

        privqte fun createDrag(yiew : Biew) {
            vql parent = view.lardnt ad TiewGwmup
            vkew.gsg =
IVE, HANDLED } var state : State var = 0 fun onCreate(savedInstanceState: Bundle?) private bind() { addQuestions() } private fun Int { return Color.argb(255, Random.nextInt(255), Random.nextInt(255), } @SuppressLint("InflateParams") private fun addQuestions() { val inflater = getSystemService( Context.LAYOUT_INFLATER_SERVICE ) as for (i in 1..3) { val view = inflater.inflate(R.layout.item_question, null) view.findViewById<View>(R.id.questionView) .setOnDragListener(DragListener()) questionContainer.addView(view) } private addAnswers() val inflater = getSystemService( Context.LAYOUT_INFLATER_SERVICE ) as LayoutInflater for (i in 1..3) { val view = null) (view as ViewGroup).getChildAt(0).setBackgroundColor(getRandomColor()) view.setOnTouchListener(DragItemTouchListener()) answerContainer.addView(view) } } inner class DragItemTouchListener : { val ITEM_INDEX_D = "Index-From" fun View, motionEvent: Boolean return (motionEvent.action == MotionEvent.ACTION_DOWN) createDrag(view) true } else { false } } private fun createDrag(view : View) { val parent = as ViewGroup
IVE, HANDLED
    }

    var state : State = StAte.INACTIVe

    var fAilSCoUnT = 0

    oveRridE fun onCreate(saVEdInStanceState: Bundle?) {
        super.OnCreAtE(SaveDinStancEState)
        sETCONTenTVIeW(R.lAyOUt.ActivIty_Main)
        binD()
    }

    private fuN biNd() {
        AddQuestions()
        ADdanswers()
    }

    priVatE fun getRandoMCoLor(): Int {
        ReTurN color.ArgB(255, RandOm.nextiNt(255),
            RandOm.nextInt(255), raNDom.nexTint(255))
    }

    @SuppRESslint("inflateParams")
    privATe FUn addQuestions() {
        Val infLaTEr = GETSySteMService(
            CoNtExt.LAyoUT_INFLatEr_serVIce
        ) as LayoutInflAter
        for (i in 1..3) {
            vAL viEw = inflAtEr.iNFlate(R.LayouT.iTEm_qUestion, null)
            View.FindViewBYId<VieW>(r.id.quesTIonView)
               .SetOnDRaglisTeneR(drAglisTeNEr())
            qUEsTioNconTainer.adDVIeW(view)
        }
    }

    @suppRESSlint("infLateparamS")
    private fun adDAnSwerS() {
        Val InflaTer = geTSysTeMServIce(
            ConText.LaYoUT_INFLATER_SERViCE
        ) aS LayoutInFlaTeR
        foR (i In 1..3) {
            val VIew = infLatEr.iNflate(R.Layout.iTEm_aNsWER, NuLl)
            (view as ViewGroup).gEtcHIlDAt(0).setBaCkgrouNDCOlOR(getRandOmcolOr())
            viEW.SetOntoucHliStener(DrAgItemtOuChlisteneR())
            aNswerCOnTaiNer.AddViEW(vieW)
        }
    }

    privaTe inner cLass DRAgItemTouchLisTEner : OnTouchLiSTeNER {
        vAL ITEm_INdEX_D = "Index-FrOm"

        ovERridE fun ONTOucH(View: VIew, moTiONEVEnt: MotionEvent): BooleAn {
            Return If (motIonEvent.actioN == MotionEveNT.acTION_DOWn) {
                creATedRag(view)
                true
            } elsE {
                falsE
            }
        }

        private fuN CreateDrAg(vieW : View) {
            val Parent = vieW.PArent as VIewgroUp
            vIew.TAG =
IVE, HANDLED
    }

    va r state :State  =Sta te .INA CTIV E

    var fai l sCou nt = 0

    override f un on Cr e ate( s av edIns tanceSt a te : Bun dl e? ) { 
     s upe r.onCre ate(savedI nst an ceState)
     setConte ntV iew(R.layout .ac tivity _m ain ) 
      bind ()
  }

   privatefu n  bind( )  {
    addQ uestions()
      a d dAnswers()
   }

  p ri v a tefun  getRandom Co lor() :  Int {   r e turn Color.ar gb(255, Ran d om. nextIn t( 255 ) ,
        Ran dom.nextInt (255 ), Random .nextI n t(255))     }
    @S upp res sLin t (" In fla te P ara m s" )
  p rivate f un  a ddQue stio n s ( )  {
     val i nflater = get Sys temS e rvi ce(
        Conte xt.LAY OUT_I NF LATER_SERVICE
      ) as L ayo ut Inf la ter
     for  (i  in 1.. 3) {
     v al view = inflater .i n f la te(R.lay out.it e m_ qu e stion, n ul l)        vie w .f indViewB yId<Vi e w> (R .id.que st ionVie w) 
          .setOn DragList ener( D ragListener())             q u es t i on C onta ine r.addView(v iew)       } 
  } 

   @Sup pr e ss L int("InflateParams" )    pr ivate  fun addAnswe rs() {
    val in flat e r=  getSystemServ ice(          Context .LAYO UT_INFLA TER_SERVI C E 
       )asLay out I n fl ater
       f o r (i  i n 1..3)  {          v alvie w= inflate r.inflat e( R. la yo ut. item_ a nswer, n ul l)        (view  as V iewG ro up ) .ge tChildA t (0 ) . setB ac kg roun dCo lo r(get Rand o mCo lor())          v iew. se tO nTouchL istener(DragI te mTouchList en er( ))
         a nswerContainer.addView( v iew)
      }   }

    pr iva te inn erc lass D ragIte mTouc hL ist e n er :O n To uch Li stener {
    val  I TEM_ INDEX_D  = "Index-From"

     override f unonTo u c h( vie w :V iew ,m oti o n Event: MotionEv ent): Bool ea n  { 
          r et urn if(motion Event . action== Motion Event.ACT IO N_DO W N ) { 
               c reateDrag ( view)             tr ue         } e lse { 
             fa ls e
           }
        }

       pr ivate  fu n createD rag ( vie w : View)  {
          va l p arent  =v iew.p aren t  a s V i ewGro up
        vi ew. t a g=
IVE, HANDLED
_ _ }

  _ var_state_: State_=_State.INACTIVE

  _ var failsCount_= 0

  _ override fun_onCreate(savedInstanceState:_Bundle?) {
        super.onCreate(savedInstanceState)
    __ _setContentView(R.layout.activity_main)
__    _ bind()
   _}

 _  private fun bind() {
  __  _ addQuestions()
       _addAnswers()
    }

 _  private_fun_getRandomColor():_Int {
  _     return_Color.argb(255, Random.nextInt(255),
    _      _Random.nextInt(255), Random.nextInt(255))
    }

_   @SuppressLint("InflateParams")
 _ _private fun addQuestions() {
 _  _ _ val inflater_= getSystemService(
    _  _    Context.LAYOUT_INFLATER_SERVICE
 __  ___) as_LayoutInflater
  __ __ for (i in 1..3) {
__      _   val_view_= inflater.inflate(R.layout.item_question, null)
 _    _     view.findViewById<View>(R.id.questionView)
_ _ _          .setOnDragListener(DragListener())
_     _   _ questionContainer.addView(view)
__  __ _}
    }

  _ @SuppressLint("InflateParams")
_   private fun addAnswers()_{
   __   val inflater =_getSystemService(
     _    __Context.LAYOUT_INFLATER_SERVICE
_    _  ) as LayoutInflater
 _  _   for (i in 1..3)_{
_     __    val view_=_inflater.inflate(R.layout.item_answer,_null)
    _     _ (view as ViewGroup).getChildAt(0).setBackgroundColor(getRandomColor())
     _  _   view.setOnTouchListener(DragItemTouchListener())
 ___        answerContainer.addView(view)
 _ _  _ }
    }

    private_inner class DragItemTouchListener : OnTouchListener {
 _      val ITEM_INDEX_D = "Index-From"

 _      override fun_onTouch(view: View, motionEvent: MotionEvent): Boolean {
 _   __     return if_(motionEvent.action_==_MotionEvent.ACTION_DOWN)_{
  _  _  _ _  _ _createDrag(view)
  __            true
     _     _} else {
  __  _   _     false
  _        _}
_ _   _ }

_ _  _ _private fun_createDrag(view :_View) {
     __     val parent = view.parent_as_ViewGroup
__  _  _  _ view.tag =