private void handleTypedArray(Context context, IAttributeSet attrs)
        {
            if (attrs == null)
            {
                return;
            }

            TypedArray typedArray = context.ObtainStyledAttributes(attrs, Resource.Styleable.CircleIndicator);

            this.mIndicatorWidth  = typedArray.GetDimensionPixelSize(Resource.Styleable.CircleIndicator_ci_width, -1);
            this.mIndicatorHeight = typedArray.GetDimensionPixelSize(Resource.Styleable.CircleIndicator_ci_height, -1);
            this.mIndicatorMargin = typedArray.GetDimensionPixelSize(Resource.Styleable.CircleIndicator_ci_margin, -1);

            this.mAnimatorResId = typedArray.GetResourceId(Resource.Styleable.CircleIndicator_ci_animator,
                                                           Resource.Animator.scale_with_alpha);
            this.mAnimatorReverseResId =
                typedArray.GetResourceId(Resource.Styleable.CircleIndicator_ci_animator_reverse, 0);
            this.mIndicatorBackgroundResId = typedArray.GetResourceId(Resource.Styleable.CircleIndicator_ci_drawable,
                                                                      Resource.Drawable.white_radius);
            this.mIndicatorUnselectedBackgroundResId =
                typedArray.GetResourceId(Resource.Styleable.CircleIndicator_ci_drawable_unselected,
                                         this.mIndicatorBackgroundResId);

            Android.Widget.Orientation orientation =
                (Android.Widget.Orientation)typedArray.GetInt(Resource.Styleable.CircleIndicator_ci_orientation, -1);
            Orientation = (orientation == Android.Widget.Orientation.Vertical
                ? Android.Widget.Orientation.Vertical
                : Android.Widget.Orientation.Horizontal);

            int gravity = typedArray.GetInt(Resource.Styleable.CircleIndicator_ci_gravity, -1);

            SetGravity((gravity >= 0 ? (GravityFlags)gravity : GravityFlags.Center));

            typedArray.Recycle();
        }
        private void addIndicator(Android.Widget.Orientation orientation, int backgroundDrawableId, Animator animator)
        {
            if (animator.IsRunning)
            {
                animator.End();
                animator.Cancel();
            }

            var indicator = new View(Context);

            indicator.SetBackgroundResource(backgroundDrawableId);
            AddView(indicator, mIndicatorWidth, mIndicatorHeight);
            LayoutParams lp = (LayoutParams)indicator.LayoutParameters;

            if (orientation == Android.Widget.Orientation.Horizontal)
            {
                lp.LeftMargin  = mIndicatorMargin;
                lp.RightMargin = mIndicatorMargin;
            }
            else
            {
                lp.TopMargin    = mIndicatorMargin;
                lp.BottomMargin = mIndicatorMargin;
            }

            indicator.LayoutParameters = lp;

            animator.SetTarget(indicator);
            animator.Start();
        }
        public CirclePageIndicator(Context context, IAttributeSet attrs, int defStyle)
            : base(context, attrs, defStyle)
        {

            if (IsInEditMode) return;

            //Load defaults from resources
            Resources res = this.Resources;
            Color defaultPageColor = res.GetColor(R.Color.default_circle_indicator_page_color);
            Color defaultFillColor = res.GetColor(R.Color.default_circle_indicator_fill_color);
            int defaultOrientation = res.GetInteger(R.Integer.default_circle_indicator_orientation);
            Color defaultStrokeColor = res.GetColor(R.Color.default_circle_indicator_stroke_color);
            float defaultStrokeWidth = res.GetDimension(R.Dimension.default_circle_indicator_stroke_width);
            float defaultRadius = res.GetDimension(R.Dimension.default_circle_indicator_radius);
            bool defaultCentered = res.GetBoolean(R.Boolean.default_circle_indicator_centered);
            bool defaultSnap = res.GetBoolean(R.Boolean.default_circle_indicator_snap);

            //Retrieve styles attributes
            TypedArray a = context.ObtainStyledAttributes(attrs, R.Styleable.CirclePageIndicator, defStyle, 0);

            mCentered = a.GetBoolean(R.Styleable.CirclePageIndicator_centered, defaultCentered);
            mOrientation = (Android.Widget.Orientation)a.GetInt(R.Styleable.CirclePageIndicator_android_orientation, defaultOrientation);
            mPaintPageFill.SetStyle(Paint.Style.Fill);
            mPaintPageFill.Color = a.GetColor(R.Styleable.CirclePageIndicator_pageColor, defaultPageColor);
            mPaintStroke.SetStyle(Paint.Style.Stroke);
            mPaintStroke.Color = a.GetColor(R.Styleable.CirclePageIndicator_strokeColor, defaultStrokeColor);
            mPaintStroke.StrokeWidth = a.GetDimension(R.Styleable.CirclePageIndicator_strokeWidth, defaultStrokeWidth);
            mPaintFill.SetStyle(Paint.Style.Fill);
            mPaintFill.Color = a.GetColor(R.Styleable.CirclePageIndicator_fillColor, defaultFillColor);
            mRadius = a.GetDimension(R.Styleable.CirclePageIndicator_radius, defaultRadius);
            mSnap = a.GetBoolean(R.Styleable.CirclePageIndicator_snap, defaultSnap);

            Drawable background = a.GetDrawable(R.Styleable.CirclePageIndicator_android_background);
            if (background != null)
            {
                SetBackgroundDrawable(background);
            }

            a.Recycle();

            ViewConfiguration configuration = ViewConfiguration.Get(context);
            mTouchSlop = ViewConfigurationCompat.GetScaledPagingTouchSlop(configuration);
        }
        public void setOrientation(Android.Widget.Orientation orientation)
        {

            switch (orientation)
            {
                case Android.Widget.Orientation.Horizontal:
                case Android.Widget.Orientation.Vertical:
                    mOrientation = orientation;
                    RequestLayout();
                    break;

                default:
                    throw new Java.Lang.IllegalArgumentException("Orientation must be either HORIZONTAL or VERTICAL.");
            }
        }