Beispiel #1
0
                // I don't want our code to dispose of this class I'd rather just let the natural
                // process manage the life cycle so we don't dispose of this too early
                void Invalidate(AView androidView)
                {
                    if (androidView.IsAlive())
                    {
                        try
                        {
                            androidView.ViewTreeObserver.RemoveOnGlobalLayoutListener(this);
                        }
                        catch
                        {
                            // just in case something along the call path here is disposed of
                        }
                    }

                    try
                    {
                        // If the androidView itself becomes disposed of the listener will survive the life of the view
                        // and it will get moved to the root views tree observer
                        if (this.IsAlive())
                        {
                            _mainActivity?.Window?.DecorView?.RootView?.ViewTreeObserver?.RemoveOnGlobalLayoutListener(this);
                        }
                    }
                    catch
                    {
                        // just in case something along the call path here is disposed of
                    }

                    _callback = null;
                    _view     = null;
                }
        internal static void SetAutomationId(AView control, Element element, string value = null)
        {
            if (!control.IsAlive() || element == null)
            {
                return;
            }

            SetAutomationId(control, element.AutomationId, value);
        }
Beispiel #3
0
 partial void DisconnectingHandler(NativeView nativeView)
 {
     if (nativeView.IsAlive() &&
         ViewCompat.GetAccessibilityDelegate(nativeView) is MauiAccessibilityDelegateCompat ad)
     {
         ad.Handler = null;
         ViewCompat.SetAccessibilityDelegate(nativeView, null);
     }
 }
Beispiel #4
0
        public static void SetClipToOutline(this AView view, bool value)
        {
            if (!view.IsAlive())
            {
                return;
            }

            view.ClipToOutline = value;
        }
Beispiel #5
0
        public static bool GetClipToOutline(this AView view)
        {
            if (!view.IsAlive())
            {
                return(false);
            }

            return(view.ClipToOutline);
        }
Beispiel #6
0
        public static bool SetElevation(this AView view, float value)
        {
            if (!view.IsAlive())
            {
                return(false);
            }

            view.Elevation = value;
            return(true);
        }
Beispiel #7
0
        public static void EnsureId(this AView view)
        {
            if (!view.IsAlive())
            {
                return;
            }

            if (view.Id == AView.NoId)
            {
                view.Id = global::Android.Views.View.GenerateViewId();
            }
        }
        internal static void SetAutomationId(AView control, string automationId, string value = null)
        {
            if (!control.IsAlive())
            {
                return;
            }

            automationId = value ?? automationId;
            if (!string.IsNullOrEmpty(automationId))
            {
                control.ContentDescription = automationId;
            }
        }
Beispiel #9
0
        partial void DisconnectingHandler(PlatformView platformView)
        {
            if (platformView.IsAlive())
            {
                platformView.FocusChange -= OnPlatformViewFocusChange;

                if (ViewCompat.GetAccessibilityDelegate(platformView) is MauiAccessibilityDelegateCompat ad)
                {
                    ad.Handler = null;
                    ViewCompat.SetAccessibilityDelegate(platformView, null);
                }
            }
        }
Beispiel #10
0
                public void OnGlobalLayout()
                {
                    if (_view == null || _callback == null)
                    {
                        return;
                    }

                    Action invokeMe = null;
                    AView  view     = null;

                    if (!_view.TryGetTarget(out view) || !view.IsAlive())
                    {
                        Invalidate(view);
                    }
                    else if (_callback.TryGetTarget(out invokeMe))
                    {
                        invokeMe();
                    }
                    else
                    {
                        Invalidate(view);
                    }
                }
 private static object GetParent(View view)
 {
     if (!view.IsAlive())
         return null;
     if (view.Id == global::Android.Resource.Id.Content)
         return view.Context.GetActivity();
     object parent = view.Parent;
     if (parent != null)
         return parent;
     var activity = view.Context.GetActivity();
     if (!activity.IsAlive())
         return null;
     var w = activity.Window;
     if (!w.IsAlive())
         return null;
     var d = w.DecorView;
     if (d.IsAlive() && ReferenceEquals(view, d.RootView))
         return activity;
     return null;
 }
Beispiel #12
0
 private static void TrySetActivated(View view, bool value)
 {
     if (PlatformExtensions.IsApiGreaterThan10 && view.IsAlive())
         view.Activated = value;
 }