Android load animation on configuration change

Milan Schramm Source

I want to play a animation when a orientation change happened. Its a loader/placeholder for a webview. But when the screen rotates, the loader shows up but no animation is playing. What do I do wrong?

override fun onConfigurationChanged(newConfig: Configuration?) {
    when (newConfig?.orientation) {
        Configuration.ORIENTATION_LANDSCAPE -> {
            loader_logo?.visibility = View.VISIBLE
            pulseAnimation(loader_logo)
        }
        Configuration.ORIENTATION_PORTRAIT -> {
            loader_logo?.visibility = View.VISIBLE
            pulseAnimation(loader_logo)
        }
    }
    super.onConfigurationChanged(newConfig)
}

Here is the animation function:

private fun pulseAnimation(view: View?) {
    val pulse = AnimationUtils.loadAnimation(this, R.anim.pulse)
    view?.startAnimation(pulse)
}

Here is my WebView setup:

private fun initWebView() {
    val webSettings = webview.settings
    webSettings.javaScriptEnabled = true
    webview.webViewClient = object : WebViewClient() {
        override fun onPageFinished(view: WebView?, url: String?) {
            refresher.isRefreshing = false
            loader_logo.visibility = View.GONE
            if (loader_logo.visibility == View.GONE) loader_logo.clearAnimation()
        }
        override fun onReceivedError(view: WebView?, request: WebResourceRequest?, error: WebResourceError?) {
            val locale = Locale.getDefault().toString()
            if (locale == "de_DE") webview.loadUrl("file:///android_asset/error_de.html")
            else webview.loadUrl("file:///android_asset/error_en.html")
            isError = true
        }
    }
    webview.loadUrl(url)
}
androidkotlinandroid-animationandroid-orientation

Answers

comments powered by Disqus