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.
|
||||
* @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.
|
||||
|
|
|
@ -46,13 +46,13 @@ class CombinerChain(initialText: String?) {
|
|||
* new event. However it may never be null.
|
||||
*/
|
||||
fun processEvent(previousEvents: ArrayList<Event>?,
|
||||
newEvent: Event?): Event? {
|
||||
newEvent: Event): Event {
|
||||
val modifiablePreviousEvents = ArrayList(previousEvents!!)
|
||||
var event = newEvent
|
||||
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.
|
||||
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.
|
||||
break
|
||||
}
|
||||
|
|
|
@ -188,11 +188,11 @@ class DeadKeyCombiner : Combiner {
|
|||
// TODO: make this a list of events instead
|
||||
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 (event!!.isDead) { // The event was a dead key. Start tracking it.
|
||||
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
|
||||
// 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)
|
||||
|| 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(),
|
||||
event)
|
||||
val resultEvent = createEventChainFromSequence(mDeadSequence.toString(), event)
|
||||
mDeadSequence.setLength(0)
|
||||
return resultEvent
|
||||
}
|
||||
|
@ -211,13 +210,13 @@ class DeadKeyCombiner : Combiner {
|
|||
val trimIndex = mDeadSequence.length - Character.charCount(
|
||||
mDeadSequence.codePointBefore(mDeadSequence.length))
|
||||
mDeadSequence.setLength(trimIndex)
|
||||
return Event.Companion.createConsumedEvent(event)
|
||||
return Event.createConsumedEvent(event)
|
||||
}
|
||||
return event
|
||||
}
|
||||
if (event.isDead) {
|
||||
mDeadSequence.appendCodePoint(event.mCodePoint)
|
||||
return Event.Companion.createConsumedEvent(event)
|
||||
return Event.createConsumedEvent(event)
|
||||
}
|
||||
// Combine normally.
|
||||
val sb = StringBuilder()
|
||||
|
@ -248,17 +247,16 @@ class DeadKeyCombiner : Combiner {
|
|||
get() = mDeadSequence
|
||||
|
||||
companion object {
|
||||
private fun createEventChainFromSequence(text: CharSequence,
|
||||
originalEvent: Event?): Event? {
|
||||
private fun createEventChainFromSequence(text: CharSequence, originalEvent: Event): Event {
|
||||
var index = text.length
|
||||
if (index <= 0) {
|
||||
return originalEvent
|
||||
}
|
||||
var lastEvent: Event? = null
|
||||
lateinit var lastEvent: Event
|
||||
do {
|
||||
val codePoint = Character.codePointBefore(text, index)
|
||||
lastEvent = Event.Companion.createHardwareKeypressEvent(codePoint,
|
||||
originalEvent!!.mKeyCode, lastEvent, false /* isKeyRepeat */)
|
||||
lastEvent = Event.createHardwareKeypressEvent(codePoint,
|
||||
originalEvent.mKeyCode, lastEvent, false /* isKeyRepeat */)
|
||||
index -= Character.charCount(codePoint)
|
||||
} while (index > 0)
|
||||
return lastEvent
|
||||
|
|
|
@ -175,8 +175,7 @@ public class NgramContext {
|
|||
}
|
||||
}
|
||||
}
|
||||
final String[] contextStringArray = prevTermList.toArray(new String[prevTermList.size()]);
|
||||
return contextStringArray;
|
||||
return prevTermList.toArray(new String[prevTermList.size()]);
|
||||
}
|
||||
|
||||
public boolean isValid() {
|
||||
|
@ -227,7 +226,7 @@ public class NgramContext {
|
|||
public int hashCode() {
|
||||
int hashValue = 0;
|
||||
for (final WordInfo wordInfo : mPrevWordsInfo) {
|
||||
if (wordInfo == null || !WordInfo.EMPTY_WORD_INFO.equals(wordInfo)) {
|
||||
if (!WordInfo.EMPTY_WORD_INFO.equals(wordInfo)) {
|
||||
break;
|
||||
}
|
||||
hashValue ^= wordInfo.hashCode();
|
||||
|
@ -267,7 +266,7 @@ public class NgramContext {
|
|||
|
||||
@Override
|
||||
public String toString() {
|
||||
final StringBuffer builder = new StringBuffer();
|
||||
final StringBuilder builder = new StringBuilder();
|
||||
for (int i = 0; i < mPrevWordsCount; i++) {
|
||||
final WordInfo wordInfo = mPrevWordsInfo[i];
|
||||
builder.append("PrevWord[");
|
||||
|
|
|
@ -127,7 +127,7 @@ public final class WordComposer {
|
|||
refreshTypedWordCache();
|
||||
}
|
||||
|
||||
private final void refreshTypedWordCache() {
|
||||
private void refreshTypedWordCache() {
|
||||
mTypedWordCache = mCombinerChain.getComposingWordWithCombiningFeedback();
|
||||
mCodePointSize = Character.codePointCount(mTypedWordCache, 0, mTypedWordCache.length());
|
||||
}
|
||||
|
@ -144,7 +144,7 @@ public final class WordComposer {
|
|||
return size() == 1;
|
||||
}
|
||||
|
||||
public final boolean isComposingWord() {
|
||||
public boolean isComposingWord() {
|
||||
return size() > 0;
|
||||
}
|
||||
|
||||
|
|
|
@ -83,15 +83,13 @@ public class UserDictionaryAddWordContents {
|
|||
// it's too long to be edited.
|
||||
mWordEditText.setSelection(mWordEditText.getText().length());
|
||||
}
|
||||
final String shortcut;
|
||||
if (UserDictionarySettings.IS_SHORTCUT_API_SUPPORTED) {
|
||||
shortcut = args.getString(EXTRA_SHORTCUT);
|
||||
final String shortcut = args.getString(EXTRA_SHORTCUT);
|
||||
if (null != shortcut && null != mShortcutEditText) {
|
||||
mShortcutEditText.setText(shortcut);
|
||||
}
|
||||
mOldShortcut = args.getString(EXTRA_SHORTCUT);
|
||||
} else {
|
||||
shortcut = null;
|
||||
mOldShortcut = null;
|
||||
}
|
||||
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.os.Build;
|
||||
import android.os.Bundle;
|
||||
import android.preference.Preference;
|
||||
import android.preference.PreferenceFragment;
|
||||
import android.preference.PreferenceGroup;
|
||||
import android.provider.UserDictionary;
|
||||
import android.text.TextUtils;
|
||||
import android.view.inputmethod.InputMethodInfo;
|
||||
|
@ -32,6 +29,9 @@ import android.view.inputmethod.InputMethodManager;
|
|||
import android.view.inputmethod.InputMethodSubtype;
|
||||
|
||||
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.common.LocaleUtils;
|
||||
|
@ -44,18 +44,17 @@ import java.util.TreeSet;
|
|||
// 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
|
||||
|
||||
public class UserDictionaryList extends PreferenceFragment {
|
||||
public class UserDictionaryList extends PreferenceFragmentCompat {
|
||||
|
||||
public static final String USER_DICTIONARY_SETTINGS_INTENT_ACTION =
|
||||
"android.settings.USER_DICTIONARY_SETTINGS";
|
||||
|
||||
@Override
|
||||
public void onCreate(final Bundle icicle) {
|
||||
super.onCreate(icicle);
|
||||
public void onCreatePreferences(@Nullable Bundle bundle, @Nullable String s) {
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
|
||||
getPreferenceManager().setStorageDeviceProtected();
|
||||
}
|
||||
setPreferenceScreen(getPreferenceManager().createPreferenceScreen(getActivity()));
|
||||
setPreferenceScreen(getPreferenceManager().createPreferenceScreen(requireContext()));
|
||||
}
|
||||
|
||||
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.
|
||||
*/
|
||||
protected void createUserDictSettings(final PreferenceGroup userDictGroup) {
|
||||
final Activity activity = getActivity();
|
||||
userDictGroup.removeAll();
|
||||
final TreeSet<String> localeSet =
|
||||
UserDictionaryList.getUserDictionaryLocalesSet(activity);
|
||||
final TreeSet<String> localeSet = UserDictionaryList.getUserDictionaryLocalesSet(requireActivity());
|
||||
if (localeSet == null) {
|
||||
userDictGroup.addPreference(createUserDictionaryPreference(null));
|
||||
return;
|
||||
}
|
||||
|
||||
if (localeSet.size() > 1) {
|
||||
// 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.
|
||||
*/
|
||||
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);
|
||||
if (null == localeString) {
|
||||
newPref.setTitle(Locale.getDefault().getDisplayName());
|
||||
|
|
|
@ -159,7 +159,7 @@ public class UserDictionarySettings extends ListFragment {
|
|||
public void onResume() {
|
||||
super.onResume();
|
||||
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
|
||||
// in UserDictionaryAddWordFragment (update/delete/insert) to be seen when
|
||||
// user goes back to this view.
|
||||
|
@ -292,28 +292,24 @@ public class UserDictionarySettings extends ListFragment {
|
|||
private static class MyAdapter extends SimpleCursorAdapter implements SectionIndexer {
|
||||
private AlphabetIndexer mIndexer;
|
||||
|
||||
private ViewBinder mViewBinder = new ViewBinder() {
|
||||
|
||||
@Override
|
||||
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;
|
||||
}
|
||||
|
||||
private final ViewBinder mViewBinder = (v, c, 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;
|
||||
};
|
||||
|
||||
public MyAdapter(final Context context, final int layout, final Cursor c,
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue