黄学彪
2021-01-28 1fcf2302f79f9cbea5ef17c3688311ed65cfabb4
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
using Shared;
using System;
using System.Collections.Generic;
using System.Text;
 
namespace HDL_ON.Stan
{
    /// <summary>
    /// 进度条(圆形)
    /// </summary>
    public class ProgressBar
    {
        /// <summary>
        /// 最大值
        /// </summary>
        private static decimal Max = 100;
        /// <summary>
        /// 当前值
        /// </summary>
        private static decimal m_value = 0;
        /// <summary>
        /// 附加文本
        /// </summary>
        private static string appendText = string.Empty;
        /// <summary>
        /// 转圈的控件
        /// </summary>
        private static Loading waitPage = null;
 
        /// <summary>
        /// 显示进度条
        /// </summary>
        /// <param name="text">初始文本</param>
        public static void Show(string text = "")
        {
            m_value = 0;
            HdlThreadLogic.Current.RunMain(() =>
            {
                if (waitPage == null)
                {
                    //取当前最顶层的界面
                    var frame = MainPage.BasePageView.GetChildren(MainPage.BasePageView.ChildrenCount - 1) as FrameLayout;
                    if (frame != null)
                    {
                        //加载Loading效果
                        waitPage = new Loading();
                        frame.AddChidren(waitPage);
                        waitPage.Start(text);
                    }
                }
            }, ShowErrorMode.NO);
        }
 
        /// <summary>
        /// 隐藏进度条
        /// </summary>
        public static void Close()
        {
            m_value = 0;
            Max = 0;
            HdlThreadLogic.Current.RunMain(() =>
            {
                if (waitPage != null)
                {
                    waitPage.RemoveFromParent();
                    waitPage = null;
                }
            }, ShowErrorMode.NO);
        }
 
        /// <summary>
        /// 进度值设定(数字)
        /// </summary>
        /// <param name="value">Value.</param>
        public static void SetValue(decimal value)
        {
            m_value += value;
            int value2 = (int)((m_value / Max) * 100);
            if (value2 > 100)
            {
                value2 = 100;
            }
 
            SetValue(value2.ToString() + "%");
        }
 
        /// <summary>
        /// 进度值设定
        /// </summary>
        /// <param name="value">Value.</param>
        /// <param name="text">附加值</param>
        public static void SetValue(decimal value, string text)
        {
            m_value += value;
            int value2 = (int)((m_value / Max) * 100);
            if (value2 > 100)
            {
                value2 = 100;
            }
 
            SetValue(value2.ToString() + "% " + text);
        }
 
        /// <summary>
        /// 进度值设定(文本)
        /// </summary>
        /// <param name="text">Text.</param>
        public static void SetValue(string text)
        {
            HdlThreadLogic.Current.RunMain(() =>
            {
                waitPage.Text = text + appendText;
            }, ShowErrorMode.NO);
        }
 
        /// <summary>
        /// 设定进度值最大的值(分母)
        /// </summary>
        /// <param name="maxValue">设定进度值最大的值(分母)</param>
        public static void SetMaxValue(decimal maxValue)
        {
            Max = maxValue;
        }
 
        /// <summary>
        /// 在进度条里面附加自定义文本
        /// </summary>
        /// <param name="i_text"></param>
        public static void SetAppendText(string i_text)
        {
            appendText = i_text;
            if (appendText != string.Empty)
            {
                //多加一个空格
                appendText = " " + appendText;
            }
        }
    }
}