parent
a79550ee1c
commit
746392a6f6
@ -0,0 +1,15 @@
|
||||
package wificar;
|
||||
|
||||
public class Configuration {
|
||||
public String videoUrl = "http://192.168.1.1:8080/?action=stream";
|
||||
public String controlIp = "192.168.1.1";
|
||||
public String controlPort = "2001";
|
||||
|
||||
public boolean needSaveScreenShot = false;
|
||||
private Configuration(){}
|
||||
private static Configuration INSTANCE;
|
||||
public static Configuration getInstance() {
|
||||
if(INSTANCE == null) INSTANCE = new Configuration();
|
||||
return INSTANCE;
|
||||
}
|
||||
}
|
@ -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+"");
|
||||
});
|
||||
}
|
||||
}
|
@ -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();
|
||||
});
|
||||
}
|
||||
}
|
Loading…
Reference in new issue