コード例 #1
0
        private View OnViewCreated(View view, string name, Context context, IAttributeSet attrs)
        {
            if (name == "fragment" || (view != null && _lastCreatedView.Target == view))
            {
                return(view);
            }
            ViewResult viewResult;

            if (view == null)
            {
                var type = TypeCache <View> .Instance.GetTypeByName(name, true, false);

                if (type == null)
                {
                    return(null);
                }
                viewResult = _viewFactory.Create(type, context, attrs);
                view       = viewResult.View;
            }
            else
            {
                var type = TypeCache <View> .Instance.GetTypeByName(name, true, false);

                if (type != null && !type.IsInstanceOfType(view))
                {
                    try
                    {
                        view = (View)JavaCastMethod.MakeGenericMethod(type).Invoke(null, new object[] { view });
                    }
                    catch
                    {
                        ;
                    }
                }
                viewResult = _viewFactory.Initialize(view, attrs);
            }

            var viewCreated = PlatformExtensions.ViewCreated;

            if (viewCreated != null)
            {
                view = viewCreated(view, name, context, attrs);
            }

            if (!viewResult.IsEmpty)
            {
                view = viewResult.View;
                var bind = viewResult.Bind;
                if (!string.IsNullOrEmpty(bind))
                {
                    var manualBindings = view as IManualBindings;
                    if (manualBindings == null)
                    {
                        BindingServiceProvider.BindingProvider.CreateBindingsFromString(view, bind);
                    }
                    else
                    {
                        manualBindings.SetBindings(bind);
                    }
                }
            }

            var viewGroup = view as ViewGroup;

            if (viewGroup != null && !viewGroup.GetBindingMemberValue(AttachedMembers.ViewGroup.DisableHierarchyListener))
            {
                viewGroup.SetOnHierarchyChangeListener(GlobalViewParentListener.Instance);
            }

            _lastCreatedView = ServiceProvider.WeakReferenceFactory(view);
            return(view);
        }
コード例 #2
0
        private View OnViewCreated(View view, string name, Context context, IAttributeSet attrs)
        {
            if (name == "fragment" || view != null && _lastCreatedView.Target == view)
            {
                return(view);
            }
            ViewResult viewResult;

            if (view == null)
            {
                var type = TypeCache <View> .Instance.GetTypeByName(name, true, false);

                if (type == null)
                {
                    return(null);
                }
                viewResult = _viewFactory.Create(type, context, attrs);
                view       = viewResult.View;
            }
            else
            {
                var type = TypeCache <View> .Instance.GetTypeByName(name, true, false);

                if (type != null && !type.IsInstanceOfType(view))
                {
                    try
                    {
                        view = (View)JavaCastMethod.MakeGenericMethod(type).Invoke(null, new object[] { view });
                    }
                    catch
                    {
                        ;
                    }
                }
                viewResult = _viewFactory.Initialize(view, attrs);
            }

            var viewCreated = AndroidToolkitExtensions.ViewCreated;

            if (viewCreated != null)
            {
                view = viewCreated(view, name, context, attrs);
            }

            string bind = null;

            if (!viewResult.IsEmpty)
            {
                view = viewResult.View;
                bind = viewResult.Bind;
                if (!string.IsNullOrEmpty(bind))
                {
                    if (AndroidToolkitExtensions.CurrentLayoutInflaterResult == null)
                    {
                        var manualBindings = view as IManualBindings;
                        if (manualBindings == null)
                        {
                            BindingServiceProvider.BindingProvider.CreateBindingsFromString(view, bind);
                        }
                        else
                        {
                            manualBindings.SetBindings(bind);
                        }
                    }
                }
            }

            if (AndroidToolkitExtensions.CurrentLayoutInflaterResult == null)
            {
                var viewGroup = view as ViewGroup;
                if (viewGroup != null && !viewGroup.IsDisableHierarchyListener())
                {
                    viewGroup.SetOnHierarchyChangeListener(GlobalViewParentListener.Instance);
                }
            }
            else
            {
                Action <object> postAction;
                if (view is ViewGroup)
                {
                    postAction = o =>
                    {
                        var vg = (ViewGroup)o;
                        if (!vg.IsDisableHierarchyListener())
                        {
                            vg.SetOnHierarchyChangeListener(GlobalViewParentListener.Instance);
                        }
                    };
                }
                else
                {
                    postAction = null;
                }
                AndroidToolkitExtensions.CurrentLayoutInflaterResult.AddBindingInfo(view, bind, postAction);
            }

            _lastCreatedView = ServiceProvider.WeakReferenceFactory(view);
            return(view);
        }
コード例 #3
0
        protected virtual View OnCreateViewInternal(string name, Context context, IAttributeSet attrs)
        {
            View view     = null;
            var  fullName = GetFullName(name);

            if (PlatformExtensions.IsApiGreaterThan10 && NestedFactory2 != null)
            {
                if (fullName != null)
                {
                    view = NestedFactory2.OnCreateView(fullName, context, attrs);
                }
                if (view == null)
                {
                    view = NestedFactory2.OnCreateView(name, context, attrs);
                }
            }
            else if (NestedFactory != null)
            {
                if (fullName != null)
                {
                    view = NestedFactory.OnCreateView(fullName, context, attrs);
                }
                if (view == null)
                {
                    view = NestedFactory.OnCreateView(name, context, attrs);
                }
            }
            if (_ignoreViewTypes.Contains(name))
            {
                return(view);
            }

            ViewResult viewResult;

            if (view == null)
            {
                viewResult = _viewFactory.Create(name, Context, attrs);
                view       = viewResult.View;
            }
            else
            {
                var type = TypeCache <View> .Instance.GetTypeByName(name, true, false);

                if (type != null)
                {
                    var clazz = Java.Lang.Class.FromType(type);
                    if (clazz.IsInstance(view) && !type.IsInstanceOfType(view))
                    {
                        view = (View)JavaCastMethod.MakeGenericMethod(type).InvokeEx(null, view);
                    }
                }
                viewResult = _viewFactory.Initialize(view, attrs);
            }
            IList <string> bindings = viewResult.DataContext.GetData(ViewFactoryConstants.Bindings);

            if (bindings != null)
            {
                var manualBindings = view as IManualBindings;
                if (manualBindings == null)
                {
                    foreach (string binding in bindings)
                    {
                        BindingServiceProvider
                        .BindingProvider
                        .CreateBindingsFromString(view, binding);
                    }
                }
                else
                {
                    manualBindings.SetBindings(bindings);
                }
            }
            Func <View, string, Context, IAttributeSet, View> viewCreated = PlatformExtensions.ViewCreated;

            if (viewCreated == null)
            {
                return(view);
            }
            return(viewCreated(view, name, Context, attrs));
        }