From d6fb0646531172f23648441c224cdcccd721b894 Mon Sep 17 00:00:00 2001 From: xm <1271024303@qq.com> Date: 星期一, 14 十二月 2020 09:59:01 +0800 Subject: [PATCH] 请合并代码,完成晾衣架最终功能。 --- ZigbeeApp/GateWay.Droid/FengLinVideo/Forms/ReverseCallFragment.cs | 309 +++++++++++++++++++++++++++++++++++++++++++++++++++ 1 files changed, 309 insertions(+), 0 deletions(-) diff --git a/ZigbeeApp/GateWay.Droid/FengLinVideo/Forms/ReverseCallFragment.cs b/ZigbeeApp/GateWay.Droid/FengLinVideo/Forms/ReverseCallFragment.cs new file mode 100755 index 0000000..4d01cc3 --- /dev/null +++ b/ZigbeeApp/GateWay.Droid/FengLinVideo/Forms/ReverseCallFragment.cs @@ -0,0 +1,309 @@ +锘� +using System; +using System.Threading; +using Android.App; +using Android.OS; +using Android.Views; +using Android.Widget; +using Com.ETouchSky; +using Com.Tool; +using GateWay.Droid.FengLinVideo.Interface; +using Java.Text; +using Org.Json; +using Java.Util; + +namespace GateWay.Droid.FengLinVideo.Forms +{ + public class ReverseCallFragment : Fragment, View.IOnClickListener, View.IOnTouchListener, VideoState + { + private VideoPhone mPhone; + private string param = ""; + + private View mView; + + private ImageView imgScreenshot; + private ImageView imgUnlock; + //private ImageView imgHangup; + //private ImageView imgCall; + + private RelativeLayout rlHangup; + private RelativeLayout rlCall; + + private TextView tvHangup; + private TextView tvCall; + private TextView tvTip; + + private System.Threading.Timer timer = null; + private int Time = 0; + + public ReverseCallFragment(VideoPhone _phone, string _param) + { + this.mPhone = _phone; + this.param = _param; + } + + public override void OnCreate(Bundle savedInstanceState) + { + base.OnCreate(savedInstanceState); + } + + public override View OnCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) + { + mView = inflater.Inflate(Resource.Layout.fragment_call, container, false); + + IniView(); + ReverseCall(param); + return mView; + } + + private void IniView() + { + + imgScreenshot = (ImageView)mView.FindViewById(Resource.Id.icon_screenshot);// + imgUnlock = (ImageView)mView.FindViewById(Resource.Id.icon_unlock);// + + tvTip = (TextView)mView.FindViewById(Resource.Id.tv_tip); + rlHangup = (RelativeLayout)mView.FindViewById(Resource.Id.rl_hangup); + //imgHangup = (ImageView)mView.FindViewById(Resource.Id.img_hangup); + tvHangup = (TextView)mView.FindViewById(Resource.Id.tv_hangup); + + rlCall = (RelativeLayout)mView.FindViewById(Resource.Id.rl_call); + //imgCall = (ImageView)mView.FindViewById(Resource.Id.img_call); + tvCall = (TextView)mView.FindViewById(Resource.Id.tv_call); + + imgScreenshot.SetOnClickListener(this); + imgUnlock.SetOnClickListener(this); + rlCall.SetOnClickListener(this); + rlHangup.SetOnClickListener(this); + + imgUnlock.SetOnTouchListener(this); + imgScreenshot.SetOnTouchListener(this); + + tvTip.SetText("鏉ョ數涓�...", null); + } + + private void ReverseCall(string param) + { + // + //涓�鑸槸鎺ㄩ�佽繃鐨勬潵鐢典俊鎭椂璋冪敤姝ゆ帴鍙f墦寮�瑙嗛绐楀彛銆傜劧鍚庡彲璋冪敤mPhone.acceptRing(param);鎺ユ敹鏉ョ數淇℃伅 + if (mPhone != null) + { + mPhone.ReverseCall(param); + } + } + + //寮�閿� + private void Unlock() + { + //寮�閿侊紝褰撴敹鍒版潵鐢典俊鎭椂鍙繘琛屽紑閿佹搷浣� + if (mPhone != null) + { + try + { + JSONObject ht = new JSONObject(); + ht.Put("command", "open");//鍥哄畾鍙傛暟 + ht.Put("room_id", 123); //鍔ㄦ�佸弬鏁� 锛屼紶閫掑紑闂ㄧ殑鎴块棿鍙枫�傝繖涓紑闂ㄥ彛璁板綍灏辫兘璁板綍璋佸紑鐨勯棬 + ht.Put("devType", 7); //鍥哄畾鍙傛暟 + mPhone.SendCustomData(ht.ToString()); + } + catch (Exception e) + { + string erro = e.Message; + } + } + } + + //鏇存柊寮�閿佹寜閽姸鎬� + private void UpdataUnlockState() + { + //寮�閿佹垚鍔燂紝15绉掑唴涓嶇粰鍐嶇偣鍑绘寜閽� + imgUnlock.Enabled = false; + imgUnlock.SetImageResource(Resource.Drawable.unlock_disable); + + new System.Threading.Thread(() => + { + System.Threading.Thread.Sleep(15 * 1000); + Activity.RunOnUiThread(() => + { + imgUnlock.Enabled = true; + imgUnlock.SetImageResource(Resource.Drawable.unlock); + }); + }).Start(); + } + + private string getTime(int time) + { + + int m = time / 60; + int s = time % 60; + + return unitFormat(m) + ":" + unitFormat(s); + + } + + private static string unitFormat(int i) + { + string retStr = null; + if (i >= 0 && i < 10) + retStr = "0" + i; + else + retStr = "" + i; + return retStr; + } + + // + private void TimeStarts() + { + try + { + if (timer != null) + timer.Dispose(); + + TimerCallback timerCallback = new TimerCallback(Tick); + timer = new System.Threading.Timer(timerCallback,null,0,1000); + + } + catch (Exception) { } + } + + private void TimeEnd() + { + Time = 0; + + if (timer != null) + { + timer.Dispose(); + timer = null; + } + } + + public void Tick(Object state) + { + Activity.RunOnUiThread(() => + { + Time++; + tvTip.SetText(getTime(Time), null); + }); + } + + public void onPhoneEvent(string msg) + { + try + { + // + TextProtocol tp = new TextProtocol(); + tp.Parse(msg); + string event1 = tp.GetString("event"); + + switch (event1) + { + case "EVT_RECV_CUSTOM_DATA": + UpdataUnlockState(); + break; + case "EVT_SnapAck": + break; + case "EVT_StartStream": + TimeStarts(); + break; + } + } + catch (Exception e) + { + string error = e.Message; + } + } + + public bool OnTouch(View v, MotionEvent e) + { + if (e.Action == MotionEventActions.Down) + { + if (v.Equals(rlCall)) + { + tvCall.Selected = true; + } + else if (v.Equals(rlHangup)) + { + tvHangup.Selected = true; + } + else if (v.Equals(imgUnlock)) + { + imgUnlock.Selected = true; + } + else if(v.Equals(imgScreenshot)) + { + imgScreenshot.Selected = true; + } + } + else if (e.Action == MotionEventActions.Up) + { + if (v.Equals(rlCall)) + { + tvCall.Selected = false; + } + else if (v.Equals(rlHangup)) + { + tvHangup.Selected = false; + } + else if (v.Equals(imgUnlock)) + { + imgUnlock.Selected = false; + } + else if (v.Equals(imgScreenshot)) + { + imgScreenshot.Selected = false; + } + } + return false; + } + + public void OnClick(View v) + { + if (v.Equals(rlCall)) + { + //鎺ユ敹鏉ョ數 + if (mPhone != null) + { + if (mPhone.IsRinging) + { + string UserData = "user text"; + //娉ㄦ剰锛歊equestAudio 璇锋眰瀵规柟闊抽锛孯equestVideo璇锋眰瀵规柟瑙嗛 SendAudio鍙戦�佹湰鍦伴煶棰� SendVideo 鍙戦�佹湰鍦拌棰� 涓�鑸棬鍙d笉鎺ユ敹鍒拌棰戯紝鎵�浠ユ渶濂借缃�0锛屽噺灏戞祦閲忔秷鑰� + string param = string.Format("RequestAudio=1\r\n" + "RequestVideo=1\r\n" + "SendAudio=1\r\n" + "SendVideo=1r\n" + "UserData=%s\r\n", UserData); + mPhone.AcceptRing(param); + } + } + rlCall.Visibility = ViewStates.Gone; + } + else if (v.Equals(rlHangup)) + { + if (mPhone != null) + { + mPhone.HangUp(); + TimeEnd(); + } + Activity.Finish(); + } + else if (v.Equals(imgScreenshot)) + { + //鏈夎棰戣繃鏉ュ彲璋冪敤姝ゆ帴鍙h繘琛屾媿鐓� + if (mPhone != null) + { + //鏈夎棰戣繃鏉ュ彲璋冪敤姝ゆ帴鍙h繘琛屾媿鐓� + if (mPhone != null) + { + + SimpleDateFormat format = new SimpleDateFormat("yyyyMMddHHmmss"); + string time = format.Format(new Date(SystemClock.CurrentThreadTimeMillis())); + + string ss = Android.OS.Environment.GetExternalStoragePublicDirectory(Android.OS.Environment.DirectoryPictures).AbsolutePath; + string path = ss + "/" + time + ".jpg"; + mPhone.Snap(path); + } + } + } + else if (v.Equals(imgUnlock)) + { + Unlock(); + } + } + } +} -- Gitblit v1.8.0