| | |
| | | using System; |
| | | using Android; |
| | | using Android.App; |
| | | using Android.Content; |
| | | using Android.Net; |
| | | using Android.OS; |
| | | using CN.Jpush.Android.Api; |
| | | using CN.Jpush.Android.Service; |
| | | using Java.Lang; |
| | | using Java.Util; |
| | | using Java.Util.Zip; |
| | | //using CN.Jpush.Android.Api; |
| | | //using CN.Jpush.Android.Service; |
| | | |
| | | using Shared; |
| | | using Shared.SimpleControl; |
| | | using SmartHome; |
| | |
| | | /// 设定为默认启动的Application |
| | | /// </summary> |
| | | [Android.App.Application] |
| | | public class Application : 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 () |
| | | { |
| | | initAll (); |
| | | if (Shared.Application.Activity != null) { |
| | | reStartApp (this); |
| | | return; |
| | | } |
| | | |
| | | RegisterActivityLifecycleCallbacks (this); |
| | | |
| | | //Shared.Application.IsGpsEnable = false; |
| | | |
| | | base.OnCreate (); |
| | | |
| | | initAll (); |
| | | } |
| | | |
| | | /// <summary> |
| | |
| | | //BaseActivity.KeepScreenON = false; |
| | | |
| | | |
| | | |
| | | BaseActivity.BackKeyAction = () => { |
| | | if (Shared.SimpleControl.MainPage.Loading != null) { |
| | | Console.WriteLine (MainPage.Loading.CurStatus); |
| | | 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); |
| | | Console.WriteLine ("lastView " + lastView); |
| | | Utlis.WriteLine ("lastView " + lastView); |
| | | if (MainPage.Loading.CurStatus) { |
| | | return; |
| | | } |
| | |
| | | BaseActivity.VerifyDateTime = DateTime.MaxValue; |
| | | return; |
| | | } else { |
| | | Console.WriteLine ("Remove Dialog!!!!"); |
| | | Utlis.WriteLine ("Remove Dialog!!!!"); |
| | | var lastView2 = Shared.Application.MainPage.GetChildren (Shared.Application.MainPage.ChildrenCount - 2); |
| | | lastView.RemoveFromParent (); |
| | | lastView2.RemoveFromParent (); |
| | | Console.WriteLine ("Remove Dialog End!!!!"); |
| | | Utlis.WriteLine ("Remove Dialog End!!!!"); |
| | | BaseActivity.VerifyDateTime = DateTime.MinValue; |
| | | return; |
| | | } |
| | | } |
| | | } catch (System.Exception ezx) { |
| | | Console.WriteLine (ezx.Message); |
| | | Utlis.WriteLine (ezx.Message); |
| | | } |
| | | if (SharedMethod.SharedMethod.CurPageLayout != null) { |
| | | if (SharedMethod.SharedMethod.CurPageLayout.ChildrenCount > 1) { |
| | | Console.WriteLine ("Remove PageLayout Children!!!!"); |
| | | Utlis.WriteLine ("Remove PageLayout Children!!!!"); |
| | | SharedMethod.SharedMethod.CurPageLayout.GetChildren (SharedMethod.SharedMethod.CurPageLayout.ChildrenCount - 1).RemoveFromParent (); |
| | | Console.WriteLine ("Remove PageLayout Children End!!!!"); |
| | | Utlis.WriteLine ("Remove PageLayout Children End!!!!"); |
| | | BaseActivity.VerifyDateTime = DateTime.MinValue; |
| | | } else { |
| | | Console.WriteLine ("BaseActivity.VerifyDateTime = DateTime.MaxValue"); |
| | | Utlis.WriteLine ("BaseActivity.VerifyDateTime = DateTime.MaxValue"); |
| | | BaseActivity.VerifyDateTime = DateTime.MaxValue; |
| | | } |
| | | } |
| | | }; |
| | | |
| | | Shared.Application.FontSize = 16; |
| | | BaseActivity.IsHideVirualButtons = false; |
| | | 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 (); |
| | | } |
| | | ////保存获取的极光服务器上的注册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) => { |
| | | Console.WriteLine ("NetworkStateChanged " + obj); |
| | | Utlis.WriteLine ("NetworkStateChanged " + obj); |
| | | UserConfig.Instance.internetStatus = obj; |
| | | UserConfig.Instance.SaveUserConfig (); |
| | | //网络变化通知 |
| | | EquipmentPublicClass.CheckLinkRemote (obj, false); |
| | | ////网络变化通知 |
| | | //EquipmentPublicClass.CheckLinkRemote (obj, false); |
| | | |
| | | //2020-06-10 同步HDLON 修改优化 |
| | | if (!IsEnterBackground) { |
| | | //网络变化通知 |
| | | EquipmentPublicClass.CheckLinkRemote (obj, false); |
| | | } else { |
| | | Console.WriteLine ("HHH 网络变化但处于后台"); |
| | | } |
| | | }; |
| | | }; |
| | | BaseActivity.RefreshUIAction += (activity) => { |
| | |
| | | }; |
| | | 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);//保存手机名称到本地文件 |
| | | ////设置极光调试模式,为false时只打印警告信息 |
| | | //JPushInterface.SetDebugMode (false); |
| | | //JPushInterface.Init (this);//保存手机名称到本地文件 |
| | | |
| | | //获取经纬度 |
| | | Shared.Application.LocationAction = (arg1, arg2) => { |
| | | |
| | | Shared.Application.LocationAction = (lon, lat) => { |
| | | try { |
| | | Shared.Application.LocationAction = null; |
| | | HttpServerRequest.Current.GetCityInfo (lon.ToString (), lat.ToString ()); |
| | | //关闭定位服务 |
| | | Shared.Application.StopGPSLocationService (); |
| | | |
| | | System.Threading.Tasks.Task.Run (() => { |
| | | while (true) { |
| | | try { |
| | | Shared.SimpleControl.CommonPage.AirQuality = new service.hdlcontrol.com_WebServiceAirQuality.WebServiceAirQuality ().GetAirQuality (arg2.ToString (), arg1.ToString ()); |
| | | if (Shared.SimpleControl.CommonPage.AirQuality != null) |
| | | break; |
| | | } catch { } |
| | | } |
| | | Shared.Application.RunOnMainThread (() => { |
| | | if (CommonPage.RefreshAir != null) |
| | | CommonPage.RefreshAir (); |
| | | }); |
| | | }); |
| | | } catch { |
| | | } 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); |
| | | //RemoteInfo.Current.ReadMsgList (UserConfig.Instance.tokenID, IsShowTip); |
| | | //JPushInterface.ClearAllNotifications (this); |
| | | |
| | | IsShowTip = true; |
| | | var status = isNetworkAvailable (this); |
| | | Console.WriteLine ("status!!!" + status); |
| | | //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; |
| | | if (status) { |
| | | var isWifi = isWifiConnected (this); |
| | | if (isWifi) { |
| | | internetStatus = 2; |
| | | } else { |
| | | internetStatus = 1; |
| | | } |
| | | } |
| | | Console.WriteLine (""); |
| | | internetStatus = NetworkUtils.CheckConnectedMode (); |
| | | Console.WriteLine ("internetStatus:" + internetStatus); |
| | | |
| | | Shared.SimpleControl.EquipmentPublicClass.CheckLinkRemote (internetStatus, false); |
| | | } |
| | | |
| | | bool isNetworkAvailable (Context context) |
| | | //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) |
| | | { |
| | | var cm = (ConnectivityManager)context.GetSystemService (ConnectivityService); |
| | | if (cm == null || cm.ActiveNetworkInfo == null) { |
| | | return false; |
| | | } else { |
| | | return cm.ActiveNetworkInfo.IsAvailable; |
| | | |
| | | } |
| | | |
| | | 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 (); |
| | | } |
| | | } |
| | | |
| | | bool isWifiConnected (Context context) |
| | | public void OnActivityStopped (Activity activity) |
| | | { |
| | | if (context != null) { |
| | | var mConnectivityManager = (ConnectivityManager)context.GetSystemService |
| | | (ConnectivityService); |
| | | var mWiFiNetworkInfo = mConnectivityManager.GetNetworkInfo (ConnectivityType.Wifi); |
| | | if (mWiFiNetworkInfo != null) { |
| | | return mWiFiNetworkInfo.IsAvailable; |
| | | |
| | | 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) { |
| | | SmartHome.MqttCommon.DisConnectRemoteMqttClient ("closeTime"); |
| | | } |
| | | } |
| | | return 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); |
| | | } |
| | | } |
| | | } |