| | |
| | | using System; |
| | | using HDL_ON.Entity; |
| | | using System.Collections.Generic; |
| | | using Shared; |
| | | |
| | | namespace HDL_ON.UI.UI2.FuntionControlView.VideoDoorLock |
| | | { |
| | | /// <summary> |
| | | /// 萤石视频门锁公共方法类 |
| | | /// </summary> |
| | | public class CommonMethod |
| | | { |
| | | public CommonMethod() |
| | | { |
| | | } |
| | | |
| | | private Loading loading; |
| | | private static CommonMethod commonMethod = null; |
| | | |
| | | public static CommonMethod Current |
| | |
| | | } |
| | | |
| | | } |
| | | |
| | | #region --------- 跳转到Android那边的方法(萤石视频门锁) -------- |
| | | /// <summary> |
| | | /// 添加设备到云端 |
| | | /// <paramref name="devSerial"/>设备序列号</param> |
| | | /// </summary> |
| | | public void SkipAddDeviceActivity(string devSerial) |
| | | { |
| | | if (string.IsNullOrEmpty(devSerial)) return; |
| | | new System.Threading.Thread(() => |
| | | { |
| | | var list = VideDoorLockSend.Current.GetVideoDoorLockDeviceList(SPK.VideoDoorLock); |
| | | if (list.Count > 0) |
| | | { |
| | | var function = list.Find((o) => o.sid == devSerial); |
| | | if (function != null) |
| | | { |
| | | this.SaveFunctionFile(function); |
| | | } |
| | | } |
| | | }) |
| | | { IsBackground = true }.Start(); |
| | | //未实现 |
| | | #if __IOS__ |
| | | |
| | | #else |
| | | |
| | | #endif |
| | | |
| | | } |
| | | /// <summary> |
| | | /// 打开实时视频画面 |
| | | /// </summary> |
| | | /// <param name="deviceSerial">设备序列号</param> |
| | | /// <param name="deviceId">设备id(云端上deviceId)</param> |
| | | /// <param name="spk">设备spk(云雀上定义好的)</param> |
| | | public void SkipRTVActivity(string deviceSerial, string deviceId, string spk) |
| | | { |
| | | Video.View.ShowDialog.Currnet.ClickBox(Language.StringByID(StringId.laizimenlinghujiao), (dialog) => |
| | | { |
| | | dialog.Close(); |
| | | }, (dialog) => |
| | | { |
| | | dialog.Close(); |
| | | }); |
| | | #if __IOS__ |
| | | #else |
| | | #endif |
| | | //jumpToEZRealPlayActivity(Shared.Application.Activity, deviceId, deviceSerial, spk) |
| | | } |
| | | /// <summary> |
| | | /// 浏览历史记录 |
| | | /// </summary> |
| | | public void SkipRecordActivity() |
| | | { |
| | | //未实现 |
| | | //this.InitializationAndroidData(); |
| | | // |
| | | } |
| | | /// <summary> |
| | | /// 临时密码开门 |
| | | /// </summary> |
| | | public void SkipPSWActivity() |
| | | { |
| | | //jumpTempPasswordActivity(Application.Activity, deviceId); |
| | | } |
| | | |
| | | /// <summary> |
| | | /// 初始化萤石SDK(实际就是传参数,多次调用也没有影响) |
| | | /// </summary> |
| | | public void InitializationAndroidData(Action<bool> action) |
| | | { |
| | | bool isBool = true; |
| | | this.SunThread(() => |
| | | { |
| | | try |
| | | { |
| | | //先获取萤石云子账号token |
| | | var ezChildAccessToken = VideDoorLockSend.Current.GetEZGetChildToken(); |
| | | this.MainThread(() => |
| | | { |
| | | if (string.IsNullOrEmpty(ezChildAccessToken)) |
| | | { |
| | | //Token |
| | | isBool = false; |
| | | return; |
| | | } |
| | | Application.RunOnMainThread(() => |
| | | { |
| | | #if __IOS__ |
| | | //iOS |
| | | //初始化萤石云SDK,中文国内key、英文海外key 开发者账号使用应用包名申请的APPKEY,不同包名应用需配置不同的APPKEY |
| | | EZSDK.IOS.EZSDK.SharedInstance().InitLibWithAppKey("1aa98a90489b4838b966b57018b4b04b", "1aa98a90489b4838b966b57018b4b04b"); |
| | | //1.设置所需河东的AccessToken和RefreshToken、域名地址 |
| | | EZSDK.IOS.EZSDK.SharedInstance().SetHDlAccessToken(UserVideoDoorLockInfo.Current.LoginTokenString, UserVideoDoorLockInfo.Current.RefreshToken); |
| | | EZSDK.IOS.EZSDK.SharedInstance().SetRequestHttpsHostAndPlatform(OnAppConfig.Instance.RequestHttpsHost, 1, DB_ResidenceData.Instance.CurrentRegion.id); |
| | | //2.设置萤石子账号的AccessToken到SDK |
| | | EZSDK.IOS.EZSDK.SharedInstance().SetEZAccessToken(ezChildAccessToken); |
| | | ////3.打开摄像头设备列表页面 |
| | | EZSDK.IOS.EZSDK.SharedInstance().Go2EZvizMonitor(); |
| | | //EZSDK.IOS.EZDeviceInfo info = new EZSDK.IOS.EZDeviceInfo(); |
| | | //info.de |
| | | //EZSDK.IOS.EZSDK.Play(info); |
| | | #else |
| | | //Android |
| | | //1.设置所需河东的token、域名地址 |
| | | //2.设置萤石子账号的token |
| | | //3.打开摄像头设备列表页面 |
| | | ((BaseActivity)Shared.Application.Activity).SetCamera(b => |
| | | { |
| | | if (b) |
| | | { |
| | | ((BaseActivity)Shared.Application.Activity).SetPermission(result => |
| | | { |
| | | if (result) |
| | | { |
| | | Android.Content.Intent intent = new Android.Content.Intent(); |
| | | var bundle = new Android.OS.Bundle(); |
| | | //传递name参数为tinyphp |
| | | bundle.PutString("EzChildAccessToken", ezChildAccessToken); |
| | | bundle.PutString("HdlToken", UserInfo.Current.LoginTokenString); |
| | | bundle.PutString("HdlrefreshToken", UserInfo.Current.RefreshToken); |
| | | bundle.PutString("Url", OnAppConfig.Instance.RequestHttpsHost); |
| | | bundle.PutString("EzvizAppKey", "1aa98a90489b4838b966b57018b4b04b"); |
| | | bundle.PutInt("Platform", 1); |
| | | bundle.PutString("HomeId", DB_ResidenceData.Instance.CurrentRegion.id); |
| | | intent.PutExtras(bundle); |
| | | //intent.SetComponent(new Android.Content.ComponentName(Shared.Application.Activity, "com.videogo.MainActivity")); |
| | | //Shared.Application.Activity.StartActivity(intent); |
| | | } |
| | | }, "android.permission.RECORD_AUDIO"); |
| | | |
| | | } |
| | | }); |
| | | #endif |
| | | }); |
| | | |
| | | }); |
| | | |
| | | } |
| | | catch (Exception e) |
| | | { |
| | | } |
| | | finally |
| | | { |
| | | this.MainThread(() => |
| | | { |
| | | action?.Invoke(isBool); |
| | | }); |
| | | } |
| | | }); |
| | | } |
| | | /// <summary> |
| | | /// 更换住宅 |
| | | /// </summary> |
| | | /// <param name="home">对象</param> |
| | | public void ChangeCurrHome(RegionInfoRes home) |
| | | { |
| | | if (DB_ResidenceData.Instance.CurrentRegion.id == home.id || string.IsNullOrEmpty(home.id)) return; |
| | | |
| | | } |
| | | #endregion |
| | | |
| | | /// <summary> |
| | | /// 萤石视频门锁的图标 |
| | | /// <param name="comerom">来自那里</param> |
| | | /// </summary> |
| | | public string GetVideoDoorLockIcon(Comerom comerom) |
| | | { |
| | |
| | | } |
| | | |
| | | } |
| | | #region --------- 功能文件保存,删除 -------- |
| | | /// <summary> |
| | | /// 保存本地文件 |
| | | /// </summary> |
| | | /// <param name="function">当前设备</param> |
| | | public void SaveFunctionFile(Function function) |
| | | { |
| | | if (function == null) return; |
| | | function.AssembleStatus(); |
| | | function.SaveFunctionFile(); |
| | | FunctionList.List.IniFunctionList(function.savePath, true); |
| | | MainPage.Log($"文件保存->{function.name}-->{function.spk}"); |
| | | } |
| | | |
| | | /// <summary> |
| | | /// 删除本地文件 |
| | | /// </summary> |
| | | /// <param name="function">当前设备</param> |
| | | public void DeleteFunction(Function function) |
| | | { |
| | | if (function == null) return; |
| | | FunctionList.List.DeleteFunction(function); |
| | | MainPage.Log($"文件删除->{function.name}-->{function.spk}"); |
| | | } |
| | | #endregion |
| | | /// <summary> |
| | | /// 获取Loading对象 |
| | | /// </summary> |
| | | /// <returns></returns> |
| | | public Loading Loading |
| | | { |
| | | get |
| | | { |
| | | if (loading == null) |
| | | { |
| | | loading = new Loading(); |
| | | } |
| | | if (MainPage.BasePageView.ChildrenCount < 1) |
| | | { |
| | | return loading; |
| | | } |
| | | View view = MainPage.BasePageView.GetChildren(MainPage.BasePageView.ChildrenCount - 1); |
| | | if (view is FrameLayout) |
| | | { |
| | | ((FrameLayout)view).AddChidren(loading); |
| | | } |
| | | else if (view is PageLayout) |
| | | { |
| | | ((PageLayout)view).AddChidren(loading); |
| | | } |
| | | return loading; |
| | | } |
| | | |
| | | } |
| | | /// <summary> |
| | | /// 获取萤石视频门锁列表 |
| | | /// </summary> |
| | |
| | | { |
| | | var list = FunctionList.List.GetVideoDoorLockList(); |
| | | #if DEBUG |
| | | list.Add(new Function { name = "视频门锁一", sid = "23456789", spk = SPK.VideoDoorLock }); |
| | | list.Add(new Function { name = "视频门锁二", sid = "2345678922", spk = SPK.VideoDoorLock }); |
| | | //list.Add(new Function { name = "视频门锁一", sid = "23456789", spk = SPK.VideoDoorLock }); |
| | | //list.Add(new Function { name = "视频门锁二", sid = "2345678922", spk = SPK.VideoDoorLock }); |
| | | #endif |
| | | return list; |
| | | } |
| | | #region ---------自定义线程(子线程,主线程)-------- |
| | | /// <summary> |
| | | /// 子线程 |
| | | /// </summary> |
| | | /// <paramref name="tipType"/>是否要提示错误信息(默认显示)<paramref> |
| | | /// <param name="action"></param> |
| | | public void SunThread(Action action, TipType tipType = TipType.confirmation) |
| | | { |
| | | new System.Threading.Thread(() => |
| | | { |
| | | try |
| | | { |
| | | action?.Invoke(); |
| | | } |
| | | catch (Exception e) |
| | | { |
| | | this.ShowAlert(e, tipType); |
| | | } |
| | | }) |
| | | { IsBackground = true }.Start(); |
| | | |
| | | } |
| | | /// <summary> |
| | | /// 主线程(UI更新) |
| | | /// </summary> |
| | | /// <paramref name="tipType"/>是否要提示错误信息(默认显示)<paramref> |
| | | /// <param name="action"></param> |
| | | public void MainThread(Action action, TipType tipType = TipType.confirmation) |
| | | { |
| | | Application.RunOnMainThread(() => |
| | | { |
| | | try |
| | | { |
| | | action?.Invoke(); |
| | | } |
| | | catch (Exception e) |
| | | { |
| | | this.ShowAlert(e, tipType); |
| | | } |
| | | }); |
| | | |
| | | } |
| | | #endregion |
| | | #region --------- 提示框,确认框 -------- |
| | | /// <summary> |
| | | /// 对话框(只要程序报错的时候才用到) |
| | | /// </summary> |
| | | /// <paramref name="e"/>异常对象<paramref> |
| | | /// <paramref name="tipType"/>是否要提示错误信息(默认显示)<paramref> |
| | | private void ShowAlert(Exception e, TipType tipType) |
| | | { |
| | | |
| | | if (tipType != TipType.confirmation) |
| | | { |
| | | return; |
| | | } |
| | | Application.RunOnMainThread(() => |
| | | { |
| | | string msg = e.Message + "\r\n" + e.StackTrace; |
| | | Alert alert = new Alert("抱歉程序出错了.", "按\"确定\"能获取更详细的错误信息.", "取消", "确定"); |
| | | alert.Show(); |
| | | alert.ResultEventHandler += (alerts, isBool) => |
| | | { |
| | | alert.Dismiss(); |
| | | if (isBool) |
| | | { |
| | | StackTraceLog stackTraceLog = new StackTraceLog(msg); |
| | | stackTraceLog.Show(); |
| | | } |
| | | }; |
| | | }); |
| | | } |
| | | /// <summary> |
| | | /// 信息提示窗口,自动关闭 |
| | | /// </summary> |
| | | /// <param name="msg">提示错误文本</param> |
| | | public void ShowTip(string msg, int time = 2) |
| | | { |
| | | Application.RunOnMainThread(() => |
| | | { |
| | | new PublicAssmebly().TipMsgAutoClose(msg, false, time * 1000); |
| | | }); |
| | | } |
| | | #endregion |
| | | /// <summary> |
| | | /// 弹框类型 |
| | | /// </summary> |
| | | public enum TipType |
| | | { |
| | | none,//无提示 |
| | | flicker,//闪烁框 |
| | | confirmation//确认框 |
| | | } |
| | | /// <summary> |
| | | /// 表示来自那个界面 |
| | | /// </summary> |
| | | public enum Comerom |
| | | { |
| | | function,//功能 |
| | | collect,//收藏 |
| | | room,//房间 |
| | | push,//推送 |
| | | } |
| | | } |
| | | } |