|
using System;
|
using Shared.IO;
|
using Shared.Net;
|
using System.Text;
|
using System.Collections.Generic;
|
// <summary>
|
// 程序主入口
|
// </summary>
|
//using SystemConfiguration;
|
using System.Net;
|
using System.IO;
|
using Shared.SimpleControl.Phone;
|
namespace Shared.SimpleControl
|
{
|
/// <summary>
|
/// 主页面
|
/// </summary>
|
public static class MainPage
|
{
|
/// <summary>
|
/// 主页面,根界面
|
/// </summary>
|
public static FrameLayout MainFrameLayout { get; internal set; }
|
public static bool Showed;
|
|
static Loading loading;
|
/// <summary>
|
/// 显示加载界面
|
/// </summary>
|
public static Loading Loading {
|
get {
|
if (loading == null) {
|
loading = new Loading ();
|
}
|
return loading;
|
}
|
}
|
|
//public static Button LogoButton = new Button ();
|
|
public static string CodeIDString = "20220112";
|
public static UserInfo LoginUser;
|
|
|
public static string SoftPadTitle = "Crabtree";
|
public static string SoftTitle = "Crabtree";
|
public static int SoftSmsType = 0;
|
public static string LogoString = "";//"Logo/Logo.png";
|
public static string WiFiStatus = "CrabtreeAdd/WiFi.png";//"CrabtreeAdd/WiFi.png";
|
public static string RegisterLogoString = "Logo/Register_logo.png";
|
public static string SeviceIP = "52.172.25.151";
|
public static string RequestHttpsHost = "https://homeautomation.havells.com";
|
|
public static double PixelScale {
|
get {
|
#if __IOS__
|
switch (Application.PhoneType) {
|
case 3:
|
case 4:
|
case 5:
|
case 6:
|
case 7:
|
case 8:
|
case 9:
|
return 1.0;
|
case 10:
|
return 1.1;
|
case 11:
|
case 12:
|
return 1.2;
|
//case 13:
|
// return 1.3;
|
}
|
var widthScale = Application.CurrentWidth / 640.0f;
|
var heightScale = Application.CurrentHeight / 1136.0f;
|
|
var scale = Math.Round (System.Math.Abs (widthScale - heightScale), 2);
|
|
return scale + 1;
|
#else
|
return 1;
|
#endif
|
}
|
}
|
|
/// <summary>
|
/// 显示当前界面
|
/// </summary>
|
public static void Show ()
|
{
|
try {
|
Showed = true;
|
UserConfig.Instance.SkinCode = 1;
|
if (Shared.Application.IsPad) {
|
Application.DesignWidth = 2048;
|
Application.DesignHeight = 1536;
|
} else {
|
Application.DesignWidth = 640;
|
Application.DesignHeight = 1136;
|
}
|
Shared.BusSocket.Start (6000);
|
CommonPage.InitReceiveEvent ();
|
|
MainFrameLayout = Application.MainPage;
|
MainFrameLayout.AddChidren (Loading);
|
if (Shared.Application.IsPad) {
|
//Pad.UserHomePage.Init ();
|
} else {
|
Phone.UserHomePage.Init ();
|
//#if __IOS__
|
// //Loading.LodingBackgroundColor = 0x10777777;
|
//#else
|
// Loading.LodingBackgroundColor = SkinStyle.Current.MainColor;
|
//#endif
|
|
Loading.TextColor = 0xFFA9A9A9;
|
Loading.LodingBackgroundColor = SkinStyle.Current.MainColor;
|
}
|
} catch (Exception ex) {
|
//new Alert ("Eorr", ex.Message, "Close").Show();
|
}
|
}
|
|
|
/// <summary>
|
/// 增加rjfi
|
/// </summary>
|
/// <param name="tip">Tip.</param>
|
/// <param name="time">Time.</param>
|
public static void AddTip (string tip, int time = 2000)
|
{
|
if (MainFrameLayout == null) {
|
return;
|
}
|
Application.RunOnMainThread (() => {
|
var button = new TextView {
|
Gravity = Gravity.Center,
|
Width = Application.GetRealWidth (560),
|
Height = Application.GetRealHeight (126),
|
BackgroundColor = SkinStyle.Current.AddTipButtonColor,
|
Radius = 10,
|
IsMoreLines = true,
|
Text = tip,
|
TextSize = 16,
|
};
|
MainFrameLayout.AddChidren (button);
|
button.MouseUpEventHandler += (sender, e) => {
|
button.RemoveFromParent ();
|
};
|
System.Threading.Tasks.Task.Run (() => {
|
System.Threading.Thread.Sleep (time);
|
Application.RunOnMainThread (() => {
|
button.RemoveFromParent ();
|
});
|
});
|
});
|
}
|
|
static DateTime requesTime = DateTime.MinValue;
|
static bool isShowLoading = true;
|
/// <summary>
|
/// 请求服务器方法
|
/// </summary>
|
/// <returns>The https.</returns>
|
/// <param name="methodType">请求方法.</param>
|
/// <param name="dataStringJson">请求的参数.</param>
|
/// <param name="needHeaders">是否需要包头.</param>
|
public static ResponsePack RequestHttps (string methodType, string dataStringJson, bool needHeaders = true, bool needTip = true,string urlHead = "")
|
{
|
ResponsePack revertObj = null;
|
try {
|
if (!SystemRemote.checeInternet ()) {
|
Application.RunOnMainThread (() => {
|
MainPage.WiFiStatus = "CrabtreeAdd/WiFiUnlink.png";
|
MainPage.Loading.Hide ();
|
});
|
}
|
//new System.Threading.Thread (() => {
|
// requesTime = DateTime.Now;
|
// isShowLoading = true;
|
// while (isShowLoading) {
|
// System.Threading.Thread.Sleep (1000);
|
// if (requesTime == DateTime.MinValue) {
|
// break;
|
// }
|
// if (requesTime.AddSeconds (30) < DateTime.Now) {
|
// Application.RunOnMainThread (Loading.Hide);
|
// isShowLoading = false;
|
// }
|
// }
|
//}) { IsBackground = true }.Start ();
|
|
|
#region
|
var webClient = new WebClient ();
|
if (urlHead == "") {
|
urlHead = $"{"https://homeautomation.havells.com"}/WebApi/";
|
} else {
|
webClient.Headers.Add ("CONTENT-TYPE", "application/json");
|
}
|
string url = urlHead + methodType;
|
if (needHeaders && LoginUser != null) {/* 如果不需要验证Token可以不用传入 */
|
webClient.Headers.Add ("Authorization", LoginUser.LoginTokenString);
|
}
|
byte [] bytes = null;
|
try {
|
bytes = webClient.UploadData (url, Encoding.UTF8.GetBytes (dataStringJson));
|
} catch (System.Net.WebException webEx) {
|
Application.RunOnMainThread (() => {
|
MainPage.Loading.Hide ();
|
revertObj = new ResponsePack () { StateCode = "Network_Error" };
|
//new Alert ( "","Network abnormal, unable to connect to the Internet", Language.StringByID (R.MyInternationalizationString.Close)).Show ();
|
return;
|
});
|
}
|
string responseString = null;
|
if (bytes != null) {
|
responseString = Encoding.UTF8.GetString (bytes);
|
}
|
|
//var request = (HttpWebRequest)WebRequest.Create (url);
|
//var data = Encoding.UTF8.GetBytes (dataStringJson);
|
//request.Method = "POST";
|
//request.ContentLength = data.Length;
|
//if (needHeaders) {/* 如果不需要验证Token可以不用传入 */
|
// request.Headers.Set (HttpRequestHeader.Authorization, LoginUser.LoginTokenString);
|
//}
|
//using (var stream = request.GetRequestStream ()) {
|
// stream.Write (data, 0, data.Length);
|
//}
|
//var response = (HttpWebResponse)request.GetResponse ();
|
//var responseString = new StreamReader (response.GetResponseStream ()).ReadToEnd ();
|
|
if (responseString != null) {
|
try {
|
revertObj = Newtonsoft.Json.JsonConvert.DeserializeObject<ResponsePack> (responseString);
|
if (revertObj.StateCode != "SUCCESS") {
|
if (methodType == "IsExistingAccount") {
|
|
} else if (needTip) {
|
Application.RunOnMainThread (() => {
|
new Alert ("", revertObj.ErrorInfo, Language.StringByID (R.MyInternationalizationString.Close)).Show ();
|
});
|
}
|
}
|
} catch (Exception ex) {
|
Console.WriteLine (ex.ToString ());
|
}
|
} else {
|
if (methodType == "Login" && needTip) {
|
Application.RunOnMainThread (() => {
|
new Alert ("", Language.StringByID (R.MyInternationalizationString.FailureToDataBase),
|
Language.StringByID (R.MyInternationalizationString.Close)).Show ();
|
});
|
} else {
|
if (needTip)
|
FailureToServer ();
|
}
|
}
|
return revertObj;
|
#endregion
|
} catch (Exception ex) {
|
Console.WriteLine (ex.Message);
|
return revertObj;
|
} finally {
|
//requesTime = requesTime.AddDays(1);
|
}
|
}
|
/// <summary>
|
/// 连接服务器失败
|
/// </summary>
|
public static void FailureToServer ()
|
{
|
Application.RunOnMainThread (() => {
|
new Alert ("", Language.StringByID (R.MyInternationalizationString.FailureToServer),
|
Language.StringByID (R.MyInternationalizationString.Close)).Show ();
|
});
|
}
|
|
/// <summary>
|
/// 设备不在线,无响应
|
/// </summary>
|
public static void DeviceNotOnline ()
|
{
|
Application.RunOnMainThread (() => {
|
new Alert ("", Language.StringByID (R.MyInternationalizationString.TipEquipmentNotOnline), Language.StringByID (R.MyInternationalizationString.Close)).Show ();
|
MainPage.Loading.Hide ();
|
});
|
}
|
|
public static void LoadingStart (string showString = "")
|
{
|
Application.RunOnMainThread (() => {
|
MainPage.Loading.Start (showString);
|
});
|
}
|
|
public static void LoadingHide ()
|
{
|
Application.RunOnMainThread (() => {
|
MainPage.Loading.Hide ();
|
});
|
}
|
}
|
}
|