1
0
Fork 0

regression: fixed input mode switching not possible in some text fields in Duolingo

This commit is contained in:
sspanak 2024-10-21 15:29:28 +03:00 committed by Dimo Karaivanov
parent 0ff354a4eb
commit 57b0c35e2f
2 changed files with 18 additions and 6 deletions

View file

@ -12,8 +12,18 @@ public class InputType extends StandardInputType {
} }
/**
* isDuoLingoReportBug
* When reporting a bug in the Duolingo app, the text field is missing the TYPE_TEXT flag, which
* causes us to detect it as a numeric field. This effectively disables Predictive mode, which is
* actually desired there. Here, we detect this particular case and treat it as a text field.
*/
private boolean isDuoLingoReportBug() { private boolean isDuoLingoReportBug() {
return isAppField("com.duolingo", EditorInfo.TYPE_TEXT_FLAG_NO_SUGGESTIONS); return
field != null
&& "com.duolingo".equals(field.packageName)
&& field.inputType == EditorInfo.TYPE_TEXT_FLAG_NO_SUGGESTIONS
&& field.imeOptions == EditorInfo.IME_ACTION_DONE;
} }

View file

@ -6,6 +6,8 @@ import android.view.inputmethod.EditorInfo;
import android.view.inputmethod.InputConnection; import android.view.inputmethod.InputConnection;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.HashSet;
import java.util.Set;
import io.github.sspanak.tt9.ime.modes.InputMode; import io.github.sspanak.tt9.ime.modes.InputMode;
@ -131,11 +133,11 @@ abstract public class StandardInputType {
* @return ArrayList<SettingsStore.MODE_ABC | SettingsStore.MODE_123 | SettingsStore.MODE_PREDICTIVE> * @return ArrayList<SettingsStore.MODE_ABC | SettingsStore.MODE_123 | SettingsStore.MODE_PREDICTIVE>
*/ */
public ArrayList<Integer> determineInputModes(Context context) { public ArrayList<Integer> determineInputModes(Context context) {
ArrayList<Integer> allowedModes = new ArrayList<>(); Set<Integer> allowedModes = new HashSet<>();
if (field == null) { if (field == null) {
allowedModes.add(InputMode.MODE_PASSTHROUGH); allowedModes.add(InputMode.MODE_PASSTHROUGH);
return allowedModes; return new ArrayList<>(allowedModes);
} }
// Calculators (only 0-9 and math) and Dialer (0-9, "#" and "*") fields // Calculators (only 0-9 and math) and Dialer (0-9, "#" and "*") fields
@ -143,7 +145,7 @@ abstract public class StandardInputType {
// Note: A Dialer field is not a Phone number field. // Note: A Dialer field is not a Phone number field.
if (isSpecialNumeric(context)) { if (isSpecialNumeric(context)) {
allowedModes.add(InputMode.MODE_PASSTHROUGH); allowedModes.add(InputMode.MODE_PASSTHROUGH);
return allowedModes; return new ArrayList<>(allowedModes);
} }
switch (field.inputType & InputType.TYPE_MASK_CLASS) { switch (field.inputType & InputType.TYPE_MASK_CLASS) {
@ -153,7 +155,7 @@ abstract public class StandardInputType {
// Numbers, dates and phone numbers default to the numeric keyboard, // Numbers, dates and phone numbers default to the numeric keyboard,
// with no extra features. // with no extra features.
allowedModes.add(InputMode.MODE_123); allowedModes.add(InputMode.MODE_123);
return allowedModes; return new ArrayList<>(allowedModes);
case InputType.TYPE_CLASS_TEXT: case InputType.TYPE_CLASS_TEXT:
// This is general text editing. We will default to the // This is general text editing. We will default to the
@ -177,7 +179,7 @@ abstract public class StandardInputType {
allowedModes.add(InputMode.MODE_123); allowedModes.add(InputMode.MODE_123);
allowedModes.add(InputMode.MODE_ABC); allowedModes.add(InputMode.MODE_ABC);
return allowedModes; return new ArrayList<>(allowedModes);
} }
} }