diff options
author | E.Z. Hart <hartez@users.noreply.github.com> | 2016-04-19 01:01:58 -0600 |
---|---|---|
committer | Jason Smith <jason.smith@xamarin.com> | 2016-04-19 00:01:58 -0700 |
commit | a98f3fb2aae3c5b6a3fa5140e51f51ec67843a49 (patch) | |
tree | 654fa47cbd3cc889061466939630dcd5133cc837 /Xamarin.Forms.Platform.Android/AppCompat | |
parent | 89a50d4bc1f4aaf83d5f92a28c2a7a96282cc0d3 (diff) | |
download | xamarin-forms-a98f3fb2aae3c5b6a3fa5140e51f51ec67843a49.tar.gz xamarin-forms-a98f3fb2aae3c5b6a3fa5140e51f51ec67843a49.tar.bz2 xamarin-forms-a98f3fb2aae3c5b6a3fa5140e51f51ec67843a49.zip |
Add TextColor Property to Picker, TimePicker, DatePicker (#84)
* Add TextColor property to TimePicker
Add TextColor page to TimePicker gallery
Add TimePicker color toggling to color toggle test page
Split color toggle tests up among tabs
* Implement TimePicker.TextColor in iOS
* Implement TimePicker.TextColor for WinRT tablet
* Add IsEnabled=false tests to DefaultColorToggleTest Button and TimePicker
Consolidate ColorStates array
Fix IsEnabled changing color bug on iOS
* Implement TimePicker.TextColor for WP8
* Add TextColor property to DatePicker
Add DatePicker section to DefaultColorToggleTest
Impement DatePicker.TextColor for WP8
* Implement DatePicker.TextColor for WinRT/UWP/Windows Phone 8.1
* Implement DatePicker.TextColor for iOS
* Add TextColor to DatePicker Gallery Page
* Implement DatePicker.TextColor for Android
* Add Picker Gallery page for TextColor
Implement Picker.TextColor on Android
Consolidate TextColor management for Button, Picker, DatePicker, TimePicker
Implement
* Add untracked TextColorSwitcher
Implement Picker.TextColor in iOS
* Implement Picker.TextColor in WinRT/UWP/Windows Phone 8.1
Remove Pioker Loaded handlers in Dispose
* Implement Picker.TextColor in WP8
* Removed unused field
Update ignored warnings
* Update docs
* Use nameof() for BindableProperties
* Cleanup
* Fix custom renderer crashes for classes using TextColorSwitcher
* Correct property name references
* Fix typo and 'if' formatting
* Add missing else
Diffstat (limited to 'Xamarin.Forms.Platform.Android/AppCompat')
-rw-r--r-- | Xamarin.Forms.Platform.Android/AppCompat/ButtonRenderer.cs | 33 | ||||
-rw-r--r-- | Xamarin.Forms.Platform.Android/AppCompat/PickerRenderer.cs | 11 |
2 files changed, 20 insertions, 24 deletions
diff --git a/Xamarin.Forms.Platform.Android/AppCompat/ButtonRenderer.cs b/Xamarin.Forms.Platform.Android/AppCompat/ButtonRenderer.cs index 3260dbf1..8f4ef35e 100644 --- a/Xamarin.Forms.Platform.Android/AppCompat/ButtonRenderer.cs +++ b/Xamarin.Forms.Platform.Android/AppCompat/ButtonRenderer.cs @@ -14,10 +14,7 @@ namespace Xamarin.Forms.Platform.Android.AppCompat { public class ButtonRenderer : ViewRenderer<Button, AppCompatButton>, global::Android.Views.View.IOnAttachStateChangeListener { - static readonly int[][] States = { new[] { GlobalResource.Attribute.StateEnabled }, new[] { -GlobalResource.Attribute.StateEnabled } }; - - ColorStateList _buttonDefaulTextColors; - Color _currentTextColor; + TextColorSwitcher _textColorSwitcher; float _defaultFontSize; Typeface _defaultTypeface; bool _isDisposed; @@ -79,7 +76,7 @@ namespace Xamarin.Forms.Platform.Android.AppCompat button.SetOnClickListener(ButtonClickListener.Instance.Value); button.Tag = this; - _buttonDefaulTextColors = button.TextColors; + _textColorSwitcher = new TextColorSwitcher(button.TextColors); SetNativeControl(button); button.AddOnAttachStateChangeListener(this); @@ -128,14 +125,16 @@ namespace Xamarin.Forms.Platform.Android.AppCompat { Resources.Theme theme = context.Theme; if (theme != null && theme.ResolveAttribute(id, value, true)) - Control.SupportBackgroundTintList = ContextCompat.GetColorStateList(context, value.Data); +#pragma warning disable 618 + Control.SupportBackgroundTintList = Resources.GetColorStateList(value.Data); +#pragma warning restore 618 else - Control.SupportBackgroundTintList = new ColorStateList(States, new[] { (int)0xffd7d6d6, 0x7fd7d6d6 }); + Control.SupportBackgroundTintList = new ColorStateList(ColorExtensions.States, new[] { (int)0xffd7d6d6, 0x7fd7d6d6 }); } catch (Exception ex) { Log.Warning("Xamarin.Forms.Platform.Android.ButtonRenderer", "Could not retrieve button background resource: {0}", ex); - Control.SupportBackgroundTintList = new ColorStateList(States, new[] { (int)0xffd7d6d6, 0x7fd7d6d6 }); + Control.SupportBackgroundTintList = new ColorStateList(ColorExtensions.States, new[] { (int)0xffd7d6d6, 0x7fd7d6d6 }); } } } @@ -145,7 +144,7 @@ namespace Xamarin.Forms.Platform.Android.AppCompat { int intColor = backgroundColor.ToAndroid().ToArgb(); int disableColor = backgroundColor.MultiplyAlpha(0.5).ToAndroid().ToArgb(); - Control.SupportBackgroundTintList = new ColorStateList(States, new[] { intColor, disableColor }); + Control.SupportBackgroundTintList = new ColorStateList(ColorExtensions.States, new[] { intColor, disableColor }); } } @@ -245,21 +244,7 @@ namespace Xamarin.Forms.Platform.Android.AppCompat void UpdateTextColor() { - Color color = Element.TextColor; - if (color == _currentTextColor) - return; - - _currentTextColor = color; - - if (color.IsDefault) - NativeButton.SetTextColor(_buttonDefaulTextColors); - else - { - // Set the new enabled state color, preserving the default disabled state color - int defaultDisabledColor = _buttonDefaulTextColors.GetColorForState(States[1], color.ToAndroid()); - - NativeButton.SetTextColor(new ColorStateList(States, new[] { color.ToAndroid().ToArgb(), defaultDisabledColor })); - } + _textColorSwitcher?.UpdateTextColor(Control, Element.TextColor); } class ButtonClickListener : Object, IOnClickListener diff --git a/Xamarin.Forms.Platform.Android/AppCompat/PickerRenderer.cs b/Xamarin.Forms.Platform.Android/AppCompat/PickerRenderer.cs index dd7fb85c..492b553b 100644 --- a/Xamarin.Forms.Platform.Android/AppCompat/PickerRenderer.cs +++ b/Xamarin.Forms.Platform.Android/AppCompat/PickerRenderer.cs @@ -2,6 +2,7 @@ using System; using System.ComponentModel; using System.Linq; using Android.App; +using Android.Content.Res; using Android.Text; using Android.Widget; using Object = Java.Lang.Object; @@ -12,6 +13,7 @@ namespace Xamarin.Forms.Platform.Android.AppCompat { AlertDialog _dialog; bool _disposed; + TextColorSwitcher _textColorSwitcher; public PickerRenderer() { @@ -51,9 +53,11 @@ namespace Xamarin.Forms.Platform.Android.AppCompat textField.Tag = this; textField.InputType = InputTypes.Null; textField.SetOnClickListener(PickerListener.Instance); + _textColorSwitcher = new TextColorSwitcher(textField.TextColors); SetNativeControl(textField); } UpdatePicker(); + UpdateTextColor(); } base.OnElementChanged(e); @@ -67,6 +71,8 @@ namespace Xamarin.Forms.Platform.Android.AppCompat UpdatePicker(); if (e.PropertyName == Picker.SelectedIndexProperty.PropertyName) UpdatePicker(); + if (e.PropertyName == Picker.TextColorProperty.PropertyName) + UpdateTextColor(); } internal override void OnFocusChangeRequested(object sender, VisualElement.FocusRequestArgs e) @@ -123,6 +129,11 @@ namespace Xamarin.Forms.Platform.Android.AppCompat Control.Text = Element.Items[Element.SelectedIndex]; } + void UpdateTextColor() + { + _textColorSwitcher?.UpdateTextColor(Control, Element.TextColor); + } + class PickerListener : Object, IOnClickListener { #region Statics |