Browse Source

Removed unnecessary code parts

lm
Leon Market 1 year ago
parent
commit
cafe763c4a

+ 6
- 13
app/src/main/java/com/example/ueberwachungssystem/Accelerometer.java View File

@@ -14,32 +14,27 @@ import androidx.appcompat.app.AppCompatActivity;
public class Accelerometer extends Detector implements SensorEventListener {

Logger logger;

private volatile boolean running = false;
public SensorManager sensorManager;
private static final int sensorType = Sensor.TYPE_LINEAR_ACCELERATION;
private Sensor accelerometer;
private Context context;

private String threadName = "Accelerometer Thread";
boolean alarm = false;
//Preallocate memory for the data of each axis of the acceleration sensor
float x;
float y;
float z;
float betrag; //Betrag aller drei Achsen sqrt(x*x + y*y + z*z)
private TextView textViewWorkerThread;
private AppCompatActivity activity;
private DetectionReport detectionReport;
TextView textViewLog;


// In constructor pass Activity, Context and TextView from MainActivity in Accelerometer class
public Accelerometer(Context context, Logger mainLogger, TextView textViewWorkerThread){
public Accelerometer(Context context, Logger mainLogger, TextView textViewLog){
super(context); //von Detektor
logger = mainLogger;
this.context = context;
this.textViewWorkerThread = textViewWorkerThread;
Logger logger = new Logger(this.getClass().getSimpleName(), textViewWorkerThread, "");
this.textViewLog = textViewLog;
//Logger logger = new Logger(this.getClass().getSimpleName(), textViewLog, "");
}

public void getSensor(){
@@ -57,7 +52,7 @@ public class Accelerometer extends Detector implements SensorEventListener {

void start() {
// register the sensor before using //
sensorManager.registerListener(this, accelerometer, SensorManager.SENSOR_DELAY_GAME);
sensorManager.registerListener(this, accelerometer, SensorManager.SENSOR_DELAY_NORMAL);
logger.log("Accelerometer, start!");
}

@@ -81,8 +76,6 @@ public class Accelerometer extends Detector implements SensorEventListener {
z = event.values[2];
betrag = (float) sqrt(x*x + y*y + z*z);
double schwelle = 1.5;
//stringBuffer.append("\nBetrag =" + betrag);
//logger.log("Betrag" + betrag);

if (!alarm) {
if (betrag > schwelle) {
@@ -111,7 +104,7 @@ public class Accelerometer extends Detector implements SensorEventListener {
logger.log("Betragswert immer noch über Schwellwert: " + betrag + "; Alarm bleibt an.");
logger.log("Betragswert immer noch über Schwellwert: " + betrag + "; Alarm bleibt an.");
}
logger.clearLog();
//logger.clearLog();
logger.log(stringBuffer.toString());
stringBuffer.delete(0, stringBuffer.length());
}

+ 2
- 8
app/src/main/java/com/example/ueberwachungssystem/MainActivity.java View File

@@ -54,16 +54,14 @@ public class MainActivity extends AppCompatActivity implements View.OnClickListe
logger.log("onCreate");
}

@Override
@Override
protected void onResume() {
super.onResume();
}
@Override
protected void onPause() {
super.onPause();
//beschleunigungssensor.stop();
//threadDemo.stop();

beschleunigungssensor.stopDetection();
}

@Override
@@ -72,15 +70,11 @@ public class MainActivity extends AppCompatActivity implements View.OnClickListe
if(v == toggleButton1) {
if (toggleButton1.isChecked()) {
logger.log("ToggleButton is ON");
//beschleunigungssensor.start();
beschleunigungssensor.startDetection();
logger.log("Detection started");
//logger.log(stringBuffer.toString());

} else {
logger.log("ToggleButton is OFF");
//threadDemo.stop();
//beschleunigungssensor.stop();
beschleunigungssensor.stopDetection();
logger.log("Detection stopped");
}

Loading…
Cancel
Save