Inheritance: Android.Views.View, PageIndicator
        protected override void Dispose(bool disposing)
        {
            if (disposing && !_disposed)
            {
                if (prevBtn != null)
                {
                    prevBtn.Click -= PrevBtn_Click;
                    prevBtn.Dispose();
                    prevBtn = null;
                }

                if (nextBtn != null)
                {
                    nextBtn.Click -= NextBtn_Click;
                    nextBtn.Dispose();
                    nextBtn = null;
                }

                if (indicators != null)
                {
                    indicators.Dispose();
                    indicators = null;
                }

                if (viewPager != null)
                {
                    viewPager.PageSelected           -= ViewPager_PageSelected;
                    viewPager.PageScrollStateChanged -= ViewPager_PageScrollStateChanged;

                    if (viewPager.Adapter != null)
                    {
                        viewPager.Adapter.Dispose();
                    }

                    viewPager.Dispose();
                    viewPager = null;
                }

                if (Element != null)
                {
                    Element.SizeChanged -= Element_SizeChanged;
                    if (Element.ItemsSource != null && Element.ItemsSource is INotifyCollectionChanged)
                    {
                        ((INotifyCollectionChanged)Element.ItemsSource).CollectionChanged -= ItemsSource_CollectionChanged;
                    }
                }

                _disposed = true;
            }

            try
            {
                base.Dispose(disposing);
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
                return;
            }
        }
        void SetNativeView()
        {
            if (orientationChanged)
            {
                var inflater = AViews.LayoutInflater.From(_context);

                try
                {
                    // Orientation BP
                    if (Element.Orientation == CarouselViewOrientation.Horizontal)
                    {
                        var hz = Resource.Layout.horizontal_viewpager;
                        nativeView = inflater.Inflate(hz, null);
                    }
                    else
                    {
                        nativeView = inflater.Inflate(Resource.Layout.vertical_viewpager, null);
                    }
                }
                catch (Exception ex) {
                    Console.WriteLine(ex.Message);
                }
                viewPager = nativeView.FindViewById <ViewPager>(Resource.Id.pager);

                orientationChanged = false;
            }

            viewPager.Adapter = new PageAdapter(Element);
            viewPager.SetCurrentItem(Element.Position, false);

            // InterPageSpacing BP
            var metrics          = Resources.DisplayMetrics;
            var interPageSpacing = Element.InterPageSpacing * metrics.Density;

            viewPager.PageMargin = (int)interPageSpacing;

            // BackgroundColor BP
            viewPager.SetBackgroundColor(Element.BackgroundColor.ToAndroid());

            viewPager.PageSelected           += ViewPager_PageSelected;
            viewPager.PageScrollStateChanged += ViewPager_PageScrollStateChanged;
            viewPager.PageScrolled           += ViewPager_PageScrolled;

            // IsSwipeEnabled BP
            SetIsSwipeEnabled();

            // TapGestureRecognizer doesn't work when added to CarouselViewControl (Android) #66, #191, #200
            ((IViewPager)viewPager)?.SetElement(Element);

            SetNativeControl(nativeView);

            // ARROWS
            SetArrows();

            // INDICATORS
            indicators = nativeView.FindViewById <CirclePageIndicator>(Resource.Id.indicator);
            SetIndicators();
        }
        void SetNativeView()
        {
            var inflater = AViews.LayoutInflater.From(Forms.Context);

            // Orientation BP
            if (Element.Orientation == CarouselViewOrientation.Horizontal)
            {
                nativeView = inflater.Inflate(Resource.Layout.horizontal_viewpager, null);
            }
            else
            {
                nativeView = inflater.Inflate(Resource.Layout.vertical_viewpager, null);
            }

            viewPager = nativeView.FindViewById <ViewPager>(Resource.Id.pager);

            viewPager.Adapter = new PageAdapter(Element);
            viewPager.SetCurrentItem(Element.Position, false);

            // InterPageSpacing BP
            var metrics          = Resources.DisplayMetrics;
            var interPageSpacing = Element.InterPageSpacing * metrics.Density;

            viewPager.PageMargin = (int)interPageSpacing;

            // InterPageSpacingColor BP
            viewPager.SetBackgroundColor(Element.InterPageSpacingColor.ToAndroid());

            // IsSwipingEnabled BP
            SetIsSwipingEnabled();

            // INDICATORS
            indicators = nativeView.FindViewById <CirclePageIndicator>(Resource.Id.indicator);

            SetPosition();

            indicators.SetViewPager(viewPager);

            // IndicatorsTintColor BP
            indicators.SetFillColor(Element.IndicatorsTintColor.ToAndroid());

            // CurrentPageIndicatorTintColor BP
            indicators.SetPageColor(Element.CurrentPageIndicatorTintColor.ToAndroid());

            // IndicatorsShape BP
            indicators.SetStyle(Element.IndicatorsShape);             // Rounded or Squared

            // ShowIndicators BP
            indicators.Visibility = Element.ShowIndicators ? AViews.ViewStates.Visible : AViews.ViewStates.Gone;

            viewPager.PageSelected           += ViewPager_PageSelected;
            viewPager.PageScrollStateChanged += ViewPager_PageScrollStateChanged;

            SetNativeControl(nativeView);
        }
示例#4
0
        void SetNativeView()
        {
            CleanUpViewPager();

            var inflater = AViews.LayoutInflater.From(Forms.Context);

            // Orientation BP
            if (Element.Orientation == CarouselViewOrientation.Horizontal)
            {
                nativeView = inflater.Inflate(Resource.Layout.horizontal_viewpager, null);
            }
            else
            {
                nativeView = inflater.Inflate(Resource.Layout.vertical_viewpager, null);
            }

            viewPager = nativeView.FindViewById <ViewPager>(Resource.Id.pager);

            viewPager.Adapter = new PageAdapter(Element);
            viewPager.SetCurrentItem(Element.Position, false);

            // InterPageSpacing BP
            var metrics          = Resources.DisplayMetrics;
            var interPageSpacing = Element.InterPageSpacing * metrics.Density;

            viewPager.PageMargin = (int)interPageSpacing;

            // BackgroundColor BP
            viewPager.SetBackgroundColor(Element.BackgroundColor.ToAndroid());

            viewPager.PageSelected           += ViewPager_PageSelected;
            viewPager.PageScrollStateChanged += ViewPager_PageScrollStateChanged;

            // IsSwipingEnabled BP
            SetIsSwipingEnabled();

            SetNativeControl(nativeView);

            // INDICATORS
            indicators = nativeView.FindViewById <CirclePageIndicator>(Resource.Id.indicator);
            SetIndicators();
        }
示例#5
0
        void CleanUpViewPager()
        {
            if (indicators != null)
            {
                indicators.Dispose();
                indicators = null;
            }

            if (viewPager != null)
            {
                viewPager.PageSelected           -= ViewPager_PageSelected;
                viewPager.PageScrollStateChanged -= ViewPager_PageScrollStateChanged;

                if (viewPager.Adapter != null)
                {
                    viewPager.Adapter.Dispose();
                }
                viewPager.Dispose();
                viewPager = null;
            }
        }
        protected override void OnElementChanged(ElementChangedEventArgs <CarouselViewControl> e)
        {
            base.OnElementChanged(e);

            if (Control == null)
            {
                // Instantiate the native control and assign it to the Control property with
                // the SetNativeControl method

                var inflater = AViews.LayoutInflater.From(Forms.Context);

                if (Element.Orientation == Orientation.Horizontal)
                {
                    nativeView = inflater.Inflate(Resource.Layout.viewpager, null);
                }
                else
                {
                    nativeView = inflater.Inflate(Resource.Layout.vertical_viewpager, null);
                }

                var metrics          = Resources.DisplayMetrics;
                var interPageSpacing = Element.InterPageSpacing * metrics.Density;

                viewPager            = nativeView.FindViewById <ViewPager>(Resource.Id.pager);
                viewPager.PageMargin = (int)interPageSpacing;

                indicator = nativeView.FindViewById <CirclePageIndicator>(Resource.Id.indicator);
                indicator.SetViewPager(viewPager);

                indicator.SetPageColor(Element.PageIndicatorTintColor.ToAndroid());
                indicator.SetFillColor(Element.CurrentPageIndicatorTintColor.ToAndroid());

                indicator.Visibility = Element.ShowIndicators ? AViews.ViewStates.Visible : AViews.ViewStates.Gone;

                SetNativeControl(nativeView);
            }

            if (e.OldElement != null)
            {
                // Unsubscribe from event handlers and cleanup any resources

                if (viewPager != null)
                {
                    viewPager.PageSelected           -= ViewPager_PageSelected;
                    viewPager.PageScrollStateChanged -= ViewPager_PageScrollStateChanged;
                }

                if (Element != null)
                {
                    Element.RemoveAction     = null;
                    Element.InsertAction     = null;
                    Element.SetCurrentAction = null;
                }
            }

            if (e.NewElement != null)
            {
                // Configure the control and subscribe to event handlers

                viewPager.PageSelected           += ViewPager_PageSelected;
                viewPager.PageScrollStateChanged += ViewPager_PageScrollStateChanged;

                Element.RemoveAction     = new Action <int>(RemoveItem);
                Element.InsertAction     = new Action <object, int>(InsertItem);
                Element.SetCurrentAction = new Action <int>(SetCurrentItem);
            }
        }