public void HideSoftKeyboard() { if (CurrentFocus == null) { return; } InputMethodManager inputMethodManager = (InputMethodManager)GetSystemService(InputMethodService); inputMethodManager.HideSoftInputFromWindow(CurrentFocus.WindowToken, 0); CurrentFocus.ClearFocus(); }
private void Drawer_DrawerOpened(object sender, DrawerLayout.DrawerOpenedEventArgs e) { if (CurrentFocus == null) { return; } InputMethodManager inputMethodManager = (InputMethodManager)this.GetSystemService(Android.Content.Context.InputMethodService); inputMethodManager.HideSoftInputFromWindow(CurrentFocus.WindowToken, 0); CurrentFocus.ClearFocus(); }
protected override void OnResume() { // counterpart to OnPause base.OnResume(); if (_application != null && _application.OnThisPlatform().GetShouldPreserveKeyboardOnResume()) { if (CurrentFocus != null && (CurrentFocus is EditText || CurrentFocus is TextView || CurrentFocus is SearchView)) { CurrentFocus.ShowKeyboard(); } } _previousState = _currentState; _currentState = AndroidApplicationLifecycleState.OnResume; OnStateChanged(); }
/// <summary> /// Called by framework. Do not call directly. /// </summary> public void OnKey(InputEvent e) { if (!Active) { return; } if ((e.KeyPressed(KeyId.Tab) && Input.ShiftDown) || e.KeyPressed(KeyId.XI_DPadUp) || e.KeyPressed(KeyId.XI_DPadLeft)) { FocusPreviousComponent(); } else if (e.KeyPressed(KeyId.Tab) || e.KeyPressed(KeyId.XI_DPadDown) || e.KeyPressed(KeyId.XI_DPadRight)) { FocusNextComponent(); } else if (CurrentFocus != null) { CurrentFocus.InvokeOnKey(e); } }
/// <summary> /// The implementation will look in the current module in focus. If it isn't /// found, it will search the other modules. The last module it checks should /// be the main module. /// </summary> /// <param name="data">The data.</param> /// <param name="dclass">The dclass.</param> /// <param name="template">The template.</param> /// <param name="id">The id.</param> /// <returns></returns> protected internal virtual IFact createFact(Object data, Defclass dclass, String template, long id) { IFact ft = null; ITemplate dft = null; if (template == null) { dft = CurrentFocus.getTemplate(dclass.ClassObject.FullName); } else { dft = CurrentFocus.getTemplate(template); } // if the deftemplate is null, check the other modules if (dft == null) { // Get the entry set from the agenda and iterate IEnumerator itr = modules.Values.GetEnumerator(); while (itr.MoveNext()) { IModule mod = (IModule)itr.Current; if (mod.containsTemplate(dclass)) { dft = mod.getTemplate(dclass); } } // we've searched every module, so now check main if (dft == null && main.containsTemplate(dclass)) { dft = main.getTemplate(dclass); } else { // throw an exception throw new AssertException("Could not find the template"); } } ft = dft.createFact(data, dclass, id); return(ft); }
protected override void OnResume() { // counterpart to OnPause base.OnResume(); if (_application != null && CurrentFocus != null && _application.OnThisPlatform().GetShouldPreserveKeyboardOnResume()) { CurrentFocus.ShowKeyboard(); } _previousState = _currentState; _currentState = AndroidApplicationLifecycleState.OnResume; if (Forms.IsLollipopOrNewer) { // Start listening for power save mode changes RegisterReceiver(_powerSaveModeBroadcastReceiver, new IntentFilter( PowerManager.ActionPowerSaveModeChanged )); } OnStateChanged(); }
protected override void OnResume() { Profile.FrameBegin(); // counterpart to OnPause base.OnResume(); if (_application != null && CurrentFocus != null && _application.OnThisPlatform().GetShouldPreserveKeyboardOnResume()) { CurrentFocus.ShowKeyboard(); } _previousState = _currentState; _currentState = AndroidApplicationLifecycleState.OnResume; if (_needMainPageAssign) { _needMainPageAssign = false; SettingMainPage(); SetMainPage(); } if (!_powerSaveReceiverRegistered && Forms.IsLollipopOrNewer) { // Start listening for power save mode changes RegisterReceiver(_powerSaveModeBroadcastReceiver, new IntentFilter( PowerManager.ActionPowerSaveModeChanged )); _powerSaveReceiverRegistered = true; } OnStateChanged(); Profile.FrameEnd(); }
public NativeInput(Rectangle position, TextInputType textInputType, string text, int textSize, Align textAlign, ITextEdit controller) { if (CurrentFocus != null) { CurrentFocus.Unfocus(); } _controller = controller; CurrentFocus = this; if (_textField != null) { EditTextEx field = _textField; field.OnBackPressed -= UnfocusByBack; _textField = null; DelayedActionInvoker.Instance.AddAction(10, (s) => { AppMain.Current.RootView.RemoveView(field); }); } { InitTextField(); } DisplayMetrics metrics = AppMain.Activity.Resources.DisplayMetrics; int padding = 0; if (textInputType == TextInputType.MultilineText) { padding = 0; } _textField.SetTextSize(Android.Util.ComplexUnitType.Px, (float)(UiUnit.FontUnit * textSize)); _textField.SetHeight(position.Height); _textField.SetPadding(0, padding, _textField.PaddingRight, padding); _textField.InputType = TypeFromContext(textInputType); if (textInputType.HasFlag(TextInputType.Uppercase)) { _textField.SetFilters(new IInputFilter[] { new InputFilterLengthFilter(controller.MaxLength), new InputFilterAllCaps() }); } else { _textField.SetFilters(new IInputFilter[] { new InputFilterLengthFilter(controller.MaxLength) }); } switch (textAlign & Align.Horz) { case Align.Left: _textField.Gravity = GravityFlags.CenterVertical | GravityFlags.Left; break; case Align.Center: _textField.Gravity = GravityFlags.CenterVertical | GravityFlags.CenterHorizontal; break; case Align.Right: _textField.Gravity = GravityFlags.CenterVertical | GravityFlags.Right; break; } if ((textInputType & TextInputType.TypeFilter) == TextInputType.MultilineText) { _textField.SetMaxLines(controller.MaxLines); _textField.EditorAction -= HandleEditorAction; _textField.Gravity = GravityFlags.Left | GravityFlags.Top; _textField.SetSingleLine(false); _textField.ImeOptions = ImeAction.ImeNull | (ImeAction)ImeFlags.NoExtractUi; } else { _textField.SetMaxLines(1); _textField.EditorAction += HandleEditorAction; _textField.SetSingleLine(true); _textField.ImeOptions = (controller.WaitsForReturn ? ImeAction.Next : ImeAction.Done) | (ImeAction)ImeFlags.NoExtractUi; } if (textInputType.HasFlag(TextInputType.NoSuggestions)) { _textField.ImeOptions |= (ImeAction)InputTypes.TextFlagNoSuggestions; } if (Android.OS.Build.VERSION.SdkInt >= Android.OS.BuildVersionCodes.JellyBean) { _textField.SetAllCaps((textInputType & TextInputType.TypeFilter) == TextInputType.Uppercase); } _textField.TransformationMethod = textInputType == TextInputType.Password ? new PasswordTransformationMethod(): null; _layoutParams.SetMargins(position.X, position.Y + 4, 0, 0); _layoutParams.Width = position.Width; _layoutParams.Height = position.Height - 4; _textField.Text = text; _textField.SetSelection(_textField.Text.Length, _textField.Text.Length); _textField.TextChanged += HandleEditingChanged; _textField.FocusChange += HandleFocusChange; _textField.RequestLayout(); _textField.Visibility = Android.Views.ViewStates.Visible; _textField.SetCursorVisible(true); _textField.RequestFocus(); _textField.RequestFocusFromTouch(); ShowKeyboard(_textField); AppMain.Current.RegisterUpdatable(this); }