Kopie Master Version 1.2 UDP Socket merged with sensor
This commit is contained in:
parent
5a0aab0176
commit
5b042611a5
@ -31,6 +31,7 @@ public class DetectorService extends LifecycleService {
|
|||||||
WifiCommunication wifiCommunication;
|
WifiCommunication wifiCommunication;
|
||||||
|
|
||||||
String dataFromWifi;
|
String dataFromWifi;
|
||||||
|
StringBuffer stringBufferFromWifi;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int onStartCommand(Intent intent, int flags, int startId) {
|
public int onStartCommand(Intent intent, int flags, int startId) {
|
||||||
@ -38,6 +39,17 @@ public class DetectorService extends LifecycleService {
|
|||||||
return START_NOT_STICKY;
|
return START_NOT_STICKY;
|
||||||
|
|
||||||
|
|
||||||
|
/** Wifi Instanz Starten und Listener **/
|
||||||
|
wifiCommunication = new WifiCommunication (1234);
|
||||||
|
wifiCommunication.setOnConnectionListener(new WifiCommunication.OnConnectionListener() {
|
||||||
|
@Override
|
||||||
|
public void onConnection(String data) {
|
||||||
|
dataFromWifi = data;
|
||||||
|
stringToStringbuffer(data);
|
||||||
|
}
|
||||||
|
|
||||||
|
});
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/** Video Detection/Recorder **/
|
/** Video Detection/Recorder **/
|
||||||
@ -45,7 +57,8 @@ public class DetectorService extends LifecycleService {
|
|||||||
videoDetector.setOnDetectionListener(new Detector.OnDetectionListener() {
|
videoDetector.setOnDetectionListener(new Detector.OnDetectionListener() {
|
||||||
@Override
|
@Override
|
||||||
public void onDetection(@NonNull DetectionReport detectionReport) {
|
public void onDetection(@NonNull DetectionReport detectionReport) {
|
||||||
passToServiceListener(detectionReport);
|
//passToServiceListener(detectionReport);
|
||||||
|
wifiCommunication.sendTrue(detectionReport.toMessage());
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
/** Motion Detection**/
|
/** Motion Detection**/
|
||||||
@ -54,7 +67,8 @@ public class DetectorService extends LifecycleService {
|
|||||||
motionDetector.setOnDetectionListener(new Detector.OnDetectionListener() {
|
motionDetector.setOnDetectionListener(new Detector.OnDetectionListener() {
|
||||||
@Override
|
@Override
|
||||||
public void onDetection(@NonNull DetectionReport detectionReport) {
|
public void onDetection(@NonNull DetectionReport detectionReport) {
|
||||||
passToServiceListener(detectionReport);
|
//passToServiceListener(detectionReport);
|
||||||
|
wifiCommunication.sendTrue(detectionReport.toMessage());
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
/** Audio Detection **/
|
/** Audio Detection **/
|
||||||
@ -62,7 +76,8 @@ public class DetectorService extends LifecycleService {
|
|||||||
audioDetector.setOnDetectionListener(new Detector.OnDetectionListener() {
|
audioDetector.setOnDetectionListener(new Detector.OnDetectionListener() {
|
||||||
@Override
|
@Override
|
||||||
public void onDetection(@NonNull DetectionReport detectionReport) {
|
public void onDetection(@NonNull DetectionReport detectionReport) {
|
||||||
passToServiceListener(detectionReport);
|
//passToServiceListener(detectionReport);
|
||||||
|
wifiCommunication.sendTrue(detectionReport.toMessage());
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
/** Audio Recorder**/
|
/** Audio Recorder**/
|
||||||
@ -71,18 +86,7 @@ public class DetectorService extends LifecycleService {
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
isServiceRunning = true;
|
isServiceRunning = true;
|
||||||
|
|
||||||
wifiCommunication = new WifiCommunication (1234);
|
|
||||||
wifiCommunication.setOnConnectionListener(new WifiCommunication.OnConnectionListener() {
|
|
||||||
@Override
|
|
||||||
public void onConnection(String data) {
|
|
||||||
dataFromWifi = data;
|
|
||||||
}
|
|
||||||
|
|
||||||
});
|
|
||||||
return super.onStartCommand(intent, flags, startId);
|
return super.onStartCommand(intent, flags, startId);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -108,18 +112,25 @@ public class DetectorService extends LifecycleService {
|
|||||||
|
|
||||||
|
|
||||||
/** Pass Detection Report to Service Detection Listener and trigger it */
|
/** Pass Detection Report to Service Detection Listener and trigger it */
|
||||||
public void passToServiceListener(DetectionReport detectionReport) {
|
public void passToServiceListener(StringBuffer stringBuffer) {
|
||||||
if (listener != null) {
|
if (listener != null) {
|
||||||
listener.onDetection(detectionReport);
|
listener.onDetection(stringBuffer);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/** On Detection Listener - runs when violation is reported */
|
/** On Detection Listener - runs when violation is reported */
|
||||||
public interface OnDetectionListener {
|
public interface OnDetectionListener {
|
||||||
void onDetection(@NonNull DetectionReport detectionReport);
|
void onDetection(@NonNull StringBuffer stringBuffer);
|
||||||
}
|
}
|
||||||
public void setOnDetectionListener(@NonNull DetectorService.OnDetectionListener listener) {
|
public void setOnDetectionListener(@NonNull DetectorService.OnDetectionListener listener) {
|
||||||
this.listener = listener;
|
this.listener = listener;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** string to stringbuffer **/
|
||||||
|
public void stringToStringbuffer(String dataString){
|
||||||
|
stringBufferFromWifi.append(dataString).append("\n");
|
||||||
|
passToServiceListener(stringBufferFromWifi);
|
||||||
|
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -3,11 +3,16 @@ package com.example.ueberwachungssystem;
|
|||||||
import static android.content.ContentValues.TAG;
|
import static android.content.ContentValues.TAG;
|
||||||
|
|
||||||
import android.annotation.SuppressLint;
|
import android.annotation.SuppressLint;
|
||||||
|
import android.content.ComponentName;
|
||||||
|
import android.content.Context;
|
||||||
|
import android.content.Intent;
|
||||||
|
import android.content.ServiceConnection;
|
||||||
import android.net.wifi.WifiInfo;
|
import android.net.wifi.WifiInfo;
|
||||||
import android.net.wifi.WifiManager;
|
import android.net.wifi.WifiManager;
|
||||||
import android.net.wifi.WifiInfo;
|
import android.net.wifi.WifiInfo;
|
||||||
import android.net.wifi.WifiManager;
|
import android.net.wifi.WifiManager;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
|
import android.os.IBinder;
|
||||||
import android.util.Log;
|
import android.util.Log;
|
||||||
import android.view.MenuItem;
|
import android.view.MenuItem;
|
||||||
import android.widget.Toast;
|
import android.widget.Toast;
|
||||||
@ -18,13 +23,19 @@ import android.widget.Button;
|
|||||||
import android.widget.TextView;
|
import android.widget.TextView;
|
||||||
import android.widget.Toast;
|
import android.widget.Toast;
|
||||||
|
|
||||||
|
import androidx.annotation.NonNull;
|
||||||
import androidx.appcompat.app.AppCompatActivity;
|
import androidx.appcompat.app.AppCompatActivity;
|
||||||
|
import androidx.camera.core.ExperimentalGetImage;
|
||||||
|
|
||||||
|
import com.example.ueberwachungssystem.Detection.DetectionReport;
|
||||||
|
import com.example.ueberwachungssystem.Detection.DetectorService;
|
||||||
|
|
||||||
import java.net.InetAddress;
|
import java.net.InetAddress;
|
||||||
import java.net.UnknownHostException;
|
import java.net.UnknownHostException;
|
||||||
import java.nio.ByteBuffer;
|
import java.nio.ByteBuffer;
|
||||||
import java.nio.ByteOrder;
|
import java.nio.ByteOrder;
|
||||||
|
|
||||||
@SuppressLint("SetTextI18n")
|
@ExperimentalGetImage
|
||||||
public class MainActivity extends AppCompatActivity {
|
public class MainActivity extends AppCompatActivity {
|
||||||
|
|
||||||
WifiCommunication communication;
|
WifiCommunication communication;
|
||||||
@ -32,20 +43,47 @@ public class MainActivity extends AppCompatActivity {
|
|||||||
boolean communicationRunning = true;
|
boolean communicationRunning = true;
|
||||||
TextView textview1;
|
TextView textview1;
|
||||||
|
|
||||||
|
private DetectorService detectorService = new DetectorService();
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void onCreate(Bundle savedInstanceState) {
|
protected void onCreate(Bundle savedInstanceState) {
|
||||||
super.onCreate(savedInstanceState);
|
super.onCreate(savedInstanceState);
|
||||||
setContentView(R.layout.activity_main);
|
setContentView(R.layout.activity_main);
|
||||||
textview1 = findViewById(R.id.textView1);
|
|
||||||
|
|
||||||
Button button1 = findViewById(R.id.buttonSend);
|
Intent serviceIntent = new Intent(this, DetectorService.class);
|
||||||
button1.setOnClickListener(new View.OnClickListener() {
|
bindService(serviceIntent, serviceConnection, Context.BIND_AUTO_CREATE);
|
||||||
|
startService(serviceIntent);
|
||||||
|
//textview1 = findViewById(R.id.textView1);
|
||||||
|
|
||||||
|
//Button button1 = findViewById(R.id.buttonSend);
|
||||||
|
/*button1.setOnClickListener(new View.OnClickListener() {
|
||||||
@Override
|
@Override
|
||||||
public void onClick(View v) {
|
public void onClick(View v) {
|
||||||
communication.sendTrue("Testmessage");
|
communication.sendTrue("Testmessage");
|
||||||
}
|
}
|
||||||
});
|
});*/
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private ServiceConnection serviceConnection = new ServiceConnection() {
|
||||||
|
@Override
|
||||||
|
public void onServiceConnected(ComponentName name, IBinder service) {
|
||||||
|
DetectorService.ServiceBinder binder = (DetectorService.ServiceBinder) service;
|
||||||
|
detectorService = binder.getBoundService();
|
||||||
|
|
||||||
|
detectorService.setOnDetectionListener(new DetectorService.OnDetectionListener() {
|
||||||
|
@Override
|
||||||
|
public void onDetection(StringBuffer stringBuffer) {
|
||||||
|
//textview für oli
|
||||||
|
Log.d("Debugger", stringBuffer.toString());
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onServiceDisconnected(ComponentName name) {
|
||||||
|
|
||||||
|
}
|
||||||
|
};
|
||||||
@Override
|
@Override
|
||||||
protected void onResume() {
|
protected void onResume() {
|
||||||
super.onResume();
|
super.onResume();
|
||||||
@ -78,7 +116,7 @@ public class MainActivity extends AppCompatActivity {
|
|||||||
getMenuInflater().inflate(R.menu.options_menu, menu);
|
getMenuInflater().inflate(R.menu.options_menu, menu);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
public boolean onOptionsItemSelected(MenuItem item) {
|
/*public boolean onOptionsItemSelected(MenuItem item) {
|
||||||
Toast.makeText(this, "Selected Item: " + item.getTitle(), Toast.LENGTH_SHORT).show();
|
Toast.makeText(this, "Selected Item: " + item.getTitle(), Toast.LENGTH_SHORT).show();
|
||||||
PopUpClass popUpClass;
|
PopUpClass popUpClass;
|
||||||
switch (item.getItemId()) {
|
switch (item.getItemId()) {
|
||||||
@ -100,6 +138,7 @@ public class MainActivity extends AppCompatActivity {
|
|||||||
default:
|
default:
|
||||||
return super.onOptionsItemSelected(item);
|
return super.onOptionsItemSelected(item);
|
||||||
}
|
}
|
||||||
}
|
}*/
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user