wjc
2023-07-31 175ace9b4dd6a166285ef8de777c412776cee467
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
using System;
using HDL_ON.UI.Music;
using Shared;
using System.Collections.Generic;
 
namespace HDL_ON.UI.UI2.FuntionControlView.Aks.CommonView
{
    /// <summary>
    /// 自定义圆角容器
    /// </summary>
    public class CornerFramLayout : BaseFramLayout
    {
        public const int cornerValue = 17;
        private int topMargin;
        private int leftMargin;
        private int bottomMargin;
        private int rightMargin;
 
        private int mRowNumber;
 
        private List<int> mList;
 
        public CornerFramLayout(int width, int height)
        {
            this.BackgroundColor = MusicColor.WhiteColor;
            this.Width = Application.GetRealWidth(width);
            this.Height = Application.GetRealHeight(height);
            this.Radius = (uint)Application.GetRealHeight(cornerValue);
 
        }
        /// <summary>
        /// 设置边距
        /// </summary>
        /// <param name="top">上边距</param>
        /// <param name="bottom">下边距</param>
        /// <param name="left">左边距</param>
        /// <param name="right">右边距</param>
        public void SetMargin(int top, int bottom, int left, int right)
        {
            this.topMargin = top;
            this.bottomMargin = bottom;
            this.leftMargin = left;
            this.rightMargin = right;
        }
 
        /// <summary>
        /// 设置列表数据
        /// </summary>
        /// <param name="list"></param>
        public void SetList(List<int> list)
        {
            if (list == null)
            {
                list = new List<int>();
            }
            this.mList = list;
        }
 
        /// <summary>
        /// 获取测试列表数据
        /// </summary>
        public List<int> GetTestList(int count)
        {
            var list = new List<int>();
            for (int i = 1; i <= count; i++)
            {
                list.Add(i);
            }
            return list;
        }
 
        /// <summary>
        /// 加载按键界面
        /// </summary>
        /// <param name="rowNumber">一行几个元素</param>
        /// <param name="action">回调</param>
        public void LoadButtonPage(int rowNumber, Action<int> action) 
        {
            if (rowNumber == 0)
            {
                return;
            }
            this.mRowNumber = rowNumber;
            int line = 0;
            int xCount = 0;
            for (int i = 1; i <= this.mList.Count; i++)
            {
                ButtonFramLayout buttonFram = new ButtonFramLayout();
                this.AddChidren(buttonFram);
                buttonFram.Tag = i - 1;
                buttonFram.Y = Application.GetRealHeight(this.topMargin) + Application.GetRealHeight(ButtonFramLayout.heightFrameLayout * line);
                buttonFram.X = Application.GetRealWidth(this.leftMargin) + Application.GetRealWidth(ButtonFramLayout.widthFrameLayout * xCount);
                buttonFram.AddImageView();
                buttonFram.AddNameView();
                if (!IsLastRight(i))
                {
                    buttonFram.AddRightLine();
                }
                if (!IsLastColumn(i))
                {
                    buttonFram.AddBottomLine();
                }
                buttonFram.GetNameButton().Text = i.ToString();
 
                xCount++;
                if (i % rowNumber == 0)
                {
 
                    line++;
                    xCount = 0;
                }
                buttonFram.SetClickListener((fl, btnIcon, btnName) =>
                {
                    action.Invoke((int)buttonFram.Tag);
                });
 
 
            }
            //this.AdjustRealHeight(this.bottomMargin);
        }
 
        /// <summary>
        /// 最后一行
        /// </summary>
        /// <param name="value"></param>
        /// <returns></returns>
        private bool IsLastColumn(int value)
        {
            int lineCount = this.mList.Count / this.mRowNumber;
            int number = this.mList.Count % this.mRowNumber;
            if (number != 0)
            {
                if (value > lineCount * this.mRowNumber)
                {
                    return true;
                }
            }
            else
            {
                if (value > lineCount-- * this.mRowNumber)
                {
                    return true;
                }
 
            }
            return false;
 
        }
        /// <summary>
        /// 最后右边那一个
        /// </summary>
        /// <param name="value"></param>
        /// <returns></returns>
        private bool IsLastRight(int value)
        {
            if (value % this.mRowNumber == 0)
            {
                return true;
            };
            return false;
        }
    }
}