Esempio n. 1
0
        protected override void OnCreate(Bundle bundle)
        {
            base.OnCreate(bundle);

            // Set our view from the "main" layout resource
            SetContentView(Resource.Layout.Main);

            _hoursPicker = FindViewById<NumberPicker>(Resource.Id.testHoursNumberPicker);
            _minutesPicker = FindViewById<NumberPicker>(Resource.Id.testMinutesNumberPicker);

            _hoursPicker.ValueChanged += (sender, args) => ValidateFieldsAndEnableButton();
            _minutesPicker.ValueChanged += (sender, args) => ValidateFieldsAndEnableButton();

            _hoursPicker.MaxValue = 12;
            _hoursPicker.MinValue = 0;

            _minutesPicker.MaxValue = 59;
            _minutesPicker.MinValue = 0;

            _inputManager = (InputMethodManager)GetSystemService(Context.InputMethodService);

            EditText hoursEditText = (EditText)_hoursPicker.GetChildAt(0);
            hoursEditText.Focusable = true;
            hoursEditText.FocusableInTouchMode = true;

            hoursEditText.FocusChange += HandleEditTextFocusChangedForKeyboard;

            //_inputManager.ShowSoftInput(hoursEditText, ShowFlags.Implicit);

            EditText minutesEditText = (EditText)_hoursPicker.GetChildAt(0);
            minutesEditText.Focusable = true;
            minutesEditText.FocusableInTouchMode = true;

            minutesEditText.FocusChange += HandleEditTextFocusChangedForKeyboard;

            //_inputManager.ShowSoftInput(minutesEditText, ShowFlags.Implicit);

            _totalQuestionsTextBox = FindViewById<EditText>(Resource.Id.totalQuestionsTextBox);
            _totalQuestionsTextBox.TextChanged += (sender, args) => ValidateFieldsAndEnableButton();
            //_inputManager.ShowSoftInput(_totalQuestionsTextBox, ShowFlags.Implicit);

            _totalQuestionsTextBox.FocusChange += HandleEditTextFocusChangedForKeyboard;

            _startTimeButton = FindViewById<Button>(Resource.Id.startTimerButton);

            _startTimeButton.Click += delegate
            {
                int numberOfQuestions = !string.IsNullOrEmpty(_totalQuestionsTextBox.Text)
                    ? Convert.ToInt32(_totalQuestionsTextBox.Text)
                    : 0;

                if (_hoursPicker.Value == 0 && _minutesPicker.Value == 0 || numberOfQuestions == 0)
                {
                    return;
                }

                var intent = new Intent(this, typeof(TimerViewActivity));
                intent.PutExtra("hours", _hoursPicker.Value);
                intent.PutExtra("minutes", _minutesPicker.Value);
                intent.PutExtra("questions", numberOfQuestions);
                StartActivity(intent);
            };

            ValidateFieldsAndEnableButton();
        }
        static void SetNumberPickerTextColor(NumberPicker numberPicker, Color color)
        {
            try
            {
                int count = numberPicker.ChildCount;
                for (int i = 0; i < count; i++)
                {
                    View child = numberPicker.GetChildAt(i);
                    if (child is EditText)
                    {
                        try
                        {
                            Field selectorWheelPaintField = numberPicker.Class
                                .GetDeclaredField("mSelectorWheelPaint");
                            selectorWheelPaintField.Accessible = true;
                            ((Paint)selectorWheelPaintField.Get(numberPicker)).Color = color;

                            Field selectionDivider = numberPicker.Class.GetDeclaredField("mSelectionDivider");
                            selectionDivider.Accessible = true;
                            selectionDivider.Set(numberPicker, numberPicker.Context.Resources.GetDrawable(Resource.Drawable.numberpicker_selection_divider));
                            
                            ((EditText)child).SetTextColor(color);
                        }
                        catch (NoSuchFieldException e)
                        {
                            Log.Debug("setNumberPickerTextColor", e.Message);
                        }
                        catch (IllegalAccessException e)
                        {
                            Log.Debug("setNumberPickerTextColor", e.Message);
                        }
                        catch (Resources.NotFoundException e)
                        {
                            Log.Debug("setNumberPickerTextColor", e.Message);
                        }
                    }
                }

                numberPicker.Invalidate();
            }
            catch
            {

            }
        }