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());
        }
Beispiel #2
0
 public bool GetValue(int index, TypedValue outValue)
 {
     return(_array.GetValue(index, outValue));
 }
        public LoadingLayout(Context context, Mode mode, PtrOrientation scrollDirection, TypedArray attrs)
            : base(context)
        {
            //base(context);
            mMode = mode;
            mScrollDirection = scrollDirection;

            switch (scrollDirection)
            {
                case PtrOrientation.HORIZONTAL:
                    LayoutInflater.From(context).Inflate(Resource.Layout.pull_to_refresh_header_horizontal, this);
                    break;
                case PtrOrientation.VERTICAL:
                default:
                    LayoutInflater.From(context).Inflate(Resource.Layout.pull_to_refresh_header_vertical, this);
                    break;
            }

            mInnerLayout = (FrameLayout)FindViewById(Resource.Id.fl_inner);
            mHeaderText = (TextView)mInnerLayout.FindViewById(Resource.Id.pull_to_refresh_text);
            mHeaderProgress = (ProgressBar)mInnerLayout.FindViewById(Resource.Id.pull_to_refresh_progress);
            mSubHeaderText = (TextView)mInnerLayout.FindViewById(Resource.Id.pull_to_refresh_sub_text);
            mHeaderImage = (ImageView)mInnerLayout.FindViewById(Resource.Id.pull_to_refresh_image);

            FrameLayout.LayoutParams lp = (FrameLayout.LayoutParams)mInnerLayout.LayoutParameters;

            switch (mode)
            {
                case Mode.PULL_FROM_END:
                    lp.Gravity = scrollDirection == PtrOrientation.VERTICAL ? GravityFlags.Top : GravityFlags.Left;

                    // Load in labels
                    mPullLabel = context.GetString(Resource.String.pull_to_refresh_from_bottom_pull_label);
                    mRefreshingLabel = context.GetString(Resource.String.pull_to_refresh_from_bottom_refreshing_label);
                    mReleaseLabel = context.GetString(Resource.String.pull_to_refresh_from_bottom_release_label);
                    break;

                case Mode.PULL_FROM_START:
                default:
                    lp.Gravity = scrollDirection == PtrOrientation.VERTICAL ? GravityFlags.Bottom : GravityFlags.Right;

                    // Load in labels
                    mPullLabel = context.GetString(Resource.String.pull_to_refresh_pull_label);
                    mRefreshingLabel = context.GetString(Resource.String.pull_to_refresh_refreshing_label);
                    mReleaseLabel = context.GetString(Resource.String.pull_to_refresh_release_label);
                    break;
            }



            if (attrs.HasValue(Resource.Styleable.PullToRefresh_ptrHeaderBackground))
            {
                Drawable background = attrs.GetDrawable(Resource.Styleable.PullToRefresh_ptrHeaderBackground);
                if (null != background)
                {
                    ViewCompat.setBackground(this, background);
                }
            }

            if (attrs.HasValue(Resource.Styleable.PullToRefresh_ptrHeaderTextAppearance))
            {
                TypedValue styleID = new TypedValue();
                attrs.GetValue(Resource.Styleable.PullToRefresh_ptrHeaderTextAppearance, styleID);
                setTextAppearance(styleID.Data);
            }
            if (attrs.HasValue(Resource.Styleable.PullToRefresh_ptrSubHeaderTextAppearance))
            {
                TypedValue styleID = new TypedValue();
                attrs.GetValue(Resource.Styleable.PullToRefresh_ptrSubHeaderTextAppearance, styleID);
                setSubTextAppearance(styleID.Data);
            }

            // Text Color attrs need to be set after TextAppearance attrs
            if (attrs.HasValue(Resource.Styleable.PullToRefresh_ptrHeaderTextColor))
            {
                ColorStateList colors = attrs.GetColorStateList(Resource.Styleable.PullToRefresh_ptrHeaderTextColor);
                if (null != colors)
                {
                    setTextColor(colors);
                }
            }
            if (attrs.HasValue(Resource.Styleable.PullToRefresh_ptrHeaderSubTextColor))
            {
                ColorStateList colors = attrs.GetColorStateList(Resource.Styleable.PullToRefresh_ptrHeaderSubTextColor);
                if (null != colors)
                {
                    setSubTextColor(colors);
                }
            }

            // Try and get defined drawable from Attrs
            Drawable imageDrawable = null;
            if (attrs.HasValue(Resource.Styleable.PullToRefresh_ptrDrawable))
            {
                imageDrawable = attrs.GetDrawable(Resource.Styleable.PullToRefresh_ptrDrawable);
            }

            // Check Specific Drawable from Attrs, these overrite the generic
            // drawable attr above
            switch (mode)
            {
                case Mode.PULL_FROM_START:
                default:

                    if (attrs.HasValue(Resource.Styleable.PullToRefresh_ptrDrawableStart))
                    {
                        imageDrawable = attrs.GetDrawable(Resource.Styleable.PullToRefresh_ptrDrawableStart);
                    }
                    else if (attrs.HasValue(Resource.Styleable.PullToRefresh_ptrDrawableTop))
                    {
                        Utils.warnDeprecation("ptrDrawableTop", "ptrDrawableStart");
                        imageDrawable = attrs.GetDrawable(Resource.Styleable.PullToRefresh_ptrDrawableTop);
                    }
                    break;

                case Mode.PULL_FROM_END:
                    if (attrs.HasValue(Resource.Styleable.PullToRefresh_ptrDrawableEnd))
                    {
                        imageDrawable = attrs.GetDrawable(Resource.Styleable.PullToRefresh_ptrDrawableEnd);
                    }
                    else if (attrs.HasValue(Resource.Styleable.PullToRefresh_ptrDrawableBottom))
                    {
                        Utils.warnDeprecation("ptrDrawableBottom", "ptrDrawableEnd");
                        imageDrawable = attrs.GetDrawable(Resource.Styleable.PullToRefresh_ptrDrawableBottom);
                    }
                    break;
            }

            // If we don't have a user defined drawable, load the default
            if (null == imageDrawable)
            {

                imageDrawable = context.Resources.GetDrawable(getDefaultDrawableResId());
            }

            // Set Drawable, and save width/height
            setLoadingDrawable(imageDrawable);

            reset();
        }
Beispiel #4
0
//JAVA TO C# CONVERTER WARNING: 'final' parameters are not available in .NET:
//ORIGINAL LINE: public LoadingLayout(android.content.Context context, final PullToRefresh.PullMode mode, final PullToRefresh.ScrollOrientation scrollDirection, android.content.res.TypedArray attrs)
        public LoadingLayout(Context context, PullMode mode, ScrollOrientation scrollDirection, TypedArray attrs) : base(context)
        {
            mMode            = mode;
            mScrollDirection = scrollDirection;

            switch (scrollDirection)
            {
            case ScrollOrientation.HORIZONTAL:
                LayoutInflater.From(context).Inflate(Resource.Layout.pull_to_refresh_header_horizontal, this);
                break;

            case ScrollOrientation.VERTICAL:
            default:
                LayoutInflater.From(context).Inflate(Resource.Layout.pull_to_refresh_header_vertical, this);
                break;
            }

            mInnerLayout    = (FrameLayout)FindViewById(Resource.Id.fl_inner);
            mHeaderText     = (TextView)mInnerLayout.FindViewById(Resource.Id.pull_to_refresh_text);
            mHeaderProgress = (ProgressBar)mInnerLayout.FindViewById(Resource.Id.pull_to_refresh_progress);
            mSubHeaderText  = (TextView)mInnerLayout.FindViewById(Resource.Id.pull_to_refresh_sub_text);
            mHeaderImage    = (ImageView)mInnerLayout.FindViewById(Resource.Id.pull_to_refresh_image);

            LayoutParams lp = (LayoutParams)mInnerLayout.LayoutParameters;

            switch (mode)
            {
            case PullMode.PULL_FROM_END:
                lp.Gravity = scrollDirection == ScrollOrientation.VERTICAL ? GravityFlags.Top : GravityFlags.Left;

                // Load in labels
                mPullLabel       = context.GetString(Resource.String.pull_to_refresh_pull_label);
                mRefreshingLabel = context.GetString(Resource.String.pull_to_refresh_refreshing_label);
                mReleaseLabel    = context.GetString(Resource.String.pull_to_refresh_release_label);
                break;

            case PullMode.PULL_FROM_START:
            default:
                lp.Gravity = scrollDirection == ScrollOrientation.VERTICAL ? GravityFlags.Bottom : GravityFlags.Right;

                // Load in labels
                mPullLabel       = context.GetString(Resource.String.pull_to_refresh_pull_label);
                mRefreshingLabel = context.GetString(Resource.String.pull_to_refresh_refreshing_label);
                mReleaseLabel    = context.GetString(Resource.String.pull_to_refresh_release_label);
                break;
            }

            if (attrs.HasValue(Resource.Styleable.PullToRefresh_ptrHeaderBackground))
            {
                Drawable background = attrs.GetDrawable(Resource.Styleable.PullToRefresh_ptrHeaderBackground);
                if (null != background)
                {
                    ViewCompat.setBackground(this, background);
                }
            }

            if (attrs.HasValue(Resource.Styleable.PullToRefresh_ptrHeaderTextAppearance))
            {
                TypedValue styleID = new TypedValue();
                attrs.GetValue(Resource.Styleable.PullToRefresh_ptrHeaderTextAppearance, styleID);
                TextAppearance = styleID.Data;
            }
            if (attrs.HasValue(Resource.Styleable.PullToRefresh_ptrSubHeaderTextAppearance))
            {
                TypedValue styleID = new TypedValue();
                attrs.GetValue(Resource.Styleable.PullToRefresh_ptrSubHeaderTextAppearance, styleID);
                SubTextAppearance = styleID.Data;
            }

            // Text Color attrs need to be set after TextAppearance attrs
            if (attrs.HasValue(Resource.Styleable.PullToRefresh_ptrHeaderTextColor))
            {
                ColorStateList colors = attrs.GetColorStateList(Resource.Styleable.PullToRefresh_ptrHeaderTextColor);
                if (null != colors)
                {
                    TextColor = colors;
                }
            }
            if (attrs.HasValue(Resource.Styleable.PullToRefresh_ptrHeaderSubTextColor))
            {
                ColorStateList colors = attrs.GetColorStateList(Resource.Styleable.PullToRefresh_ptrHeaderSubTextColor);
                if (null != colors)
                {
                    SubTextColor = colors;
                }
            }

            // Try and get defined drawable from Attrs
            Drawable imageDrawable = null;

            if (attrs.HasValue(Resource.Styleable.PullToRefresh_ptrDrawable))
            {
                imageDrawable = attrs.GetDrawable(Resource.Styleable.PullToRefresh_ptrDrawable);
            }

            // Check Specific Drawable from Attrs, these overrite the generic
            // drawable attr above
            switch (mode)
            {
            case PullMode.PULL_FROM_START:
            default:
                if (attrs.HasValue(Resource.Styleable.PullToRefresh_ptrDrawableStart))
                {
                    imageDrawable = attrs.GetDrawable(Resource.Styleable.PullToRefresh_ptrDrawableStart);
                }
                else if (attrs.HasValue(Resource.Styleable.PullToRefresh_ptrDrawableTop))
                {
                    Utils.warnDeprecation("ptrDrawableTop", "ptrDrawableStart");
                    imageDrawable = attrs.GetDrawable(Resource.Styleable.PullToRefresh_ptrDrawableTop);
                }
                break;

            case PullMode.PULL_FROM_END:
                if (attrs.HasValue(Resource.Styleable.PullToRefresh_ptrDrawableEnd))
                {
                    imageDrawable = attrs.GetDrawable(Resource.Styleable.PullToRefresh_ptrDrawableEnd);
                }
                else if (attrs.HasValue(Resource.Styleable.PullToRefresh_ptrDrawableBottom))
                {
                    Utils.warnDeprecation("ptrDrawableBottom", "ptrDrawableEnd");
                    imageDrawable = attrs.GetDrawable(Resource.Styleable.PullToRefresh_ptrDrawableBottom);
                }
                break;
            }

            // If we don't have a user defined drawable, load the default
            if (null == imageDrawable)
            {
                imageDrawable = context.Resources.GetDrawable(DefaultDrawableResId);
            }

            // Set Drawable, and save width/height
            LoadingDrawable = imageDrawable;

            reset();
        }