Skip to content

Commit

Permalink
Disable loading animation in webview.
Browse files Browse the repository at this point in the history
  • Loading branch information
DeltaFlyerW committed May 1, 2024
1 parent a61a456 commit a347d04
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 18 deletions.
1 change: 0 additions & 1 deletion assets/html/blockAreaSetting.html
Original file line number Diff line number Diff line change
Expand Up @@ -329,7 +329,6 @@
if (left + width > canvasWidth) left = canvasWidth - width;
if (top + height > canvasHeight) top = canvasHeight - height;

console.log(JSON.stringify({top, left, width, height}))
div.style.width = width + 'px';
div.style.height = height + 'px';
div.style.top = top + 'px';
Expand Down
3 changes: 1 addition & 2 deletions src/com/deltaflyer/osu/BlockAreaPreference.kt
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@ class BlockAreaPreference : Preference {
super.onClick()

BlockAreaWebViewFragment().also {
it.setCurrentConfig(getPersistedString("null"))

it.setCallback(object : BlockAreaWebViewFragment.Callback {
override fun onMessageReceived(message: String?) {
Expand All @@ -57,7 +56,7 @@ class BlockAreaPreference : Preference {
}
})

it.setURL("file:///android_asset/html/blockAreaSetting.html")
it.url = "file:///android_asset/html/blockAreaSetting.html"
it.show()
}
}
Expand Down
33 changes: 18 additions & 15 deletions src/com/deltaflyer/osu/BlockAreaWebViewFragment.kt
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.deltaflyer.osu

import android.util.Log
import android.view.View
import android.webkit.JavascriptInterface
import android.webkit.WebView
import com.edlplan.ui.fragment.WebViewFragment
Expand All @@ -9,26 +10,28 @@ import ru.nsu.ccfit.zuev.osuplus.R

class BlockAreaWebViewFragment : WebViewFragment() {

private lateinit var myWebView: WebView
private lateinit var currentConfig: String
private lateinit var webview: WebView
private lateinit var callback: Callback
lateinit var url: String

override fun onLoadView() {
super.onLoadView()
myWebView = findViewById<WebView>(R.id.web)!!
myWebView.addJavascriptInterface(object : Any() {
@JavascriptInterface
fun postMessage(message: String?) {
callback.onMessageReceived(message)
}
}, "Android")
webview = findViewById<WebView>(R.id.web)!!.also {
val webSettings = it.settings
webSettings.javaScriptEnabled = true
webSettings.userAgentString = "osudroid"
it.loadUrl(url)
it.addJavascriptInterface(object : Any() {
@JavascriptInterface
fun postMessage(message: String?) {
callback.onMessageReceived(message)
}
}, "Android")
}

findViewById<View>(R.id.close_button)!!.setOnClickListener { v: View? -> dismiss() }
}


fun setCurrentConfig(persistedString: String): BlockAreaWebViewFragment {
this.currentConfig = persistedString
return this
}

fun setCallback(callback: Callback): BlockAreaWebViewFragment {
this.callback = callback
Expand All @@ -38,7 +41,7 @@ class BlockAreaWebViewFragment : WebViewFragment() {
fun execute(js: String) {
Log.d("WebViewFruit", "Exec: $js")

this.myWebView.evaluateJavascript(js) { value ->
this.webview.evaluateJavascript(js) { value ->
Log.d("WebViewFruit", value)
}
}
Expand Down

0 comments on commit a347d04

Please sign in to comment.