Exemplo n.º 1
0
        protected override void OnRestoreInstanceState(IParcelable state)
        {
            SavedState ss = (SavedState)state;

            base.OnRestoreInstanceState(ss.SuperState);

            Settings = ss.Settings;
            if (HeaderBackground != null)
            {
                HeaderBackground.SetBackgroundColor(new Color(Settings.Color));
            }

            MaterialViewPagerAnimator animator = MaterialViewPagerHelper.GetAnimator(Context);

            //-1*ss.yOffset restore to 0
            animator.RestoreScroll(-1 * ss.YOffset, ss.Settings);
            MaterialViewPagerHelper.Register(Context, animator);
        }
Exemplo n.º 2
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);
            }
        }