赞
踩
- <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
- android:layout_width="match_parent"
- android:layout_height="match_parent"
- android:gravity="left"
- android:fitsSystemWindows="true">
-
-
- <LinearLayout
- android:layout_width="match_parent"
- android:layout_height="match_parent"
- android:background="#03A9F4"
- android:orientation="vertical">
-
- <ImageView
- android:layout_width="200dp"
- android:layout_height="0dp"
- android:layout_gravity="center_horizontal"
- android:layout_weight="1.5"
- android:background="@mipmap/logo"
- android:backgroundTint="@color/CDP_color"
- android:scaleType="fitCenter" />
-
- <LinearLayout
- android:layout_width="match_parent"
- android:layout_height="0dp"
- android:layout_gravity="center_vertical"
- android:layout_marginLeft="100dp"
- android:layout_marginTop="30dp"
- android:layout_marginRight="100dp"
- android:layout_weight="1.5"
- android:orientation="horizontal">
-
- <TextView
- android:layout_width="0dp"
- android:layout_height="wrap_content"
- android:layout_gravity="center_vertical"
- android:layout_weight="1"
- android:gravity="center"
- android:padding="3dp"
- android:text="@string/deviceid"
- android:textColor="@color/black"
- android:textSize="20sp" />
-
- <EditText
- android:id="@+id/deviceid"
- android:layout_width="0dp"
- android:layout_height="wrap_content"
- android:layout_margin="1dp"
- android:layout_weight="3"
- android:background="@drawable/editviewcase"
- android:cursorVisible="true"
- android:hint="CDP"
- android:paddingStart="10dp"
- android:selectAllOnFocus="true"
- android:text="CDP"
- android:textColorHint="#c0c0c0" />
- </LinearLayout>
-
- <LinearLayout
- android:layout_width="match_parent"
- android:layout_height="0dp"
- android:layout_gravity="center_vertical"
- android:layout_marginLeft="100dp"
- android:layout_marginTop="10dp"
- android:layout_marginRight="100dp"
- android:layout_weight="1.5"
- android:orientation="horizontal">
-
- <TextView
- android:layout_width="0dp"
- android:layout_height="wrap_content"
- android:layout_gravity="center_vertical"
- android:layout_weight="1"
- android:gravity="center"
- android:text="@string/loginname"
- android:textColor="@color/black"
- android:textSize="20sp" />
-
- <EditText
- android:id="@+id/loginname"
- android:layout_width="0dp"
- android:layout_height="wrap_content"
- android:layout_margin="1dp"
- android:layout_weight="3"
- android:background="@drawable/editviewcase"
- android:cursorVisible="true"
- android:hint="CDP"
- android:maxLength="10"
- android:paddingStart="10dp"
- android:selectAllOnFocus="true"
- android:text="CDP"
- android:textColorHint="#c0c0c0" />
- </LinearLayout>
-
- <LinearLayout
- android:layout_width="match_parent"
- android:layout_height="0dp"
- android:layout_gravity="center_vertical"
- android:layout_marginLeft="100dp"
- android:layout_marginTop="10dp"
- android:layout_marginRight="100dp"
- android:layout_weight="1.5"
- android:gravity="center"
- android:orientation="horizontal">
-
- <TextView
- android:layout_width="0dp"
- android:layout_height="wrap_content"
- android:layout_weight="1"
- android:gravity="center"
- android:padding="3dp"
- android:text="密 码"
- android:textColor="@color/black"
- android:textSize="20sp" />
-
- <LinearLayout
- android:layout_width="0dp"
- android:layout_height="wrap_content"
- android:layout_weight="3"
- android:background="@drawable/editviewcase"
- android:gravity="center">
-
- <EditText
- android:id="@+id/loginpasswd"
- android:layout_width="0dp"
- android:layout_height="wrap_content"
- android:layout_margin="1dp"
- android:layout_weight="3"
- android:background="#00000000"
- android:hint="@string/loginpsd"
- android:inputType="textPassword"
- android:maxLength="16"
- android:paddingStart="10dp"
- android:selectAllOnFocus="true"
- android:text="CDP"
- android:textColorHint="#c0c0c0" />
-
- <ImageView
- android:id="@+id/remember"
- android:layout_width="wrap_content"
- android:layout_height="wrap_content"
- android:layout_alignParentEnd="true"
- android:layout_marginEnd="10dp"
- android:background="@drawable/ic_off"
- android:text="显示密码"
- android:textSize="18sp" />
- </LinearLayout>
-
-
- </LinearLayout>
-
-
- <LinearLayout
- android:layout_width="match_parent"
- android:layout_height="0dp"
- android:layout_marginTop="10dp"
- android:layout_weight="1.5"
- android:orientation="horizontal">
-
- <Button
- android:id="@+id/reset"
- android:layout_width="wrap_content"
- android:layout_height="wrap_content"
- android:layout_marginLeft="150dp"
- android:layout_marginRight="100dp"
- android:layout_weight="1"
- android:background="@drawable/loginbutton"
- android:text="重 置"
- android:textColor="@color/white"
- android:textSize="20sp" />
-
- <Button
- android:id="@+id/connect"
- android:layout_width="wrap_content"
- android:layout_height="wrap_content"
- android:layout_marginRight="150dp"
- android:layout_weight="1"
- android:background="@drawable/loginbutton"
- android:text="连 接"
- android:textColor="@color/white"
- android:textSize="20sp" />
- </LinearLayout>
-
- </LinearLayout>
-
-
-
- </RelativeLayout>
- <?xml version="1.0" encoding="utf-8"?>
- <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
- xmlns:app="http://schemas.android.com/apk/res-auto"
- xmlns:tools="http://schemas.android.com/tools"
- android:layout_width="match_parent"
- android:layout_height="match_parent"
- android:orientation="vertical"
- android:background="@color/blue"
- tools:context=".Activity.MainActivity">
- <RelativeLayout
- android:layout_width="match_parent"
- android:layout_height="0dp"
- android:background="@drawable/bg_selete_all"
- android:layout_weight="1">
-
- <ImageView
- android:layout_width="140dp"
- android:layout_height="50dp"
- android:layout_centerInParent="true"
- android:layout_marginLeft="10dp"
- android:layout_marginTop="10dp"
- android:layout_marginRight="10dp"
- android:layout_marginBottom="10dp"
- android:background="@mipmap/logo"
- android:backgroundTint="@color/CDP_color"
- android:scaleType="fitCenter" />
-
- <TextureView
- android:id="@+id/video_view"
- android:layout_width="match_parent"
- android:layout_height="match_parent"
- android:layout_marginStart="5dp"
- android:layout_marginTop="5dp"
- android:layout_marginEnd="5dp"
- android:layout_marginBottom="5dp"
- android:visibility="visible" />
-
- </RelativeLayout>
-
- <androidx.recyclerview.widget.RecyclerView
- android:id="@+id/center_view"
- android:layout_width="match_parent"
- android:layout_weight="1"
- android:layout_height="0dp"
- android:background="@drawable/bg_selete_all"/>
-
- <LinearLayout
- android:layout_marginTop="5dp"
- android:layout_width="match_parent"
- android:layout_height="0dp"
- android:background="@drawable/bg_selete_all"
- android:layout_weight="1"
- android:orientation="horizontal">
- <LinearLayout
- android:layout_width="0dp"
- android:orientation="vertical"
- android:layout_weight="1"
- android:padding="5dp"
- android:layout_height="match_parent">
-
- <Button
- android:id="@+id/Traffic_Light"
- android:layout_width="match_parent"
- android:gravity="center"
- android:layout_weight="1"
- android:background="@drawable/loginbutton"
- android:text="红绿灯识别"
- android:textColor="@color/white"
- android:textSize="13sp"
- android:layout_height="0dp"/>
- <Button
- android:id="@+id/Traffic"
- android:layout_marginTop="5dp"
- android:gravity="center"
- android:layout_width="match_parent"
- android:layout_weight="1"
- android:background="@drawable/loginbutton"
- android:text="交通标志识别"
- android:textColor="@color/white"
- android:textSize="13sp"
- android:layout_height="0dp"/>
- <Button
- android:id="@+id/FaceMask"
- android:layout_marginTop="5dp"
- android:gravity="center"
- android:layout_width="match_parent"
- android:layout_weight="1"
- android:background="@drawable/loginbutton"
- android:text="口罩识别"
- android:textColor="@color/white"
- android:textSize="13sp"
- android:layout_height="0dp"/>
- <Button
- android:id="@+id/Shap"
- android:layout_marginTop="5dp"
- android:gravity="center"
- android:layout_width="match_parent"
- android:layout_weight="1"
- android:background="@drawable/loginbutton"
- android:text="图形识别"
- android:textColor="@color/white"
- android:textSize="13sp"
- android:layout_height="0dp"/>
- <Button
- android:id="@+id/QR_Code"
- android:layout_marginTop="5dp"
- android:layout_width="match_parent"
- android:layout_weight="1"
- android:gravity="center"
- android:background="@drawable/loginbutton"
- android:text="多二维码识别"
- android:textColor="@color/white"
- android:textSize="13sp"
- android:layout_height="0dp"/>
- </LinearLayout>
- <LinearLayout
- android:layout_width="0dp"
- android:orientation="vertical"
- android:padding="5dp"
- android:layout_weight="1"
- android:layout_height="match_parent">
- <Button
- android:id="@+id/Color_Qr"
-
- android:gravity="center"
- android:layout_width="match_parent"
- android:layout_weight="1"
- android:background="@drawable/loginbutton"
- android:text="彩色二维码识别"
- android:textColor="@color/white"
- android:textSize="13sp"
- android:layout_height="0dp"/>
-
-
- <Button
- android:layout_marginTop="5dp"
- android:id="@+id/Chepai"
- android:layout_width="match_parent"
- android:layout_weight="1"
- android:gravity="center"
- android:background="@drawable/loginbutton"
- android:text="车牌识别"
- android:textColor="@color/white"
- android:textSize="13sp"
- android:layout_height="0dp"/>
- <Button
- android:id="@+id/shapchepai"
- android:layout_marginTop="5dp"
- android:gravity="center"
- android:layout_width="match_parent"
- android:layout_weight="1"
- android:background="@drawable/loginbutton"
- android:text="指定车型车牌识别"
- android:textColor="@color/white"
- android:textSize="13sp"
- android:layout_height="0dp"/>
-
-
- <Button
- android:id="@+id/color_chepai"
- android:layout_width="match_parent"
- android:gravity="center"
- android:layout_marginTop="5dp"
- android:layout_weight="1"
- android:background="@drawable/loginbutton"
- android:text="指定颜色车牌识别"
- android:textColor="@color/white"
- android:textSize="13sp"
- android:layout_height="0dp"/>
-
- <Button
- android:id="@+id/Clear_img"
- android:layout_marginTop="5dp"
- android:layout_width="match_parent"
- android:gravity="center"
- android:layout_weight="1"
- android:background="@drawable/loginbutton"
- android:text="清空"
- android:textColor="@color/white"
- android:textSize="13sp"
- android:layout_height="0dp"/>
-
- </LinearLayout>
- <LinearLayout
- android:layout_width="0dp"
- android:orientation="vertical"
- android:padding="5dp"
- android:layout_weight="1"
- android:layout_height="match_parent">
-
- <Button
- android:id="@+id/wenzi"
-
- android:gravity="center"
- android:layout_width="match_parent"
- android:layout_weight="1"
- android:background="@drawable/loginbutton"
- android:text="文字识别"
- android:textColor="@color/white"
- android:textSize="13sp"
- android:layout_height="0dp"/>
-
-
- <Button
- android:layout_marginTop="5dp"
- android:id="@+id/Dxcj"
- android:layout_width="match_parent"
- android:layout_weight="1"
- android:gravity="center"
- android:background="@drawable/loginbutton"
- android:text="定向裁剪"
- android:textColor="@color/white"
- android:textSize="13sp"
- android:layout_height="0dp"/>
- <Button
- android:id="@+id/TFT"
- android:layout_marginTop="5dp"
- android:gravity="center"
- android:layout_width="match_parent"
- android:layout_weight="1"
- android:background="@drawable/loginbutton"
- android:text="TFT_A"
- android:textColor="@color/white"
- android:textSize="13sp"
- android:layout_height="0dp"/>
-
-
- <Button
- android:id="@+id/TFT_B"
- android:layout_width="match_parent"
- android:gravity="center"
- android:layout_marginTop="5dp"
- android:layout_weight="1"
- android:background="@drawable/loginbutton"
- android:text="TFT_B"
- android:visibility="invisible"
- android:textColor="@color/white"
- android:textSize="13sp"
- android:layout_height="0dp"/>
-
- <Button
-
- android:layout_marginTop="5dp"
- android:layout_width="match_parent"
- android:gravity="center"
- android:layout_weight="1"
- android:visibility="invisible"
- android:background="@drawable/loginbutton"
- android:text="暂定"
- android:textColor="@color/white"
- android:textSize="13sp"
- android:layout_height="0dp"/>
- </LinearLayout>
- </LinearLayout>
-
- </LinearLayout>
- <?xml version="1.0" encoding="utf-8"?>
-
- <androidx.cardview.widget.CardView
- xmlns:android="http://schemas.android.com/apk/res/android"
- xmlns:app="http://schemas.android.com/apk/res-auto"
- android:layout_width="match_parent"
- android:layout_height="wrap_content"
- android:layout_marginStart="10dp"
- android:layout_marginEnd="10dp"
- android:layout_marginTop="10dp"
- app:cardCornerRadius="5dp">
-
- <LinearLayout
- android:background="@drawable/bg_selete_all"
- android:orientation="vertical"
- android:layout_width="match_parent"
- android:layout_height="wrap_content"
- >
-
- <ImageView
- android:id="@+id/test_image"
- android:padding="3dp"
- android:layout_width="240dp"
- android:layout_height="180dp"
- android:scaleType="fitCenter"
- android:layout_gravity="center_horizontal" />
-
- <TextView
- android:id="@+id/test_name"
- android:layout_width="wrap_content"
- android:layout_height="wrap_content"
- android:textSize="13sp"
- android:layout_marginTop="2dp"
- android:layout_marginBottom="2dp" />
-
- <TextView
- android:id="@+id/test_name2"
- android:layout_width="wrap_content"
- android:layout_height="wrap_content"
- android:layout_marginTop="2dp"
- android:layout_marginBottom="2dp"
- android:textSize="13sp" />
-
- </LinearLayout>
- </androidx.cardview.widget.CardView>
- package com.example.test_car.CameraUtile;
-
- import android.app.IntentService;
- import android.content.Intent;
- import android.util.Log;
-
- import java.io.IOException;
- import java.io.UnsupportedEncodingException;
- import java.net.DatagramPacket;
- import java.net.DatagramSocket;
- import java.net.InetAddress;
- import java.net.InetSocketAddress;
- import java.net.SocketException;
- import java.net.UnknownHostException;
- import java.util.Timer;
- import java.util.TimerTask;
-
- public class CameraSearchService extends IntentService {
-
- public CameraSearchService() {
- super("CameraSearchService");
- }
-
- //摄像头ͷIP
- private String IP = null;
-
- @Override
- protected void onHandleIntent(Intent intent) {
- SearchCameraUtil searchCameraUtil;
- for (int i = 0;i < 1 && IP == null;i++) {
- searchCameraUtil = new SearchCameraUtil();
- IP = searchCameraUtil !=null ? searchCameraUtil.send(): null;
- try {
- Thread.sleep(500);
- } catch (InterruptedException e) {
- e.printStackTrace();
- }
- }
- Intent mintent = new Intent(CameraConnectUtil.A_S);
- mintent.putExtra("IP", XcApplication.cameraip);
- mintent.putExtra("IP", IP + ":81");
- mintent.putExtra("pureip", IP);
- sendBroadcast(mintent);
- }
-
- class SearchCameraUtil {
- private String IP = "";
- private String TAG = "UDPClient";
- private final int PORT = 3565;
- private final int SERVER_PORT = 8600;
- private byte[] mbyte = new byte[]{68, 72, 1, 1};
- private DatagramSocket dSocket = null;
- private byte[] msg = new byte[1024];
- boolean isConn = false;
-
- public SearchCameraUtil() {
- }
-
- public String send() {
- InetAddress local = null;
-
- try {
- local = InetAddress.getByName("255.255.255.255");
- Log.e(this.TAG, "已找到服务器,连接中...");
- } catch (UnknownHostException var7) {
- Log.e(this.TAG, "未找到服务器.");
- var7.printStackTrace();
- return null;
- }
-
- try {
- if (this.dSocket != null) {
- this.dSocket.close();
- this.dSocket = null;
- }
- // 第一次连接没有报错,第二次开始报这个错误。字面意思看出是由于端口被占用,未释放导致。
- // 虽然程序貌似已经退出,个人猜测是由于系统还没有及时释放导致的。
- // this.dSocket = new DatagramSocket(3565);
- if(dSocket == null){
- dSocket = new DatagramSocket(null);
- dSocket.setReuseAddress(true);
- dSocket.bind(new InetSocketAddress(PORT));
- }
- Log.e(this.TAG, "正在连接服务器...");
- } catch (SocketException var6) {
- var6.printStackTrace();
- Log.e(this.TAG, "服务器连接失败.");
- return null;
- }
-
- DatagramPacket sendPacket = new DatagramPacket(this.mbyte, 4, local, SERVER_PORT);
- DatagramPacket recPacket = new DatagramPacket(this.msg, this.msg.length);
-
- try {
- this.dSocket.send(sendPacket);
-
- Timer timer = new Timer();
- timer.schedule(new TimerTask() {
- @Override
- public void run() {
- if (isConn){
- dSocket.close();
- this.cancel();
- }
- isConn = true;
- }
- }, 0, 500);
- this.dSocket.receive(recPacket);
- timer.cancel();
- String text = new String(this.msg, 0, recPacket.getLength());
- if (text.substring(0, 2).equals("DH")) {
- this.getIP(text);
- }
-
- Log.e("IP值", this.IP);
- this.dSocket.close();
- Log.e(this.TAG, "消息发送成功!");
- } catch (IOException var5) {
- var5.printStackTrace();
- Log.e(this.TAG, "消息发送失败.");
- return null;
- }
-
- return this.IP;
- }
-
- private void getIP(String text) {
- try {
- byte[] ipbyte = text.getBytes("UTF-8");
-
- for(int i = 4; i < 22 && ipbyte[i] != 0; ++i) {
- if (ipbyte[i] == 46) {
- this.IP = this.IP + ".";
- } else {
- this.IP = this.IP + (ipbyte[i] - 48);
- }
- }
- } catch (UnsupportedEncodingException var4) {
- var4.printStackTrace();
- }
-
- }
- }
- }
- package com.example.test_car.CameraUtile;
-
- import android.content.BroadcastReceiver;
- import android.content.Context;
- import android.content.Intent;
- import android.content.IntentFilter;
- import android.util.Log;
-
- import com.example.test_car.Activity.MainActivity;
- import com.example.test_car.MessageBean.DataRefreshBean;
-
- import org.greenrobot.eventbus.EventBus;
-
-
-
-
- public class CameraConnectUtil {
-
- public CameraConnectUtil(Context context){
- this.context = context;
- }
-
- private Context context;
-
- public void cameraInit() {
- //广播接收器注册
- IntentFilter intentFilter = new IntentFilter();
- intentFilter.addAction(A_S);
- context.registerReceiver(myBroadcastReceiver, intentFilter);
- }
-
- public void cameraStopService(){
- Intent intent = new Intent(context, CameraSearchService.class);
- context.stopService(intent);
- }
-
- public static final String A_S = "com.a_s";
- public BroadcastReceiver myBroadcastReceiver = new BroadcastReceiver() {
- public void onReceive(Context arg0, Intent arg1) {
- MainActivity.IPCamera = arg1.getStringExtra("IP");
- MainActivity.purecameraip = arg1.getStringExtra("pureip");
- Log.e("camera ip::", " " + MainActivity.IPCamera);
- EventBus.getDefault().post(new DataRefreshBean(2));
- context.unregisterReceiver(this);
- }
- };
-
-
- // 搜索摄像cameraIP
- public void search() {
- Intent intent = new Intent(context, CameraSearchService.class);
- context.startService(intent);
- }
-
- public void destroy(){
- try {
- context.unregisterReceiver(myBroadcastReceiver);
- }catch (RuntimeException ignored){
-
- }
- }
-
- }
- package com.example.test_car.MessageBean;
-
- public class DataRefreshBean {
-
- private int refreshState;
-
- public DataRefreshBean(int refreshState){
- this.refreshState = refreshState;
- }
-
- public int getRefreshState() {
- return refreshState;
- }
-
- public void setRefreshState(int refreshState) {
- this.refreshState = refreshState;
- }
- }
- package com.example.test_car.Utils;
-
-
- import android.content.Context;
- import android.media.MediaScannerConnection;
- import android.net.Uri;
- import android.util.Log;
- import android.view.TextureView;
- import android.view.View;
-
- import com.example.test_car.Activity.MainActivity;
-
- import org.videolan.libvlc.LibVLC;
- import org.videolan.libvlc.Media;
- import org.videolan.libvlc.MediaPlayer;
-
- import java.io.File;
- import java.net.FileNameMap;
- import java.net.URLConnection;
- import java.util.ArrayList;
-
-
- /**
- * VLC播放视频工具类
- */
- public class VLCPlayer implements MediaPlayer.EventListener{
-
- private LibVLC libVLC;
- private MediaPlayer mediaPlayer;
-
- public VLCPlayer(Context context) {
- ArrayList<String> options = new ArrayList<>();
- options.add("--no-drop-late-frames"); //防止掉帧
- options.add("--skip-frames"); //防止掉帧
- options.add("--rtsp-tcp");//强制使用TCP方式
- options.add("--avcodec-hw=any"); //尝试使用硬件加速
- options.add("--live-caching=0");//缓冲时长
- options.add("--no-audio");//关闭音频
- options.add("--sout-display");//持续串流输出
- options.add("--network-caching=300");//网络缓冲时长
-
-
-
- libVLC = new LibVLC(context, options);
- mediaPlayer = new MediaPlayer(libVLC);
- mediaPlayer.setEventListener(this);
- }
-
- /**
- * 设置播放视图
- * @param textureView
- */
- public void setVideoSurface(TextureView textureView) {
- mediaPlayer.getVLCVout().setVideoSurface(textureView.getSurfaceTexture());
- mediaPlayer.getVLCVout().setWindowSize(textureView.getWidth(), textureView.getHeight());
- textureView.addOnLayoutChangeListener(new View.OnLayoutChangeListener() {
- @Override
- public void onLayoutChange(View v, int left, int top, int right, int bottom,
- int oldLeft, int oldTop, int oldRight, int oldBottom) {
- // 获取新的宽度和高度
- int newWidth = right - left;
- int newHeight = bottom - top;
- // 设置VLC播放器的宽高参数
- mediaPlayer.getVLCVout().setWindowSize(newWidth, newHeight);
- }
- });
-
- mediaPlayer.getVLCVout().attachViews();
-
- }
-
- /**
- * 设置播放地址
- * @param url
- */
- public void setDataSource(String url) {
- try {
- Media media = new Media(libVLC, Uri.parse(url));
- media.setHWDecoderEnabled(false,false);
- mediaPlayer.setMedia(media);
- }catch (Exception e){
- Log.e("VLCPlayer",e.getMessage(),e);
- }
- }
-
- /**
- * 播放
- */
- public void play() {
- if (mediaPlayer == null) {
- return;
- }
- mediaPlayer.play();
- }
-
- /**
- * 暂停
- */
- public void pause() {
- if (mediaPlayer == null) {
- return;
- }
- mediaPlayer.pause();
- }
-
- /**
- * 停止播放
- */
- public void stop() {
- if (mediaPlayer == null) {
- return;
- }
- new Thread(new Runnable() {
- @Override
- public void run() {
- mediaPlayer.stop();
- }
- }).start();
- }
-
- public boolean takeSnapShot(int number, String _path, int width, int height){
-
- boolean b = mediaPlayer.takeSnapShot(number,_path,width,height);
- MediaScannerConnection.scanFile(MainActivity.INSTANCE, new String[]{_path}, null, (path, uri) -> Log.e("资源刷新成功路径为", path));
- return b;
- }
-
- /**
- * 兼容android 10
- * 更新图库
- * @param mContext
- * @param file
- */
- public static void updatePhotoAlbum(Context mContext,String file) {
- // 扫描刷新
- String[] pathArray = new String[]{file};
- String[] typeArray = new String[]{"image/jpeg"};
- MediaScannerConnection.scanFile(mContext, pathArray, typeArray, new MediaScannerConnection.OnScanCompletedListener() {
- @Override
- public void onScanCompleted(String s, Uri uri) {
- Log.d("ImageUtils", "onScanCompleted s->" + s);
- }
- });
- }
-
- public static String getMimeType(File file) {
- FileNameMap fileNameMap = URLConnection.getFileNameMap();
- String type = fileNameMap.getContentTypeFor(file.getName());
- return type;
- }
-
-
-
- /**
- * 释放资源
- */
- public void release() {
- if(mediaPlayer!=null) {
- mediaPlayer.release();
- }
- if(libVLC!=null) {
- libVLC.release();
- }
- }
-
-
- @Override
- public void onEvent(MediaPlayer.Event event) {
- switch (event.type) {
- case MediaPlayer.Event.Buffering:
- // 处理缓冲事件
- if (callback != null) {
- callback.onBuffering(event.getBuffering());
- }
- break;
- case MediaPlayer.Event.EndReached:
- // 处理播放结束事件
- if (callback != null) {
- callback.onEndReached();
- }
- break;
- case MediaPlayer.Event.EncounteredError:
- // 处理播放错误事件
- if (callback != null) {
- callback.onError();
- }
- break;
- case MediaPlayer.Event.TimeChanged:
- // 处理播放进度变化事件
- if (callback != null) {
- callback.onTimeChanged(event.getTimeChanged());
- }
- break;
- case MediaPlayer.Event.PositionChanged:
- // 处理播放位置变化事件
- if (callback != null) {
- callback.onPositionChanged(event.getPositionChanged());
- }
- break;
- case MediaPlayer.Event.Vout:
-
- break;
- }
- }
-
-
- private VLCPlayerCallback callback;
-
- public void setCallback(VLCPlayerCallback callback) {
- this.callback = callback;
- }
-
- public interface VLCPlayerCallback {
- void onBuffering(float bufferPercent);
- void onEndReached();
- void onError();
- void onTimeChanged(long currentTime);
- void onPositionChanged(float position);
- }
-
- }
- package com.example.test_car.Activity;
-
- import androidx.appcompat.app.AppCompatActivity;
- import androidx.core.view.ViewCompat;
- import androidx.core.view.WindowInsetsControllerCompat;
-
- import android.content.Intent;
- import android.os.Bundle;
- import android.util.Log;
- import android.view.View;
- import android.view.Window;
- import android.view.WindowManager;
- import android.widget.Button;
-
- import com.example.test_car.CameraUtile.CameraConnectUtil;
- import com.example.test_car.CameraUtile.CameraSearchService;
- import com.example.test_car.MessageBean.DataRefreshBean;
- import com.example.test_car.R;
-
- import org.greenrobot.eventbus.EventBus;
- import org.greenrobot.eventbus.Subscribe;
- import org.greenrobot.eventbus.ThreadMode;
-
- public class Login extends AppCompatActivity {
- private Button bt_connect = null;
- @Override
- protected void onCreate(Bundle savedInstanceState) {
- super.onCreate(savedInstanceState);
- supportRequestWindowFeature(Window.FEATURE_NO_TITLE);//用于在 Activity 中去除标题栏
- getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
- WindowManager.LayoutParams.FLAG_FULLSCREEN);// 设置全屏
- Window window = getWindow();
- window.addFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS);
- window.addFlags(WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS);
- WindowInsetsControllerCompat wic = ViewCompat.getWindowInsetsController(getWindow().getDecorView());
- if (wic != null) {
- // true表示Light Mode,状态栏字体呈黑色,反之呈白色
- wic.setAppearanceLightStatusBars(true);
- }
- setContentView(R.layout.activity_login);
- EventBus.getDefault().register(this); // EventBus消息注册,只有注册了消息机制后,才能收到广播出来的消息
- bt_connect=findViewById(R.id.connect);
- bt_connect.setOnClickListener(new View.OnClickListener() {
- @Override
- public void onClick(View v) {
- search();
- }
- });
- CameraConnectUtil cameraConnectUtil = new CameraConnectUtil(this);
- cameraConnectUtil.cameraInit();//摄像头初始化
-
- }
-
-
- // 搜索摄像cameraIP
- private void search() {
- Intent intent = new Intent(Login.this, CameraSearchService.class);
- startService(intent);
- }
-
- /**
- * 接收Eventbus消息
- *
- * @param refresh
- */
- @Subscribe(threadMode = ThreadMode.MAIN)
- public void onEventMainThread(DataRefreshBean refresh) {
- if (refresh.getRefreshState() == 2) {//如果CameraConnectUtil中广播出来的消息为2
- startFirstActivity();//页面跳转
- }
- }
-
- private void startFirstActivity() {
- startActivity(new Intent(Login.this,MainActivity.class));
- finish();
- }
- @Override
- protected void onDestroy() {
- super.onDestroy();
- EventBus.getDefault().unregister(this); // EventBus消息注销
- Log.e("LoginActivity", "onDestroy");
- }
- }
- package com.example.test_car.Activity;
-
- import androidx.annotation.NonNull;
- import androidx.appcompat.app.AppCompatActivity;
-
- import android.annotation.SuppressLint;
- import android.app.AlertDialog;
- import android.content.Context;
- import android.content.Intent;
- import android.graphics.Bitmap;
- import android.graphics.SurfaceTexture;
- import android.net.DhcpInfo;
- import android.net.wifi.WifiManager;
- import android.os.Bundle;
- import android.os.Handler;
- import android.os.Message;
- import android.text.format.Formatter;
- import android.util.Log;
- import android.view.MotionEvent;
- import android.view.TextureView;
- import android.view.View;
- import android.view.WindowManager;
- import android.widget.Button;
-
- import com.bkrcl.control_car_video.camerautil.CameraCommandUtil;
- import com.example.test_car.CameraUtile.CameraConnectUtil;
- import com.example.test_car.CameraUtile.XcApplication;
- import com.example.test_car.Data.Connect;
- import com.example.test_car.MessageBean.DataRefreshBean;
- import com.example.test_car.R;
- import com.example.test_car.Utils.ToastUtil;
- import com.example.test_car.Utils.VLCPlayer;
-
- import org.greenrobot.eventbus.EventBus;
- import org.greenrobot.eventbus.Subscribe;
- import org.greenrobot.eventbus.ThreadMode;
-
- import java.net.InetAddress;
- import java.net.UnknownHostException;
- import java.util.concurrent.ExecutorService;
- import java.util.concurrent.Executors;
-
- public class MainActivity extends AppCompatActivity implements VLCPlayer.VLCPlayerCallback {
-
- private static final String TAG = "测试";
- // 摄像头IP
- public static String IPCamera = null;
- public static String purecameraip = null;
- // 图片
- public static Bitmap bitmap;
- // 摄像头连接状态
- private boolean cameraConnectState = false;
- ToastUtil toastUtil = new ToastUtil(this);
- Connect connect = new Connect();
- // 摄像头工具
- public static CameraCommandUtil cameraCommandUtil;
- private CameraConnectUtil cameraConnectUtil;
- public static MainActivity INSTANCE;
- // 小车ip
- static String IPCar,IPmask;
-
- private VLCPlayer vlcPlayer;
- //坐标
- private float x1 = 0;
- private float y1 = 0;
-
- //控件
- private TextureView textureView;
- Button Traffic_Light_btn;//红绿灯识别按钮
- Button Traffic_btn;//交通标志
- Button FaceMask_btn;//口罩
- Button Shap_btn;//图形
- Button QR_Code_btn;//多二维码
- Button Color_QR_btn;//彩色二维码
- Button Chepai_btn;//车牌
- Button Shap_ChePai_btn;//指定车型车牌
- Button Color_Chepai_btn;//指定颜色车牌
- Button Clear_btn ;// 清空
- Button wenzi_btn;//文字
- Button Dxcj;//定向裁剪
- Button TFT;
-
-
-
-
- @Override
- protected void onCreate(Bundle savedInstanceState) {
- super.onCreate(savedInstanceState);
- getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
- WindowManager.LayoutParams.FLAG_FULLSCREEN);//这段代码是用于设置 Android 应用程序窗口为全屏模式
- setContentView(R.layout.activity_main);
-
- initView();//控件初始化
- init();
- btn();
- wifi_Init();//wifi初始化
- INSTANCE=this;
- EventBus.getDefault().register(this); // EventBus消息注册
- cameraCommandUtil = new CameraCommandUtil();
- cameraConnectUtil = new CameraConnectUtil(this);
- cameraConnectUtil.cameraInit();//摄像头初始化
- cameraConnectUtil.search();//搜索摄像头
- XcApplication.executorServicetor.execute(()->{
- connect.connect(recvhandler,IPCar);
- });//建立与小车的连接
-
- }
-
-
-
- public static void setBitmap(Bitmap bitmap1) {
- bitmap = bitmap1;
- }
-
- public boolean isCameraConnectState() {//判断是否连接成功
- return cameraConnectState;
- }
- public void setCameraConnectState(boolean cameraConnectState) {
- this.cameraConnectState = cameraConnectState;
- }
- // 得到当前摄像头的图片信息,转换为Bitmap
- public Bitmap getBitmap() {
- return bitmap = textureView.getBitmap();
- }
-
- //WiFi初始化
- /**
- * 首先,通过 getSystemService(Context.WIFI_SERVICE) 方法获取到 WifiManager 对象,
- * 该对象用于管理 Wi-Fi 相关的操作。然后使用 wifiManager.getDhcpInfo() 方法获取到 DhcpInfo 对象,
- * DhcpInfo 包含了当前连接的 Wi-Fi 网络的 DHCP 信息,包括网关地址、IP 地址、子网掩码等。
- * 接着,通过 Formatter.formatIpAddress(dhcpInfo.gateway) 将 DhcpInfo 中的网关地址转换成字符串格式的 IP 地址。
- * 这里的 dhcpInfo.gateway 表示 DhcpInfo 中保存的网关地址,通过 Formatter.formatIpAddress()
- * 方法将其转换成常用的点分十进制的 IP 地址表示形式。
- */
- private void wifi_Init() {
- // 得到服务器的IP地址
- WifiManager wifiManager = (WifiManager) getApplicationContext().getSystemService(Context.WIFI_SERVICE);
- // 服务器管理器
- DhcpInfo dhcpInfo = wifiManager.getDhcpInfo();
- IPCar = Formatter.formatIpAddress(dhcpInfo.gateway);
- IPmask = Formatter.formatIpAddress(dhcpInfo.netmask);
- }
-
-
- /**
- * 接收显示小车发送的数据
- */
- @SuppressLint("HandlerLeak")
- private final Handler recvhandler = new Handler() {
- @SuppressLint("SetTextI18n")
- public void handleMessage(Message msg) {
- if (msg.what == 1) {
- byte[] mByte = (byte[]) msg.obj;
- if (mByte[0] == 0x55) {
- if (mByte[1] == (byte) 0xaa) {//主车
- // 显示数据
-
- }
-
- }
- }
- }
- };
-
-
-
- private final Bitmap newbitmap = null;
- /**
- * 接收Eventbus消息
- *
- * @param refresh
- */
- @SuppressLint("SetTextI18n")
- @Subscribe(threadMode = ThreadMode.MAIN)
- public void onEventMainThread(DataRefreshBean refresh) {
- if (refresh.getRefreshState() == 1) {//这个if其实可以不用谢,因为我没有做刷新按钮
- Log.e(TAG, "onEventMainThread: " + IPCamera);
- if (IPCamera.equals("null:81")) {
- Log.e(TAG, "onEventMainThread: " + IPCamera);
- cameraConnectUtil.cameraStopService();
- cameraConnectUtil.cameraInit();
- cameraConnectUtil.search();
- } else {
- cameraConnectUtil.cameraStopService();
- cameraConnectUtil.cameraInit();
- cameraConnectUtil.search();
- initVLCPlayer(false); // 初始化视频流
- }
- } else if (refresh.getRefreshState() == 2) {//广播为2,代表摄像头和网络没问题
- setCameraConnectState(true);
- if (!IPCamera.equals("null:81")) {
- try {
- if (!isIpAddressInSubnet(IPCar, purecameraip,IPmask)) {
- toastUtil.ShowToast("请检查摄像头配置,当前摄像头地址与小车不在同一网段内,请重新配置");
- } else initVLCPlayer(false); // 初始化视频流
- } catch (UnknownHostException e) {
- throw new RuntimeException(e);
- }
- }
- } else if (refresh.getRefreshState() == 4) {//表示没搜到摄像头
- if (bitmap != null) {
- bitmap.recycle();
- }
- setBitmap(newbitmap);
- }
- }
-
-
- public static boolean isIpAddressInSubnet(String ipAddress, String subnetAddress, String subnetMask) throws UnknownHostException {
- InetAddress inetAddress = InetAddress.getByName(ipAddress);
- InetAddress subnet = InetAddress.getByName(subnetAddress);
- InetAddress mask = InetAddress.getByName(subnetMask);
-
- byte[] inetAddressBytes = inetAddress.getAddress();
- byte[] subnetBytes = subnet.getAddress();
- byte[] maskBytes = mask.getAddress();
-
- for (int i = 0; i < inetAddressBytes.length; i++) {
- int addressByte = inetAddressBytes[i] & 0xFF;
- int subnetByte = subnetBytes[i] & 0xFF;
- int maskByte = maskBytes[i] & 0xFF;
-
- if ((addressByte & maskByte) != (subnetByte & maskByte)) {
- return false;
- }
- }
-
- return true;
- }
-
- /**
- * 初始化视频流的代码
- * @param isFirst
- */
- private void initVLCPlayer(Boolean isFirst) {
- XcApplication.executorServicetor.execute(() -> {
- if (isFirst) {
- vlcPlayer = new VLCPlayer(this);
- vlcPlayer.setVideoSurface(textureView);
-
- }
- // String ip = IPCamera.substring(0, IPCamera.indexOf(":"));
- String url = "rtsp://admin:888888@" + purecameraip + ":10554/tcp/av0_0";
- vlcPlayer.setDataSource(url);
- vlcPlayer.setCallback(INSTANCE);
- vlcPlayer.play();
- });
- }
-
- /**
- * 初始化视频流控件
- */
- private void initView(){
- textureView = findViewById(R.id.video_view);
- textureView.setOnTouchListener(new ontouchlistener1());
- // 视频流显示区域
- textureView.setSurfaceTextureListener(new TextureView.SurfaceTextureListener() {
- @Override
- public void onSurfaceTextureAvailable(SurfaceTexture surfaceTexture, int i, int i1) {
- initVLCPlayer(true);
- }
-
- @Override
- public void onSurfaceTextureSizeChanged(@NonNull SurfaceTexture surface, int width, int height) {
-
- }
-
- @Override
- public boolean onSurfaceTextureDestroyed(@NonNull SurfaceTexture surface) {
- return false;
- }
-
- @Override
- public void onSurfaceTextureUpdated(@NonNull SurfaceTexture surface) {
-
- }
- });
-
- }
- /**
- * 初始化按钮控件
- */
- private void init(){
- Clear_btn = findViewById(R.id.Clear_img);//清空按钮
- Traffic_Light_btn=findViewById(R.id.Traffic_Light);//红绿灯识别按钮
- Traffic_btn = findViewById(R.id.Traffic);//交通标志
- FaceMask_btn = findViewById(R.id.FaceMask);//口罩
- Shap_btn = findViewById(R.id.Shap);//图形
- QR_Code_btn = findViewById(R.id.QR_Code);//多二维码
- Color_QR_btn = findViewById(R.id.Color_Qr);//彩色二维码
- Chepai_btn = findViewById(R.id.Chepai);//车牌
- Shap_ChePai_btn = findViewById(R.id.shapchepai);//指定车型车牌
- Color_Chepai_btn = findViewById(R.id.color_chepai);//指定颜色车牌
- wenzi_btn = findViewById(R.id.wenzi);//文字
- Dxcj = findViewById(R.id.Dxcj);//定向裁剪
- TFT =findViewById(R.id.TFT);
-
- }
-
- /**
- * 底部按钮点击事件
- */
- private void btn(){
-
- Clear_btn.setOnClickListener(new View.OnClickListener() {
- @Override
- public void onClick(View view) {
-
- }
- });//清空
- Traffic_Light_btn.setOnClickListener(new View.OnClickListener() {
- @Override
- public void onClick(View view) {
-
- }
- });//红绿灯
- Traffic_btn.setOnClickListener(new View.OnClickListener() {
- @Override
- public void onClick(View view) {
-
- }
- });//交通标志
- FaceMask_btn.setOnClickListener(new View.OnClickListener() {
- @Override
- public void onClick(View view) {
-
-
- }
- });//口罩
- Shap_btn.setOnClickListener(new View.OnClickListener() {
- @Override
- public void onClick(View view) {
-
- toastUtil.ShowToast("请自行进行模型训练,如果不会,请联系学长!");
- }
- });//图形
- QR_Code_btn.setOnClickListener(new View.OnClickListener() {
- @Override
- public void onClick(View view) {
-
- }
- });//多二维码
- Color_QR_btn.setOnClickListener(new View.OnClickListener() {
- @Override
- public void onClick(View view) {
-
- }
- });//颜色二维码
- Chepai_btn.setOnClickListener(new View.OnClickListener() {
- @Override
- public void onClick(View view) {
-
- }
- });//车牌
- Shap_ChePai_btn.setOnClickListener(new View.OnClickListener() {
- @Override
- public void onClick(View view) {
-
- }
- });//指定车型识别车牌
- Color_Chepai_btn.setOnClickListener(new View.OnClickListener() {
- @Override
- public void onClick(View view) {
-
- }
- });//指定颜色识别车牌
- wenzi_btn.setOnClickListener(new View.OnClickListener() {
- @Override
- public void onClick(View v) {
-
- }
- });//文字
- Dxcj.setOnClickListener(new View.OnClickListener() {
- @Override
- public void onClick(View v) {
-
- }
- });//定向裁剪
- TFT.setOnClickListener(new View.OnClickListener() {
- @Override
- public void onClick(View v) {
- TFT_Control();
- }
- });//控制tft
-
- }
-
-
- private void TFT_Control() {
- AlertDialog.Builder tft_builder = new AlertDialog.Builder(this);
- tft_builder.setTitle("多功能信息显示标志物");
- String[] ga = {"TFT(A)", "TFT(B)", "TFT(C)"};
- tft_builder.setSingleChoiceItems(ga, -1, (dialog, i) -> {
- switch (i) {
- case 0: // A
- Smart_DataDisplay_Image("多功能信息显示标志物(A)",0x0B);
- break;
- case 1: // B
- Smart_DataDisplay_Image("多功能信息显示标志物(B)",0x08);
- break;
- case 2: // C
- Smart_DataDisplay_Image("多功能信息显示标志物(C)",0x11);
- break;
- default:
- break;
- }
- });
- tft_builder.create().show();
- }
-
- /**
- * 显示弹窗
- * @param
- */
- private void Smart_DataDisplay_Image(String name,int id) {
- AlertDialog.Builder TFT_Image_builder = new AlertDialog.Builder(this);
- TFT_Image_builder.setTitle(name);
- String[] TFT_Image_item = { "上翻一页", "下翻一页", "自动翻页"};
- TFT_Image_builder.setSingleChoiceItems(TFT_Image_item, -1, (dialog, which) -> {
- // TODO 自动生成的方法存根
- switch (which) {
- case 0:
- connect.TFT_LCD(id, 0x10, 0x01, 0x00, 0x00);
- break;
- case 1:
- connect.TFT_LCD(id, 0x10, 0x02, 0x00, 0x00);
- break;
- case 2:
- connect.TFT_LCD(id, 0x10, 0x03, 0x00, 0x00);
- break;
- }
- });
- TFT_Image_builder.create().show();
- }
-
-
-
- @Override
- public void onBuffering(float bufferPercent) {
-
- }
-
- @Override
- public void onEndReached() {
-
- }
-
- @Override
- public void onError() {
-
- }
-
- @Override
- public void onTimeChanged(long currentTime) {
-
- }
-
- @Override
- public void onPositionChanged(float position) {
-
- }
-
-
- /**
- * 控制摄像头滑动
- */
- private class ontouchlistener1 implements View.OnTouchListener {
- @Override
- public boolean onTouch(View v, MotionEvent event) {
- // TODO 自动生成的方法存根
- if (cameraConnectState) {
- switch (event.getAction() & MotionEvent.ACTION_MASK) {
- // 点击位置坐标
- case MotionEvent.ACTION_DOWN:
- x1 = event.getX();
- y1 = event.getY();
- break;
- // 弹起坐标
- case MotionEvent.ACTION_UP:
- float x2 = event.getX();
- float y2 = event.getY();
- float xx = x1 > x2 ? x1 - x2 : x2 - x1;
- float yy = y1 > y2 ? y1 - y2 : y2 - y1;
- // 判断滑屏趋势
- int MINLEN = 30;
- if (xx > yy) {
- if ((x1 > x2) && (xx > MINLEN)) { // left
- XcApplication.executorServicetor.execute(new Runnable() {
- @Override
- public void run() {
- cameraCommandUtil.postHttp(IPCamera, 4, 1); //左
- }
- });
-
- } else if ((x1 < x2) && (xx > MINLEN)) { // right
- XcApplication.executorServicetor.execute(new Runnable() {
- @Override
- public void run() {
- cameraCommandUtil.postHttp(IPCamera, 6, 1); //右
- }
- });
- }
- } else {
- if ((y1 > y2) && (yy > MINLEN)) { // up
- XcApplication.executorServicetor.execute(new Runnable() {
- @Override
- public void run() {
- cameraCommandUtil.postHttp(IPCamera, 0, 1); //上
- }
- });
- } else if ((y1 < y2) && (yy > MINLEN)) { // down
- XcApplication.executorServicetor.execute(new Runnable() {
- @Override
- public void run() {
- cameraCommandUtil.postHttp(IPCamera, 2, 1); //下
- }
- });
- }
- }
- x1 = 0;
- x2 = 0;
- y1 = 0;
- y2 = 0;
-
- break;
- }
- }
- return true;
- }
- }
- /**
- * 生命周期结束时结束Socket链接
- */
- @Override
- protected void onDestroy() {
- super.onDestroy();
- connect.destory();
- }
-
- }
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。