mirror of
https://github.com/Helium314/HeliBoard.git
synced 2025-05-19 00:10:20 +00:00
hopefully fix spell checker language detection
This commit is contained in:
parent
445eb37b5f
commit
529839b6c8
4 changed files with 28 additions and 36 deletions
|
@ -248,7 +248,8 @@ private fun loadEnabledSubtypes(context: Context) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private var initialized = false
|
var initialized = false
|
||||||
|
private set
|
||||||
private val enabledSubtypes = mutableListOf<InputMethodSubtype>()
|
private val enabledSubtypes = mutableListOf<InputMethodSubtype>()
|
||||||
private val resourceSubtypesByLocale = LinkedHashMap<String, MutableList<InputMethodSubtype>>(100)
|
private val resourceSubtypesByLocale = LinkedHashMap<String, MutableList<InputMethodSubtype>>(100)
|
||||||
private val additionalSubtypes = mutableListOf<InputMethodSubtype>()
|
private val additionalSubtypes = mutableListOf<InputMethodSubtype>()
|
||||||
|
|
|
@ -17,6 +17,7 @@
|
||||||
package org.dslul.openboard.inputmethod.latin.spellcheck;
|
package org.dslul.openboard.inputmethod.latin.spellcheck;
|
||||||
|
|
||||||
import android.content.ContentResolver;
|
import android.content.ContentResolver;
|
||||||
|
import android.content.SharedPreferences;
|
||||||
import android.database.ContentObserver;
|
import android.database.ContentObserver;
|
||||||
import android.os.Binder;
|
import android.os.Binder;
|
||||||
import android.provider.UserDictionary.Words;
|
import android.provider.UserDictionary.Words;
|
||||||
|
@ -38,6 +39,9 @@ import org.dslul.openboard.inputmethod.latin.common.LocaleUtils;
|
||||||
import org.dslul.openboard.inputmethod.latin.common.StringUtils;
|
import org.dslul.openboard.inputmethod.latin.common.StringUtils;
|
||||||
import org.dslul.openboard.inputmethod.latin.define.DebugFlags;
|
import org.dslul.openboard.inputmethod.latin.define.DebugFlags;
|
||||||
import com.android.inputmethod.latin.utils.BinaryDictionaryUtils;
|
import com.android.inputmethod.latin.utils.BinaryDictionaryUtils;
|
||||||
|
|
||||||
|
import org.dslul.openboard.inputmethod.latin.settings.SubtypeSettingsKt;
|
||||||
|
import org.dslul.openboard.inputmethod.latin.utils.DeviceProtectedUtils;
|
||||||
import org.dslul.openboard.inputmethod.latin.utils.ScriptUtils;
|
import org.dslul.openboard.inputmethod.latin.utils.ScriptUtils;
|
||||||
import org.dslul.openboard.inputmethod.latin.utils.StatsUtils;
|
import org.dslul.openboard.inputmethod.latin.utils.StatsUtils;
|
||||||
import org.dslul.openboard.inputmethod.latin.utils.SuggestionResults;
|
import org.dslul.openboard.inputmethod.latin.utils.SuggestionResults;
|
||||||
|
@ -148,17 +152,21 @@ public abstract class AndroidWordLevelSpellCheckerSession extends Session {
|
||||||
|
|
||||||
final InputMethodManager imm;
|
final InputMethodManager imm;
|
||||||
if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.M) {
|
if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.M) {
|
||||||
imm = mService.getApplicationContext()
|
imm = mService.getApplicationContext().getSystemService(InputMethodManager.class);
|
||||||
.getSystemService(InputMethodManager.class);
|
|
||||||
if (imm != null) {
|
if (imm != null) {
|
||||||
final InputMethodSubtype currentInputMethodSubtype =
|
final InputMethodSubtype currentInputMethodSubtype = imm.getCurrentInputMethodSubtype();
|
||||||
imm.getCurrentInputMethodSubtype();
|
|
||||||
if (currentInputMethodSubtype != null) {
|
if (currentInputMethodSubtype != null) {
|
||||||
final String localeString = currentInputMethodSubtype.getLocale();
|
final String localeString = currentInputMethodSubtype.getLocale();
|
||||||
if (!TextUtils.isEmpty(localeString)) {
|
if (!TextUtils.isEmpty(localeString)) {
|
||||||
// Use keyboard locale if available in the spell checker
|
// Use keyboard locale if available in the spell checker
|
||||||
return localeString;
|
return localeString;
|
||||||
}
|
}
|
||||||
|
// localeString for this app is always empty, get it from settings if possible
|
||||||
|
// and we're sure this app is used
|
||||||
|
if (SubtypeSettingsKt.getInitialized() && "dummy".equals(currentInputMethodSubtype.getExtraValue())) {
|
||||||
|
final SharedPreferences prefs = DeviceProtectedUtils.getSharedPreferences(mService);
|
||||||
|
return SubtypeSettingsKt.getSelectedSubtype(prefs).getLocale();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -253,8 +261,7 @@ public abstract class AndroidWordLevelSpellCheckerSession extends Session {
|
||||||
// If the lower case version is not in the dictionary, it's still possible
|
// If the lower case version is not in the dictionary, it's still possible
|
||||||
// that we have an all-caps version of a word that needs to be capitalized
|
// that we have an all-caps version of a word that needs to be capitalized
|
||||||
// according to the dictionary. E.g. "GERMANS" only exists in the dictionary as "Germans".
|
// according to the dictionary. E.g. "GERMANS" only exists in the dictionary as "Germans".
|
||||||
return mService.isValidWord(mLocale,
|
return mService.isValidWord(mLocale, StringUtils.capitalizeFirstAndDowncaseRest(lowerCaseText, mLocale));
|
||||||
StringUtils.capitalizeFirstAndDowncaseRest(lowerCaseText, mLocale));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Note : this must be reentrant
|
// Note : this must be reentrant
|
||||||
|
@ -274,11 +281,10 @@ public abstract class AndroidWordLevelSpellCheckerSession extends Session {
|
||||||
updateLocale();
|
updateLocale();
|
||||||
// It's good to keep this not local specific since the standard
|
// It's good to keep this not local specific since the standard
|
||||||
// ones may show up in other languages also.
|
// ones may show up in other languages also.
|
||||||
String text = textInfo.getText().
|
String text = textInfo.getText()
|
||||||
replaceAll(AndroidSpellCheckerService.APOSTROPHE,
|
.replaceAll(AndroidSpellCheckerService.APOSTROPHE, AndroidSpellCheckerService.SINGLE_QUOTE)
|
||||||
AndroidSpellCheckerService.SINGLE_QUOTE).
|
.replaceAll("^" + quotesRegexp, "")
|
||||||
replaceAll("^" + quotesRegexp, "").
|
.replaceAll(quotesRegexp + "$", "");
|
||||||
replaceAll(quotesRegexp + "$", "");
|
|
||||||
|
|
||||||
final String localeRegex = scriptToPunctuationRegexMap.get(
|
final String localeRegex = scriptToPunctuationRegexMap.get(
|
||||||
ScriptUtils.getScriptFromSpellCheckerLocale(mLocale)
|
ScriptUtils.getScriptFromSpellCheckerLocale(mLocale)
|
||||||
|
@ -289,8 +295,7 @@ public abstract class AndroidWordLevelSpellCheckerSession extends Session {
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!mService.hasMainDictionaryForLocale(mLocale)) {
|
if (!mService.hasMainDictionaryForLocale(mLocale)) {
|
||||||
return AndroidSpellCheckerService.getNotInDictEmptySuggestions(
|
return AndroidSpellCheckerService.getNotInDictEmptySuggestions(false /* reportAsTypo */);
|
||||||
false /* reportAsTypo */);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Handle special patterns like email, URI, telephone number.
|
// Handle special patterns like email, URI, telephone number.
|
||||||
|
|
|
@ -16,46 +16,31 @@
|
||||||
|
|
||||||
package org.dslul.openboard.inputmethod.latin.spellcheck;
|
package org.dslul.openboard.inputmethod.latin.spellcheck;
|
||||||
|
|
||||||
import android.annotation.TargetApi;
|
|
||||||
import android.content.Intent;
|
|
||||||
import android.os.Build;
|
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
import android.preference.PreferenceActivity;
|
|
||||||
|
|
||||||
import org.dslul.openboard.inputmethod.latin.permissions.PermissionsManager;
|
import org.dslul.openboard.inputmethod.latin.permissions.PermissionsManager;
|
||||||
import org.dslul.openboard.inputmethod.latin.utils.FragmentUtils;
|
|
||||||
|
|
||||||
|
import androidx.appcompat.app.AppCompatActivity;
|
||||||
import androidx.core.app.ActivityCompat;
|
import androidx.core.app.ActivityCompat;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Spell checker preference screen.
|
* Spell checker preference screen.
|
||||||
*/
|
*/
|
||||||
public final class SpellCheckerSettingsActivity extends PreferenceActivity
|
public final class SpellCheckerSettingsActivity extends AppCompatActivity
|
||||||
implements ActivityCompat.OnRequestPermissionsResultCallback {
|
implements ActivityCompat.OnRequestPermissionsResultCallback {
|
||||||
private static final String DEFAULT_FRAGMENT = SpellCheckerSettingsFragment.class.getName();
|
private static final String DEFAULT_FRAGMENT = SpellCheckerSettingsFragment.class.getName();
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void onCreate(Bundle savedInstanceState) {
|
protected void onCreate(Bundle savedInstanceState) {
|
||||||
super.onCreate(savedInstanceState);
|
super.onCreate(savedInstanceState);
|
||||||
|
getSupportFragmentManager().beginTransaction()
|
||||||
|
.replace(android.R.id.content, new SpellCheckerSettingsFragment())
|
||||||
|
.commit();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Intent getIntent() {
|
public void onRequestPermissionsResult(int requestCode, String[] permissions, int[] grantResults) {
|
||||||
final Intent modIntent = new Intent(super.getIntent());
|
super.onRequestPermissionsResult(requestCode, permissions, grantResults);
|
||||||
modIntent.putExtra(EXTRA_SHOW_FRAGMENT, DEFAULT_FRAGMENT);
|
|
||||||
modIntent.putExtra(EXTRA_NO_HEADERS, true);
|
|
||||||
return modIntent;
|
|
||||||
}
|
|
||||||
|
|
||||||
@TargetApi(Build.VERSION_CODES.KITKAT)
|
|
||||||
@Override
|
|
||||||
public boolean isValidFragment(String fragmentName) {
|
|
||||||
return FragmentUtils.isValidFragment(fragmentName);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onRequestPermissionsResult(
|
|
||||||
int requestCode, String[] permissions, int[] grantResults) {
|
|
||||||
PermissionsManager.get(this).onRequestPermissionsResult(
|
PermissionsManager.get(this).onRequestPermissionsResult(
|
||||||
requestCode, permissions, grantResults);
|
requestCode, permissions, grantResults);
|
||||||
}
|
}
|
||||||
|
|
|
@ -16,6 +16,7 @@ the system picker crashes on some devices for unknown reasons.
|
||||||
android:isDefault="@bool/im_is_default"
|
android:isDefault="@bool/im_is_default"
|
||||||
android:supportsSwitchingToNextInputMethod="true">
|
android:supportsSwitchingToNextInputMethod="true">
|
||||||
<subtype android:icon="@drawable/ic_ime_switcher_dark"
|
<subtype android:icon="@drawable/ic_ime_switcher_dark"
|
||||||
|
android:imeSubtypeExtraValue="dummy"
|
||||||
android:imeSubtypeMode="keyboard"
|
android:imeSubtypeMode="keyboard"
|
||||||
android:isAsciiCapable="true"
|
android:isAsciiCapable="true"
|
||||||
/>
|
/>
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue