1

I'm trying to create an image switcher for a battery animation. using kotlin support is there anything I'm missing?

import android.content.Intent
import android.support.v7.app.AppCompatActivity
import android.os.Bundle
import android.os.Handler
import android.view.View
import android.widget.ImageSwitcher
import java.util.*

class SplashScreen : AppCompatActivity() {

    private val splashTimeOut = 6000L
    private val chargeAnimation = arrayOf(
            R.drawable.charge_1,
            R.drawable.charge2,
            R.drawable.charge_3,
            R.drawable.charge_4)
    private var index = 0

    override fun onCreate(savedInstanceState: Bundle?) {

        super.onCreate(savedInstanceState)
        setContentView(R.layout.activity_splash_screen)

        window.decorView.systemUiVisibility = View.SYSTEM_UI_FLAG_HIDE_NAVIGATION or
                View.SYSTEM_UI_FLAG_LAYOUT_STABLE or View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION or
                View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN or View.SYSTEM_UI_FLAG_FULLSCREEN or
                View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY

        val t = Timer()
        //Set the schedule function and rate
        t.scheduleAtFixedRate(object : TimerTask() {

            override fun run() {
                //Called each time when 1000 milliseconds (1 second) (the period parameter)

                // If index reaches maximum reset it
                if (index + 1 < chargeAnimation.size) index + 1 else 0
                runOnUiThread { ***imageSwitcher***.setImageResource(chargeAnimation[index]) }
            }

        }, 500, 1000)

        Handler().postDelayed(Runnable{
            kotlin.run{
                val intent = Intent(this, RegisterScreen::class.java)
                startActivity(intent)
                finish()
            }
        }, splashTimeOut)}}
marc_s
  • 732,580
  • 175
  • 1,330
  • 1,459
IKesh Pack
  • 11
  • 1
  • 1
    At first, your missing an understandable description to your problem. What exactly did you try and where did you get stuck? –  Mar 25 '18 at 18:11
  • have you defined `imageSwitcher` variable? – Stefan Golubović Mar 25 '18 at 20:49
  • if your `ImageSwitcher`'s id is `imageSwitcher`, then you're missing [kotlin extensions](https://kotlinlang.org/docs/tutorials/android-plugin.html) – Stefan Golubović Mar 25 '18 at 20:53
  • my goodness thank you. @StefanGolubović. this is what ive done now: val imageSwitcher = findViewById(R.id.battery_animation) imageSwitcher.setFactory { val imageView = ImageView(this@SplashScreen)} though now I'm getting error: expected a value of type View! – IKesh Pack Mar 25 '18 at 20:58

0 Answers0