-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
8 changed files
with
312 additions
and
2 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
77 changes: 77 additions & 0 deletions
77
app/src/main/java/com/evo/qrgo/application/ModuleCallback.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
/* | ||
* Copyright (C) 2017 OrionStar Technology Project | ||
* | ||
* 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 | ||
* | ||
* http://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. | ||
*/ | ||
|
||
package com.evo.qrgo.application; | ||
|
||
import android.os.RemoteException; | ||
import android.util.Log; | ||
|
||
import com.ainirobot.coreservice.client.module.ModuleCallbackApi; | ||
|
||
public class ModuleCallback extends ModuleCallbackApi { | ||
|
||
private static final String TAG = ModuleCallback.class.getName(); | ||
|
||
/** | ||
* Receive speech request | ||
* 接收语音指令 底层发起request 请求 | ||
* | ||
* @param reqId | ||
* @param reqType 语音指令类型, Speech type | ||
* @param reqText 语音识别内容, Speech text | ||
* @param reqParam 语音指令参数, Speech param | ||
* @throws RemoteException | ||
*/ | ||
@Override | ||
public boolean onSendRequest(int reqId, String reqType, String reqText, String reqParam) throws RemoteException { | ||
Log.d(TAG, "New request: " + " type is:" + reqType + " text is:" + reqText + " reqParam = " + reqParam); | ||
String text = "New request: " + " type is:" + reqType + " text is:" + reqText + " reqParam = " + reqParam; | ||
return true; | ||
} | ||
|
||
/** | ||
* hardware error callback | ||
* 硬件出现异常回调 | ||
* @param function | ||
* @param type | ||
* @param message | ||
* @throws RemoteException | ||
*/ | ||
@Override | ||
public void onHWReport(int function, String type, String message) throws RemoteException { | ||
Log.i(TAG, "onHWReport function:" + function + " type:" + type + " message:" + message); | ||
} | ||
|
||
/** | ||
* Suspend system, after this message, RobotOS can not work with this APP | ||
* 控制权被系统剥夺,收到该事件后,所有Api调用无效 | ||
* @throws RemoteException | ||
*/ | ||
@Override | ||
public void onSuspend() throws RemoteException { | ||
Log.d(TAG, "onSuspend"); | ||
} | ||
|
||
/** | ||
* Recovery system, after this message, RobotOS can work with this APP again. | ||
* 控制权恢复,收到该事件后,重新恢复对机器人的控制 | ||
* @throws RemoteException | ||
*/ | ||
@Override | ||
public void onRecovery() throws RemoteException { | ||
Log.d(TAG, "onRecovery"); | ||
} | ||
} |
133 changes: 133 additions & 0 deletions
133
app/src/main/java/com/evo/qrgo/application/RobotOSApplication.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,133 @@ | ||
/* | ||
* Copyright (C) 2017 OrionStar Technology Project | ||
* | ||
* 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 | ||
* | ||
* http://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. | ||
*/ | ||
|
||
package com.evo.qrgo.application; | ||
|
||
import android.app.Application; | ||
import android.content.Context; | ||
import android.os.HandlerThread; | ||
import android.util.Log; | ||
|
||
import com.ainirobot.coreservice.client.ApiListener; | ||
import com.ainirobot.coreservice.client.RobotApi; | ||
import com.ainirobot.coreservice.client.module.ModuleCallbackApi; | ||
import com.ainirobot.coreservice.client.speech.SkillApi; | ||
|
||
public class RobotOSApplication extends Application { | ||
|
||
private static final String TAG = RobotOSApplication.class.getName(); | ||
|
||
private Context mContext; | ||
private SkillApi mSkillApi; | ||
|
||
private SpeechCallback mSkillCallback; | ||
private HandlerThread mApiCallbackThread; | ||
private ModuleCallbackApi mModuleCallback; | ||
private static RobotOSApplication mApplication; | ||
|
||
@Override | ||
public void onCreate() { | ||
super.onCreate(); | ||
mContext = this; | ||
mApplication = this; | ||
init(); | ||
initRobotApi(); | ||
} | ||
|
||
private void init() { | ||
mSkillCallback = new SpeechCallback(); | ||
mModuleCallback = new ModuleCallback(); | ||
mApiCallbackThread = new HandlerThread("RobotOSDemo"); | ||
mApiCallbackThread.start(); | ||
} | ||
|
||
public static RobotOSApplication getInstance() { | ||
return mApplication; | ||
} | ||
|
||
private void initRobotApi() { | ||
RobotApi.getInstance().connectServer(mContext, new ApiListener() { | ||
@Override | ||
public void handleApiDisabled() { | ||
Log.i(TAG, "handleApiDisabled"); | ||
} | ||
|
||
/** | ||
* Server connected, set callback to handle message | ||
* Server已连接,设置接收请求的回调,包含语音指令、系统事件等 | ||
* | ||
* Start connect RobotOS, init and make it ready to use | ||
* 启动与RobotOS连接,这里可以做一些初始化的工作 例如连接语音,本地服务等 | ||
*/ | ||
@Override | ||
public void handleApiConnected() { | ||
Log.i(TAG, "handleApiConnected"); | ||
addApiCallBack(); | ||
initSkillApi(); | ||
} | ||
|
||
/** | ||
* Disconnect RobotOS | ||
* 连接已断开 | ||
*/ | ||
@Override | ||
public void handleApiDisconnected() { | ||
Log.i(TAG, "handleApiDisconnected"); | ||
} | ||
}); | ||
} | ||
|
||
private void addApiCallBack() { | ||
Log.d(TAG, "CoreService connected "); | ||
RobotApi.getInstance().setCallback(mModuleCallback); | ||
RobotApi.getInstance().setResponseThread(mApiCallbackThread); | ||
} | ||
|
||
private void initSkillApi() { | ||
mSkillApi = new SkillApi(); | ||
ApiListener apiListener = new ApiListener() { | ||
@Override | ||
public void handleApiDisabled() { | ||
} | ||
|
||
/** | ||
* Handle speech service | ||
* 语音服务连接成功,注册语音回调 | ||
*/ | ||
@Override | ||
public void handleApiConnected() { | ||
mSkillApi.registerCallBack(mSkillCallback); | ||
} | ||
|
||
/** | ||
* Disconnect speech service | ||
* 语音服务已断开 | ||
*/ | ||
@Override | ||
public void handleApiDisconnected() { | ||
} | ||
}; | ||
mSkillApi.addApiEventListener(apiListener); | ||
mSkillApi.connectApi(mContext); | ||
} | ||
|
||
public SkillApi getSkillApi() { | ||
if (mSkillApi.isApiConnectedService()) { | ||
return mSkillApi; | ||
} | ||
return null; | ||
} | ||
} |
51 changes: 51 additions & 0 deletions
51
app/src/main/java/com/evo/qrgo/application/SpeechCallback.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
/* | ||
* Copyright (C) 2017 OrionStar Technology Project | ||
* | ||
* 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 | ||
* | ||
* http://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. | ||
*/ | ||
|
||
package com.evo.qrgo.application; | ||
|
||
import android.os.RemoteException; | ||
|
||
import com.ainirobot.coreservice.client.speech.SkillCallback; | ||
|
||
public class SpeechCallback extends SkillCallback { | ||
|
||
private static final String TAG = SpeechCallback.class.getName(); | ||
|
||
@Override | ||
public void onSpeechParResult(String s) throws RemoteException { | ||
} | ||
|
||
@Override | ||
public void onStart() throws RemoteException { | ||
} | ||
|
||
@Override | ||
public void onStop() throws RemoteException { | ||
} | ||
|
||
@Override | ||
public void onVolumeChange(int i) throws RemoteException { | ||
//LogTools.info(TAG+" onVolumeChange :" + i); | ||
} | ||
|
||
@Override | ||
public void onQueryEnded(int i) throws RemoteException { | ||
} | ||
|
||
@Override | ||
public void onQueryAsrResult(String asrResult) throws RemoteException { | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters