From f33fe453182152289f6b325b93d2064c5b0c3dea Mon Sep 17 00:00:00 2001 From: sspanak Date: Mon, 10 Feb 2025 13:21:54 +0200 Subject: [PATCH] fixed the search field in the default Contacts app being detected as email field on some devices --- .../github/sspanak/tt9/hacks/InputType.java | 33 +++++++++++++++++-- 1 file changed, 30 insertions(+), 3 deletions(-) diff --git a/app/src/main/java/io/github/sspanak/tt9/hacks/InputType.java b/app/src/main/java/io/github/sspanak/tt9/hacks/InputType.java index f74e0b50..b6fee065 100644 --- a/app/src/main/java/io/github/sspanak/tt9/hacks/InputType.java +++ b/app/src/main/java/io/github/sspanak/tt9/hacks/InputType.java @@ -12,18 +12,45 @@ public class InputType extends StandardInputType { } + @Override + public boolean isEmail() { + return super.isEmail() && !isAndroidContactsSearch(); + } + + /** - * isContactsAndroid15Field + * isAndroid15ContactsField * "First Name" and "Last Name" fields in Android 15 are specified absolutely incorrectly. * Thank you for wasting my time, Google! */ - private boolean isContactsAndroid15Field() { + private boolean isAndroid15ContactsField() { return isAppField("com.google.android.contacts", 8288) && field.privateImeOptions != null && field.privateImeOptions.contains("requestPhoneticOutput"); } + /** + * Yet another randomly defined field. On Unihertz Atom L (Android 11) and Show F2 (Android 8), + * the search field in the Contacts app is defined as "email", instead of a plain text field, like + * in other devices. This causes us to display suggestions for email addresses, which is not desired. + * Bug report: #698 + */ + public boolean isAndroidContactsSearch() { + if (field == null) { + return false; + } + + boolean isActionDone = (field.imeOptions & EditorInfo.IME_MASK_ACTION) == EditorInfo.IME_ACTION_DONE; + boolean notNavigateNext = (field.imeOptions & EditorInfo.IME_FLAG_NAVIGATE_NEXT) != EditorInfo.IME_FLAG_NAVIGATE_NEXT; + boolean notNavigatePrevious = (field.imeOptions & EditorInfo.IME_FLAG_NAVIGATE_PREVIOUS) != EditorInfo.IME_FLAG_NAVIGATE_PREVIOUS; + + return + (isAppField("com.android.contacts", 33) || isAppField("com.google.android.contacts", 33)) + && (isActionDone || (notNavigateNext && notNavigatePrevious)); + } + + /** * isDeezerSearchBar * The field for searching songs and artists in Deezer does not support composing text, which @@ -190,7 +217,7 @@ public class InputType extends StandardInputType { */ @Override public boolean isDefectiveText() { - return isDuoLingoReportBug() || isContactsAndroid15Field(); + return isDuoLingoReportBug() || isAndroid15ContactsField(); }