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
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
using System;
 
namespace Shared.Phone.UserCenter
{
    /// <summary>
    /// Button的共通,共有的方法写在里面,
    /// 初始值:标准字体和颜色,文字向左靠齐
    /// </summary>
    public class ButtonCommon : Button
    {
        /// <summary>
        /// 单击弹起事件
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        public delegate void _MouseUpEvent(object sender, MouseEventArgs e);
        /// <summary>
        /// 单击弹起事件(这事件封装有可单击的时间间隔的功能:5秒)
        /// </summary>
        public _MouseUpEvent MouseUpEvent;
        /// <summary>
        /// 能否触发单击弹起事件
        /// </summary>
        public bool isCanClickUp = true;
        /// <summary>
        /// 显示可执行单击弹起的倒计时
        /// </summary>
        public bool IsShowMouseUpTime = false;
        /// <summary>
        /// 弹起间隔2秒(设置为0时,无间隔)
        /// </summary>
        public int MouseUpTime = 2;
        /// <summary>
        /// 向上的偏差值
        /// </summary>
        public int DeviationValue = Application.GetRealHeight(10);
        /// <summary>
        /// 初始化(初始值:标准字体颜色,文字向左靠齐)
        /// </summary>
        public ButtonCommon()
        {
            this.TextColor = UserCenterColor.Current.TextColor;
            this.TextAlignment = TextAlignment.CenterLeft;
 
            //测试,全体字体为14号字
            this.TextSize = 14;
 
            this.MouseUpEventHandler += this.Button_MouseUpEvent;
        }
 
        /// <summary>
        /// 初始化控件大小(不以平均值进行真实数值计算)
        /// </summary>
        /// <param name="i_Width">宽度</param>
        /// <param name="i_Height">高度</param>
        /// <param name="real">是否计算真实值</param>
        public void InitSize(int i_Width, int i_Height, bool real = true)
        {
            if (real == true)
            {
                i_Width = Application.GetRealWidth(i_Width);
                i_Height = Application.GetRealHeight(i_Height);
            }
 
            this.Height = i_Height;
            this.Width = i_Width;
        }
 
        /// <summary>
        /// 初始化控件大小(不以平均值进行真实数值计算)
        /// </summary>
        /// <param name="i_Width">宽度</param>
        /// <param name="real">是否计算真实值</param>
        public void InitSize(int i_Width, bool real = false)
        {
            if (real == true)
            {
                i_Width = Application.GetRealWidth(i_Width);
            }
 
            this.Height = ControlCommonResourse.NormalControlHeight;
            this.Width = i_Width;
        }
 
        /// <summary>
        /// 初始化控件大小
        /// </summary>
        public void InitSize()
        {
            this.Height = ControlCommonResourse.NormalControlHeight;
            this.Width = Application.CurrentWidth - ControlCommonResourse.XXLeft;
        }
 
        /// <summary>
        /// 初始化控件大小(以平均值进行真实数值计算)
        /// </summary>
        /// <param name="i_Width">宽度</param>
        /// <param name="i_Height">高度</param>
        /// <param name="real">是否计算真实值</param>
        public void InitAvgSize(int i_Width, int i_Height, bool real = true)
        {
            if (real == true)
            {
                i_Width = Application.GetMinRealAverage(i_Width);
                i_Height = Application.GetMinRealAverage(i_Height);
            }
 
            this.Height = i_Height;
            this.Width = i_Width;
        }
 
        /// <summary>
        /// Y轴重置(真实数值,没有父容器无效)
        /// </summary>
        /// <param name="alignment">上下对齐方式</param>
        /// <param name="Space">上下两部分的间距</param>
        public void ReSetYaxis(UViewAlignment alignment, int Space = 0)
        {
            if (this.Parent == null)
            {
                return;
            }
            //Y轴重置
            int YY = UserCenterLogic.GetControlChidrenYaxis(this.Parent.Height, this.Height, alignment, Space);
            if (alignment == UViewAlignment.Top)
            {
                YY = YY + this.DeviationValue;
            }
            else if (alignment == UViewAlignment.Bottom)
            {
                YY = YY - this.DeviationValue;
            }
            this.Y = UserCenterLogic.GetControlChidrenYaxis(this.Parent.Height, this.Height, alignment, Space);
        }
 
        /// <summary>
        /// 单击弹起事件
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void Button_MouseUpEvent(object sender, MouseEventArgs e)
        {
            if (this.MouseUpEvent == null)
            {
                //永久移除事件
                this.MouseUpEventHandler -= this.Button_MouseUpEvent;
                return;
            }
            if (this.isCanClickUp == false)
            {
                return;
            }
 
            if (this.MouseUpTime > 0)
            {
                this.isCanClickUp = false;
                string text = this.Text;
 
                new System.Threading.Thread(() =>
                {
                    //不能够连续狂点
                    int myTime = this.MouseUpTime;
                    while (myTime >= 0)
                    {
                        if (this.IsShowMouseUpTime == true)
                        {
                            Application.RunOnMainThread(() =>
                            {
                                this.Text = text + "(" + myTime + ")";
                            });
                        }
                        System.Threading.Thread.Sleep(1000);
                        myTime--;
                    }
                    this.isCanClickUp = true;
 
                    if (this.IsShowMouseUpTime == true)
                    {
                        Application.RunOnMainThread(() =>
                        {
                            this.Text = text;
                        });
                    }
                })
                { IsBackground = true }.Start();
            }
 
            //执行自定义的事件
            this.MouseUpEvent(sender, e);
        }
    }
 
    /// <summary>
    /// Icon类的共通
    /// </summary>
    public class ButtonIconCommon : ButtonCommon
    {
        /// <summary>
        /// 是否启用点亮功能(默认不启用)
        /// </summary>
        public bool UseClickStatu = false;
 
        /// <summary>
        /// Icon类的共通
        /// </summary>
        public ButtonIconCommon()
        {
            //这个事件是搞点亮特效的
            this.MouseDownEventHandler += this.Button_MouseDownEvent;
        }
        /// <summary>
        /// 单击按下事件
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void Button_MouseDownEvent(object sender, MouseEventArgs e)
        {
            if (this.UseClickStatu == false)
            {
                //永久移除
                this.MouseDownEventHandler -= this.Button_MouseDownEvent;
                return;
            }
 
            if (string.IsNullOrEmpty(this.SelectedImagePath) == false)
            {
                //设置选择的状态
                this.SetSelectStatu();
 
                if (string.IsNullOrEmpty(this.UnSelectedImagePath) == false)
                {
                    new System.Threading.Thread(() =>
                    {
                        System.Threading.Thread.Sleep(ControlCommonResourse.StatuChangedWaitTime);
                        Application.RunOnMainThread(() =>
                        {
                            //设置不选择状态
                            this.SetNotSelectStatu();
                        });
                    })
                    { IsBackground = true }.Start();
                }
            }
            else if (string.IsNullOrEmpty(this.Text) == false)
            {
                uint oldColor = this.TextColor;
                //设置选择状态
                this.TextColor = UserCenterColor.Current.SelectTextColor;
                new System.Threading.Thread(() =>
                {
                    System.Threading.Thread.Sleep(ControlCommonResourse.StatuChangedWaitTime);
                    Application.RunOnMainThread(() =>
                    {
                        //设置不选择状态
                        this.TextColor = oldColor;
                    });
                })
                { IsBackground = true }.Start();
            }
        }
 
        /// <summary>
        /// 设置选择的状态
        /// </summary>
        public void SetSelectStatu()
        {
            this.IsSelected = true;
        }
 
        /// <summary>
        /// 设置非选择的状态
        /// </summary>
        public void SetNotSelectStatu()
        {
            Application.RunOnMainThread(() =>
            {
                //设置不选择状态
                this.IsSelected = false;
            });
        }
    }
 
    /// <summary>
    /// 单击按钮类的共通(初始值:拥有点亮功能,白色字体,蓝色背景,文字居中)
    /// </summary>
    public class ClickButtonCommon : ButtonCommon
    {
        /// <summary>
        /// 是否启用点亮功能(默认不启用)
        /// </summary>
        public bool UseClickStatu = false;
        /// <summary>
        /// 原来的背景色
        /// </summary>
        private uint oldBackgroundColor = 0;
 
        /// <summary>
        /// 单击按钮类的共通(初始值:拥有点亮功能,白色字体,蓝色背景,文字居中)
        /// </summary>
        public ClickButtonCommon()
        {
            this.TextColor = UserCenterColor.Current.White;
            this.BackgroundColor = UserCenterColor.Current.ClickButtonColor;
            this.TextAlignment = TextAlignment.Center;
 
            this.MouseDownEventHandler += this.Button_MouseDownEvent;
        }
        /// <summary>
        /// 单击按下事件
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void Button_MouseDownEvent(object sender, MouseEventArgs e)
        {
            if (this.UseClickStatu == false)
            {
                //永久移除
                this.MouseDownEventHandler -= this.Button_MouseDownEvent;
                return;
            }
 
            //设置点击后的状态
            this.SetClickStatu();
 
            new System.Threading.Thread(() =>
            {
                System.Threading.Thread.Sleep(ControlCommonResourse.StatuChangedWaitTime);
                //设置非点击后的状态
                this.SetNotClickStatu();
            })
            { IsBackground = true }.Start();
        }
 
        /// <summary>
        /// 设置点击后的状态
        /// </summary>
        public void SetClickStatu()
        {
            if (this.oldBackgroundColor == 0)
            {
                this.oldBackgroundColor = this.BackgroundColor;
            }
            this.BackgroundColor = UserCenterColor.Current.ButtonClickColor;
        }
 
        /// <summary>
        /// 设置非点击后的状态
        /// </summary>
        public void SetNotClickStatu()
        {
            Application.RunOnMainThread(() =>
            {
                //设置不选择状态
                this.BackgroundColor = oldBackgroundColor;
            });
        }
    }
}