黄学彪
2019-12-17 5986f63b75bd81c6cef262c670e9251c038cbf5d
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
using System;
using System.Collections.Generic;
using System.Text;
 
namespace Shared.Phone.UserCenter
{
    /// <summary>
    /// 界面类型的进度条控件
    /// </summary>
    public class ProgressFormBar
    {
        #region ■ 变量声明___________________________
 
        /// <summary>
        /// 界面类型的进度条控件
        /// </summary>
        private static ProgressFormBar m_Current = null;
        /// <summary>
        /// 界面类型的进度条控件
        /// </summary>
        public static ProgressFormBar Current
        {
            get
            {
                if (m_Current == null)
                {
                    m_Current = new ProgressFormBar();
                }
                return m_Current;
            }
        }
        /// <summary>
        /// 消息控件单击的事件
        /// </summary>
        public Action MsgClickEvent = null;
        /// <summary>
        /// 界面关闭的事件
        /// </summary>
        public Action CloseEvent = null;
        /// <summary>
        /// 容器控件
        /// </summary>
        private FrameLayout bodyFrameLayout = null;
        /// <summary>
        /// 信息控件
        /// </summary>
        private NormalViewControl btnText = null;
        /// <summary>
        /// 进度值文本的显示控件
        /// </summary>
        private NormalViewControl btnProgressView = null;
        /// <summary>
        /// 进度值能够移动的那个框控件
        /// </summary>
        private FrameLayout frameProgress = null;
        /// <summary>
        /// 进度条
        /// </summary>
        private FrameLayout btnProgressBar = null;
        /// <summary>
        /// 进度条容器的最大宽度
        /// </summary>
        private int ProRowWidth = 0;
        /// <summary>
        /// 原来的滑动标识
        /// </summary>
        private bool oldScrollEnabled = false;
        /// <summary>
        /// 原来的那个圆形进度条是否可见
        /// </summary>
        private bool oldPrigressVisible = false;
 
        #endregion
 
        #region ■ 初始化_____________________________
 
        /// <summary>
        /// 初始化进度条
        /// </summary>
        private void InitProgressFormBar()
        {
            //安卓可以点击系统的返回键
            this.oldScrollEnabled = UserView.HomePage.Instance.ScrollEnabled;
            UserView.HomePage.Instance.ScrollEnabled = false;
            Shared.Common.CommonPage.BackKeyCanClick = false;
 
            this.oldPrigressVisible = Common.CommonPage.Loading.Visible;
            if (oldPrigressVisible == true)
            {
                //圆形进度条临时关闭
                Common.CommonPage.Loading.Hide();
            }
 
            //容器
            bodyFrameLayout = new FrameLayout();
            bodyFrameLayout.BackgroundColor = UserCenterColor.Current.DialogBackColor;
            Common.CommonPage.Instance.AddChidren(bodyFrameLayout);
 
            var frameBack = new FrameLayout();
            frameBack.Width = Application.GetRealWidth(674);
            frameBack.Height = Application.GetRealHeight(386);
            frameBack.BackgroundColor = UserCenterColor.Current.White;
            frameBack.Gravity = Gravity.CenterHorizontal;
            frameBack.Y = Application.GetRealHeight(683);
            frameBack.Radius = (uint)Application.GetRealHeight(17);
            bodyFrameLayout.AddChidren(frameBack);
 
            //进度显示文本
            this.btnText = new NormalViewControl(frameBack.Width, Application.GetRealHeight(58), false);
            btnText.Y = Application.GetRealHeight(248);
            btnText.TextColor = UserCenterColor.Current.TextGrayColor1;
            btnText.TextAlignment = TextAlignment.Center;
            frameBack.AddChidren(btnText);
            btnText.ButtonClickEvent += (sender, e) =>
            {
                this.MsgClickEvent?.Invoke();
            };
 
            //进度条
            var btnProRow = new FrameLayout();
            btnProRow.Gravity = Gravity.CenterHorizontal;
            btnProRow.Y = Application.GetRealHeight(161);
            btnProRow.Width = Application.GetRealWidth(559);
            btnProRow.Height = Application.GetRealHeight(29);
            btnProRow.BackgroundColor = 0xfff5f5f5;
            btnProRow.Radius = (uint)Application.GetRealHeight(29) / 2;
            frameBack.AddChidren(btnProRow);
            this.btnProgressBar = new FrameLayout();
            btnProgressBar.Width = 0;
            btnProgressBar.Height = btnProRow.Height;
            btnProgressBar.BackgroundColor = 0xfffb744a;
            btnProgressBar.Radius = (uint)Application.GetRealHeight(29) / 2;
            btnProRow.AddChidren(btnProgressBar);
 
            //进度值文本
            this.frameProgress = new FrameLayout();
            frameProgress.Width = Application.GetRealWidth(84);
            frameProgress.Height = Application.GetRealHeight(60);
            frameProgress.Y = Application.GetRealHeight(86);
            frameBack.AddChidren(frameProgress);
            frameProgress.X = btnProRow.X + btnProgressBar.Right - frameProgress.Width / 2;
            var btnProgressPic = new PicViewControl(84, 60);
            btnProgressPic.UnSelectedImagePath = "Item/ProgressMsg.png";
            frameProgress.AddChidren(btnProgressPic);
            this.btnProgressView = new NormalViewControl(84, 45, true);
            btnProgressView.TextSize = 10;
            btnProgressView.TextAlignment = TextAlignment.Center;
            btnProgressView.Text = "0%";
            frameProgress.AddChidren(btnProgressView);
 
            this.ProRowWidth = btnProRow.Width;
        }
 
        #endregion
 
        #region ■ 设置信息___________________________
 
        /// <summary>
        /// 设置显示信息
        /// </summary>
        /// <param name="msg"></param>
        public void SetMsg(string msg)
        {
            HdlThreadLogic.Current.RunMain(() =>
            {
                btnText.Text = msg;
            });
        }
 
        #endregion
 
        #region ■ 设置进度值_________________________
 
        /// <summary>
        /// 设置进度值
        /// </summary>
        /// <param name="value">此值为百分比值(也就是小于或者等于1的)</param>
        public void SetValue(decimal value)
        {
            this.SetValueEx(value);
        }
 
        /// <summary>
        /// 设置进度值
        /// </summary>
        /// <param name="value">进度值,内部会除以maxValue</param>
        /// <param name="maxValue">最大值</param>
        public void SetValue(decimal value, decimal maxValue)
        {
            decimal result = value / maxValue;
            this.SetValueEx(result);
        }
 
        /// <summary>
        /// 设置进度值
        /// </summary>
        /// <param name="value"></param>
        private void SetValueEx(decimal value)
        {
            if (btnProgressBar == null)
            {
                return;
            }
            HdlThreadLogic.Current.RunMain(() =>
            {
                int width = (int)(value * ProRowWidth);
                btnProgressBar.Width = width;
                //文本显示
                btnProgressView.Text = ((int)(value * 100)) + "%";
                //文本显示的那个图片框移动
                frameProgress.X = ControlCommonResourse.XXLeft + btnProgressBar.Right - frameProgress.Width / 2;
            });
        }
 
        #endregion
 
        #region ■ 开启进度条_________________________
 
        /// <summary>
        /// 开启进度条
        /// </summary>
        public void Start()
        {
            if (this.bodyFrameLayout == null)
            {
                HdlThreadLogic.Current.RunMain(() =>
                {
                    //初始化进度条
                    this.InitProgressFormBar();
                });
            }
        }
 
        #endregion
 
        #region ■ 关闭进度条_________________________
 
        /// <summary>
        /// 关闭进度条
        /// </summary>
        public void Close()
        {
            HdlThreadLogic.Current.RunMain(() =>
            {
                if (this.oldScrollEnabled == true)
                {
                    //如果它原来就是不可以滑动的话,不处理
                    UserView.HomePage.Instance.ScrollEnabled = true;
                }
                Shared.Common.CommonPage.BackKeyCanClick = true;
                if (this.oldPrigressVisible == true)
                {
                    //如果原来的进度条是可见的话,还原回去
                    Common.CommonPage.Loading.Start(Common.CommonPage.Loading.Text);
                }
 
                bodyFrameLayout?.RemoveFromParent();
                bodyFrameLayout = null;
                btnText = null;
                btnProgressView = null;
                frameProgress = null;
                btnProgressBar = null;
                this.MsgClickEvent = null;
                //关闭事件
                this.CloseEvent?.Invoke();
                this.CloseEvent = null;
            });
        }
 
        #endregion
    }
}