Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.RECORD_AUDIO" />

<application
android:icon="@drawable/icon"
Expand Down Expand Up @@ -58,5 +59,9 @@
android:authorities="com.maxistar.authority"
android:exported="false" />
</application>

<queries>
<intent>
<action android:name="android.speech.RecognitionService" />
</intent>
</queries>
</manifest>
Original file line number Diff line number Diff line change
Expand Up @@ -39,10 +39,12 @@
import android.view.KeyEvent;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.view.inputmethod.EditorInfo;
import android.webkit.WebView;
import android.webkit.WebViewClient;
import android.widget.EditText;
import android.widget.ProgressBar;
import android.widget.ScrollView;
import android.widget.SearchView;
import android.widget.Toast;
Expand All @@ -53,6 +55,7 @@
import com.maxistar.textpad.ServiceLocator;
import com.maxistar.textpad.service.SettingsService;
import com.maxistar.textpad.TPStrings;
import com.maxistar.textpad.tts.Dictator;
import com.maxistar.textpad.service.AlternativeUrlsService;
import com.maxistar.textpad.service.RecentFilesService;
import com.maxistar.textpad.service.ThemeService;
Expand Down Expand Up @@ -106,7 +109,7 @@ public class EditorActivity extends AppCompatActivity {

Uri lastTriedSystemUri = null;


boolean changed = false;

boolean exitDialogShown = false;
Expand Down Expand Up @@ -309,7 +312,7 @@ public void onSaveInstanceState(@NonNull Bundle outState) {
protected void onStop() {
super.onStop();
}

@Override
public void onBackPressed() {
if (this.changed && !exitDialogShown) {
Expand Down Expand Up @@ -475,7 +478,7 @@ public boolean onPrepareOptionsMenu(Menu menu) {

MenuItem redoMenu = menu.findItem(R.id.menu_edit_redo);
redoMenu.setEnabled(editTextUndoRedo.getCanRedo());

updateRecentFiles(menu);

if (android.os.Build.VERSION.SDK_INT < Build.VERSION_CODES.LOLLIPOP) {
Expand Down Expand Up @@ -608,6 +611,8 @@ public boolean onOptionsItemSelected(@NonNull MenuItem item) {
openRecentFile(4);
} else if (itemId == R.id.menu_document_new) {
newFile();
} else if (itemId == R.id.menu_dictate) {
startDictation();
} else if (itemId == R.id.menu_document_save) {
saveFile();
} else if (itemId == R.id.menu_document_save_as) {
Expand Down Expand Up @@ -709,6 +714,13 @@ private void showSettings() {
}
}

private void startDictation() {
ProgressBar view = findViewById(R.id.speechProgressBar);
view.setVisibility(View.VISIBLE);
Dictator dictator = new Dictator();
dictator.startDictation(mText, this, view);
}

private void showSettingsActivity() {
Intent intent = new Intent(this.getBaseContext(),
SettingsActivity.class);
Expand Down Expand Up @@ -859,7 +871,7 @@ protected void exitApplication() {
System.exitFromApp(EditorActivity.this);
}
}

protected void selectFileUsingAndroidSystemPicker() {
Intent intent = new Intent(Intent.ACTION_OPEN_DOCUMENT);
intent.addCategory(Intent.CATEGORY_OPENABLE);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
package com.maxistar.textpad.nlp.tokenizer;

import java.util.ArrayList;

public class GenericTokenizer {
final static int MODE_DEFAULT = 0;
final static int MODE_PUNCTUATION = 1;
final static int MODE_WHITESPACE = 2;
final static int MODE_WORD = 3;

public String[] tokenizeString(String input) {
int length = input.length();
int mode = MODE_DEFAULT;
ArrayList<String> result = new ArrayList<>();
StringBuilder currentWord = new StringBuilder();
for (int i = 0; i < length; i++) {
String currentChar = input.substring(i, i + 1);
if (mode == MODE_WORD) {
if (isLetter(currentChar)) {
currentWord.append(currentChar);
} else if (isPunctuation(currentChar)) {
result.add(currentWord.toString());
result.add(currentChar);
mode = MODE_PUNCTUATION;
currentWord = new StringBuilder();
} else if (isWhitespace(currentChar)) {
result.add(currentWord.toString());
result.add(currentChar);
mode = MODE_WHITESPACE;
currentWord = new StringBuilder();
}
} else if (mode == MODE_PUNCTUATION) {
if (isLetter(currentChar)) {
currentWord.append(currentChar);
mode = MODE_WORD;
} else if (isPunctuation(currentChar)) {
result.add(currentChar);
} else if (isWhitespace(currentChar)) {
result.add(currentChar);
mode = MODE_WHITESPACE;
}
} else if (mode == MODE_WHITESPACE) {
if (isLetter(currentChar)) {
currentWord.append(currentChar);
mode = MODE_WORD;
} else if (isPunctuation(currentChar)) {
result.add(currentChar);
mode = MODE_PUNCTUATION;
} else if (isWhitespace(currentChar)) {
result.add(currentChar);
}
} else {
if (isLetter(currentChar)) {
currentWord.append(currentChar);
mode = MODE_WORD;
} else if (isPunctuation(currentChar)) {
result.add(currentChar);
mode = MODE_PUNCTUATION;
} else if (isWhitespace(currentChar)) {
result.add(currentChar);
mode = MODE_WHITESPACE;
}
}
}
String[] res = new String[result.size()];
return result.toArray(res);
}

private boolean isWhitespace(String currentChar) {
return currentChar.equals(" ") || currentChar.equals("\n");
}

private boolean isPunctuation(String currentChar) {
return currentChar.matches("[—?,:;.…!«»)(]");
}

private boolean isLetter(String currentChar) {
return currentChar.matches("[a-zA-Zа-яА-Я\\-]");
}
}
Loading