wjc
2023-08-09 44d6b49d86f8c531cbed718a8c109f3bc2db2177
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
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
using System;
using HDL_ON.UI.Music;
using Shared;
using System.Collections.Generic;
using HDL_ON.UI.UI2.FuntionControlView.Aks.Entity;
 
namespace HDL_ON.UI.UI2.FuntionControlView.Aks.CommonView
{
    /// <summary>
    /// 自定义圆角容器
    /// </summary>
    public class CornerFramLayout : BaseFramLayout
    {
        private int topMargin;
        private int leftMargin;
        private int bottomMargin;
        private int rightMargin;
        /// <summary>
        /// 一行几个元素
        /// </summary>
        private int mRowNumber;
        /// <summary>
        /// 列表最大值
        /// </summary>
        private int mListCount;
 
        public Action<KeypadEntity> selectAction = null;
        /// <summary>
        /// 当前选择的索引(内部使用)
        /// </summary>
        private int CurrnetSelectIndex = -1;
 
 
        /// <summary>
        /// 
        /// </summary>
        /// <param name="width">容器宽度</param>
        /// <param name="height">容器高度</param>
        ///<param name="rowNumber">圆角值</param>
        public CornerFramLayout(int width, int height, int radius = 0)
        {
            this.BackgroundColor = MusicColor.WhiteColor;
            this.Width = Application.GetRealWidth(width);
            this.Height = Application.GetRealHeight(height);
            this.Radius = (uint)Application.GetRealHeight(radius);
 
 
        }
        /// <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>
        public List<KeypadEntity> GetTestList()
        {
            return AksCommonMethod.Current.GetTYYKeypadList();
        }
 
        /// <summary>
        /// 动态加载按键界面
        /// </summary>
        /// <param name="mList">列表</param>
        /// <param name="mRowNumber">一行多少个元素</param>
        public void LoadButtonPage(List<KeypadEntity> mList, int mRowNumber)
        {
            if (mRowNumber == 0)
            {
                return;
            }
            this.mRowNumber = mRowNumber;
            this.mListCount = mList.Count;
            int line = 0;
            int xCount = 0;
            for (int i = 1; i <= mList.Count; i++)
            {
                var keypad = mList[i - 1];
                ButtonFramLayout buttonFram = new ButtonFramLayout();
                this.AddChidren(buttonFram);
                buttonFram.Tag = keypad;
                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.GetImageButton().UnSelectedImagePath = keypad.localIconAddress;
                buttonFram.GetNameButton().Text = keypad.name;
 
                xCount++;
                if (i % this.mRowNumber == 0)
                {
 
                    line++;
                    xCount = 0;
                }
                buttonFram.SetClickListener((fl, btnIcon, btnName) =>
                {
                    if (buttonFram.Tag != null)
                    {
                        selectAction?.Invoke((KeypadEntity)buttonFram.Tag);
                    }
                });
 
                //if (CurrnetSelectIndex != -1 && CurrnetSelectIndex == i)
                //{
                //    selectAction?.Invoke((int)buttonFram.Tag);
                //}
 
 
            }
        }
 
        /// <summary>
        /// 动态加载按键界面
        /// </summary>
        /// <param name="mList">列表</param>
        /// <param name="list">列表中索引,表示某一条宽度加宽</param>
        public void LoadButtonPage(List<KeypadEntity> mList, List<int> list)
        {
 
            int currnetheightValue = 0;
            int currnetWidthValue = 0;
            //获取相对一个纬度值
            int heightDimensionValue = this.Height - Application.GetRealHeight(this.topMargin) - Application.GetRealHeight(this.bottomMargin) - Application.GetRealHeight(ButtonFramLayout.heightFrameLayout / 2);
            int widthDimensionValue = this.Width - Application.GetRealWidth(this.leftMargin) - Application.GetRealWidth(this.rightMargin) - Application.GetRealHeight(ButtonFramLayout.widthFrameLayout / 2);
            for (int i = 1; i <= mList.Count; i++)
            {
                var keypad = mList[i - 1];
                ButtonFramLayout buttonFram = null;
                if (list.Contains(i))
                {
                    buttonFram = new ButtonFramLayout(ButtonFramLayout.widthFrameLayout * 2);
                    buttonFram.Y = Application.GetRealHeight(this.topMargin) + Application.GetRealHeight(currnetheightValue);
                    buttonFram.X = Application.GetRealWidth(this.leftMargin) + Application.GetRealWidth(currnetWidthValue);
                    currnetWidthValue += ButtonFramLayout.widthFrameLayout * 2;
                }
                else
                {
                    buttonFram = new ButtonFramLayout();
                    buttonFram.Y = Application.GetRealHeight(this.topMargin) + Application.GetRealHeight(currnetheightValue);
                    buttonFram.X = Application.GetRealWidth(this.leftMargin) + Application.GetRealWidth(currnetWidthValue);
                    currnetWidthValue += ButtonFramLayout.widthFrameLayout;
 
                }
 
                this.AddChidren(buttonFram);
                buttonFram.AddImageView();
                buttonFram.AddNameView();
                buttonFram.Tag = keypad;//标记数据
                buttonFram.GetImageButton().UnSelectedImagePath = keypad.localIconAddress;
                buttonFram.GetNameButton().Text = keypad.name;
                if (widthDimensionValue > Application.GetRealWidth(currnetWidthValue))
                {
                    //加右线
                    buttonFram.AddRightLine();
                }
 
                if (heightDimensionValue > buttonFram.Bottom)
                {
                    //加底线
                    buttonFram.AddBottomLine();
                }
 
                if (widthDimensionValue < Application.GetRealWidth(currnetWidthValue))
                {
                    currnetheightValue += ButtonFramLayout.heightFrameLayout;
                    currnetWidthValue = 0;
                }
 
                buttonFram.SetClickListener((fl, btnIcon, btnName) =>
                {
                    if (buttonFram.Tag != null)
                    {
                        selectAction?.Invoke((KeypadEntity)buttonFram.Tag);
                    }
                });
 
                //if (CurrnetSelectIndex != -1 && CurrnetSelectIndex == i)
                //{
                //    selectAction?.Invoke((int)buttonFram.Tag);
                //}
            }
        }
 
        /// <summary>
        ///动态加载数字按键界面
        /// </summary>
        public void LoadNumberButtonPage(List<KeypadEntity> mList)
        {
 
            int currnetheightValue = 0;
            int currnetWidthValue = 0;
            int heightMaxValue = 84;
            int widthMaxValue = 78;
            //获取相对一个纬度值
            int heightDimensionValue = this.Height - Application.GetRealHeight(this.topMargin) - Application.GetRealHeight(this.bottomMargin) - Application.GetRealHeight(heightMaxValue / 2);
            int widthDimensionValue = this.Width - Application.GetRealWidth(this.leftMargin) - Application.GetRealWidth(this.rightMargin) - Application.GetRealHeight(widthMaxValue / 2);
            for (int i = 1; i <= mList.Count; i++)
            {
                var keypad = mList[i - 1];
                Button button = new Button
                {
                    Y = Application.GetRealHeight(this.topMargin) + Application.GetRealHeight(currnetheightValue),
                    X = Application.GetRealWidth(this.leftMargin) + Application.GetRealWidth(currnetWidthValue),
                    Width = Application.GetRealWidth(widthMaxValue),
                    Height = Application.GetRealHeight(heightMaxValue),
                    Text = keypad.name,
                    TextSize = TextSize.Text20,
                    TextColor = MusicColor.TextColor,
                    TextAlignment = TextAlignment.Center,
                    IsBold = true,
                    Tag = keypad,
                    BackgroundColor = MusicColor.WhiteColor,
                    SelectedBackgroundColor = 0xff454635,
                };
                this.AddChidren(button);
 
                currnetWidthValue += widthMaxValue;
                if (widthDimensionValue < Application.GetRealWidth(currnetWidthValue))
                {
                    currnetheightValue += heightMaxValue;
                    currnetWidthValue = 0;
                }
                button.MouseDownEventHandler += (sen, e) =>
                {
                    if (button.Tag == null || ((KeypadEntity)button.Tag).keypad == "none")
                    {
                        return;
                    }
                    button.IsSelected = true;
                    selectAction?.Invoke((KeypadEntity)button.Tag);
                };
                button.MouseUpEventHandler += (sen, e) =>
                {
                    button.IsSelected = false;
                };
 
                //if (CurrnetSelectIndex != -1 && CurrnetSelectIndex == i)
                //{
                //    selectAction?.Invoke((int)buttonFram.Tag);
                //}
            }
        }
 
        /// <summary>
        /// 动态加载图片界面
        /// </summary>
        public void LoadImagePage(List<KeypadEntity> mList)
        {
            int currnetheightValue = 0;
            int currnetWidthValue = 0;
            int heightMaxValue = ImageFramlayout.heightFrameLayout;
            int widthMaxValue = ImageFramlayout.widthFrameLayout;
            //获取相对一个纬度值
            int heightDimensionValue = this.Height - Application.GetRealHeight(this.topMargin) - Application.GetRealHeight(this.bottomMargin) - Application.GetRealHeight(heightMaxValue / 2);
            int widthDimensionValue = this.Width - Application.GetRealWidth(this.leftMargin) - Application.GetRealWidth(this.rightMargin) - Application.GetRealHeight(widthMaxValue / 2);
            for (int i = 1; i <= mList.Count; i++)
            {
                var keypad = mList[i - 1];
                ImageFramlayout imageFram = new ImageFramlayout();
                imageFram.AddView(this);
                imageFram.Tag = keypad;
                imageFram.Y = Application.GetRealHeight(this.topMargin) + Application.GetRealHeight(currnetheightValue);
                imageFram.X = Application.GetRealWidth(currnetWidthValue);
                imageFram.btnName.Text = keypad.name;
                currnetWidthValue += (widthMaxValue + 8);//8是隔间值
                if (widthDimensionValue < Application.GetRealWidth(currnetWidthValue))
                {
                    currnetheightValue += (heightMaxValue + 20);//20是隔间值
                    currnetWidthValue = 0;
                }
 
                imageFram.SetClickListener((fl) =>
                {
                    if (imageFram.Tag != null)
                    {
                        selectAction?.Invoke((KeypadEntity)imageFram.Tag);
                    }
                });
                //if (CurrnetSelectIndex != -1 && CurrnetSelectIndex == i)
                //{
                //    selectAction?.Invoke((int)imageFram.Tag);
                //}
            }
        }
        /// <summary>
        /// 动态加载图片界面
        /// </summary>
        /// <param name="mRowNumber">一行多少个元素</param>
        public void LoadImagePage(List<KeypadEntity> mList, int mRowNumber)
        {
 
            if (mRowNumber == 0)
            {
                return;
            }
            this.mListCount = mList.Count;
            this.mRowNumber = mRowNumber;
            int line = 0;
            int xCount = 0;
            for (int i = 1; i <= mList.Count; i++)
            {
                var keypad = mList[i - 1];
                ImageFramlayout imageFram = new ImageFramlayout();
                imageFram.AddView(this);
                imageFram.Tag = keypad;
                imageFram.Y = Application.GetRealHeight(this.topMargin) + Application.GetRealHeight((ImageFramlayout.heightFrameLayout + 20) * line);
                imageFram.X = Application.GetRealWidth((ImageFramlayout.widthFrameLayout + 8) * xCount);
                imageFram.btnName.Text = keypad.name;
 
                xCount++;
                if (i % this.mRowNumber == 0)
                {
 
                    line++;
                    xCount = 0;
                }
                imageFram.SetClickListener((fl) =>
                {
                    if (imageFram.Tag != null)
                    {
                        selectAction?.Invoke((KeypadEntity)imageFram.Tag);
                    }
                });
 
                //if (CurrnetSelectIndex != -1 && CurrnetSelectIndex == i)
                //{
                //    selectAction?.Invoke((int)imageFram.Tag);
                //}
 
 
            }
        }
        /// <summary> 
        /// 设置初始选择(请在初始化完成之前调用)
        /// </summary>
        /// <param name="index">从列表0开始计算第一个元素,设置超过列表最大(new List().count-1)值视为无效</param>
        public void SetIndex(int index = -1)
        {
            if (index == -1) { return; }
            this.CurrnetSelectIndex = index;
 
        }
        /// <summary>
        /// 最后一行
        /// </summary>
        /// <param name="index">当前索引值</param>
        /// <returns></returns>
        private bool IsLastColumn(int index)
        {
            if (this.mRowNumber == 0 || mListCount == 0)
            {
                return false;
            }
            int lineCount = mListCount / this.mRowNumber;//得出行数
            int number = mListCount % this.mRowNumber;
            if (number != 0)
            {
                if (index > lineCount * this.mRowNumber)
                {
                    return true;
                }
            }
            else
            {
                int value = --lineCount * this.mRowNumber;
                if (index > value)
                {
                    return true;
                }
 
            }
            return false;
        }
        /// <summary>
        /// 最后右边那一个
        /// </summary>
        /// <param name="value"></param>
        /// <returns></returns>
        private bool IsLastRight(int value)
        {
            if (this.mRowNumber == 0)
            {
                return false;
            }
            if (value % this.mRowNumber == 0)
            {
                return true;
            };
            return false;
        }
 
 
        /// <summary>
        /// 重新计算button宽度
        /// </summary>
        /// <param name="button">控件</param>
        /// <param name="widthMax">宽度最大最</param>
        /// <param name="padding">内边距</param>
        private void AdjustRealWidth(Button button, int widthMax = 0, int padding = 0)
        {
            if (button == null)
            {
                return;
            }
            int width;
            if (widthMax == 0)
            {
                //内边距
                width = button.GetTextWidth() + Application.GetRealWidth(padding * 2);
            }
            else
            {
                if (button.GetTextWidth() > Application.GetRealWidth(widthMax))
                {
 
                    button.TextSize = 10;//控件高度不变,改变字体大小,准备换行;
                    width = Application.GetRealWidth(widthMax);
                }
                else
                {
                    width = button.GetTextWidth();
                }
 
            }
 
            button.Width = width;
        }
 
 
 
 
    }
}