Kristof
Topic Author
Posts: 19
Joined: 22 Apr 2014, 14:44

Need more control over the touchscreen keyboard

05 Jun 2014, 12:56

On Android and iOS, when a textbox gets focus then the touchscreen keyboard is opened automatically.

However I need more control over this touchscreen keyboard:
* When the textbox is for an email address, the specific email keyboard should open (with the '@' key).
* I would like to disable the 'text preview'.

I see how I can do this in Unity (http://docs.unity3d.com/Manual/MobileKe ... ml#Android). However I don't see how I can wire this up in NoesisGUI.

The correct point to look at seems to be "NoesisGUISystem.OverrideDefaultSoftwareKeyboardCallbacks()", however I don't know how I can get a reference to the NoesisGUISystem instance.

What would be the recommended approach here?

Kristof
Last edited by Kristof on 12 Jun 2014, 10:53, edited 1 time in total.
 
User avatar
sfernandez
Site Admin
Posts: 2908
Joined: 22 Dec 2011, 19:20

Re: Need more control over the touchscreen keyboard

06 Jun 2014, 02:23

Yes, the way to have more control over the software keyboard is overriding the default behaviour by providing your own callbacks.

You can get the instance this way:
GameObject go = GameObject.Find("NoesisGUISystem");
NoesisGUISystem noesisGUI = go.GetComponent<NoesisGUISystem>();
Or just modify the NoesisGUISystem.cs script and add a new static property to make the instance public:
public static NoesisGUISystem Instance
{
  get { return _instance; }
}
We will add this for the following release to make things easier.
 
Kristof
Topic Author
Posts: 19
Joined: 22 Apr 2014, 14:44

Re: Need more control over the touchscreen keyboard

10 Jun 2014, 11:23

I've implemented your second solution and it indeed does the trick. Thanks a lot!
 
Kristof
Topic Author
Posts: 19
Joined: 22 Apr 2014, 14:44

Re: Need more control over the touchscreen keyboard

10 Jun 2014, 15:08

While at first the proposed solution seemed to solve my problem, I still can't get the functionality that I want.

I have made a helper-class to display the touch-keyboard. This class has exactly the same functionality as the NoesisGUISystem class relating to the keyboard. The idea is that I will extend this class to support more functionality (e.g. showing a keyboard for email addresses).

However this helper-class does not work (although it contains the same functionality as NoesisGUISystem):
[*] Whatever text is typed in the keyboard is not copied into the textbox
[*] From some logging I have found out that the 'text' property of the keyboard is always null.
[*] When the keyboard is closed, it always reopens automatically

I've added my code below. Does anybody have an idea of what I am doing wrong here?
class TouchKeyboardHelper : MonoBehaviour
{

    public void Start()
    {
        NoesisGUISystem.Instance.OverrideDefaultSoftwareKeyboardCallbacks(ShowSoftwareKeyboard, HideSoftwareKeyboard);
    }

    private Noesis.Control _focusedElement = null;
    private TouchScreenKeyboard _keyboard = null;
    private bool _keyboardActivated = false;

    private void ShowSoftwareKeyboard(UIElement focusedElement)
    {
        if (focusedElement != null)
        {
            var tb = focusedElement.As<Noesis.TextBox>();
            if (tb != null)
            {
                _focusedElement = tb;
                _keyboard = TouchScreenKeyboard.Open(tb.GetText());
            }
            else
            {
                var pb = focusedElement.As<Noesis.PasswordBox>();
                if (pb != null)
                {
                    _focusedElement = pb;
                    _keyboard = TouchScreenKeyboard.Open(pb.GetPassword(),
                        TouchScreenKeyboardType.Default, false, false, true);
                }
            }
        }
    }

    private void HideSoftwareKeyboard()
    {
        if (_keyboard != null)
        {
            // TODO: Force software keyboard to hide

            _focusedElement = null;
            _keyboard = null;
        }
    }
       

    public void Update()
    {
        UpdateText();
    }

    private void UpdateText()
    {
        if (_focusedElement != null && _keyboard != null)
        {
            if (_keyboard.active)
            {
                _keyboardActivated = true;

                var tb = _focusedElement.As<Noesis.TextBox>();
                if (tb != null)
                {
                    tb.SetText(_keyboard.text);
                }
                else
                {
                    var pb = _focusedElement.As<Noesis.PasswordBox>();
                    pb.SetPassword(_keyboard.text);
                }
            }

            if (_keyboardActivated)
            {
                if (_keyboard.done || _keyboard.wasCanceled)
                {
                    _keyboardActivated = false;

                    // Remove focus from the text box
                    _focusedElement.GetKeyboard().Focus(null);
                }
            }
        }
    }
}
 
User avatar
sfernandez
Site Admin
Posts: 2908
Joined: 22 Dec 2011, 19:20

Re: Need more control over the touchscreen keyboard

16 Jun 2014, 13:40

I found the source of all the problems you described. NoesisGUISystem exposes the IsSoftwareKeyboardActive property that is used by NoesisGUIPanel to update the focus of the application when OnApplicationFocus message is received.

If you take a look at the implementation of IsSoftwareKeyboardActive property, it relies on the _keyboard member variable, that is not modified if you override the default software keyboard callbacks.

To solve it, modify that property to something like this:
#if !UNITY_STANDALONE
    private bool _keyboardActive = false;
#endif

    public static bool IsSoftwareKeyboardActive
    {
        get
        {
#if !UNITY_STANDALONE
            if (_isInitialized)
            {
                return _instance._keyboardActive;
            }
#endif
            return false;
        }
        set
        {
#if !UNITY_STANDALONE
            if (_isInitialized)
            {
                _instance._keyboardActive = value;
            }
#endif
        }
    }
And update this property when software keyboard is shown and hidden.
_keyboard = TouchScreenKeyboard.Open(tb.GetText());
NoesisGUISystem.IsSoftwareKeyboardActive = true;
_keyboard = null;
NoesisGUISystem.IsSoftwareKeyboardActive = false;
We have to simplify this code to make it easier for users to override the default behavior. We'll try to improve it for the next version.
 
User avatar
sfernandez
Site Admin
Posts: 2908
Joined: 22 Dec 2011, 19:20

Re: Need more control over the touchscreen keyboard

27 Jun 2014, 15:14

In the upcoming 1.1.9 version we are going to improve the way default software keyboard management can be overridden. We will expose a base SoftwareKeyboardManager that can be inherited to modify how TouchScreen keyboard is opened, or to override completely how software keyboard is managed. There will be more info in the 'First steps with NoesisGUI in Unity' tutorial.
 
User avatar
sfernandez
Site Admin
Posts: 2908
Joined: 22 Dec 2011, 19:20

Re: Need more control over the touchscreen keyboard

01 Jul 2014, 15:01

Improvements done in current 1.1.9 version.
Take a look at the documentation (Software Keyboard section): http://www.noesisengine.com/docs/Gui.Co ... orial.html
 
Kristof
Topic Author
Posts: 19
Joined: 22 Apr 2014, 14:44

Re: Need more control over the touchscreen keyboard

02 Jul 2014, 13:59

Thanks, that's exactly what I need.

Who is online

Users browsing this forum: Ahrefs [Bot] and 4 guests