|
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))
|
{
|
//有视频过来可调用此接口进行拍照
|
if (mPhone != null)
|
{
|
//有视频过来可调用此接口进行拍照
|
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;
|
}
|
}
|
}
|
}
|