xm
2020-08-14 a45fe56aeeac8f28a9891b83362954067c8166dc
ZigbeeApp/Shared/Phone/UserCenter/CommonBase/Controls/CompoundControls/SeekBarControl.cs
New file
@@ -0,0 +1,163 @@
using System;
using System.Collections.Generic;
using System.Text;
namespace Shared.Phone.UserCenter
{
    /// <summary>
    /// 左右滑动的进度条控件
    /// </summary>
    public class SeekBarControl : DiyImageSeekBar
    {
        #region ■ 变量声明___________________________
        /// <summary>
        /// 进度条可用时的背景色
        /// </summary>
        private uint ProgressBarEnableColor = 0;
        /// <summary>
        /// 进度条不可用时的背景色(默认灰色)
        /// </summary>
        public uint ProgressBarUnEnableColor = 0xffe8e8e8;
        /// <summary>
        /// 当前可用状态
        /// </summary>
        private bool nowEnable = true;
        /// <summary>
        /// 控件能否使用
        /// </summary>
        public new bool Enable
        {
            set
            {
                //状态没有改变
                if (nowEnable == value) { return; }
                nowEnable = value;
                this.IsClickable = value;
                if (value == true)
                {
                    //原来的颜色
                    base.ProgressBarColor = ProgressBarEnableColor;
                }
                else
                {
                    //灰色
                    base.ProgressBarColor = ProgressBarUnEnableColor;
                }
            }
        }
        /// <summary>
        /// 进度条颜色
        /// </summary>
        public new uint ProgressBarColor
        {
            set
            {
                ProgressBarEnableColor = value;
                base.ProgressBarColor = value;
            }
        }
        /// <summary>
        /// 进度值改变,如果要设置初始进度值,此变量要在设置初始进度值之前进行设置(第一个参数0:滑动的时候,1:手指弹起的时候)
        /// </summary>
        public Action<int, int> ProgressChangedEvent = null;
        /// <summary>
        /// 进度条事件的触发时间间隔(默认没有间隔,单位为毫秒)
        /// </summary>
        public int EventWaitTime = -1;
        /// <summary>
        /// 前回时间
        /// </summary>
        private DateTime oldTime = DateTime.Now;
        #endregion
        #region ■ 初始化_____________________________
        /// <summary>
        /// 左右滑动的进度条控件
        /// </summary>
        /// <param name="i_width">宽度,非真实值</param>
        public SeekBarControl(int i_width = 962)
        {
            this.Width = Application.GetRealWidth(i_width);
            this.Height = Application.GetRealHeight(84);
            //圆球的宽度
            this.ThumbImageHeight = Application.GetRealHeight(84);
            this.ThumbImagePath = "Item/SeekBarIcon.png";
            //进度条的宽度
            this.SeekBarViewHeight = Application.GetRealHeight(10);
            //进度条背景色
            this.SeekBarBackgroundColor = 0xfff5f5f5;
            //上方是否显示文本
            this.IsProgressTextShow = false;
            this.MaxValue = 100;
            this.Gravity = Gravity.CenterHorizontal;
            //进度条值改变事件
            this.OnProgressChangedEvent += this.MyProgressChangedEvent;
            //手指弹起事件
            this.OnStopTrackingTouchEvent += this.MyStopTrackingTouchEvent;
        }
        #endregion
        #region ■ 事件_______________________________
        /// <summary>
        /// 进度条值改变事件
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="value"></param>
        private void MyProgressChangedEvent(object sender, int value)
        {
            if (this.ProgressChangedEvent == null)
            {
                this.OnProgressChangedEvent -= this.MyProgressChangedEvent;
                return;
            }
            //时间间隔
            if (EventWaitTime != -1)
            {
                if ((DateTime.Now - oldTime).TotalMilliseconds < EventWaitTime) { return; }
                oldTime = DateTime.Now;
            }
            this.ProgressChangedEvent(0, value);
        }
        /// <summary>
        /// 手指弹起事件
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="value"></param>
        private void MyStopTrackingTouchEvent(object sender, int value)
        {
            if (this.ProgressChangedEvent == null)
            {
                this.OnStopTrackingTouchEvent -= this.MyStopTrackingTouchEvent;
                return;
            }
            //弹起事件不需要判断时间
            this.ProgressChangedEvent(1, value);
        }
        #endregion
        #region ■ 一般方法___________________________
        /// <summary>
        /// 控件摧毁
        /// </summary>
        public override void RemoveFromParent()
        {
            this.ProgressChangedEvent = null;
            base.RemoveFromParent();
        }
        #endregion
    }
}