Ejemplo n.º 1
0
        public CircleImageView(Context context, int color, float radius) : base(context)
        {
            float density       = Context.Resources.DisplayMetrics.Density;
            int   diameter      = (int)(radius * density * 2);
            int   shadowYOffset = (int)(density * Y_OFFSET);
            int   shadowXOffset = (int)(density * X_OFFSET);

            mShadowRadius = (int)(density * SHADOW_RADIUS);

            ShapeDrawable circle;

            if (elevationSupported())
            {
                circle = new ShapeDrawable(new OvalShape());
                ViewCompat.SetElevation(this, SHADOW_ELEVATION * density);
            }
            else
            {
                OvalShape oval = new OvalShadow(this, mShadowRadius, diameter);
                circle = new ShapeDrawable(oval);
                ViewCompat.SetLayerType(this, ViewCompat.LayerTypeSoftware, circle.Paint);
                circle.Paint.SetShadowLayer(mShadowRadius, shadowXOffset, shadowYOffset,
                                            new Color(KEY_SHADOW_COLOR));
                int padding = mShadowRadius;
                // set padding so the inner image sits correctly within the shadow.
                SetPadding(padding, padding, padding, padding);
            }
            circle.Paint.Color = new Color(color);
            SetBackgroundDrawable(circle);
        }
Ejemplo n.º 2
0
        public CircleImageView(Context context, int color, float radius) : base(context)
        {
            var density       = Context.Resources.DisplayMetrics.Density;
            var diameter      = (int)(radius * density * 2);
            var shadowYOffset = (int)(density * YOffset);
            var shadowXOffset = (int)(density * XOffset);

            _shadowRadius = (int)(density * ShadowRadius);

            ShapeDrawable circle;

            if (ElevationSupported())
            {
                circle = new ShapeDrawable(new OvalShape());
                ViewCompat.SetElevation(this, ShadowElevation * density);
            }
            else
            {
                OvalShape oval = new OvalShadow(this, _shadowRadius, diameter);
                circle = new ShapeDrawable(oval);
#pragma warning disable 618
                ViewCompat.SetLayerType(this, ViewCompat.LayerTypeSoftware, circle.Paint);
#pragma warning restore 618
                circle.Paint.SetShadowLayer(_shadowRadius, shadowXOffset, shadowYOffset,
                                            new Color(KeyShadowColor));
                var padding = _shadowRadius;
                SetPadding(padding, padding, padding, padding);
            }
            circle.Paint.Color = new Color(color);
#pragma warning disable 618
            SetBackgroundDrawable(circle);
#pragma warning restore 618
        }
        protected override void OnLayout(bool changed, int left, int top, int right, int bottom)
        {
            base.OnLayout(changed, left, top, right, bottom);
            float density = Context.Resources.DisplayMetrics.Density;

            mDiameter = Math.Min(MeasuredWidth, MeasuredHeight);
            if (mDiameter <= 0)
            {
                mDiameter = (int)density * DEFAULT_CIRCLE_DIAMETER;
            }
            if (Background == null && mCircleBackgroundEnabled)
            {
                int shadowYOffset = (int)(density * Y_OFFSET);
                int shadowXOffset = (int)(density * X_OFFSET);
                mShadowRadius = (int)(density * SHADOW_RADIUS);

                if (ElevationSupported())
                {
                    mBgCircle = new ShapeDrawable(new OvalShape());
                    ViewCompat.SetElevation(this, SHADOW_ELEVATION * density);
                }
                else
                {
                    OvalShape oval = new OvalShadow(mShadowRadius, mDiameter, this);
                    mBgCircle = new ShapeDrawable(oval);
                    ViewCompat.SetLayerType(this, ViewCompat.LayerTypeSoftware, mBgCircle.Paint);
                    mBgCircle.Paint.SetShadowLayer(mShadowRadius, shadowXOffset, shadowYOffset,
                                                   KEY_SHADOW_COLOR);
                    int padding = (int)mShadowRadius;
                    SetPadding(padding, padding, padding, padding);
                }
                mBgCircle.Paint.Color = mBackGroundColor;
                SetBackgroundDrawable(mBgCircle);
            }
            mProgressDrawable.SetBackgrounColor(mBackGroundColor);
            mProgressDrawable.SetColorSchemeColors(mColors);
            mProgressDrawable.SetSizeParameters(mDiameter, mDiameter,
                                                mInnerRadius <= 0 ? (mDiameter - mProgressStokeWidth * 2) / 4 : mInnerRadius,
                                                mProgressStokeWidth,
                                                mArrowWidth < 0 ? mProgressStokeWidth * 5 : mArrowWidth,
                                                mArrowHeight < 0 ? mProgressStokeWidth * 2 : mArrowHeight);
            if (IsShowArrow())
            {
                mProgressDrawable.SetArrowScale(1f);
                mProgressDrawable.ShowArrow(true);
            }
            base.SetImageDrawable(null);
            base.SetImageDrawable(mProgressDrawable);
            mProgressDrawable.SetAlpha(255);
            mProgressDrawable.Start();
        }