| | |
| | | package cn.com.basic.face.fragment; |
| | | |
| | | import android.content.Context; |
| | | import android.net.wifi.WifiManager; |
| | | import android.os.Build; |
| | | import android.os.Bundle; |
| | | import android.os.SystemClock; |
| | | import android.text.format.Formatter; |
| | | 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.TextView; |
| | |
| | | import cn.com.basic.face.base.BaseFragment; |
| | | |
| | | import cn.com.basic.face.base.MainActivity; |
| | | import cn.com.basic.face.discern.common.CommonVariables; |
| | | import cn.com.basic.face.service.DeviceMng; |
| | | import cn.com.basic.face.util.RtspFaceNative; |
| | | |
| | | import cn.com.basic.face.service.SurveillanceMng; |
| | | import cn.com.basic.face.widget.surveilance.SurveillanceBottomAttendanceListView; |
| | | import cn.com.basic.face.widget.surveilance.SurveillanceBottomVisitorListView; |
| | | |
| | | import com.facebook.common.file.FileUtils; |
| | | import com.lidroid.xutils.view.annotation.ViewInject; |
| | | import com.lidroid.xutils.view.annotation.event.OnClick; |
| | | |
| | | import java.io.BufferedReader; |
| | | 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.util.Date; |
| | | |
| | | public class SurveillanceFragment extends BaseFragment { |
| | | |
| | |
| | | @ViewInject(R.id.fragment_supervisory_bottom_attendance_list_view) |
| | | private SurveillanceBottomAttendanceListView fragment_supervisory_bottom_attendance_list_view; |
| | | @ViewInject(R.id.fragment_supervisory_enter_camera) |
| | | SurfaceView fragment_supervisory_enter_camera; |
| | | private SurfaceView fragment_supervisory_enter_camera; |
| | | @ViewInject(R.id.fragment_supervisory_exit_camera) |
| | | SurfaceView fragment_supervisory_exit_camera; |
| | | private SurfaceView fragment_supervisory_exit_camera; |
| | | @ViewInject(R.id.fragment_surveillance_enter_timer) |
| | | private TextView fragment_surveillance_enter_timer; |
| | | @ViewInject(R.id.fragment_surveillance_exit_timer) |
| | |
| | | |
| | | static boolean useNative = false; |
| | | |
| | | public static boolean isEmulator() { |
| | | return Build.FINGERPRINT.startsWith("generic") |
| | | || Build.FINGERPRINT.startsWith("unknown") |
| | | || Build.MODEL.contains("google_sdk") |
| | | || Build.MODEL.contains("Emulator") |
| | | || Build.MODEL.contains("Android SDK built for x86") |
| | | || Build.MANUFACTURER.contains("Genymotion") |
| | | || (Build.BRAND.startsWith("generic") && Build.DEVICE.startsWith("generic")) |
| | | || "google_sdk".equals(Build.PRODUCT); |
| | | } |
| | | |
| | | static { |
| | | if (isEmulator()) { |
| | | useNative = false; |
| | | } else { |
| | | useNative = true; |
| | | } |
| | | useNative = false; |
| | | if (useNative) { |
| | | System.loadLibrary("cvface_api"); |
| | | System.loadLibrary("opencv_java3"); |
| | |
| | | System.loadLibrary("protoc"); |
| | | System.loadLibrary("rtspface"); |
| | | RtspFaceNative.init(); |
| | | RtspFaceNative.setLocalIP("192.168.1.10"); |
| | | // 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); |
| | | } |
| | | } |
| | | |
| | |
| | | |
| | | @Override |
| | | protected void initViews(View view, Bundle savedInstanceState) { |
| | | new Thread(new Runnable() { |
| | | @Override |
| | | public void run() { |
| | | try { |
| | | if (useNative) { |
| | | MainActivity.getInstance().runOnUiThread(new Runnable() { |
| | | public void run() { |
| | | RtspFaceNative.setSurface(1, fragment_supervisory_enter_camera.getHolder().getSurface()); |
| | | RtspFaceNative.setSurface(2, fragment_supervisory_exit_camera.getHolder().getSurface()); |
| | | RtspFaceNative.createPlayer(1, "rtsp://admin:admin12345@192.168.1.70:554/h264/ch1/sub/av_stream"); |
| | | RtspFaceNative.createPlayer(2, "rtsp://admin:admin12345@192.168.1.70:554/h264/ch1/sub/av_stream"); |
| | | RtspFaceNative.setFaceCallback(1, "cn/com/basic/face/util/RtspFaceNative", "faceCallBack"); |
| | | RtspFaceNative.setFaceCallback(2, "cn/com/basic/face/util/RtspFaceNative", "faceCallBack"); |
| | | } |
| | | }); |
| | | |
| | | } else { |
| | | } |
| | | } catch (Exception e) { |
| | | e.printStackTrace(); |
| | | } |
| | | try { |
| | | final SimpleDateFormat sdf = new SimpleDateFormat("yyyy年MM月dd日 HH:mm:ss分"); |
| | | 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 (InterruptedException e) { |
| | | fragment_supervisory_enter_camera.getHolder().addCallback(new SurfaceHolder.Callback() { |
| | | public void surfaceCreated(SurfaceHolder holder) { |
| | | 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"); |
| | | } |
| | | } |
| | | }).start(); |
| | | reloadBottomList(); |
| | | |
| | | public void surfaceChanged(SurfaceHolder holder, int format, int width, int height) {} |
| | | public void surfaceDestroyed(SurfaceHolder holder) { |
| | | System.out.println("surfaceDestroyed"); |
| | | } |
| | | }); |
| | | fragment_supervisory_exit_camera.getHolder().addCallback(new SurfaceHolder.Callback() { |
| | | public void surfaceCreated(SurfaceHolder holder) { |
| | | 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"); |
| | | } |
| | | } |
| | | |
| | | public void surfaceChanged(SurfaceHolder holder, int format, int width, int height) {} |
| | | public void surfaceDestroyed(SurfaceHolder holder) { |
| | | System.out.println("surfaceDestroyed"); |
| | | } |
| | | }); |
| | | new SurveillanceMng.SurveillanceListThread().start(); |
| | | } |
| | | |
| | | @OnClick(R.id.fragment_supervisory_bottom_visitor_radio_button) |
| | |
| | | fragment_supervisory_bottom_visit_list_view.setVisibility(fragment_supervisory_bottom_visitor_radio_button.isChecked()?View.VISIBLE:View.GONE); |
| | | fragment_supervisory_bottom_attendance_background.setVisibility(!fragment_supervisory_bottom_visitor_radio_button.isChecked()?View.VISIBLE:View.GONE); |
| | | fragment_supervisory_bottom_attendance_list_view.setVisibility(!fragment_supervisory_bottom_visitor_radio_button.isChecked()?View.VISIBLE:View.GONE); |
| | | reloadBottomList(); |
| | | } |
| | | |
| | | @OnClick(R.id.fragment_supervisory_bottom_attendance_radio_button) |
| | |
| | | fragment_supervisory_bottom_visit_list_view.setVisibility(fragment_supervisory_bottom_visitor_radio_button.isChecked()?View.VISIBLE:View.GONE); |
| | | fragment_supervisory_bottom_attendance_background.setVisibility(!fragment_supervisory_bottom_visitor_radio_button.isChecked()?View.VISIBLE:View.GONE); |
| | | fragment_supervisory_bottom_attendance_list_view.setVisibility(!fragment_supervisory_bottom_visitor_radio_button.isChecked()?View.VISIBLE:View.GONE); |
| | | reloadBottomList(); |
| | | } |
| | | |
| | | @Override |
| | |
| | | public void setMenuVisibility(boolean menuVisible) { |
| | | super.setMenuVisibility(menuVisible); |
| | | if (menuVisible && fragment_supervisory_bottom_visit_list_view != null) { |
| | | //reloadBottomList(); |
| | | } |
| | | } |
| | | |
| | | private void reloadBottomList() { |
| | | SurveillanceMng.getInstance().findSurveillanceBottomList(fragment_supervisory_bottom_visitor_radio_button.isChecked()); |
| | | } |
| | | |
| | | } |