Skip to content
This repository has been archived by the owner on Jun 30, 2022. It is now read-only.

Commit

Permalink
Assistant Android app - (#1649)
Browse files Browse the repository at this point in the history
* Virtual Assistant Client for Android - initial public commit

* updated .gitignore to ensure the /src/debug folder is not ignored

* implemented feedback from PR 1493

* code cleanup after merge

* fixes possible exception due to race condition

* fix: release created and stopped audio records

* added timeout event so that client app can notify user

* WIP adaptive card click events

* WIP adaptive card clicking

* finished implementation of adaptive card clicking

* Updated Location event so that the data is consumed properly

* additional IPA -> VA changes

* logcat logging of complete JSON data

* using suggested actions for adaptive card click

* undo incorrect commit

* added suggested actions feature

* updates to allow the service to receive connections from other apps

* small code updates + locationProvider threading fix

* finished feature to broadcast data to other apps
  • Loading branch information
abiemann authored and darrenj committed Jun 24, 2019
1 parent adc7dec commit 03b9919
Show file tree
Hide file tree
Showing 9 changed files with 324 additions and 129 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -87,8 +87,9 @@
<service
android:name=".service.SpeechService"
android:enabled="true"
android:exported="true" /> <!-- ASSISTANT -->
android:exported="true" />

<!-- ASSISTANT -->
<service
android:name=".assistant.AssistantService"
android:permission="android.permission.BIND_VOICE_INTERACTION">
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package com.microsoft.bot.builder.solutions.virtualassistant;

interface ISpeechService {

boolean isSpeechSdkRunning();
void sendTextMessage(String msg);
void initializeSpeechSdk(boolean haveRecordAudioPermission);
void connectAsync();
void startLocationUpdates();
void resetBot();
String getConfiguration();// the String is "Configuration" as JSON
void setConfiguration(String json);// the String is "Configuration" as JSON
void sendLocationEvent(String lat, String lon);
void requestWelcomeCard();
void injectReceivedActivity(String json);
void listenOnceAsync();
void sendActivityMessageAsync(String msg);
String getSuggestedActions();//the String is "List<CardAction>" as JSON
void clearSuggestedActions();
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import android.content.pm.PackageManager;
import android.os.Bundle;
import android.os.IBinder;
import android.os.RemoteException;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.support.design.widget.Snackbar;
Expand All @@ -21,24 +22,24 @@
import android.view.inputmethod.InputMethodManager;
import android.widget.Toast;

import com.microsoft.bot.builder.solutions.virtualassistant.ISpeechService;
import com.microsoft.bot.builder.solutions.virtualassistant.R;
import com.microsoft.bot.builder.solutions.virtualassistant.service.ServiceBinder;
import com.microsoft.bot.builder.solutions.virtualassistant.service.SpeechService;

/**
* This base class provides functionality that is reusable in Activities of this app
*/
public abstract class BaseActivity extends AppCompatActivity {

// Constants
public static final String LOGTAG = "BaseActivity";
private static final Integer PERMISSION_REQUEST_RECORD_AUDIO = 101;
private static final Integer PERMISSION_REQUEST_FINE_LOCATION = 102;
private static final String SHARED_PREFS_NAME = "my_shared_prefs";
protected static final String SHARED_PREF_SHOW_TEXTINPUT = "SHARED_PREF_SHOW_TEXTINPUT";

// State
private SharedPreferences sharedPreferences;
protected SpeechService speechServiceBinder;
protected ISpeechService speechServiceBinder;

// Override these
protected void permissionDenied(String manifestPermission){};
Expand Down Expand Up @@ -188,32 +189,37 @@ public void onRequestPermissionsResult(int requestCode, @NonNull String[] permis
}

public void doBindService() {
Intent intent = null;
intent = new Intent(this, SpeechService.class);
bindService(intent, myConnection, Context.BIND_AUTO_CREATE);
Intent intent = new Intent();
intent.setClassName("com.microsoft.bot.builder.solutions.virtualassistant","com.microsoft.bot.builder.solutions.virtualassistant.service.SpeechService");
boolean success = bindService(intent, myConnection, Context.BIND_AUTO_CREATE);
Log.d(LOGTAG,"success = "+success);
}

public ServiceConnection myConnection = new ServiceConnection() {

public void onServiceConnected(ComponentName className, IBinder binder) {
speechServiceBinder = ((ServiceBinder) binder).getSpeechService();
Log.d("ServiceConnection","connected");
speechServiceBinder = ISpeechService.Stub.asInterface(binder);
Log.d(LOGTAG,"connected");
// now use speechServiceBinder to execute methods in the service
serviceConnected();
}

public void onServiceDisconnected(ComponentName className) {
Log.d("ServiceConnection","disconnected");
Log.d(LOGTAG,"disconnected");
speechServiceBinder = null;
}
};

protected void initializeAndConnect(){
if (speechServiceBinder != null) {
speechServiceBinder.initializeSpeechSdk(true);
speechServiceBinder.getSpeechSdk().connectAsync();
try {
speechServiceBinder.initializeSpeechSdk(true);
speechServiceBinder.connectAsync();
} catch (RemoteException exception){
Log.e(LOGTAG, exception.getMessage());
}
} else {
Log.e("ServiceConnection", "do not have a binding to the service");
Log.e(LOGTAG, "do not have a binding to the service");
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,14 @@
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.os.RemoteException;
import android.support.design.widget.TextInputEditText;
import android.util.Log;
import android.view.KeyEvent;
import android.view.inputmethod.EditorInfo;

import com.google.gson.Gson;
import com.google.gson.reflect.TypeToken;
import com.microsoft.bot.builder.solutions.directlinespeech.model.Configuration;
import com.microsoft.bot.builder.solutions.virtualassistant.R;
import com.microsoft.bot.builder.solutions.virtualassistant.activities.BaseActivity;
Expand Down Expand Up @@ -37,6 +41,7 @@ public class BotConfigurationActivity extends BaseActivity {

// STATE
private Configuration configuration;
private Gson gson;

public static Intent getNewIntent(Context context) {
return new Intent(context, BotConfigurationActivity.class);
Expand All @@ -47,6 +52,7 @@ protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(CONTENT_VIEW);
ButterKnife.bind(this);
gson = new Gson();
}

@Override
Expand Down Expand Up @@ -94,27 +100,37 @@ public void onClickOk() {
}

private void showConfiguration(){
configuration = speechServiceBinder.getConfiguration();
serviceKey.setText(configuration.serviceKey);
serviceRegion.setText(configuration.serviceRegion);
botId.setText(configuration.botId);
voiceName.setText(configuration.voiceName);
userId.setText(configuration.userId);
locale.setText(configuration.locale);
locationLat.setText(configuration.geolat);
locationLon.setText(configuration.geolon);
try {
final String json = speechServiceBinder.getConfiguration();
configuration = gson.fromJson(json, new TypeToken<Configuration>(){}.getType());
serviceKey.setText(configuration.serviceKey);
serviceRegion.setText(configuration.serviceRegion);
botId.setText(configuration.botId);
voiceName.setText(configuration.voiceName);
userId.setText(configuration.userId);
locale.setText(configuration.locale);
locationLat.setText(configuration.geolat);
locationLon.setText(configuration.geolon);
} catch (RemoteException exception){
Log.e(LOGTAG, exception.getMessage());
}
}

private void saveConfiguration(){
configuration.serviceKey = serviceKey.getText().toString();
configuration.serviceRegion = serviceRegion.getText().toString();
configuration.botId = botId.getText().toString();
configuration.voiceName = voiceName.getText().toString();
configuration.userId = userId.getText().toString();
configuration.locale = locale.getText().toString();
configuration.geolat = locationLat.getText().toString();
configuration.geolon = locationLon.getText().toString();
speechServiceBinder.setConfiguration(configuration);
try {
configuration.serviceKey = serviceKey.getText().toString();
configuration.serviceRegion = serviceRegion.getText().toString();
configuration.botId = botId.getText().toString();
configuration.voiceName = voiceName.getText().toString();
configuration.userId = userId.getText().toString();
configuration.locale = locale.getText().toString();
configuration.geolat = locationLat.getText().toString();
configuration.geolon = locationLon.getText().toString();
String json = gson.toJson(configuration);
speechServiceBinder.setConfiguration(json);
} catch (RemoteException exception){
Log.e(LOGTAG, exception.getMessage());
}
}

}
Loading

0 comments on commit 03b9919

Please sign in to comment.