黄学彪
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
using Shared.Phone.UserCenter;
using System;
using System.Collections.Generic;
using System.Text;
 
namespace Shared.Phone.MainPage
{
    /// <summary>
    /// 选择本地设备图片的界面
    /// </summary>
    public class SelectLocalDeviceImageForm : EditorCommonForm
    {
        #region ■ 变量声明___________________________
 
        /// <summary>
        /// 结束选择的事件(图片名字)
        /// </summary>
        public Action<string> FinishSelectEvent = null;
        /// <summary>
        /// 当前选择的图标控件
        /// </summary>
        private PicViewControl selectContr = null;
 
        #endregion
 
        #region ■ 初始化_____________________________
 
        /// <summary>
        /// 画面显示(底层会固定调用此方法,借以完成画面创建)
        /// </summary>
        public void ShowForm()
        {
            //初始化中部信息
            this.InitMiddleFrame();
            //设置头部信息
            base.SetTitleText(Language.StringByID(R.MyInternationalizationString.SelectIcon));
        }
 
        /// <summary>
        /// 初始化中部信息
        /// </summary>
        private void InitMiddleFrame()
        {
            //清空bodyFrame
            this.ClearBodyFrame();
 
            //列表控件
            var listView = new VerticalListControl();
            listView.Height = bodyFrameLayout.Height;
            bodyFrameLayout.AddChidren(listView);
 
            int space = this.GetPictrueRealSize(46);
            int backWidth = (listView.Width - HdlControlResourse.XXLeft * 2 - space * 3) / 4;
            //防止误差,分两步计算
            int iconWidth = backWidth - this.GetPictrueRealSize(43) - this.GetPictrueRealSize(43);
 
            //一共28张图片
            FrameLayout frameRow = null;
            for (int i = 0; i < 28; i++)
            {
                //4个一组
                if (i % 4 == 0)
                {
                    //行控件
                    frameRow = new FrameLayout();
                    frameRow.Height = backWidth + Application.GetRealHeight(58);
                    listView.AddChidren(frameRow);
                }
                //背景
                var frameBack = new FrameLayoutStatuControl();
                frameBack.UseClickStatu = false;
                frameBack.Height = backWidth;
                frameBack.Width = backWidth;
                frameBack.Radius = (uint)backWidth / 2;
                frameBack.BackgroundColor = UserCenterColor.Current.White;
                frameBack.X = HdlControlResourse.XXLeft + (i % 4) * (backWidth + space);
                frameBack.Y = Application.GetRealHeight(58);
                frameRow.AddChidren(frameBack);
 
                //图片
                var btnIcon = new PicViewControl(iconWidth, iconWidth, false);
                btnIcon.UnSelectedImagePath = $"FunctionIcon/{i + 1}Icon.png";
                btnIcon.SelectedImagePath = $"FunctionIcon/{i + 1}IconSelected.png";
                btnIcon.Gravity = Gravity.Center;
                frameBack.AddChidren(btnIcon, ChidrenBindMode.BindEvent);
 
                frameBack.ButtonClickEvent += (sender, e) =>
                {
                    btnIcon.IsSelected = !btnIcon.IsSelected;
                    if (this.selectContr != null && this.selectContr.UnSelectedImagePath != btnIcon.UnSelectedImagePath)
                    {
                        //取消掉前一个
                        this.selectContr.IsSelected = false;
                    }
                    this.selectContr = btnIcon;
                };
            }
 
            //确定
            var btnSave = new BottomClickButton();
            btnSave.TextID = R.MyInternationalizationString.uConfirm1;
            bodyFrameLayout.AddChidren(btnSave);
            btnSave.ButtonClickEvent += (sender, e) =>
            {
                if (this.selectContr != null && this.selectContr.IsSelected == true)
                {
                    //调用回调函数
                    this.FinishSelectEvent?.Invoke(this.selectContr.UnSelectedImagePath);
                }
                this.CloseForm();
            };
 
            //调整桌布高度
            listView.AdjustRealHeightByBottomButton(Application.GetRealHeight(23));
        }
 
        #endregion
 
        #region ■ 界面关闭___________________________
 
        /// <summary>
        /// 界面关闭
        /// </summary>
        public override void CloseFormBefore()
        {
            this.FinishSelectEvent = null;
 
            base.CloseFormBefore();
        }
 
        #endregion
    }
}