1
0
Fork 0

Calculator apps now work in Passthrough mode (#326)

---------
Co-authored-by: Alex Knop <alexknoptech@protonmail.com>
Co-authored-by: sspanak <doftor.livain@gmail.com>
This commit is contained in:
alexknop 2023-08-01 03:27:19 -04:00 committed by GitHub
parent cd60c55fe5
commit d4c6467da3
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 12 additions and 9 deletions

View file

@ -33,17 +33,18 @@ public class InputType {
/** /**
* isDialer * isSpecialNumeric
* Dialer fields seem to take care of numbers and backspace on their own, * Calculator and 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 Phone field. Dialer is where you * NOTE: A Dialer field is not the same as Phone field. Dialer is where you
* actually dial and call a phone number. While the Phone field is a text * actually dial and call a phone number. While the Phone field is a text
* field in any app or a webpage, intended for typing phone numbers. * field in any app or a webpage, intended for typing phone numbers.
* *
* More info: <a href="https://github.com/sspanak/tt9/issues/46">in this Github issue</a>. * More info: <a href="https://github.com/sspanak/tt9/issues/46">in this Github issue</a>
* and <a href="https://github.com/sspanak/tt9/pull/326">the PR about calculators</a>.
*/ */
public boolean isDialer() { public boolean isSpecialNumeric() {
if (field == null) { if (field == null) {
return false; return false;
} }
@ -51,7 +52,8 @@ public class InputType {
int inputType = field.inputType & android.text.InputType.TYPE_MASK_CLASS; int inputType = field.inputType & android.text.InputType.TYPE_MASK_CLASS;
return return
inputType == android.text.InputType.TYPE_CLASS_PHONE && field.packageName.equals("com.android.dialer"); inputType == android.text.InputType.TYPE_CLASS_PHONE && field.packageName.equals("com.android.dialer")
|| inputType == android.text.InputType.TYPE_CLASS_NUMBER && field.packageName.contains("com.android.calculator");
} }

View file

@ -90,9 +90,10 @@ public class TextField {
return allowedModes; return allowedModes;
} }
// Dialer field, not to be confused with Phone text field. // Calculators (support only 0-9 and math) and Dialer (0-9, "#" and "*"),
// It only accepts 0-9, "#" and "*". // handle all input themselves, so we are supposed to pass through all key presses.
if (inputType.isDialer()) { // Note: A Dialer field is not a Phone number field.
if (inputType.isSpecialNumeric()) {
allowedModes.add(InputMode.MODE_PASSTHROUGH); allowedModes.add(InputMode.MODE_PASSTHROUGH);
return allowedModes; return allowedModes;
} }

View file

@ -2,7 +2,7 @@ package io.github.sspanak.tt9.ime.modes;
import androidx.annotation.NonNull; import androidx.annotation.NonNull;
// see: InputType.isDialer() // see: InputType.isSpecialNumeric()
public class ModePassthrough extends InputMode { public class ModePassthrough extends InputMode {
ModePassthrough() { ModePassthrough() {
reset(); reset();