use of ai.saiy.android.localisation.SupportedLanguage in project Saiy-PS by brandall76.
the class FragmentSuperuserHelper method enrollmentFailed.
/**
* Notify the user that the account creation failed
*
* @param accountName the account name
*/
private void enrollmentFailed(@NonNull final String accountName) {
if (DEBUG) {
MyLog.i(CLS_NAME, "enrollmentFailed");
}
final SupportedLanguage sl = SupportedLanguage.getSupportedLanguage(SPH.getVRLocale(getApplicationContext()));
getParentActivity().speak(PersonalityResponse.getEnrollmentAPIError(getApplicationContext(), sl), LocalRequest.ACTION_SPEAK_ONLY);
SaiyAccountHelper.deleteAccount(getApplicationContext(), accountName, null);
}
use of ai.saiy.android.localisation.SupportedLanguage in project Saiy-PS by brandall76.
the class CustomCommandHelper method commandExists.
/**
* Check if the keyphrase for the custom command already exists
*
* @param dbCustomCommand the {@link DBCustomCommand}
* @param customCommand the prepared {@link CustomCommand}
* @return true if the keyphrase exists, false otherwise
*/
private static Pair<Boolean, Long> commandExists(@NonNull final DBCustomCommand dbCustomCommand, @NonNull final CustomCommand customCommand) {
if (dbCustomCommand.databaseExists()) {
final ArrayList<CustomCommandContainer> customCommandContainerArray = dbCustomCommand.getKeyphrases();
if (UtilsList.notNaked(customCommandContainerArray)) {
if (DEBUG) {
MyLog.i(CLS_NAME, "have commands");
}
final SupportedLanguage sl = SupportedLanguage.getSupportedLanguage(UtilsLocale.stringToLocale(customCommand.getVRLocale()));
final Locale loc = sl.getLocale();
for (final CustomCommandContainer ccc : customCommandContainerArray) {
if (ccc.getKeyphrase().toLowerCase(loc).trim().matches(customCommand.getKeyphrase().toLowerCase(loc).trim())) {
if (DEBUG) {
MyLog.i(CLS_NAME, "keyphrase matched: " + ccc.getKeyphrase() + " ~ " + customCommand.getKeyphrase());
}
return new Pair<>(true, ccc.getRowId());
}
}
if (DEBUG) {
MyLog.i(CLS_NAME, "command is not a duplicate");
}
} else {
if (DEBUG) {
MyLog.i(CLS_NAME, "no commands");
}
}
} else {
if (DEBUG) {
MyLog.i(CLS_NAME, "databaseExists: false");
}
}
return new Pair<>(false, -1L);
}
use of ai.saiy.android.localisation.SupportedLanguage in project Saiy-PS by brandall76.
the class AssistantIntentService method onHandleIntent.
@Override
protected void onHandleIntent(final Intent intent) {
if (DEBUG) {
MyLog.i(CLS_NAME, "onHandleIntent");
examineIntent(intent);
}
final Bundle actionBundle = new Bundle();
actionBundle.putInt(LocalRequest.EXTRA_ACTION, LocalRequest.ACTION_SPEAK_LISTEN);
if (intent != null) {
final Bundle bundle = intent.getExtras();
if (bundle != null) {
final String action = intent.getAction();
if (UtilsString.notNaked(action)) {
if (DEBUG) {
MyLog.i(CLS_NAME, "onHandleIntent: action: " + action);
}
if (intent.getAction().equals(Intent.ACTION_ASSIST)) {
if (DEBUG) {
if (bundle.containsKey(EXTRA_ASSIST_CONTEXT)) {
final Bundle assistBundle = bundle.getBundle(EXTRA_ASSIST_CONTEXT);
MyLog.i(CLS_NAME, "onHandleIntent checking assistBundle");
examineBundle(assistBundle);
}
}
}
}
if (bundle.containsKey(LocalRequest.EXTRA_RECOGNITION_LANGUAGE)) {
final String vrLocale = bundle.getString(LocalRequest.EXTRA_RECOGNITION_LANGUAGE);
if (UtilsString.notNaked(vrLocale)) {
if (DEBUG) {
MyLog.i(CLS_NAME, "onHandleIntent: EXTRA_RECOGNITION_LANGUAGE: " + vrLocale);
}
actionBundle.putString(LocalRequest.EXTRA_RECOGNITION_LANGUAGE, vrLocale);
} else {
if (DEBUG) {
MyLog.i(CLS_NAME, "onHandleIntent: EXTRA_RECOGNITION_LANGUAGE naked");
}
}
} else {
if (DEBUG) {
MyLog.i(CLS_NAME, "onHandleIntent: no EXTRA_RECOGNITION_LANGUAGE");
}
}
if (bundle.containsKey(LocalRequest.EXTRA_TTS_LANGUAGE)) {
final String ttsLocale = bundle.getString(LocalRequest.EXTRA_TTS_LANGUAGE);
if (UtilsString.notNaked(ttsLocale)) {
if (DEBUG) {
MyLog.i(CLS_NAME, "onHandleIntent: EXTRA_TTS_LANGUAGE: " + ttsLocale);
}
actionBundle.putString(LocalRequest.EXTRA_TTS_LANGUAGE, ttsLocale);
} else {
if (DEBUG) {
MyLog.i(CLS_NAME, "onHandleIntent: EXTRA_TTS_LANGUAGE naked");
}
}
} else {
if (DEBUG) {
MyLog.i(CLS_NAME, "onHandleIntent: no EXTRA_TTS_LANGUAGE");
}
}
if (bundle.containsKey(LocalRequest.EXTRA_SUPPORTED_LANGUAGE)) {
final SupportedLanguage supportedLanguage = (SupportedLanguage) bundle.getSerializable(LocalRequest.EXTRA_SUPPORTED_LANGUAGE);
if (supportedLanguage != null) {
actionBundle.putSerializable(LocalRequest.EXTRA_SUPPORTED_LANGUAGE, supportedLanguage);
actionBundle.putString(LocalRequest.EXTRA_UTTERANCE, PersonalityHelper.getIntro(getApplicationContext(), supportedLanguage));
} else {
if (DEBUG) {
MyLog.i(CLS_NAME, "onHandleIntent: EXTRA_SUPPORTED_LANGUAGE null");
}
}
} else {
if (DEBUG) {
MyLog.i(CLS_NAME, "onHandleIntent: no EXTRA_SUPPORTED_LANGUAGE");
}
}
if (bundle.containsKey(RecognizerIntent.EXTRA_SECURE)) {
final Object secureObject = bundle.get(RecognizerIntent.EXTRA_SECURE);
if (secureObject != null) {
boolean secure = false;
if (secureObject instanceof Boolean) {
secure = (boolean) secureObject;
} else if (secureObject instanceof String) {
secure = Boolean.parseBoolean((String) secureObject);
} else {
if (DEBUG) {
MyLog.i(CLS_NAME, "onHandleIntent: EXTRA_SECURE of unknown type ignoring");
}
}
if (secure) {
actionBundle.putInt(LocalRequest.EXTRA_CONDITION, Condition.CONDITION_SECURE);
} else {
if (DEBUG) {
MyLog.i(CLS_NAME, "onHandleIntent: EXTRA_SECURE false ignoring");
}
}
} else {
if (DEBUG) {
MyLog.i(CLS_NAME, "onHandleIntent: secureObject null");
}
}
} else {
if (DEBUG) {
MyLog.i(CLS_NAME, "onHandleIntent: no EXTRA_SECURE");
}
}
} else {
if (DEBUG) {
MyLog.i(CLS_NAME, "onHandleIntent: bundle null ignoring");
}
}
} else {
if (DEBUG) {
MyLog.i(CLS_NAME, "onHandleIntent: intent null ignoring");
}
}
if (!actionBundle.containsKey(LocalRequest.EXTRA_RECOGNITION_LANGUAGE)) {
actionBundle.putString(LocalRequest.EXTRA_RECOGNITION_LANGUAGE, SPH.getVRLocale(getApplicationContext()).toString());
} else {
if (DEBUG) {
MyLog.i(CLS_NAME, "onHandleIntent: actionBundle: auto adding EXTRA_RECOGNITION_LANGUAGE");
}
}
if (!actionBundle.containsKey(LocalRequest.EXTRA_TTS_LANGUAGE)) {
actionBundle.putString(LocalRequest.EXTRA_TTS_LANGUAGE, SPH.getTTSLocale(getApplicationContext()).toString());
} else {
if (DEBUG) {
MyLog.i(CLS_NAME, "onHandleIntent: actionBundle: auto adding EXTRA_TTS_LANGUAGE");
}
}
if (!actionBundle.containsKey(LocalRequest.EXTRA_SUPPORTED_LANGUAGE)) {
@SuppressWarnings("ConstantConditions") final SupportedLanguage sl = SupportedLanguage.getSupportedLanguage(UtilsLocale.stringToLocale(actionBundle.getString(LocalRequest.EXTRA_RECOGNITION_LANGUAGE)));
actionBundle.putSerializable(LocalRequest.EXTRA_SUPPORTED_LANGUAGE, sl);
actionBundle.putString(LocalRequest.EXTRA_UTTERANCE, PersonalityHelper.getIntro(getApplicationContext(), sl));
} else {
if (DEBUG) {
MyLog.i(CLS_NAME, "onHandleIntent: actionBundle: auto adding EXTRA_SUPPORTED_LANGUAGE");
}
}
new LocalRequest(getApplicationContext(), actionBundle).execute();
}
use of ai.saiy.android.localisation.SupportedLanguage in project Saiy-PS by brandall76.
the class LocalRequest method prepareDefault.
/**
* Utility method to cut down on boiler plate requests
*
* @param action to perform
* @param utterance to speak
*/
public void prepareDefault(final int action, @Nullable final String utterance) {
final Locale vrLocale = SPH.getVRLocale(weakContext.get());
final SupportedLanguage sl = SupportedLanguage.getSupportedLanguage(vrLocale);
bundle.putInt(LocalRequest.EXTRA_ACTION, action);
bundle.putString(LocalRequest.EXTRA_UTTERANCE, utterance);
bundle.putString(LocalRequest.EXTRA_RECOGNITION_LANGUAGE, vrLocale.toString());
bundle.putString(LocalRequest.EXTRA_TTS_LANGUAGE, SPH.getTTSLocale(weakContext.get()).toString());
bundle.putSerializable(LocalRequest.EXTRA_SUPPORTED_LANGUAGE, sl);
}
use of ai.saiy.android.localisation.SupportedLanguage in project Saiy-PS by brandall76.
the class SelfAwareConditions method getSupportedLanguage.
/**
* Get the supported language of the {@link Locale} which will enable us to apply any resource
* localisation when resolving a command.
*
* @param servingRemote true if the request is remote
* @return the {@link SupportedLanguage}
*/
public SupportedLanguage getSupportedLanguage(final boolean servingRemote) {
if (DEBUG) {
MyLog.i(CLS_NAME, "getSupportedLanguage");
}
SupportedLanguage sl = (SupportedLanguage) getBundle().getSerializable(LocalRequest.EXTRA_SUPPORTED_LANGUAGE);
if (sl != null) {
return sl;
} else {
if (DEBUG) {
MyLog.i(CLS_NAME, "getSupportedLanguage: adding to bundle");
}
sl = SupportedLanguage.getSupportedLanguage(getVRLocale(servingRemote));
getBundle().putSerializable(LocalRequest.EXTRA_SUPPORTED_LANGUAGE, sl);
return sl;
}
}
Aggregations