黄学彪
2020-09-22 ade5917841b0fdcb1df7353ef7c56b1a1bdc9282
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
using System;
using System.Collections.Generic;
using System.Text;
 
namespace Shared.Phone.UserCenter
{
    /// <summary>
    /// 左右滑动的进度条控件
    /// </summary>
    public class SeekBarControl : DiyImageSeekBar
    {
        #region ■ 变量声明___________________________
 
        private uint nowProgressBarColor = 0;
        /// <summary>
        /// 控件能否使用
        /// </summary>
        public new bool Enable
        {
            set
            {
                this.IsClickable = value;
                if (value == true)
                {
                    //原来的颜色
                    base.ProgressBarColor = nowProgressBarColor;
                }
                else
                {
                    //灰色
                    base.ProgressBarColor = 0xffe8e8e8;
                }
            }
        }
 
        /// <summary>
        /// 进度条颜色
        /// </summary>
        public new uint ProgressBarColor
        {
            set
            {
                nowProgressBarColor = 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
    }
}