|
using System;
|
using System.Collections.Generic;
|
using System.Linq;
|
using System.Text;
|
using System.Threading;
|
using Android.App;
|
using Android.Content;
|
using Android.Icu.Text;
|
using Android.OS;
|
using Android.Runtime;
|
using Android.Util;
|
using Android.Views;
|
using Android.Widget;
|
using Com.ETouchSky;
|
using Com.Tool;
|
using HDL_ON.DAL.Server;
|
using HDL_ON_Android.FengLinVideo.Interface;
|
using Java.Util;
|
using Org.Json;
|
|
namespace HDL_ON_Android.FengLinVideo.Form
|
{
|
public class MonitorFragment : Fragment, View.IOnClickListener, VideoState
|
{
|
|
private View mView;
|
private VideoPhone mPhone;
|
|
// 截图
|
private LinearLayout screenshotLayout;
|
private ImageView screenImage;
|
private TextView ScreenText;
|
|
//开锁
|
private LinearLayout unlockLayout;
|
private ImageView unlockImag;
|
private TextView unlockText;
|
|
// 更新线程
|
public static Thread thread = null;
|
|
public MonitorFragment(VideoPhone phone)
|
{
|
this.mPhone = phone;
|
}
|
|
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()
|
{
|
screenshotLayout = (LinearLayout)mView.FindViewById(Resource.Id.icon_sceenshotLayout);
|
screenImage = (ImageView)mView.FindViewById(Resource.Id.icon_sceenshotImg);
|
ScreenText = (TextView)mView.FindViewById(Resource.Id.icon_sceenshotText);
|
|
unlockLayout = (LinearLayout)mView.FindViewById(Resource.Id.icon_unlockLayout);
|
unlockImag = (ImageView)mView.FindViewById(Resource.Id.icon_unlockImg);
|
unlockText = (TextView)mView.FindViewById(Resource.Id.icon_unlockText);
|
|
unlockLayout.SetOnClickListener(this);
|
screenshotLayout.SetOnClickListener(this);
|
}
|
|
/// <summary>
|
/// 开锁
|
/// </summary>
|
private void Unlock()
|
{
|
if (mPhone != null)
|
{
|
try
|
{
|
unlockImag.Selected = true;
|
JSONObject ht = new JSONObject();
|
ht.Put("command", "open");//固定参数
|
ht.Put("room_id", VideoActivity.Roomno);
|
ht.Put("devType", 7);
|
mPhone.SendCustomData(ht.ToString());
|
}
|
catch { }
|
}
|
}
|
|
/// <summary>
|
/// 更新开锁按钮状态
|
/// </summary>
|
private void UpdataUnlockState()
|
{
|
try
|
{
|
//开锁成功,15秒内不给再点击按钮
|
unlockLayout.Enabled = false;
|
if (thread != null)
|
{
|
try
|
{
|
thread.Interrupt();
|
}
|
catch { }
|
thread = null;
|
}
|
|
thread = new Thread(() =>
|
{
|
try
|
{
|
Thread.Sleep(15 * 1000);
|
|
Activity.RunOnUiThread(() =>
|
{
|
if (unlockLayout != null)
|
unlockLayout.Enabled = true;
|
});
|
}
|
catch { }
|
});
|
|
thread.Start();
|
}
|
catch { }
|
}
|
|
public void OnClick(View v)
|
{
|
//
|
if (v.Equals(unlockLayout))
|
{
|
if (mPhone != null)
|
Unlock();
|
}
|
else if (v.Equals(screenshotLayout))
|
{
|
|
//有视频过来可调用此接口进行拍照
|
if (mPhone != null)
|
{
|
// 内部储存/DCIM/Camera/.....jpg
|
screenImage.Selected = true;
|
SimpleDateFormat format = new SimpleDateFormat("yyyyMMddHHmmss");
|
string time = format.Format(new Date(SystemClock.CurrentThreadTimeMillis()));
|
string ss = Android.OS.Environment.ExternalStorageDirectory.Path + "/DCIM/Camera";
|
string path = ss + "/" + time + ".jpg";
|
mPhone.Snap(path);
|
}
|
}
|
}
|
|
/// <summary>
|
/// 通话状态回调方法
|
/// </summary>
|
/// <param name="msg"></param>
|
public void OnPhoneEvent(string msg)
|
{
|
try
|
{
|
//
|
TextProtocol tp = new TextProtocol();
|
tp.Parse(msg);
|
string event1 = tp.GetString("event");
|
|
switch (event1)
|
{
|
case "EVT_HangUp"://挂断
|
Activity.Finish();
|
break;
|
case "EVT_RECV_CUSTOM_DATA":
|
UpdataUnlockState();
|
break;
|
case "EVT_SnapAck":
|
int error = tp.GetInt("error");
|
string filePath = tp.GetString("filePath");
|
if (error == 0)
|
{
|
screenImage.Selected = true;
|
}
|
else
|
{
|
screenImage.Selected = false;
|
}
|
break;
|
}
|
}
|
catch { }
|
}
|
|
public override void OnDestroy()
|
{
|
base.OnDestroy();
|
|
if (thread != null)
|
{
|
try
|
{
|
thread.Interrupt();
|
}
|
catch { }
|
thread = null;
|
}
|
}
|
}
|
}
|