基本ok
This commit is contained in:
@@ -2,6 +2,8 @@ plugins {
|
||||
id 'com.android.application'
|
||||
}
|
||||
|
||||
apply from: '../common.gradle'
|
||||
|
||||
android {
|
||||
namespace 'cn.ykbox.dashboard'
|
||||
compileSdk 35
|
||||
@@ -11,16 +13,20 @@ android {
|
||||
applicationId "cn.ykbox.dashboard"
|
||||
minSdk 21
|
||||
targetSdk 35
|
||||
versionCode 1
|
||||
versionName "1.0"
|
||||
versionCode gitVersionCode()
|
||||
versionName gitVersionTag()
|
||||
|
||||
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
|
||||
}
|
||||
|
||||
buildTypes {
|
||||
debug {
|
||||
signingConfig signingConfigs.release
|
||||
}
|
||||
release {
|
||||
minifyEnabled false
|
||||
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
|
||||
signingConfig signingConfigs.release
|
||||
}
|
||||
}
|
||||
compileOptions {
|
||||
@@ -30,6 +36,59 @@ android {
|
||||
buildFeatures {
|
||||
viewBinding true
|
||||
}
|
||||
|
||||
// sign the application
|
||||
signingConfigs {
|
||||
release {
|
||||
storeFile file('..\\sinclass.jks')
|
||||
storePassword '=efX!O4i'
|
||||
keyAlias 'ScreenClient'
|
||||
keyPassword '=efX!O4i'
|
||||
|
||||
v1SigningEnabled true
|
||||
v2SigningEnabled true
|
||||
}
|
||||
}
|
||||
|
||||
android.applicationVariants.all { variant ->
|
||||
def docDir = rootProject.getRootDir().getAbsolutePath() + "/../apk/dashboard"
|
||||
def releaseDir = rootProject.getRootDir().getAbsolutePath() + "/../apk/dashboard"
|
||||
if (versionName.contains("beta"))
|
||||
releaseDir += "/beta"
|
||||
|
||||
variant.outputs.all {
|
||||
// 常规版本不加后缀
|
||||
outputFileName = "dashboard_${defaultConfig.versionName}.apk"
|
||||
}
|
||||
|
||||
// assemble 结束后,将apk复制到指定目录
|
||||
variant.assembleProvider.get().doLast {
|
||||
variant.outputs.all {
|
||||
if (variant.buildType.name == 'release') {
|
||||
copy {
|
||||
from "${project.getProjectDir().path}/build/outputs/apk/${variant.buildType.name}/${outputFileName}"
|
||||
into releaseDir
|
||||
}
|
||||
|
||||
def downloadUrl = "http://thinkdisk.thinkbo.cn/src/web/dashboard/${outputFileName}"
|
||||
genUpdateJson(downloadUrl, releaseDir, outputFileName, 'changelog.md', defaultConfig, variant)
|
||||
|
||||
File file = new File("${project.getProjectDir().path}/changelog.md")
|
||||
replaceText(file, 'VERSION_CODE', "${defaultConfig.versionCode}")
|
||||
|
||||
// 用 pandoc 将 changelog.md 导出为 html 格式
|
||||
exec {
|
||||
workingDir project.getProjectDir().getAbsolutePath()
|
||||
commandLine 'pandoc', '--standalone', '--embed-resources',
|
||||
'--css', rootProject.getRootDir().getAbsolutePath() + '/doc/themes/blue/blue.css',
|
||||
'changelog.md', '-f',
|
||||
'markdown', '-t', 'html', '-s',
|
||||
'-o', "${docDir}/changelog.html"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
repositories {
|
||||
|
||||
19
app_dashboard/changelog.md
Normal file
19
app_dashboard/changelog.md
Normal file
@@ -0,0 +1,19 @@
|
||||
---
|
||||
title: "看板APP更新日志和文件下载"
|
||||
author:
|
||||
- 宁波升维信息技术有限公司
|
||||
---
|
||||
|
||||
<!--
|
||||
1. 更新记录 文字不可变,且前一行需为空行
|
||||
2. $ {VERSION_CODE} (去掉空格),会自动替换实际修订号,比如 1.1.4.$ {VERSION_CODE}
|
||||
-->
|
||||
|
||||
### [1.0.0.${VERSION_CODE}] - 2025.9.12
|
||||
|
||||
#### 文件下载
|
||||
|
||||
* [dashboard_1.0.0.apk](dashboard_1.0.0.apk)
|
||||
|
||||
#### 更新记录
|
||||
* 初版
|
||||
@@ -2,6 +2,8 @@
|
||||
<manifest xmlns:android="http://schemas.android.com/apk/res/android">
|
||||
|
||||
<uses-permission android:name="android.permission.INTERNET" />
|
||||
<uses-permission android:name="android.permission.SCHEDULE_EXACT_ALARM" />
|
||||
<uses-permission android:name="android.permission.USE_EXACT_ALARM" />
|
||||
|
||||
<application
|
||||
android:allowBackup="true"
|
||||
@@ -46,7 +48,11 @@
|
||||
<receiver
|
||||
android:name=".receiver.CommandBroadcastReceiver"
|
||||
android:enabled="true"
|
||||
android:exported="false" />
|
||||
android:exported="false" >
|
||||
<intent-filter>
|
||||
<action android:name="cn.ykbox.dashboard.ACTION_SEND_COMMAND" />
|
||||
</intent-filter>
|
||||
</receiver>
|
||||
</application>
|
||||
|
||||
</manifest>
|
||||
@@ -5,6 +5,7 @@ import android.app.PendingIntent;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.content.SharedPreferences;
|
||||
import android.os.Build;
|
||||
import android.os.Bundle;
|
||||
import android.os.Handler;
|
||||
import android.os.Looper;
|
||||
@@ -12,6 +13,11 @@ import android.text.TextUtils;
|
||||
import android.util.Log;
|
||||
import android.view.MotionEvent;
|
||||
import android.view.View;
|
||||
import android.webkit.WebResourceError;
|
||||
import android.webkit.WebResourceRequest;
|
||||
import android.webkit.WebResourceResponse;
|
||||
import android.webkit.WebSettings;
|
||||
import android.webkit.WebView;
|
||||
import android.webkit.WebViewClient;
|
||||
import android.widget.Toast;
|
||||
|
||||
@@ -36,8 +42,13 @@ public class BuildingDashboardActivity extends FullscreenActivity {
|
||||
private static final long CONFIG_LOAD_INTERVAL = 10 * 60 * 1000; // 10 minutes
|
||||
private static final int MAX_COMMAND_ALARMS = 20; // 支持的最大闹钟指令数量
|
||||
|
||||
private Context mContext;
|
||||
private String mainUrl;
|
||||
private int retryCount = 0;
|
||||
private static final int MAX_RETRY = 99; // 最大重试次数
|
||||
private static final int RETRY_DELAY = 60000; // 1分钟 = 60000毫秒
|
||||
private String configUrl;
|
||||
|
||||
private ConfigReader configReader;
|
||||
private String lastAppliedSerialConfig = null;
|
||||
|
||||
@@ -88,9 +99,34 @@ public class BuildingDashboardActivity extends FullscreenActivity {
|
||||
configUrl = url + "/data/config.json";
|
||||
|
||||
configLoadHandler.post(configLoadRunnable);
|
||||
loadUrlWithRetry();
|
||||
}
|
||||
|
||||
private void loadUrlWithRetry() {
|
||||
binding.webview.loadUrl(mainUrl);
|
||||
}
|
||||
|
||||
private void handleLoadError() {
|
||||
if (retryCount < MAX_RETRY) {
|
||||
retryCount++;
|
||||
Log.d("WebView", "加载失败,将在1分钟后重试 (第" + retryCount + "次重试)");
|
||||
|
||||
// 使用Handler延迟执行重试
|
||||
configLoadHandler.postDelayed(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
Log.d("WebView", "开始重试加载...");
|
||||
loadUrlWithRetry();
|
||||
}
|
||||
}, RETRY_DELAY);
|
||||
|
||||
} else {
|
||||
Log.e("WebView", "重试次数已达上限,加载失败");
|
||||
// 这里可以显示错误页面或提示用户
|
||||
showToast("网页加载失败,请检查网络连接");
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onPause() {
|
||||
super.onPause();
|
||||
@@ -117,8 +153,45 @@ public class BuildingDashboardActivity extends FullscreenActivity {
|
||||
}
|
||||
|
||||
private void initWebView() {
|
||||
binding.webview.getSettings().setJavaScriptEnabled(true);
|
||||
binding.webview.setWebViewClient(new WebViewClient());
|
||||
WebSettings webSettings = binding.webview.getSettings();
|
||||
webSettings.setCacheMode(WebSettings.LOAD_NO_CACHE);
|
||||
webSettings.setJavaScriptEnabled(true);
|
||||
|
||||
binding.webview.setWebViewClient(new WebViewClient() {
|
||||
@Override
|
||||
public void onReceivedError(WebView view, WebResourceRequest request,
|
||||
WebResourceError error) {
|
||||
super.onReceivedError(view, request, error);
|
||||
|
||||
// 只处理主页面的错误,不处理资源文件错误
|
||||
if (request.getUrl().toString().equals(mainUrl)) {
|
||||
handleLoadError();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onReceivedHttpError(WebView view, WebResourceRequest request,
|
||||
WebResourceResponse errorResponse) {
|
||||
super.onReceivedHttpError(view, request, errorResponse);
|
||||
|
||||
// 处理HTTP错误(如404, 500等)
|
||||
if (request.getUrl().toString().equals(mainUrl)) {
|
||||
handleLoadError();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onPageFinished(WebView view, String url) {
|
||||
super.onPageFinished(view, url);
|
||||
|
||||
// 页面加载成功,重置重试计数
|
||||
if (url.equals(mainUrl)) {
|
||||
retryCount = 0;
|
||||
Log.d("WebView", "页面加载成功: " + url);
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
private void initConfigLoader() {
|
||||
@@ -209,8 +282,19 @@ public class BuildingDashboardActivity extends FullscreenActivity {
|
||||
calendar.add(Calendar.DAY_OF_YEAR, 1);
|
||||
}
|
||||
|
||||
alarmManager.setRepeating(AlarmManager.RTC_WAKEUP, calendar.getTimeInMillis(), AlarmManager.INTERVAL_DAY, pendingIntent);
|
||||
Log.d(TAG, "Set repeating alarm for " + time + " with command " + hex + " on port " + portPath + " at " + baudRate + " baud");
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
|
||||
alarmManager.setExactAndAllowWhileIdle(AlarmManager.RTC_WAKEUP, calendar.getTimeInMillis(), pendingIntent);
|
||||
Log.d(TAG, "setExactAndAllowWhileIdle, Set repeating alarm for " + time + " with command " + hex + " on port " + portPath + " at " + baudRate + " baud");
|
||||
} else if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
|
||||
alarmManager.setExact(AlarmManager.RTC_WAKEUP, calendar.getTimeInMillis(), pendingIntent);
|
||||
Log.d(TAG, "setExact, Set repeating alarm for " + time + " with command " + hex + " on port " + portPath + " at " + baudRate + " baud");
|
||||
} else {
|
||||
alarmManager.set(AlarmManager.RTC_WAKEUP, calendar.getTimeInMillis(), pendingIntent);
|
||||
Log.d(TAG, "Set repeating alarm for " + time + " with command " + hex + " on port " + portPath + " at " + baudRate + " baud");
|
||||
}
|
||||
|
||||
// alarmManager.setRepeating(AlarmManager.RTC_WAKEUP, calendar.getTimeInMillis(), AlarmManager.INTERVAL_DAY, pendingIntent);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -228,6 +312,8 @@ public class BuildingDashboardActivity extends FullscreenActivity {
|
||||
}
|
||||
|
||||
private void showToast(String message) {
|
||||
Toast.makeText(this, message, Toast.LENGTH_SHORT).show();
|
||||
runOnUiThread(() -> Toast.makeText(mContext,
|
||||
message,
|
||||
Toast.LENGTH_SHORT).show());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -19,7 +19,6 @@ public class CommandBroadcastReceiver extends BroadcastReceiver {
|
||||
if (intent != null && ACTION_SEND_COMMAND.equals(intent.getAction())) {
|
||||
String hexCommand = intent.getStringExtra(EXTRA_COMMAND_HEX);
|
||||
String portPath = intent.getStringExtra(EXTRA_PORT_PATH);
|
||||
// 新增:从 Intent 中获取波特率,如果不存在则默认为 9600
|
||||
int baudRate = intent.getIntExtra(EXTRA_BAUD_RATE, 9600);
|
||||
|
||||
if (hexCommand != null && !hexCommand.isEmpty() && portPath != null && !portPath.isEmpty()) {
|
||||
|
||||
@@ -38,12 +38,6 @@
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="设置" />
|
||||
<Button
|
||||
android:id="@+id/power_off_tv_button"
|
||||
style="?android:attr/buttonBarButtonStyle"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="关电视" />
|
||||
</LinearLayout>
|
||||
</FrameLayout>
|
||||
|
||||
|
||||
Reference in New Issue
Block a user