diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..c2f90e5 --- /dev/null +++ b/.gitignore @@ -0,0 +1,3 @@ + +.DS_Store +*.properties diff --git a/README.md b/README.md new file mode 100644 index 0000000..b4174f6 --- /dev/null +++ b/README.md @@ -0,0 +1,129 @@ +# 在 Android 平板上使用 VS Code([`code-server`](https://coder.com/docs/code-server/)) + +
![](/ReadmeImageZhCN.png)
+ +## English + +[README_EN.md](/README_EN.md)(Translated by ChatGPT 3.5) + +## 这个仓库是什么? + +这个仓库实际上是一个套壳 Android WebView 的应用程序源码,网站指向了 http://127.0.0.1:8080/ 。 + +其实做这个项目是因为是我觉得截止目前的主流通过在 Android 本地模拟 Linux 服务器并在此基础上运行 [`code-server`](https://coder.com/docs/code-server/) 的方案的界面并不是很好看,于是我做了一个适配异形屏,隐藏导航栏但不隐藏状态栏的 Android WebView 套壳软件来弥补这个问题。可以为有相同需求者节省时间。 + +如果你对此仓库有相关建议,欢迎提交 issue(s) 或 PR。 + +## 如何使用? + +以下内容均需要非中国大陆网络环境。 + +### 初次配置 + +在 F-Droid 中下载 termux 软件:[https://f-droid.org/zh_Hans/packages/com.termux/](https://f-droid.org/zh_Hans/packages/com.termux/) + +[![](https://gitlab.com/fdroid/artwork/-/raw/master/badge/get-it-on-zh-hans.png)](https://f-droid.org/zh_Hans/packages/com.termux/) + +在本仓库的发行版中下载 8080 软件,也可自行编译。 + +下载完成后,打开 termux 软件,输入此命令以选择 termux 所在镜像: + +```bash +termux-change-repo +``` + +然后输入下列命令安装 OpenSSL 和 Ubuntu 环境 + +```bash +pkg install wget openssl-tool proot -y +``` + +```bash +hash -r +``` + +```bash +wget https://raw.githubusercontent.com/EXALAB/AnLinux-Resources/master/Scripts/Installer/Ubuntu/ubuntu.sh +``` + +```bash +bash ubuntu.sh +``` + +然后,输入此命令以启动 Ubuntu 环境: + +```bash +./start-ubuntu.sh +``` + +进入 Ubuntu 环境后,输入下列命令下载并解压 `code-server`: + +```bash +apt update && apt upgrade +``` + +> 请注意替换尖括号及其内容为相应版本号,例如:`wget https://github.com/coder/code-server/releases/download/v4.15.0/code-server-4.15.0-linux-arm64.tar.gz`。 + +```bash +wget https://github.com/cdr/code-server/releases/download//code-server--linux-arm64.tar.gz +``` + +> 请注意替换尖括号及其内容为相应版本号,例如:`tar -xvf ./code-server-4.15.0-linux-arm64.tar.gz`。 + +```bash +tar -xvf ./code-server--linux-arm64.tar.gz +``` + +移动的解压后目录: + +> 请注意替换尖括号及其内容为相应版本号,例如:`cd code-server-4.15.0-linux-arm64/bin`。 + +```bash +cd code-server--linux-arm64/bin +``` + +输入以下命令设置进入 `code-server` 的临时密码: + +> 请注意替换尖括号及其内容为你设置的密码。 + +```bash +export PASSWORD="" +``` + +启动 `code-server`: + +```bash +./code-server +``` + +打开从本仓库下载的 8080 软件,输入你设置的密码,即可进入 `code-server`。 + +### 日后使用 + +打开 termux,依次运行以下命令: + +```bash +./start-ubuntu.sh +``` + +> 请注意替换尖括号及其内容为相应版本号。 + +```bash +cd code-server--linux-arm64/bin +``` + +> 请注意替换尖括号及其内容为你设置的密码。 + +```bash +export PASSWORD="" +``` + +```bash +./code-server +``` + +然后打开 8080 软件即可。 + +### 更多 + +由于 termux 的文件保存在私有目录(data/data)中,非 root 设备无法进入,因此可以通过在 Ubuntu 环境下安装各种使用 SSH、Web 等方式的服务器管理工具进行文件管理。 diff --git a/README_EN.md b/README_EN.md new file mode 100644 index 0000000..742fdf9 --- /dev/null +++ b/README_EN.md @@ -0,0 +1,129 @@ +> Translated from Chinese Simplified by ChatGPT 3.5. + +# Use VS Code on Your Android Tablet([`code-server`](https://coder.com/docs/code-server/)) + +
![](/ReadmeImageEN.png)
+ +## 简体中文 + +[README简体中文.md](/README.md) + +## What is this repository? + +This repository is actually the source code of an Android WebView application with a shell, which points to http://127.0.0.1:8080/. + +I created this project because I felt that the existing solutions for running [`code-server`](https://coder.com/docs/code-server/) on Android tablets, which involve emulating a local Linux server and running `code-server` on top of it, had interfaces that were not very appealing. Therefore, I created an Android WebView shell application that adapts to unconventional screen sizes, hides the navigation bar but not the status bar, to address this issue. This can save time for those with the same requirement. + +If you have any suggestions or feedback regarding this repository, please feel free to submit issue(s) or PR. + +## How to use? + +### Initial Configuration + +Download the `termux` app from F-Droid: [https://f-droid.org/packages/com.termux/](https://f-droid.org/packages/com.termux/) + +[![](https://gitlab.com/fdroid/artwork/-/raw/master/badge/get-it-on-en-us.png)](https://f-droid.org/en/packages/com.termux/) + +In the Releases section of this repository, download the 8080 app, or you can compile it yourself. + +After the download is complete, open the `termux` app and enter the following command to select the mirror for `termux`: + +```bash +termux-change-repo +``` + +Then enter the following commands to install OpenSSL and the Ubuntu environment: + +```bash +pkg install wget openssl-tool proot -y +``` + +```bash +hash -r +``` + +```bash +wget https://raw.githubusercontent.com/EXALAB/AnLinux-Resources/master/Scripts/Installer/Ubuntu/ubuntu.sh +``` + +```bash +bash ubuntu.sh +``` + +Then, enter the following command to start the Ubuntu environment: + +```bash +./start-ubuntu.sh +``` + +Once inside the Ubuntu environment, enter the following command to download and extract `code-server`: + +```bash +apt update && apt upgrade +``` + +> Please note to replace the angle brackets and their contents with the corresponding version number, for example: `wget https://github.com/coder/code-server/releases/download/v4.15.0/code-server-4.15.0-linux-arm64.tar.gz`. + +```bash +wget https://github.com/cdr/code-server/releases/download//code-server--linux-arm64.tar.gz +``` + +> Please note to replace the angle brackets and their contents with the corresponding version number, for example: `tar -xvf ./code-server-4.15.0-linux-arm64.tar.gz`. + +```bash +tar -xvf ./code-server--linux-arm64.tar.gz +``` + +Move to the extracted directory: + +> Please note to replace the angle brackets and their contents with the corresponding version number, for example: `cd code-server-4.15.0-linux-arm64/bin`. + +```bash +cd code-server--linux-arm64/bin +``` + +Enter the following command to set a temporary password for accessing `code-server`: + +> Please note to replace the angle brackets and their contents with your desired password. + +```bash +export PASSWORD="" +``` + +Start `code-server`: + +```bash +./code-server +``` + +Open the 8080 app that you downloaded from this repository and enter the password you set to access `code-server`. + +### Subsequent Usage + +Open `termux` and execute the following commands: + +```bash +./start-ubuntu.sh +``` + +> Please note to replace the angle brackets and their contents with the corresponding version number. + +```bash +cd code-server--linux-arm64/bin +``` + +> Please note to replace the angle brackets and their contents with your set password. + +```bash +export PASSWORD="" +``` + +```bash +./code-server +``` + +Then open the 8080 app. + +### Additional Notes + +Since termux stores files in a private directory (data/data), non-root devices cannot access it. Therefore, you can install various server management tools in the Ubuntu environment, such as SSH or web-based tools, to manage files. \ No newline at end of file diff --git a/ReadmeImageEN.png b/ReadmeImageEN.png new file mode 100644 index 0000000..f39ef0e Binary files /dev/null and b/ReadmeImageEN.png differ diff --git a/ReadmeImageZhCN.png b/ReadmeImageZhCN.png new file mode 100644 index 0000000..f40ee83 Binary files /dev/null and b/ReadmeImageZhCN.png differ diff --git a/app/.gitignore b/app/.gitignore new file mode 100644 index 0000000..42afabf --- /dev/null +++ b/app/.gitignore @@ -0,0 +1 @@ +/build \ No newline at end of file diff --git a/app/build.gradle b/app/build.gradle new file mode 100644 index 0000000..f5bac73 --- /dev/null +++ b/app/build.gradle @@ -0,0 +1,54 @@ +plugins { + id 'com.android.application' + id 'org.jetbrains.kotlin.android' +} + +android { + namespace 'com.dev.a8080' + compileSdk 33 + + defaultConfig { + applicationId "com.dev.a8080" + minSdk 26 + targetSdk 33 + versionCode 1 + versionName "1.0" + + testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner" + + } + + splits { + abi{ + enable true + reset() + include 'arm64-v8a','armeabi-v7a','x86','x86_64' + universalApk true + } + } + + buildTypes { + release { + minifyEnabled false + proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro' + } + } + compileOptions { + sourceCompatibility JavaVersion.VERSION_1_8 + targetCompatibility JavaVersion.VERSION_1_8 + } + kotlinOptions { + jvmTarget = '1.8' + } +} + +dependencies { + + implementation 'androidx.core:core-ktx:1.10.1' + implementation 'androidx.appcompat:appcompat:1.6.1' + implementation 'com.google.android.material:material:1.9.0' + implementation 'androidx.constraintlayout:constraintlayout:2.1.4' + testImplementation 'junit:junit:4.13.2' + androidTestImplementation 'androidx.test.ext:junit:1.1.5' + androidTestImplementation 'androidx.test.espresso:espresso-core:3.5.1' +} \ No newline at end of file diff --git a/app/proguard-rules.pro b/app/proguard-rules.pro new file mode 100644 index 0000000..481bb43 --- /dev/null +++ b/app/proguard-rules.pro @@ -0,0 +1,21 @@ +# Add project specific ProGuard rules here. +# You can control the set of applied configuration files using the +# proguardFiles setting in build.gradle. +# +# For more details, see +# http://developer.android.com/guide/developing/tools/proguard.html + +# If your project uses WebView with JS, uncomment the following +# and specify the fully qualified class name to the JavaScript interface +# class: +#-keepclassmembers class fqcn.of.javascript.interface.for.webview { +# public *; +#} + +# Uncomment this to preserve the line number information for +# debugging stack traces. +#-keepattributes SourceFile,LineNumberTable + +# If you keep the line number information, uncomment this to +# hide the original source file name. +#-renamesourcefileattribute SourceFile \ No newline at end of file diff --git a/app/src/androidTest/java/com/dev/a8080/ExampleInstrumentedTest.kt b/app/src/androidTest/java/com/dev/a8080/ExampleInstrumentedTest.kt new file mode 100644 index 0000000..3674807 --- /dev/null +++ b/app/src/androidTest/java/com/dev/a8080/ExampleInstrumentedTest.kt @@ -0,0 +1,22 @@ +package com.dev.a8080 + +import androidx.test.ext.junit.runners.AndroidJUnit4 +import androidx.test.platform.app.InstrumentationRegistry +import org.junit.Assert.* +import org.junit.Test +import org.junit.runner.RunWith + +/** + * Instrumented test, which will execute on an Android device. + * + * See [testing documentation](http://d.android.com/tools/testing). + */ +@RunWith(AndroidJUnit4::class) +class ExampleInstrumentedTest { + @Test + fun useAppContext() { + // Context of the app under test. + val appContext = InstrumentationRegistry.getInstrumentation().targetContext + assertEquals("com.dev.a8080", appContext.packageName) + } +} \ No newline at end of file diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml new file mode 100644 index 0000000..896f681 --- /dev/null +++ b/app/src/main/AndroidManifest.xml @@ -0,0 +1,56 @@ + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/app/src/main/ic_launcher-playstore.png b/app/src/main/ic_launcher-playstore.png new file mode 100644 index 0000000..cae363e Binary files /dev/null and b/app/src/main/ic_launcher-playstore.png differ diff --git a/app/src/main/java/com/dev/a8080/MainActivity.kt b/app/src/main/java/com/dev/a8080/MainActivity.kt new file mode 100644 index 0000000..7e67fd1 --- /dev/null +++ b/app/src/main/java/com/dev/a8080/MainActivity.kt @@ -0,0 +1,335 @@ +package com.dev.a8080 + +import android.Manifest +import android.annotation.SuppressLint +import android.app.DownloadManager +import android.content.Context +import android.content.Intent +import android.content.pm.ActivityInfo +import android.content.pm.PackageManager +import android.content.res.Configuration +import android.graphics.Bitmap +import android.net.Uri +import android.net.http.SslError +import android.os.Build +import android.os.Bundle +import android.os.Environment +import android.provider.Settings +import android.view.View +import android.view.ViewGroup +import android.view.WindowManager +import android.webkit.SslErrorHandler +import android.webkit.WebResourceRequest +import android.webkit.WebSettings +import android.webkit.WebView +import android.webkit.WebViewClient +import androidx.annotation.RequiresApi +import androidx.appcompat.app.AppCompatActivity +import androidx.core.app.ActivityCompat +import androidx.core.content.ContextCompat +import androidx.core.view.ViewCompat +import androidx.core.view.WindowInsetsAnimationCompat +import androidx.core.view.WindowInsetsCompat +import com.google.android.material.dialog.MaterialAlertDialogBuilder + +class CustomWebView(context: Context) : WebView(context) { + override fun onSizeChanged(w: Int, h: Int, ow: Int, oh: Int) { + super.onSizeChanged(w, h, ow, oh) + requestLayout() + } +} + +class MainActivity : AppCompatActivity() { + private var originalPaddingBottom = 0 + private lateinit var myWebView: WebView + + @SuppressLint("UseCompatLoadingForDrawables", "ResourceAsColor") + override fun onConfigurationChanged(newConfig: Configuration) { + super.onConfigurationChanged(newConfig) + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.P) { + val cutoutMode = window.attributes.layoutInDisplayCutoutMode + if (newConfig.orientation == Configuration.ORIENTATION_LANDSCAPE) { + window.attributes.layoutInDisplayCutoutMode = + WindowManager.LayoutParams.LAYOUT_IN_DISPLAY_CUTOUT_MODE_SHORT_EDGES + } else { + window.attributes.layoutInDisplayCutoutMode = cutoutMode + } + } + window.decorView.apply { + systemUiVisibility = + if ((context.resources.configuration.uiMode and Configuration.UI_MODE_NIGHT_MASK) == Configuration.UI_MODE_NIGHT_NO) { + window.setBackgroundDrawableResource(R.drawable.white) + window.navigationBarColor = getColor(R.color.white) + window.statusBarColor = getColor(R.color.white) + setBackgroundColor(getColor(R.color.white)) + View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN or View.SYSTEM_UI_FLAG_HIDE_NAVIGATION or View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY or View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR or WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS + } else { + window.setBackgroundDrawableResource(R.drawable.black) + window.navigationBarColor = getColor(R.color.black) + window.statusBarColor = getColor(R.color.black) + setBackgroundColor(getColor(R.color.black)) + View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN or View.SYSTEM_UI_FLAG_HIDE_NAVIGATION or View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY or WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS or View.SYSTEM_UI_FLAG_LAYOUT_STABLE or View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION + } + } + } + + + @RequiresApi(Build.VERSION_CODES.Q) + @SuppressLint("SetJavaScriptEnabled", "MissingInflatedId") + override fun onCreate(savedInstanceState: Bundle?) { + window.decorView.apply { + systemUiVisibility = + if ((context.resources.configuration.uiMode and Configuration.UI_MODE_NIGHT_MASK) == Configuration.UI_MODE_NIGHT_NO) { + window.setBackgroundDrawableResource(R.drawable.white) + window.navigationBarColor = getColor(R.color.white) + window.statusBarColor = getColor(R.color.white) + setBackgroundColor(getColor(R.color.white)) + View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN or View.SYSTEM_UI_FLAG_HIDE_NAVIGATION or View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY or View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR or WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS + } else { + window.setBackgroundDrawableResource(R.drawable.black) + window.navigationBarColor = getColor(R.color.black) + window.statusBarColor = getColor(R.color.black) + setBackgroundColor(getColor(R.color.black)) + View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN or View.SYSTEM_UI_FLAG_HIDE_NAVIGATION or View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY or WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS or View.SYSTEM_UI_FLAG_LAYOUT_STABLE or View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION + } + } + + @RequiresApi(Build.VERSION_CODES.R) if (!Environment.isExternalStorageManager()) { + val builder = MaterialAlertDialogBuilder(this) + builder.setTitle("请求所有文件访问权限") + .setMessage("Android WebView 可能调用文件,是否给予所有文件访问权限?") + .setPositiveButton("前往权限设置") { dialog, which -> + var intent = Intent(Settings.ACTION_MANAGE_APP_ALL_FILES_ACCESS_PERMISSION) + intent.data = Uri.parse("package:" + this.packageName) + val rmes = 100 + startActivityForResult(intent, rmes) + }.setNegativeButton("拒绝") { dialog, which -> } + val dialog = builder.create() + dialog.show() + + } + //隐藏导航栏 + window.decorView.apply { + systemUiVisibility = + if ((context.resources.configuration.uiMode and Configuration.UI_MODE_NIGHT_MASK) == Configuration.UI_MODE_NIGHT_NO) { + View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN or View.SYSTEM_UI_FLAG_HIDE_NAVIGATION or View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY or View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR or WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS + } else { + View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN or View.SYSTEM_UI_FLAG_HIDE_NAVIGATION or View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY or WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS + } + } + + //强制横屏 + requestedOrientation = ActivityInfo.SCREEN_ORIENTATION_SENSOR_LANDSCAPE + + + super.onCreate(savedInstanceState) + setContentView(R.layout.activity_main) + + myWebView = findViewById(R.id.webview) + var rootLayout: ViewGroup? = findViewById(R.id.rootLayout) + + + //权限申请 + if (ContextCompat.checkSelfPermission( + this, Manifest.permission.WRITE_EXTERNAL_STORAGE + ) == PackageManager.PERMISSION_DENIED + ) { + val requestCode = 100 + ActivityCompat.requestPermissions( + this, arrayOf(Manifest.permission.WRITE_EXTERNAL_STORAGE), requestCode + ) + } + + + if (ContextCompat.checkSelfPermission( + this, Manifest.permission.WRITE_EXTERNAL_STORAGE + ) == PackageManager.PERMISSION_DENIED + ) { + val requestCode = 100 + ActivityCompat.requestPermissions( + this, arrayOf(Manifest.permission.WRITE_EXTERNAL_STORAGE), requestCode + ) + } + if (ContextCompat.checkSelfPermission( + this, Manifest.permission.READ_EXTERNAL_STORAGE + ) == PackageManager.PERMISSION_DENIED + ) { + val requestCode = 100 + ActivityCompat.requestPermissions( + this, arrayOf(Manifest.permission.READ_EXTERNAL_STORAGE), requestCode + ) + } + if (ContextCompat.checkSelfPermission( + this, Manifest.permission.READ_MEDIA_AUDIO + ) == PackageManager.PERMISSION_DENIED + ) { + val requestCode = 100 + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU) { + ActivityCompat.requestPermissions( + this, arrayOf(Manifest.permission.READ_MEDIA_AUDIO), requestCode + ) + } + } + if (ContextCompat.checkSelfPermission( + this, Manifest.permission.READ_MEDIA_VIDEO + ) == PackageManager.PERMISSION_DENIED + ) { + val requestCode = 100 + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU) { + ActivityCompat.requestPermissions( + this, arrayOf(Manifest.permission.READ_MEDIA_VIDEO), requestCode + ) + } + } + if (ContextCompat.checkSelfPermission( + this, Manifest.permission.READ_MEDIA_IMAGES + ) == PackageManager.PERMISSION_DENIED + ) { + val requestCode = 100 + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU) { + ActivityCompat.requestPermissions( + this, arrayOf(Manifest.permission.READ_MEDIA_IMAGES), requestCode + ) + } + } + + //WebView的设置 + //myWebView.clearCache(true) + myWebView.webViewClient = WebViewClient() + myWebView.settings.javaScriptEnabled = true + myWebView.settings.domStorageEnabled = true + myWebView.settings.safeBrowsingEnabled = false + myWebView.settings.cacheMode = WebSettings.LOAD_NO_CACHE + myWebView.settings.databaseEnabled = true + myWebView.settings.mixedContentMode = WebSettings.MIXED_CONTENT_ALWAYS_ALLOW + myWebView.settings.pluginState = WebSettings.PluginState.ON + myWebView.settings.allowFileAccess = true + myWebView.setBackgroundColor(0) + myWebView.background.alpha = 0 + myWebView.settings.loadWithOverviewMode = true + myWebView.settings.javaScriptCanOpenWindowsAutomatically = true + myWebView.settings.allowUniversalAccessFromFileURLs = true + myWebView.settings.loadsImagesAutomatically = true + myWebView.settings.defaultTextEncodingName = "utf-8" + myWebView.settings.allowContentAccess = true + myWebView.settings.forceDark = WebSettings.FORCE_DARK_AUTO + originalPaddingBottom = myWebView.paddingBottom + + myWebView.setDownloadListener { url, _, _, _, _ -> + val builder = MaterialAlertDialogBuilder(this) + builder.setTitle("是否下载?").setMessage(url) + .setPositiveButton("下载") { dialog, which -> + //系统下载 + val request = DownloadManager.Request(Uri.parse(url)) + val downloadManager = + getSystemService(Context.DOWNLOAD_SERVICE) as DownloadManager + downloadManager.enqueue(request) + }.setNegativeButton("拒绝") { dialog, which -> } + val dialog = builder.create() + dialog.show() + } + + + + myWebView.webViewClient = object : WebViewClient() { + @Deprecated("Deprecated in Java", ReplaceWith("false")) + override fun shouldOverrideUrlLoading(view: WebView?, url: String?): Boolean { + return false + } + + override fun onPageStarted(view: WebView?, url: String?, favicon: Bitmap?) { + super.onPageStarted(view, url, favicon) + } + + override fun shouldOverrideUrlLoading( + view: WebView?, request: WebResourceRequest? + ): Boolean { + return super.shouldOverrideUrlLoading(view, request) + } + + @SuppressLint("WebViewClientOnReceivedSslError") + override fun onReceivedSslError( + view: WebView?, handler: SslErrorHandler?, error: SslError? + ) { + handler?.proceed()//信任所有SSL证书 + } + + override fun onPageFinished(view: WebView?, url: String?) { + super.onPageFinished(view, url) + myWebView.requestLayout() + } + } + myWebView.settings.userAgentString = + "Mozilla/5.0 (Windows NT 10.0; Win64; arm64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/116.0.0.0 Safari/537.36" + + + //适配状态栏、异形屏和软键盘高度 + ViewCompat.setOnApplyWindowInsetsListener(rootLayout!!) { _, insets -> + val statusBarHeight = insets.getInsets(WindowInsetsCompat.Type.systemBars()).top + rootLayout.setPadding(0, statusBarHeight, 0, 0) + val imeVisible = insets.isVisible(WindowInsetsCompat.Type.ime()) + val cutoutLeft = rootLayout.rootWindowInsets.displayCutout?.safeInsetLeft ?: 0 + val cutoutRight = rootLayout.rootWindowInsets.displayCutout?.safeInsetRight ?: 0 + + if (imeVisible) { + val imeHeight = insets.getInsets(WindowInsetsCompat.Type.ime()).bottom + rootLayout.setPadding(cutoutLeft, statusBarHeight, cutoutRight, imeHeight) + } else { + rootLayout.setPadding(cutoutLeft, statusBarHeight, cutoutRight, 0) + } + WindowInsetsCompat.Builder(insets).build() + } + + + myWebView.loadUrl("http://127.0.0.1:8080") + + //软键盘动画 + ViewCompat.setWindowInsetsAnimationCallback( + rootLayout, + object : WindowInsetsAnimationCompat.Callback(DISPATCH_MODE_STOP) { + var startBottom = 0f + + override fun onPrepare(animation: WindowInsetsAnimationCompat) { + startBottom = rootLayout.bottom.toFloat() + } + + var endBottom = 0f + + override fun onStart( + animation: WindowInsetsAnimationCompat, + bounds: WindowInsetsAnimationCompat.BoundsCompat + ): WindowInsetsAnimationCompat.BoundsCompat { + endBottom = rootLayout.bottom.toFloat() + + return bounds + } + + override fun onProgress( + insets: WindowInsetsCompat, + runningAnimations: MutableList + ): WindowInsetsCompat { + val imeAnimation = runningAnimations.find { + it.typeMask and WindowInsetsCompat.Type.ime() != 0 + } ?: return insets + + myWebView.translationY = + (startBottom - endBottom) * (1 - imeAnimation.interpolatedFraction) + + return insets + } + }) + + + } + + @Deprecated("Deprecated in Java") + override fun onBackPressed() { + if (myWebView.canGoBack()) { + myWebView.goBack() + } else { + super.onBackPressed() + } + } + + +} \ No newline at end of file diff --git a/app/src/main/res/drawable/black.xml b/app/src/main/res/drawable/black.xml new file mode 100644 index 0000000..d1e1335 --- /dev/null +++ b/app/src/main/res/drawable/black.xml @@ -0,0 +1,10 @@ + + + + \ No newline at end of file diff --git a/app/src/main/res/drawable/ic_launcher_background.xml b/app/src/main/res/drawable/ic_launcher_background.xml new file mode 100644 index 0000000..7ab9c3f --- /dev/null +++ b/app/src/main/res/drawable/ic_launcher_background.xml @@ -0,0 +1,170 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/app/src/main/res/drawable/ic_launcher_foreground.xml b/app/src/main/res/drawable/ic_launcher_foreground.xml new file mode 100644 index 0000000..c51ceca --- /dev/null +++ b/app/src/main/res/drawable/ic_launcher_foreground.xml @@ -0,0 +1,51 @@ + + + + + + + + + + + + + + + + + + + + + diff --git a/app/src/main/res/drawable/white.xml b/app/src/main/res/drawable/white.xml new file mode 100644 index 0000000..daa5e93 --- /dev/null +++ b/app/src/main/res/drawable/white.xml @@ -0,0 +1,10 @@ + + + + \ No newline at end of file diff --git a/app/src/main/res/layout/activity_main.xml b/app/src/main/res/layout/activity_main.xml new file mode 100644 index 0000000..7a64040 --- /dev/null +++ b/app/src/main/res/layout/activity_main.xml @@ -0,0 +1,26 @@ + + + + + + + + + + + \ No newline at end of file diff --git a/app/src/main/res/mipmap-anydpi-v26/ic_launcher.xml b/app/src/main/res/mipmap-anydpi-v26/ic_launcher.xml new file mode 100644 index 0000000..eca70cf --- /dev/null +++ b/app/src/main/res/mipmap-anydpi-v26/ic_launcher.xml @@ -0,0 +1,5 @@ + + + + + \ No newline at end of file diff --git a/app/src/main/res/mipmap-anydpi-v26/ic_launcher_round.xml b/app/src/main/res/mipmap-anydpi-v26/ic_launcher_round.xml new file mode 100644 index 0000000..eca70cf --- /dev/null +++ b/app/src/main/res/mipmap-anydpi-v26/ic_launcher_round.xml @@ -0,0 +1,5 @@ + + + + + \ No newline at end of file diff --git a/app/src/main/res/mipmap-hdpi/ic_launcher.png b/app/src/main/res/mipmap-hdpi/ic_launcher.png new file mode 100644 index 0000000..b539562 Binary files /dev/null and b/app/src/main/res/mipmap-hdpi/ic_launcher.png differ diff --git a/app/src/main/res/mipmap-hdpi/ic_launcher_round.png b/app/src/main/res/mipmap-hdpi/ic_launcher_round.png new file mode 100644 index 0000000..c34d9b7 Binary files /dev/null and b/app/src/main/res/mipmap-hdpi/ic_launcher_round.png differ diff --git a/app/src/main/res/mipmap-mdpi/ic_launcher.png b/app/src/main/res/mipmap-mdpi/ic_launcher.png new file mode 100644 index 0000000..e9adb8c Binary files /dev/null and b/app/src/main/res/mipmap-mdpi/ic_launcher.png differ diff --git a/app/src/main/res/mipmap-mdpi/ic_launcher_round.png b/app/src/main/res/mipmap-mdpi/ic_launcher_round.png new file mode 100644 index 0000000..8f35042 Binary files /dev/null and b/app/src/main/res/mipmap-mdpi/ic_launcher_round.png differ diff --git a/app/src/main/res/mipmap-xhdpi/ic_launcher.png b/app/src/main/res/mipmap-xhdpi/ic_launcher.png new file mode 100644 index 0000000..e533ed8 Binary files /dev/null and b/app/src/main/res/mipmap-xhdpi/ic_launcher.png differ diff --git a/app/src/main/res/mipmap-xhdpi/ic_launcher_round.png b/app/src/main/res/mipmap-xhdpi/ic_launcher_round.png new file mode 100644 index 0000000..0d8c852 Binary files /dev/null and b/app/src/main/res/mipmap-xhdpi/ic_launcher_round.png differ diff --git a/app/src/main/res/mipmap-xxhdpi/ic_launcher.png b/app/src/main/res/mipmap-xxhdpi/ic_launcher.png new file mode 100644 index 0000000..a7b7284 Binary files /dev/null and b/app/src/main/res/mipmap-xxhdpi/ic_launcher.png differ diff --git a/app/src/main/res/mipmap-xxhdpi/ic_launcher_round.png b/app/src/main/res/mipmap-xxhdpi/ic_launcher_round.png new file mode 100644 index 0000000..af6890b Binary files /dev/null and b/app/src/main/res/mipmap-xxhdpi/ic_launcher_round.png differ diff --git a/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png b/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png new file mode 100644 index 0000000..930fdb8 Binary files /dev/null and b/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png differ diff --git a/app/src/main/res/mipmap-xxxhdpi/ic_launcher_round.png b/app/src/main/res/mipmap-xxxhdpi/ic_launcher_round.png new file mode 100644 index 0000000..0f9a4a6 Binary files /dev/null and b/app/src/main/res/mipmap-xxxhdpi/ic_launcher_round.png differ diff --git a/app/src/main/res/values-night-v27/themes.xml b/app/src/main/res/values-night-v27/themes.xml new file mode 100644 index 0000000..afd56f5 --- /dev/null +++ b/app/src/main/res/values-night-v27/themes.xml @@ -0,0 +1,16 @@ + + + + + \ No newline at end of file diff --git a/app/src/main/res/values-night-v29/themes.xml b/app/src/main/res/values-night-v29/themes.xml new file mode 100644 index 0000000..9d23396 --- /dev/null +++ b/app/src/main/res/values-night-v29/themes.xml @@ -0,0 +1,17 @@ + + + + + \ No newline at end of file diff --git a/app/src/main/res/values-night/themes.xml b/app/src/main/res/values-night/themes.xml new file mode 100644 index 0000000..6bddff2 --- /dev/null +++ b/app/src/main/res/values-night/themes.xml @@ -0,0 +1,14 @@ + + + + \ No newline at end of file diff --git a/app/src/main/res/values-v27/themes.xml b/app/src/main/res/values-v27/themes.xml new file mode 100644 index 0000000..90fa76d --- /dev/null +++ b/app/src/main/res/values-v27/themes.xml @@ -0,0 +1,16 @@ + + + + + \ No newline at end of file diff --git a/app/src/main/res/values-v29/themes.xml b/app/src/main/res/values-v29/themes.xml new file mode 100644 index 0000000..6b2f8ea --- /dev/null +++ b/app/src/main/res/values-v29/themes.xml @@ -0,0 +1,17 @@ + + + + + \ No newline at end of file diff --git a/app/src/main/res/values/colors.xml b/app/src/main/res/values/colors.xml new file mode 100644 index 0000000..7982bb1 --- /dev/null +++ b/app/src/main/res/values/colors.xml @@ -0,0 +1,5 @@ + + + #181818 + #f8f8f8 + \ No newline at end of file diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml new file mode 100644 index 0000000..9b65227 --- /dev/null +++ b/app/src/main/res/values/strings.xml @@ -0,0 +1,3 @@ + + 8080 + \ No newline at end of file diff --git a/app/src/main/res/values/themes.xml b/app/src/main/res/values/themes.xml new file mode 100644 index 0000000..87c7976 --- /dev/null +++ b/app/src/main/res/values/themes.xml @@ -0,0 +1,16 @@ + + + + +