wei
2021-02-23 0f5d7d18f98d6d961b3d21dc2b1b59905e261fff
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
using Shared;
using HDL_ON.UI.CSS;
using System;
using System.Collections.Generic;
using System.Text;
 
namespace HDL_ON.Stan
{
    /// <summary>
    /// 电池百分比控件
    /// </summary>
    public class BatteryPersentControl : NormalFrameLayout
    {
        #region ■ 变量声明___________________________
 
        /// <summary>
        /// 电池百分比显示的值
        /// </summary>
        private NormalViewControl btnBatteryView = null;
        /// <summary>
        /// 进度条
        /// </summary>
        private NormalViewControl btnProgress = null;
 
        #endregion
 
        #region ■ 初始化_____________________________
 
        /// <summary>
        /// 电池百分比控件
        /// </summary>
        public BatteryPersentControl()
        {
            //以图片的计算方法计算高度
            this.Height = this.GetPictrueRealSize(25);
            this.Width = this.GetPictrueRealSize(24) + Application.GetRealWidth(30 + 4);
        }
 
        /// <summary>
        /// 初始化控件
        /// </summary>
        public void InitControl()
        {
            var btnIcon = new IconViewControl(24);
            btnIcon.UnSelectedImagePath = "FunctionIcon/Electrical/WeepRobot/Battery.png";
            this.AddChidren(btnIcon);
 
            //电池百分比
            this.btnBatteryView = new NormalViewControl(30, 16, true);
            btnBatteryView.X = btnIcon.Right + Application.GetRealWidth(4);
            btnBatteryView.Y = btnIcon.Y + (btnIcon.Height - Application.GetRealHeight(16)) / 2;
            btnBatteryView.TextSize = CSS_FontSize.PromptFontSize_SecondaryLevel;
            btnBatteryView.TextColor = CSS_Color.PromptingColor1;
            this.AddChidren(btnBatteryView);
 
            //进度条控件
            this.btnProgress = new NormalViewControl(this.GetPictrueRealSize(15), this.GetPictrueRealSize(8), false);
            btnProgress.X = this.GetPictrueRealSize(4);
            btnProgress.Gravity = Gravity.CenterVertical;
            btnProgress.BackgroundColor = CSS_Color.PromptingColor1;
            this.AddChidren(btnProgress);
        }
 
        #endregion
 
        #region ■ 一般方法___________________________
 
        /// <summary>
        /// 百分比值
        /// </summary>
        /// <param name="i_value"></param>
        public void SetValue(decimal i_value)
        {
            int myWidth = (int)((i_value / 100) * this.GetPictrueRealSize(15));
            this.btnBatteryView.Text = i_value + "%";
            this.btnProgress.Width = myWidth;
            if (i_value <= 20)
            {
                if (this.btnProgress.BackgroundColor == CSS_Color.PromptingColor1)
                {
                    //变红色
                    this.btnProgress.BackgroundColor = 0xfff62f48;
                }
            }
            else
            {
                if (this.btnProgress.BackgroundColor == 0xfff62f48)
                {
                    //变红色
                    this.btnProgress.BackgroundColor = CSS_Color.PromptingColor1;
                }
            }
        }
 
        #endregion
    }
}