Skip to content

Commit

Permalink
v1
Browse files Browse the repository at this point in the history
  • Loading branch information
engrpanda committed Apr 8, 2024
1 parent 32ec1dd commit 68e0064
Show file tree
Hide file tree
Showing 8 changed files with 312 additions and 2 deletions.
6 changes: 6 additions & 0 deletions .idea/vcs.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 4 additions & 0 deletions app/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -74,4 +74,8 @@ dependencies {

implementation("com.journeyapps:zxing-android-embedded:4.3.0")
implementation("com.google.zxing:core:3.5.3")
implementation(files("libs/robotservice.jar"))
implementation("com.google.code.gson:gson:2.8.8")


}
9 changes: 9 additions & 0 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,21 @@
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools">

<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
<uses-permission android:name="com.ainirobot.coreservice.robotSettingProvider" />
<uses-permission android:name="android.permission.FOREGROUND_SERVICE" />
<uses-permission android:name="android.permission.RECORD_AUDIO" />


<uses-feature
android:name="android.hardware.camera"
android:required="false" />
<uses-permission android:name="android.permission.CAMERA"/>

<application
android:name=".application.RobotOSApplication"
android:allowBackup="true"
android:dataExtractionRules="@xml/data_extraction_rules"
android:fullBackupContent="@xml/backup_rules"
Expand Down
25 changes: 24 additions & 1 deletion app/src/main/java/com/evo/qrgo/MainActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -4,19 +4,24 @@ import android.Manifest
import android.content.Context
import android.content.pm.PackageManager
import android.os.Bundle
import android.view.View
import android.widget.Toast
import androidx.activity.result.contract.ActivityResultContracts
import androidx.appcompat.app.AppCompatActivity
import androidx.core.content.ContextCompat
import com.ainirobot.coreservice.client.RobotApi
import com.ainirobot.coreservice.client.listener.CommandListener
import com.evo.qrgo.databinding.ActivityMainBinding
import com.journeyapps.barcodescanner.ScanContract
import com.journeyapps.barcodescanner.ScanIntentResult
import com.journeyapps.barcodescanner.ScanOptions
import android.view.View



class MainActivity : AppCompatActivity() {

private val reqId = 0

private val requestPermissionLauncher =
registerForActivityResult(ActivityResultContracts.RequestPermission()) { isGranted ->
if (isGranted) {
Expand All @@ -41,6 +46,8 @@ class MainActivity : AppCompatActivity() {
binding.textResult.text = string
// Hide the ImageView after scanning
binding.imageView.visibility = View.GONE

RobotApi.getInstance().startNavigation(0, string, 1.0, (10 * 1000).toLong(), mMotionListener)
}

private fun showCamera() {
Expand Down Expand Up @@ -87,5 +94,21 @@ class MainActivity : AppCompatActivity() {
}


private val mMotionListener: CommandListener = object : CommandListener() {
override fun onResult(result: Int, message: String) {
if ("succeed" == message) {
} else {
}
}
}

private fun showToast(message: String) {
Toast.makeText(this, message, Toast.LENGTH_SHORT).show()
}

// Handle back button click
fun onBackButtonClick(view: View) {
onBackPressed()
}

}
77 changes: 77 additions & 0 deletions app/src/main/java/com/evo/qrgo/application/ModuleCallback.java
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 app/src/main/java/com/evo/qrgo/application/RobotOSApplication.java
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 app/src/main/java/com/evo/qrgo/application/SpeechCallback.java
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 {
}
}
9 changes: 8 additions & 1 deletion app/src/main/res/layout/activity_main.xml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,14 @@
android:layout_height="match_parent"
tools:context=".MainActivity">


<Button
android:id="@+id/backButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="16dp"
android:text="Back"
android:onClick="onBackButtonClicked"
android:layout_gravity="start|top"/>

<androidx.appcompat.widget.LinearLayoutCompat
android:id="@+id/layout_result"
Expand Down

0 comments on commit 68e0064

Please sign in to comment.