|
1 | 1 | package io.flutter.embedding.engine.systemchannels;
|
2 | 2 |
|
| 3 | +import android.os.Build; |
| 4 | +import android.view.View; |
3 | 5 | import android.view.inputmethod.EditorInfo;
|
4 | 6 | import androidx.annotation.NonNull;
|
5 | 7 | import androidx.annotation.Nullable;
|
6 |
| -import androidx.autofill.HintConstants; |
7 | 8 | import io.flutter.Log;
|
8 | 9 | import io.flutter.embedding.engine.dart.DartExecutor;
|
9 | 10 | import io.flutter.plugin.common.JSONMethodCodec;
|
@@ -134,7 +135,7 @@ public void requestExistingInputState() {
|
134 | 135 | channel.invokeMethod("TextInputClient.requestExistingInputState", null);
|
135 | 136 | }
|
136 | 137 |
|
137 |
| - private HashMap<Object, Object> createEditingStateJSON( |
| 138 | + private static HashMap<Object, Object> createEditingStateJSON( |
138 | 139 | String text, int selectionStart, int selectionEnd, int composingStart, int composingEnd) {
|
139 | 140 | HashMap<Object, Object> state = new HashMap<>();
|
140 | 141 | state.put("text", text);
|
@@ -316,10 +317,10 @@ public static Configuration fromJson(@NonNull JSONObject json)
|
316 | 317 | }
|
317 | 318 | Configuration[] fields = null;
|
318 | 319 | if (!json.isNull("fields")) {
|
319 |
| - final JSONArray fields = json.getJSONArray("fields"); |
320 |
| - fields = new Configuration[fields.length()]; |
| 320 | + final JSONArray jsonFields = json.getJSONArray("fields"); |
| 321 | + fields = new Configuration[jsonFields.length()]; |
321 | 322 | for (int i = 0; i < fields.length; i++) {
|
322 |
| - fields[i] = Configuration.fromJson(fields.getJSONObject(i)); |
| 323 | + fields[i] = Configuration.fromJson(jsonFields.getJSONObject(i)); |
323 | 324 | }
|
324 | 325 | }
|
325 | 326 | final Integer inputAction = inputActionFromTextInputAction(inputActionName);
|
@@ -382,81 +383,85 @@ public static Autofill fromJson(@NonNull JSONObject json)
|
382 | 383 |
|
383 | 384 | @NonNull
|
384 | 385 | private static String translateAutofillHint(@NonNull String hint) {
|
385 |
| - switch (hint) { |
386 |
| - case "addressCity": |
387 |
| - return HintConstants.AUTOFILL_HINT_POSTAL_ADDRESS_LOCALITY; |
388 |
| - case "addressState": |
389 |
| - return HintConstants.AUTOFILL_HINT_POSTAL_ADDRESS_REGION; |
390 |
| - case "birthday": |
391 |
| - return HintConstants.AUTOFILL_HINT_BIRTH_DATE_FULL; |
392 |
| - case "birthdayDay": |
393 |
| - return HintConstants.AUTOFILL_HINT_BIRTH_DATE_DAY; |
394 |
| - case "birthdayMonth": |
395 |
| - return HintConstants.AUTOFILL_HINT_BIRTH_DATE_MONTH; |
396 |
| - case "birthdayYear": |
397 |
| - return HintConstants.AUTOFILL_HINT_BIRTH_DATE_YEAR; |
398 |
| - case "countryName": |
399 |
| - return HintConstants.AUTOFILL_HINT_POSTAL_ADDRESS_COUNTRY; |
400 |
| - case "creditCardExpirationDate": |
401 |
| - return HintConstants.AUTOFILL_HINT_CREDIT_CARD_NUMBER; |
402 |
| - case "creditCardExpirationDay": |
403 |
| - return HintConstants.AUTOFILL_HINT_CREDIT_CARD_EXPIRATION_DAY; |
404 |
| - case "creditCardExpirationMonth": |
405 |
| - return HintConstants.AUTOFILL_HINT_CREDIT_CARD_EXPIRATION_MONTH; |
406 |
| - case "creditCardExpirationYear": |
407 |
| - return HintConstants.AUTOFILL_HINT_CREDIT_CARD_EXPIRATION_YEAR; |
408 |
| - case "creditCardNumber": |
409 |
| - return HintConstants.AUTOFILL_HINT_CREDIT_CARD_NUMBER; |
410 |
| - case "creditCardSecurityCode": |
411 |
| - return HintConstants.AUTOFILL_HINT_CREDIT_CARD_SECURITY_CODE; |
412 |
| - case "email": |
413 |
| - return HintConstants.AUTOFILL_HINT_EMAIL_ADDRESS; |
414 |
| - case "familyName": |
415 |
| - return HintConstants.AUTOFILL_HINT_PERSON_NAME_FAMILY; |
416 |
| - case "fullStreetAddress": |
417 |
| - return HintConstants.AUTOFILL_HINT_POSTAL_ADDRESS_STREET_ADDRESS; |
418 |
| - case "gender": |
419 |
| - return HintConstants.AUTOFILL_HINT_GENDER; |
420 |
| - case "givenName": |
421 |
| - return HintConstants.AUTOFILL_HINT_PERSON_NAME_GIVEN; |
422 |
| - case "middleInitial": |
423 |
| - return HintConstants.AUTOFILL_HINT_PERSON_NAME_MIDDLE_INITIAL; |
424 |
| - case "middleName": |
425 |
| - return HintConstants.AUTOFILL_HINT_PERSON_NAME_MIDDLE; |
426 |
| - case "name": |
427 |
| - return HintConstants.AUTOFILL_HINT_PERSON_NAME; |
428 |
| - case "namePrefix": |
429 |
| - return HintConstants.AUTOFILL_HINT_PERSON_NAME_PREFIX; |
430 |
| - case "nameSuffix": |
431 |
| - return HintConstants.AUTOFILL_HINT_PERSON_NAME_SUFFIX; |
432 |
| - case "newPassword": |
433 |
| - return HintConstants.AUTOFILL_HINT_NEW_PASSWORD; |
434 |
| - case "newUsername": |
435 |
| - return HintConstants.AUTOFILL_HINT_NEW_USERNAME; |
436 |
| - case "oneTimeCode": |
437 |
| - return HintConstants.AUTOFILL_HINT_SMS_OTP; |
438 |
| - case "password": |
439 |
| - return HintConstants.AUTOFILL_HINT_PASSWORD; |
440 |
| - case "postalAddress": |
441 |
| - return HintConstants.AUTOFILL_HINT_POSTAL_ADDRESS; |
442 |
| - case "postalAddressExtended": |
443 |
| - return HintConstants.AUTOFILL_HINT_POSTAL_ADDRESS_EXTENDED_ADDRESS; |
444 |
| - case "postalAddressExtendedPostalCode": |
445 |
| - return HintConstants.AUTOFILL_HINT_POSTAL_ADDRESS_EXTENDED_POSTAL_CODE; |
446 |
| - case "postalCode": |
447 |
| - return HintConstants.AUTOFILL_HINT_POSTAL_CODE; |
448 |
| - case "telephoneNumber": |
449 |
| - return HintConstants.AUTOFILL_HINT_PHONE_NUMBER; |
450 |
| - case "telephoneNumberCountryCode": |
451 |
| - return HintConstants.AUTOFILL_HINT_PHONE_COUNTRY_CODE; |
452 |
| - case "telephoneNumberDevice": |
453 |
| - return HintConstants.AUTOFILL_HINT_PHONE_NUMBER_DEVICE; |
454 |
| - case "telephoneNumberNational": |
455 |
| - return HintConstants.AUTOFILL_HINT_PHONE_NATIONAL; |
456 |
| - case "username": |
457 |
| - return HintConstants.AUTOFILL_HINT_NEW_USERNAME; |
458 |
| - default: |
459 |
| - return hint; |
| 386 | + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) { |
| 387 | + switch (hint) { |
| 388 | + case "addressCity": |
| 389 | + return "addressLocality"; |
| 390 | + case "addressState": |
| 391 | + return "addressRegion"; |
| 392 | + case "birthday": |
| 393 | + return "birthDateFull"; |
| 394 | + case "birthdayDay": |
| 395 | + return "birthDateDay"; |
| 396 | + case "birthdayMonth": |
| 397 | + return "birthDateMonth"; |
| 398 | + case "birthdayYear": |
| 399 | + return "birthDateYear"; |
| 400 | + case "countryName": |
| 401 | + return "addressCountry"; |
| 402 | + case "creditCardExpirationDate": |
| 403 | + return View.AUTOFILL_HINT_CREDIT_CARD_EXPIRATION_DATE; |
| 404 | + case "creditCardExpirationDay": |
| 405 | + return View.AUTOFILL_HINT_CREDIT_CARD_EXPIRATION_DAY; |
| 406 | + case "creditCardExpirationMonth": |
| 407 | + return View.AUTOFILL_HINT_CREDIT_CARD_EXPIRATION_MONTH; |
| 408 | + case "creditCardExpirationYear": |
| 409 | + return View.AUTOFILL_HINT_CREDIT_CARD_EXPIRATION_YEAR; |
| 410 | + case "creditCardNumber": |
| 411 | + return View.AUTOFILL_HINT_CREDIT_CARD_NUMBER; |
| 412 | + case "creditCardSecurityCode": |
| 413 | + return View.AUTOFILL_HINT_CREDIT_CARD_SECURITY_CODE; |
| 414 | + case "email": |
| 415 | + return View.AUTOFILL_HINT_EMAIL_ADDRESS; |
| 416 | + case "familyName": |
| 417 | + return "personFamilyName"; |
| 418 | + case "fullStreetAddress": |
| 419 | + return "streetAddress"; |
| 420 | + case "gender": |
| 421 | + return "gender"; |
| 422 | + case "givenName": |
| 423 | + return "personGivenName"; |
| 424 | + case "middleInitial": |
| 425 | + return "personMiddleInitial"; |
| 426 | + case "middleName": |
| 427 | + return "personMiddleName"; |
| 428 | + case "name": |
| 429 | + return "personName"; |
| 430 | + case "namePrefix": |
| 431 | + return "personNamePrefix"; |
| 432 | + case "nameSuffix": |
| 433 | + return "personNameSuffix"; |
| 434 | + case "newPassword": |
| 435 | + return "newPassword"; |
| 436 | + case "newUsername": |
| 437 | + return "newUsername"; |
| 438 | + case "oneTimeCode": |
| 439 | + return "smsOTPCode"; |
| 440 | + case "password": |
| 441 | + return View.AUTOFILL_HINT_PASSWORD; |
| 442 | + case "postalAddress": |
| 443 | + return View.AUTOFILL_HINT_POSTAL_ADDRESS; |
| 444 | + case "postalAddressExtended": |
| 445 | + return "extendedAddress"; |
| 446 | + case "postalAddressExtendedPostalCode": |
| 447 | + return "extendedPostalCode"; |
| 448 | + case "postalCode": |
| 449 | + return View.AUTOFILL_HINT_POSTAL_CODE; |
| 450 | + case "telephoneNumber": |
| 451 | + return "phoneNumber"; |
| 452 | + case "telephoneNumberCountryCode": |
| 453 | + return "phoneCountryCode"; |
| 454 | + case "telephoneNumberDevice": |
| 455 | + return "phoneNumberDevice"; |
| 456 | + case "telephoneNumberNational": |
| 457 | + return "phoneNational"; |
| 458 | + case "username": |
| 459 | + return View.AUTOFILL_HINT_USERNAME; |
| 460 | + default: |
| 461 | + return hint; |
| 462 | + } |
| 463 | + } else { |
| 464 | + return hint; |
460 | 465 | }
|
461 | 466 | }
|
462 | 467 |
|
|
0 commit comments