Esempio n. 1
0
        public void _backspaceRepeat(UIButton button)
        {
            IUIKeyInput keyInput = this.keyInput;

            if (!keyInput.HasText)
            {
                return;
            }

            this._buttonPlayClick(button);
            this._buttonInput(button);
        }
Esempio n. 2
0
        public void _buttonInput(UIButton button)
        {
            MMNumberKeyboardButton keyboardButton = MMNumberKeyboardButton.None;

            //https://github.com/xamarin/monotouch-samples/blob/master/AppPrefs/Settings.cs
            //NSArray.FromArray<NSDictionary> (
            //	foreach (KeyValuePair<NSObject,NSObject> t in this.buttonDictionary.GetEnumerator<KeyValuePair<NSObject,NSObject>>()) {
            //foreach (var t in this.buttonDictionary.GetEnumerator()) {
            //	this.buttonDictionary.
            //foreach (var item  in NSArray.FromArray<NSDictionary> (this.buttonDictionary.GetEnumerator)) {
            for (nuint i = 0; i < this.buttonDictionary.Count; i++)
            {
                //id key, id obj, BOOL *stop
                NSObject key = this.buttonDictionary.Keys[i];
                NSObject obj = this.buttonDictionary.Values[i];

                MMNumberKeyboardButton k = (MMNumberKeyboardButton)Enum.Parse(typeof(MMNumberKeyboardButton), key.ToString());
                if (button == obj)
                {
                    keyboardButton = k;
                    //stop = true;
                    break;
                }
            }

            if (keyboardButton == MMNumberKeyboardButton.None)
            {
                return;
            }

            // Get first responder.
            IUIKeyInput keyInput = this.keyInput;
            MMNumberKeyboardDelegate Delegate = this.Delegate;

            if (!(keyInput != null))
            {
                return;
            }

            // Handle number.
            /*const*/ MMNumberKeyboardButton numberMin = MMNumberKeyboardButton.NumberMin;
            /*const*/ MMNumberKeyboardButton numberMax = MMNumberKeyboardButton.NumberMax;

            if (keyboardButton >= numberMin && keyboardButton < numberMax)
            {
                NSNumber number  = NSNumber.FromNInt(keyboardButton - numberMin);
                string   @string = number.ToString();

                if (Delegate.RespondsToSelector(new Selector("numberKeyboard:shouldAddText:")))
                {
                    //bool  shouldAdd = Delegate.numberKeyboard(this ,/*shouldAddText*/ @string);
                    //bool  shouldAdd = Delegate.Invoke("numberKeyboard", new [] {this ,/*shouldAddText*/ @string});
                    bool shouldAdd = (bool)Delegate.Invoke("numberKeyboard", this, /*shouldAddText*/ @string);
                    if (!shouldAdd)
                    {
                        return;
                    }
                }

                keyInput.InsertText(@string);
            }

            // Handle backspace.
            else if (keyboardButton == MMNumberKeyboardButton.Backspace)
            {
                keyInput.DeleteBackward();
            }

            // Handle done.
            else if (keyboardButton == MMNumberKeyboardButton.Done)
            {
                bool shouldReturn = true;

                if (Delegate.RespondsToSelector(new Selector("numberKeyboardShouldReturn*/ ")))
                {
                    shouldReturn = (bool)Delegate.Invoke("numberKeyboardShouldReturn", this);
                }

                if (shouldReturn)
                {
                    this._dismissKeyboard(button);
                }
            }

            // Handle special key.
            else if (keyboardButton == MMNumberKeyboardButton.Special)
            {
                Action handler = this.specialKeyHandler;
                if (handler != null)
                {
                    handler();
                }
            }

            // Handle .
            else if (keyboardButton == MMNumberKeyboardButton.DecimalPoint)
            {
                string decimalText = button.Title(UIControlState.Normal);
                if (Delegate.RespondsToSelector(new Selector("numberKeyboard:shouldAddText:")))
                {
                    bool shouldAdd = (bool)Delegate.Invoke("numberKeyboard", new object[] { this, /*shouldAddText*/ decimalText });
                    if (!shouldAdd)
                    {
                        return;
                    }
                }

                keyInput.InsertText(decimalText);
            }
        }