JLChen
2020-06-04 6d55af8792cf8fbef0055e677b900fc352dba9a2
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
using System;
using Shared;
using Shared.SimpleControl.R;
 
namespace Shared.SimpleControl.Phone.Music
{
    class A31WifiPassword : FrameLayout
    {
        public void Show (string pas)
        {
            AddChidren (new Button {
                Height = Application.GetRealHeight (36),
                BackgroundColor = SkinStyle.Current.MusicTopFrameLayout,
            });
 
            var topFrameLayout = new FrameLayout {
                Height = Application.GetRealHeight (90),
                Y = Application.GetRealHeight (36),
                BackgroundColor = SkinStyle.Current.MusicTopFrameLayout,
            };
            AddChidren (topFrameLayout);
 
            var btnTitle = new Button {
                TextColor = SkinStyle.Current.MusicTextColor,
                Text = "WI-FI PASSWORD",
            };
            topFrameLayout.AddChidren (btnTitle);
 
            var back = new Button {
                Width = Application.GetRealWidth (82),
                Height = Application.GetRealHeight (89),
                X = Application.GetRealWidth (10),
                Gravity = Gravity.CenterVertical,
                UnSelectedImagePath = "MusicIcon/HomepageBack.png",
            };
            topFrameLayout.AddChidren (back);
            back.MouseDownEventHandler += (sender, e) => {
                RemoveFromParent ();
            };
 
            var complete = new Button {
                Width = Application.GetRealWidth (110),
                Height = Application.GetRealHeight (100),
                X = Application.GetRealWidth (530),
                Gravity = Gravity.CenterVertical,
                TextID = MyInternationalizationString.complete,
                TextColor = SkinStyle.Current.MusicTextColor,
            };
            topFrameLayout.AddChidren (complete);
 
            var frameLayout = new FrameLayout {
                Y = topFrameLayout.Bottom,
                Height = Application.GetRealHeight (Application.DesignHeight - 126),
                BackgroundColor = SkinStyle.Current.MusicVerticalScrolViewLayout,
            };
            AddChidren (frameLayout);
 
            var flBackgroundColor = new FrameLayout {
                Y = Application.GetRealHeight (100),
                Height = Application.GetRealHeight (80),
                BackgroundColor = SkinStyle.Current.MusicVerticalScrolViewLayout,
                BorderWidth = 1,
                BorderColor = 0xff66e9d8,// SkinStyle.Current.MusicEditBorderColor,
                Radius = 1,
            };
            frameLayout.AddChidren (flBackgroundColor);
 
            var wifipas = new Button {
                Width = Application.GetRealWidth (150),
                Height = Application.GetRealHeight (80),
                X = Application.GetRealWidth (30),
                Gravity = Gravity.CenterVertical,
                TextID = MyInternationalizationString.wifipassword,
                TextColor = SkinStyle.Current.MusicTextColor,
                //Text = "Wi-Fi密码:"
            };
            flBackgroundColor.AddChidren (wifipas);
 
            var username = new EditText {
                Width = Application.GetRealWidth (320),
                Height = Application.GetRealHeight (80),
                X = Application.GetRealWidth (180),
                TextAlignment = TextAlignment.CenterLeft,
                //Radius = (uint)Application.GetRealHeight(6),
                //BackgroundColor = SkinStyle.Current.MusicEditTextBackgroundColor,
                PlaceholderText="Wi-Fi password",
                Text=pas==""? "":pas,
                PlaceholderTextColor = SkinStyle.Current.MusicEditTextPlaceholderTextColor,
                TextColor = SkinStyle.Current.MusicTextColor,
                BorderWidth = 1,
                BorderColor = SkinStyle.Current.MusicEditBorderColor,
                Radius = 1,
            };
            flBackgroundColor.AddChidren (username);
 
            var btndel = new Button {
                Width = Application.GetRealWidth (89),
                Height = Application.GetRealHeight (86),
                X = Application.GetRealWidth (520),
                Gravity = Gravity.CenterVertical,
                UnSelectedImagePath = "MusicIcon/delpas.png",
 
            };
            flBackgroundColor.AddChidren (btndel);
            btndel.MouseUpEventHandler += (sender, e) => {
                username.Text = "";
            };
 
            complete.MouseUpEventHandler += (sender, e) => {
                var textstr = username.Text.Trim ();
                if (textstr != "" && textstr.Length < 8) {
                    //密码长度需要大于8位;
                    new Alert (Language.StringByID (MyInternationalizationString.Tip),
                               Language.StringByID (MyInternationalizationString.passwordlength),
                              Language.StringByID (MyInternationalizationString.Close)).Show ();
                    return;
                }
                MainPage.Loading.Start (Language.StringByID (MyInternationalizationString.load));
                System.Threading.Tasks.Task.Run (() => {
                    if (textstr != "") {
                        openWeb ("http://" + A31MusicModel.Current.IPAddress + "/httpapi.asp?command=setNetwork:1:" + textstr);
                    } else {
                        openWeb ("http://" + A31MusicModel.Current.IPAddress + "/httpapi.asp?command=setNetwork:0:");
                    }
 
                    Application.RunOnMainThread (() => {
                        MainPage.Loading.Hide ();
                        MainPage.MainFrameLayout.RemoveAt (MainPage.MainFrameLayout.ChildrenCount - 1);
                        MainPage.MainFrameLayout.RemoveAt (MainPage.MainFrameLayout.ChildrenCount - 1);
                        MainPage.MainFrameLayout.RemoveAt (MainPage.MainFrameLayout.ChildrenCount - 1);
                        MainPage.MainFrameLayout.RemoveAt (MainPage.MainFrameLayout.ChildrenCount - 1);
                        MainPage.MainFrameLayout.RemoveAt (MainPage.MainFrameLayout.ChildrenCount - 1);
                    });
                });
 
            };
 
            var tiptext = new Button {
                Y = Application.GetRealHeight (115+80),
                Height = Application.GetRealHeight (80),
                Width=Application.GetRealWidth(530),
                X = Application.GetRealWidth (30),
                TextColor = SkinStyle.Current.MusicTextColor,
                TextID = MyInternationalizationString.passwordlength,
                TextAlignment = TextAlignment.CenterLeft,
                //Text="the password must contain at least 8 characters.",
                //密码必须至少包含8个字符。
            };
            frameLayout.AddChidren (tiptext);
 
 
        }
        string openWeb (string url)
        {
            try {
                var webClient = new Shared.Net.MyWebClient (4000);
                return webClient.DownloadString (url);
            } catch (Exception e) {
                System.Console.WriteLine (e.Message);
                return null;
            }
        }
    }
}