From 2f5a3edbb5d0e43dab522eb6ddbd601f2f690620 Mon Sep 17 00:00:00 2001 From: fengge <844143714@qq.com> Date: Sun, 15 Mar 2026 12:46:02 +0800 Subject: [PATCH] first commit --- StandAPP/.gitignore | 15 ++ StandAPP/.idea/.gitignore | 3 + StandAPP/.idea/AndroidProjectSystem.xml | 6 + StandAPP/.idea/compiler.xml | 6 + StandAPP/.idea/deploymentTargetSelector.xml | 18 ++ StandAPP/.idea/deviceManager.xml | 13 + StandAPP/.idea/gradle.xml | 18 ++ StandAPP/.idea/misc.xml | 9 + StandAPP/.idea/runConfigurations.xml | 17 ++ StandAPP/app/.gitignore | 1 + StandAPP/app/build.gradle.kts | 64 +++++ StandAPP/app/proguard-rules.pro | 31 +++ .../stand/standapp/ExampleInstrumentedTest.kt | 24 ++ StandAPP/app/src/main/AndroidManifest.xml | 52 ++++ StandAPP/app/src/main/assets/print_demo.html | 195 ++++++++++++++ .../com/stand/standapp/AndroidInterface.kt | 92 +++++++ .../main/java/com/stand/standapp/AppConfig.kt | 51 ++++ .../java/com/stand/standapp/LoginActivity.kt | 103 +++++++ .../java/com/stand/standapp/MainActivity.kt | 84 ++++++ .../java/com/stand/standapp/UpdateManager.kt | 245 +++++++++++++++++ .../java/com/stand/standapp/ui/theme/Color.kt | 11 + .../java/com/stand/standapp/ui/theme/Theme.kt | 58 ++++ .../java/com/stand/standapp/ui/theme/Type.kt | 34 +++ .../app/src/main/res/drawable/bg_login.xml | 7 + .../res/drawable/ic_launcher_background.xml | 170 ++++++++++++ .../res/drawable/ic_launcher_foreground.xml | 30 +++ .../main/res/drawable/shape_button_login.xml | 4 + .../src/main/res/drawable/shape_edit_text.xml | 4 + .../src/main/res/drawable/shape_login_box.xml | 5 + .../src/main/res/layout/activity_login.xml | 127 +++++++++ .../app/src/main/res/layout/activity_main.xml | 7 + .../app/src/main/res/layout/dialog_update.xml | 40 +++ .../res/mipmap-anydpi-v26/ic_launcher.xml | 6 + .../mipmap-anydpi-v26/ic_launcher_round.xml | 6 + .../src/main/res/mipmap-hdpi/ic_launcher.webp | Bin 0 -> 1404 bytes .../res/mipmap-hdpi/ic_launcher_round.webp | Bin 0 -> 2898 bytes .../src/main/res/mipmap-mdpi/ic_launcher.webp | Bin 0 -> 982 bytes .../res/mipmap-mdpi/ic_launcher_round.webp | Bin 0 -> 1772 bytes .../main/res/mipmap-xhdpi/ic_launcher.webp | Bin 0 -> 1900 bytes .../res/mipmap-xhdpi/ic_launcher_round.webp | Bin 0 -> 3918 bytes .../main/res/mipmap-xxhdpi/ic_launcher.webp | Bin 0 -> 2884 bytes .../res/mipmap-xxhdpi/ic_launcher_round.webp | Bin 0 -> 5914 bytes .../main/res/mipmap-xxxhdpi/ic_launcher.webp | Bin 0 -> 3844 bytes .../res/mipmap-xxxhdpi/ic_launcher_round.webp | Bin 0 -> 7778 bytes StandAPP/app/src/main/res/values/colors.xml | 10 + StandAPP/app/src/main/res/values/strings.xml | 3 + StandAPP/app/src/main/res/values/themes.xml | 9 + .../app/src/main/res/xml/backup_rules.xml | 13 + .../main/res/xml/data_extraction_rules.xml | 19 ++ StandAPP/app/src/main/res/xml/file_paths.xml | 8 + .../main/res/xml/network_security_config.xml | 7 + .../com/stand/standapp/ExampleUnitTest.kt | 17 ++ StandAPP/build.gradle.kts | 5 + StandAPP/gradle.properties | 17 ++ StandAPP/gradle/gradle-daemon-jvm.properties | 12 + StandAPP/gradle/libs.versions.toml | 33 +++ StandAPP/gradle/wrapper/gradle-wrapper.jar | Bin 0 -> 45457 bytes .../gradle/wrapper/gradle-wrapper.properties | 9 + StandAPP/gradlew | 251 ++++++++++++++++++ StandAPP/gradlew.bat | 94 +++++++ StandAPP/img.png | Bin 0 -> 364332 bytes StandAPP/key/StandAPP | Bin 0 -> 2524 bytes StandAPP/settings.gradle.kts | 27 ++ StandAPP/屏幕截图 2026-03-13 021623.png | Bin 0 -> 322340 bytes 64 files changed, 2090 insertions(+) create mode 100644 StandAPP/.gitignore create mode 100644 StandAPP/.idea/.gitignore create mode 100644 StandAPP/.idea/AndroidProjectSystem.xml create mode 100644 StandAPP/.idea/compiler.xml create mode 100644 StandAPP/.idea/deploymentTargetSelector.xml create mode 100644 StandAPP/.idea/deviceManager.xml create mode 100644 StandAPP/.idea/gradle.xml create mode 100644 StandAPP/.idea/misc.xml create mode 100644 StandAPP/.idea/runConfigurations.xml create mode 100644 StandAPP/app/.gitignore create mode 100644 StandAPP/app/build.gradle.kts create mode 100644 StandAPP/app/proguard-rules.pro create mode 100644 StandAPP/app/src/androidTest/java/com/stand/standapp/ExampleInstrumentedTest.kt create mode 100644 StandAPP/app/src/main/AndroidManifest.xml create mode 100644 StandAPP/app/src/main/assets/print_demo.html create mode 100644 StandAPP/app/src/main/java/com/stand/standapp/AndroidInterface.kt create mode 100644 StandAPP/app/src/main/java/com/stand/standapp/AppConfig.kt create mode 100644 StandAPP/app/src/main/java/com/stand/standapp/LoginActivity.kt create mode 100644 StandAPP/app/src/main/java/com/stand/standapp/MainActivity.kt create mode 100644 StandAPP/app/src/main/java/com/stand/standapp/UpdateManager.kt create mode 100644 StandAPP/app/src/main/java/com/stand/standapp/ui/theme/Color.kt create mode 100644 StandAPP/app/src/main/java/com/stand/standapp/ui/theme/Theme.kt create mode 100644 StandAPP/app/src/main/java/com/stand/standapp/ui/theme/Type.kt create mode 100644 StandAPP/app/src/main/res/drawable/bg_login.xml create mode 100644 StandAPP/app/src/main/res/drawable/ic_launcher_background.xml create mode 100644 StandAPP/app/src/main/res/drawable/ic_launcher_foreground.xml create mode 100644 StandAPP/app/src/main/res/drawable/shape_button_login.xml create mode 100644 StandAPP/app/src/main/res/drawable/shape_edit_text.xml create mode 100644 StandAPP/app/src/main/res/drawable/shape_login_box.xml create mode 100644 StandAPP/app/src/main/res/layout/activity_login.xml create mode 100644 StandAPP/app/src/main/res/layout/activity_main.xml create mode 100644 StandAPP/app/src/main/res/layout/dialog_update.xml create mode 100644 StandAPP/app/src/main/res/mipmap-anydpi-v26/ic_launcher.xml create mode 100644 StandAPP/app/src/main/res/mipmap-anydpi-v26/ic_launcher_round.xml create mode 100644 StandAPP/app/src/main/res/mipmap-hdpi/ic_launcher.webp create mode 100644 StandAPP/app/src/main/res/mipmap-hdpi/ic_launcher_round.webp create mode 100644 StandAPP/app/src/main/res/mipmap-mdpi/ic_launcher.webp create mode 100644 StandAPP/app/src/main/res/mipmap-mdpi/ic_launcher_round.webp create mode 100644 StandAPP/app/src/main/res/mipmap-xhdpi/ic_launcher.webp create mode 100644 StandAPP/app/src/main/res/mipmap-xhdpi/ic_launcher_round.webp create mode 100644 StandAPP/app/src/main/res/mipmap-xxhdpi/ic_launcher.webp create mode 100644 StandAPP/app/src/main/res/mipmap-xxhdpi/ic_launcher_round.webp create mode 100644 StandAPP/app/src/main/res/mipmap-xxxhdpi/ic_launcher.webp create mode 100644 StandAPP/app/src/main/res/mipmap-xxxhdpi/ic_launcher_round.webp create mode 100644 StandAPP/app/src/main/res/values/colors.xml create mode 100644 StandAPP/app/src/main/res/values/strings.xml create mode 100644 StandAPP/app/src/main/res/values/themes.xml create mode 100644 StandAPP/app/src/main/res/xml/backup_rules.xml create mode 100644 StandAPP/app/src/main/res/xml/data_extraction_rules.xml create mode 100644 StandAPP/app/src/main/res/xml/file_paths.xml create mode 100644 StandAPP/app/src/main/res/xml/network_security_config.xml create mode 100644 StandAPP/app/src/test/java/com/stand/standapp/ExampleUnitTest.kt create mode 100644 StandAPP/build.gradle.kts create mode 100644 StandAPP/gradle.properties create mode 100644 StandAPP/gradle/gradle-daemon-jvm.properties create mode 100644 StandAPP/gradle/libs.versions.toml create mode 100644 StandAPP/gradle/wrapper/gradle-wrapper.jar create mode 100644 StandAPP/gradle/wrapper/gradle-wrapper.properties create mode 100644 StandAPP/gradlew create mode 100644 StandAPP/gradlew.bat create mode 100644 StandAPP/img.png create mode 100644 StandAPP/key/StandAPP create mode 100644 StandAPP/settings.gradle.kts create mode 100644 StandAPP/屏幕截图 2026-03-13 021623.png diff --git a/StandAPP/.gitignore b/StandAPP/.gitignore new file mode 100644 index 0000000..aa724b7 --- /dev/null +++ b/StandAPP/.gitignore @@ -0,0 +1,15 @@ +*.iml +.gradle +/local.properties +/.idea/caches +/.idea/libraries +/.idea/modules.xml +/.idea/workspace.xml +/.idea/navEditor.xml +/.idea/assetWizardSettings.xml +.DS_Store +/build +/captures +.externalNativeBuild +.cxx +local.properties diff --git a/StandAPP/.idea/.gitignore b/StandAPP/.idea/.gitignore new file mode 100644 index 0000000..26d3352 --- /dev/null +++ b/StandAPP/.idea/.gitignore @@ -0,0 +1,3 @@ +# Default ignored files +/shelf/ +/workspace.xml diff --git a/StandAPP/.idea/AndroidProjectSystem.xml b/StandAPP/.idea/AndroidProjectSystem.xml new file mode 100644 index 0000000..4a53bee --- /dev/null +++ b/StandAPP/.idea/AndroidProjectSystem.xml @@ -0,0 +1,6 @@ + + + + + \ No newline at end of file diff --git a/StandAPP/.idea/compiler.xml b/StandAPP/.idea/compiler.xml new file mode 100644 index 0000000..b589d56 --- /dev/null +++ b/StandAPP/.idea/compiler.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/StandAPP/.idea/deploymentTargetSelector.xml b/StandAPP/.idea/deploymentTargetSelector.xml new file mode 100644 index 0000000..f6411f2 --- /dev/null +++ b/StandAPP/.idea/deploymentTargetSelector.xml @@ -0,0 +1,18 @@ + + + + + + + + + \ No newline at end of file diff --git a/StandAPP/.idea/deviceManager.xml b/StandAPP/.idea/deviceManager.xml new file mode 100644 index 0000000..91f9558 --- /dev/null +++ b/StandAPP/.idea/deviceManager.xml @@ -0,0 +1,13 @@ + + + + + + \ No newline at end of file diff --git a/StandAPP/.idea/gradle.xml b/StandAPP/.idea/gradle.xml new file mode 100644 index 0000000..02c4aa5 --- /dev/null +++ b/StandAPP/.idea/gradle.xml @@ -0,0 +1,18 @@ + + + + + + + \ No newline at end of file diff --git a/StandAPP/.idea/misc.xml b/StandAPP/.idea/misc.xml new file mode 100644 index 0000000..a8a2b16 --- /dev/null +++ b/StandAPP/.idea/misc.xml @@ -0,0 +1,9 @@ + + + + + + + + \ No newline at end of file diff --git a/StandAPP/.idea/runConfigurations.xml b/StandAPP/.idea/runConfigurations.xml new file mode 100644 index 0000000..16660f1 --- /dev/null +++ b/StandAPP/.idea/runConfigurations.xml @@ -0,0 +1,17 @@ + + + + + + \ No newline at end of file diff --git a/StandAPP/app/.gitignore b/StandAPP/app/.gitignore new file mode 100644 index 0000000..42afabf --- /dev/null +++ b/StandAPP/app/.gitignore @@ -0,0 +1 @@ +/build \ No newline at end of file diff --git a/StandAPP/app/build.gradle.kts b/StandAPP/app/build.gradle.kts new file mode 100644 index 0000000..f84519c --- /dev/null +++ b/StandAPP/app/build.gradle.kts @@ -0,0 +1,64 @@ +plugins { + alias(libs.plugins.android.application) + alias(libs.plugins.kotlin.compose) +} + +android { + namespace = "com.stand.standapp" + compileSdk = 36 + + defaultConfig { + applicationId = "com.stand.standapp" + minSdk = 24 + targetSdk = 34 + versionCode = 1 + versionName = "1.0.0" + + testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner" + } + + buildTypes { + release { + // 1. 开启代码混淆/压缩 (注意是 isMinifyEnabled) + isMinifyEnabled = true + + // 2. 开启资源压缩 (注意是 isShrinkResources) + // 必须配合 isMinifyEnabled = true 使用 + isShrinkResources = true + proguardFiles( + getDefaultProguardFile("proguard-android-optimize.txt"), + "proguard-rules.pro" + ) + } + } + compileOptions { + sourceCompatibility = JavaVersion.VERSION_17 + targetCompatibility = JavaVersion.VERSION_17 + } + buildFeatures { + compose = true + } +} + +dependencies { + implementation("io.github.justson:agentweb-core:v5.1.1-androidx") + implementation("com.github.Justson:Downloader:v5.0.4-androidx") + implementation("com.google.android.material:material:1.12.0") + implementation("com.squareup.okhttp3:okhttp:4.12.0") + implementation(libs.androidx.appcompat) + 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.compose.ui) + implementation(libs.androidx.compose.ui.graphics) + implementation(libs.androidx.compose.ui.tooling.preview) + implementation(libs.androidx.compose.material3) + testImplementation(libs.junit) + androidTestImplementation(libs.androidx.junit) + androidTestImplementation(libs.androidx.espresso.core) + androidTestImplementation(platform(libs.androidx.compose.bom)) + androidTestImplementation(libs.androidx.compose.ui.test.junit4) + debugImplementation(libs.androidx.compose.ui.tooling) + debugImplementation(libs.androidx.compose.ui.test.manifest) +} \ No newline at end of file diff --git a/StandAPP/app/proguard-rules.pro b/StandAPP/app/proguard-rules.pro new file mode 100644 index 0000000..6f74ca9 --- /dev/null +++ b/StandAPP/app/proguard-rules.pro @@ -0,0 +1,31 @@ +# AgentWeb 混淆规则 +-keep class com.just.agentweb.** { *; } +-dontwarn com.just.agentweb.** + +# 忽略不存在的可选依赖报错 +-dontwarn com.alipay.sdk.** +-dontwarn com.download.library.** +-dontwarn com.google.android.material.snackbar.** + +# 保护 JavaScript 交互接口 (非常重要!) +-keepattributes *Annotation* +-keepattributes *JavascriptInterface* +-keepclassmembers class * { + @android.webkit.JavascriptInterface ; +} + +# 保护你自己的 JS 交互类 +-keep class com.stand.standapp.AndroidInterface { *; } + +# OkHttp 混淆规则 +-keepattributes Signature +-keepattributes InnerClasses +-dontwarn okhttp3.** +-dontwarn okio.** +-dontwarn javax.annotation.** +-dontwarn org.conscrypt.** +# A resource is loaded at runtime for config index: +-keepnames class okhttp3.internal.publicsuffix.PublicSuffixDatabase + +# 保护实体类 (如果你后续有 JSON 解析) +-keep class com.stand.standapp.** { *; } diff --git a/StandAPP/app/src/androidTest/java/com/stand/standapp/ExampleInstrumentedTest.kt b/StandAPP/app/src/androidTest/java/com/stand/standapp/ExampleInstrumentedTest.kt new file mode 100644 index 0000000..a88cd3c --- /dev/null +++ b/StandAPP/app/src/androidTest/java/com/stand/standapp/ExampleInstrumentedTest.kt @@ -0,0 +1,24 @@ +package com.stand.standapp + +import androidx.test.platform.app.InstrumentationRegistry +import androidx.test.ext.junit.runners.AndroidJUnit4 + +import org.junit.Test +import org.junit.runner.RunWith + +import org.junit.Assert.* + +/** + * 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.stand.standapp", appContext.packageName) + } +} \ No newline at end of file diff --git a/StandAPP/app/src/main/AndroidManifest.xml b/StandAPP/app/src/main/AndroidManifest.xml new file mode 100644 index 0000000..c78341b --- /dev/null +++ b/StandAPP/app/src/main/AndroidManifest.xml @@ -0,0 +1,52 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/StandAPP/app/src/main/assets/print_demo.html b/StandAPP/app/src/main/assets/print_demo.html new file mode 100644 index 0000000..872d333 --- /dev/null +++ b/StandAPP/app/src/main/assets/print_demo.html @@ -0,0 +1,195 @@ + + + + + + 智能调度终端 - 打印演示 + + + +
+
+

打印控制台

+
+ +
未检测到 App 接口
+ +
+ 设备信息:
+ 应用版本: Unknown
+ 环境检测: Browser +
+ + +

(支持 PDF 导出、网络打印机、A4 适配)

+ + +

(适用于蓝牙/USB 小票机,传输原始 JSON)

+ + + + +
+
测试签收单
+
+

单号: SN20260315888

+

物料: 工业级调度终端 x 5

+

物料: 工业级调度终端 x 5

+

物料: 工业级调度终端 x 5

+

物料: 工业级调度终端 x 5

+

物料: 工业级调度终端 x 5

+

物料: 工业级调度终端 x 5

+

物料: 工业级调度终端 x 5

+

物料: 工业级调度终端 x 5

+

物料: 工业级调度终端 x 5

+

物料: 工业级调度终端 x 5

+

物料: 工业级调度终端 x 5

+

物料: 工业级调度终端 x 5

+

物料: 工业级调度终端 x 5

+

物料: 工业级调度终端 x 5

+

物料: 工业级调度终端 x 5

+

物料: 工业级调度终端 x 5

+

物料: 工业级调度终端 x 5

+

物料: 工业级调度终端 x 5

+

物料: 工业级调度终端 x 5

+

物料: 工业级调度终端 x 5

+

物料: 工业级调度终端 x 5

+

物料: 工业级调度终端 x 5

+

物料: 工业级调度终端 x 5

+

物料: 工业级调度终端 x 5

+

物料: 工业级调度终端 x 5

+

物料: 工业级调度终端 x 5

+

物料: 工业级调度终端 x 5

+

物料: 工业级调度终端 x 5

+

物料: 工业级调度终端 x 5

+

物料: 工业级调度终端 x 5

+

物料: 工业级调度终端 x 5

+

物料: 工业级调度终端 x 5

+

物料: 工业级调度终端 x 5

+

物料: 工业级调度终端 x 5

+

物料: 工业级调度终端 x 5

+

物料: 工业级调度终端 x 5

+

物料: 工业级调度终端 x 5

+

物料: 工业级调度终端 x 5

+

物料: 工业级调度终端 x 5

+

物料: 工业级调度终端 x 5

+

物料: 工业级调度终端 x 5

+

物料: 工业级调度终端 x 5

+

物料: 工业级调度终端 x 5

+

物料: 工业级调度终端 x 5

+

物料: 工业级调度终端 x 5

+

物料: 工业级调度终端 x 5

+

物料: 工业级调度终端 x 5

+

物料: 工业级调度终端 x 5

+

物料: 工业级调度终端 x 5

+

物料: 工业级调度终端 x 5

+

物料: 工业级调度终端 x 5

+

物料: 工业级调度终端 x 5

+

物料: 工业级调度终端 x 5

+

物料: 工业级调度终端 x 5

+

物料: 工业级调度终端 x 5

+

物料: 工业级调度终端 x 5

+

物料: 工业级调度终端 x 5

+

物料: 工业级调度终端 x 5

+

物料: 工业级调度终端 x 5

+

物料: 工业级调度终端 x 5

+

物料: 工业级调度终端 x 5

+

物料: 工业级调度终端 x 5

+

物料: 工业级调度终端 x 5

+

物料: 工业级调度终端 x 5

+

时间:

+
+ [ 此处为二维码/条码预览 ] +
+
+
+ + + + + + diff --git a/StandAPP/app/src/main/java/com/stand/standapp/AndroidInterface.kt b/StandAPP/app/src/main/java/com/stand/standapp/AndroidInterface.kt new file mode 100644 index 0000000..8494e62 --- /dev/null +++ b/StandAPP/app/src/main/java/com/stand/standapp/AndroidInterface.kt @@ -0,0 +1,92 @@ +package com.stand.standapp + +import android.content.Context +import android.os.Handler +import android.os.Looper +import android.util.Log +import android.webkit.JavascriptInterface +import android.widget.Toast +import android.print.PrintAttributes +import android.print.PrintManager +import com.stand.standapp.R + +class AndroidInterface(private val activity: MainActivity) { + + /** + * JS 调用:标准系统打印 (PDF/网络打印机/AirPrint) + * 适用于打印精美的 A4 单据或页面 + */ + @JavascriptInterface + fun printPage() { + Handler(Looper.getMainLooper()).post { + try { + val printManager = activity.getSystemService(Context.PRINT_SERVICE) as PrintManager + // 获取 WebView 的打印适配器 + val webView = activity.getAgentWeb()?.webCreator?.getWebView() + if (webView == null) { + Toast.makeText(activity, "WebView 未就绪", Toast.LENGTH_SHORT).show() + return@post + } + + val printAdapter = webView.createPrintDocumentAdapter("Document") + val jobName = activity.getString(R.string.app_name) + " Print Job" + + printManager.print(jobName, printAdapter, PrintAttributes.Builder().build()) + } catch (e: Exception) { + Log.e("Print", "系统打印失败", e) + Toast.makeText(activity, "打印服务启动失败", Toast.LENGTH_SHORT).show() + } + } + } + + /** + * JS 调用:原始数据打印 + * 适用于热敏小票打印机 (蓝牙、USB、网络) + * @param data 可以是 JSON 字符串,包含打印的指令或文本 + */ + @JavascriptInterface + fun printRawData(data: String) { + Log.d("Print", "收到 H5 原始打印数据: $data") + Handler(Looper.getMainLooper()).post { + // 这里可以弹出一个选择框让用户选择打印机,或者根据配置自动连接 + // 常见的打印流程:1. 解析数据 -> 2. 转换成 ESC/POS 指令 -> 3. 发送到通道 + Toast.makeText(activity, "H5指令打印: $data", Toast.LENGTH_LONG).show() + + // 预留不同通道的入口 + // connectAndPrint(data) + } + } + + /** + * JS 调用:在线升级 (手动触发检查) + */ + @JavascriptInterface + fun startUpdate(apkUrl: String) { + Handler(Looper.getMainLooper()).post { + UpdateManager(activity).checkUpdate() + } + } + + /** + * JS 调用:退出应用 + */ + @JavascriptInterface + fun exitApp() { + Handler(Looper.getMainLooper()).post { + activity.showExitDialog() + } + } + + /** + * 获取版本号给 H5 判断是否需要升级 + */ + @JavascriptInterface + fun getVersionName(): String { + return try { + val packageInfo = activity.packageManager.getPackageInfo(activity.packageName, 0) + packageInfo.versionName ?: "1.0.0" + } catch (e: Exception) { + "1.0.0" + } + } +} diff --git a/StandAPP/app/src/main/java/com/stand/standapp/AppConfig.kt b/StandAPP/app/src/main/java/com/stand/standapp/AppConfig.kt new file mode 100644 index 0000000..de1777d --- /dev/null +++ b/StandAPP/app/src/main/java/com/stand/standapp/AppConfig.kt @@ -0,0 +1,51 @@ +package com.stand.standapp + +import android.content.Context +import android.content.SharedPreferences + +object AppConfig { + private const val PREF_NAME = "app_settings" + private const val KEY_SERVER_URL = "server_url" + private const val KEY_REMEMBER_LOGIN = "remember_login" + private const val KEY_USERNAME = "saved_username" + private const val KEY_PASSWORD = "saved_password" + + // 默认服务器地址 + const val DEFAULT_SERVER_URL = "http://152.32.186.199:38080" + + private fun getPrefs(context: Context): SharedPreferences { + return context.getSharedPreferences(PREF_NAME, Context.MODE_PRIVATE) + } + + fun getServerUrl(context: Context): String { + return getPrefs(context).getString(KEY_SERVER_URL, DEFAULT_SERVER_URL) ?: DEFAULT_SERVER_URL + } + + fun setServerUrl(context: Context, url: String) { + getPrefs(context).edit().putString(KEY_SERVER_URL, url).apply() + } + + fun isRememberLogin(context: Context): Boolean { + return getPrefs(context).getBoolean(KEY_REMEMBER_LOGIN, false) + } + + fun setRememberLogin(context: Context, remember: Boolean) { + getPrefs(context).edit().putBoolean(KEY_REMEMBER_LOGIN, remember).apply() + } + + fun getSavedUsername(context: Context): String { + return getPrefs(context).getString(KEY_USERNAME, "") ?: "" + } + + fun setSavedUsername(context: Context, username: String) { + getPrefs(context).edit().putString(KEY_USERNAME, username).apply() + } + + fun getSavedPassword(context: Context): String { + return getPrefs(context).getString(KEY_PASSWORD, "") ?: "" + } + + fun setSavedPassword(context: Context, password: String) { + getPrefs(context).edit().putString(KEY_PASSWORD, password).apply() + } +} diff --git a/StandAPP/app/src/main/java/com/stand/standapp/LoginActivity.kt b/StandAPP/app/src/main/java/com/stand/standapp/LoginActivity.kt new file mode 100644 index 0000000..9041191 --- /dev/null +++ b/StandAPP/app/src/main/java/com/stand/standapp/LoginActivity.kt @@ -0,0 +1,103 @@ +package com.stand.standapp + +import android.content.Intent +import android.os.Bundle +import android.widget.* +import androidx.appcompat.app.AlertDialog +import androidx.appcompat.app.AppCompatActivity + +class LoginActivity : AppCompatActivity() { + + override fun onCreate(savedInstanceState: Bundle?) { + super.onCreate(savedInstanceState) + setContentView(R.layout.activity_login) + + val etUsername = findViewById(R.id.et_username) + val etPassword = findViewById(R.id.et_password) + val cbRemember = findViewById(R.id.cb_remember) + val btnLogin = findViewById