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/MonitorFragment.cs | 237 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 files changed, 237 insertions(+), 0 deletions(-) diff --git a/ZigbeeApp/GateWay.Droid/FengLinVideo/Forms/MonitorFragment.cs b/ZigbeeApp/GateWay.Droid/FengLinVideo/Forms/MonitorFragment.cs new file mode 100755 index 0000000..26311cf --- /dev/null +++ b/ZigbeeApp/GateWay.Droid/FengLinVideo/Forms/MonitorFragment.cs @@ -0,0 +1,237 @@ +锘� +using System; +using Android.App; +using Android.OS; +using Android.Content.Res; +using Android.Graphics; +using Android.Views; +using Android.Widget; +using Com.ETouchSky; +using Org.Json; +using Com.Tool; +using GateWay.Droid.FengLinVideo.Interface; +using Java.Util; +using GateWay.Droid.FengLinVideo.widget; +using Java.Text; + +namespace GateWay.Droid.FengLinVideo.Forms +{ + + public class MonitorFragment : Fragment, View.IOnClickListener, View.IOnTouchListener,VideoState + { + private View mView; + private VideoPhone mPhone; + private RelativeLayout rlScreenshot; + private ImageView imgScreenshot; + private TextView tvScreenshot; + + private RelativeLayout rlUnlock; + private ImageView imgUnlock; + private TextView tvUnlock; + private System.Threading.Thread thread = null; + + public MonitorFragment(VideoPhone phone) + { + mPhone = phone; + } + + 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_monitor, container, false); + + iniView(); + + return mView; + } + + private void iniView() + { + // + rlScreenshot = (RelativeLayout)mView.FindViewById(Resource.Id.rl_sceenshot); + imgScreenshot = (ImageView)mView.FindViewById(Resource.Id.icon_screenshot); + tvScreenshot = (TextView)mView.FindViewById(Resource.Id.tv_screenshot); + + rlUnlock = (RelativeLayout)mView.FindViewById(Resource.Id.rl_unlock); + imgUnlock = (ImageView)mView.FindViewById(Resource.Id.icon_unlock); + tvUnlock = (TextView)mView.FindViewById(Resource.Id.tv_unlock); + + rlScreenshot.SetOnClickListener(this); + rlUnlock.SetOnClickListener(this); + + rlScreenshot.SetOnTouchListener(this); + rlUnlock.SetOnTouchListener(this); + } + + //寮�閿� + 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() + { + try + { + //寮�閿佹垚鍔燂紝15绉掑唴涓嶇粰鍐嶇偣鍑绘寜閽� + rlUnlock.Enabled = false; + imgUnlock.SetImageResource(Resource.Drawable.unlock_disable); + tvUnlock.SetTextColor(new Color(Activity.GetColor(Resource.Color.color_disable))); + if (thread != null) + { + try + { + thread.Interrupt(); + } + catch { } + thread = null; + } + thread = new System.Threading.Thread(() => + { + try + { + System.Threading.Thread.Sleep(15 * 1000); + Activity.RunOnUiThread(() => + { + try + { + rlUnlock.Enabled = true; + imgUnlock.SetImageResource(Resource.Drawable.unlock); + tvUnlock.SetTextColor(new Color(Activity.GetColor(Resource.Color.text_color))); + } + catch { } + }); + } + catch { } + }); + + thread.Start(); + } + catch { } + } + + public void OnClick(View v) + { + // + if (v.Equals(rlUnlock)) + { + if (mPhone != null) + unlock(); + } + else if (v.Equals(rlScreenshot)) + { + //鏈夎棰戣繃鏉ュ彲璋冪敤姝ゆ帴鍙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); + } + } + } + } + + public bool OnTouch(View v, MotionEvent e) + { + if (e.Action == MotionEventActions.Down) + { + if (v.Equals(rlScreenshot)) + { + imgScreenshot.Selected = true; + tvScreenshot.Selected = true; + } + else if (v.Equals(rlUnlock)) + { + imgUnlock.Selected = true; + tvUnlock.Selected = true; + } + } + else if (e.Action == MotionEventActions.Up) + { + if (v.Equals(rlScreenshot)) + { + imgScreenshot.Selected = false; + tvScreenshot.Selected = false; + } + else if (v.Equals(rlUnlock)) + { + imgUnlock.Selected = false; + tvUnlock.Selected = false; + } + } + else + { + // + } + return false; + } + + public void onPhoneEvent(string msg) + { + try + { + // + TextProtocol tp = new TextProtocol(); + tp.Parse(msg); + string event1 = tp.GetString("event"); + + switch (event1) + { + case "EVT_HangUp": + break; + case "EVT_RECV_CUSTOM_DATA": + updataUnlockState(); + break; + case "EVT_SnapAck": + break; + } + } + catch (Exception e) + { + string error = e.Message; + } + } + + public override void OnDestroy() + { + base.OnDestroy(); + + if (thread != null) + { + try + { + thread.Interrupt(); + } + catch { } + thread = null; + } + } + } +} -- Gitblit v1.8.0