This commit is contained in:
Zhanghu
2025-09-12 14:23:33 +08:00
parent 36a7cfa3ad
commit 142134c342
9 changed files with 384 additions and 20 deletions

View File

@@ -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 {

View 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)
#### 更新记录
* 初版

View File

@@ -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>

View File

@@ -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());
}
}

View File

@@ -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()) {

View File

@@ -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>

View File

@@ -25,7 +25,7 @@ ext {
return new Date().format("yyyy-MM-dd", TimeZone.getTimeZone("UTC"))
}
genUpdateJson = { downloadUrl, releaseDir, apkFileName, defaultConfig, variant ->
genUpdateJson = { downloadUrl, releaseDir, apkFileName, logfile, defaultConfig, variant ->
// 生成 update.json 文件,用于自动更新
def releaseTime = releaseTime()
def txtFile = new File(releaseDir, "update.json")
@@ -33,14 +33,15 @@ ext {
def fileMd5 = ""
// 读取 changelog并提取最新版本的日志
def changeLogFile = new File(project.getProjectDir().path, "changelog.md")
def changeLogFile = new File(project.getProjectDir().path, logfile)
def text = changeLogFile.text
def marker = "### 更新记录"
def marker = "#### 更新记录"
def startIndex = text.indexOf(marker)
if (startIndex != -1) {
// 找到标记后,找到下一个空行
def endIndex = text.indexOf('\r\n\r\n', startIndex)
def endIndex = text.indexOf('### [', startIndex)
if(endIndex == -1)
endIndex = text.length() - 1
@@ -48,7 +49,10 @@ ext {
// 截取内容并存储到变量B
def content = text.substring(startIndex + marker.length(), endIndex)
changeLog = content.trim()
changeLog = changeLog.replaceAll("\r\n", "\\\\n")
changeLog = changeLog
.replaceAll("\r\n", "\\\\n") // 处理 Windows 换行
.replaceAll("\n", "\\\\n") // 处理 Linux/macOS 换行
.replaceAll("\r", "\\\\n") // 处理旧版 macOS 换行
}
}
@@ -74,6 +78,13 @@ ext {
" \"downloadUrl\": \"${downloadUrl}\"\n" +
"}"
}
replaceText = {File file, String key, String value ->
def fileText = file.text
def regex = '\\$\\{' + key + '\\}'
fileText = (fileText =~ /${regex}/).replaceAll(value)
file.write(fileText)
}
}
// 自定义任务

185
gradlew vendored Normal file → Executable file
View File

@@ -0,0 +1,185 @@
#!/usr/bin/env sh
#
# Copyright 2015 the original author or authors.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# https://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
##############################################################################
##
## Gradle start up script for UN*X
##
##############################################################################
# Attempt to set APP_HOME
# Resolve links: $0 may be a link
PRG="$0"
# Need this for relative symlinks.
while [ -h "$PRG" ] ; do
ls=`ls -ld "$PRG"`
link=`expr "$ls" : '.*-> \(.*\)$'`
if expr "$link" : '/.*' > /dev/null; then
PRG="$link"
else
PRG=`dirname "$PRG"`"/$link"
fi
done
SAVED="`pwd`"
cd "`dirname \"$PRG\"`/" >/dev/null
APP_HOME="`pwd -P`"
cd "$SAVED" >/dev/null
APP_NAME="Gradle"
APP_BASE_NAME=`basename "$0"`
# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"'
# Use the maximum available, or set MAX_FD != -1 to use that value.
MAX_FD="maximum"
warn () {
echo "$*"
}
die () {
echo
echo "$*"
echo
exit 1
}
# OS specific support (must be 'true' or 'false').
cygwin=false
msys=false
darwin=false
nonstop=false
case "`uname`" in
CYGWIN* )
cygwin=true
;;
Darwin* )
darwin=true
;;
MINGW* )
msys=true
;;
NONSTOP* )
nonstop=true
;;
esac
CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar
# Determine the Java command to use to start the JVM.
if [ -n "$JAVA_HOME" ] ; then
if [ -x "$JAVA_HOME/jre/sh/java" ] ; then
# IBM's JDK on AIX uses strange locations for the executables
JAVACMD="$JAVA_HOME/jre/sh/java"
else
JAVACMD="$JAVA_HOME/bin/java"
fi
if [ ! -x "$JAVACMD" ] ; then
die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME
Please set the JAVA_HOME variable in your environment to match the
location of your Java installation."
fi
else
JAVACMD="java"
which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
Please set the JAVA_HOME variable in your environment to match the
location of your Java installation."
fi
# Increase the maximum file descriptors if we can.
if [ "$cygwin" = "false" -a "$darwin" = "false" -a "$nonstop" = "false" ] ; then
MAX_FD_LIMIT=`ulimit -H -n`
if [ $? -eq 0 ] ; then
if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then
MAX_FD="$MAX_FD_LIMIT"
fi
ulimit -n $MAX_FD
if [ $? -ne 0 ] ; then
warn "Could not set maximum file descriptor limit: $MAX_FD"
fi
else
warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT"
fi
fi
# For Darwin, add options to specify how the application appears in the dock
if $darwin; then
GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\""
fi
# For Cygwin or MSYS, switch paths to Windows format before running java
if [ "$cygwin" = "true" -o "$msys" = "true" ] ; then
APP_HOME=`cygpath --path --mixed "$APP_HOME"`
CLASSPATH=`cygpath --path --mixed "$CLASSPATH"`
JAVACMD=`cygpath --unix "$JAVACMD"`
# We build the pattern for arguments to be converted via cygpath
ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null`
SEP=""
for dir in $ROOTDIRSRAW ; do
ROOTDIRS="$ROOTDIRS$SEP$dir"
SEP="|"
done
OURCYGPATTERN="(^($ROOTDIRS))"
# Add a user-defined pattern to the cygpath arguments
if [ "$GRADLE_CYGPATTERN" != "" ] ; then
OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)"
fi
# Now convert the arguments - kludge to limit ourselves to /bin/sh
i=0
for arg in "$@" ; do
CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -`
CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option
if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition
eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"`
else
eval `echo args$i`="\"$arg\""
fi
i=`expr $i + 1`
done
case $i in
0) set -- ;;
1) set -- "$args0" ;;
2) set -- "$args0" "$args1" ;;
3) set -- "$args0" "$args1" "$args2" ;;
4) set -- "$args0" "$args1" "$args2" "$args3" ;;
5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;;
6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;;
7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;;
8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;;
9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;;
esac
fi
# Escape application args
save () {
for i do printf %s\\n "$i" | sed "s/'/'\\\\''/g;1s/^/'/;\$s/\$/' \\\\/" ; done
echo " "
}
APP_ARGS=`save "$@"`
# Collect all arguments for the java command, following the shell quoting and substitution rules
eval set -- $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS "\"-Dorg.gradle.appname=$APP_BASE_NAME\"" -classpath "\"$CLASSPATH\"" org.gradle.wrapper.GradleWrapperMain "$APP_ARGS"
exec "$JAVACMD" "$@"

5
release.sh Executable file
View File

@@ -0,0 +1,5 @@
#!/usr/bin/env sh
export JAVA_HOME=/opt/android-studio/jbr
./gradlew clean assembleRelease