diff --git a/src/app/src/main/AndroidManifest.xml b/src/app/src/main/AndroidManifest.xml
index 66a89f5..734cc86 100644
--- a/src/app/src/main/AndroidManifest.xml
+++ b/src/app/src/main/AndroidManifest.xml
@@ -13,6 +13,12 @@
+
+
+
+
+
+
{
@@ -520,11 +537,14 @@ public class MySurfaceView extends SurfaceView implements Callback {
protected Bitmap detectAndDraw(Bitmap image) {
Box[] result = null;
- KeyPoint[] keyPoints = null;
+ KeyPoint[] keyPoints;
if (USE_MODEL == YOLOV5S) {
+ keyPoints = null;
result = YOLOv5.detect(image, threshold, nms_threshold);
} else if (USE_MODEL == SIMPLE_POSE) {
keyPoints = SimplePose.detect(image);
+ } else {
+ keyPoints = null;
}
if (result == null && keyPoints == null) {
detectCamera.set(false);
diff --git a/src/app/src/main/java/wificar/MyVideo.java b/src/app/src/main/java/wificar/MyVideo.java
index 308a174..d986129 100644
--- a/src/app/src/main/java/wificar/MyVideo.java
+++ b/src/app/src/main/java/wificar/MyVideo.java
@@ -1,32 +1,40 @@
package wificar;
import android.app.Activity;
+import android.content.Context;
import android.content.Intent;
+import android.graphics.Bitmap;
+import android.graphics.Canvas;
+import android.hardware.display.DisplayManager;
+import android.hardware.display.VirtualDisplay;
+import android.media.MediaScannerConnection;
+import android.media.projection.MediaProjection;
+import android.media.projection.MediaProjectionManager;
+import android.net.Uri;
import android.os.Bundle;
+import android.os.Environment;
import android.os.Message;
import android.os.StrictMode;
+import android.util.DisplayMetrics;
import android.util.Log;
import android.view.KeyEvent;
+import android.view.Surface;
import android.view.View;
-import android.view.View.OnClickListener;
import android.view.Window;
import android.view.WindowManager;
-import android.widget.Button;
import android.widget.ImageButton;
-import android.widget.LinearLayout;
import android.widget.RelativeLayout;
import android.widget.Toast;
-import androidx.annotation.BinderThread;
-
+import java.io.File;
+import java.io.FileOutputStream;
+import java.io.IOException;
+import java.io.InputStream;
import java.io.OutputStream;
import java.net.InetAddress;
import java.net.Socket;
import java.net.URL;
import java.net.UnknownHostException;
-import java.sql.Time;
-import java.util.Timer;
-import java.util.TimerTask;
import my.wificar.R;
@@ -37,9 +45,11 @@ public class MyVideo extends Activity {
URL videoUrl;
MySurfaceView r;
OutputStream socketWriter;
- private ImageButton TakePhotos;
- private ImageButton ViewPhotos;
+ InputStream socketReader;
+ SocketListener socketListener2001;
+ SoundSocketListener socketListener2002;
private Socket socket;
+ private Socket soundSocket;
private RockerView rockerView;
private long exitTime = 0;
@@ -54,8 +64,6 @@ public class MyVideo extends Activity {
StrictMode.setThreadPolicy(policy);
}
r = findViewById(R.id.mySurfaceViewVideo);
- TakePhotos = findViewById(R.id.TakePhoto);
- ViewPhotos = findViewById(R.id.ViewPhoto);
Intent intent = getIntent();
//Intentиkeyȡvalue
@@ -65,31 +73,13 @@ public class MyVideo extends Activity {
Log.d("wifirobot", "control is :++++" + CtrlIp);
Log.d("wifirobot", "CtrlPort is :++++" + CtrlPort);
r.GetCameraIP(CameraIp);
-
- TakePhotos.setOnClickListener(arg0 -> {
- // TODO Auto-generated method stub
- if (null != Constant.handler) {
- Message message = new Message();
- message.what = 1;
- Constant.handler.sendMessage(message);
- }
- });
-
- ViewPhotos.setOnClickListener(arg0 -> {
- // TODO Auto-generated method stub
- Intent intent1 = new Intent();
- intent1.setClass(MyVideo.this, BgPictureShowActivity.class);
- //ͨIntentһActivity
- MyVideo.this.startActivity(intent1);
-
- });
- new Thread(()->InitSocket()).run();
+ InitSocket(this);
}
-
- public void InitSocket() {
+ public void InitSocket(Activity activity) {
try {
socket = new Socket(InetAddress.getByName(CtrlIp), Integer.parseInt(CtrlPort));
+ soundSocket = new Socket(InetAddress.getByName(CtrlIp), 2002);
} catch (UnknownHostException e) {
// TODO Auto-generated catch block
e.printStackTrace();
@@ -99,19 +89,21 @@ public class MyVideo extends Activity {
}
try {
socketWriter = socket.getOutputStream();
+ socketReader = socket.getInputStream();
+ socketListener2001 = new SocketListener(activity,socketReader);
+ socketListener2002 = new SoundSocketListener(activity,soundSocket.getInputStream());
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
rockerView = new RockerView(this,socketWriter,this.getApplicationContext(),null);
- RelativeLayout.LayoutParams params = new RelativeLayout.LayoutParams(1000,1000);
+ RelativeLayout.LayoutParams params = new RelativeLayout.LayoutParams(500,500);
addContentView(rockerView,params);
//Toast.makeText(this,"ʼʧܣ"+e.getMessage(),Toast.LENGTH_LONG).show();
}
public void onDestroy() {
super.onDestroy();
-
}
@Override
diff --git a/src/app/src/main/java/wificar/RockerView.java b/src/app/src/main/java/wificar/RockerView.java
index f36a4ef..b850327 100644
--- a/src/app/src/main/java/wificar/RockerView.java
+++ b/src/app/src/main/java/wificar/RockerView.java
@@ -23,8 +23,8 @@ public class RockerView extends View{
Paint backPaint = new Paint(); //
Paint bubblePaint = new Paint(); // ݻ
Paint rectfPaint = new Paint();
- float bubbleX = 300, bubbleY = 700; // ݵλ
- float backX = 300, backY = 700; // Բλ
+ float bubbleX = 0, bubbleY = 0; // ݵλ
+ float backX = 0, backY = 0; // Բλ
int radiusBack = 200, radiusBubble = 100; // 屳ԲԼݵİ뾶
RectF mRectF = new RectF(backX-radiusBack,backY-radiusBack,backX+radiusBack,backY+radiusBack);
Context mContext;
diff --git a/src/app/src/main/java/wificar/SocketListener.java b/src/app/src/main/java/wificar/SocketListener.java
new file mode 100644
index 0000000..1510865
--- /dev/null
+++ b/src/app/src/main/java/wificar/SocketListener.java
@@ -0,0 +1,88 @@
+package wificar;
+
+import android.app.Activity;
+import android.content.Intent;
+import android.graphics.Bitmap;
+import android.net.Uri;
+import android.os.AsyncTask;
+import android.os.Environment;
+import android.view.View;
+import android.widget.ImageView;
+import android.widget.TextView;
+import android.widget.Toast;
+
+import androidx.loader.content.AsyncTaskLoader;
+
+import java.io.File;
+import java.io.FileOutputStream;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.OutputStream;
+
+import my.wificar.R;
+
+public class SocketListener {
+ private Activity activity;
+ private InputStream inputStream;
+
+ public SocketListener(Activity activity,InputStream inputStream) {
+ this.activity = activity;
+ this.inputStream = inputStream;
+
+ AsyncTask.execute(()->{
+ while (true) {
+ try {
+ if (inputStream.available() != 0) {
+ int value = inputStream.read();
+ int input1 = value % 2;
+ int input2 = value >> 1;
+
+ onMessage1(input1);
+ onMessage2(input2);
+ }
+ } catch (IOException e) {
+ throw new RuntimeException(e);
+ }
+ }
+ });
+ AsyncTask.execute(()->{
+ while(true) {
+ try {
+ Thread.sleep(1000);
+ onMessage1(0);
+ } catch (InterruptedException e) {
+ throw new RuntimeException(e);
+ }
+ }
+ });
+ }
+ int count = 0;
+ private void onMessage1(int inputValue) {
+ //TODO
+ activity.runOnUiThread(()->{
+ TextView textComponent = activity.findViewById(R.id.showLive);
+ ImageView redCircle = activity.findViewById(R.id.redCircle);
+ ImageView greenCircle = activity.findViewById(R.id.greenCircle);
+ if(inputValue == 1) {
+ textComponent.setText("д");
+ greenCircle.setVisibility(View.VISIBLE);
+ redCircle.setVisibility(View.GONE);
+ count++;
+ if(count >= 60) {
+ count = 0;
+ Configuration.getInstance().needSaveScreenShot = true;
+ }
+ } else {
+ textComponent.setText("δ");
+ greenCircle.setVisibility(View.GONE);
+ redCircle.setVisibility(View.VISIBLE);
+ }
+ });
+ }
+ private void onMessage2(int inputValue) {
+ activity.runOnUiThread(()->{
+ TextView textView = activity.findViewById(R.id.distance);
+ textView.setText(inputValue+"");
+ });
+ }
+}
diff --git a/src/app/src/main/java/wificar/SoundSocketListener.java b/src/app/src/main/java/wificar/SoundSocketListener.java
new file mode 100644
index 0000000..baab1a5
--- /dev/null
+++ b/src/app/src/main/java/wificar/SoundSocketListener.java
@@ -0,0 +1,54 @@
+package wificar;
+
+import android.app.Activity;
+import android.os.AsyncTask;
+import android.view.View;
+import android.widget.ImageView;
+import android.widget.TextView;
+import android.widget.Toast;
+
+import java.io.IOException;
+import java.io.InputStream;
+
+import my.wificar.R;
+
+public class SoundSocketListener {
+ private Activity activity;
+ private InputStream inputStream;
+
+ public SoundSocketListener(Activity activity, InputStream inputStream) {
+ this.activity = activity;
+ this.inputStream = inputStream;
+
+ AsyncTask.execute(()->{
+ while (true) {
+ try {
+ if (inputStream.available() != 0) {
+ if(inputStream.read() == 255) {
+ int value = inputStream.read();
+ if(inputStream.read() == 255) {
+ onMessage(value);
+ }
+ }
+ if(inputStream.read() == 254) {
+ int value = inputStream.read();
+ if(inputStream.read() == 254) {
+ activity.runOnUiThread(()->{
+ Toast.makeText(activity,"ݣ"+value,Toast.LENGTH_SHORT).show();
+ });
+ }
+ }
+ }
+ } catch (IOException e) {
+ throw new RuntimeException(e);
+ }
+ }
+ });
+ }
+ private void onMessage(int inputValue) {
+ //TODO
+ activity.runOnUiThread(()->{
+ Toast.makeText(activity, inputValue, Toast.LENGTH_SHORT).show();
+ });
+ }
+}
diff --git a/src/app/src/main/res/layout/activity_settings.xml b/src/app/src/main/res/layout/activity_settings.xml
index 03c2f93..b533653 100644
--- a/src/app/src/main/res/layout/activity_settings.xml
+++ b/src/app/src/main/res/layout/activity_settings.xml
@@ -32,7 +32,7 @@
android:id="@+id/button6"
android:layout_width="100dp"
android:layout_height="35dp"
- android:layout_marginStart="144dp"
+ android:layout_marginStart="130dp"
android:text="绝对位置模式"
android:textSize="12sp"
app:layout_constraintBottom_toBottomOf="@+id/textView"
@@ -41,9 +41,9 @@
-
-
+ app:layout_constraintBottom_toBottomOf="@+id/controlIp"
+ app:layout_constraintStart_toEndOf="@+id/controlIp" />
-
-
-
-
-
-
-
-
-
-
+ app:layout_constraintEnd_toEndOf="parent"
+ app:layout_constraintStart_toStartOf="parent"
+ app:layout_constraintTop_toTopOf="parent">
+
+
+
+
-
-
-
-
+ android:layout_marginBottom="20dp"
+ android:gravity="right">
+ android:textSize="18dp"
+ android:textStyle="bold" />
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+