private void CreateCustomKeyboard()
        {
            var activity = Plugin.CurrentActivity.CrossCurrentActivity.Current.Activity;

            var rootView         = activity.FindViewById(global::Android.Resource.Id.Content);
            var activityRootView = (ViewGroup)((ViewGroup)rootView).GetChildAt(0);

            this.mKeyboardView = activityRootView.FindViewById <KeyboardView>(Droid.Resource.Id.customKeyboard);

            // If the previous line fails, it means the keyboard needs to be created and added
            if (this.mKeyboardView == null)
            {
                this.mKeyboardView =
                    (KeyboardView)activity.LayoutInflater.Inflate(Resource.Layout.customkeyboard, null);
                this.mKeyboardView.Id                   = Resource.Id.customKeyboard;
                this.mKeyboardView.Focusable            = true;
                this.mKeyboardView.FocusableInTouchMode = true;

                this.mKeyboardView.Release += (sender, e) => { };

                var layoutParams = new RelativeLayout.LayoutParams(LayoutParams.MatchParent, LayoutParams.WrapContent);
                layoutParams.AddRule(LayoutRules.AlignParentBottom);
                activityRootView.AddView(this.mKeyboardView, layoutParams);
            }
            EditText.SetTextIsSelectable(true);
            // EditText.SetCursorVisible(true);
            this.HideKeyboardView();

            this.mKeyboard = new Keyboard(this.context, Resource.Xml.special_keyboard);

            this.SetCurrentKeyboard();
        }
Example #2
0
        public void HandleCustomEntry()
        {
            SetContentView(Resource.Layout.Main);                                                                          // xml specifies layout view
            mKeyboard = new Android.InputMethodServices.Keyboard(this, Resource.Xml.keyboard2);                            // KB xml
            et        = (TextView)FindViewById(Resource.Id.target);                                                        // User input is text view. Text entry caused standard KB to appear
            var inputManager = (InputMethodManager)MainActivity.mainActivity.GetSystemService(Context.InputMethodService); // Not necessary now

            inputManager.HideSoftInputFromWindow(et.WindowToken, HideSoftInputFlags.None);
            inputManager.HideSoftInputFromInputMethod(et.WindowToken, HideSoftInputFlags.None);
            Window.DecorView.ClearFocus();
            et.ClearFocus();
            mKeyboardView            = (CustomKeyboardView)this.FindViewById(Resource.Id.keyboard_view);
            mKeyboardView.Keyboard   = mKeyboard;
            mKeyboardView.Visibility = ViewStates.Visible;
            // MainActivity.app.Unfocus();

            /*
             * et.Touch += (sender1, e1) => {
             *  System.Diagnostics.Debug.WriteLine("onTouch - true");
             *  // mKeyboardView.Visibility = ViewStates.Visible;
             *  // ShowKeyboard(mTargetView);
             *  // ShowKeyboardWithAnimation();
             *  // MainActivity.app.Unfocus();
             *  e1.Handled = true;
             * };
             */

            mKeyboardView.Key += (sender1, e1) =>
            {
                long eventTime = JavaSystem.CurrentTimeMillis();
                // System.Diagnostics.Debug.WriteLine("mKeyboardView.Key event, primarycode: " + e1.PrimaryCode);
                if (ProcessKeyCode(e1.PrimaryCode))
                {
                    // System.Diagnostics.Debug.WriteLine("mKeyboardView done with keyboard entry");
                    active = false;
                    Finish();
                }
            };
        }
        public VehiclePlateKeyboard(Context context) : base(context)
        {
            var contentView = PutContentView(
                Resource.Layout.keyboard_vehicle_plate);

            mNumbersTextView[0] = contentView.FindViewById <TextView>(
                Resource.Id.keyboard_number_0);
            mNumbersTextView[1] = contentView.FindViewById <TextView>(
                Resource.Id.keyboard_number_1);
            mNumbersTextView[2] = contentView.FindViewById <TextView>(
                Resource.Id.keyboard_number_2);
            mNumbersTextView[3] = contentView.FindViewById <TextView>(
                Resource.Id.keyboard_number_3);
            mNumbersTextView[4] = contentView.FindViewById <TextView>(
                Resource.Id.keyboard_number_4);
            mNumbersTextView[5] = contentView.FindViewById <TextView>(
                Resource.Id.keyboard_number_5);
            mNumbersTextView[6] = contentView.FindViewById <TextView>(
                Resource.Id.keyboard_number_6);

            foreach (var item in mNumbersTextView)
            {
                item.SoundEffectsEnabled = false;
                item.Click += TextViewItemClick;
            }

            mProvinceKeyboard_0 = new Android.InputMethodServices.Keyboard(
                context, Resource.Xml.keyboard_vehicle_province_0);
            mProvinceKeyboard_1 = new Android.InputMethodServices.Keyboard(
                context, Resource.Xml.keyboard_vehicle_province_1);
            mCityCodeKeyboard = new Android.InputMethodServices.Keyboard(
                context, Resource.Xml.keyboard_vehicle_code);
            mNumberKeyboard = new Android.InputMethodServices.Keyboard(
                context, Resource.Xml.keyboard_vehicle_number);
            mNUmberExtraKeyboard = new Android.InputMethodServices.Keyboard(
                context, Resource.Xml.keyboard_vehicle_number_extra);

            mKeyboardView = contentView.FindViewById <KeyboardView>(
                Resource.Id.keyboard_view);

            mKeyboardView.Key += (sender, keyCodes) =>
            {
                int  code     = (int)keyCodes.KeyCodes[0];
                char charCode = (char)keyCodes.PrimaryCode;
                if (400 < code && code < 500)
                {
                    charCode = PROVINCE_CHINESE[code - 400];
                }
                else if (500 < code)
                {
                    charCode = EXTRA_CHINESE[code - 500];
                }
                mSelectedTextView.Text = ((char)charCode).ToString();
                NextNumber();
            };
            mKeyboardView.PreviewEnabled = false;

            mCommitButton = contentView.FindViewById <Button>(
                Resource.Id.keyboard_commit);
            mCommitButton.Click += (s, e) =>
            {
                string number = GetInput(mNumbersTextView);
                if (number.Length == mNumbersTextView.Length)
                {
                    OnFinish(number);
                    Dismiss();
                }
            };
        }