use of ai.saiy.android.user.SaiyAccount in project Saiy-PS by brandall76.
the class CommandVocalRecognition method getResponse.
/**
* Resolve the required command returning an {@link Outcome} object
*
* @param ctx the application context
* @param sl the {@link SupportedLanguage} we are using to analyse the voice data.
* @return {@link Outcome} containing everything we need to respond to the command.
*/
public Outcome getResponse(@NonNull final Context ctx, @NonNull final SupportedLanguage sl) {
final long then = System.nanoTime();
final Outcome outcome = new Outcome();
outcome.setQubit(new Qubit());
final SaiyAccountList saiyAccountList = SaiyAccountHelper.getAccounts(ctx);
if (saiyAccountList != null && saiyAccountList.size() > 0) {
if (DEBUG) {
MyLog.v(CLS_NAME, "saiyAccountList.size: " + saiyAccountList.size());
}
switch(saiyAccountList.size()) {
case 1:
default:
final SaiyAccount saiyAccount = saiyAccountList.getSaiyAccountList().get(0);
if (saiyAccount != null) {
final ProfileItem profileItem = saiyAccount.getProfileItem();
if (profileItem != null) {
final String profileId = profileItem.getId();
if (UtilsString.notNaked(profileId)) {
if (DEBUG) {
MyLog.d(CLS_NAME, "profileId: " + profileId);
}
final Speaker.Status status = Speaker.Status.getStatus(profileItem.getStatus());
if (DEBUG) {
MyLog.d(CLS_NAME, "status: " + status.name());
}
switch(status) {
case SUCCEEDED:
outcome.setUtterance(SaiyResourcesHelper.getStringResource(ctx, sl, R.string.speech_enroll_instructions_15));
outcome.setAction(LocalRequest.ACTION_SPEAK_LISTEN);
outcome.setOutcome(Outcome.SUCCESS);
outcome.setExtra(profileId);
break;
default:
if (DEBUG) {
MyLog.w(CLS_NAME, "enrollment status");
}
outcome.setOutcome(Outcome.FAILURE);
outcome.setUtterance(SaiyResourcesHelper.getStringResource(ctx, sl, R.string.error_vi_status));
break;
}
} else {
if (DEBUG) {
MyLog.w(CLS_NAME, "profile id naked");
}
outcome.setOutcome(Outcome.FAILURE);
outcome.setUtterance(SaiyResourcesHelper.getStringResource(ctx, sl, R.string.error_vi_status));
}
} else {
if (DEBUG) {
MyLog.w(CLS_NAME, "profile item null");
}
outcome.setOutcome(Outcome.FAILURE);
outcome.setUtterance(SaiyResourcesHelper.getStringResource(ctx, sl, R.string.error_vi_status));
}
} else {
if (DEBUG) {
MyLog.w(CLS_NAME, "account null");
}
outcome.setOutcome(Outcome.FAILURE);
outcome.setUtterance(SaiyResourcesHelper.getStringResource(ctx, sl, R.string.error_vi_no_account));
}
break;
}
} else {
if (DEBUG) {
MyLog.w(CLS_NAME, "no accounts");
}
outcome.setOutcome(Outcome.FAILURE);
outcome.setUtterance(SaiyResourcesHelper.getStringResource(ctx, sl, R.string.error_vi_no_account));
}
if (DEBUG) {
MyLog.getElapsed(CLS_NAME, then);
}
return outcome;
}
use of ai.saiy.android.user.SaiyAccount in project Saiy-PS by brandall76.
the class FragmentSuperuserHelper method proceedEnrollment.
/**
* Proceed with the enrollment process knowing that any existing association to the
* given account has been deleted consensually along with any remote profile.
* <p>
* Once the account set up is complete a callback will be provided from the
* {@link ISaiyAccount} interface. Any issue in the account creation will be
* handled by {@link #monitorAccountCreation(String)}
*
* @param accountName the account name
*/
private void proceedEnrollment(@NonNull final String accountName) {
if (DEBUG) {
MyLog.i(CLS_NAME, "proceedEnrollment");
}
final SaiyAccount saiyAccount = new SaiyAccount(accountName, true);
saiyAccount.setAccountId(getApplicationContext(), this);
saiyAccount.setPseudonym(SPH.getUserName(getApplicationContext()), true);
getParentActivity().showProgress(true);
monitorAccountCreation(accountName);
}
Aggregations