From a4924de3136289d10cabbf2f61a228387d44ded7 Mon Sep 17 00:00:00 2001 From: gxc <guoxuecheng@guoxuechengdeMacBook-Pro.local> Date: 星期四, 07 十一月 2019 13:48:36 +0800 Subject: [PATCH] Merge branch 'dev-tzy' into DEV_GXC --- ZigbeeApp/GateWay.Droid/Application.cs | 105 ++++++++++++++++++++++++++++++++++++++++++++++------ 1 files changed, 92 insertions(+), 13 deletions(-) diff --git a/ZigbeeApp/GateWay.Droid/Application.cs b/ZigbeeApp/GateWay.Droid/Application.cs old mode 100755 new mode 100644 index 68be8f3..650397c --- a/ZigbeeApp/GateWay.Droid/Application.cs +++ b/ZigbeeApp/GateWay.Droid/Application.cs @@ -14,24 +14,97 @@ using Microsoft.AppCenter; using Microsoft.AppCenter.Analytics; using Microsoft.AppCenter.Crashes; +using Com.Tencent.MM.Sdk.Openapi; namespace com.hdl.home { - /// <summary>鈥� /// 璁惧畾涓洪粯璁ゅ惎鍔ㄧ殑Application鈥� /// </summary>鈥� [Android.App.Application]鈥� public class Application : Android.App.Application鈥� {鈥� public Application(IntPtr handle, Android.Runtime.JniHandleOwnership ownerShip) : base(handle, ownerShip) { }鈥ㄢ�� public override void OnCreate()鈥� {鈥� //瀹夊崜閰嶇綉鍒濆鈥� var result = Com.Mediatek.Elian.ElianNative.LoadLib();鈥� if (!result)鈥� {鈥� System.Console.WriteLine("Error,can't load elianjni lib");鈥� } - initAll();鈥� base.OnCreate();鈥� } + [Activity(Name = "com.hdl.home.wxapi.WXEntryActivity", Exported = true, Theme = "@android:style/Theme.Translucent", LaunchMode = Android.Content.PM.LaunchMode.SingleTask)] + class WXEntryActivity : Android.App.Activity, IWXAPIEventHandler + { + public void OnReq(BaseReq p0) + { + } + protected override void OnNewIntent(Intent intent) + { + base.OnNewIntent(intent); + Intent = intent; + com.hdl.home.Application.api.HandleIntent(intent, this); + //Finish(); + } + public static Action<string> RespAction; + public void OnResp(BaseResp p0) + { + if (p0 is SendAuth.Resp) + { + var resp = p0 as SendAuth.Resp; - /// <summary>鈥� /// 鎵�鏈夊垵濮嬪寲鍏ㄩ儴鍦ㄨ繖涓柟娉曞疄鐜扳�� /// </summary>鈥� void initAll()鈥� {鈥� BaseActivity.IsEnnableGPS = false;鈥� //璁剧疆鏋佸厜璋冭瘯妯″紡锛屼负false鏃跺彧鎵撳嵃璀﹀憡淇℃伅 - // System.Console.WriteLine($"AAA : {System.DateTime.Now.ToString()}"); -鈥� JPushInterface.SetDebugMode(false); + switch (resp.ErrCode) + { + case SendAuth.Resp.InnerErrCode.ErrOk: + var result = new System.Net.WebClient { }.DownloadString($"https://api.weixin.qq.com/sns/oauth2/access_token?appid=wx2ec8f53f6fa36e82&secret=a08585cd6ff2ce64570b9e7e6525dd8e&code={resp.Token}&grant_type=authorization_code"); + RespAction?.Invoke(result); + break; + default: + RespAction?.Invoke(null); + break; + + //case SendAuth.Resp.InnerErrCode.ErrUserCancel: + // break; + //case SendAuth.Resp.InnerErrCode.ErrAuthDenied: + // break; + + } + } + + this.Finish(); + } + //IWXAPI api; + protected override void OnCreate(Bundle savedInstanceState) + { + base.OnCreate(savedInstanceState); + // 閫氳繃WXAPIFactory宸ュ巶锛岃幏鍙朓WXAPI鐨勫疄渚� + //api = WXAPIFactory.CreateWXAPI(this, "wx2ec8f53f6fa36e82", false); + + // 灏嗗簲鐢ㄧ殑appId娉ㄥ唽鍒板井淇� + //api.RegisterApp("wx2ec8f53f6fa36e82"); + + com.hdl.home.Application.api.HandleIntent(Intent, this); + } + } + /// <summary>鈥� /// 璁惧畾涓洪粯璁ゅ惎鍔ㄧ殑Application鈥� /// </summary>鈥� [Android.App.Application]鈥� public class Application : Android.App.Application鈥� {鈥� public Application(IntPtr handle, Android.Runtime.JniHandleOwnership ownerShip) : base(handle, ownerShip) { }鈥ㄢ�� public override void OnCreate()鈥� { + //瀹夊崜閰嶇綉鍒濆 + //var result = Com.Mediatek.Elian.ElianNative.LoadLib(); + //if (!result) + //{ + // System.Console.WriteLine("Error,can't load elianjni lib"); + //} + initAll();鈥� base.OnCreate(); + // 閫氳繃WXAPIFactory宸ュ巶锛岃幏鍙朓WXAPI鐨勫疄渚� + api = WXAPIFactory.CreateWXAPI(this, "wx2ec8f53f6fa36e82", true); + + // 灏嗗簲鐢ㄧ殑appId娉ㄥ唽鍒板井淇� + api.RegisterApp("wx2ec8f53f6fa36e82"); + } + + internal static IWXAPI api; + + public static void WXLogin() { + var req = new SendAuth.Req { Scope = "snsapi_userinfo", State = "ZigbeeApp" }; + api.SendReq(req); + } + /// <summary>鈥� /// 鎵�鏈夊垵濮嬪寲鍏ㄩ儴鍦ㄨ繖涓柟娉曞疄鐜扳�� /// </summary>鈥� void initAll()鈥� {鈥� BaseActivity.IsEnnableGPS = false; + //璁剧疆鏋佸厜璋冭瘯妯″紡锛屼负false鏃跺彧鎵撳嵃璀﹀憡淇℃伅 + // System.Console.WriteLine($"AAA : {System.DateTime.Now.ToString()}"); +#if Release鈥� JPushInterface.SetDebugMode(false); //淇濆瓨鎵嬫満鍚嶇О鍒版湰鍦版枃浠� //System.Console.WriteLine($"BBB : {System .DateTime .Now .ToString ()}"); JPushInterface.Init(this); //System.Console.WriteLine($"CCC : {System.DateTime.Now.ToString()}"); - +#endif BaseActivity.BackKeyAction = () => { try { @@ -49,8 +122,8 @@ { Console.WriteLine("Remove Dialog!!!!"); var lastView2 = Shared.Application.MainPage.GetChildren(Shared.Application.MainPage.ChildrenCount - 2); - Shared.Application.MainPage.Remove(lastView); - Shared.Application.MainPage.Remove(lastView2); + lastView.RemoveFromParent(); + lastView2.RemoveFromParent(); Console.WriteLine("Remove Dialog End!!!!"); return; } @@ -62,7 +135,7 @@ if (HomePage.Instance.ChildrenCount > 1) { Console.WriteLine("Remove PageLayout Children!!!!"); - HomePage.Instance.Remove(HomePage.Instance.GetChildren(HomePage.Instance.ChildrenCount - 1)); + HomePage.Instance.GetChildren(HomePage.Instance.ChildrenCount - 1).RemoveFromParent(); Console.WriteLine("Remove PageLayout Children End!!!!"); } else @@ -72,10 +145,13 @@ } }; 鈥� BaseActivity.OnCreateActoin += (activity, application) => { - AppCenter.Start("4802834a-e7e9-4dd8-93f1-c2f88f0bd464", typeof(Analytics), typeof(Crashes));鈥� //淇濆瓨鑾峰彇鐨勬瀬鍏夋湇鍔″櫒涓婄殑娉ㄥ唽ID鍒版湰鍦版枃浠垛�� var registrationId = JPushInterface.GetRegistrationID(activity); + Shared.Application.FontSize = 12; + AppCenter.Start("4802834a-e7e9-4dd8-93f1-c2f88f0bd464", typeof(Analytics), typeof(Crashes)); + +#if Release鈥� //淇濆瓨鑾峰彇鐨勬瀬鍏夋湇鍔″櫒涓婄殑娉ㄥ唽ID鍒版湰鍦版枃浠垛�� var registrationId = JPushInterface.GetRegistrationID(activity); System.Console.WriteLine("registrationId-鏋佸厜id=" + registrationId); - if (!string.IsNullOrEmpty(registrationId))鈥� {鈥� Shared.Common.Config.Instance.RegistrationID = registrationId;鈥� Shared.Common.Config.Instance.Save();鈥� }鈥� };鈥� BaseActivity.RefreshUIAction += (activity) => {鈥� Shared.Language.CurrentLanguage = "Chinese";鈥� Shared.Common.CommonPage.Instance.Show();鈥� };鈥� BaseActivity.OnResumeAction += (activity) => {鈥� };鈥� BaseActivity.NetworkStateChanged += (v) =>鈥� {鈥� //缃戠粶鐘舵�佸彉鍖栧鐞嗕簨浠� - Shared.Common.CommonPage.nowNetworkMode = v;鈥� };鈥� BaseActivity.OnDestroyAction += (activity) => {鈥� //socket鍋滄杩炴帴鈥� //ZigBee.Device.ZbGateway.FindGateWaySocket.Stop();鈥� };鈥ㄢ�� }鈥ㄢ�� public static bool IsShowTip = true;鈥� JpushNotificationReceiver myReceiver = new JpushNotificationReceiver { };鈥ㄢ�� /// <summary>鈥� /// 椤圭洰鍚姩鏃剁綉缁滄煡璇⑩�� /// </summary>鈥� void checkSomeInfo()鈥� {鈥� var status = isNetworkAvailable(this);鈥� string internetStatus = "Available";鈥� if (!status)鈥� {鈥� internetStatus = "UnaVailable";鈥� }鈥� else鈥� {鈥� var isWifi = isWifiConnected(this);鈥� if (isWifi)鈥� {鈥� internetStatus = "WiFiConnect";鈥� }鈥� else鈥� {鈥� internetStatus = "MobileConnect";鈥� }鈥� }鈥ㄢ�� int connectState = 0;鈥� if (internetStatus == "UnaVailable")鈥� {鈥� connectState = 0;鈥� }鈥� else if (internetStatus == "WiFiConnect")鈥� {鈥� connectState = 2;鈥� }鈥� else鈥� {鈥� connectState = 1;鈥� }鈥� //ZigBee.Device.ZbGateway.CheckConnection(connectState);鈥� }鈥ㄢ�� /// <summary>鈥� /// 缃戠粶鏄惁鍙敤鈥� /// </summary>鈥� /// <returns><c>true</c>, if network available was ised, <c>false</c> otherwise.</returns>鈥� /// <param name="context">Context.</param>鈥� bool isNetworkAvailable(Context context)鈥� {鈥� var cm = (ConnectivityManager)context.GetSystemService(ConnectivityService);鈥ㄢ�� if (cm == null || cm.ActiveNetworkInfo == null)鈥� {鈥� //褰撳墠缃戠粶涓嶅彲鐢ㄢ�� return false;鈥� }鈥� else鈥� {鈥� return cm.ActiveNetworkInfo.IsAvailable;鈥� }鈥� }鈥ㄢ�� /// <summary>鈥� /// 缃戠粶鏄惁杩炴帴鈥� /// </summary>鈥� /// <returns><c>true</c>, if wifi connected was ised, <c>false</c> otherwise.</returns>鈥� /// <param name="context">Context.</param>鈥� bool isWifiConnected(Context context)鈥� {鈥� if (context != null)鈥� {鈥� var cm = (ConnectivityManager)context.GetSystemService(ConnectivityService);鈥ㄢ�� var mWiFiNetworkInfo = cm.GetNetworkInfo(ConnectivityType.Wifi);鈥� if (Android.Net.NetworkInfo.State.Connected == mWiFiNetworkInfo.GetState())鈥� {鈥� //褰撳墠缃戠粶鏄疻i-Fi杩炴帴鈥� return true;鈥� }鈥ㄢ�� var moWiFiNetworkInfo = cm.GetNetworkInfo(ConnectivityType.Mobile);鈥� if (Android.Net.NetworkInfo.State.Connected == moWiFiNetworkInfo.GetState())鈥� {鈥� //褰撳墠缃戠粶鏄疢obile杩炴帴鈥� return false;鈥� }鈥� }鈥� return false;鈥� } + if (!string.IsNullOrEmpty(registrationId))鈥� {鈥� Shared.Common.Config.Instance.RegistrationID = registrationId;鈥� Shared.Common.Config.Instance.Save();鈥� }鈥�#endif鈥� };鈥� BaseActivity.RefreshUIAction += (activity) => {鈥� Shared.Language.CurrentLanguage = "Chinese";鈥� Shared.Common.CommonPage.Instance.Show();鈥� };鈥� BaseActivity.OnResumeAction += (activity) => {鈥� };鈥� BaseActivity.NetworkStateChanged += (v) =>鈥� {鈥� //缃戠粶鐘舵�佸彉鍖栧鐞嗕簨浠� + Shared.Common.CommonPage.nowNetworkMode = v;鈥� };鈥� BaseActivity.OnDestroyAction += (activity) => {鈥� //socket鍋滄杩炴帴鈥� //ZigBee.Device.ZbGateway.FindGateWaySocket.Stop();鈥� };鈥ㄢ�� HDLUtils.SetAuthoritiesName("com.hdl.home.fileProvider");鈥� }鈥ㄢ�� public static bool IsShowTip = true;鈥� JpushNotificationReceiver myReceiver = new JpushNotificationReceiver { };鈥ㄢ�� /// <summary>鈥� /// 椤圭洰鍚姩鏃剁綉缁滄煡璇⑩�� /// </summary>鈥� void checkSomeInfo()鈥� {鈥� var status = isNetworkAvailable(this);鈥� string internetStatus = "Available";鈥� if (!status)鈥� {鈥� internetStatus = "UnaVailable";鈥� }鈥� else鈥� {鈥� var isWifi = isWifiConnected(this);鈥� if (isWifi)鈥� {鈥� internetStatus = "WiFiConnect";鈥� }鈥� else鈥� {鈥� internetStatus = "MobileConnect";鈥� }鈥� }鈥ㄢ�� int connectState = 0;鈥� if (internetStatus == "UnaVailable")鈥� {鈥� connectState = 0;鈥� }鈥� else if (internetStatus == "WiFiConnect")鈥� {鈥� connectState = 2;鈥� }鈥� else鈥� {鈥� connectState = 1;鈥� }鈥� //ZigBee.Device.ZbGateway.CheckConnection(connectState);鈥� }鈥ㄢ�� /// <summary>鈥� /// 缃戠粶鏄惁鍙敤鈥� /// </summary>鈥� /// <returns><c>true</c>, if network available was ised, <c>false</c> otherwise.</returns>鈥� /// <param name="context">Context.</param>鈥� bool isNetworkAvailable(Context context)鈥� {鈥� var cm = (ConnectivityManager)context.GetSystemService(ConnectivityService);鈥ㄢ�� if (cm == null || cm.ActiveNetworkInfo == null)鈥� {鈥� //褰撳墠缃戠粶涓嶅彲鐢ㄢ�� return false;鈥� }鈥� else鈥� {鈥� return cm.ActiveNetworkInfo.IsAvailable;鈥� }鈥� }鈥ㄢ�� /// <summary>鈥� /// 缃戠粶鏄惁杩炴帴鈥� /// </summary>鈥� /// <returns><c>true</c>, if wifi connected was ised, <c>false</c> otherwise.</returns>鈥� /// <param name="context">Context.</param>鈥� bool isWifiConnected(Context context)鈥� {鈥� if (context != null)鈥� {鈥� var cm = (ConnectivityManager)context.GetSystemService(ConnectivityService);鈥ㄢ�� var mWiFiNetworkInfo = cm.GetNetworkInfo(ConnectivityType.Wifi);鈥� if (Android.Net.NetworkInfo.State.Connected == mWiFiNetworkInfo.GetState())鈥� {鈥� //褰撳墠缃戠粶鏄疻i-Fi杩炴帴鈥� return true;鈥� }鈥ㄢ�� var moWiFiNetworkInfo = cm.GetNetworkInfo(ConnectivityType.Mobile);鈥� if (Android.Net.NetworkInfo.State.Connected == moWiFiNetworkInfo.GetState())鈥� {鈥� //褰撳墠缃戠粶鏄疢obile杩炴帴鈥� return false;鈥� }鈥� }鈥� return false;鈥� } } public class JpushNotificationReceiver : BroadcastReceiver @@ -149,7 +225,10 @@ String message = bundle.GetString(JPushInterface.ExtraAlert); System.Console.WriteLine(TAG, "message : " + message); String extras = bundle.GetString(JPushInterface.ExtraExtra); - System.Console.WriteLine(TAG, "extras : " + extras); + System.Console.WriteLine(TAG, "extras : " + extras); + + //澶勭悊鏋佸厜娑堟伅鎺ㄩ�佺殑閫昏緫鍑芥暟 + Shared.Phone.UserCenter.HdlJiguangMsgPushLogic.Current.AdjustJiguangMsgPush(title, message, extras); } /// <summary> /// 鎵撳紑娑堟伅鏄剧ず鐣岄潰 -- Gitblit v1.8.0