From d6119c2d7fe2f802dd224d77bf2d95eeeedb4526 Mon Sep 17 00:00:00 2001
From: xuxiuxi <xuxiuxi@454eff88-639b-444f-9e54-f578c98de674>
Date: 星期一, 10 七月 2017 16:08:15 +0800
Subject: [PATCH] 

---
 VisitFace/DemoForBsk/app/src/main/java/cn/com/basic/face/fragment/SurveillanceFragment.java |  175 +++++++++++++++++++++++++---------------------------------
 1 files changed, 75 insertions(+), 100 deletions(-)

diff --git a/VisitFace/DemoForBsk/app/src/main/java/cn/com/basic/face/fragment/SurveillanceFragment.java b/VisitFace/DemoForBsk/app/src/main/java/cn/com/basic/face/fragment/SurveillanceFragment.java
index 3788dfa..7fb2382 100644
--- a/VisitFace/DemoForBsk/app/src/main/java/cn/com/basic/face/fragment/SurveillanceFragment.java
+++ b/VisitFace/DemoForBsk/app/src/main/java/cn/com/basic/face/fragment/SurveillanceFragment.java
@@ -4,13 +4,17 @@
 import android.net.wifi.WifiManager;
 import android.os.Build;
 import android.os.Bundle;
+import android.os.Environment;
+import android.os.SystemClock;
 import android.text.format.Formatter;
+import android.util.Log;
 import android.view.SurfaceHolder;
 import android.view.SurfaceView;
 import android.view.View;
 import android.widget.ProgressBar;
 import android.widget.RadioButton;
 import android.widget.RadioGroup;
+import android.widget.RelativeLayout;
 import android.widget.TextView;
 
 import com.bsk.zhangbo.demoforbsk.R;
@@ -31,12 +35,13 @@
 import com.lidroid.xutils.view.annotation.event.OnClick;
 
 import java.io.BufferedReader;
+import java.io.DataOutputStream;
 import java.io.File;
-import java.io.FileInputStream;
 import java.io.FileReader;
-import java.io.InputStream;
-import java.io.InputStreamReader;
-import java.text.SimpleDateFormat;
+import java.net.InetAddress;
+import java.net.NetworkInterface;
+import java.net.SocketException;
+import java.util.*;
 
 public class SurveillanceFragment extends BaseFragment {
 
@@ -60,10 +65,10 @@
     private TextView fragment_surveillance_enter_timer;
     @ViewInject(R.id.fragment_surveillance_exit_timer)
     private TextView fragment_surveillance_exit_timer;
-    @ViewInject(R.id.fragment_supervisory_enter_progress_bar)
-    private ProgressBar fragment_supervisory_enter_progress_bar;
-    @ViewInject(R.id.fragment_supervisory_exit_progress_bar)
-    private ProgressBar fragment_supervisory_exit_progress_bar;
+    @ViewInject(R.id.fragment_supervisory_exit_camera_relative_layout)
+    private RelativeLayout fragment_supervisory_exit_camera_relative_layout;
+    @ViewInject(R.id.fragment_supervisory_enter_camera_relative_layout)
+    private RelativeLayout fragment_supervisory_enter_camera_relative_layout;
 
     static boolean useNative = false;
 
@@ -84,6 +89,10 @@
         } else {
             useNative = true;
         }
+        if (CommonVariables.FACE_SERVER) {
+            useNative = false;
+        }
+        //useNative = false;
         if (useNative) {
             System.loadLibrary("cvface_api");
             System.loadLibrary("opencv_java3");
@@ -92,13 +101,47 @@
             System.loadLibrary("protoc");
             System.loadLibrary("rtspface");
             RtspFaceNative.init();
-//            RtspFaceNative.setLocalIP("192.168.1.10");
-//            RtspFaceNative.setLocalIP("192.168.1.106");//鑷繁鎵嬫満ip
-//            RtspFaceNative.setLocalIP("192.168.1.203");
-//            RtspFaceNative.setLocalIP("192.168.1.205");
             WifiManager wm = (WifiManager) MainActivity.getInstance().getSystemService(Context.WIFI_SERVICE);
             String ip = Formatter.formatIpAddress(wm.getConnectionInfo().getIpAddress());
-            RtspFaceNative.setLocalIP(ip);
+            String ipAddress = null;
+            try {
+                for (Enumeration<NetworkInterface> en = NetworkInterface.getNetworkInterfaces(); en.hasMoreElements();) {
+                    NetworkInterface intf = en.nextElement();
+                    for (Enumeration<InetAddress> enumIpAddr = intf.getInetAddresses(); enumIpAddr.hasMoreElements();) {
+                        InetAddress inetAddress = enumIpAddr.nextElement();
+                        if (!inetAddress.isLoopbackAddress()) {
+                            String ip1 = inetAddress.getHostAddress().toString();
+                            if (ip1.contains("192.")) {
+                                ipAddress = ip1;
+                            }
+                        }
+                    }
+                }
+            } catch (SocketException ex) {}
+
+            try{
+                //Process su = Runtime.getRuntime().exec("su");
+                //DataOutputStream outputStream = new DataOutputStream(su.getOutputStream());
+
+                //outputStream.writeBytes("busybox ifconfig wlan0 down\n");
+                //outputStream.flush();
+                //Thread.sleep(5000);
+//                outputStream.writeBytes("busybox ifconfig wlan0 hw ether  f4:8b:32:62:4f:89\n");
+//                outputStream.flush();
+
+                //outputStream.writeBytes("exit\n");
+                //outputStream.flush();
+                //su.waitFor();
+                /*
+                busybox ifconfig wlan0 hw ether  AC:83:F3:42:19:CE
+
+
+                 */
+            }catch(Exception e){
+                e.printStackTrace();
+            }
+//            outputStream.writeBytes("busybox ifconfig wlan0 hw ether  00:e0:2c:31:1a:ba\n");
+            RtspFaceNative.setLocalIP(ipAddress);
         }
     }
 
@@ -123,107 +166,39 @@
 
     @Override
     protected void initViews(View view, Bundle savedInstanceState) {
+        if (CommonVariables.FACE_SERVER) {
+            fragment_supervisory_enter_camera_relative_layout.addView(MainActivity.getInstance().mPreview);
+            fragment_supervisory_enter_camera_relative_layout.addView(MainActivity.getInstance().mDraw);
+
+        }
         fragment_supervisory_enter_camera.getHolder().addCallback(new SurfaceHolder.Callback() {
-            @Override
             public void surfaceCreated(SurfaceHolder holder) {
-                fragment_supervisory_enter_progress_bar.setVisibility(View.INVISIBLE);
-                RtspFaceNative.setSurface(Integer.parseInt(CommonVariables.Camera.IN), fragment_supervisory_enter_camera.getHolder().getSurface());
-                RtspFaceNative.createPlayer(Integer.parseInt(CommonVariables.Camera.IN), DeviceMng.getInstance().getCamera1Address());
-                RtspFaceNative.setFaceCallback(Integer.parseInt(CommonVariables.Camera.IN), "cn/com/basic/face/util/RtspFaceNative", "faceCallBack");
+                if (useNative) {
+                    RtspFaceNative.setSurface(Integer.parseInt(CommonVariables.Camera.IN), fragment_supervisory_enter_camera.getHolder().getSurface());
+                    RtspFaceNative.createPlayer(Integer.parseInt(CommonVariables.Camera.IN), DeviceMng.getInstance().getCamera1Address());
+                    RtspFaceNative.setFaceCallback(Integer.parseInt(CommonVariables.Camera.IN), "cn/com/basic/face/util/RtspFaceNative", "faceCallBack");
+                }
             }
 
-            @Override
-            public void surfaceChanged(SurfaceHolder holder, int format, int width, int height) {
-
-            }
-
-            @Override
+            public void surfaceChanged(SurfaceHolder holder, int format, int width, int height) {}
             public void surfaceDestroyed(SurfaceHolder holder) {
-                //fragment_supervisory_enter_progress_bar.setVisibility(View.VISIBLE);
+                System.out.println("surfaceDestroyed");
             }
         });
         fragment_supervisory_exit_camera.getHolder().addCallback(new SurfaceHolder.Callback() {
-            @Override
             public void surfaceCreated(SurfaceHolder holder) {
-                fragment_supervisory_exit_progress_bar.setVisibility(View.INVISIBLE);
-                RtspFaceNative.setSurface(Integer.parseInt(CommonVariables.Camera.OUT), fragment_supervisory_exit_camera.getHolder().getSurface());
-                RtspFaceNative.createPlayer(Integer.parseInt(CommonVariables.Camera.OUT), DeviceMng.getInstance().getCamera2Address());
-                RtspFaceNative.setFaceCallback(Integer.parseInt(CommonVariables.Camera.OUT), "cn/com/basic/face/util/RtspFaceNative", "faceCallBack");
+                if (useNative) {
+                    RtspFaceNative.setSurface(Integer.parseInt(CommonVariables.Camera.OUT), fragment_supervisory_exit_camera.getHolder().getSurface());
+                    RtspFaceNative.createPlayer(Integer.parseInt(CommonVariables.Camera.OUT), DeviceMng.getInstance().getCamera2Address());
+                    RtspFaceNative.setFaceCallback(Integer.parseInt(CommonVariables.Camera.OUT), "cn/com/basic/face/util/RtspFaceNative", "faceCallBack");
+                }
             }
 
-            @Override
-            public void surfaceChanged(SurfaceHolder holder, int format, int width, int height) {
-
-            }
-
-            @Override
+            public void surfaceChanged(SurfaceHolder holder, int format, int width, int height) {}
             public void surfaceDestroyed(SurfaceHolder holder) {
-                //fragment_supervisory_exit_progress_bar.setVisibility(View.VISIBLE);
+                System.out.println("surfaceDestroyed");
             }
         });
-        new Thread(new Runnable() {
-            @Override
-            public void run() {
-                try {
-                    if (useNative) {
-                        MainActivity.getInstance().runOnUiThread(new Runnable() {
-                            public void run() {
-                                try {
-//                                    File file2 = MainActivity.getInstance().getExternalFilesDir(null);
-//                                    File[] files = file2.listFiles();
-//                                    for (File file : files) {
-//                                        System.out.println(file.getAbsolutePath());
-//                                    }
-//                                    String s1 = getStringFromFile("/sdcard/license.lic");
-//                                    String str = convertStreamToString(MainActivity.getInstance().getAssets().open("license.lic"));
-//                                    RtspFaceNative.dbgSetStfaceLicense(str);
-                                } catch (Exception e) {
-                                    e.printStackTrace();
-                                }
-
-                            }
-                            public String convertStreamToString(InputStream is) throws Exception {
-                                BufferedReader reader = new BufferedReader(new InputStreamReader(is));
-                                StringBuilder sb = new StringBuilder();
-                                String line = null;
-                                while ((line = reader.readLine()) != null) {
-                                    sb.append(line).append("\n");
-                                }
-                                reader.close();
-                                return sb.toString();
-                            }
-                            public String getStringFromFile (String filePath) throws Exception {
-                                File fl = new File(filePath);
-                                FileInputStream fin = new FileInputStream(fl);
-                                String ret = convertStreamToString(fin);
-                                //Make sure you close all streams.
-                                fin.close();
-                                return ret;
-                            }
-                        });
-
-                    } else {
-                    }
-                } catch (Exception e) {
-                    e.printStackTrace();
-                }
-                try {
-                    final SimpleDateFormat sdf = new SimpleDateFormat("yyyy骞碝M鏈坉d鏃�  HH锛歮m锛歴s鍒�");
-//                    while (true) {
-//                        Thread.sleep(1000);
-//                        MainActivity.getInstance().runOnUiThread(new Runnable() {
-//                            @Override
-//                            public void run() {
-//                                fragment_surveillance_enter_timer.setText(sdf.format(new Date()));
-//                                fragment_surveillance_exit_timer.setText(sdf.format(new Date()));
-//                            }
-//                        });
-//                    }
-                } catch (Exception e) {
-                    e.printStackTrace();
-                }
-            }
-        }).start();
         new SurveillanceMng.SurveillanceListThread().start();
     }
 

--
Gitblit v1.8.0