package cn.thens.kdroid.sample.jbridge

import android.app.Activity
import android.os.Bundle
import cn.thens.kdroid.core.log.Logdog
import cn.thens.kdroid.core.web.JBridge
import cn.thens.kdroid.core.web.WebViewSecurity
import org.jetbrains.anko.*

class JBridgeActivity : Activity() {
    private val url get() = "file:///android_asset/jbridge.html"

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)

        frameLayout {
            val web = webView {
                WebViewSecurity.init(this)
                val jBridge = JBridge.create(this)
                jBridge.register("toast") { arg, callback ->
                    toast(arg)
                    Logdog.info(arg)
                    callback("toast.callback")
                }
            }
            button("refresh") {
                setOnClickListener { web.loadUrl(url) }
            }.lparams(wrapContent, wrapContent)
        }
    }
}