Ejemplo n.º 1
0
        public override void AddView(Android.Views.View child)
        {
            child.GetType().GetRuntimeProperty("TopPadding").SetValue(child, 0);
            var padding = child.GetType().GetRuntimeProperty("TopPadding").GetValue(child);

            base.AddView(child);
        }
Ejemplo n.º 2
0
        protected override void OnElementChanged(ElementChangedEventArgs <TabbedPage> e)
        {
            base.OnElementChanged(e);

            if (e.NewElement == null || e.OldElement != null)
            {
                return;
            }

            TabLayout tablayout = (TabLayout)ViewGroup.GetChildAt(1);

            Android.Views.ViewGroup vgroup = (Android.Views.ViewGroup)tablayout.GetChildAt(0);
            for (int i = 0; i < vgroup.ChildCount; i++)
            {
                Android.Views.ViewGroup vvgroup = (Android.Views.ViewGroup)vgroup.GetChildAt(i);
                Typeface fontFace = Typeface.CreateFromAsset(this.Context.Assets, "IranSans.ttf");
                for (int j = 0; j < vvgroup.ChildCount; j++)
                {
                    Android.Views.View vView = (Android.Views.View)vvgroup.GetChildAt(j);
                    if (vView.GetType() == typeof(Android.Support.V7.Widget.AppCompatTextView) || vView.GetType() == typeof(Android.Widget.TextView))
                    {
                        //here change textview style
                        TextView txtView = (TextView)vView;
                        txtView.TextSize = 14f;
                        txtView.SetTypeface(fontFace, TypefaceStyle.Normal);
                    }
                }
            }
        }
Ejemplo n.º 3
0
        public override void OnViewAdded(Android.Views.View child)
        {
            base.OnViewAdded(child);

            if (child.GetType() == typeof(Support.Toolbar))
                _toolbar = (Support.Toolbar)child;
        }
 public override void OnViewAdded(Android.Views.View child)
 {
     base.OnViewAdded(child);
     if (child.GetType() == typeof(Android.Support.V7.Widget.Toolbar))
     {
         toolbar = (Android.Support.V7.Widget.Toolbar)child;
         toolbar.ChildViewAdded += Toolbar_ChildViewAdded;
     }
 }
        public override void OnViewAdded(Android.Views.View child)
        {
            base.OnViewAdded(child);

            if (child.GetType() == typeof(Toolbar))
            {
                _toolbar = (Toolbar)child;
                _toolbar.ChildViewAdded += Toolbar_ChildViewAdded;
            }
        }
Ejemplo n.º 6
0
 private static DependencyProperty GetVisibilityProperty(View view)
 {
     if (view is FrameworkElement)
     {
         return(VisibilityProperty);
     }
     else
     {
         return(DependencyProperty.GetProperty(view.GetType(), nameof(Visibility)));
     }
 }
Ejemplo n.º 7
0
        public override void OnViewAdded(Android.Views.View child)
        {
            base.OnViewAdded(child);
            if (child.GetType() == typeof(Android.Support.V7.Widget.Toolbar))
            {
                toolbar = (Android.Support.V7.Widget.Toolbar)child;
                toolbar.ChildViewAdded += Toolbar_ChildViewAdded;

                toolbar.SetNavigationIcon(Resource.Drawable.devnl);
            }
        }
        /// <summary>
        /// When adding a view, tweak the top padding if necessary.
        /// According to:
        /// https://github.com/xamarin/Xamarin.Forms/blob/589adbd3ef145ec85f9fe64eda008251c1cdb745/Xamarin.Forms.Platform.Android/AppCompat/MasterDetailPageRenderer.cs
        /// The TopPadding is always set for the detail. This works fine when the master detail is shown normally, but
        /// if it is inside a navigation page (such as the inspection view) then you get extra unwanted padding.
        /// The 'fix' is to set the top padding to 0 for the detail, only of course the types and fields are hidden from us...
        /// </summary>
        /// <param name="child">Child.</param>
        public override void AddView(Android.Views.View child)
        {
            try
            {
                var isMasterField = child.GetType().GetField("_isMaster", BindingFlags.NonPublic | BindingFlags.Instance);
                if (isMasterField == null)
                {
                    return;
                }

                var isMaster = isMasterField.GetValue(child);
                if ((bool)isMaster)
                {
                    return;
                }

                var parentField = child.GetType().GetField("_parent", BindingFlags.NonPublic | BindingFlags.Instance);
                if (parentField == null)
                {
                    return;
                }

                var parent = parentField.GetValue(child) as MasterDetailPage;
                if (parent == null || !(parent.Parent is NavigationPage))
                {
                    return;
                }

                var topPaddingProperty = child.GetType().GetProperty("TopPadding", BindingFlags.Public | BindingFlags.Instance);
                if (topPaddingProperty != null)
                {
                    topPaddingProperty.SetValue(child, 0);
                }
            }
            finally
            {
                base.AddView(child);
            }
        }
        public override void OnViewAdded(Android.Views.View child)
        {
            base.OnViewAdded(child);
            if (child.GetType() == typeof(Support.Toolbar))
            {
                toolbar = (Support.Toolbar)child;
            }
            titleText = (TextView)toolbar.FindViewById(Resource.Id.toolbar_title);
            Typeface tf = Typeface.CreateFromAsset(Context.Assets, "HelveticaNeueMed.ttf");

            titleText.SetTypeface(tf, TypefaceStyle.Normal);
            if (this.Title != null)
            {
                SetCustomView(this.Title);
            }
        }
        public override void OnViewAdded(Android.Views.View child)
        {
            base.OnViewAdded(child);

            try
            {
                if (child.GetType() == typeof(Support.Toolbar))
                {
                    _toolbar = (Support.Toolbar)child;
                }
            }
            catch (Exception e)
            {
                new Exception(e.Message);
            }
        }
        public override void OnViewAdded(Android.Views.View child)
        {
            base.OnViewAdded(child);

            if (child.GetType() == typeof(Android.Support.V7.Widget.Toolbar))
            {
                _toolbar = (Android.Support.V7.Widget.Toolbar)child;
                MyNavigationPageRenderer myNavigationPageRenderer = (MyNavigationPageRenderer)Element;
                GradientDrawable         gradientDrawable         = new GradientDrawable(
                    GradientDrawable.Orientation.LeftRight,
                    new int[] { myNavigationPageRenderer.StartColor.ToAndroid(),
                                myNavigationPageRenderer.EndColor.ToAndroid() });
                _toolbar.SetBackgroundDrawable(gradientDrawable);
                _toolbar.Elevation = 0;
            }
        }
        public override void OnViewAdded(Android.Views.View child)
        {
            base.OnViewAdded(child);

            if (child.GetType() == typeof(Support.Toolbar))
            {
                toolbar = (Support.Toolbar)child;
            }

            for (int i = 0; i < toolbar.ChildCount; i++)
            {
                var item = toolbar.GetChildAt(i);

                if (item.GetType() == typeof(ImageButton))
                {
                    ImageButton ib = item as ImageButton;
                    ib.SetImageResource(Resource.Drawable.hollowstar);
                }
            }
        }
Ejemplo n.º 13
0
        private void LogArrange(View view, Rect frame)
        {
            if (this.Log().IsEnabled(Microsoft.Extensions.Logging.LogLevel.Debug))
            {
                var viewName = (view as IFrameworkElement).SelectOrDefault(f => f.Name, "NativeView");
                var margin   = (view as IFrameworkElement).SelectOrDefault(f => f.Margin, Thickness.Empty);

                this.Log().DebugFormat("[{0}/{1}] ArrangeChild({2}/{3}/{4}/{5})", LoggingOwnerTypeName, Name, view.GetType(), viewName, frame, margin);
            }
        }
Ejemplo n.º 14
0
        protected Size MeasureChild(View view, Size slotSize)
        {
            var frameworkElement = view as IFrameworkElement;
            var ret = default(Size);

            if (frameworkElement != null)
            {
                var margin = frameworkElement.Margin;

                if (frameworkElement.Visibility == Visibility.Collapsed)
                {
                    // By default iOS views measure to normal size, even if they're hidden.
                    // We want the collapsed behavior, so we return a 0,0 size instead.
                    SetDesiredChildSize(view, ret);

                    if (this.Log().IsEnabled(Microsoft.Extensions.Logging.LogLevel.Debug))
                    {
                        var viewName = frameworkElement.SelectOrDefault(f => f.Name, "NativeView");

                        this.Log().DebugFormat(
                            "[{0}/{1}] MeasureChild(HIDDEN/{2}/{3}/{4}/{5}) = {6}",
                            LoggingOwnerTypeName,
                            Name,
                            view.GetType(),
                            viewName,
                            slotSize,
                            margin,
                            ret
                            );
                    }

                    return(ret);
                }

                if (margin != Thickness.Empty)
                {
                    // Apply the margin for framework elements, as if it were padding to the child.
                    slotSize = new Size(
                        Max(0, slotSize.Width - margin.Left - margin.Right),
                        Max(0, slotSize.Height - margin.Top - margin.Bottom)
                        );
                }

                // Alias the Dependency Properties values to avoid double calls.
                var childWidth     = frameworkElement.Width;
                var childMaxWidth  = frameworkElement.MaxWidth;
                var childHeight    = frameworkElement.Height;
                var childMaxHeight = frameworkElement.MaxHeight;

                var optionalMaxWidth  = !IsInfinity(childMaxWidth) && !IsNaN(childMaxWidth) ? childMaxWidth : (double?)null;
                var optionalWidth     = !IsNaN(childWidth) ? childWidth : (double?)null;
                var optionalMaxHeight = !IsInfinity(childMaxHeight) && !IsNaN(childMaxHeight) ? childMaxHeight : (double?)null;
                var optionalHeight    = !IsNaN(childHeight) ? childHeight : (double?)null;

                // After the margin has been removed, ensure the remaining space slot does not go
                // over the explicit or maximum size of the child.
                if (optionalMaxWidth != null || optionalWidth != null)
                {
                    var constrainedWidth = Min(
                        optionalMaxWidth ?? double.PositiveInfinity,
                        optionalWidth ?? double.PositiveInfinity
                        );

                    slotSize.Width = Min(slotSize.Width, constrainedWidth);
                }

                if (optionalMaxHeight != null || optionalHeight != null)
                {
                    var constrainedHeight = Min(
                        optionalMaxHeight ?? double.PositiveInfinity,
                        optionalHeight ?? double.PositiveInfinity
                        );

                    slotSize.Height = Min(slotSize.Height, constrainedHeight);
                }
            }

            ret = MeasureChildOverride(view, slotSize);

            if (
                IsPositiveInfinity(ret.Height) || IsPositiveInfinity(ret.Width)
                )
            {
                if (this.Log().IsEnabled(Microsoft.Extensions.Logging.LogLevel.Error))
                {
                    var viewName = frameworkElement.SelectOrDefault(f => f.Name, "NativeView");
                    var margin   = frameworkElement.SelectOrDefault(f => f.Margin, Thickness.Empty);

                    this.Log().ErrorFormat(
                        "[{0}/{1}] MeasureChild({2}/{3}/{4}/{5}) = Child returned INFINITY {6}",
                        LoggingOwnerTypeName,
                        Name,
                        view.GetType(),
                        viewName,
                        slotSize,
                        margin,
                        ret
                        );
                }

                ret = new Size(0, 0);
            }
            else
            {
                if (this.Log().IsEnabled(Microsoft.Extensions.Logging.LogLevel.Debug))
                {
                    var viewName = frameworkElement.SelectOrDefault(f => f.Name, "NativeView");
                    var margin   = frameworkElement.SelectOrDefault(f => f.Margin, Thickness.Empty);

                    this.Log().DebugFormat(
                        "[{0}/{1}] MeasureChild({2}/{3}/{4}/{5}) = {6}",
                        LoggingOwnerTypeName,
                        Name,
                        view.GetType(),
                        viewName,
                        slotSize,
                        margin,
                        ret
                        );
                }
            }

            if (frameworkElement != null)
            {
                var margin = frameworkElement.Margin;

                if (margin != Thickness.Empty)
                {
                    // Report the size to the parent without the margin, only if the
                    // size has changed or that the control required a measure
                    //
                    // This condition is required because of the measure caching that
                    // some systems apply (Like android UI).
                    ret = new Size(
                        ret.Width + margin.Left + margin.Right,
                        ret.Height + margin.Top + margin.Bottom
                        );
                }
            }

            SetDesiredChildSize(view, ret);

            return(ret);
        }