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
1105f82d
authored
Jun 05, 2020
by
pye52
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
增加根据后台返回的指示语改变界面显示的指令
parent
913ccb4c
Show whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
118 additions
and
7 deletions
+118
-7
app/src/main/java/com/bgycc/smartcanteen/activity/MainActivity.java
+22
-3
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/res/layout/activity_main.xml
+0
-1
app/src/main/res/values/strings.xml
+1
-3
No files found.
app/src/main/java/com/bgycc/smartcanteen/activity/MainActivity.java
View file @
1105f82d
...
...
@@ -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,6 +53,7 @@ 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
;
...
...
@@ -58,6 +61,7 @@ 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 +90,7 @@ public class MainActivity extends AppCompatActivity implements View.OnClickListe
private
TextView
message
;
private
AudioManager
audioManager
;
private
String
idle_notice
;
private
WorkManager
workManager
;
private
Handler
handler
=
new
Handler
();
private
SimpleDateFormat
payDateFormat
=
new
SimpleDateFormat
(
"HH:mm:ss.SSS"
,
Locale
.
getDefault
());
...
...
@@ -138,7 +143,7 @@ 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
));
...
...
@@ -182,7 +187,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 +248,16 @@ public class MainActivity extends AppCompatActivity implements View.OnClickListe
commandViewModel
.
commandFinish
(
command
);
return
;
}
if
(
CommandHelper
.
changedPaymentNotice
(
command
))
{
Gson
gson
=
Injection
.
provideGson
();
try
{
CommandNotice
commandNotice
=
gson
.
fromJson
(
command
.
getData
(),
CommandNotice
.
class
);
idle_notice
=
commandNotice
.
getData
().
getNotice
();
}
finally
{
commandViewModel
.
commandFinish
(
command
);
}
return
;
}
// 检查当前是否有在执行的任务
if
(
runningCommand
!=
null
)
{
// 若已经有在执行的任务,则跳过该次响应
...
...
@@ -401,7 +416,7 @@ public class MainActivity extends AppCompatActivity implements View.OnClickListe
SCTaskExecutor
.
getInstance
().
quit
();
MonitorUtils
.
stopMonitors
(
this
);
LogUtils
.
d
(
TAG
,
"MainActivity onDestroy,退出应用"
);
android
.
os
.
Process
.
killProcess
(
android
.
os
.
Process
.
myPid
());
Process
.
killProcess
(
myPid
());
}
private
void
initViews
()
{
...
...
@@ -413,6 +428,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
());
...
...
app/src/main/java/com/bgycc/smartcanteen/command/CommandHelper.java
View file @
1105f82d
...
...
@@ -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 @
1105f82d
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/res/layout/activity_main.xml
View file @
1105f82d
...
...
@@ -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 @
1105f82d
...
...
@@ -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