Exemple #1
0
 public void SetOnClickEventHandler <TData>(PagerAnimatedAdapter <TData> .PagerItemClickHandler clickHandler)
 {
     if (Adapter is PagerAnimatedAdapter <TData> adapter)
     {
         adapter.ItemClick += clickHandler;
     }
 }
Exemple #2
0
        /// <summary>
        ///     Inits the control.
        /// </summary>
        /// <param name="dataCollection">Data collection of TData.</param>
        /// <param name="viewInflater">
        ///     Method which will return view of page inflated with TData. Background of result view should
        ///     be transparent and setted through BackgroundColor parameter.
        /// </param>
        /// <param name="wm">Window manager.</param>
        /// <param name="fm">Fragment manager.</param>
        /// <param name="pageGapDistance">Distance between two pages in px.</param>
        /// <param name="activePageSideOffset">Distance from side of control to side of page in px.</param>
        /// <param name="animationType"></param>
        /// <param name="darkenMultiplier">
        ///     How much inactive pages should be darkened. Value from 0.0f to 1.0f, where 0.0f is not
        ///     darkened at all and 1.0f completely black.
        /// </param>
        /// <param name="shrinkedViewScale">
        ///     Size of inactive pages respectively to active page. Value from 0.0f to 1.0f, where 0.0f
        ///     shrinkes page to invisible and 1.0f doesn't resize inactive page.
        /// </param>
        /// <param name="backgroundColor">Background color. Transparent if null.</param>
        /// <param name="cornerRadius">Corner radius.</param>
        /// <typeparam name="TData">Type of each item in collection, from which pages will be inflated.</typeparam>
        public void InitControl <TData>(IList <TData> dataCollection,
                                        PagerAnimatedAdapter <TData> .ViewInflatHandler viewInflater,
                                        IWindowManager wm,
                                        FragmentManager fm,
                                        int pageGapDistance         = 0,
                                        int activePageSideOffset    = 0,
                                        AnimationType animationType = AnimationType.None,
                                        float darkenMultiplier      = 0.4f,
                                        float shrinkedViewScale     = 0.8f,
                                        Color?backgroundColor       = null,
                                        int cornerRadius            = 0)
        {
            PageMargin         = pageGapDistance;
            OffscreenPageLimit = 3;
            SetClipToPadding(false);
            SetPadding(activePageSideOffset, 0, activePageSideOffset, 0);
            var displaySize = new Point();

            wm.DefaultDisplay.GetSize(displaySize);

            var backgroundShape = new RoundRectShape(
                new float[]
            {
                cornerRadius, cornerRadius, cornerRadius, cornerRadius, cornerRadius, cornerRadius, cornerRadius,
                cornerRadius
            },
                null, null);

            var backgroundShapeDrawable = new ShapeDrawable(backgroundShape);
            var backgroundPaint         = backgroundShapeDrawable.Paint;

            backgroundPaint.Color = backgroundColor ?? Color.Transparent;
            backgroundPaint.SetStyle(Paint.Style.Fill);

            ShapeDrawable foregroundShapeDrawable = null;

            switch (animationType)
            {
            case AnimationType.None:
                PageTransformer = null;
                break;

            case AnimationType.Revealing:
                foregroundShapeDrawable = new ShapeDrawable(backgroundShape);
                var foregroundPaint = foregroundShapeDrawable.Paint;
                foregroundPaint.Color = Color.Black;
                foregroundPaint.SetStyle(Paint.Style.Fill);
                PageTransformer = new RevealingPageTransformer(darkenMultiplier, shrinkedViewScale,
                                                               AnimationHorizontalPositionOffset);
                break;

            default:
                break;
            }

            AnimationHorizontalPositionOffset = (float)(PageMargin + PaddingLeft) / displaySize.X;
            SetPageTransformer(true, PageTransformer);

            var adapter = new PagerAnimatedAdapter <TData>(dataCollection, viewInflater, backgroundShapeDrawable,
                                                           foregroundShapeDrawable, fm);

            Adapter = adapter;
        }