diff options
Diffstat (limited to 'Xamarin.Forms.Platform.Android/Cells/EntryCellEditText.cs')
-rw-r--r-- | Xamarin.Forms.Platform.Android/Cells/EntryCellEditText.cs | 45 |
1 files changed, 45 insertions, 0 deletions
diff --git a/Xamarin.Forms.Platform.Android/Cells/EntryCellEditText.cs b/Xamarin.Forms.Platform.Android/Cells/EntryCellEditText.cs new file mode 100644 index 00000000..287804ba --- /dev/null +++ b/Xamarin.Forms.Platform.Android/Cells/EntryCellEditText.cs @@ -0,0 +1,45 @@ +using System; +using Android.App; +using Android.Content; +using Android.Graphics; +using Android.Views; +using Android.Widget; + +namespace Xamarin.Forms.Platform.Android +{ + public sealed class EntryCellEditText : EditText + { + SoftInput _startingMode; + + public EntryCellEditText(Context context) : base(context) + { + } + + public override bool OnKeyPreIme(Keycode keyCode, KeyEvent e) + { + if (keyCode == Keycode.Back && e.Action == KeyEventActions.Down) + { + EventHandler handler = BackButtonPressed; + if (handler != null) + handler(this, EventArgs.Empty); + } + return base.OnKeyPreIme(keyCode, e); + } + + protected override void OnFocusChanged(bool gainFocus, FocusSearchDirection direction, Rect previouslyFocusedRect) + { + Window window = ((Activity)Context).Window; + if (gainFocus) + { + _startingMode = window.Attributes.SoftInputMode; + window.SetSoftInputMode(SoftInput.AdjustPan); + } + else + window.SetSoftInputMode(_startingMode); + + base.OnFocusChanged(gainFocus, direction, previouslyFocusedRect); + } + + internal event EventHandler BackButtonPressed; + } +}
\ No newline at end of file |