protected override void OnElementChanged(ElementChangedEventArgs <Button> e) { base.OnElementChanged(e); if (e.OldElement == null) { AButton button = Control; if (button == null) { button = CreateNativeControl(); button.SetOnClickListener(ButtonClickListener.Instance.Value); button.SetOnTouchListener(ButtonTouchListener.Instance.Value); button.Tag = this; SetNativeControl(button); _textColorSwitcher = new TextColorSwitcher(button.TextColors); button.AddOnAttachStateChangeListener(this); } } else { if (_drawableEnabled) { _drawableEnabled = false; _backgroundDrawable.Reset(); _backgroundDrawable = null; } } UpdateAll(); }
protected override void OnElementChanged(ElementChangedEventArgs <Picker> e) { if (e.OldElement != null) { ((INotifyCollectionChanged)e.OldElement.Items).CollectionChanged -= RowsCollectionChanged; } if (e.NewElement != null) { ((INotifyCollectionChanged)e.NewElement.Items).CollectionChanged += RowsCollectionChanged; if (Control == null) { var textField = CreateNativeControl(); var useLegacyColorManagement = e.NewElement.UseLegacyColorManagement(); _textColorSwitcher = new TextColorSwitcher(textField.TextColors, useLegacyColorManagement); SetNativeControl(textField); _originalHintTextColor = Control.CurrentHintTextColor; } UpdateFont(); UpdatePicker(); UpdateTextColor(); } base.OnElementChanged(e); }
protected override void OnElementChanged(ElementChangedEventArgs <Picker> e) { if (e.OldElement != null) { ((ObservableList <string>)e.OldElement.Items).CollectionChanged -= RowsCollectionChanged; } if (e.NewElement != null) { ((ObservableList <string>)e.NewElement.Items).CollectionChanged += RowsCollectionChanged; if (Control == null) { var textField = new EditText(Context) { Focusable = false, Clickable = true, Tag = this }; textField.SetOnClickListener(PickerListener.Instance); _textColorSwitcher = new TextColorSwitcher(textField.TextColors); SetNativeControl(textField); } UpdatePicker(); UpdateTextColor(); } base.OnElementChanged(e); }
protected override void OnElementChanged(ElementChangedEventArgs <Picker> e) { if (e.OldElement != null) { ((INotifyCollectionChanged)e.OldElement.Items).CollectionChanged -= RowsCollectionChanged; } if (e.NewElement != null) { ((INotifyCollectionChanged)e.NewElement.Items).CollectionChanged += RowsCollectionChanged; if (Control == null) { var textField = CreateNativeControl(); textField.SetOnClickListener(PickerListener.Instance); _textColorSwitcher = new TextColorSwitcher(textField.TextColors); SetNativeControl(textField); } UpdateFont(); UpdatePicker(); UpdateTextColor(); } base.OnElementChanged(e); }
protected override void OnElementChanged(ElementChangedEventArgs <Button> e) { base.OnElementChanged(e); if (e.OldElement == null) { AButton button = Control; if (button == null) { button = CreateNativeControl(); button.SetOnClickListener(ButtonClickListener.Instance.Value); button.SetOnTouchListener(ButtonTouchListener.Instance.Value); button.Tag = this; SetNativeControl(button); var useLegacyColorManagement = e.NewElement.UseLegacyColorManagement(); _textColorSwitcher = new TextColorSwitcher(button.TextColors, useLegacyColorManagement); button.AddOnAttachStateChangeListener(this); } } if (_backgroundTracker == null) { _backgroundTracker = new ButtonBackgroundTracker(Element, Control); } else { _backgroundTracker.Button = e.NewElement; } UpdateAll(); }
protected override void OnElementChanged(ElementChangedEventArgs <TimePicker> e) { base.OnElementChanged(e); if (e.OldElement == null) { var textField = CreateNativeControl(); textField.SetOnClickListener(TimePickerListener.Instance); SetNativeControl(textField); var useLegacyColorManagement = e.NewElement.UseLegacyColorManagement(); _textColorSwitcher = new TextColorSwitcher(textField.TextColors, useLegacyColorManagement); _is24HourFormat = DateFormat.Is24HourFormat(Context); _timeFormat = _is24HourFormat ? "HH:mm" : Element.Format; } SetTime(e.NewElement.Time); UpdateTextColor(); if ((int)Build.VERSION.SdkInt > 16) { Control.TextAlignment = global::Android.Views.TextAlignment.ViewStart; } }
protected override void OnElementChanged(ElementChangedEventArgs <Editor> e) { base.OnElementChanged(e); HandleKeyboardOnFocus = true; var edit = Control; if (edit == null) { edit = CreateNativeControl(); SetNativeControl(edit); edit.AddTextChangedListener(this); edit.OnKeyboardBackPressed += OnKeyboardBackPressed; var useLegacyColorManagement = e.NewElement.UseLegacyColorManagement(); _textColorSwitcher = new TextColorSwitcher(edit.TextColors, useLegacyColorManagement); } edit.SetSingleLine(false); edit.Gravity = GravityFlags.Top; if ((int)Build.VERSION.SdkInt > 16) { edit.TextAlignment = global::Android.Views.TextAlignment.ViewStart; } edit.SetHorizontallyScrolling(false); UpdateText(); UpdateInputType(); UpdateTextColor(); UpdateFont(); }
protected override void OnElementChanged(ElementChangedEventArgs <Entry> e) { base.OnElementChanged(e); HandleKeyboardOnFocus = true; if (e.OldElement == null) { var textView = CreateNativeControl(); textView.AddTextChangedListener(this); textView.SetOnEditorActionListener(this); textView.OnKeyboardBackPressed += OnKeyboardBackPressed; textView.SelectionChanged += SelectionChanged; var useLegacyColorManagement = e.NewElement.UseLegacyColorManagement(); _textColorSwitcher = new TextColorSwitcher(textView.TextColors, useLegacyColorManagement); _hintColorSwitcher = new TextColorSwitcher(textView.HintTextColors, useLegacyColorManagement); SetNativeControl(textView); } Control.Hint = Element.Placeholder; Control.Text = Element.Text; UpdateInputType(); UpdateColor(); UpdateAlignment(); UpdateFont(); UpdatePlaceholderColor(); UpdateMaxLength(); UpdateImeOptions(); UpdateReturnType(); UpdateCursorSelection(); }
protected override void OnElementChanged(ElementChangedEventArgs <SearchBar> e) { base.OnElementChanged(e); SearchView searchView = Control; var isDesigner = Context.IsDesignerContext(); if (searchView == null) { searchView = CreateNativeControl(); searchView.SetIconifiedByDefault(false); // set Iconified calls onSearchClicked // https://github.com/aosp-mirror/platform_frameworks_base/blob/6d891937a38220b0c712a1927f969e74bea3a0f3/core/java/android/widget/SearchView.java#L674-L680 // which causes requestFocus. The designer does not support focuses. if (!isDesigner) { searchView.Iconified = false; } SetNativeControl(searchView); _editText = _editText ?? Control.GetChildrenOfType <EditText>().FirstOrDefault(); if (_editText != null) { var useLegacyColorManagement = e.NewElement.UseLegacyColorManagement(); _textColorSwitcher = new TextColorSwitcher(_editText.TextColors, useLegacyColorManagement); _hintColorSwitcher = new TextColorSwitcher(_editText.HintTextColors, useLegacyColorManagement); } } if (!isDesigner) { ClearFocus(searchView); } UpdateInputType(); UpdatePlaceholder(); UpdateText(); UpdateEnabled(); UpdateCancelButtonColor(); UpdateFont(); UpdateHorizontalTextAlignment(); UpdateVerticalTextAlignment(); UpdateTextColor(); UpdateCharacterSpacing(); UpdatePlaceholderColor(); UpdateMaxLength(); if (e.OldElement == null) { searchView.SetOnQueryTextListener(this); searchView.SetOnQueryTextFocusChangeListener(this); } }
protected override void OnElementChanged(ElementChangedEventArgs <SearchBar> e) { base.OnElementChanged(e); HandleKeyboardOnFocus = true; SearchView searchView = Control; if (searchView == null) { searchView = CreateNativeControl(); searchView.SetIconifiedByDefault(false); searchView.Iconified = false; SetNativeControl(searchView); _editText = _editText ?? Control.GetChildrenOfType <EditText>().FirstOrDefault(); if (_editText != null) { var useLegacyColorManagement = e.NewElement.UseLegacyColorManagement(); _textColorSwitcher = new TextColorSwitcher(_editText.TextColors, useLegacyColorManagement); _hintColorSwitcher = new TextColorSwitcher(_editText.HintTextColors, useLegacyColorManagement); } } BuildVersionCodes androidVersion = Build.VERSION.SdkInt; if (androidVersion >= BuildVersionCodes.JellyBean) { _inputType = searchView.InputType; } else { // < API 16, Cannot get the default InputType for a SearchView _inputType = InputTypes.ClassText | InputTypes.TextFlagAutoComplete | InputTypes.TextFlagNoSuggestions; } ClearFocus(searchView); UpdatePlaceholder(); UpdateText(); UpdateEnabled(); UpdateCancelButtonColor(); UpdateFont(); UpdateAlignment(); UpdateTextColor(); UpdatePlaceholderColor(); if (e.OldElement == null) { searchView.SetOnQueryTextListener(this); searchView.SetOnQueryTextFocusChangeListener(this); } }
public SearchHandlerAppearanceTracker(IShellSearchView searchView) { _searchHandler = searchView.SearchHandler; _control = searchView.View; _searchHandler.PropertyChanged += SearchHandlerPropertyChanged; _searchHandler.FocusChangeRequested += SearchHandlerFocusChangeRequested; _editText = (_control as ViewGroup).GetChildrenOfType <EditText>().FirstOrDefault(); _textColorSwitcher = new TextColorSwitcher(_editText.TextColors, false); _hintColorSwitcher = new TextColorSwitcher(_editText.HintTextColors, false); UpdateSearchBarColors(); UpdateFont(); UpdateTextAlignment(); UpdateInputType(); }
protected override void OnElementChanged(ElementChangedEventArgs <TimePicker> e) { base.OnElementChanged(e); if (e.OldElement == null) { var textField = CreateNativeControl(); textField.SetOnClickListener(TimePickerListener.Instance); SetNativeControl(textField); _textColorSwitcher = new TextColorSwitcher(textField.TextColors); } SetTime(e.NewElement.Time); UpdateTextColor(); }
protected override void OnElementChanged(ElementChangedEventArgs <Entry> e) { base.OnElementChanged(e); if (e.OldElement == null) { SetNativeControl(CreateNativeControl()); EditText.AddTextChangedListener(this); EditText.SetOnEditorActionListener(this); if (EditText is IFormsEditText formsEditText) { formsEditText.OnKeyboardBackPressed += OnKeyboardBackPressed; formsEditText.SelectionChanged += SelectionChanged; } var useLegacyColorManagement = e.NewElement.UseLegacyColorManagement(); _textColorSwitcher = new TextColorSwitcher(EditText.TextColors, useLegacyColorManagement); _hintColorSwitcher = new TextColorSwitcher(EditText.HintTextColors, useLegacyColorManagement); } // When we set the control text, it triggers the SelectionChanged event, which updates CursorPosition and SelectionLength; // These one-time-use variables will let us initialize a CursorPosition and SelectionLength via ctor/xaml/etc. _cursorPositionChangePending = Element.IsSet(Entry.CursorPositionProperty); _selectionLengthChangePending = Element.IsSet(Entry.SelectionLengthProperty); UpdatePlaceHolderText(); EditText.Text = Element.Text; UpdateInputType(); UpdateColor(); UpdateAlignment(); UpdateFont(); UpdatePlaceholderColor(); UpdateMaxLength(); UpdateImeOptions(); UpdateReturnType(); UpdateIsReadOnly(); if (_cursorPositionChangePending || _selectionLengthChangePending) { UpdateCursorSelection(); } }
protected override void OnElementChanged(ElementChangedEventArgs <DatePicker> e) { base.OnElementChanged(e); if (e.OldElement == null) { var textField = CreateNativeControl(); textField.SetOnClickListener(TextFieldClickHandler.Instance); SetNativeControl(textField); _textColorSwitcher = new TextColorSwitcher(textField.TextColors); } SetDate(Element.Date); UpdateMinimumDate(); UpdateMaximumDate(); UpdateTextColor(); }
protected override void OnElementChanged(ElementChangedEventArgs <TimePicker> e) { base.OnElementChanged(e); if (e.OldElement == null) { var textField = new EditText(Context) { Focusable = false, Clickable = true, Tag = this }; textField.SetOnClickListener(TimePickerListener.Instance); SetNativeControl(textField); _textColorSwitcher = new TextColorSwitcher(textField.TextColors); } SetTime(e.NewElement.Time); UpdateTextColor(); }
protected override void OnElementChanged(ElementChangedEventArgs <SearchBar> e) { base.OnElementChanged(e); SearchView searchView = Control; if (searchView == null) { searchView = CreateNativeControl(); searchView.SetIconifiedByDefault(false); searchView.Iconified = false; SetNativeControl(searchView); _editText = _editText ?? Control.GetChildrenOfType <EditText>().FirstOrDefault(); if (_editText != null) { var useLegacyColorManagement = e.NewElement.UseLegacyColorManagement(); _textColorSwitcher = new TextColorSwitcher(_editText.TextColors, useLegacyColorManagement); _hintColorSwitcher = new TextColorSwitcher(_editText.HintTextColors, useLegacyColorManagement); } } ClearFocus(searchView); UpdateInputType(); UpdatePlaceholder(); UpdateText(); UpdateEnabled(); UpdateCancelButtonColor(); UpdateFont(); UpdateHorizontalTextAlignment(); UpdateVerticalTextAlignment(); UpdateTextColor(); UpdateCharacterSpacing(); UpdatePlaceholderColor(); UpdateMaxLength(); if (e.OldElement == null) { searchView.SetOnQueryTextListener(this); searchView.SetOnQueryTextFocusChangeListener(this); } }
protected override void OnElementChanged(ElementChangedEventArgs <DatePicker> e) { base.OnElementChanged(e); if (e.OldElement == null) { var textField = CreateNativeControl(); SetNativeControl(textField); var useLegacyColorManagement = e.NewElement.UseLegacyColorManagement(); _textColorSwitcher = new TextColorSwitcher(textField.TextColors, useLegacyColorManagement); } SetDate(Element.Date); UpdateFont(); UpdateMinimumDate(); UpdateMaximumDate(); UpdateTextColor(); }
protected override void OnElementChanged(ElementChangedEventArgs <Editor> e) { base.OnElementChanged(e); var edit = Control; if (edit == null) { edit = CreateNativeControl(); SetNativeControl(edit); edit.AddTextChangedListener(this); if (edit is IFormsEditText formsEditText) { formsEditText.OnKeyboardBackPressed += OnKeyboardBackPressed; } var useLegacyColorManagement = e.NewElement.UseLegacyColorManagement(); _textColorSwitcher = new TextColorSwitcher(edit.TextColors, useLegacyColorManagement); defaultPlaceholdercolor = Control.HintTextColors; } edit.SetSingleLine(false); edit.Gravity = GravityFlags.Top; if ((int)Build.VERSION.SdkInt > 16) { edit.TextAlignment = global::Android.Views.TextAlignment.ViewStart; } edit.SetHorizontallyScrolling(false); UpdateText(); UpdateInputType(); UpdateTextColor(); UpdateFont(); UpdateMaxLength(); UpdatePlaceholderColor(); UpdatePlaceholderText(); UpdateIsReadOnly(); }
protected override void OnElementChanged(ElementChangedEventArgs <DatePicker> e) { base.OnElementChanged(e); if (e.OldElement == null) { var textField = CreateNativeControl(); textField.SetOnClickListener(TextFieldClickHandler.Instance); textField.InputType = InputTypes.Null; textField.KeyPress += TextFieldKeyPress; SetNativeControl(textField); var useLegacyColorManagement = e.NewElement.UseLegacyColorManagement(); _textColorSwitcher = new TextColorSwitcher(textField.TextColors, useLegacyColorManagement); } SetDate(Element.Date); UpdateFont(); UpdateMinimumDate(); UpdateMaximumDate(); UpdateTextColor(); }
protected override void UpdateTextColor() { _textColorSwitcher = _textColorSwitcher ?? new TextColorSwitcher(EditText.TextColors, Element.UseLegacyColorManagement()); _textColorSwitcher.UpdateTextColor(EditText, Element.TextColor); }
protected override void UpdatePlaceholderColor() { _hintColorSwitcher = _hintColorSwitcher ?? new TextColorSwitcher(EditText.HintTextColors, Element.UseLegacyColorManagement()); _hintColorSwitcher.UpdateTextColor(EditText, Element.PlaceholderColor, EditText.SetHintTextColor); }