コード例 #1
0
        public static void SetColorFilter(this ADrawable drawable, AColor color, FilterMode mode)
        {
            if (drawable == null)
            {
                return;
            }

            if (NativeVersion.Supports(NativeApis.BlendModeColorFilter))
            {
                BlendMode?filterMode29 = GetFilterMode(mode);

                if (filterMode29 != null)
                {
                    drawable.SetColorFilter(new BlendModeColorFilter(color, filterMode29));
                }
            }
            else
            {
#pragma warning disable CS0612 // Type or member is obsolete
                PorterDuff.Mode?filterModePre29 = GetFilterModePre29(mode);
#pragma warning restore CS0612 // Type or member is obsolete

                if (filterModePre29 != null)
#pragma warning disable CS0618 // Type or member is obsolete
                {
                    drawable.SetColorFilter(color, filterModePre29);
                }
#pragma warning restore CS0618 // Type or member is obsolete
            }
        }
コード例 #2
0
        public static void UpdateTextHtml(this TextView textView, ILabel label)
        {
            var newText = label.Text ?? string.Empty;

            if (NativeVersion.IsAtLeast(24))
            {
                textView.SetText(Html.FromHtml(newText, FromHtmlOptions.ModeCompact), BufferType.Spannable);
            }
            else
#pragma warning disable CS0618 // Type or member is obsolete
            {
                textView.SetText(Html.FromHtml(newText), BufferType.Spannable);
            }
#pragma warning restore CS0618 // Type or member is obsolete
        }
コード例 #3
0
ファイル: SwitchExtensions.cs プロジェクト: ultracpy/maui
        internal static UIView GetTrackSubview(this UISwitch uISwitch)
        {
            UIView uIView;

            if (NativeVersion.IsAtLeast(13))
            {
                uIView = uISwitch.Subviews[0].Subviews[0];
            }
            else
            {
                uIView = uISwitch.Subviews[0].Subviews[0].Subviews[0];
            }

            return(uIView);
        }
コード例 #4
0
        public MauiTimePicker(Action dateSelected)
        {
            BorderStyle = UITextBorderStyle.RoundedRect;

            _picker = new UIDatePicker {
                Mode = UIDatePickerMode.Time, TimeZone = new NSTimeZone("UTC")
            };
            _dateSelected = dateSelected;

            if (NativeVersion.IsAtLeast(14))
            {
                _picker.PreferredDatePickerStyle = UIDatePickerStyle.Wheels;
            }

            var width   = UIScreen.MainScreen.Bounds.Width;
            var toolbar = new UIToolbar(new RectangleF(0, 0, width, 44))
            {
                BarStyle = UIBarStyle.Default, Translucent = true
            };
            var spacer = new UIBarButtonItem(UIBarButtonSystemItem.FlexibleSpace);

            var doneButton = new UIBarButtonItem(UIBarButtonSystemItem.Done, (o, a) =>
            {
                _dateSelected?.Invoke();
            });

            toolbar.SetItems(new[] { spacer, doneButton }, false);

            InputView          = _picker;
            InputAccessoryView = toolbar;

            InputView.AutoresizingMask          = UIViewAutoresizing.FlexibleHeight;
            InputAccessoryView.AutoresizingMask = UIViewAutoresizing.FlexibleHeight;

            InputAssistantItem.LeadingBarButtonGroups  = null;
            InputAssistantItem.TrailingBarButtonGroups = null;

            AccessibilityTraits = UIAccessibilityTrait.Button;
        }
コード例 #5
0
ファイル: SwitchExtensions.cs プロジェクト: ultracpy/maui
        public static void UpdateTrackColor(this UISwitch uiSwitch, ISwitch view, UIColor?defaultOnTrackColor, UIColor?defaultOffTrackColor)
        {
            if (view == null)
            {
                return;
            }

            if (view.TrackColor == Maui.Color.Default)
            {
                uiSwitch.OnTintColor = defaultOnTrackColor;
            }
            else
            {
                uiSwitch.OnTintColor = view.TrackColor.ToNative();
            }

            UIView uIView;

            if (NativeVersion.IsAtLeast(13))
            {
                uIView = uiSwitch.Subviews[0].Subviews[0];
            }
            else
            {
                uIView = uiSwitch.Subviews[0].Subviews[0].Subviews[0];
            }

            if (view.TrackColor == Maui.Color.Default)
            {
                uIView.BackgroundColor = defaultOffTrackColor;
            }
            else
            {
                uIView.BackgroundColor = uiSwitch.OnTintColor;
            }
        }
コード例 #6
0
        public static UIImage?ConvertToImage(this UIView view)
        {
            if (!NativeVersion.IsAtLeast(10))
            {
                UIGraphics.BeginImageContext(view.Frame.Size);
                view.Layer.RenderInContext(UIGraphics.GetCurrentContext());
                var image = UIGraphics.GetImageFromCurrentImageContext();
                UIGraphics.EndImageContext();

                if (image.CGImage == null)
                {
                    return(null);
                }

                return(new UIImage(image.CGImage));
            }

            var imageRenderer = new UIGraphicsImageRenderer(view.Bounds.Size);

            return(imageRenderer.CreateImage((a) =>
            {
                view.Layer.RenderInContext(a.CGContext);
            }));
        }
コード例 #7
0
        public static void UpdateSemanticNodeInfo(this View nativeView, IView virtualView, AccessibilityNodeInfoCompat?info)
        {
            if (info == null)
            {
                return;
            }

            var semantics = virtualView?.Semantics;

            if (semantics == null)
            {
                return;
            }

            string?newText = null;
            string?newContentDescription = null;

            var desc = semantics.Description;

            if (!string.IsNullOrEmpty(desc))
            {
                // Edit Text fields won't read anything for the content description
                if (nativeView is EditText et)
                {
                    if (!string.IsNullOrEmpty(et.Text))
                    {
                        newText = $"{desc}, {et.Text}";
                    }
                    else
                    {
                        newText = $"{desc}";
                    }
                }
                else
                {
                    newContentDescription = desc;
                }
            }

            var hint = semantics.Hint;

            if (!string.IsNullOrEmpty(hint))
            {
                // info HintText won't read anything back when using TalkBack pre API 26
                if (NativeVersion.IsAtLeast(26))
                {
                    info.HintText = hint;

                    if (nativeView is EditText)
                    {
                        info.ShowingHintText = false;
                    }
                }
                else
                {
                    if (nativeView is EditText et)
                    {
                        newText = newText ?? et.Text;
                        newText = $"{newText}, {hint}";
                    }
                    else if (nativeView is TextView tv)
                    {
                        if (newContentDescription != null)
                        {
                            newText = $"{newContentDescription}, {hint}";
                        }
                        else if (!string.IsNullOrEmpty(tv.Text))
                        {
                            newText = $"{tv.Text}, {hint}";
                        }
                        else
                        {
                            newText = $"{hint}";
                        }
                    }
                    else
                    {
                        if (newContentDescription != null)
                        {
                            newText = $"{newContentDescription}, {hint}";
                        }
                        else
                        {
                            newText = $"{hint}";
                        }
                    }

                    newContentDescription = null;
                }
            }

            if (!string.IsNullOrWhiteSpace(newContentDescription))
            {
                info.ContentDescription = newContentDescription;
            }

            if (!string.IsNullOrWhiteSpace(newText))
            {
                info.Text = newText;
            }
        }