feat(android): use native webview instead of gioui framework
All checks were successful
arcad/arcast/pipeline/head This commit looks good
All checks were successful
arcad/arcast/pipeline/head This commit looks good
This commit is contained in:
@ -63,7 +63,7 @@ dependencies {
|
||||
implementation 'androidx.compose.ui:ui-graphics'
|
||||
implementation 'androidx.compose.ui:ui-tooling-preview'
|
||||
implementation 'androidx.compose.material3:material3'
|
||||
implementation files('libs/sys_android.jar')
|
||||
implementation("androidx.webkit:webkit:1.10.0")
|
||||
testImplementation 'junit:junit:4.13.2'
|
||||
androidTestImplementation 'androidx.test.ext:junit:1.1.5'
|
||||
androidTestImplementation 'androidx.test.espresso:espresso-core:3.5.1'
|
||||
|
3
android/app/libs/.gitignore
vendored
3
android/app/libs/.gitignore
vendored
@ -1 +1,2 @@
|
||||
/mobile.aar
|
||||
/mobile.aar
|
||||
/arcast*
|
Binary file not shown.
Binary file not shown.
@ -8,8 +8,6 @@
|
||||
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />
|
||||
<uses-permission android:name="android.permission.CHANGE_WIFI_MULTICAST_STATE" />
|
||||
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
|
||||
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
|
||||
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
|
||||
<uses-permission android:name="android.permission.WAKE_LOCK" />
|
||||
|
||||
<application
|
||||
@ -35,12 +33,6 @@
|
||||
<category android:name="android.intent.category.LAUNCHER" />
|
||||
</intent-filter>
|
||||
</activity>
|
||||
<activity android:name="org.gioui.GioActivity"
|
||||
android:theme="@style/Theme.GioApp"
|
||||
android:configChanges="orientation|keyboardHidden"
|
||||
android:windowSoftInputMode="adjustResize"
|
||||
android:keepScreenOn="true">
|
||||
</activity>
|
||||
</application>
|
||||
|
||||
</manifest>
|
@ -0,0 +1,31 @@
|
||||
package com.example.arcast_player
|
||||
|
||||
import android.webkit.WebView
|
||||
import com.cadoles.arcast.android.Bridge
|
||||
|
||||
class ArcastBridge(private val webview: WebView) : Bridge {
|
||||
private var title: String = ""
|
||||
private var url: String = ""
|
||||
|
||||
override fun getTitle(): String {
|
||||
return title
|
||||
}
|
||||
|
||||
override fun getURL(): String {
|
||||
return url
|
||||
}
|
||||
|
||||
override fun loadURL(url: String) {
|
||||
webview.post(Runnable {
|
||||
webview.loadUrl(url)
|
||||
})
|
||||
}
|
||||
|
||||
fun setURL(url: String) {
|
||||
this.url = url
|
||||
}
|
||||
|
||||
fun setTitle(title: String) {
|
||||
this.title = title
|
||||
}
|
||||
}
|
@ -0,0 +1,18 @@
|
||||
package com.example.arcast_player
|
||||
|
||||
import android.webkit.WebResourceRequest
|
||||
import android.webkit.WebView
|
||||
import android.webkit.WebViewClient
|
||||
|
||||
class ArcastWebviewClient(private var bridge: ArcastBridge): WebViewClient() {
|
||||
|
||||
override fun shouldOverrideUrlLoading(view: WebView?, request: WebResourceRequest?): Boolean {
|
||||
return false
|
||||
}
|
||||
|
||||
override fun onPageFinished(view: WebView?, url: String?) {
|
||||
super.onPageFinished(view, url)
|
||||
bridge.title = view?.title.toString()
|
||||
bridge.url = url.toString()
|
||||
}
|
||||
}
|
@ -12,29 +12,26 @@ import androidx.compose.runtime.Composable
|
||||
import androidx.compose.ui.Modifier
|
||||
import androidx.compose.ui.tooling.preview.Preview
|
||||
import com.cadoles.arcast_player.ui.theme.ArcastplayerTheme
|
||||
import org.gioui.GioActivity
|
||||
import android.view.WindowManager
|
||||
import android.webkit.WebView
|
||||
import com.cadoles.arcast.android.Android as Arcast
|
||||
import com.example.arcast_player.ArcastBridge
|
||||
import com.example.arcast_player.ArcastWebviewClient
|
||||
|
||||
class MainActivity : ComponentActivity() {
|
||||
override fun onCreate(savedInstanceState: Bundle?) {
|
||||
super.onCreate(savedInstanceState)
|
||||
startActivity(Intent(this, GioActivity::class.java))
|
||||
window.addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON)
|
||||
}
|
||||
}
|
||||
val wv = WebView(applicationContext)
|
||||
val bridge: ArcastBridge = ArcastBridge(wv)
|
||||
|
||||
@Composable
|
||||
fun Greeting(name: String, modifier: Modifier = Modifier) {
|
||||
Text(
|
||||
text = "Hello $name!",
|
||||
modifier = modifier
|
||||
)
|
||||
}
|
||||
wv.webViewClient = ArcastWebviewClient(bridge)
|
||||
Arcast.setBridge(bridge)
|
||||
|
||||
@Preview(showBackground = true)
|
||||
@Composable
|
||||
fun GreetingPreview() {
|
||||
ArcastplayerTheme {
|
||||
Greeting("Android")
|
||||
val port = Arcast.startServer(filesDir.absolutePath)
|
||||
|
||||
wv.settings.javaScriptEnabled = true
|
||||
wv.loadUrl("http://127.0.0.1:${port}")
|
||||
|
||||
setContentView(wv)
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user