the initial text case is now obtained from the input field
This commit is contained in:
parent
283bf7de6b
commit
6fed5b69d6
5 changed files with 57 additions and 31 deletions
|
|
@ -32,6 +32,8 @@ public class InputFieldHelper {
|
||||||
* isDialerField
|
* isDialerField
|
||||||
* Dialer fields seem to take care of numbers and backspace on their own,
|
* Dialer fields seem to take care of numbers and backspace on their own,
|
||||||
* so we need to be aware of them.
|
* so we need to be aware of them.
|
||||||
|
*
|
||||||
|
* NOTE: A Dialer field is not the same as a Phone field in a phone book.
|
||||||
*/
|
*/
|
||||||
public static boolean isDialerField(EditorInfo inputField) {
|
public static boolean isDialerField(EditorInfo inputField) {
|
||||||
return
|
return
|
||||||
|
|
@ -79,12 +81,23 @@ public class InputFieldHelper {
|
||||||
|
|
||||||
return
|
return
|
||||||
variation == InputType.TYPE_TEXT_VARIATION_PASSWORD
|
variation == InputType.TYPE_TEXT_VARIATION_PASSWORD
|
||||||
|| variation == InputType.TYPE_TEXT_VARIATION_VISIBLE_PASSWORD;
|
|| variation == InputType.TYPE_TEXT_VARIATION_VISIBLE_PASSWORD
|
||||||
|
|| variation == InputType.TYPE_TEXT_VARIATION_WEB_PASSWORD;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public static boolean isRegularTextField(EditorInfo inputField) {
|
private static boolean isPersonNameField(EditorInfo inputField) {
|
||||||
return !isPasswordField(inputField) && !isEmailField(inputField);
|
return inputField != null && (inputField.inputType & InputType.TYPE_MASK_VARIATION) == InputType.TYPE_TEXT_VARIATION_PERSON_NAME;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public static boolean isSpecializedTextField(EditorInfo inputField) {
|
||||||
|
return isEmailField(inputField) || isPasswordField(inputField) || isUriField(inputField);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
private static boolean isUriField(EditorInfo inputField) {
|
||||||
|
return inputField != null && (inputField.inputType & InputType.TYPE_MASK_VARIATION) == InputType.TYPE_TEXT_VARIATION_URI;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -153,27 +166,27 @@ public class InputFieldHelper {
|
||||||
* Helper to update the shift state of our keyboard based on the initial
|
* Helper to update the shift state of our keyboard based on the initial
|
||||||
* editor state.
|
* editor state.
|
||||||
*/
|
*/
|
||||||
public static void determineTextCase(EditorInfo inputField) {
|
public static int determineTextCase(InputConnection inputConnection, EditorInfo inputField) {
|
||||||
// Logger.d("updateShift", "CM start: " + mCapsMode);
|
if (inputField == null || inputConnection == null || inputField.inputType == InputType.TYPE_NULL) {
|
||||||
// if (inputField != null && mCapsMode != SettingsStore.CASE_UPPER) {
|
return InputMode.CASE_UNDEFINED;
|
||||||
// int caps = 0;
|
}
|
||||||
// if (inputField.inputType != InputType.TYPE_NULL) {
|
|
||||||
// caps = currentInputConnection.getCursorCapsMode(inputField.inputType);
|
if (isSpecializedTextField(inputField)) {
|
||||||
// }
|
return InputMode.CASE_LOWER;
|
||||||
// // mInputView.setShifted(mCapsLock || caps != 0);
|
}
|
||||||
// // Logger.d("updateShift", "caps: " + caps);
|
|
||||||
// if ((caps & TextUtils.CAP_MODE_CHARACTERS) == TextUtils.CAP_MODE_CHARACTERS) {
|
if (isPersonNameField(inputField)) {
|
||||||
// mCapsMode = SettingsStore.CASE_UPPER;
|
return InputMode.CASE_CAPITALIZE;
|
||||||
// } else if ((caps & TextUtils.CAP_MODE_SENTENCES) == TextUtils.CAP_MODE_SENTENCES) {
|
}
|
||||||
// mCapsMode = SettingsStore.CASE_CAPITALIZE;
|
|
||||||
// } else if ((caps & TextUtils.CAP_MODE_WORDS) == TextUtils.CAP_MODE_WORDS) {
|
switch (inputField.inputType & InputType.TYPE_MASK_FLAGS) {
|
||||||
// mCapsMode = SettingsStore.CASE_CAPITALIZE;
|
case InputType.TYPE_TEXT_FLAG_CAP_CHARACTERS:
|
||||||
// } else {
|
return InputMode.CASE_UPPER;
|
||||||
// mCapsMode = SettingsStore.CASE_LOWER;
|
case InputType.TYPE_TEXT_FLAG_CAP_WORDS:
|
||||||
// }
|
return InputMode.CASE_CAPITALIZE;
|
||||||
// updateStatusIcon();
|
}
|
||||||
// }
|
|
||||||
// Logger.d("updateShift", "CM end: " + mCapsMode);
|
return InputMode.CASE_UNDEFINED;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -95,7 +95,7 @@ abstract class KeyPadHandler extends InputMethodService {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
onRestart(inputField);
|
onStart(inputField);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -386,7 +386,7 @@ abstract class KeyPadHandler extends InputMethodService {
|
||||||
|
|
||||||
// helpers
|
// helpers
|
||||||
abstract protected void onInit();
|
abstract protected void onInit();
|
||||||
abstract protected void onRestart(EditorInfo inputField);
|
abstract protected void onStart(EditorInfo inputField);
|
||||||
abstract protected void onFinish();
|
abstract protected void onFinish();
|
||||||
abstract protected View createSoftKeyView();
|
abstract protected View createSoftKeyView();
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -83,9 +83,8 @@ public class TraditionalT9 extends KeyPadHandler {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
protected void onRestart(EditorInfo inputField) {
|
protected void onStart(EditorInfo inputField) {
|
||||||
this.inputField = inputField;
|
this.inputField = inputField;
|
||||||
|
|
||||||
// in case we are back from Settings screen, update the language list
|
// in case we are back from Settings screen, update the language list
|
||||||
mEnabledLanguages = settings.getEnabledLanguageIds();
|
mEnabledLanguages = settings.getEnabledLanguageIds();
|
||||||
validateLanguages();
|
validateLanguages();
|
||||||
|
|
@ -94,6 +93,7 @@ public class TraditionalT9 extends KeyPadHandler {
|
||||||
determineAllowedInputModes();
|
determineAllowedInputModes();
|
||||||
mInputMode = InputModeValidator.validateMode(settings, mInputMode, allowedInputModes);
|
mInputMode = InputModeValidator.validateMode(settings, mInputMode, allowedInputModes);
|
||||||
|
|
||||||
|
mInputMode.setTextFieldCase(InputFieldHelper.determineTextCase(currentInputConnection, inputField));
|
||||||
// Some modes may want to change the default text case based on grammar rules.
|
// Some modes may want to change the default text case based on grammar rules.
|
||||||
determineNextTextCase();
|
determineNextTextCase();
|
||||||
InputModeValidator.validateTextCase(settings, mInputMode, settings.getTextCase());
|
InputModeValidator.validateTextCase(settings, mInputMode, settings.getTextCase());
|
||||||
|
|
|
||||||
|
|
@ -16,12 +16,14 @@ abstract public class InputMode {
|
||||||
public static final int MODE_123 = 2;
|
public static final int MODE_123 = 2;
|
||||||
|
|
||||||
// text case
|
// text case
|
||||||
|
public static final int CASE_UNDEFINED = -1;
|
||||||
public static final int CASE_UPPER = 0;
|
public static final int CASE_UPPER = 0;
|
||||||
public static final int CASE_CAPITALIZE = 1;
|
public static final int CASE_CAPITALIZE = 1;
|
||||||
public static final int CASE_LOWER = 2;
|
public static final int CASE_LOWER = 2;
|
||||||
public static final int CASE_DICTIONARY = 3; // do not force it, but use the dictionary word as-is
|
public static final int CASE_DICTIONARY = 3; // do not force it, but use the dictionary word as-is
|
||||||
protected ArrayList<Integer> allowedTextCases = new ArrayList<>();
|
protected ArrayList<Integer> allowedTextCases = new ArrayList<>();
|
||||||
protected int textCase = CASE_LOWER;
|
protected int textCase = CASE_LOWER;
|
||||||
|
protected int textFieldTextCase = CASE_UNDEFINED;
|
||||||
|
|
||||||
// data
|
// data
|
||||||
protected ArrayList<String> suggestions = new ArrayList<>();
|
protected ArrayList<String> suggestions = new ArrayList<>();
|
||||||
|
|
@ -91,11 +93,17 @@ abstract public class InputMode {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void setTextFieldCase(int newTextCase) {
|
||||||
|
textFieldTextCase = allowedTextCases.contains(newTextCase) ? newTextCase : CASE_UNDEFINED;
|
||||||
|
}
|
||||||
|
|
||||||
public void defaultTextCase() {
|
public void defaultTextCase() {
|
||||||
textCase = allowedTextCases.get(0);
|
textCase = allowedTextCases.get(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void nextTextCase() {
|
public void nextTextCase() {
|
||||||
|
textFieldTextCase = CASE_UNDEFINED; // since it's a user's choice, the default matters no more
|
||||||
|
|
||||||
int nextIndex = (allowedTextCases.indexOf(textCase) + 1) % allowedTextCases.size();
|
int nextIndex = (allowedTextCases.indexOf(textCase) + 1) % allowedTextCases.size();
|
||||||
textCase = allowedTextCases.get(nextIndex);
|
textCase = allowedTextCases.get(nextIndex);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -144,7 +144,7 @@ public class ModePredictive extends InputMode {
|
||||||
|| lastAcceptedWord.equals("'")
|
|| lastAcceptedWord.equals("'")
|
||||||
|| lastAcceptedWord.equals("@")
|
|| lastAcceptedWord.equals("@")
|
||||||
)
|
)
|
||||||
&& InputFieldHelper.isRegularTextField(inputField);
|
&& !InputFieldHelper.isSpecializedTextField(inputField);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -168,7 +168,7 @@ public class ModePredictive extends InputMode {
|
||||||
|| lastAcceptedWord.endsWith("]")
|
|| lastAcceptedWord.endsWith("]")
|
||||||
|| lastAcceptedWord.endsWith("%")
|
|| lastAcceptedWord.endsWith("%")
|
||||||
)
|
)
|
||||||
&& InputFieldHelper.isRegularTextField(inputField);
|
&& !InputFieldHelper.isSpecializedTextField(inputField);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -185,7 +185,7 @@ public class ModePredictive extends InputMode {
|
||||||
&& !lastAcceptedSequence.equals("0")
|
&& !lastAcceptedSequence.equals("0")
|
||||||
// Emoji
|
// Emoji
|
||||||
&& !lastAcceptedSequence.startsWith("1")
|
&& !lastAcceptedSequence.startsWith("1")
|
||||||
&& InputFieldHelper.isRegularTextField(inputField);
|
&& !InputFieldHelper.isSpecializedTextField(inputField);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -529,6 +529,11 @@ public class ModePredictive extends InputMode {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (textFieldTextCase != CASE_UNDEFINED) {
|
||||||
|
textCase = textFieldTextCase;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
// start of text
|
// start of text
|
||||||
if (!isThereText) {
|
if (!isThereText) {
|
||||||
textCase = CASE_CAPITALIZE;
|
textCase = CASE_CAPITALIZE;
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue