using System;
|
using Android.App;
|
using Android.Content;
|
using Android.OS;
|
//using CN.Jpush.Android.Api;
|
//using CN.Jpush.Android.Service;
|
|
using Shared;
|
using Shared.SimpleControl;
|
using SmartHome;
|
|
|
namespace SharedMethod
|
{
|
public static class SharedMethod
|
{
|
//public static UIApplication sharedApp;
|
public static void ChangeSkin ()
|
{
|
//if (UserConfig.Instance.SkinCode == 0) {
|
// sharedApp.StatusBarStyle = UIStatusBarStyle.LightContent;
|
// Shared.Application.Skin = UserConfig.Instance.CurrentSkinName;
|
//} else if (UserConfig.Instance.SkinCode == 1) {
|
// sharedApp.StatusBarStyle = UIStatusBarStyle.Default;
|
// Shared.Application.Skin = UserConfig.Instance.CurrentSkinName;
|
//}
|
}
|
|
public static PageLayout CurPageLayout = null;
|
}
|
|
}
|
namespace com.hdl.on
|
{
|
|
/// <summary>
|
/// 设定为默认启动的Application
|
/// </summary>
|
[Android.App.Application]
|
public class Application : Android.App.Application, Android.App.Application.IActivityLifecycleCallbacks
|
{
|
static void reStartApp (Android.App.Application application)
|
{
|
var intent = new Intent (application, typeof (BaseActivity));
|
intent.AddFlags (ActivityFlags.NewTask);
|
application.StartActivity (intent);
|
Android.OS.Process.KillProcess (Android.OS.Process.MyPid ());
|
}
|
|
public Application (IntPtr handle, Android.Runtime.JniHandleOwnership ownerShip) : base (handle, ownerShip) { }
|
public override void OnCreate ()
|
{
|
if (Shared.Application.Activity != null) {
|
reStartApp (this);
|
return;
|
}
|
|
RegisterActivityLifecycleCallbacks (this);
|
|
//Shared.Application.IsGpsEnable = false;
|
|
base.OnCreate ();
|
|
initAll ();
|
}
|
|
/// <summary>
|
/// 所有初始化全部在这个方法实现
|
/// </summary>
|
void initAll ()
|
{
|
//BaseActivity.TopMargin = -30;
|
//BaseActivity.IsEnnableGPS = false;
|
//BaseActivity.VerifyDateTime = DateTime.MaxValue;
|
//BaseActivity.KeepScreenON = false;
|
|
|
BaseActivity.BackKeyAction = () => {
|
if (Shared.SimpleControl.MainPage.Loading != null) {
|
Utlis.WriteLine (MainPage.Loading.CurStatus);
|
if (Shared.SimpleControl.MainPage.Loading.CurStatus) {
|
Shared.SimpleControl.MainPage.Loading.Hide ();
|
return;
|
}
|
}
|
//if(BaseActivity.VerifyDateTime == DateTime.MaxValue) { } else
|
try {
|
var lastView = Shared.Application.MainPage.GetChildren (Shared.Application.MainPage.ChildrenCount - 1);
|
Utlis.WriteLine ("lastView " + lastView);
|
if (MainPage.Loading.CurStatus) {
|
return;
|
}
|
if (lastView != null && lastView.Tag.ToString () == "Dialog") {
|
if (SharedMethod.SharedMethod.CurPageLayout == null) {
|
BaseActivity.VerifyDateTime = DateTime.MaxValue;
|
return;
|
} else {
|
Utlis.WriteLine ("Remove Dialog!!!!");
|
var lastView2 = Shared.Application.MainPage.GetChildren (Shared.Application.MainPage.ChildrenCount - 2);
|
lastView.RemoveFromParent ();
|
lastView2.RemoveFromParent ();
|
Utlis.WriteLine ("Remove Dialog End!!!!");
|
BaseActivity.VerifyDateTime = DateTime.MinValue;
|
return;
|
}
|
}
|
} catch (System.Exception ezx) {
|
Utlis.WriteLine (ezx.Message);
|
}
|
if (SharedMethod.SharedMethod.CurPageLayout != null) {
|
if (SharedMethod.SharedMethod.CurPageLayout.ChildrenCount > 1) {
|
Utlis.WriteLine ("Remove PageLayout Children!!!!");
|
SharedMethod.SharedMethod.CurPageLayout.GetChildren (SharedMethod.SharedMethod.CurPageLayout.ChildrenCount - 1).RemoveFromParent ();
|
Utlis.WriteLine ("Remove PageLayout Children End!!!!");
|
BaseActivity.VerifyDateTime = DateTime.MinValue;
|
} else {
|
Utlis.WriteLine ("BaseActivity.VerifyDateTime = DateTime.MaxValue");
|
BaseActivity.VerifyDateTime = DateTime.MaxValue;
|
}
|
}
|
};
|
|
Shared.Application.FontSize = 16;
|
BaseActivity.IsHideVirualButtons = true;
|
ZXing.Mobile.MobileBarcodeScanner.Initialize (this);
|
init ();
|
BaseActivity.OnCreateActoin += (activity, application) => {
|
Microsoft.AppCenter.AppCenter.Start ("d0f0f0c5-88af-494b-93af-9a667801b7a3", typeof (Microsoft.AppCenter.Analytics.Analytics), typeof (Microsoft.AppCenter.Crashes.Crashes));
|
////保存获取的极光服务器上的注册ID到本地文件
|
//var tokenID = JPushInterface.GetRegistrationID (activity);
|
//if (!string.IsNullOrEmpty (tokenID) && UserConfig.Instance.tokenID != tokenID) {
|
// UserConfig.Instance.tokenID = tokenID;
|
// UserConfig.Instance.SaveUserConfig ();
|
//}
|
BaseActivity.NetworkStateChanged += (int obj) => {
|
Utlis.WriteLine ("NetworkStateChanged " + obj);
|
UserConfig.Instance.internetStatus = obj;
|
UserConfig.Instance.SaveUserConfig ();
|
////网络变化通知
|
//EquipmentPublicClass.CheckLinkRemote (obj, false);
|
|
//2020-06-10 同步HDLON 修改优化
|
if (!IsEnterBackground) {
|
//网络变化通知
|
EquipmentPublicClass.CheckLinkRemote (obj, false);
|
} else {
|
Console.WriteLine ("HHH 网络变化但处于后台");
|
}
|
};
|
};
|
BaseActivity.RefreshUIAction += (activity) => {
|
MainPage.Show ();
|
checkSomeInfo ();
|
};
|
BaseActivity.OnResumeAction += (activity) => {
|
if (MainPage.Showed) {
|
checkSomeInfo ();
|
Shared.Application.RunOnMainThread (() => {
|
MainPage.Loading.Hide ();
|
});
|
}
|
if (WiFiSet.refreshView != null) {
|
WiFiSet.refreshView ();
|
}
|
};
|
BaseActivity.OnDestroyAction += (activity) => {
|
BusSocket.Stop ();
|
};
|
HDLUtils.SetAuthoritiesName ("com.hdl.crabtreenew.fileProvider");
|
}
|
|
public static bool IsShowTip = true;
|
|
void init ()
|
{
|
Shared.Application.Skin = UserConfig.Instance.CurrentSkinName;
|
SkinStyle.Current.ChangeColor ();
|
UserConfig.Instance.phoneName = Android.OS.Build.Manufacturer;
|
////设置极光调试模式,为false时只打印警告信息
|
//JPushInterface.SetDebugMode (false);
|
//JPushInterface.Init (this);//保存手机名称到本地文件
|
|
//获取经纬度
|
Shared.Application.LocationAction = (lon, lat) => {
|
try {
|
Shared.Application.LocationAction = null;
|
HttpServerRequest.Current.GetCityInfo (lon.ToString (), lat.ToString ());
|
//关闭定位服务
|
Shared.Application.StopGPSLocationService ();
|
} catch (System.Exception ex) {
|
Utlis.WriteLine ("GetCityInfo catch" + ex.Message);
|
}
|
Utlis.WriteLine ($"经纬度:::{lon}:{lat}");
|
};
|
|
}
|
|
void checkSomeInfo ()
|
{
|
//RemoteInfo.Current.ReadMsgList (UserConfig.Instance.tokenID, IsShowTip);
|
//JPushInterface.ClearAllNotifications (this);
|
|
IsShowTip = true;
|
//var status = isNetworkAvailable (this);
|
//Utlis.WriteLine ("status!!!" + status);
|
//int internetStatus = 0;
|
//if (status) {
|
// var isWifi = isWifiConnected (this);
|
// if (isWifi) {
|
// internetStatus = 2;
|
// } else {
|
// internetStatus = 1;
|
// }
|
//}
|
//Utlis.WriteLine ("");
|
|
//2020-06-10 修改网络判断出错问题
|
int internetStatus = 0;
|
internetStatus = NetworkUtils.CheckConnectedMode ();
|
Console.WriteLine ("internetStatus:" + internetStatus);
|
|
Shared.SimpleControl.EquipmentPublicClass.CheckLinkRemote (internetStatus, false);
|
}
|
|
//bool isNetworkAvailable (Context context)
|
//{
|
// var cm = (ConnectivityManager)context.GetSystemService (ConnectivityService);
|
// if (cm == null || cm.ActiveNetworkInfo == null) {
|
// return false;
|
// } else {
|
// return cm.ActiveNetworkInfo.IsAvailable;
|
// }
|
//}
|
|
//bool isWifiConnected (Context context)
|
//{
|
// if (context != null) {
|
// var mConnectivityManager = (ConnectivityManager)context.GetSystemService
|
// (ConnectivityService);
|
// var mWiFiNetworkInfo = mConnectivityManager.GetNetworkInfo (ConnectivityType.Wifi);
|
// if (mWiFiNetworkInfo != null) {
|
// return mWiFiNetworkInfo.IsAvailable;
|
// }
|
// }
|
// return false;
|
//}
|
|
|
public void OnActivityCreated (Activity activity, Bundle savedInstanceState)
|
{
|
|
}
|
|
public void OnActivityDestroyed (Activity activity)
|
{
|
//throw new NotImplementedException ();
|
}
|
|
public void OnActivityPaused (Activity activity)
|
{
|
//throw new NotImplementedException ();
|
}
|
|
public void OnActivityResumed (Activity activity)
|
{
|
//throw new NotImplementedException ();
|
}
|
|
public void OnActivitySaveInstanceState (Activity activity, Bundle outState)
|
{
|
//throw new NotImplementedException ();
|
}
|
|
public void OnActivityStarted (Activity activity)
|
{
|
//throw new NotImplementedException ();
|
|
mCount++;
|
if (mCount == 1) {
|
Console.WriteLine ("HHH OnActivityStarted:foreground");
|
BusSocketStart ();
|
}
|
}
|
|
public void OnActivityStopped (Activity activity)
|
{
|
|
mCount--;
|
if (mCount == 0) {
|
Console.WriteLine ("HHH OnActivityStopped: background");
|
BusSocketStop ();
|
}
|
}
|
|
|
public override void OnTerminate ()
|
{
|
base.OnTerminate ();
|
UnregisterActivityLifecycleCallbacks (this);
|
}
|
|
int mCount;
|
|
/// <summary>
|
/// 是否进入后台
|
/// </summary>
|
public bool IsEnterBackground = false;
|
|
DateTime closeTime = DateTime.MinValue;
|
|
/// <summary>
|
/// BusSocketStop
|
/// </summary>
|
void BusSocketStop ()
|
{
|
IsEnterBackground = true;
|
//进入后台mqtt正在连接重置状态
|
MqttCommon.remoteMqttIsConnecting = false;
|
Shared.BusSocket.Stop ();
|
closeTime = DateTime.Now;
|
}
|
|
|
/// <summary>
|
/// BusSocketStart
|
/// </summary>
|
void BusSocketStart ()
|
{
|
IsEnterBackground = false;
|
|
if (closeTime == DateTime.MinValue) {
|
closeTime = DateTime.Now;
|
} else if (closeTime.AddSeconds (20) < DateTime.Now) {
|
if (CommonPage.IsRemote) {
|
MqttCommon.DisConnectRemote ("closeTime", false);
|
}
|
}
|
|
Shared.BusSocket.Start (6000);
|
}
|
|
void Hide () {
|
// Window _window;
|
// _window = this.GetWindow ();
|
// WindowManager.LayoutParams params = _window.getAttributes ();
|
//params.systemUiVisibility = View.SYSTEM_UI_FLAG_HIDE_NAVIGATION;
|
// _window.setAttributes (params);
|
}
|
}
|
}
|