Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
P
peanut-sample
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
刘立
peanut-sample
Commits
25561d28
Commit
25561d28
authored
Nov 26, 2018
by
llxqb
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
优化代码(删除多余引用)
parent
d7e437bc
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
309 additions
and
199 deletions
+309
-199
app/src/main/java/peanut/keenon/com/peanutsample/DinnerActivity.java
+144
-113
app/src/main/res/layout/activity_dinner.xml
+161
-86
app/src/main/res/values/strings.xml
+4
-0
No files found.
app/src/main/java/peanut/keenon/com/peanutsample/DinnerActivity.java
View file @
25561d28
...
...
@@ -7,6 +7,7 @@ import android.media.MediaPlayer;
import
android.os.Bundle
;
import
android.os.Handler
;
import
android.os.Message
;
import
android.util.Log
;
import
android.view.View
;
import
android.view.animation.Animation
;
import
android.view.animation.AnimationUtils
;
...
...
@@ -71,13 +72,17 @@ public class DinnerActivity extends Activity {
private
static
final
int
SCAN_REQUEST_CODE
=
0x400
;
private
static
final
int
FACE_DETECT_REQUEST_CODE
=
0x401
;
/**
* 返回的条形码数字
*/
private
String
mAuthCode
=
null
;
private
String
mOpenId
=
null
;
private
enum
RobotStatus
{
private
enum
RobotStatus
{
NORMAL
,
WALKING
}
//xunfei appid = 5af25aee
private
static
final
String
TAG
=
"ROBOT"
;
...
...
@@ -91,12 +96,12 @@ public class DinnerActivity extends Activity {
private
WorkModeManager
workModeManager
=
null
;
private
ManualControlManager
manualControlManager
=
null
;
private
LinearLayout
robotLayout
=
null
;
private
LinearLayout
robotLayout
=
null
;
private
LinearLayout
.
LayoutParams
robotParams
=
null
;
private
LinearLayout
dinnerLayout
=
null
;
private
LinearLayout
robotPlate
=
null
;
private
LinearLayout
robotPlate
=
null
;
private
Logger
log
=
new
Logger
();
...
...
@@ -118,6 +123,9 @@ public class DinnerActivity extends Activity {
private
int
mCurrentPath
=
0
;
private
int
mCurrentIndex
=
0
;
/**
* 导航目标点集合
*/
private
List
targetData
=
new
ArrayList
();
//XUNFEI VOICE
...
...
@@ -129,7 +137,7 @@ public class DinnerActivity extends Activity {
private
String
voicer
=
"xiaofang"
;
//nannan
private
String
[]
mCloudVoicersEntries
;
private
String
[]
mCloudVoicersValue
;
private
String
[]
mCloudVoicersValue
;
// 缓冲进度
private
int
mPercentForBuffering
=
0
;
...
...
@@ -142,16 +150,16 @@ public class DinnerActivity extends Activity {
private
RobotServiceAction
mAction
=
new
RobotServiceAction
();
//REQ
private
TextView
tvStoreName
=
null
;
private
TextView
tvStoreAddress
=
null
;
private
TextView
tvRobotWorkMode
=
null
;
private
TextView
tvStoreName
=
null
;
private
TextView
tvStoreAddress
=
null
;
private
TextView
tvRobotWorkMode
=
null
;
private
String
mUserToken
=
null
;
private
String
mUserToken
=
null
;
private
Button
btnScan
=
null
;
private
Button
btnScan
=
null
;
private
Context
mContext
=
null
;
private
Button
mPickup
=
null
;
private
Context
mContext
=
null
;
private
Button
mPickup
=
null
;
private
MediaPlayer
mediaPlayer
=
new
MediaPlayer
();
...
...
@@ -161,44 +169,52 @@ public class DinnerActivity extends Activity {
setContentView
(
R
.
layout
.
activity_dinner
);
mContext
=
this
;
log
.
d
(
TAG
,
"autoPilotResume"
);
//initialize robot relative interface
initXunfei
();
initRobot
();
initApp
();
tvStoreName
=
(
TextView
)
findViewById
(
R
.
id
.
store_name
);
tvStoreAddress
=
(
TextView
)
findViewById
(
R
.
id
.
store_address
);
tvRobotWorkMode
=
(
TextView
)
findViewById
(
R
.
id
.
robot_work_mode
);
robotLayout
=
(
LinearLayout
)
findViewById
(
R
.
id
.
robot
);
robotParams
=(
LinearLayout
.
LayoutParams
)
robotLayout
.
getLayoutParams
();
mLoading
=
(
MetroLoadingView
)
findViewById
(
R
.
id
.
loading
);
dinnerLayout
=
(
LinearLayout
)
findViewById
(
R
.
id
.
content
);
robotPlate
=
(
LinearLayout
)
findViewById
(
R
.
id
.
robot_plate
);
mRobot
=
(
ImageView
)
findViewById
(
R
.
id
.
robot_dinner
);
mDinnerStatus
=
(
TextView
)
findViewById
(
R
.
id
.
dinner_status
);
mDinnerStatusValue
=
(
FlickerTextView
)
findViewById
(
R
.
id
.
dinner_status_value
);
rotateAnimation
=
AnimationUtils
.
loadAnimation
(
DinnerActivity
.
this
,
R
.
anim
.
rotate_view
);
rotatePlate
=
AnimationUtils
.
loadAnimation
(
DinnerActivity
.
this
,
R
.
anim
.
rotate_plate
);
tvStoreName
=
findViewById
(
R
.
id
.
store_name
);
tvStoreAddress
=
findViewById
(
R
.
id
.
store_address
);
tvRobotWorkMode
=
findViewById
(
R
.
id
.
robot_work_mode
);
robotLayout
=
findViewById
(
R
.
id
.
robot
);
robotParams
=
(
LinearLayout
.
LayoutParams
)
robotLayout
.
getLayoutParams
();
mLoading
=
findViewById
(
R
.
id
.
loading
);
dinnerLayout
=
findViewById
(
R
.
id
.
content
);
robotPlate
=
findViewById
(
R
.
id
.
robot_plate
);
mRobot
=
findViewById
(
R
.
id
.
robot_dinner
);
mDinnerStatus
=
findViewById
(
R
.
id
.
dinner_status
);
mDinnerStatusValue
=
findViewById
(
R
.
id
.
dinner_status_value
);
rotateAnimation
=
AnimationUtils
.
loadAnimation
(
DinnerActivity
.
this
,
R
.
anim
.
rotate_view
);
rotatePlate
=
AnimationUtils
.
loadAnimation
(
DinnerActivity
.
this
,
R
.
anim
.
rotate_plate
);
if
(
mLoading
.
isAnimating
())
{
mLoading
.
stop
();
}
top
=
(
CheckBox
)
findViewById
(
R
.
id
.
plate_top
);
left
=
(
CheckBox
)
findViewById
(
R
.
id
.
plate_left
);
right
=
(
CheckBox
)
findViewById
(
R
.
id
.
plate_right
);
mTableGroup
=
(
RadioGroupEx
)
findViewById
(
R
.
id
.
tableGroup
);
top
=
findViewById
(
R
.
id
.
plate_top
);
left
=
findViewById
(
R
.
id
.
plate_left
);
right
=
findViewById
(
R
.
id
.
plate_right
);
btnScan
=
(
Button
)
findViewById
(
R
.
id
.
btn_scan
);
mTableGroup
=
findViewById
(
R
.
id
.
tableGroup
);
Button
btnReset
=
findViewById
(
R
.
id
.
btn_reset
);
btnReset
.
setOnClickListener
(
new
View
.
OnClickListener
()
{
@Override
public
void
onClick
(
View
v
)
{
top
.
setChecked
(
false
);
left
.
setChecked
(
false
);
right
.
setChecked
(
false
);
top
.
setText
(
""
);
left
.
setText
(
""
);
right
.
setText
(
""
);
mCurrentPlate
=
null
;
mCurrentIndex
=
0
;
dinnerPath
=
null
;
mTableGroup
.
clearCheck
();
}
});
btnScan
=
findViewById
(
R
.
id
.
btn_scan
);
btnScan
.
setOnClickListener
(
new
View
.
OnClickListener
()
{
@Override
public
void
onClick
(
View
view
)
{
...
...
@@ -212,8 +228,7 @@ public class DinnerActivity extends Activity {
}
});
mGo
=
(
Button
)
findViewById
(
R
.
id
.
btn_go
);
mGo
=
findViewById
(
R
.
id
.
btn_go
);
mGo
.
setOnClickListener
(
new
View
.
OnClickListener
()
{
@Override
public
void
onClick
(
View
view
)
{
...
...
@@ -223,12 +238,11 @@ public class DinnerActivity extends Activity {
}
});
mPickup
=
(
Button
)
findViewById
(
R
.
id
.
btn_pickup
);
mPickup
=
findViewById
(
R
.
id
.
btn_pickup
);
mPickup
.
setOnClickListener
(
new
View
.
OnClickListener
()
{
@Override
public
void
onClick
(
View
view
)
{
mCurrentPath
++;
mCurrentPath
++;
startDispatch
(
mCurrentPath
);
//mDinnerStatusValue.setText("送餐中");
}
...
...
@@ -238,17 +252,32 @@ public class DinnerActivity extends Activity {
@Override
public
void
onCheckedChanged
(
RadioGroup
radioGroup
,
int
i
)
{
int
id
=
radioGroup
.
getCheckedRadioButtonId
();
RadioButton
radio
=
(
RadioButton
)
findViewById
(
id
);
if
(
radio
!=
null
)
{
RadioButton
radio
=
(
RadioButton
)
findViewById
(
id
);
if
(
radio
!=
null
)
{
if
(
mCurrentPlate
==
null
)
{
top
.
setText
(
radio
.
getText
());
left
.
setText
(
radio
.
getText
());
right
.
setText
(
radio
.
getText
());
// top.setText(radio.getText());
// left.setText(radio.getText());
// right.setText(radio.getText());
//
// int target = Integer.valueOf(radio.getTag().toString());
// dinnerPath[0] = target;
// dinnerPath[1] = target;
// dinnerPath[2] = target;
if
(
mCurrentIndex
==
0
)
{
top
.
setText
(
radio
.
getText
());
dinnerPath
[
0
]
=
Integer
.
valueOf
(
radio
.
getTag
().
toString
());
mCurrentIndex
++;
}
else
if
(
mCurrentIndex
==
1
)
{
left
.
setText
(
radio
.
getText
());
dinnerPath
[
1
]
=
Integer
.
valueOf
(
radio
.
getTag
().
toString
());
mCurrentIndex
++;
}
else
if
(
mCurrentIndex
==
2
)
{
right
.
setText
(
radio
.
getText
());
dinnerPath
[
2
]
=
Integer
.
valueOf
(
radio
.
getTag
().
toString
());
mCurrentIndex
++;
}
int
target
=
Integer
.
valueOf
(
radio
.
getTag
().
toString
());
dinnerPath
[
0
]
=
target
;
dinnerPath
[
1
]
=
target
;
dinnerPath
[
2
]
=
target
;
}
else
{
mCurrentPlate
.
setText
(
radio
.
getText
());
int
target
=
Integer
.
valueOf
(
radio
.
getTag
().
toString
());
...
...
@@ -261,13 +290,13 @@ public class DinnerActivity extends Activity {
top
.
setOnCheckedChangeListener
(
new
CompoundButton
.
OnCheckedChangeListener
()
{
@Override
public
void
onCheckedChanged
(
CompoundButton
compoundButton
,
boolean
checked
)
{
if
(
checked
)
{
if
(
checked
)
{
mCurrentPlate
=
(
CheckBox
)
compoundButton
;
mCurrentIndex
=
0
;
left
.
setChecked
(
false
);
right
.
setChecked
(
false
);
}
else
{
if
(
mCurrentPlate
==
compoundButton
)
{
}
else
{
if
(
mCurrentPlate
==
compoundButton
)
{
mCurrentPlate
=
null
;
}
}
...
...
@@ -277,13 +306,13 @@ public class DinnerActivity extends Activity {
left
.
setOnCheckedChangeListener
(
new
CompoundButton
.
OnCheckedChangeListener
()
{
@Override
public
void
onCheckedChanged
(
CompoundButton
compoundButton
,
boolean
checked
)
{
if
(
checked
)
{
if
(
checked
)
{
mCurrentPlate
=
(
CheckBox
)
compoundButton
;
mCurrentIndex
=
1
;
top
.
setChecked
(
false
);
right
.
setChecked
(
false
);
}
else
{
if
(
mCurrentPlate
==
compoundButton
)
{
}
else
{
if
(
mCurrentPlate
==
compoundButton
)
{
mCurrentPlate
=
null
;
}
}
...
...
@@ -293,13 +322,13 @@ public class DinnerActivity extends Activity {
right
.
setOnCheckedChangeListener
(
new
CompoundButton
.
OnCheckedChangeListener
()
{
@Override
public
void
onCheckedChanged
(
CompoundButton
compoundButton
,
boolean
checked
)
{
if
(
checked
)
{
if
(
checked
)
{
mCurrentPlate
=
(
CheckBox
)
compoundButton
;
mCurrentIndex
=
2
;
top
.
setChecked
(
false
);
left
.
setChecked
(
false
);
}
else
{
if
(
mCurrentPlate
==
compoundButton
)
{
}
else
{
if
(
mCurrentPlate
==
compoundButton
)
{
mCurrentPlate
=
null
;
}
}
...
...
@@ -317,7 +346,7 @@ public class DinnerActivity extends Activity {
startRobotThread
();
merchant
=
(
ImageView
)
findViewById
(
R
.
id
.
merchantLogo
);
merchant
=
(
ImageView
)
findViewById
(
R
.
id
.
merchantLogo
);
merchant
.
setOnClickListener
(
new
View
.
OnClickListener
()
{
@Override
public
void
onClick
(
View
v
)
{
...
...
@@ -327,15 +356,15 @@ public class DinnerActivity extends Activity {
});
}
private
void
startDispatch
(
int
current
){
private
void
startDispatch
(
int
current
)
{
Message
msg
=
new
Message
();
msg
.
what
=
ROBOT_DISPATCH
;
msg
.
arg1
=
current
;
handler
.
sendMessage
(
msg
);
}
private
void
dispatching
(
int
current
){
if
(
current
<
targetData
.
size
())
{
//仍然有未送达的餐,这里继续进行送餐
private
void
dispatching
(
int
current
)
{
if
(
current
<
targetData
.
size
())
{
//仍然有未送达的餐,这里继续进行送餐
mDinnerStatusValue
.
setText
(
"送餐中"
);
mPickup
.
setVisibility
(
View
.
GONE
);
int
target
=
Integer
.
valueOf
(
targetData
.
get
(
current
).
toString
());
...
...
@@ -345,12 +374,12 @@ public class DinnerActivity extends Activity {
}
else
{
log
.
d
(
TAG
,
"autoPilotToPoint"
+
"("
+
target
+
")"
+
" called"
);
}
}
else
if
(
current
==
targetData
.
size
())
{
//机器人到达全部目标点,准备返回
}
else
if
(
current
==
targetData
.
size
())
{
//机器人到达全部目标点,准备返回
mDinnerStatusValue
.
setText
(
"返回中"
);
mPickup
.
setVisibility
(
View
.
GONE
);
int
ret
=
autoPilotManager
.
autoPilotToPoint
(
1
);
String
orderNumber
=
mAuthCode
;
if
(
mUserToken
!=
null
&&
!
mUserToken
.
isEmpty
())
{
//already login
if
(
mUserToken
!=
null
&&
!
mUserToken
.
isEmpty
())
{
//already login
try
{
mAction
.
setIndex
(
WebApiRequest
.
ORDER_COMPLETED_INDEX
);
mAction
.
orderCompleted
(
mUserToken
,
orderNumber
);
...
...
@@ -358,7 +387,7 @@ public class DinnerActivity extends Activity {
e
.
printStackTrace
();
}
}
}
else
{
//机器人返回到起点
}
else
{
//机器人返回到起点
setRobotStatus
(
RobotStatus
.
NORMAL
);
dinnerPath
[
0
]
=
0
;
dinnerPath
[
1
]
=
0
;
...
...
@@ -366,13 +395,13 @@ public class DinnerActivity extends Activity {
}
}
private
void
startDelivery
(){
if
(
calcPath
()
==
0
)
{
private
void
startDelivery
()
{
if
(
calcPath
()
==
0
)
{
int
code
=
mTts
.
startSpeaking
(
"请先设置送餐桌号"
,
mTtsListener
);
}
else
{
}
else
{
//int code = mTts.startSpeaking("正在送餐", mTtsListener);
String
orderNumber
=
mAuthCode
;
if
(
mUserToken
!=
null
&&
!
mUserToken
.
isEmpty
())
{
//already login
if
(
mUserToken
!=
null
&&
!
mUserToken
.
isEmpty
())
{
//already login
try
{
mAction
.
setIndex
(
WebApiRequest
.
ORDER_DELIVERY_INDEX
);
mAction
.
orderDelivery
(
mUserToken
,
orderNumber
);
...
...
@@ -380,6 +409,7 @@ public class DinnerActivity extends Activity {
e
.
printStackTrace
();
}
setRobotStatus
(
RobotStatus
.
WALKING
);
// Log.e("ddd","targetData:"+targetData.toString());
int
target
=
Integer
.
valueOf
(
targetData
.
get
(
mCurrentPath
).
toString
());
int
ret
=
autoPilotManager
.
autoPilotToPoint
(
target
);
if
(
ret
!=
PeanutErrorCode
.
SUCCESS
)
{
...
...
@@ -391,12 +421,12 @@ public class DinnerActivity extends Activity {
}
}
private
void
initApp
(){
private
void
initApp
()
{
mAction
.
setSucceedListener
(
new
NetworkListener
.
Succeed
<
WebResponse
>()
{
@Override
public
void
onRequestSucceed
(
WebResponse
data
,
int
index
)
{
log
.
d
(
TAG
,
data
.
toString
());
if
(
data
.
statusCode
==
AppConstant
.
ERROR_SUCCESS
)
{
if
(
data
.
statusCode
==
AppConstant
.
ERROR_SUCCESS
)
{
switch
(
index
)
{
case
WebApiRequest
.
USER_LOGIN_INDEX
:
mUserToken
=
data
.
token
;
...
...
@@ -406,13 +436,13 @@ public class DinnerActivity extends Activity {
break
;
case
WebApiRequest
.
ORDER_QUERY_INDEX
:
OrderInfo
info
=
data
.
order
;
if
(
info
!=
null
&&
info
.
tab_num
!=
null
&&
!
info
.
tab_num
.
isEmpty
())
{
if
(
info
!=
null
&&
info
.
tab_num
!=
null
&&
!
info
.
tab_num
.
isEmpty
())
{
RadioButton
radioButton
=
findRadioButtonByTag
(
Integer
.
valueOf
(
info
.
tab_num
));
if
(
radioButton
!=
null
)
{
if
(
radioButton
!=
null
)
{
radioButton
.
performClick
();
mTts
.
startSpeaking
(
radioButton
.
getText
().
toString
(),
mTtsListener
);
}
}
else
{
}
else
{
mTts
.
startSpeaking
(
"桌号为空,请手动选择桌号"
,
mTtsListener
);
}
...
...
@@ -422,7 +452,7 @@ public class DinnerActivity extends Activity {
case
WebApiRequest
.
ORDER_DELIVERY_INDEX
:
break
;
}
}
else
{
}
else
{
switch
(
index
)
{
case
WebApiRequest
.
USER_LOGIN_INDEX
:
mTts
.
startSpeaking
(
"网络异常啦!"
,
mTtsListener
);
...
...
@@ -457,20 +487,20 @@ public class DinnerActivity extends Activity {
mediaPlayer
=
MediaPlayer
.
create
(
this
,
R
.
raw
.
lovin
);
}
private
RadioButton
findRadioButtonByTag
(
int
tag
){
private
RadioButton
findRadioButtonByTag
(
int
tag
)
{
RadioButton
radio
=
null
;
if
(
mTableGroup
!=
null
)
{
for
(
int
i
=
0
;
i
<
mTableGroup
.
getChildCount
();
i
++)
{
RadioButton
rb
=
(
RadioButton
)
mTableGroup
.
getChildAt
(
i
);
if
(
Integer
.
valueOf
(
rb
.
getTag
().
toString
())
==
tag
)
{
if
(
mTableGroup
!=
null
)
{
for
(
int
i
=
0
;
i
<
mTableGroup
.
getChildCount
();
i
++)
{
RadioButton
rb
=
(
RadioButton
)
mTableGroup
.
getChildAt
(
i
);
if
(
Integer
.
valueOf
(
rb
.
getTag
().
toString
())
==
tag
)
{
radio
=
rb
;
break
;
}
}
}
return
radio
;
return
radio
;
}
//设置加载动画
...
...
@@ -495,10 +525,10 @@ public class DinnerActivity extends Activity {
}
//消息处理者,创建一个Handler的子类对象,目的是重写Handler的处理消息的方法(handleMessage())
private
Handler
handler
=
new
Handler
(){
private
Handler
handler
=
new
Handler
()
{
@Override
public
void
handleMessage
(
Message
msg
)
{
switch
(
msg
.
what
){
switch
(
msg
.
what
)
{
case
LOGIN:
try
{
mAction
.
setIndex
(
WebApiRequest
.
USER_LOGIN_INDEX
);
...
...
@@ -522,7 +552,7 @@ public class DinnerActivity extends Activity {
}
};
public
void
startLoginThread
(){
public
void
startLoginThread
()
{
new
Thread
(
new
Runnable
()
{
@Override
public
void
run
()
{
...
...
@@ -536,12 +566,12 @@ public class DinnerActivity extends Activity {
e
.
printStackTrace
();
}
//打印log
log
.
d
(
TAG
,
"start login"
);
log
.
d
(
TAG
,
"start login"
);
}
}).
start
();
}
public
void
startRobotThread
(){
public
void
startRobotThread
()
{
new
Thread
(
new
Runnable
()
{
@Override
public
void
run
()
{
...
...
@@ -555,12 +585,12 @@ public class DinnerActivity extends Activity {
e
.
printStackTrace
();
}
//打印log
log
.
d
(
TAG
,
"start login"
);
log
.
d
(
TAG
,
"start login"
);
}
}).
start
();
}
private
void
initRobot
(){
private
void
initRobot
()
{
sdk
=
PeanutSDK
.
createInstance
(
getApplicationContext
(),
"sdk_type=local"
);
robot
=
sdk
.
getFinder
().
find
();
autoPilotManager
=
robot
.
getAutoPilotManager
();
...
...
@@ -575,7 +605,7 @@ public class DinnerActivity extends Activity {
@Override
public
void
onProcessChanged
(
PeanutPath
peanutPath
)
{
if
(
mediaPlayer
!=
null
)
{
if
(
mediaPlayer
!=
null
)
{
mediaPlayer
.
start
();
}
}
...
...
@@ -583,9 +613,9 @@ public class DinnerActivity extends Activity {
@Override
public
void
onFinished
(
PeanutPath
peanutPath
)
{
int
destination
=
peanutPath
.
getDestinationId
();
if
(
destination
==
ROBOT_START_TARGET
)
{
//机器人到达终点
if
(
destination
==
ROBOT_START_TARGET
)
{
//机器人到达终点
dispatching
(
ROBOT_INITIALIZED
);
}
else
{
}
else
{
int
code
=
mTts
.
startSpeaking
(
"送到啦,请您慢用"
,
mTtsListener
);
mDinnerStatusValue
.
setText
(
"请取餐"
);
mPickup
.
setVisibility
(
View
.
VISIBLE
);
...
...
@@ -594,7 +624,7 @@ public class DinnerActivity extends Activity {
startActivityForResult
(
intent
,
FACE_DETECT_REQUEST_CODE
);
}
if
(
mediaPlayer
!=
null
)
{
if
(
mediaPlayer
!=
null
)
{
mediaPlayer
.
pause
();
}
}
...
...
@@ -602,7 +632,7 @@ public class DinnerActivity extends Activity {
@Override
public
void
onBlocking
(
PeanutPath
peanutPath
)
{
int
code
=
mTts
.
startSpeaking
(
"亲,挡到我啦,人家可是很忙的!"
,
mTtsListener
);
if
(
mediaPlayer
!=
null
)
{
if
(
mediaPlayer
!=
null
)
{
mediaPlayer
.
pause
();
}
}
...
...
@@ -674,7 +704,7 @@ public class DinnerActivity extends Activity {
//workModeManager.changeMode(WorkMode.MODE_AUTO_PILOT);
}
private
void
initXunfei
(){
private
void
initXunfei
()
{
// 初始化合成对象
mTts
=
SpeechSynthesizer
.
createSynthesizer
(
DinnerActivity
.
this
,
mTtsInitListener
);
...
...
@@ -743,13 +773,14 @@ public class DinnerActivity extends Activity {
/**
* 参数设置
*
* @return
*/
private
void
setParam
(){
private
void
setParam
()
{
// 清空参数
mTts
.
setParameter
(
SpeechConstant
.
PARAMS
,
null
);
// 根据合成引擎设置相应参数
if
(
mEngineType
.
equals
(
SpeechConstant
.
TYPE_CLOUD
))
{
if
(
mEngineType
.
equals
(
SpeechConstant
.
TYPE_CLOUD
))
{
mTts
.
setParameter
(
SpeechConstant
.
ENGINE_TYPE
,
SpeechConstant
.
TYPE_CLOUD
);
// 设置在线合成发音人
mTts
.
setParameter
(
SpeechConstant
.
VOICE_NAME
,
voicer
);
...
...
@@ -759,7 +790,7 @@ public class DinnerActivity extends Activity {
mTts
.
setParameter
(
SpeechConstant
.
PITCH
,
"75"
);
//设置合成音量
mTts
.
setParameter
(
SpeechConstant
.
VOLUME
,
"100"
);
}
else
{
}
else
{
mTts
.
setParameter
(
SpeechConstant
.
ENGINE_TYPE
,
SpeechConstant
.
TYPE_LOCAL
);
// 设置本地合成发音人 voicer为空,默认通过语记界面指定发音人。
mTts
.
setParameter
(
SpeechConstant
.
VOICE_NAME
,
""
);
...
...
@@ -779,9 +810,9 @@ public class DinnerActivity extends Activity {
//mTts.setParameter(SpeechConstant.TTS_AUDIO_PATH, Environment.getExternalStorageDirectory()+"/msc/tts.wav");
}
private
void
setRobotStatus
(
RobotStatus
status
){
if
(
status
==
RobotStatus
.
NORMAL
)
{
//普通状态
if
(
mediaPlayer
!=
null
)
{
private
void
setRobotStatus
(
RobotStatus
status
)
{
if
(
status
==
RobotStatus
.
NORMAL
)
{
//普通状态
if
(
mediaPlayer
!=
null
)
{
mediaPlayer
.
pause
();
//mediaPlayer = null;
}
...
...
@@ -812,7 +843,7 @@ public class DinnerActivity extends Activity {
left
.
setText
(
""
);
right
.
setText
(
""
);
}
else
{
//送餐状态
}
else
{
//送餐状态
int
code
=
mTts
.
startSpeaking
(
"出发啦!"
,
mTtsListener
);
robotParams
.
weight
=
0
;
robotLayout
.
setLayoutParams
(
robotParams
);
...
...
@@ -839,28 +870,28 @@ public class DinnerActivity extends Activity {
//mediaPlayer = null;
//mediaPlayer = new MediaPlayer();
//mediaPlayer = MediaPlayer.create(this, R.raw.lovin);
if
(
mediaPlayer
!=
null
)
{
if
(
mediaPlayer
!=
null
)
{
mediaPlayer
.
seekTo
(
0
);
mediaPlayer
.
start
();
//开始播放
}
}
}
private
int
calcPath
(){
private
int
calcPath
()
{
for
(
int
num
:
dinnerPath
)
{
if
((
num
!=
0
)
&&
!
targetData
.
contains
(
num
))
{
targetData
.
add
(
num
);
}
}
return
targetData
.
size
();
return
targetData
.
size
();
}
@Override
protected
void
onActivityResult
(
int
requestCode
,
int
resultCode
,
Intent
data
)
{
switch
(
requestCode
){
switch
(
requestCode
)
{
case
SCAN_REQUEST_CODE:
if
(
resultCode
==
RESULT_OK
){
if
(
resultCode
==
RESULT_OK
)
{
mAuthCode
=
data
.
getStringExtra
(
"authCode"
);
//Toast.makeText(MainActivity.this, mAuthCode, Toast.LENGTH_SHORT).show();
//start to query
...
...
@@ -868,7 +899,7 @@ public class DinnerActivity extends Activity {
//table 2 = 108730605004391217
String
orderNumber
=
mAuthCode
;
if
(
mUserToken
!=
null
&&
!
mUserToken
.
isEmpty
())
{
//already login
if
(
mUserToken
!=
null
&&
!
mUserToken
.
isEmpty
())
{
//already login
try
{
mAction
.
setIndex
(
WebApiRequest
.
ORDER_QUERY_INDEX
);
mAction
.
orderQuery
(
mUserToken
,
orderNumber
);
...
...
@@ -879,9 +910,9 @@ public class DinnerActivity extends Activity {
}
break
;
case
FACE_DETECT_REQUEST_CODE:
if
(
resultCode
==
RESULT_OK
)
{
if
(
resultCode
==
RESULT_OK
)
{
mOpenId
=
data
.
getStringExtra
(
"openid"
);
if
(
mOpenId
!=
null
)
{
if
(
mOpenId
!=
null
)
{
mTts
.
startSpeaking
(
mOpenId
+
"请取餐!"
,
mTtsListener
);
}
}
...
...
@@ -896,13 +927,13 @@ public class DinnerActivity extends Activity {
//robot sdk release
sdk
.
release
();
//xunfei sdk release
if
(
null
!=
mTts
)
{
if
(
null
!=
mTts
)
{
mTts
.
stopSpeaking
();
// 退出时释放连接
mTts
.
destroy
();
}
if
(
mediaPlayer
!=
null
)
{
if
(
mediaPlayer
!=
null
)
{
mediaPlayer
.
stop
();
mediaPlayer
.
release
();
mediaPlayer
=
null
;
...
...
app/src/main/res/layout/activity_dinner.xml
View file @
25561d28
...
...
@@ -15,76 +15,80 @@
android:id=
"@+id/robot"
android:layout_width=
"0dp"
android:layout_height=
"match_parent"
android:
orientation=
"vertical
"
android:
layout_weight=
"2
"
>
android:
layout_weight=
"2
"
android:
orientation=
"vertical
"
>
<LinearLayout
android:layout_width=
"match_parent"
android:layout_height=
"73dp"
android:layout_marginLeft=
"8dp"
android:layout_marginTop=
"8dp"
android:layout_height=
"73dp"
android:orientation=
"horizontal"
>
<ImageView
android:id=
"@+id/merchantLogo"
android:layout_width=
"wrap_content"
android:layout_height=
"wrap_content"
android:src=
"@drawable/md"
/>
android:src=
"@drawable/md"
/>
<LinearLayout
android:layout_width=
"match_parent"
android:layout_height=
"match_parent"
android:layout_marginLeft=
"8dp"
android:orientation=
"vertical"
>
<TextView
android:id=
"@+id/store_name"
android:layout_width=
"wrap_content"
android:layout_height=
"wrap_content"
android:textColor=
"@color/colorNormal"
android:textSize=
"20dp"
android:textStyle=
"bold"
android:layout_weight=
"1"
android:gravity=
"top"
android:text=
"麦当劳"
/>
android:text=
"麦当劳"
android:textColor=
"@color/colorNormal"
android:textSize=
"20dp"
android:textStyle=
"bold"
/>
<TextView
android:id=
"@+id/store_address"
android:layout_width=
"wrap_content"
android:layout_height=
"wrap_content"
android:textColor=
"@color/colorNormal"
android:layout_weight=
"1"
android:gravity=
"center"
android:text=
"祁连山南路店"
/>
android:text=
"祁连山南路店"
android:textColor=
"@color/colorNormal"
/>
<TextView
android:id=
"@+id/robot_work_mode"
android:layout_width=
"wrap_content"
android:layout_height=
"wrap_content"
android:textColor=
"@color/colorNormal"
android:layout_weight=
"1"
android:gravity=
"bottom"
android:text=
"机器人壹号 - 可可小爱"
/>
android:text=
"机器人壹号 - 可可小爱"
android:textColor=
"@color/colorNormal"
/>
</LinearLayout>
</LinearLayout>
<TextView
android:layout_width=
"match_parent"
android:layout_height=
"wrap_content"
android:layout_marginTop=
"6dp"
android:layout_marginBottom=
"4dp"
android:paddingTop=
"2dp"
android:paddingBottom=
"2dp"
android:textSize=
"14dp"
android:layout_marginTop=
"6dp"
android:background=
"@color/colorNormal"
android:gravity=
"center"
android:paddingBottom=
"2dp"
android:paddingTop=
"2dp"
android:text=
"送餐桌号"
android:textColor=
"@color/colorDefault"
android:background=
"@color/colorNormal"
android:text=
"送餐桌号"
/>
android:textSize=
"14dp"
/>
<peanut.keenon.com.control.RadioGroupEx
android:id=
"@+id/tableGroup"
android:layout_width=
"match_parent"
android:layout_height=
"match_parent"
android:layout_marginBottom=
"10dp"
android:paddingBottom=
"10dp"
android:gravity=
"center"
android:orientation=
"horizontal"
>
android:orientation=
"horizontal"
android:paddingBottom=
"10dp"
>
<RadioButton
android:id=
"@+id/btn1"
...
...
@@ -96,10 +100,10 @@
android:background=
"@drawable/radiobutton_background"
android:button=
"@null"
android:gravity=
"center"
android:tag=
"1"
android:text=
"一号餐桌"
android:textColor=
"@color/radiobutton_textcolor"
android:textSize=
"14sp"
android:tag=
"1"
/>
android:textSize=
"14sp"
/>
<RadioButton
android:id=
"@+id/btn2"
...
...
@@ -111,10 +115,10 @@
android:background=
"@drawable/radiobutton_background"
android:button=
"@null"
android:gravity=
"center"
android:tag=
"2"
android:text=
"二号餐桌"
android:textColor=
"@color/radiobutton_textcolor"
android:textSize=
"14sp"
android:tag=
"2"
/>
android:textSize=
"14sp"
/>
<RadioButton
android:id=
"@+id/btn3"
...
...
@@ -126,10 +130,10 @@
android:background=
"@drawable/radiobutton_background"
android:button=
"@null"
android:gravity=
"center"
android:tag=
"3"
android:text=
"三号餐桌"
android:textColor=
"@color/radiobutton_textcolor"
android:textSize=
"14sp"
android:tag=
"3"
/>
android:textSize=
"14sp"
/>
<RadioButton
android:id=
"@+id/btn4"
...
...
@@ -141,10 +145,10 @@
android:background=
"@drawable/radiobutton_background"
android:button=
"@null"
android:gravity=
"center"
android:tag=
"4"
android:text=
"四号餐桌"
android:textColor=
"@color/radiobutton_textcolor"
android:textSize=
"14sp"
android:tag=
"4"
/>
android:textSize=
"14sp"
/>
<RadioButton
android:id=
"@+id/btn5"
...
...
@@ -156,10 +160,10 @@
android:background=
"@drawable/radiobutton_background"
android:button=
"@null"
android:gravity=
"center"
android:tag=
"5"
android:text=
"五号餐桌"
android:textColor=
"@color/radiobutton_textcolor"
android:textSize=
"14sp"
android:tag=
"5"
/>
android:textSize=
"14sp"
/>
<RadioButton
android:id=
"@+id/btn6"
...
...
@@ -171,10 +175,10 @@
android:background=
"@drawable/radiobutton_background"
android:button=
"@null"
android:gravity=
"center"
android:tag=
"6"
android:text=
"六号餐桌"
android:textColor=
"@color/radiobutton_textcolor"
android:textSize=
"14sp"
android:tag=
"6"
/>
android:textSize=
"14sp"
/>
<RadioButton
android:id=
"@+id/bt7"
...
...
@@ -186,10 +190,10 @@
android:background=
"@drawable/radiobutton_background"
android:button=
"@null"
android:gravity=
"center"
android:tag=
"7"
android:text=
"七号餐桌"
android:textColor=
"@color/radiobutton_textcolor"
android:textSize=
"14sp"
android:tag=
"7"
/>
android:textSize=
"14sp"
/>
<RadioButton
android:id=
"@+id/btn8"
...
...
@@ -201,10 +205,25 @@
android:background=
"@drawable/radiobutton_background"
android:button=
"@null"
android:gravity=
"center"
android:tag=
"8"
android:text=
"八号餐桌"
android:textColor=
"@color/radiobutton_textcolor"
android:textSize=
"14sp"
android:tag=
"8"
/>
android:textSize=
"14sp"
/>
<RadioButton
android:id=
"@+id/btn9"
android:layout_width=
"90dp"
android:layout_height=
"35dp"
android:layout_marginStart=
"10dp"
android:layout_marginTop=
"10dp"
android:layout_weight=
"1"
android:background=
"@drawable/radiobutton_background"
android:button=
"@null"
android:gravity=
"center"
android:tag=
"8"
android:text=
"九号餐桌"
android:textColor=
"@color/radiobutton_textcolor"
android:textSize=
"14sp"
/>
</peanut.keenon.com.control.RadioGroupEx>
...
...
@@ -214,10 +233,10 @@
android:id=
"@+id/content"
android:layout_width=
"0dp"
android:layout_height=
"match_parent"
android:
orientation=
"vertical
"
android:
layout_weight=
"1
"
android:background=
"@color/colorRobot"
android:gravity=
"center"
android:
layout_weight=
"1
"
>
android:
orientation=
"vertical
"
>
<RelativeLayout
android:id=
"@+id/metro"
...
...
@@ -229,55 +248,95 @@
android:id=
"@+id/robot_plate"
android:layout_width=
"230dp"
android:layout_height=
"230dp"
android:orientation=
"vertical"
android:background=
"@drawable/robot_load_background"
android:layout_alignParentTop=
"true"
android:gravity=
"center"
>
android:background=
"@drawable/robot_load_background"
android:gravity=
"center"
android:orientation=
"vertical"
>
<!--
<peanut.keenon.com.control.NestedRadioGroup
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center">
-->
<CheckBox
android:id=
"@+id/plate_top"
<RelativeLayout
android:layout_width=
"100dp"
android:layout_height=
"100dp"
android:background=
"@drawable/plate_background"
android:button=
"@null"
android:gravity=
"center"
android:layout_marginTop=
"-30dp"
android:text=
""
/>
android:orientation=
"vertical"
>
<CheckBox
android:id=
"@+id/plate_top"
android:layout_width=
"match_parent"
android:layout_height=
"match_parent"
android:background=
"@drawable/plate_background"
android:button=
"@null"
android:gravity=
"center"
android:text=
""
/>
<TextView
android:layout_width=
"match_parent"
android:layout_height=
"wrap_content"
android:layout_alignParentTop=
"true"
android:gravity=
"center_horizontal"
android:text=
"@string/dinner_top_table"
android:textSize=
"10sp"
/>
</RelativeLayout>
<LinearLayout
android:layout_width=
"match_parent"
android:layout_height=
"wrap_content"
android:orientation=
"horizontal"
android:layout_marginTop=
"-14dp"
android:gravity=
"center"
>
<!--
<peanut.keenon.com.control.CircleButton
android:layout_width="100dp"
android:layout_height="100dp"
android:src="@drawable/plate"
app:cb_color="#99CC00"
app:cb_pressedRingWidth="8dp"/>
-->
<CheckBox
android:id=
"@+id/plate_left"
android:gravity=
"center"
android:orientation=
"horizontal"
>
<RelativeLayout
android:layout_width=
"100dp"
android:layout_height=
"100dp"
android:background=
"@drawable/plate_background"
android:button=
"@null"
android:gravity=
"center"
android:text=
""
/>
<CheckBox
android:id=
"@+id/plate_right"
android:orientation=
"vertical"
>
<CheckBox
android:id=
"@+id/plate_left"
android:layout_width=
"match_parent"
android:layout_height=
"match_parent"
android:background=
"@drawable/plate_background"
android:button=
"@null"
android:gravity=
"center"
android:text=
""
/>
<TextView
android:layout_width=
"match_parent"
android:layout_height=
"wrap_content"
android:layout_alignParentTop=
"true"
android:gravity=
"center_horizontal"
android:text=
"@string/dinner_left_table"
android:textSize=
"10sp"
/>
</RelativeLayout>
<RelativeLayout
android:layout_width=
"100dp"
android:layout_height=
"100dp"
android:background=
"@drawable/plate_background"
android:button=
"@null"
android:gravity=
"center"
android:text=
""
/>
android:orientation=
"vertical"
>
<CheckBox
android:id=
"@+id/plate_right"
android:layout_width=
"match_parent"
android:layout_height=
"match_parent"
android:background=
"@drawable/plate_background"
android:button=
"@null"
android:gravity=
"center"
android:text=
""
/>
<TextView
android:layout_width=
"match_parent"
android:layout_height=
"wrap_content"
android:layout_alignParentTop=
"true"
android:gravity=
"center_horizontal"
android:text=
"@string/dinner_right_table"
android:textSize=
"10sp"
/>
</RelativeLayout>
</LinearLayout>
<!--
</peanut.keenon.com.control.NestedRadioGroup>
...
...
@@ -289,39 +348,51 @@
android:id=
"@+id/robot_dinner"
android:layout_width=
"80dp"
android:layout_height=
"200dp"
android:src=
"@drawable/robot"
android:layout_marginBottom=
"16dp"
android:visibility=
"invisible"
/>
android:src=
"@drawable/robot"
android:visibility=
"invisible"
/>
<TextView
android:id=
"@+id/dinner_status"
android:layout_width=
"200dp"
android:layout_height=
"200dp"
android:background=
"@drawable/status_background"
android:text=
""
android:gravity=
"center"
android:text
Size=
"42dp
"
android:text
=
"
"
android:textColor=
"@color/colorFocus"
android:visibility=
"gone"
/>
android:textSize=
"42dp"
android:visibility=
"gone"
/>
<peanut.keenon.com.control.FlickerTextView
android:id=
"@+id/dinner_status_value"
android:layout_width=
"200dp"
android:layout_height=
"200dp"
android:text=
""
android:gravity=
"center"
android:text
Size=
"42dp
"
android:text
=
"
"
android:textColor=
"@color/colorFocus"
android:visibility=
"gone"
/>
android:textSize=
"42dp"
android:visibility=
"gone"
/>
</RelativeLayout>
<include
layout=
"@layout/metro_loading"
/>
<include
layout=
"@layout/metro_loading"
/>
<LinearLayout
android:layout_width=
"match_parent"
android:layout_height=
"wrap_content"
android:orientation=
"vertical"
android:gravity=
"center"
>
android:gravity=
"center"
android:orientation=
"vertical"
>
<Button
android:id=
"@+id/btn_reset"
android:layout_width=
"160dp"
android:layout_height=
"80dp"
android:layout_marginBottom=
"8dp"
android:layout_marginTop=
"8dp"
android:background=
"@drawable/button_background"
android:gravity=
"center"
android:text=
"重置餐桌"
android:textColor=
"@color/colorFocus"
/>
<Button
android:id=
"@+id/btn_scan"
android:layout_width=
"160dp"
...
...
@@ -331,11 +402,13 @@
android:background=
"@drawable/button_background"
android:gravity=
"center"
android:text=
"扫一扫"
android:textColor=
"@color/colorFocus"
/>
android:textColor=
"@color/colorFocus"
/>
<TextView
android:layout_width=
"16dp"
android:layout_height=
"0dp"
android:visibility=
"invisible"
/>
android:visibility=
"invisible"
/>
<Button
android:id=
"@+id/btn_go"
android:layout_width=
"120dp"
...
...
@@ -345,11 +418,13 @@
android:background=
"@drawable/button_background"
android:gravity=
"center"
android:text=
"立即送餐"
android:textColor=
"@color/colorFocus"
/>
android:textColor=
"@color/colorFocus"
/>
<TextView
android:layout_width=
"0dp"
android:layout_height=
"0dp"
android:visibility=
"invisible"
/>
android:visibility=
"invisible"
/>
<Button
android:id=
"@+id/btn_pickup"
android:layout_width=
"200dp"
...
...
@@ -358,10 +433,10 @@
android:layout_marginTop=
"8dp"
android:background=
"@drawable/button_background"
android:gravity=
"center"
android:textSize=
"32dp"
android:text=
"确认取餐"
android:textColor=
"@color/colorFocus"
android:visibility=
"gone"
/>
android:textSize=
"32dp"
android:visibility=
"gone"
/>
</LinearLayout>
</LinearLayout>
...
...
app/src/main/res/values/strings.xml
View file @
25561d28
...
...
@@ -13,4 +13,8 @@
<string
name=
"code_text"
>
将商品的条形码置于边框内,即可进行记录
</string>
<string
name=
"query_text"
>
将订单的条形码置于边框内,即可进行查询
</string>
<string
name=
"scan_tips"
>
应收金额
</string>
<string
name=
"dinner_top_table"
>
1
</string>
<string
name=
"dinner_left_table"
>
2
</string>
<string
name=
"dinner_right_table"
>
3
</string>
</resources>
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