public MaterialViewPagerAnimator(MaterialViewPager materialViewPager)
        {
            Settings = materialViewPager.Settings;

            MaterialViewPager = materialViewPager;
            _mHeader          = materialViewPager.MaterialViewPagerHeader;
            Context context = _mHeader.Context;

            // initialise the scrollMax to headerHeight, so until the first cell touch the top of the screen
            ScrollMax = Settings.HeaderHeight;
            //save in into dp once
            ScrollMaxDp = Utils.DpToPx(ScrollMax, context);

            //heightMaxScrollToolbar = context.getResources().getDimension(R.dimen.material_viewpager_padding_top);
            Elevation = Utils.DpToPx(4, context);
        }
		public MaterialViewPagerAnimator(MaterialViewPager materialViewPager)
		{
			Settings = materialViewPager.Settings;

			MaterialViewPager = materialViewPager;
			_mHeader = materialViewPager.MaterialViewPagerHeader;
			Context context = _mHeader.Context;

			// initialise the scrollMax to headerHeight, so until the first cell touch the top of the screen
			ScrollMax = Settings.HeaderHeight;
			//save in into dp once
			ScrollMaxDp = Utils.DpToPx(ScrollMax, context);

			//heightMaxScrollToolbar = context.getResources().getDimension(R.dimen.material_viewpager_padding_top);
			Elevation = Utils.DpToPx(4, context);
		}
		protected override void OnFinishInflate()
		{
			base.OnFinishInflate();

			//add @layout/material_view_pager_layout as child, containing all the MaterialViewPager views
			AddView(LayoutInflater.From(Context).Inflate(Resource.Layout.material_view_pager_layout, this, false));

			_headerBackgroundContainer = FindViewById<ViewGroup>(Resource.Id.headerBackgroundContainer);
			_pagerTitleStripContainer = FindViewById<ViewGroup>(Resource.Id.pagerTitleStripContainer);
			_logoContainer = FindViewById<ViewGroup>(Resource.Id.logoContainer);

			MToolbar = FindViewById<Toolbar>(Resource.Id.toolbar);
			if (Settings.DisableToolbar)
				MToolbar.Visibility = ViewStates.Invisible;
			MViewPager = FindViewById<ViewPager>(Resource.Id.viewPager);

			MViewPager.AddOnPageChangeListener(this);

			//inflate subviews defined in attributes

			{
				int headerId = Settings.HeaderLayoutId;
				if (headerId == -1)
				{
					headerId = Settings.AnimatedHeaderImage ? Resource.Layout.material_view_pager_moving_header : Resource.Layout.material_view_pager_imageview_header;
				}
				_headerBackgroundContainer.AddView(LayoutInflater.From(Context).Inflate(headerId, _headerBackgroundContainer, false));
			}

			if (IsInEditMode)
			{ //preview titlestrip
				//add fake tabs on edit mode
				Settings.PagerTitleStripId = Resource.Layout.tools_material_view_pager_pagertitlestrip;
			}
			if (Settings.PagerTitleStripId != -1)
			{
				_pagerTitleStripContainer.AddView(LayoutInflater.From(Context).Inflate(Settings.PagerTitleStripId, _pagerTitleStripContainer, false));
			}

			if (Settings.LogoLayoutId != -1)
			{
				_logoContainer.AddView(LayoutInflater.From(Context).Inflate(Settings.LogoLayoutId, _logoContainer, false));
				if (Settings.LogoMarginTop != 0)
				{
					RelativeLayout.LayoutParams layoutParams = (RelativeLayout.LayoutParams)_logoContainer.LayoutParameters;
					layoutParams.SetMargins(0, Settings.LogoMarginTop, 0, 0);
					_logoContainer.LayoutParameters = layoutParams;
				}
			}

			HeaderBackground = FindViewById(Resource.Id.headerBackground);
			ToolbarLayoutBackground = FindViewById(Resource.Id.toolbar_layout_background);

			InitialiseHeights();

			//construct the materialViewPagerHeader with subviews
			if (!IsInEditMode)
			{
				MaterialViewPagerHeader = MaterialViewPagerHeader
						.WithToolbar(MToolbar)
						.WithToolbarLayoutBackground(ToolbarLayoutBackground)
						.WithPagerSlidingTabStrip(_pagerTitleStripContainer)
						.WithHeaderBackground(HeaderBackground)
						.WithStatusBackground(FindViewById(Resource.Id.statusBackground))
						.WithLogo(_logoContainer);

				//and construct the MaterialViewPagerAnimator
				//attach it to the activity to enable MaterialViewPagerHeaderView.setMaterialHeight();
				MaterialViewPagerHelper.Register(Context, new MaterialViewPagerAnimator(this));
			}
			else
			{

				//if in edit mode, add fake cardsviews
				View sample = LayoutInflater.From(Context).Inflate(Resource.Layout.tools_list_items, _pagerTitleStripContainer, false);

				LayoutParams param = (LayoutParams)sample.LayoutParameters;
				int marginTop = (int)Math.Round(Utils.DpToPx(Settings.HeaderHeight + 10, Context));
				param.SetMargins(0, marginTop, 0, 0);
				LayoutParameters = param;

				AddView(sample);
			}
		}
Esempio n. 4
0
        protected override void OnFinishInflate()
        {
            base.OnFinishInflate();

            //add @layout/material_view_pager_layout as child, containing all the MaterialViewPager views
            AddView(LayoutInflater.From(Context).Inflate(Resource.Layout.material_view_pager_layout, this, false));

            _headerBackgroundContainer = FindViewById <ViewGroup>(Resource.Id.headerBackgroundContainer);
            _pagerTitleStripContainer  = FindViewById <ViewGroup>(Resource.Id.pagerTitleStripContainer);
            _logoContainer             = FindViewById <ViewGroup>(Resource.Id.logoContainer);

            MToolbar = FindViewById <Toolbar>(Resource.Id.toolbar);
            if (Settings.DisableToolbar)
            {
                MToolbar.Visibility = ViewStates.Invisible;
            }
            MViewPager = FindViewById <ViewPager>(Resource.Id.viewPager);

            MViewPager.AddOnPageChangeListener(this);

            //inflate subviews defined in attributes

            {
                int headerId = Settings.HeaderLayoutId;
                if (headerId == -1)
                {
                    headerId = Settings.AnimatedHeaderImage ? Resource.Layout.material_view_pager_moving_header : Resource.Layout.material_view_pager_imageview_header;
                }
                _headerBackgroundContainer.AddView(LayoutInflater.From(Context).Inflate(headerId, _headerBackgroundContainer, false));
            }

            if (IsInEditMode)
            {             //preview titlestrip
                //add fake tabs on edit mode
                Settings.PagerTitleStripId = Resource.Layout.tools_material_view_pager_pagertitlestrip;
            }
            if (Settings.PagerTitleStripId != -1)
            {
                _pagerTitleStripContainer.AddView(LayoutInflater.From(Context).Inflate(Settings.PagerTitleStripId, _pagerTitleStripContainer, false));
            }

            if (Settings.LogoLayoutId != -1)
            {
                _logoContainer.AddView(LayoutInflater.From(Context).Inflate(Settings.LogoLayoutId, _logoContainer, false));
                if (Settings.LogoMarginTop != 0)
                {
                    RelativeLayout.LayoutParams layoutParams = (RelativeLayout.LayoutParams)_logoContainer.LayoutParameters;
                    layoutParams.SetMargins(0, Settings.LogoMarginTop, 0, 0);
                    _logoContainer.LayoutParameters = layoutParams;
                }
            }

            HeaderBackground        = FindViewById(Resource.Id.headerBackground);
            ToolbarLayoutBackground = FindViewById(Resource.Id.toolbar_layout_background);

            InitialiseHeights();

            //construct the materialViewPagerHeader with subviews
            if (!IsInEditMode)
            {
                MaterialViewPagerHeader = MaterialViewPagerHeader
                                          .WithToolbar(MToolbar)
                                          .WithToolbarLayoutBackground(ToolbarLayoutBackground)
                                          .WithPagerSlidingTabStrip(_pagerTitleStripContainer)
                                          .WithHeaderBackground(HeaderBackground)
                                          .WithStatusBackground(FindViewById(Resource.Id.statusBackground))
                                          .WithLogo(_logoContainer);

                //and construct the MaterialViewPagerAnimator
                //attach it to the activity to enable MaterialViewPagerHeaderView.setMaterialHeight();
                MaterialViewPagerHelper.Register(Context, new MaterialViewPagerAnimator(this));
            }
            else
            {
                //if in edit mode, add fake cardsviews
                View sample = LayoutInflater.From(Context).Inflate(Resource.Layout.tools_list_items, _pagerTitleStripContainer, false);

                LayoutParams param     = (LayoutParams)sample.LayoutParameters;
                int          marginTop = (int)Math.Round(Utils.DpToPx(Settings.HeaderHeight + 10, Context));
                param.SetMargins(0, marginTop, 0, 0);
                LayoutParameters = param;

                AddView(sample);
            }
        }