From 3f6685c77beeb12baf840733fb890860f4c26e7c Mon Sep 17 00:00:00 2001 From: mac <user@users-MacBook-Pro.local> Date: 星期四, 25 七月 2024 17:25:59 +0800 Subject: [PATCH] 2024年07月25日17:24:45 --- HDL-ON_Android/SplashActivity.cs | 462 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++- 1 files changed, 453 insertions(+), 9 deletions(-) diff --git a/HDL-ON_Android/SplashActivity.cs b/HDL-ON_Android/SplashActivity.cs index 1611515..450ac81 100644 --- a/HDL-ON_Android/SplashActivity.cs +++ b/HDL-ON_Android/SplashActivity.cs @@ -1,28 +1,472 @@ -锘縰sing Android.App; +锘縰sing System; +using Android; +using Android.App; using Android.Content; +using Android.Content.PM; +using Android.Locations; +using Android.Net; using Android.OS; +using Android.Support.V4.App; +using Android.Support.V4.Content; +using CN.Jpush.Android.Api; +//using Android.Widget; using Com.Hdl.ON.Jpush.Androidjpush; +using HDL_ON; +using Java.Util; using Shared; namespace HDL_ON_Android { - [Activity(Theme = "@style/SplashTheme", MainLauncher = true, Name = "com.hdl.onpro.SplashActivity")] + [Activity(Theme = "@style/SplashTheme", MainLauncher = true, LaunchMode = LaunchMode.SingleTask, Name = "com.hdl.onpro.SplashActivity", ScreenOrientation = ScreenOrientation.Portrait)] [IntentFilter(new string[] { "com.hdl.onpro.SplashActivity", Intent.ActionView })] public class SplashActivity : Activity { + protected override void OnActivityResult(int requestCode, Result resultVal, Intent data) + { + Console.WriteLine("123456"); + if (requestCode == 99) + { + if (resultVal == Result.Ok) + { + if (!OnAppConfig.Instance.FirstRunApp) + { + ////鎵撳紑baseActivity + Intent i = new Intent(this, typeof(BaseActivity));//Intent intent=new Intent( 璧峰缁勪欢瀵硅薄 , 鐩爣 Service.class); + StartActivityForResult(i, 1); + OverridePendingTransition(0, 0); + initAll(); + initOhterSdk(); + Finish();//鍏抽棴鑷繁 + } + } + } + base.OnActivityResult(requestCode, resultVal, data); + } + + [Obsolete] protected override void OnCreate(Bundle savedInstanceState) { + Console.WriteLine("123456"); base.OnCreate(savedInstanceState); + if(Shared.Application.Activity != null && Shared.Application.Activity.GetType() == typeof(BaseActivity)) + { + Finish(); + return; + } - //鎵撳紑baseActivity - Intent i = new Intent(this, typeof(BaseActivity));//Intent intent=new Intent( 璧峰缁勪欢瀵硅薄 , 鐩爣 Service.class); - StartActivity(i); + //Intent i = new Intent(this, typeof(BaseActivity));//Intent intent=new Intent( 璧峰缁勪欢瀵硅薄 , 鐩爣 Service.class); + //StartActivityForResult(i, 1); + //OverridePendingTransition(0, 0); + //initAll(); +#if DEBUG + HDL_ON.OnAppConfig.Instance.isAgreePrivacyPolicy = true; +#endif + if (HDL_ON.OnAppConfig.Instance.FirstRunApp || !HDL_ON.OnAppConfig.Instance.isAgreePrivacyPolicy) + { + //OnAppConfig.Instance.FirstRunApp = false; + //OnAppConfig.Instance.SaveConfig(); + Language.CurrentLanguage = "Chinese"; + var localeList = Resources.Configuration.Locale; + Console.WriteLine("褰撳墠璇█缂╁啓:" + localeList.Language); + if (localeList.Language == "zh") + { + Language.CurrentLanguage = "Chinese"; + } + else if (localeList.Language == "es") + { + Language.CurrentLanguage = "Spanish"; + } + else if (localeList.Language == "ru") + { + Language.CurrentLanguage = "russian"; + } + else if (localeList.Language == "bg") + { + Language.CurrentLanguage = "斜褗谢谐邪褉褋泻懈"; + } + //else if (localeList.Language == "uk") + //{ + // Language.CurrentLanguage = "Ukraine"; + //} + else + { + Language.CurrentLanguage = "English"; + } - OverridePendingTransition(0, 0); - Finish(); + Intent intent = new Intent(this, typeof(AgreementActivity)); + StartActivityForResult(intent, 99); + } + else + { + ////鎵撳紑baseActivity + Intent i = new Intent(this, typeof(BaseActivity));//Intent intent=new Intent( 璧峰缁勪欢瀵硅薄 , 鐩爣 Service.class); + StartActivityForResult(i, 1); + OverridePendingTransition(0, 0); + initAll(); + initOhterSdk(); + Finish();//鍏抽棴鑷繁 + } } + + + public void Permissions() + { + string[] mPermissionList = new string[] + { + Manifest.Permission.ReadSms + }; + + foreach (string permissions in mPermissionList) + { + if (ContextCompat.CheckSelfPermission(this, permissions) != 0) + { + ActivityCompat.RequestPermissions(this, new string[] { permissions }, 1); + } + } + } + + + + void initOhterSdk() + { + //娉ㄥ唽鏈鐞嗗紓甯镐簨浠� + //AppCenter.Start("64ac5859-2cd7-4ef8-a5da-5455e29679ec", typeof(Analytics), typeof(Crashes)); + //鎵嬫満鍚嶇О Android.OS.Build.Manufacturer; + //OnAppConfig.Instance.PhoneName = Android.OS.Build.Manufacturer; + //#if DEBUG + //CN.Jpush.Android.Api.JPushInterface.SetDebugMode(true); + //#endif + JPushInterface.Init(this); + + //Com.Chteam.Agent.BuglyAgentHelper.Init(this.ApplicationContext, "316a8f5d83"); + + + BaseActivity.OnCreateActoin += (activity, application) => + { + //鑾峰彇鏋佸厜鎺ㄩ�両D + GetJPushRegistrationID(activity); + + }; + + try + { + //鍒濆鍖栧弸鐩焥dk + Com.Hdl.Umsdk.UmSdk.InitUmSdk(this, "61d565d9e0f9bb492bbc3d5a", "Android"); + ////鍒濆鍖栧弸鐩焥dk config + Com.Hdl.Umsdk.UmSdk.InitUMConfigure(this, "61d565d9e0f9bb492bbc3d5a", "Android", ""); + } + catch (Exception ex) + { + Console.WriteLine("鍒濆鍖栧弸鐩烻DK寮傚父:" + ex.Message); + } + + } + + /// <summary> + /// 鎵�鏈夊垵濮嬪寲鍏ㄩ儴鍦ㄨ繖涓柟娉曞疄鐜� + /// </summary> + void initAll() + { + //绂佹灞忓箷闀夸寒 + BaseActivity.KeepScreenON = false; + //闅愯棌铏氭嫙鎸夐敭 + BaseActivity.IsHideVirualButtons = true; + + + + //瀹炵幇瀹夊崜杩斿洖鎸夐敭 + BaseActivity.BackKeyAction = () => + { + try + { + var result = MainPage.LoadEvent_BackAction(); + switch (result) + { + case 0: + break; + case 1: + case 2: + BaseActivity.VerifyDateTime = DateTime.MaxValue; + break; + default: + BaseActivity.VerifyDateTime = DateTime.MaxValue; + break; + } + } + catch (Exception ex) + { + MainPage.Log(ex.Message); + BaseActivity.VerifyDateTime = DateTime.MaxValue; + } + }; + + BaseActivity.OnCreateActoin = (activity, application) => + { + Language.CurrentLanguage = "Chinese"; + var localeList = Resources.Configuration.Locale; + Console.WriteLine("褰撳墠璇█缂栧彿" + localeList.Language); + if (localeList.Language == "zh") + { + Language.CurrentLanguage = "Chinese"; + } + else if (localeList.Language == "es") + { + Language.CurrentLanguage = "Spanish"; + } + else if (localeList.Language == "ru") + { + Language.CurrentLanguage = "russian"; + } + else if (localeList.Language == "bg") + { + Language.CurrentLanguage = "斜褗谢谐邪褉褋泻懈"; + } + //else if (localeList.Language == "uk") + //{ + // Language.CurrentLanguage = "Ukraine"; + //} + else + { + Language.CurrentLanguage = "English"; + } + + BaseActivity.NetworkStateChanged += (int internetStatus) => + { + //if (!IsEnterBackground) + //{ + // ////BusSocket.Stop(); + // //new System.Threading.Thread(() => + // //{ + // // System.Threading.Thread.Sleep(1000); + // // //BusSocket.Start(); + // //}) + // //{ IsBackground = true }.Start(); + + //} + //else + //{ + //Console.WriteLine("HHH 缃戠粶鍙樺寲浣嗗浜庡悗鍙�"+internetStatus); + //} + + //缃戠粶鍙樺寲澶勭悊 + HDLCommon.Current.UpdateInternetStatus((int)internetStatus, MainPage.IsEnterBackground); + }; + }; + BaseActivity.RefreshUIAction = (activity) => + { + Language.CurrentLanguage = "Chinese"; + var localeList = Resources.Configuration.Locale; + Console.WriteLine("褰撳墠璇█锛�" + localeList.Language); + if (localeList.Language == "zh") + { + Language.CurrentLanguage = "Chinese"; + } + else if (localeList.Language == "es") + { + Language.CurrentLanguage = "Spanish"; + } + else if (localeList.Language == "ru") + { + Language.CurrentLanguage = "russian"; + } + else if (localeList.Language == "bg") + { + Language.CurrentLanguage = "斜褗谢谐邪褉褋泻懈"; + } + //else if (localeList.Language == "uk") + //{ + // Language.CurrentLanguage = "Ukraine"; + //} + else + { + Language.CurrentLanguage = "English"; + } + MainPage.Show(); + checkSomeInfo(); + }; + BaseActivity.OnResumeAction = (activity) => + { + checkSomeInfo(); + }; + BaseActivity.OnDestroyAction = (activity) => + { + Console.WriteLine("OnDestroyAction"); + //BusSocket.Stop(); + //UserInfo.Current.unlockTime = DateTime.Now; + }; + + + HDLUtils.SetAuthoritiesName("com.hdl.onpro.fileProvider"); + + //Shared.Application.IsGpsEnable = true; + //bool isfirst = true; + + + + var isfirst = true; + //鑾峰彇缁忕含搴� + Shared.Application.LocationAction = (lon, lat) => + { + try + { + if (isfirst) + { + //鍙Е鍙戜竴娆� + new HDL_ON.DAL.Server.HttpServerRequest().GetCityWeatherInfo(lon.ToString().Replace(",", "."), lat.ToString().Replace(",", ".")); + } + isfirst = false; + ///鐩戝惉缁忕含搴� + HDL_ON.UI.UI2.Intelligence.Automation.LogicMethod.Current.AppLatAndLonEvent(lon, lat); + //鍏抽棴瀹氫綅鏈嶅姟 + //Shared.Application.StopGPSLocationService(); + } + catch (Exception ex) + { + Utlis.WriteLine("GetCityInfo catch" + ex.Message); + } + MainPage.Log($"缁忕含搴�:::{lon}:{lat}"); + }; + } + + + + /// <summary> + /// + /// </summary> + /// <param name="activity"></param> + void GetJPushRegistrationID(BaseActivity activity) + { + try + { + //淇濆瓨鑾峰彇鐨勬瀬鍏夋湇鍔″櫒涓婄殑娉ㄥ唽ID鍒版湰鍦版枃浠� + var tokenID = JPushInterface.GetRegistrationID(activity); + Console.WriteLine("RegistrationID: " + tokenID); + if (!string.IsNullOrEmpty(tokenID) && OnAppConfig.Instance.PushDeviceToken != tokenID) + { + OnAppConfig.Instance.PushDeviceToken = tokenID; + OnAppConfig.Instance.PhoneName = Android.OS.Build.Manufacturer; + OnAppConfig.Instance.SaveConfig(); + } + int loadTokenCount = 0; + System.Threading.Tasks.Task.Run(() => + { + while (string.IsNullOrEmpty(tokenID)) + { + System.Threading.Thread.Sleep(1000); + tokenID = JPushInterface.GetRegistrationID(activity); + Console.WriteLine("Sleep.tokenID + " + JPushInterface.GetRegistrationID(activity)); + loadTokenCount++; + if (loadTokenCount > 30) + { + break; + } + } + Console.WriteLine("RegistrationID: " + tokenID); + if (!string.IsNullOrEmpty(tokenID) && OnAppConfig.Instance.PushDeviceToken != tokenID) + { + OnAppConfig.Instance.PushDeviceToken = tokenID; + OnAppConfig.Instance.PhoneName = Android.OS.Build.Manufacturer; + OnAppConfig.Instance.SaveConfig(); + } + }); + + } + catch + { + + } + } + + public static bool IsShowTip = true; + + void checkSomeInfo() + { + try + { + IsShowTip = true; + var status = isNetworkAvailable(this); + int internetStatus = 0; + if (!status) + { + internetStatus = 0; + } + + var isWifi = isWifiConnected(this); + if (isWifi) + { + internetStatus = 2; + } + else + { + internetStatus = 1; + } + } + catch (Exception ex) + { + Console.WriteLine($"android check some info erorr : {ex.Message}"); + } + } + + 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; + } + + + + + + // 鍦ㄤ綘鐨勬椿鍔紙Activity锛夋垨鐗囨锛團ragment锛変腑鐨勬煇涓柟娉曚腑锛屽紑濮嬬洃鍚綅缃彉鍖� + void StartLocationUpdates() + { + // 鍒涘缓浣嶇疆绠$悊鍣� + var locationManager = (LocationManager)GetSystemService(Context.LocationService); + + // 璁剧疆浣嶇疆鐩戝惉鍣� + var locationListener = new MyLocationListener_V2(); + + // 璇锋眰浣嶇疆鏇存柊 + locationManager.RequestLocationUpdates(LocationManager.GpsProvider, 0, 0, locationListener); + } + + // 鍦ㄤ綘鐨勬椿鍔紙Activity锛夋垨鐗囨锛團ragment锛変腑鐨勬煇涓柟娉曚腑锛屽仠姝㈢洃鍚綅缃彉鍖� + void StopLocationUpdates() + { + // 鍒涘缓浣嶇疆绠$悊鍣� + var locationManager = (LocationManager)GetSystemService(Context.LocationService); + + // 璁剧疆浣嶇疆鐩戝惉鍣� + var locationListener = new MyLocationListener_V2(); + + // 鍋滄浣嶇疆鏇存柊 + locationManager.RemoveUpdates(locationListener); + } + + + } - - } \ No newline at end of file -- Gitblit v1.8.0