public SmoothProgressBar(Context context, IAttributeSet attrs, int defStyle) 
            : base(context, attrs, defStyle)
        {
            var res = context.Resources;
            var a = context.ObtainStyledAttributes(attrs, Resource.Styleable.SmoothProgressBar, defStyle, 0);

            var color = a.GetColor(Resource.Styleable.SmoothProgressBar_spb_color,
                res.GetColor(Resource.Color.spb_default_color));
            var sectionsCount = a.GetInteger(Resource.Styleable.SmoothProgressBar_spb_sections_count,
                res.GetInteger(Resource.Integer.spb_default_sections_count));
            var separatorLength =
                a.GetDimensionPixelSize(Resource.Styleable.SmoothProgressBar_spb_stroke_separator_length,
                    res.GetDimensionPixelSize(Resource.Dimension.spb_default_stroke_separator_length));
            var strokeWidth = a.GetDimension(Resource.Styleable.SmoothProgressBar_spb_stroke_width,
                res.GetDimension(Resource.Dimension.spb_default_stroke_width));
            var speed = a.GetFloat(Resource.Styleable.SmoothProgressBar_spb_speed,
                float.Parse(res.GetString(Resource.String.spb_default_speed), CultureInfo.InvariantCulture));
            var reversed = a.GetBoolean(Resource.Styleable.SmoothProgressBar_spb_reversed,
                res.GetBoolean(Resource.Boolean.spb_default_reversed));
            var mirrorMode = a.GetBoolean(Resource.Styleable.SmoothProgressBar_spb_mirror_mode,
                res.GetBoolean(Resource.Boolean.spb_default_mirror_mode));
            var colorsId = a.GetResourceId(Resource.Styleable.SmoothProgressBar_spb_colors, 0);
            var idInterpolator = a.GetResourceId(Resource.Styleable.SmoothProgressBar_android_interpolator, 0);
            a.Recycle();

            if (idInterpolator > 0)
                SetInterpolator(context, idInterpolator);

            Color[] colors = null;
            if (colorsId != 0)
                colors = IntsToColors(res.GetIntArray(colorsId));

            var builder =
                new SmoothProgressDrawable.Builder(context)
                    .Speed(speed)
                    .SectionsCount(sectionsCount)
                    .SeparatorLength(separatorLength)
                    .StrokeWidth(strokeWidth)
                    .Reversed(reversed)
                    .MirrorMode(mirrorMode);

            if (Interpolator != null) builder.Interpolator(Interpolator);

            if (colors != null && colors.Length > 0)
                builder.Colors(colors);
            else
                builder.Color(color);

            IndeterminateDrawable = builder.Build();
        }
Exemplo n.º 2
0
        public SmoothProgressBar(Context context, IAttributeSet attrs, int defStyle)
            : base(context, attrs, defStyle)
        {
            var res = context.Resources;
            var a   = context.ObtainStyledAttributes(attrs, Resource.Styleable.SmoothProgressBar, defStyle, 0);

            var color = a.GetColor(Resource.Styleable.SmoothProgressBar_spb_color,
                                   res.GetColor(Resource.Color.spb_default_color));
            var sectionsCount = a.GetInteger(Resource.Styleable.SmoothProgressBar_spb_sections_count,
                                             res.GetInteger(Resource.Integer.spb_default_sections_count));
            var separatorLength =
                a.GetDimensionPixelSize(Resource.Styleable.SmoothProgressBar_spb_stroke_separator_length,
                                        res.GetDimensionPixelSize(Resource.Dimension.spb_default_stroke_separator_length));
            var strokeWidth = a.GetDimension(Resource.Styleable.SmoothProgressBar_spb_stroke_width,
                                             res.GetDimension(Resource.Dimension.spb_default_stroke_width));
            var speed = a.GetFloat(Resource.Styleable.SmoothProgressBar_spb_speed,
                                   float.Parse(res.GetString(Resource.String.spb_default_speed)));
            var reversed = a.GetBoolean(Resource.Styleable.SmoothProgressBar_spb_reversed,
                                        res.GetBoolean(Resource.Boolean.spb_default_reversed));
            var mirrorMode = a.GetBoolean(Resource.Styleable.SmoothProgressBar_spb_mirror_mode,
                                          res.GetBoolean(Resource.Boolean.spb_default_mirror_mode));
            var colorsId       = a.GetResourceId(Resource.Styleable.SmoothProgressBar_spb_colors, 0);
            var idInterpolator = a.GetResourceId(Resource.Styleable.SmoothProgressBar_android_interpolator, 0);

            a.Recycle();

            if (idInterpolator > 0)
            {
                SetInterpolator(context, idInterpolator);
            }

            Color[] colors = null;
            if (colorsId != 0)
            {
                colors = IntsToColors(res.GetIntArray(colorsId));
            }

            var builder =
                new SmoothProgressDrawable.Builder(context)
                .Speed(speed)
                .SectionsCount(sectionsCount)
                .SeparatorLength(separatorLength)
                .StrokeWidth(strokeWidth)
                .Reversed(reversed)
                .MirrorMode(mirrorMode);

            if (Interpolator != null)
            {
                builder.Interpolator(Interpolator);
            }

            if (colors != null && colors.Length > 0)
            {
                builder.Colors(colors);
            }
            else
            {
                builder.Color(color);
            }

            IndeterminateDrawable = builder.Build();
        }