|
8 | 8 | using Syncfusion.Maui.Toolkit.EntryView;
|
9 | 9 | #if ANDROID
|
10 | 10 | using Android.Text;
|
| 11 | +using Android.Provider; |
| 12 | +using Android.Content; |
| 13 | +using Android.Views.InputMethods; |
| 14 | +using System.Linq; |
11 | 15 | #elif MACCATALYST || IOS
|
12 | 16 | using UIKit;
|
13 | 17 | using Foundation;
|
@@ -266,6 +270,11 @@ public partial class SfNumericEntry : SfView, ITextElement, ITouchListener, IKey
|
266 | 270 | /// </summary>
|
267 | 271 | readonly CornerRadius _initialCornderRadius = 5;
|
268 | 272 | #elif ANDROID
|
| 273 | + /// <summary> |
| 274 | + /// Indicates whether the samsung device use samsung keyboard or any other. |
| 275 | + /// </summary> |
| 276 | + bool _isSamsungWithSamsungKeyboard; |
| 277 | + |
269 | 278 | /// <summary>
|
270 | 279 | /// Holds the length of text currently selected by the user.
|
271 | 280 | /// </summary>
|
@@ -541,7 +550,7 @@ protected void OnGotFocus()
|
541 | 550 | protected void OnLostFocus()
|
542 | 551 | {
|
543 | 552 | #if ANDROID
|
544 |
| - if (IsSamsungDevice() && _textBox != null) |
| 553 | + if (_isSamsungWithSamsungKeyboard && _textBox != null) |
545 | 554 | {
|
546 | 555 | // Ensure _textBox.Text isn't just a decimal separator or a minus sign
|
547 | 556 | if (_textBox.Text == GetNumberDecimalSeparator(GetNumberFormat()) || _textBox.Text == "-")
|
@@ -995,4 +1004,71 @@ void UpdateFrames()
|
995 | 1004 | #endif
|
996 | 1005 | #endregion
|
997 | 1006 | }
|
| 1007 | + |
| 1008 | +#if ANDROID |
| 1009 | + |
| 1010 | + /// <summary> |
| 1011 | + /// A utility class for checking the current keyboard in use on an Android device. |
| 1012 | + /// </summary> |
| 1013 | + internal static class KeyboardChecker |
| 1014 | + { |
| 1015 | + |
| 1016 | + /// <summary> |
| 1017 | + /// A constant representing the package name for the Google Keyboard application. |
| 1018 | + /// </summary> |
| 1019 | + const string GboardPackage = "com.google.android.inputmethod.latin"; |
| 1020 | + |
| 1021 | + |
| 1022 | + // Update the known package names for Samsung Keyboard and Gboard |
| 1023 | + static readonly string[] SamsungKeyboardPackages = ["com.samsung.android.keyboard", "com.sec.android.inputmethod", "com.samsung.android.honeyboard"]; |
| 1024 | + |
| 1025 | + /// <summary> |
| 1026 | + /// Gets the name of the current keyboard being used on the Android device. |
| 1027 | + /// </summary> |
| 1028 | + /// <param name="context">The context of the application, used to access system services.</param> |
| 1029 | + /// <returns>A string representing the name of the keyboard: "Samsung Keyboard", "Gboard", "Other Keyboard", or "Unknown Keyboard".</returns> |
| 1030 | + public static string GetCurrentKeyboard(Context context) |
| 1031 | + { |
| 1032 | + if (context.GetSystemService(Context.InputMethodService) is InputMethodManager inputMethodManager && inputMethodManager != null) |
| 1033 | + { |
| 1034 | + var defaultInputMethodId = Settings.Secure.GetString( |
| 1035 | + context.ContentResolver, |
| 1036 | + Settings.Secure.DefaultInputMethod |
| 1037 | + ); |
| 1038 | + |
| 1039 | + if (string.IsNullOrEmpty(defaultInputMethodId)) |
| 1040 | + { |
| 1041 | + return "Unknown Keyboard"; |
| 1042 | + } |
| 1043 | + |
| 1044 | + var inputMethodList = inputMethodManager.InputMethodList; |
| 1045 | + foreach (var inputMethod in inputMethodList) |
| 1046 | + { |
| 1047 | + if (inputMethod?.Id != null && inputMethod.Id.Equals(defaultInputMethodId, StringComparison.Ordinal)) |
| 1048 | + { |
| 1049 | + var packageName = inputMethod.PackageName; |
| 1050 | + if (!string.IsNullOrEmpty(packageName)) |
| 1051 | + { |
| 1052 | + if (SamsungKeyboardPackages.Contains(packageName)) |
| 1053 | + { |
| 1054 | + return "Samsung Keyboard"; |
| 1055 | + } |
| 1056 | + else if (packageName.Equals(GboardPackage, StringComparison.OrdinalIgnoreCase)) |
| 1057 | + { |
| 1058 | + return "Gboard"; |
| 1059 | + } |
| 1060 | + else |
| 1061 | + { |
| 1062 | + return "Other Keyboard"; |
| 1063 | + } |
| 1064 | + } |
| 1065 | + } |
| 1066 | + } |
| 1067 | + } |
| 1068 | + |
| 1069 | + return "Unknown Keyboard"; |
| 1070 | + } |
| 1071 | + } |
| 1072 | +#endif |
| 1073 | + |
998 | 1074 | }
|
0 commit comments