From 80faceb86399017851f9f72feaaef868a37ff23f Mon Sep 17 00:00:00 2001
From: wxr <464027401@qq.com>
Date: 星期五, 26 三月 2021 10:50:35 +0800
Subject: [PATCH] Merge remote-tracking branch 'origin/lss' into temp-wxr

---
 HDL-ON_Android/FengLinVideo/Form/ReverseCallFragment.cs |  404 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++
 1 files changed, 404 insertions(+), 0 deletions(-)

diff --git a/HDL-ON_Android/FengLinVideo/Form/ReverseCallFragment.cs b/HDL-ON_Android/FengLinVideo/Form/ReverseCallFragment.cs
new file mode 100644
index 0000000..ba0102f
--- /dev/null
+++ b/HDL-ON_Android/FengLinVideo/Form/ReverseCallFragment.cs
@@ -0,0 +1,404 @@
+锘�
+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.Common;
+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 ReverseCallFragment : Fragment, View.IOnClickListener, VideoState
+    {
+        private VideoPhone mPhone;
+        private string param = "";
+        private bool isCalling = false;
+
+        private View mView;
+
+        private ImageView screenshotImg;// 鎴浘
+        private ImageView unlockImg;// 寮�閿�
+        private LinearLayout answerLayout; // 鎺ュ惉
+        private ImageView hangupImg; // 鎺ュ惉
+        private ImageView answerImg;// 鎸傛柇
+        private TextView hangupText;
+
+        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 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()
+        {
+            screenshotImg = (ImageView)mView.FindViewById(Resource.Id.callScreenshotImg);//
+            unlockImg = (ImageView)mView.FindViewById(Resource.Id.callUnlockImg);//
+            tvTip = (TextView)mView.FindViewById(Resource.Id.callTipText);
+            answerLayout = (LinearLayout)mView.FindViewById(Resource.Id.callAnswerLayout);
+            hangupImg = (ImageView)mView.FindViewById(Resource.Id.callHangupImg);
+            answerImg = (ImageView)mView.FindViewById(Resource.Id.callAnswerImg);
+            hangupText = (TextView)mView.FindViewById(Resource.Id.callHangupText);
+
+            screenshotImg.SetOnClickListener(this);
+            unlockImg.SetOnClickListener(this);
+            hangupImg.SetOnClickListener(this);
+            answerImg.SetOnClickListener(this);
+
+            hangupText.SetText(GetString(Resource.String.video_not_answer), null);
+            tvTip.SetText(GetString(Resource.String.calling), null);
+        }
+
+        /// <summary>
+        /// 涓�鑸槸鎺ㄩ�佽繃鐨勬潵鐢典俊鎭椂璋冪敤姝ゆ帴鍙f墦寮�瑙嗛绐楀彛銆傜劧鍚庡彲璋冪敤mPhone.acceptRing(param);鎺ユ敹鏉ョ數淇℃伅
+        /// </summary>
+        /// <param name="param"></param>
+        private void ReverseCall(string param)
+        {
+            if (mPhone != null)
+            {
+                mPhone.ReverseCall(param);
+            }
+        }
+
+        /// <summary>
+        /// 寮�閿�
+        /// </summary>
+        private void Unlock()
+        {
+            //寮�閿侊紝褰撴敹鍒版潵鐢典俊鎭椂鍙繘琛屽紑閿佹搷浣�
+            if (mPhone != null)
+            {
+                try
+                {
+                    unlockImg.Selected = true;
+                    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;
+                }
+            }
+        }
+
+        /// <summary>
+        /// 鏇存柊寮�閿佹寜閽姸鎬�,寮�閿佹垚鍔燂紝15绉掑唴涓嶇粰鍐嶇偣鍑绘寜閽�
+        /// </summary>
+        private void UpdataUnlockState()
+        {
+            try
+            {
+                if (unlockImg == null) return;
+
+                unlockImg.Enabled = false;
+
+                new Thread(() =>
+                {
+                    Thread.Sleep(15 * 1000);
+                    Activity.RunOnUiThread(() =>
+                    {
+                        if (unlockImg != null)
+                            unlockImg.Enabled = true;
+                    });
+                }).Start();
+            }
+            catch { }
+        }
+
+        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;
+        }
+
+        /// <summary>
+        /// 閫氳瘽璁板綍璁℃椂鍣紝浠庢媺娴佹垚鍔熷紑濮嬭绠楁椂闂�
+        /// </summary>
+        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)
+        {
+            try
+            {
+                Activity.RunOnUiThread(() =>
+                {
+                    try
+                    {
+                        Time++;
+                        if (tvTip != null)
+                            tvTip.SetText(GetTime(Time), null);
+                    }
+                    catch { }
+                });
+            }
+            catch { }
+        }
+
+        /// <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_RECV_CUSTOM_DATA":
+                        string data = tp.GetString("data");
+                        UpdataUnlockState();
+                        break;
+                    case "EVT_StartStream":// 鎷夋祦鎴愬姛锛屽紑濮嬭褰曢�氳瘽鏃堕棿
+                        isCalling = true;
+                        TimeStarts();
+                        hangupText.SetText(GetString(Resource.String.video_hang_up), null);
+                        break;
+                    case "EVT_StopStream":
+                        if (isCalling == false)
+                            PostReject();// 鎷掓帴
+                        else
+                            PostHangup();// 姝e父鎸傛柇
+                        break;
+                    case "EVT_SnapAck":
+                        int error = tp.GetInt("error");
+                        string filePath = tp.GetString("filePath");
+                        if (error == 0)
+                        {
+                            screenshotImg.Selected = true;
+                            PostScreenshot(filePath);
+                        }
+                        else
+                        {
+                            screenshotImg.Selected = false;
+                        }
+                        break;
+                }
+            }
+            catch (Exception e)
+            {
+                string error = e.Message;
+            }
+        }
+
+        public void OnClick(View v)
+        {
+            if (v.Equals(answerImg))
+            {
+                //鎺ユ敹鏉ョ數
+                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=0r\n" + "UserData=%s\r\n", UserData);
+                        mPhone.AcceptRing(param);
+                        answerLayout.Visibility = ViewStates.Gone;
+                        PostAnswer();
+                    }
+                }
+            }
+            else if (v.Equals(hangupImg))
+            {
+                if (mPhone != null)
+                {
+                    mPhone.HangUp();
+                    TimeEnd();
+                }
+                Activity.Finish();
+            }
+            else if (v.Equals(screenshotImg))
+            {
+                //鏈夎棰戣繃鏉ュ彲璋冪敤姝ゆ帴鍙h繘琛屾媿鐓�
+                if (mPhone != null)
+                {
+                    // 鍐呴儴鍌ㄥ瓨/DCIM/Camera/.....jpg
+                    screenshotImg.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);
+                }
+            }
+            else if (v.Equals(unlockImg))
+            {
+                Unlock();
+            }
+        }
+
+        /// <summary>
+        /// post 鎴浘
+        /// </summary>
+        /// <param name="path">鎴浘淇濈暀鐨勮矾寰�</param>
+        private void PostScreenshot(string path)
+        {
+            new Thread(() =>
+            {
+                try
+                {
+                    string[] str = path.Split("/");
+                    string img_name = str.GetValue(str.Length - 1).ToString().Replace(".jpg", "");
+                    byte[] images = FileUtlis.Files.ReadFileForPath(path);
+                    Dictionary<string, object> d = new Dictionary<string, object>();
+                    d.Add("callId", VideoActivity.CallId);
+                    d.Add("images", images);
+                    d.Add("imagesName", img_name);
+                    string jsonString = HttpUtil.GetSignRequestJson(d);
+
+                    string url = "/home-wisdom/app/fl/vi/screenshot";
+                    ResponsePackNew response = HttpUtil.RequestHttpsPost(url, jsonString);
+                    Log.Info("FengLinVideo", "Post Screenshot Response code=" + response.Code);
+                }
+                catch { }
+
+            }).Start();
+        }
+
+        /// <summary>
+        /// post 鎺ュ惉鐢佃瘽璁板綍
+        /// </summary>
+        private void PostAnswer()
+        {
+            new Thread(() =>
+            {
+                try
+                {
+                    Dictionary<string, object> d = new Dictionary<string, object>();
+                    d.Add("uuid", VideoActivity.UUId);//涓版灄璇锋眰鐨勫敮涓�id string
+                    d.Add("cmtID", VideoActivity.CmtID);//涓版灄绀惧尯id string
+                    d.Add("roomno", VideoActivity.Roomno);//涓版灄鎴块棿鍙� string
+                    d.Add("unitno", VideoActivity.Unitno);//涓版灄妤兼爧鍙� string
+                    d.Add("HomeID", VideoActivity.HomeID);//涓版灄浣忓畢id string
+                    d.Add("callId", VideoActivity.CallId);//鍛煎彨璁板綍id int
+                    string jsonString = HttpUtil.GetSignRequestJson(d);
+
+                    string url = "/home-wisdom/app/fl/vi/answer";
+                    ResponsePackNew response = HttpUtil.RequestHttpsPost(url, jsonString);
+                    Log.Info("FengLinVideo", "Post Answer Response code=" + response.Code);
+                }
+                catch { }
+
+            }).Start();
+        }
+
+        /// <summary>
+        /// post 鎸傛柇鐢佃瘽璁板綍
+        /// </summary>
+        private void PostHangup()
+        {
+            new Thread(() =>
+            {
+                try
+                {
+                    Dictionary<string, object> d = new Dictionary<string, object>();
+                    d.Add("callId", VideoActivity.CallId);//鍛煎彨璁板綍id int
+                    d.Add("callDuration", Time);//閫氳瘽鏃堕暱锛堢锛� int
+                    string jsonString = HttpUtil.GetSignRequestJson(d);
+
+                    string url = "/home-wisdom/app/fl/vi/hang-up";
+                    ResponsePackNew response = HttpUtil.RequestHttpsPost(url, jsonString);
+                    Log.Info("FengLinVideo", "Post Hangup Response code=" + response.Code);
+                }
+                catch { }
+
+            }).Start();
+        }
+
+        /// <summary>
+        /// post 鎷掓帴璁板綍
+        /// </summary>
+        private void PostReject()
+        {
+            new Thread(() =>
+            {
+                try
+                {
+                    Dictionary<string, object> d = new Dictionary<string, object>();
+                    d.Add("callId", VideoActivity.CallId);//鍛煎彨璁板綍id int
+                    string jsonString = HttpUtil.GetSignRequestJson(d);
+
+                    string url = "/home-wisdom/app/fl/vi/reject";
+                    ResponsePackNew response = HttpUtil.RequestHttpsPost(url, jsonString);
+                    Log.Info("FengLinVideo", "Post Reject Response code=" + response.Code);
+                }
+                catch { }
+
+            }).Start();
+        }
+    }
+}

--
Gitblit v1.8.0