示例#1
0
        public virtual void Initialize(ITabProvider provider)
        {
            Orientation       = StackOrientation.Vertical;
            HorizontalOptions = LayoutOptions.Center;
            VerticalOptions   = LayoutOptions.Center;
            WidthRequest      = 94;
            HeightRequest     = 44;
            Spacing           = 0;

            Children.Add(TextLabel = new Label
            {
                Text                    = provider?.Title,
                FontSize                = 16,
                HeightRequest           = 42,
                TextColor               = Color.Black,
                HorizontalTextAlignment = TextAlignment.Center,
                VerticalTextAlignment   = TextAlignment.Center,
                VerticalOptions         = LayoutOptions.Center
            });

            Children.Add(BottomView = new BoxView
            {
                HeightRequest     = 2,
                HorizontalOptions = LayoutOptions.Fill,
                VerticalOptions   = LayoutOptions.End
            });
        }
示例#2
0
 public void Initialize(ITabProvider provider)
 {
     BorderRadius    = Convert.ToInt32(DotSize / 2);
     HeightRequest   = DotSize;
     WidthRequest    = DotSize;
     BackgroundColor = DotColor;
     //Source = provider.ImageSource;
 }
        /// <summary>
        /// Overrides the base method to use <see cref="IconTabProviderCallback"/> if it is not null.
        ///
        /// If it is null, or if the callback returns null, then the default implementation will be
        /// used, which simply returns a new default instance of the <see cref="IconTabProvider"/>.
        /// </summary>
        /// <param name="context">The context.</param>
        /// <param name="adapter">The adapter.</param>
        /// <returns></returns>
        public override ITabProvider CreateIconTabProvider(Context context, PagerAdapter adapter)
        {
            ITabProvider toReturn = null;

            if (_iconTabProviderCallback != null)
            {
                toReturn = _iconTabProviderCallback(context, adapter);
            }
            return(toReturn ?? base.CreateIconTabProvider(context, adapter));
        }
        /// <summary>
        /// Creates a tab provider to be used for the given adapter.
        /// </summary>
        /// <param name="context">The context.</param>
        /// <param name="adapter">The adapter.</param>
        /// <returns>
        /// Must return an ITabProvider instance.
        /// </returns>
        public virtual ITabProvider CreateTabProvider(Context context, Android.Support.V4.View.PagerAdapter adapter)
        {
            ITabProvider tabProvider = adapter as ITabProvider;

            if (tabProvider != null)
            {
                return(tabProvider);
            }
            else
            {
                //if the adapter supports the IIconTabProvider interface, then create
                //an instance of the IconTabProvider, otherwise use the TextTabProvider.
                if (adapter is PagerSlidingTabStrip.IIconTabProvider)
                {
                    return(CreateIconTabProvider(context, adapter));
                }
                else
                {
                    return(CreateTextTabProvider(context, adapter));
                }
            }
        }
		/// <summary>
		/// Sets the view pager for this instance.
		/// </summary>
		/// <param name="pager">The pager.</param>
		/// <param name="tabProviderFactory">The factory to use to select the correct tab provider for the given
		/// pager, and equally as a factory for more complex tab providers to delegate to if they want to reuse
		/// .  This also then is set on the .</param>
		/// <exception cref="System.ArgumentException">ViewPager does not have adapter instance.;pager</exception>
		public void SetViewPager(ViewPager pager, TabProviderFactory tabProviderFactory = null)
		{
			if (pager == null)
				return;
			if (pager.Adapter == null)
			{
				throw new ArgumentException("ViewPager does not have adapter instance.", "pager");
			}

			//the property returns the default factory if set to null here.
			_tabProviderFactory = tabProviderFactory;

			//changes made here to be more tolerant of being set to the same pager or to a pager with
			//the same adapter, or to the same pager with a different adapter.
			if (_pager != pager)
			{
				if (_pager != null)
				{
					pager.PageScrolled -= pager_PageScrolled;
					pager.PageScrollStateChanged -= pager_PageScrollStateChanged;
					pager.PageSelected -= pager_PageSelected;
				}
				this._pager = pager;
				pager.PageScrolled += pager_PageScrolled;
				pager.PageScrollStateChanged += pager_PageScrollStateChanged;
				pager.PageSelected += pager_PageSelected;
			}

			if (_adapter != pager.Adapter)
			{
				if (_adapter != null && _observer != null)
				{
					_adapter.UnregisterDataSetObserver(_observer);
				}

				_adapter = pager.Adapter;
				_tabProviderFactory = tabProviderFactory;
				//re-create the Lazys for the default text and tab providers
				_textTabProvider = new Lazy<ITabProvider>(() => TabProviderFactory.CreateTextTabProvider(Context, _adapter));
				_iconTabProvider = new Lazy<ITabProvider>(() => TabProviderFactory.CreateIconTabProvider(Context, _adapter));
				//avoid recycling any previous views, because we've changed adapters.
				_tabsContainer.RemoveAllViews();

				var newProvider = TabProviderFactory.CreateTabProvider(Context, _adapter);
				if (newProvider != _tabProvider && _tabProvider != null)
				{
					//good housekeeping
					_tabProvider.TabUpdated -= _tabProvider_TabUpdated;
					_tabProvider.TabUpdateRequired -= _tabProvider_TabUpdateRequired;
				}

				_tabProvider = newProvider;
				_tabProvider.TabUpdated += _tabProvider_TabUpdated;
				_tabProvider.TabUpdateRequired += _tabProvider_TabUpdateRequired;

				if (_observer == null)
					_observer = new PagerAdapterDataSetObserver(this);

				_adapter.RegisterDataSetObserver(_observer);
			}


			NotifyDataSetChanged();
		}
        /// <summary>
        /// Sets the view pager for this instance, from this the control inherits the PagerAdapter and then
        /// derives the <see cref="ITabProvider"/> - unless you also pass a custom <see cref="TabProviderFactory"/>
        /// in the <paramref name="tabProviderFactory"/> .
        /// </summary>
        /// <param name="pager">The pager.</param>
        /// <param name="tabProviderFactory">The factory to use to select the correct tab provider for the given
        /// pager, and equally as a factory for more complex tab providers to delegate to if they want to reuse
        /// .  This also then is set on the .</param>
        /// <exception cref="System.ArgumentException">ViewPager does not have adapter instance.;pager</exception>
        public void SetViewPager(ViewPager pager, TabProviderFactory tabProviderFactory = null)
        {
            if (pager == null)
            {
                return;
            }
            if (pager.Adapter == null)
            {
                throw new ArgumentException("ViewPager does not have adapter instance.", "pager");
            }

            //the property returns the default factory if set to null here.
            _tabProviderFactory = tabProviderFactory;

            //changes made here to be more tolerant of being set to the same pager or to a pager with
            //the same adapter, or to the same pager with a different adapter.
            if (_pager != pager)
            {
                if (_pager != null)
                {
                    pager.PageScrolled           -= pager_PageScrolled;
                    pager.PageScrollStateChanged -= pager_PageScrollStateChanged;
                    pager.PageSelected           -= pager_PageSelected;
                }
                this._pager                   = pager;
                pager.PageScrolled           += pager_PageScrolled;
                pager.PageScrollStateChanged += pager_PageScrollStateChanged;
                pager.PageSelected           += pager_PageSelected;
            }

            if (_adapter != pager.Adapter)
            {
                if (_adapter != null && _observer != null)
                {
                    _adapter.UnregisterDataSetObserver(_observer);
                }

                _adapter            = pager.Adapter;
                _tabProviderFactory = tabProviderFactory;
                //re-create the Lazys for the default text and tab providers
                _textTabProvider = new Lazy <ITabProvider>(() => TabProviderFactory.CreateTextTabProvider(Context, _adapter));
                _iconTabProvider = new Lazy <ITabProvider>(() => TabProviderFactory.CreateIconTabProvider(Context, _adapter));
                //avoid recycling any previous views, because we've changed adapters.
                _tabsContainer.RemoveAllViews();

                var newProvider = TabProviderFactory.CreateTabProvider(Context, _adapter);
                if (newProvider != _tabProvider && _tabProvider != null)
                {
                    //good housekeeping
                    _tabProvider.TabUpdated        -= _tabProvider_TabUpdated;
                    _tabProvider.TabUpdateRequired -= _tabProvider_TabUpdateRequired;
                }

                _tabProvider                    = newProvider;
                _tabProvider.TabUpdated        += _tabProvider_TabUpdated;
                _tabProvider.TabUpdateRequired += _tabProvider_TabUpdateRequired;

                if (_observer == null)
                {
                    _observer = new PagerAdapterDataSetObserver(this);
                }

                _adapter.RegisterDataSetObserver(_observer);
            }


            NotifyDataSetChanged();
        }