黄学彪
2020-12-16 0d9f64668fd7350d6a21fd157e32009a96d98134
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
using System;
using System.Collections.Generic;
using System.Text;
 
namespace Shared.Phone
{
    /// <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 btnTitle = null;
        /// <summary>
        /// 进度条控件
        /// </summary>
        private ProgressRowBar btnProgressBar = null;
        /// <summary>
        /// 原来的滑动标识
        /// </summary>
        private bool oldScrollEnabled = false;
        /// <summary>
        /// 原来的那个圆形进度条是否可见
        /// </summary>
        private bool oldPrigressVisible = false;
 
        #endregion
 
        #region ■ 初始化_____________________________
 
        /// <summary>
        /// 初始化进度条
        /// </summary>
        private void InitProgressFormBar(bool i_hadTitle)
        {
            //拥有标题时,扩大的高度
            int titleValue = 40;
 
            //安卓可以点击系统的返回键
            this.oldScrollEnabled = UserView.HomePage.Instance.ScrollEnabled;
            UserView.HomePage.Instance.ScrollEnabled = false;
            Common.Config.Instance.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();
            if (i_hadTitle == false)
            {
                frameBack.Y = Application.GetRealHeight(683);
                frameBack.Height = Application.GetRealHeight(386);
            }
            else
            {
                frameBack.Y = Application.GetRealHeight(683 + titleValue / 2);
                frameBack.Height = Application.GetRealHeight(386 + titleValue);
            }
            frameBack.Width = Application.GetRealWidth(674);
            frameBack.BackgroundColor = UserCenterColor.Current.White;
            frameBack.Gravity = Gravity.CenterHorizontal;
            frameBack.Radius = (uint)Application.GetRealHeight(17);
            bodyFrameLayout.AddChidren(frameBack);
 
            //进度显示文本
            this.btnTitle = new NormalViewControl(frameBack.Width, Application.GetRealHeight(58), false);
            btnTitle.Y = Application.GetRealHeight(40);
            btnTitle.TextColor = UserCenterColor.Current.TextGrayColor1;
            btnTitle.TextAlignment = TextAlignment.Center;
            frameBack.AddChidren(btnTitle);
 
            //进度显示文本
            this.btnText = new NormalViewControl(frameBack.Width, Application.GetRealHeight(58), false);
            if (i_hadTitle == false)
            {
                btnText.Y = Application.GetRealHeight(248);
            }
            else
            {
                btnText.Y = Application.GetRealHeight(248 + titleValue);
            }
            btnText.TextColor = UserCenterColor.Current.TextGrayColor1;
            btnText.TextAlignment = TextAlignment.Center;
            frameBack.AddChidren(btnText);
            btnText.ButtonClickEvent += (sender, e) =>
            {
                this.MsgClickEvent?.Invoke();
            };
 
            //进度条
            this.btnProgressBar = new ProgressRowBar(559, 29);
            btnProgressBar.Gravity = Gravity.CenterHorizontal;
            if (i_hadTitle == false)
            {
                btnProgressBar.Y = Application.GetRealHeight(161);
            }
            else
            {
                btnProgressBar.Y = Application.GetRealHeight(161 + titleValue);
            }
            frameBack.AddChidren(btnProgressBar);
            btnProgressBar.StartMode1(true);
        }
 
        #endregion
 
        #region ■ 设置信息___________________________
 
        /// <summary>
        /// 设置显示信息
        /// </summary>
        /// <param name="msg"></param>
        public void SetMsg(string msg)
        {
            HdlThreadLogic.Current.RunMain(() =>
            {
                btnText.Text = msg;
            }, ShowErrorMode.NO);
        }
 
        /// <summary>
        /// 设置标题信息
        /// </summary>
        /// <param name="i_title"></param>
        public void SetTitle(string i_title)
        {
            HdlThreadLogic.Current.RunMain(() =>
            {
                btnTitle.Text = i_title;
            }, ShowErrorMode.NO);
        }
 
        #endregion
 
        #region ■ 设置进度值_________________________
 
        /// <summary>
        /// 设置进度值
        /// </summary>
        /// <param name="value">此值为百分比值(也就是小于或者等于1的)</param>
        public void SetValue(decimal value)
        {
            this.btnProgressBar?.SetValue(value);
        }
 
        /// <summary>
        /// 设置进度值
        /// </summary>
        /// <param name="value">进度值,内部会除以maxValue</param>
        /// <param name="maxValue">最大值</param>
        public void SetValue(decimal value, decimal maxValue)
        {
            this.btnProgressBar?.SetValue(value, maxValue);
        }
 
        /// <summary>
        /// 重置进度条,让它复位
        /// </summary>
        public void ResetProgressBar()
        {
            if (this.btnProgressBar != null)
            {
                btnProgressBar.ProgressBarGoback = true;
                btnProgressBar.SetValue(0);
 
                System.Threading.Thread.Sleep(500);
 
                btnProgressBar.ProgressBarGoback = false;
            }
        }
 
        #endregion
 
        #region ■ 开启进度条_________________________
 
        /// <summary>
        /// 开启进度条
        /// </summary>
        /// <param name="i_hadTitle">是否拥有标题</param>
        public void Start(bool i_hadTitle = false)
        {
            if (this.bodyFrameLayout == null)
            {
                HdlThreadLogic.Current.RunMain(() =>
                {
                    //初始化进度条
                    this.InitProgressFormBar(i_hadTitle);
                }, ShowErrorMode.NO);
            }
        }
 
        #endregion
 
        #region ■ 关闭进度条_________________________
 
        /// <summary>
        /// 关闭进度条
        /// </summary>
        public void Close()
        {
            HdlThreadLogic.Current.RunMain(() =>
            {
                if (this.oldScrollEnabled == true)
                {
                    //如果它原来就是不可以滑动的话,不处理
                    UserView.HomePage.Instance.ScrollEnabled = true;
                }
                Common.Config.Instance.BackKeyCanClick = true;
                if (this.oldPrigressVisible == true)
                {
                    //如果原来的进度条是可见的话,还原回去
                    Common.CommonPage.Loading.Start(Common.CommonPage.Loading.Text);
                }
 
                bodyFrameLayout?.RemoveFromParent();
                bodyFrameLayout = null;
                btnText = null;
                btnProgressBar = null;
                this.MsgClickEvent = null;
                //关闭事件
                this.CloseEvent?.Invoke();
                this.CloseEvent = null;
            }, ShowErrorMode.NO);
        }
 
        #endregion
    }
}