mobi.voiceassistant.base
Class Agent

java.lang.Object
  extended by android.content.Context
      extended by android.content.ContextWrapper
          extended by android.app.Service
              extended by mobi.voiceassistant.base.IntentExecutorService
                  extended by mobi.voiceassistant.base.Agent
All Implemented Interfaces:
ComponentCallbacks, ComponentCallbacks2
Direct Known Subclasses:
AssistantAgent, RemoteListAgent

public abstract class Agent
extends IntentExecutorService

Base class for implementing agents


Field Summary
static String ARG_REQUEST
           
static String ARG_RESPONSE
           
 
Fields inherited from class android.app.Service
START_CONTINUATION_MASK, START_FLAG_REDELIVERY, START_FLAG_RETRY, START_NOT_STICKY, START_REDELIVER_INTENT, START_STICKY, START_STICKY_COMPATIBILITY
 
Fields inherited from class android.content.Context
ACCESSIBILITY_SERVICE, ACCOUNT_SERVICE, ACTIVITY_SERVICE, ALARM_SERVICE, AUDIO_SERVICE, BIND_ABOVE_CLIENT, BIND_ADJUST_WITH_ACTIVITY, BIND_ALLOW_OOM_MANAGEMENT, BIND_AUTO_CREATE, BIND_DEBUG_UNBIND, BIND_IMPORTANT, BIND_NOT_FOREGROUND, BIND_WAIVE_PRIORITY, BLUETOOTH_SERVICE, CLIPBOARD_SERVICE, CONNECTIVITY_SERVICE, CONTEXT_IGNORE_SECURITY, CONTEXT_INCLUDE_CODE, CONTEXT_RESTRICTED, DEVICE_POLICY_SERVICE, DISPLAY_SERVICE, DOWNLOAD_SERVICE, DROPBOX_SERVICE, INPUT_METHOD_SERVICE, INPUT_SERVICE, KEYGUARD_SERVICE, LAYOUT_INFLATER_SERVICE, LOCATION_SERVICE, MEDIA_ROUTER_SERVICE, MODE_APPEND, MODE_ENABLE_WRITE_AHEAD_LOGGING, MODE_MULTI_PROCESS, MODE_PRIVATE, MODE_WORLD_READABLE, MODE_WORLD_WRITEABLE, NFC_SERVICE, NOTIFICATION_SERVICE, NSD_SERVICE, POWER_SERVICE, SEARCH_SERVICE, SENSOR_SERVICE, STORAGE_SERVICE, TELEPHONY_SERVICE, TEXT_SERVICES_MANAGER_SERVICE, UI_MODE_SERVICE, USB_SERVICE, USER_SERVICE, VIBRATOR_SERVICE, WALLPAPER_SERVICE, WIFI_P2P_SERVICE, WIFI_SERVICE, WINDOW_SERVICE
 
Fields inherited from interface android.content.ComponentCallbacks2
TRIM_MEMORY_BACKGROUND, TRIM_MEMORY_COMPLETE, TRIM_MEMORY_MODERATE, TRIM_MEMORY_RUNNING_CRITICAL, TRIM_MEMORY_RUNNING_LOW, TRIM_MEMORY_RUNNING_MODERATE, TRIM_MEMORY_UI_HIDDEN
 
Constructor Summary
Agent()
           
 
Method Summary
protected  void goBackground(Bundle args, int requestCode)
          Call this method if you want to continue computation on background thread.
protected  void goBackground(Request request, Response response, int requestCode)
          Call this method if you want to continue computation on background thread.
protected  void onBackground(Bundle args, int requestCode)
          Override this method if you called goBackground(android.os.Bundle, int).
protected  void onBackground(Request request, Response response, int requestCode)
          Override this method if you called goBackground(Request, Response, int).
protected abstract  void onCommand(Request request)
          Override this method to handle voice commands for this agent issued by user.
protected  void onExecute(Intent bindIntent, Intent intent)
           
protected  void onModalCancel(Request request)
          Override this method if you called Response.enterModalScope(int) (or it's variants).
protected  void onModalFail(Request request)
          Override this method if you called Response.enterModalScope(int) (or it's variants).
protected  void onRequest(String action, Request request)
          Override this method if you use custom actions for PendingRequest.
 
Methods inherited from class mobi.voiceassistant.base.IntentExecutorService
onBind
 
Methods inherited from class android.app.Service
dump, getApplication, onConfigurationChanged, onCreate, onDestroy, onLowMemory, onRebind, onStart, onStartCommand, onTaskRemoved, onTrimMemory, onUnbind, startForeground, stopForeground, stopSelf, stopSelf, stopSelfResult
 
Methods inherited from class android.content.ContextWrapper
attachBaseContext, bindService, checkCallingOrSelfPermission, checkCallingOrSelfUriPermission, checkCallingPermission, checkCallingUriPermission, checkPermission, checkUriPermission, checkUriPermission, clearWallpaper, createConfigurationContext, createDisplayContext, createPackageContext, databaseList, deleteDatabase, deleteFile, enforceCallingOrSelfPermission, enforceCallingOrSelfUriPermission, enforceCallingPermission, enforceCallingUriPermission, enforcePermission, enforceUriPermission, enforceUriPermission, fileList, getApplicationContext, getApplicationInfo, getAssets, getBaseContext, getCacheDir, getClassLoader, getContentResolver, getDatabasePath, getDir, getExternalCacheDir, getExternalFilesDir, getFilesDir, getFileStreamPath, getMainLooper, getObbDir, getPackageCodePath, getPackageManager, getPackageName, getPackageResourcePath, getResources, getSharedPreferences, getSystemService, getTheme, getWallpaper, getWallpaperDesiredMinimumHeight, getWallpaperDesiredMinimumWidth, grantUriPermission, isRestricted, openFileInput, openFileOutput, openOrCreateDatabase, openOrCreateDatabase, peekWallpaper, registerReceiver, registerReceiver, removeStickyBroadcast, removeStickyBroadcastAsUser, revokeUriPermission, sendBroadcast, sendBroadcast, sendBroadcastAsUser, sendBroadcastAsUser, sendOrderedBroadcast, sendOrderedBroadcast, sendOrderedBroadcastAsUser, sendStickyBroadcast, sendStickyBroadcastAsUser, sendStickyOrderedBroadcast, sendStickyOrderedBroadcastAsUser, setTheme, setWallpaper, setWallpaper, startActivities, startActivities, startActivity, startActivity, startInstrumentation, startIntentSender, startIntentSender, startService, stopService, unbindService, unregisterReceiver
 
Methods inherited from class android.content.Context
getString, getString, getText, obtainStyledAttributes, obtainStyledAttributes, obtainStyledAttributes, obtainStyledAttributes, registerComponentCallbacks, unregisterComponentCallbacks
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

ARG_REQUEST

public static final String ARG_REQUEST
See Also:
Constant Field Values

ARG_RESPONSE

public static final String ARG_RESPONSE
See Also:
Constant Field Values
Constructor Detail

Agent

public Agent()
Method Detail

onCommand

protected abstract void onCommand(Request request)
Override this method to handle voice commands for this agent issued by user. This method is called by Assistant when Request with AgentContract.Intents.ACTION_COMMAND arrives. Inside this method Request.getContent() returns instance of Token and Request.getDispatchId() returns id of command in corresponding module. Note that this method called on main thread.

See Also:
onModalCancel(Request), onModalFail(Request)

onModalFail

protected void onModalFail(Request request)
Override this method if you called Response.enterModalScope(int) (or it's variants). When user says something that cannot be matched by any pattern in modal module this method is called. Note that this method called on main thread. Default implementation throws UnsupportedOperationException.

See Also:
onCommand(Request), onModalFail(Request)

onModalCancel

protected void onModalCancel(Request request)
Override this method if you called Response.enterModalScope(int) (or it's variants). Default implementation throws UnsupportedOperationException. Note that this method called on main thread.

See Also:
onCommand(Request), onModalFail(Request)

onBackground

protected void onBackground(Request request,
                            Response response,
                            int requestCode)
Override this method if you called goBackground(Request, Response, int). Default implementation throws UnsupportedOperationException.

Parameters:
request - Request passed to goBackground(Request, Response, int).
response - Response passed to goBackground(Request, Response, int).
requestCode - Code passed to goBackground(Request, Response, int).

onBackground

protected void onBackground(Bundle args,
                            int requestCode)
Override this method if you called goBackground(android.os.Bundle, int). Default implementation calls onBackground(Request, Response, int).

Parameters:
args - Bundle passed to goBackground(android.os.Bundle, int).
requestCode - Code passed to goBackground(android.os.Bundle, int).

onExecute

protected void onExecute(Intent bindIntent,
                         Intent intent)
Specified by:
onExecute in class IntentExecutorService

onRequest

protected void onRequest(String action,
                         Request request)
Override this method if you use custom actions for PendingRequest. Default implementation calls onCommand(Request) for AgentContract.Intents.ACTION_COMMAND, onModalFail(Request) for AgentContract.Intents.ACTION_MODAL_FAIL and onModalCancel(Request) for AgentContract.Intents.ACTION_MODAL_CANCEL

Parameters:
action - The action from Request.getAction()
request - The request itself

goBackground

protected final void goBackground(Request request,
                                  Response response,
                                  int requestCode)
Call this method if you want to continue computation on background thread. Do not forget to override onBackground(Request, Response, int).

Parameters:
request - Request passed to onBackground(Request, Response, int).
response - Response passed to onBackground(Request, Response, int).
requestCode - Code passed to onBackground(Request, Response, int).

goBackground

protected final void goBackground(Bundle args,
                                  int requestCode)
Call this method if you want to continue computation on background thread. Do not forget to override onBackground(android.os.Bundle, int).

Parameters:
args - Bundle passed to onBackground(android.os.Bundle, int).
requestCode - Code passed to onBackground(android.os.Bundle, int).