Skip to content

Commit

Permalink
Small fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
Kaljurand committed Jul 12, 2020
1 parent 795166e commit 2897e4c
Show file tree
Hide file tree
Showing 6 changed files with 30 additions and 26 deletions.
5 changes: 3 additions & 2 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ dependencies {
implementation 'androidx.appcompat:appcompat:1.1.0'
implementation 'androidx.preference:preference:1.1.1'
implementation 'androidx.recyclerview:recyclerview:1.1.0'
//implementation 'androidx.activity:activity:1.2.0-alpha06'
implementation 'androidx.dynamicanimation:dynamicanimation:1.0.0'
implementation 'com.google.android.material:material:1.1.0'
}
Expand All @@ -25,8 +26,8 @@ android {
applicationId 'ee.ioc.phon.android.speak'
minSdkVersion 16
targetSdkVersion 30
versionCode 1732
versionName '1.7.32'
versionCode 1733
versionName '1.7.33'
vectorDrawables.useSupportLibrary = true
// Keep only en and et resources
resConfigs "en", "et"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,6 @@
import android.widget.TextView;
import android.widget.Toast;

import androidx.annotation.NonNull;
import androidx.appcompat.app.AppCompatActivity;

import java.io.FileNotFoundException;
Expand Down Expand Up @@ -312,20 +311,13 @@ protected void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
}

@Override
public void onRequestPermissionsResult(int requestCode, @NonNull String permissions[], @NonNull int[] grantResults) {
switch (requestCode) {
case PERMISSION_REQUEST_RECORD_AUDIO: {
if (grantResults.length > 0 && grantResults[0] == PackageManager.PERMISSION_GRANTED) {
showError("");
setTvPrompt();
} else {
setTvPrompt(getString(R.string.promptPermissionRationale));
}
break;
}
default: {
break;
public void onRequestPermissionsResults(int requestCode, String[] permissions, int[] grantResults) {
if (requestCode == PERMISSION_REQUEST_RECORD_AUDIO) {
if (grantResults.length > 0 && grantResults[0] == PackageManager.PERMISSION_GRANTED) {
showError("");
setTvPrompt();
} else {
setTvPrompt(getString(R.string.promptPermissionRationale));
}
}
}
Expand Down Expand Up @@ -607,7 +599,8 @@ protected void sayVoicePrompt(final TtsProvider.Listener listener) {
}

// TODO: use it to speak errors if EXTRA_SPEAK_ERRORS
private void sayVoicePrompt(final String lang, final String prompt, final TtsProvider.Listener listener) {
private void sayVoicePrompt(final String lang, final String prompt,
final TtsProvider.Listener listener) {
mTts = new TtsProvider(this, status -> {
if (status == TextToSpeech.SUCCESS) {
Locale locale = mTts.chooseLanguage(lang);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,6 @@ public void onCreate(Bundle savedInstanceState) {
*/
setUpActivity(R.layout.activity_recognizer);
registerPrompt(findViewById(R.id.tvPrompt));

}

@Override
Expand Down
10 changes: 8 additions & 2 deletions app/src/main/java/ee/ioc/phon/android/speak/model/Rewrites.java
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,12 @@ public SpannableStringBuilder[] getRules(CommandMatcher commandMatcher) {
return array;
}

/**
* Saves the rewrites under a new name. If the new name equals the old name, then nothing is done.
* If the new name is null then the rewrites are deleted.
*
* @param newName New name of the rewrites or null if the rewrites should be deleted.
*/
public void rename(String newName) {
if (!mId.equals(newName)) {
if (newName != null) {
Expand All @@ -123,9 +129,9 @@ public void rename(String newName) {
Set<String> deleteKeys = new HashSet<>();
deleteKeys.add(mId);
PreferenceUtils.clearPrefMap(mPrefs, mRes, R.string.keyRewritesMap, deleteKeys);
// Replace the name in the defaults
Set<String> defaults = new HashSet<>(getDefaults());
if (defaults.contains(mId)) {
defaults.remove(mId);
if (defaults.remove(mId)) {
if (newName != null) {
defaults.add(newName);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,8 +80,9 @@ public void onCreate() {
if (clip != null) {
UtteranceRewriter ur = mRuleManager.addRecent(clip.toString(), rewritesClip);
PreferenceUtils.putPrefMapEntry(mPrefs, mRes, R.string.keyRewritesMap, REWRITES_NAME_CLIP, ur.toTsv());
// TODO: update rewriters because the tables have changed
//mCommandEditor.setRewriters(Utils.makeList(Utils.genRewriters(mPrefs, mRes, null, language, service, app)));
mCommandEditor.setRewriters(
Utils.makeList(
Utils.genRewriters(mPrefs, mRes, null, mRuleManager.getCommandMatcher())));
}
});
}
Expand Down Expand Up @@ -363,8 +364,12 @@ private void commitResults(List<String> results) {
UtteranceRewriter ur = mRuleManager.addFrequent(editorResult, rewritesFreq);
PreferenceUtils.putPrefMapEntry(mPrefs, mRes, R.string.keyRewritesMap, REWRITES_NAME_FREQUENT, ur.toTsv());
}
// TODO: update rewriters because the tables have changed
//mCommandEditor.setRewriters(Utils.makeList(Utils.genRewriters(mPrefs, mRes, null, language, service, app)));
// Update rewriters because the tables have changed
if (rewritesRec != null || rewritesFreq != null) {
mCommandEditor.setRewriters(
Utils.makeList(
Utils.genRewriters(mPrefs, mRes, null, mRuleManager.getCommandMatcher())));
}
}
}

Expand Down

0 comments on commit 2897e4c

Please sign in to comment.