Ejemplo n.º 1
0
        private void DeactivateEditTextImpl()
        {
            if (activeEditText == null)
            {
                throw new Exception("Internal error: Can not deactivate the EditText, it is already nullified");
            }

            // remove callbacks
            editText.EditorAction     -= AndroidEditTextOnEditorAction;
            editText.AfterTextChanged -= AndroidEditTextOnAfterTextChanged;

            editText.ClearFocus();

            editText       = null;
            activeEditText = null;

            // remove the edit text from the layout and hide the layout
            GetGameContext().EditTextLayout.Visibility = ViewStates.Gone;

            // deactivate the ime (hide the keyboard)
            if (staticEditText != null) // staticEditText can be null if window have already been detached.
            {
                inputMethodManager.HideSoftInputFromWindow(staticEditText.WindowToken, HideSoftInputFlags.None);
            }
            inputMethodManager = null;

            FocusedElement = null;
        }
Ejemplo n.º 2
0
        private void ActivateEditTextImpl()
        {
            if (activeEditText != null)
            {
                throw new Exception("Internal error: Can not activate edit text, another edit text is already active");
            }

            EnsureStaticEditText();

            activeEditText = this;
            editText       = staticEditText;

            // set up the initial state of the android EditText
            UpdateInputTypeImpl();

            editText.SetMaxLines(MaxLines);
            editText.SetMinLines(MinLines);

            UpdateTextToEditImpl();
            UpdateSelectionToEditImpl();

            // add callbacks
            editText.EditorAction     += AndroidEditTextOnEditorAction;
            editText.AfterTextChanged += AndroidEditTextOnAfterTextChanged;

            // add the edit to the overlay layout and show the layout
            GetGameContext().EditTextLayout.Visibility = ViewStates.Visible;

            // set the focus to the edit box
            editText.RequestFocus();

            // activate the ime (show the keyboard)
            inputMethodManager = (InputMethodManager)PlatformAndroid.Context.GetSystemService(Context.InputMethodService);
            inputMethodManager.ShowSoftInput(staticEditText, ShowFlags.Forced);
        }
Ejemplo n.º 3
0
        // Delay creation of static edit text to last moment when we are sure to be in Android UI thread.
        // -> some Android phones crashes when native edit text is created from another thread than OS UI thread.
        private void EnsureStaticEditText()
        {
            if (staticEditText == null)
            {
                // create and add the edit text
                staticEditText = new MyAndroidEditText(PlatformAndroid.Context);

                var editLayoutParams = new RelativeLayout.LayoutParams(ViewGroup.LayoutParams.MatchParent, ViewGroup.LayoutParams.WrapContent);
                editLayoutParams.SetMargins(75, 200, 75, 0);
                GetGameContext().EditTextLayout.AddView(staticEditText, editLayoutParams);
            }
        }
Ejemplo n.º 4
0
        // Delay creation of static edit text to last moment when we are sure to be in Android UI thread.
        // -> some Android phones crashes when native edit text is created from another thread than OS UI thread.
        private void EnsureStaticEditText()
        {
            if (staticEditText == null)
            {
                // create and add the edit text
                staticEditText = new MyAndroidEditText(PlatformAndroid.Context);

                var editLayoutParams = new RelativeLayout.LayoutParams(ViewGroup.LayoutParams.MatchParent, ViewGroup.LayoutParams.WrapContent);
                editLayoutParams.SetMargins(75, 200, 75, 0);
                GetGameContext().EditTextLayout.AddView(staticEditText, editLayoutParams);
            }
        }
Ejemplo n.º 5
0
        protected override void OnUISystemChanged(UISystem system)
        {
            base.OnUISystemChanged(system);

            // create the Android OS edit text only when element is inserted into hierarchy.
            if (staticEditText == null)
            {
                // create and add the edit text
                staticEditText = new MyAndroidEditText(PlatformAndroid.Context);

                var editLayoutParams = new RelativeLayout.LayoutParams(ViewGroup.LayoutParams.MatchParent, ViewGroup.LayoutParams.WrapContent);
                editLayoutParams.SetMargins(75, 200, 75, 0);
                game.Context.EditTextLayout.AddView(staticEditText, editLayoutParams);
            }
        }
Ejemplo n.º 6
0
        private void DeactivateEditTextImpl()
        {
            if (activeEditText == null)
                throw new Exception("Internal error: Can not deactivate the EditText, it is already nullified");

            // remove callbacks
            editText.EditorAction -= AndroidEditTextOnEditorAction;
            editText.AfterTextChanged -= AndroidEditTextOnAfterTextChanged;

            editText.ClearFocus();

            editText = null;
            activeEditText = null;

            // remove the edit text from the layout and hide the layout
            GetGameContext().EditTextLayout.Visibility = ViewStates.Gone;

            // deactivate the ime (hide the keyboard)
            if (staticEditText != null) // staticEditText can be null if window have already been detached.
                inputMethodManager.HideSoftInputFromWindow(staticEditText.WindowToken, HideSoftInputFlags.None);
            inputMethodManager = null;

            FocusedElement = null;
        }
Ejemplo n.º 7
0
        private void ActivateEditTextImpl()
        {
            if(activeEditText != null)
                throw new Exception("Internal error: Can not activate edit text, another edit text is already active");

            EnsureStaticEditText();

            activeEditText = this;
            editText = staticEditText;
            
            // set up the initial state of the android EditText
            UpdateInputTypeImpl();

            editText.SetMaxLines(MaxLines);
            editText.SetMinLines(MinLines);

            UpdateTextToEditImpl();
            UpdateSelectionToEditImpl();

            // add callbacks
            editText.EditorAction += AndroidEditTextOnEditorAction;
            editText.AfterTextChanged += AndroidEditTextOnAfterTextChanged;

            // add the edit to the overlay layout and show the layout
            GetGameContext().EditTextLayout.Visibility = ViewStates.Visible;

            // set the focus to the edit box
            editText.RequestFocus();

            // activate the ime (show the keyboard)
            inputMethodManager = (InputMethodManager)PlatformAndroid.Context.GetSystemService(Context.InputMethodService);
            inputMethodManager.ShowSoftInput(staticEditText, ShowFlags.Forced);
        }