Browse Source

Kopie Master Version 1.2 UDP Socket merged with sensor

copie
Miguel Siebenhaar 1 year ago
parent
commit
5b042611a5

+ 28
- 17
app/src/main/java/com/example/ueberwachungssystem/Detection/DetectorService.java View File

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) {
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 **/
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**/
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 **/
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**/








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);
} }






/** 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);

}
} }

+ 46
- 7
app/src/main/java/com/example/ueberwachungssystem/MainActivity.java View File

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;
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;
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);
button1.setOnClickListener(new View.OnClickListener() {
Intent serviceIntent = new Intent(this, DetectorService.class);
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();
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()) {
default: default:
return super.onOptionsItemSelected(item); return super.onOptionsItemSelected(item);
} }
}
}*/

} }



Loading…
Cancel
Save