Skip to content
Toggle navigation
P
Projects
G
Groups
S
Snippets
Help
huangzhicong
/
SmartCanteen
This project
Loading...
Sign in
Toggle navigation
Go to a project
Project
Repository
Issues
0
Merge Requests
0
Pipelines
Wiki
Snippets
Members
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Commit
5d29ef61
authored
Jun 08, 2020
by
pye52
Browse files
Options
Browse Files
Download
Plain Diff
Merge branch 'develop'
parents
940f60d9
30b4d247
Hide whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
136 additions
and
17 deletions
+136
-17
app/build.gradle
+2
-2
app/src/main/java/com/bgycc/smartcanteen/activity/MainActivity.java
+33
-8
app/src/main/java/com/bgycc/smartcanteen/command/CommandHelper.java
+6
-0
app/src/main/java/com/bgycc/smartcanteen/entity/CommandNotice.java
+89
-0
app/src/main/java/com/bgycc/smartcanteen/utils/MonitorUtils.java
+5
-3
app/src/main/res/layout/activity_main.xml
+0
-1
app/src/main/res/values/strings.xml
+1
-3
No files found.
app/build.gradle
View file @
5d29ef61
...
...
@@ -7,8 +7,8 @@ android {
applicationId
"com.bgycc.smartcanteen"
minSdkVersion
22
targetSdkVersion
29
versionCode
1
7
versionName
"1.
3.7
"
versionCode
1
40
versionName
"1.
4.0
"
testInstrumentationRunner
"androidx.test.runner.AndroidJUnitRunner"
ndk
{
abiFilters
"armeabi"
,
"armeabi-v7a"
,
"x86"
,
"mips"
...
...
app/src/main/java/com/bgycc/smartcanteen/activity/MainActivity.java
View file @
5d29ef61
...
...
@@ -15,6 +15,7 @@ import android.content.Context;
import
android.content.pm.PackageInfo
;
import
android.content.pm.PackageManager
;
import
android.media.AudioManager
;
import
android.os.Process
;
import
android.os.Bundle
;
import
android.os.Handler
;
import
android.text.TextUtils
;
...
...
@@ -34,6 +35,7 @@ import com.bgycc.smartcanteen.Injection;
import
com.bgycc.smartcanteen.R
;
import
com.bgycc.smartcanteen.command.CommandHelper
;
import
com.bgycc.smartcanteen.entity.Command
;
import
com.bgycc.smartcanteen.entity.CommandNotice
;
import
com.bgycc.smartcanteen.entity.PayData
;
import
com.bgycc.smartcanteen.executor.SCTaskExecutor
;
import
com.bgycc.smartcanteen.socket.SCWebSocketClient
;
...
...
@@ -51,13 +53,14 @@ import com.bgycc.smartcanteen.viewModel.PayOnlineViewModel;
import
com.bgycc.smartcanteen.viewModel.QRCodeViewModel
;
import
com.bgycc.smartcanteen.viewModel.ViewModelFactory
;
import
com.blankj.utilcode.util.LogUtils
;
import
com.google.gson.Gson
;
import
java.net.URI
;
import
java.net.URISyntaxException
;
import
java.text.SimpleDateFormat
;
import
java.util.Date
;
import
java.util.Locale
;
import
static
android
.
os
.
Process
.
myPid
;
import
static
com
.
bgycc
.
smartcanteen
.
utils
.
SmartCanteenUtils
.
TAG
;
@SuppressWarnings
(
"all"
)
...
...
@@ -86,6 +89,8 @@ public class MainActivity extends AppCompatActivity implements View.OnClickListe
private
TextView
message
;
private
AudioManager
audioManager
;
private
Gson
gson
;
private
String
idle_notice
;
private
WorkManager
workManager
;
private
Handler
handler
=
new
Handler
();
private
SimpleDateFormat
payDateFormat
=
new
SimpleDateFormat
(
"HH:mm:ss.SSS"
,
Locale
.
getDefault
());
...
...
@@ -103,9 +108,10 @@ public class MainActivity extends AppCompatActivity implements View.OnClickListe
}
String
host
=
SmartCanteenUtils
.
getMainWebSocketServerUrl
(
deviceSN
,
BuildConfig
.
VERSION_NAME
);
LogUtils
.
d
(
TAG
,
"服务器地址: "
+
host
);
gson
=
Injection
.
provideGson
();
try
{
URI
uri
=
new
URI
(
host
);
SCWebSocketClient
.
init
(
uri
,
deviceSN
,
Injection
.
provideGson
()
);
SCWebSocketClient
.
init
(
uri
,
deviceSN
,
gson
);
}
catch
(
URISyntaxException
e
)
{
LogUtils
.
e
(
TAG
,
"服务器地址异常: "
+
e
.
getMessage
(),
e
);
}
...
...
@@ -138,12 +144,12 @@ public class MainActivity extends AppCompatActivity implements View.OnClickListe
switch
(
event
.
getState
())
{
case
PayOnlineState
.
IDLE
:
message
.
setTextColor
(
getResources
().
getColor
(
R
.
color
.
qrcode_normal
));
message
.
setText
(
R
.
string
.
pay_idl
e
);
message
.
setText
(
idle_notic
e
);
break
;
case
PayOnlineState
.
SEND
:
message
.
setTextColor
(
getResources
().
getColor
(
R
.
color
.
pay_idle
));
message
.
setText
(
R
.
string
.
pay_wait
);
String
time
=
payDateFormat
.
format
(
new
Date
());
String
time
=
payDateFormat
.
format
(
System
.
currentTimeMillis
());
String
log
=
"支付进度: "
+
time
+
" - "
+
event
.
getMessage
();
LogUtils
.
file
(
TAG
,
log
);
...
...
@@ -182,7 +188,7 @@ public class MainActivity extends AppCompatActivity implements View.OnClickListe
switch
(
event
.
getState
())
{
case
QRCodeState
.
IDLE
:
message
.
setTextColor
(
getResources
().
getColor
(
R
.
color
.
qrcode_normal
));
message
.
setText
(
R
.
string
.
pay_idl
e
);
message
.
setText
(
idle_notic
e
);
break
;
case
QRCodeState
.
SCANNING
:
message
.
setTextColor
(
getResources
().
getColor
(
R
.
color
.
qrcode_normal
));
...
...
@@ -243,6 +249,17 @@ public class MainActivity extends AppCompatActivity implements View.OnClickListe
commandViewModel
.
commandFinish
(
command
);
return
;
}
// 修改主界面的提示语
if
(
CommandHelper
.
changedPaymentNotice
(
command
))
{
try
{
CommandNotice
commandNotice
=
gson
.
fromJson
(
command
.
getData
(),
CommandNotice
.
class
);
idle_notice
=
commandNotice
.
getData
().
getNotice
();
message
.
setText
(
idle_notice
);
}
finally
{
commandViewModel
.
commandFinish
(
command
);
}
return
;
}
// 检查当前是否有在执行的任务
if
(
runningCommand
!=
null
)
{
// 若已经有在执行的任务,则跳过该次响应
...
...
@@ -329,10 +346,12 @@ public class MainActivity extends AppCompatActivity implements View.OnClickListe
SCWebSocketClient
.
getInstance
().
tryConnect
();
}
// 检查debug layout是否已初始化
private
boolean
debugLayoutIsNotInflate
()
{
return
debugVs
!=
null
;
}
// 主界面显示模式切换: Debug <==> Release
private
void
toggleDebugLayout
()
{
if
(
debugLayoutIsNotInflate
())
{
inflateDebugLayout
();
...
...
@@ -366,7 +385,7 @@ public class MainActivity extends AppCompatActivity implements View.OnClickListe
TTSHelper
.
speak
(
successMessage
);
qrCodeViewModel
.
scan
();
String
successTime
=
payDateFormat
.
format
(
new
Date
());
String
successTime
=
payDateFormat
.
format
(
System
.
currentTimeMillis
());
String
successLog
=
"支付成功: "
+
successTime
+
" - "
+
successMessage
;
LogUtils
.
file
(
TAG
,
successLog
);
...
...
@@ -384,7 +403,7 @@ public class MainActivity extends AppCompatActivity implements View.OnClickListe
TTSHelper
.
speak
(
failedMessage
);
qrCodeViewModel
.
scan
();
String
failedTime
=
payDateFormat
.
format
(
new
Date
());
String
failedTime
=
payDateFormat
.
format
(
System
.
currentTimeMillis
());
String
failedLog
=
"支付失败: "
+
failedTime
+
" - "
+
failedMessage
;
LogUtils
.
file
(
TAG
,
failedLog
);
...
...
@@ -400,6 +419,8 @@ public class MainActivity extends AppCompatActivity implements View.OnClickListe
SCWebSocketClient
.
getInstance
().
realClose
();
SCTaskExecutor
.
getInstance
().
quit
();
MonitorUtils
.
stopMonitors
(
this
);
LogUtils
.
d
(
TAG
,
"MainActivity onDestroy,退出应用"
);
Process
.
killProcess
(
myPid
());
}
private
void
initViews
()
{
...
...
@@ -411,6 +432,10 @@ public class MainActivity extends AppCompatActivity implements View.OnClickListe
settingText
=
findViewById
(
R
.
id
.
_setting_msg
);
message
=
findViewById
(
R
.
id
.
_message
);
// 设置默认指示语
idle_notice
=
getString
(
R
.
string
.
default_message
);
message
.
setText
(
idle_notice
);
settingLayout
.
setAlpha
(
0
);
settingImg
.
post
(()
->
{
Animation
anim
=
new
RotateAnimation
(
0
f
,
360
f
,
0.5f
*
settingImg
.
getWidth
(),
0.5f
*
settingImg
.
getHeight
());
...
...
@@ -511,7 +536,7 @@ public class MainActivity extends AppCompatActivity implements View.OnClickListe
private
Runnable
updateTimeRunnable
=
new
Runnable
()
{
@Override
public
void
run
()
{
socketConnectedTime
.
setText
(
socketConnectedTimeDateFormat
.
format
(
new
Date
()));
socketConnectedTime
.
setText
(
socketConnectedTimeDateFormat
.
format
(
System
.
currentTimeMillis
()));
handler
.
postDelayed
(
this
,
1000
);
}
};
...
...
app/src/main/java/com/bgycc/smartcanteen/command/CommandHelper.java
View file @
5d29ef61
...
...
@@ -18,6 +18,7 @@ public class CommandHelper {
private
static
final
String
CONFIG_WIFI
=
"CONFIG_WIFI"
;
private
static
final
String
CONFIG_LOG
=
"CONFIG_LOG"
;
private
static
final
String
EXEC_SHELL
=
"EXEC_SHELL"
;
private
static
final
String
PAYMENT_CHANGED
=
"PAYMENT_CHANGED"
;
// 设备指令白名单
private
static
final
Set
<
String
>
COMMAND_WHITELIST
=
new
HashSet
<
String
>()
{
...
...
@@ -27,6 +28,7 @@ public class CommandHelper {
add
(
CONFIG_WIFI
);
add
(
CONFIG_LOG
);
add
(
EXEC_SHELL
);
add
(
PAYMENT_CHANGED
);
}
};
...
...
@@ -38,6 +40,10 @@ public class CommandHelper {
return
command
.
getAction
().
equals
(
CONFIG_LOG
);
}
public
static
boolean
changedPaymentNotice
(
Command
command
)
{
return
command
.
getAction
().
equals
(
PAYMENT_CHANGED
);
}
/**
* 根据action检查是否为指令类型
*/
...
...
app/src/main/java/com/bgycc/smartcanteen/entity/CommandNotice.java
0 → 100644
View file @
5d29ef61
package
com
.
bgycc
.
smartcanteen
.
entity
;
import
java.util.Objects
;
public
class
CommandNotice
{
private
String
action
;
private
CommandNoticeData
data
;
public
String
getAction
()
{
return
action
;
}
public
void
setAction
(
String
action
)
{
this
.
action
=
action
;
}
public
CommandNoticeData
getData
()
{
return
data
;
}
public
void
setData
(
CommandNoticeData
data
)
{
this
.
data
=
data
;
}
@Override
public
boolean
equals
(
Object
o
)
{
if
(
this
==
o
)
return
true
;
if
(
o
==
null
||
getClass
()
!=
o
.
getClass
())
return
false
;
CommandNotice
that
=
(
CommandNotice
)
o
;
return
Objects
.
equals
(
action
,
that
.
action
)
&&
Objects
.
equals
(
data
,
that
.
data
);
}
@Override
public
int
hashCode
()
{
return
Objects
.
hash
(
action
,
data
);
}
@Override
public
String
toString
()
{
return
"CommandNotice{"
+
"action='"
+
action
+
'\''
+
", data="
+
data
+
'}'
;
}
public
static
class
CommandNoticeData
{
private
int
payment
;
private
String
notice
;
public
int
getPayment
()
{
return
payment
;
}
public
void
setPayment
(
int
payment
)
{
this
.
payment
=
payment
;
}
public
String
getNotice
()
{
return
notice
;
}
public
void
setNotice
(
String
notice
)
{
this
.
notice
=
notice
;
}
@Override
public
boolean
equals
(
Object
o
)
{
if
(
this
==
o
)
return
true
;
if
(
o
==
null
||
getClass
()
!=
o
.
getClass
())
return
false
;
CommandNoticeData
that
=
(
CommandNoticeData
)
o
;
return
payment
==
that
.
payment
&&
Objects
.
equals
(
notice
,
that
.
notice
);
}
@Override
public
int
hashCode
()
{
return
Objects
.
hash
(
payment
,
notice
);
}
@Override
public
String
toString
()
{
return
"CommandNoticeData{"
+
"payment="
+
payment
+
", notice='"
+
notice
+
'\''
+
'}'
;
}
}
}
app/src/main/java/com/bgycc/smartcanteen/utils/MonitorUtils.java
View file @
5d29ef61
...
...
@@ -26,17 +26,19 @@ public class MonitorUtils {
private
static
final
int
LOG_REPEAT_INTERVAL
=
4
;
private
static
final
int
DATABASE_REPEAT_INTERVAL
=
12
;
// 每天早上指定时间重启设备
private
static
final
int
REBOOT_HOUR_OF_DAY
=
3
;
private
static
final
int
REBOOT_MIN
=
0
;
private
static
final
int
REBOOT_HOUR_OF_DAY
=
0
;
private
static
final
int
REBOOT_MIN
_OF_HOUR
=
1
;
public
static
void
startMonitors
(
Context
context
)
{
startLogFilesMonitor
(
context
);
startDatabaseMonitor
(
context
);
startRebootMonitor
(
context
);
}
public
static
void
stopMonitors
(
Context
context
)
{
stopLogFilesMonitor
(
context
);
stopDatabaseMonitor
(
context
);
stopRebootMonitor
(
context
);
}
// 指定时间重启设备
...
...
@@ -46,7 +48,7 @@ public class MonitorUtils {
Calendar
future
=
Calendar
.
getInstance
(
Locale
.
getDefault
());
future
.
add
(
Calendar
.
DAY_OF_YEAR
,
1
);
future
.
set
(
Calendar
.
HOUR_OF_DAY
,
REBOOT_HOUR_OF_DAY
);
future
.
set
(
Calendar
.
MINUTE
,
REBOOT_MIN
);
future
.
set
(
Calendar
.
MINUTE
,
REBOOT_MIN
_OF_HOUR
);
future
.
set
(
Calendar
.
SECOND
,
0
);
long
delay
=
future
.
getTimeInMillis
()
-
now
.
getTimeInMillis
();
LogUtils
.
d
(
TAG
,
delay
+
"毫秒后将重启设备"
);
...
...
app/src/main/res/layout/activity_main.xml
View file @
5d29ef61
...
...
@@ -36,7 +36,6 @@
<TextView
android:id=
"@+id/_message"
android:text=
"@string/default_message"
android:textSize=
"70sp"
android:textColor=
"#333"
android:textAlignment=
"center"
...
...
app/src/main/res/values/strings.xml
View file @
5d29ef61
...
...
@@ -12,16 +12,14 @@
<string
name=
"network_type_ethernet"
>
以太网
</string>
<string
name=
"network_type_wifi"
>
Wifi
</string>
<string
name=
"network_type_unknown"
>
未知
</string>
<string
name=
"default_message"
>
请出示付款码
</string>
<string
name=
"default_message"
>
获取后台配置
</string>
<string
name=
"qrcode_failed"
>
请出示付款码
</string>
<string
name=
"qrcode_scanning"
>
正在扫描…
</string>
<string
name=
"beep"
>
beep
</string>
<string
name=
"scan_repeat"
>
请勿重复扫码
</string>
<string
name=
"invalidate_qrcode"
>
无效二维码
</string>
<string
name=
"pay_idle"
>
请出示付款码
</string>
<string
name=
"pay_wait"
>
交易处理中
</string>
<string
name=
"pay_success"
>
支付成功
</string>
<string
name=
"pay_failed"
>
支付失败
</string>
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment