mirror of
https://github.com/Helium314/HeliBoard.git
synced 2025-05-17 23:42:55 +00:00
address some warnings, migrate user dictionary settings to androidx
This commit is contained in:
parent
c6efd5a843
commit
cc84ff6a00
8 changed files with 47 additions and 55 deletions
|
@ -17,7 +17,7 @@ interface Combiner {
|
||||||
* @param event the event to combine with the existing state.
|
* @param event the event to combine with the existing state.
|
||||||
* @return the resulting event.
|
* @return the resulting event.
|
||||||
*/
|
*/
|
||||||
fun processEvent(previousEvents: ArrayList<Event>?, event: Event?): Event?
|
fun processEvent(previousEvents: ArrayList<Event>?, event: Event?): Event
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get the feedback that should be shown to the user for the current state of this combiner.
|
* Get the feedback that should be shown to the user for the current state of this combiner.
|
||||||
|
|
|
@ -46,13 +46,13 @@ class CombinerChain(initialText: String?) {
|
||||||
* new event. However it may never be null.
|
* new event. However it may never be null.
|
||||||
*/
|
*/
|
||||||
fun processEvent(previousEvents: ArrayList<Event>?,
|
fun processEvent(previousEvents: ArrayList<Event>?,
|
||||||
newEvent: Event?): Event? {
|
newEvent: Event): Event {
|
||||||
val modifiablePreviousEvents = ArrayList(previousEvents!!)
|
val modifiablePreviousEvents = ArrayList(previousEvents!!)
|
||||||
var event = newEvent
|
var event = newEvent
|
||||||
for (combiner in mCombiners) { // A combiner can never return more than one event; it can return several
|
for (combiner in mCombiners) { // A combiner can never return more than one event; it can return several
|
||||||
// code points, but they should be encapsulated within one event.
|
// code points, but they should be encapsulated within one event.
|
||||||
event = combiner.processEvent(modifiablePreviousEvents, event)
|
event = combiner.processEvent(modifiablePreviousEvents, event)
|
||||||
if (event!!.isConsumed) { // If the event is consumed, then we don't pass it to subsequent combiners:
|
if (event.isConsumed) { // If the event is consumed, then we don't pass it to subsequent combiners:
|
||||||
// they should not see it at all.
|
// they should not see it at all.
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
|
|
|
@ -188,11 +188,11 @@ class DeadKeyCombiner : Combiner {
|
||||||
// TODO: make this a list of events instead
|
// TODO: make this a list of events instead
|
||||||
val mDeadSequence = StringBuilder()
|
val mDeadSequence = StringBuilder()
|
||||||
|
|
||||||
override fun processEvent(previousEvents: ArrayList<Event>?, event: Event?): Event? {
|
override fun processEvent(previousEvents: ArrayList<Event>?, event: Event?): Event {
|
||||||
if (TextUtils.isEmpty(mDeadSequence)) { // No dead char is currently being tracked: this is the most common case.
|
if (TextUtils.isEmpty(mDeadSequence)) { // No dead char is currently being tracked: this is the most common case.
|
||||||
if (event!!.isDead) { // The event was a dead key. Start tracking it.
|
if (event!!.isDead) { // The event was a dead key. Start tracking it.
|
||||||
mDeadSequence.appendCodePoint(event.mCodePoint)
|
mDeadSequence.appendCodePoint(event.mCodePoint)
|
||||||
return Event.Companion.createConsumedEvent(event)
|
return Event.createConsumedEvent(event)
|
||||||
}
|
}
|
||||||
// Regular keystroke when not keeping track of a dead key. Simply said, there are
|
// Regular keystroke when not keeping track of a dead key. Simply said, there are
|
||||||
// no dead keys at all in the current input, so this combiner has nothing to do and
|
// no dead keys at all in the current input, so this combiner has nothing to do and
|
||||||
|
@ -201,8 +201,7 @@ class DeadKeyCombiner : Combiner {
|
||||||
}
|
}
|
||||||
if (Character.isWhitespace(event!!.mCodePoint)
|
if (Character.isWhitespace(event!!.mCodePoint)
|
||||||
|| event.mCodePoint == mDeadSequence.codePointBefore(mDeadSequence.length)) { // When whitespace or twice the same dead key, we should output the dead sequence as is.
|
|| event.mCodePoint == mDeadSequence.codePointBefore(mDeadSequence.length)) { // When whitespace or twice the same dead key, we should output the dead sequence as is.
|
||||||
val resultEvent = createEventChainFromSequence(mDeadSequence.toString(),
|
val resultEvent = createEventChainFromSequence(mDeadSequence.toString(), event)
|
||||||
event)
|
|
||||||
mDeadSequence.setLength(0)
|
mDeadSequence.setLength(0)
|
||||||
return resultEvent
|
return resultEvent
|
||||||
}
|
}
|
||||||
|
@ -211,13 +210,13 @@ class DeadKeyCombiner : Combiner {
|
||||||
val trimIndex = mDeadSequence.length - Character.charCount(
|
val trimIndex = mDeadSequence.length - Character.charCount(
|
||||||
mDeadSequence.codePointBefore(mDeadSequence.length))
|
mDeadSequence.codePointBefore(mDeadSequence.length))
|
||||||
mDeadSequence.setLength(trimIndex)
|
mDeadSequence.setLength(trimIndex)
|
||||||
return Event.Companion.createConsumedEvent(event)
|
return Event.createConsumedEvent(event)
|
||||||
}
|
}
|
||||||
return event
|
return event
|
||||||
}
|
}
|
||||||
if (event.isDead) {
|
if (event.isDead) {
|
||||||
mDeadSequence.appendCodePoint(event.mCodePoint)
|
mDeadSequence.appendCodePoint(event.mCodePoint)
|
||||||
return Event.Companion.createConsumedEvent(event)
|
return Event.createConsumedEvent(event)
|
||||||
}
|
}
|
||||||
// Combine normally.
|
// Combine normally.
|
||||||
val sb = StringBuilder()
|
val sb = StringBuilder()
|
||||||
|
@ -248,17 +247,16 @@ class DeadKeyCombiner : Combiner {
|
||||||
get() = mDeadSequence
|
get() = mDeadSequence
|
||||||
|
|
||||||
companion object {
|
companion object {
|
||||||
private fun createEventChainFromSequence(text: CharSequence,
|
private fun createEventChainFromSequence(text: CharSequence, originalEvent: Event): Event {
|
||||||
originalEvent: Event?): Event? {
|
|
||||||
var index = text.length
|
var index = text.length
|
||||||
if (index <= 0) {
|
if (index <= 0) {
|
||||||
return originalEvent
|
return originalEvent
|
||||||
}
|
}
|
||||||
var lastEvent: Event? = null
|
lateinit var lastEvent: Event
|
||||||
do {
|
do {
|
||||||
val codePoint = Character.codePointBefore(text, index)
|
val codePoint = Character.codePointBefore(text, index)
|
||||||
lastEvent = Event.Companion.createHardwareKeypressEvent(codePoint,
|
lastEvent = Event.createHardwareKeypressEvent(codePoint,
|
||||||
originalEvent!!.mKeyCode, lastEvent, false /* isKeyRepeat */)
|
originalEvent.mKeyCode, lastEvent, false /* isKeyRepeat */)
|
||||||
index -= Character.charCount(codePoint)
|
index -= Character.charCount(codePoint)
|
||||||
} while (index > 0)
|
} while (index > 0)
|
||||||
return lastEvent
|
return lastEvent
|
||||||
|
|
|
@ -175,8 +175,7 @@ public class NgramContext {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
final String[] contextStringArray = prevTermList.toArray(new String[prevTermList.size()]);
|
return prevTermList.toArray(new String[prevTermList.size()]);
|
||||||
return contextStringArray;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean isValid() {
|
public boolean isValid() {
|
||||||
|
@ -227,7 +226,7 @@ public class NgramContext {
|
||||||
public int hashCode() {
|
public int hashCode() {
|
||||||
int hashValue = 0;
|
int hashValue = 0;
|
||||||
for (final WordInfo wordInfo : mPrevWordsInfo) {
|
for (final WordInfo wordInfo : mPrevWordsInfo) {
|
||||||
if (wordInfo == null || !WordInfo.EMPTY_WORD_INFO.equals(wordInfo)) {
|
if (!WordInfo.EMPTY_WORD_INFO.equals(wordInfo)) {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
hashValue ^= wordInfo.hashCode();
|
hashValue ^= wordInfo.hashCode();
|
||||||
|
@ -267,7 +266,7 @@ public class NgramContext {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String toString() {
|
public String toString() {
|
||||||
final StringBuffer builder = new StringBuffer();
|
final StringBuilder builder = new StringBuilder();
|
||||||
for (int i = 0; i < mPrevWordsCount; i++) {
|
for (int i = 0; i < mPrevWordsCount; i++) {
|
||||||
final WordInfo wordInfo = mPrevWordsInfo[i];
|
final WordInfo wordInfo = mPrevWordsInfo[i];
|
||||||
builder.append("PrevWord[");
|
builder.append("PrevWord[");
|
||||||
|
|
|
@ -127,7 +127,7 @@ public final class WordComposer {
|
||||||
refreshTypedWordCache();
|
refreshTypedWordCache();
|
||||||
}
|
}
|
||||||
|
|
||||||
private final void refreshTypedWordCache() {
|
private void refreshTypedWordCache() {
|
||||||
mTypedWordCache = mCombinerChain.getComposingWordWithCombiningFeedback();
|
mTypedWordCache = mCombinerChain.getComposingWordWithCombiningFeedback();
|
||||||
mCodePointSize = Character.codePointCount(mTypedWordCache, 0, mTypedWordCache.length());
|
mCodePointSize = Character.codePointCount(mTypedWordCache, 0, mTypedWordCache.length());
|
||||||
}
|
}
|
||||||
|
@ -144,7 +144,7 @@ public final class WordComposer {
|
||||||
return size() == 1;
|
return size() == 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
public final boolean isComposingWord() {
|
public boolean isComposingWord() {
|
||||||
return size() > 0;
|
return size() > 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -83,15 +83,13 @@ public class UserDictionaryAddWordContents {
|
||||||
// it's too long to be edited.
|
// it's too long to be edited.
|
||||||
mWordEditText.setSelection(mWordEditText.getText().length());
|
mWordEditText.setSelection(mWordEditText.getText().length());
|
||||||
}
|
}
|
||||||
final String shortcut;
|
|
||||||
if (UserDictionarySettings.IS_SHORTCUT_API_SUPPORTED) {
|
if (UserDictionarySettings.IS_SHORTCUT_API_SUPPORTED) {
|
||||||
shortcut = args.getString(EXTRA_SHORTCUT);
|
final String shortcut = args.getString(EXTRA_SHORTCUT);
|
||||||
if (null != shortcut && null != mShortcutEditText) {
|
if (null != shortcut && null != mShortcutEditText) {
|
||||||
mShortcutEditText.setText(shortcut);
|
mShortcutEditText.setText(shortcut);
|
||||||
}
|
}
|
||||||
mOldShortcut = args.getString(EXTRA_SHORTCUT);
|
mOldShortcut = args.getString(EXTRA_SHORTCUT);
|
||||||
} else {
|
} else {
|
||||||
shortcut = null;
|
|
||||||
mOldShortcut = null;
|
mOldShortcut = null;
|
||||||
}
|
}
|
||||||
mMode = args.getInt(EXTRA_MODE); // default return value for #getInt() is 0 = MODE_EDIT
|
mMode = args.getInt(EXTRA_MODE); // default return value for #getInt() is 0 = MODE_EDIT
|
||||||
|
|
|
@ -22,9 +22,6 @@ import android.content.Intent;
|
||||||
import android.database.Cursor;
|
import android.database.Cursor;
|
||||||
import android.os.Build;
|
import android.os.Build;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
import android.preference.Preference;
|
|
||||||
import android.preference.PreferenceFragment;
|
|
||||||
import android.preference.PreferenceGroup;
|
|
||||||
import android.provider.UserDictionary;
|
import android.provider.UserDictionary;
|
||||||
import android.text.TextUtils;
|
import android.text.TextUtils;
|
||||||
import android.view.inputmethod.InputMethodInfo;
|
import android.view.inputmethod.InputMethodInfo;
|
||||||
|
@ -32,6 +29,9 @@ import android.view.inputmethod.InputMethodManager;
|
||||||
import android.view.inputmethod.InputMethodSubtype;
|
import android.view.inputmethod.InputMethodSubtype;
|
||||||
|
|
||||||
import androidx.annotation.Nullable;
|
import androidx.annotation.Nullable;
|
||||||
|
import androidx.preference.Preference;
|
||||||
|
import androidx.preference.PreferenceFragmentCompat;
|
||||||
|
import androidx.preference.PreferenceGroup;
|
||||||
|
|
||||||
import org.dslul.openboard.inputmethod.latin.R;
|
import org.dslul.openboard.inputmethod.latin.R;
|
||||||
import org.dslul.openboard.inputmethod.latin.common.LocaleUtils;
|
import org.dslul.openboard.inputmethod.latin.common.LocaleUtils;
|
||||||
|
@ -44,18 +44,17 @@ import java.util.TreeSet;
|
||||||
// packages/apps/Settings/src/com/android/settings/inputmethod/UserDictionaryList.java
|
// packages/apps/Settings/src/com/android/settings/inputmethod/UserDictionaryList.java
|
||||||
// in order to deal with some devices that have issues with the user dictionary handling
|
// in order to deal with some devices that have issues with the user dictionary handling
|
||||||
|
|
||||||
public class UserDictionaryList extends PreferenceFragment {
|
public class UserDictionaryList extends PreferenceFragmentCompat {
|
||||||
|
|
||||||
public static final String USER_DICTIONARY_SETTINGS_INTENT_ACTION =
|
public static final String USER_DICTIONARY_SETTINGS_INTENT_ACTION =
|
||||||
"android.settings.USER_DICTIONARY_SETTINGS";
|
"android.settings.USER_DICTIONARY_SETTINGS";
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onCreate(final Bundle icicle) {
|
public void onCreatePreferences(@Nullable Bundle bundle, @Nullable String s) {
|
||||||
super.onCreate(icicle);
|
|
||||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
|
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
|
||||||
getPreferenceManager().setStorageDeviceProtected();
|
getPreferenceManager().setStorageDeviceProtected();
|
||||||
}
|
}
|
||||||
setPreferenceScreen(getPreferenceManager().createPreferenceScreen(getActivity()));
|
setPreferenceScreen(getPreferenceManager().createPreferenceScreen(requireContext()));
|
||||||
}
|
}
|
||||||
|
|
||||||
public static TreeSet<String> getUserDictionaryLocalesSet(final Activity activity) {
|
public static TreeSet<String> getUserDictionaryLocalesSet(final Activity activity) {
|
||||||
|
@ -115,10 +114,12 @@ public class UserDictionaryList extends PreferenceFragment {
|
||||||
* @param userDictGroup The group to put the settings in.
|
* @param userDictGroup The group to put the settings in.
|
||||||
*/
|
*/
|
||||||
protected void createUserDictSettings(final PreferenceGroup userDictGroup) {
|
protected void createUserDictSettings(final PreferenceGroup userDictGroup) {
|
||||||
final Activity activity = getActivity();
|
|
||||||
userDictGroup.removeAll();
|
userDictGroup.removeAll();
|
||||||
final TreeSet<String> localeSet =
|
final TreeSet<String> localeSet = UserDictionaryList.getUserDictionaryLocalesSet(requireActivity());
|
||||||
UserDictionaryList.getUserDictionaryLocalesSet(activity);
|
if (localeSet == null) {
|
||||||
|
userDictGroup.addPreference(createUserDictionaryPreference(null));
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
if (localeSet.size() > 1) {
|
if (localeSet.size() > 1) {
|
||||||
// Have an "All languages" entry in the languages list if there are two or more active
|
// Have an "All languages" entry in the languages list if there are two or more active
|
||||||
|
@ -141,7 +142,7 @@ public class UserDictionaryList extends PreferenceFragment {
|
||||||
* @return The corresponding preference.
|
* @return The corresponding preference.
|
||||||
*/
|
*/
|
||||||
protected Preference createUserDictionaryPreference(@Nullable final String localeString) {
|
protected Preference createUserDictionaryPreference(@Nullable final String localeString) {
|
||||||
final Preference newPref = new Preference(getActivity());
|
final Preference newPref = new Preference(requireContext());
|
||||||
final Intent intent = new Intent(USER_DICTIONARY_SETTINGS_INTENT_ACTION);
|
final Intent intent = new Intent(USER_DICTIONARY_SETTINGS_INTENT_ACTION);
|
||||||
if (null == localeString) {
|
if (null == localeString) {
|
||||||
newPref.setTitle(Locale.getDefault().getDisplayName());
|
newPref.setTitle(Locale.getDefault().getDisplayName());
|
||||||
|
|
|
@ -159,7 +159,7 @@ public class UserDictionarySettings extends ListFragment {
|
||||||
public void onResume() {
|
public void onResume() {
|
||||||
super.onResume();
|
super.onResume();
|
||||||
ListAdapter adapter = getListView().getAdapter();
|
ListAdapter adapter = getListView().getAdapter();
|
||||||
if (adapter != null && adapter instanceof MyAdapter) {
|
if (adapter instanceof MyAdapter) {
|
||||||
// The list view is forced refreshed here. This allows the changes done
|
// The list view is forced refreshed here. This allows the changes done
|
||||||
// in UserDictionaryAddWordFragment (update/delete/insert) to be seen when
|
// in UserDictionaryAddWordFragment (update/delete/insert) to be seen when
|
||||||
// user goes back to this view.
|
// user goes back to this view.
|
||||||
|
@ -292,28 +292,24 @@ public class UserDictionarySettings extends ListFragment {
|
||||||
private static class MyAdapter extends SimpleCursorAdapter implements SectionIndexer {
|
private static class MyAdapter extends SimpleCursorAdapter implements SectionIndexer {
|
||||||
private AlphabetIndexer mIndexer;
|
private AlphabetIndexer mIndexer;
|
||||||
|
|
||||||
private ViewBinder mViewBinder = new ViewBinder() {
|
private final ViewBinder mViewBinder = (v, c, columnIndex) -> {
|
||||||
|
if (!IS_SHORTCUT_API_SUPPORTED) {
|
||||||
@Override
|
// just let SimpleCursorAdapter set the view values
|
||||||
public boolean setViewValue(final View v, final Cursor c, final int columnIndex) {
|
|
||||||
if (!IS_SHORTCUT_API_SUPPORTED) {
|
|
||||||
// just let SimpleCursorAdapter set the view values
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
if (columnIndex == INDEX_SHORTCUT) {
|
|
||||||
final String shortcut = c.getString(INDEX_SHORTCUT);
|
|
||||||
if (TextUtils.isEmpty(shortcut)) {
|
|
||||||
v.setVisibility(View.GONE);
|
|
||||||
} else {
|
|
||||||
((TextView)v).setText(shortcut);
|
|
||||||
v.setVisibility(View.VISIBLE);
|
|
||||||
}
|
|
||||||
v.invalidate();
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
if (columnIndex == INDEX_SHORTCUT) {
|
||||||
|
final String shortcut = c.getString(INDEX_SHORTCUT);
|
||||||
|
if (TextUtils.isEmpty(shortcut)) {
|
||||||
|
v.setVisibility(View.GONE);
|
||||||
|
} else {
|
||||||
|
((TextView)v).setText(shortcut);
|
||||||
|
v.setVisibility(View.VISIBLE);
|
||||||
|
}
|
||||||
|
v.invalidate();
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
};
|
};
|
||||||
|
|
||||||
public MyAdapter(final Context context, final int layout, final Cursor c,
|
public MyAdapter(final Context context, final int layout, final Cursor c,
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue