|
using System;
|
using System.Text;
|
using System.Collections.Generic;
|
using System.Net;
|
using System.IO;
|
using Shared.SimpleControl.Phone;
|
// <summary>
|
// 程序主入口
|
// </summary>
|
//using SystemConfiguration;
|
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 RequestVersion = "2.701111";
|
public static UserInfo LoginUser;
|
/// <summary>
|
/// 是否是管理员权限(变更了,成员的时候,这个也为ture。为什么会声明这样变量,因为有些接口必须使用原来的Token)
|
/// </summary>
|
public static bool IsAdministrator {
|
get {
|
if (UserConfig.Instance == null || UserConfig.Instance.CurrentRegion == null) {
|
return false;
|
} else {
|
return UserConfig.Instance.CurrentRegion.IsOthreShare;
|
}
|
}
|
}
|
|
///// <summary>
|
///// 是否账号在其它设备登录了
|
///// </summary>
|
//public static bool IsOtherDevicesLogin = false;
|
|
//#if __IOS__
|
// public static readonly string PhoneType = "iOS";
|
//#else
|
// public static readonly string PhoneType = "Android";
|
//#endif
|
|
public static string SoftPadTitle = "Crabtree";
|
public static string SoftTitle = "Crabtree";
|
public static int SoftSmsType = 0;
|
public static string RequestSource = "1"; //0:Zigbee、1:HdlOn、2:GraphicsMonitor、3:BusproSoft、4:AgentWeb
|
|
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";
|
|
|
#region GetDesignHeight
|
/// <summary>
|
/// 获取view的计算高度,ON软件为了适配全面特殊使用的比例方法,由于一些背景图片是直接全部填充的,改动成三层的(view-button-button)的工作量很大,不禁需要增加一个view,还需要修改图片
|
/// </summary>
|
/// <returns>The view height.</returns>
|
public static int GetDesignHeight (int height)
|
{
|
int ss = Convert.ToInt32 (height / PixelScale);
|
return Application.GetRealHeight (ss);
|
}
|
#endregion
|
|
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;
|
}
|
//印度客户定制APP默认使用英文
|
Language.CurrentLanguage = "English";
|
|
|
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;
|
}
|
|
CommonUtlis.Current.CheckIfJailBreak ();
|
|
} catch (Exception ex) {
|
//new Alert ("Eorr", ex.Message, "Close").Show();
|
}
|
}
|
|
|
/// <summary>
|
/// 弹出错误提示
|
/// </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,
|
BackgroundColor = SkinStyle.Current.MainColor,
|
Radius = 10,
|
IsMoreLines = true,
|
Text = tip,
|
TextSize = 16,
|
TextColor = 0xFF000000
|
};
|
MainFrameLayout.AddChidren (button);
|
button.MouseUpEventHandler += (sender, e) => {
|
button.RemoveFromParent ();
|
};
|
System.Threading.Tasks.Task.Run (() => {
|
System.Threading.Thread.Sleep (time);
|
Application.RunOnMainThread (() => {
|
button.RemoveFromParent ();
|
});
|
});
|
});
|
}
|
|
|
|
#region LoadingTipMsg 远程连接Tip
|
|
static Button btnLoadingTipMsg;
|
|
public static void LoadingTipShow (string tip)
|
{
|
|
if (MainFrameLayout == null) {
|
return;
|
}
|
|
Application.RunOnMainThread (() => {
|
try {
|
if (btnLoadingTipMsg == null) {
|
btnLoadingTipMsg = new Button () {
|
Height = Application.GetRealHeight (90),
|
BackgroundColor = SkinStyle.Current.MainColor,
|
//BackgroundColor = 0xFF000000,
|
Y = Application.GetRealHeight (36),
|
TextAlignment = TextAlignment.Center,
|
TextColor = 0xFF000000,
|
};
|
}
|
if (btnLoadingTipMsg.Parent == null) {
|
MainFrameLayout.AddChidren (btnLoadingTipMsg);
|
if (btnLoadingTipMsg.MouseUpEventHandler == null) {
|
btnLoadingTipMsg.MouseUpEventHandler += (sender, e) => {
|
if (btnLoadingTipMsg.Parent != null)
|
btnLoadingTipMsg.RemoveFromParent ();
|
};
|
}
|
}
|
|
btnLoadingTipMsg.Text = tip;
|
|
} catch { }
|
});
|
}
|
|
public static void LoadingTipHide ()
|
{
|
if (MainFrameLayout == null) {
|
return;
|
}
|
Application.RunOnMainThread (() => {
|
try {
|
if (btnLoadingTipMsg != null) {
|
if (btnLoadingTipMsg.Parent != null)
|
btnLoadingTipMsg.RemoveFromParent ();
|
}
|
|
} catch { }
|
});
|
}
|
|
#endregion
|
|
/// <summary>
|
/// 连接服务器失败
|
/// </summary>
|
public static void FailureToServer ()
|
{
|
//Application.RunOnMainThread (() => {
|
// new Alert ("", Language.StringByID (R.MyInternationalizationString.FailureToServer),
|
// Language.StringByID (R.MyInternationalizationString.Close)).Show ();
|
//});
|
ShowAlertOnMainThread (ErrorCode.FailedRequestServer);
|
}
|
|
/// <summary>
|
/// 2020-01-11 弹窗提示
|
/// </summary>
|
/// <param name="mes"></param>
|
public static void ShowAlertOnMainThread (string mes)
|
{
|
Application.RunOnMainThread (() => {
|
new Alert ("", mes, 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 LoadingSetText (string showString = "")
|
{
|
Application.RunOnMainThread (() => {
|
MainPage.Loading.Text = showString;
|
});
|
}
|
|
public static void LoadingHide ()
|
{
|
Application.RunOnMainThread (() => {
|
MainPage.Loading.Hide ();
|
});
|
}
|
|
|
|
}
|
}
|