Пример #1
0
 private void OnThumbTintChanged(Brush newValue)
 {
     if (newValue is SolidColorBrush asColorBrush)
     {
         ThumbDrawable?.SetColorFilter(asColorBrush.Color, PorterDuff.Mode.SrcIn);
     }
 }
Пример #2
0
        private void OnThumbTintChanged(Brush newValue)
        {
            if (newValue is SolidColorBrush asColorBrush)
            {
#if __ANDROID_28__
#pragma warning disable 618 // SetColorFilter is deprecated
                ThumbDrawable?.SetColorFilter(asColorBrush.ColorWithOpacity, PorterDuff.Mode.SrcIn);
#pragma warning restore 618 // SetColorFilter is deprecated
#else
                ThumbDrawable?.SetColorFilter(new BlendModeColorFilter(asColorBrush.ColorWithOpacity, BlendMode.SrcIn));
#endif
            }
        }
Пример #3
0
        public DiscreteSeekBar(Context context, IAttributeSet attrs, int defStyleAttr)
            : base(context, attrs, defStyleAttr)
        {
            mShowIndicatorRunnable = new Runnable(Run);
            mFloaterListener       = this;

            Focusable = true;
            SetWillNotDraw(false);

            mTouchSlop = ViewConfiguration.Get(context).ScaledWindowTouchSlop;
            float density = context.Resources.DisplayMetrics.Density;

            TypedArray a = context.ObtainStyledAttributes(attrs, Resource.Styleable.DiscreteSeekBar,
                                                          defStyleAttr, Resource.Style.Widget_DiscreteSeekBar);

            int max   = 100;
            int min   = 0;
            int value = 0;

            mMirrorForRtl          = a.GetBoolean(Resource.Styleable.DiscreteSeekBar_dsb_mirrorForRtl, mMirrorForRtl);
            mAllowTrackClick       = a.GetBoolean(Resource.Styleable.DiscreteSeekBar_dsb_allowTrackClickToDrag, mAllowTrackClick);
            mIndicatorPopupEnabled = a.GetBoolean(Resource.Styleable.DiscreteSeekBar_dsb_indicatorPopupEnabled, mIndicatorPopupEnabled);
            mTrackHeight           = a.GetDimensionPixelSize(Resource.Styleable.DiscreteSeekBar_dsb_trackHeight, (int)(1 * density));
            mScrubberHeight        = a.GetDimensionPixelSize(Resource.Styleable.DiscreteSeekBar_dsb_scrubberHeight, (int)(4 * density));
            int thumbSize  = a.GetDimensionPixelSize(Resource.Styleable.DiscreteSeekBar_dsb_thumbSize, (int)(density * ThumbDrawable.DEFAULT_SIZE_DP));
            int separation = a.GetDimensionPixelSize(Resource.Styleable.DiscreteSeekBar_dsb_indicatorSeparation,
                                                     (int)(SEPARATION_DP * density));

            //Extra pixels for a minimum touch area of 32dp
            int touchBounds = (int)(density * 32);

            mAddedTouchBounds = System.Math.Max(0, (touchBounds - thumbSize) / 2);

            int        indexMax   = Resource.Styleable.DiscreteSeekBar_dsb_max;
            int        indexMin   = Resource.Styleable.DiscreteSeekBar_dsb_min;
            int        indexValue = Resource.Styleable.DiscreteSeekBar_dsb_value;
            TypedValue @out       = new TypedValue();

            //Not sure why, but we wanted to be able to use dimensions here...
            if (a.GetValue(indexMax, @out))
            {
                if (@out.Type == DataType.Dimension)
                {
                    max = a.GetDimensionPixelSize(indexMax, max);
                }
                else
                {
                    max = a.GetInteger(indexMax, max);
                }
            }
            if (a.GetValue(indexMin, @out))
            {
                if (@out.Type == DataType.Dimension)
                {
                    min = a.GetDimensionPixelSize(indexMin, min);
                }
                else
                {
                    min = a.GetInteger(indexMin, min);
                }
            }
            if (a.GetValue(indexValue, @out))
            {
                if (@out.Type == DataType.Dimension)
                {
                    value = a.GetDimensionPixelSize(indexValue, value);
                }
                else
                {
                    value = a.GetInteger(indexValue, value);
                }
            }

            mMin   = min;
            mMax   = Math.Max(min + 1, max);
            mValue = Math.Max(min, Math.Min(max, value));
            UpdateKeyboardRange();

            mIndicatorFormatter = a.GetString(Resource.Styleable.DiscreteSeekBar_dsb_indicatorFormatter);

            ColorStateList trackColor    = a.GetColorStateList(Resource.Styleable.DiscreteSeekBar_dsb_trackColor);
            ColorStateList progressColor = a.GetColorStateList(Resource.Styleable.DiscreteSeekBar_dsb_progressColor);
            ColorStateList rippleColor   = a.GetColorStateList(Resource.Styleable.DiscreteSeekBar_dsb_rippleColor);
            bool           editMode      = IsInEditMode;

            if (editMode || rippleColor == null)
            {
                rippleColor = new ColorStateList(new int[][] { new int[] { } }, new int[] { Color.DarkGray });
            }
            if (editMode || trackColor == null)
            {
                trackColor = new ColorStateList(new int[][] { new int[] { } }, new int[] { Color.Gray });
            }
            if (editMode || progressColor == null)
            {
                progressColor = new ColorStateList(new int[][] { new int[] { } }, new int[] { DEFAULT_THUMB_COLOR });
            }

            mRipple = SeekBarCompat.GetRipple(rippleColor);
            if (isLollipopOrGreater)
            {
                SeekBarCompat.SetBackground(this, mRipple);
            }
            else
            {
                mRipple.SetCallback(this);
            }

            TrackRectDrawable shapeDrawable = new TrackRectDrawable(trackColor);

            mTrack = shapeDrawable;
            mTrack.SetCallback(this);

            shapeDrawable = new TrackRectDrawable(progressColor);
            mScrubber     = shapeDrawable;
            mScrubber.SetCallback(this);

            mThumb = new ThumbDrawable(progressColor, thumbSize);
            mThumb.SetCallback(this);
            mThumb.SetBounds(0, 0, mThumb.IntrinsicWidth, mThumb.IntrinsicHeight);


            if (!editMode)
            {
                mIndicator = new PopupIndicator(context, attrs, defStyleAttr, ConvertValueToMessage(mMax),
                                                thumbSize, thumbSize + mAddedTouchBounds + separation);
                mIndicator.SetListener(mFloaterListener);
            }
            a.Recycle();

            SetNumericTransformer(new DefaultNumericTransformer());
        }