diff --git a/misc/build.gradle.kts b/misc/build.gradle.kts index 6a2dc60d..f062ff03 100644 --- a/misc/build.gradle.kts +++ b/misc/build.gradle.kts @@ -50,6 +50,9 @@ dependencies { val composeBom = platform(libs.androidx.compose.bom) implementation(composeBom) androidTestImplementation(composeBom) + implementation("androidx.lifecycle:lifecycle-viewmodel-compose:2.8.2") + implementation("androidx.webkit:webkit:1.11.0") + implementation("androidx.appcompat:appcompat:1.7.0") implementation(libs.androidx.core.ktx) implementation(libs.androidx.activity.compose) implementation(libs.androidx.compose.runtime) diff --git a/misc/src/main/java/com/example/snippets/jetpackwebkit/JetpackWebkitActivity.kt b/misc/src/main/java/com/example/snippets/jetpackwebkit/JetpackWebkitActivity.kt new file mode 100644 index 00000000..c064f697 --- /dev/null +++ b/misc/src/main/java/com/example/snippets/jetpackwebkit/JetpackWebkitActivity.kt @@ -0,0 +1,42 @@ +package com.example.snippets.jetpackwebkit + +import android.annotation.SuppressLint +import android.os.Bundle +import android.webkit.WebView +import android.webkit.WebViewClient +import androidx.appcompat.app.AppCompatActivity +import androidx.webkit.WebSettingsCompat +import androidx.webkit.WebViewFeature + +class MainActivity : AppCompatActivity() { + @SuppressLint("SetJavaScriptEnabled") + override fun onCreate(savedInstanceState: Bundle?) { + super.onCreate(savedInstanceState) + // Sets the user interface from a layout resource. + setContentView(R.layout.activity_main) + + // You still get your WebView instance the standard way. + // [START android_views_notifications_build_basic] + + // import android.webkit.WebView + // import androidx.webkit.WebSettingsCompat + // import androidx.webkit.WebViewFeature + + val webView: WebView = findViewById(R.id.my_webview) + + // This is necessary to keep navigation inside your WebView + webView.webViewClient = WebViewClient() + + // Enable JavaScript + webView.settings.javaScriptEnabled = true + + // To enable a modern feature, you pass that instance to a Jetpack Webkit helper. + if (WebViewFeature.isFeatureSupported(WebViewFeature.FORCE_DARK)) { + WebSettingsCompat.setForceDark(webView.settings, WebSettingsCompat.FORCE_DARK_ON) + } + // [END android_views_notifications_build_basic] + + // Load a URL + webView.loadUrl("https://developer.android.com") + } +} \ No newline at end of file diff --git a/misc/src/main/java/com/example/snippets/jetpackwebkit/app/build.gradle.kts b/misc/src/main/java/com/example/snippets/jetpackwebkit/app/build.gradle.kts new file mode 100644 index 00000000..7c2b9b2c --- /dev/null +++ b/misc/src/main/java/com/example/snippets/jetpackwebkit/app/build.gradle.kts @@ -0,0 +1,60 @@ +plugins { + alias(libs.plugins.android.application) + alias(libs.plugins.kotlin.android) + alias(libs.plugins.kotlin.compose) +} + +android { + namespace = "com.example.webviewdarkmode" + compileSdk = 36 + + defaultConfig { + applicationId = "com.example.webviewdarkmode" + minSdk = 24 + targetSdk = 36 + versionCode = 1 + versionName = "1.0" + + testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner" + } + + buildTypes { + release { + isMinifyEnabled = false + proguardFiles( + getDefaultProguardFile("proguard-android-optimize.txt"), + "proguard-rules.pro" + ) + } + } + compileOptions { + sourceCompatibility = JavaVersion.VERSION_11 + targetCompatibility = JavaVersion.VERSION_11 + } + kotlinOptions { + jvmTarget = "11" + } + buildFeatures { + compose = true + } +} + +dependencies { + implementation("androidx.webkit:webkit:1.11.0") + implementation("androidx.appcompat:appcompat:1.7.0") + implementation(libs.androidx.core.ktx) + implementation(libs.androidx.lifecycle.runtime.ktx) + implementation(libs.androidx.activity.compose) + implementation(platform(libs.androidx.compose.bom)) + implementation(libs.androidx.ui) + implementation(libs.androidx.ui.graphics) + implementation(libs.androidx.ui.tooling.preview) + implementation(libs.androidx.material3) + testImplementation(libs.junit) + androidTestImplementation(libs.androidx.junit) + androidTestImplementation(libs.androidx.espresso.core) + androidTestImplementation(platform(libs.androidx.compose.bom)) + androidTestImplementation(libs.androidx.ui.test.junit4) + debugImplementation(libs.androidx.ui.tooling) + debugImplementation(libs.androidx.ui.test.manifest) +} \ No newline at end of file diff --git a/misc/src/main/java/com/example/snippets/jetpackwebkit/gradle/libs.versions.toml b/misc/src/main/java/com/example/snippets/jetpackwebkit/gradle/libs.versions.toml new file mode 100644 index 00000000..5d464bd3 --- /dev/null +++ b/misc/src/main/java/com/example/snippets/jetpackwebkit/gradle/libs.versions.toml @@ -0,0 +1,32 @@ +[versions] +agp = "8.12.3" +kotlin = "2.0.21" +coreKtx = "1.17.0" +junit = "4.13.2" +junitVersion = "1.3.0" +espressoCore = "3.7.0" +lifecycleRuntimeKtx = "2.9.4" +activityCompose = "1.11.0" +composeBom = "2024.09.00" + +[libraries] +androidx-core-ktx = { group = "androidx.core", name = "core-ktx", version.ref = "coreKtx" } +junit = { group = "junit", name = "junit", version.ref = "junit" } +androidx-junit = { group = "androidx.test.ext", name = "junit", version.ref = "junitVersion" } +androidx-espresso-core = { group = "androidx.test.espresso", name = "espresso-core", version.ref = "espressoCore" } +androidx-lifecycle-runtime-ktx = { group = "androidx.lifecycle", name = "lifecycle-runtime-ktx", version.ref = "lifecycleRuntimeKtx" } +androidx-activity-compose = { group = "androidx.activity", name = "activity-compose", version.ref = "activityCompose" } +androidx-compose-bom = { group = "androidx.compose", name = "compose-bom", version.ref = "composeBom" } +androidx-ui = { group = "androidx.compose.ui", name = "ui" } +androidx-ui-graphics = { group = "androidx.compose.ui", name = "ui-graphics" } +androidx-ui-tooling = { group = "androidx.compose.ui", name = "ui-tooling" } +androidx-ui-tooling-preview = { group = "androidx.compose.ui", name = "ui-tooling-preview" } +androidx-ui-test-manifest = { group = "androidx.compose.ui", name = "ui-test-manifest" } +androidx-ui-test-junit4 = { group = "androidx.compose.ui", name = "ui-test-junit4" } +androidx-material3 = { group = "androidx.compose.material3", name = "material3" } + +[plugins] +android-application = { id = "com.android.application", version.ref = "agp" } +kotlin-android = { id = "org.jetbrains.kotlin.android", version.ref = "kotlin" } +kotlin-compose = { id = "org.jetbrains.kotlin.plugin.compose", version.ref = "kotlin" } + diff --git a/misc/src/main/res/layout/jetpack_webkit_layout.xml b/misc/src/main/res/layout/jetpack_webkit_layout.xml new file mode 100644 index 00000000..66d2821b --- /dev/null +++ b/misc/src/main/res/layout/jetpack_webkit_layout.xml @@ -0,0 +1,27 @@ + + + + + + + + + + + + + + \ No newline at end of file