public abstract class

BaseBehaviorService

extends Service
java.lang.Object
   ↳ android.content.Context
     ↳ android.content.ContextWrapper
       ↳ android.app.Service
         ↳ com.nuwarobotics.service.custombehavior.BaseBehaviorService

Class Overview

Target SDK : 2.0.0.05

Developer should implement a class to determine how to react when receiving a customized NLP response from NUWA Trainingkit.
This could be achieved by extending from class BaseBehaviorService.
BaseBehaviorService declared three important functions which onInitialize(), createCustomBehavior() and notifyBehaviorFinished().
There are two functions need to be implemented which onInitialize() and createCustomBehavior().

     public class CustomBehaviorImpl extends BaseBehaviorService {
     @Override
     public void onInitialize() {
         handler = new Handler(Looper.getMainLooper());
         try {
         	// TODO initialize
             mSystemBehaviorManager.setWelcomeSentence(new String[]{"你好, %s.這是一個歡迎詞的測試!", "%s, 挖底家", "%s, 有什麼可以為您服務的嗎?"});
         } catch (RemoteException e) {
             e.printStackTrace();
         }
     }

     @Override
     public CustomBehavior createCustomBehavior() {
         return new CustomBehavior.Stub() {
             @Override
             public void prepare(final String parameter) {
 				// TODO write your preparing work
             }

             @Override
             public void process(final String parameter) {
 				// TODO the actual process logic

                 // TODO simulate asynchronous task while process complete
                 handler.postDelayed(new Runnable() {
                     @Override
                     public void run() {
                         try {
                             notifyBehaviorFinished();
                         } catch (RemoteException e) {
                             e.printStackTrace();
                         }
                     }
                 }, 5000);
             }

             @Override
             public void finish(final String parameter) {
             	// TODO the whole session has been finished.
             }
         };
     }
 }

Summary

[Expand]
Inherited Constants
From class android.app.Service
From class android.content.Context
From interface android.content.ComponentCallbacks2
Public Constructors
BaseBehaviorService()
Public Methods
IBinder onBind(Intent intent)
Standard onBind life cycle of Service.
void onDestroy()
Standard destroy life cycle of Service.
int onStartCommand(Intent intent, int flags, int startId)
Standard onStartCommand life cycle of Service.
Protected Methods
void abandonBehaviorFocus(OnBehaviorFocusChangeListener listener)
To abandon get Behavior Focus.(It will return original system behavior)
Target SDK : 2.0.0.07
abstract CustomBehavior createCustomBehavior()
After that, the other function createCustomBehavior should create a CustomBehavior object.
ISystemBehaviorManager getSystemBehaviorManager()
Use to get API interface.
void notifyBehaviorFinished()
To notify robot behavior system that the process has been completed.
abstract void onInitialize()
When the extending class has been started, developer could initialize resource here.
void requestBehaviorFocus(OnBehaviorFocusChangeListener listener)
To request get Behavior Focus.(It will disable system behavior)
Target SDK : 2.0.0.07
void resetWelcomeSentence()
To reset welcome sentence.
void setWelcomeSentence(String[] sentences)
To set welcome sentence when robot detected someone.
[Expand]
Inherited Methods
From class android.app.Service
From class android.content.ContextWrapper
From class android.content.Context
From class java.lang.Object
From interface android.content.ComponentCallbacks
From interface android.content.ComponentCallbacks2

Public Constructors

public BaseBehaviorService ()

Public Methods

public IBinder onBind (Intent intent)

Standard onBind life cycle of Service.

public void onDestroy ()

Standard destroy life cycle of Service.

public int onStartCommand (Intent intent, int flags, int startId)

Standard onStartCommand life cycle of Service.

Protected Methods

protected void abandonBehaviorFocus (OnBehaviorFocusChangeListener listener)

To abandon get Behavior Focus.(It will return original system behavior)
Target SDK : 2.0.0.07

Throws
RemoteException

protected abstract CustomBehavior createCustomBehavior ()

After that, the other function createCustomBehavior should create a CustomBehavior object. CustomBehavior is a interface which define custom behavior once receiving customized NLP result. It declared three callback functions for developer to implement customized behavior.

Returns
  • CustomBehavior class object

protected ISystemBehaviorManager getSystemBehaviorManager ()

Use to get API interface.

Returns
  • instence of ISystemBehaviorManager created in BaseBehavior Service.

protected void notifyBehaviorFinished ()

To notify robot behavior system that the process has been completed.

Throws
RemoteException

protected abstract void onInitialize ()

When the extending class has been started, developer could initialize resource here.

protected void requestBehaviorFocus (OnBehaviorFocusChangeListener listener)

To request get Behavior Focus.(It will disable system behavior)
Target SDK : 2.0.0.07

Throws
RemoteException

protected void resetWelcomeSentence ()

To reset welcome sentence.

Throws
RemoteException

protected void setWelcomeSentence (String[] sentences)

To set welcome sentence when robot detected someone.

Throws
RemoteException