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

public class Accelerometer extends Detector implements SensorEventListener { public class Accelerometer extends Detector implements SensorEventListener {


Logger logger; Logger logger;

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

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




// In constructor pass Activity, Context and TextView from MainActivity in Accelerometer class // 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 super(context); //von Detektor
logger = mainLogger; logger = mainLogger;
this.context = context; 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(){ public void getSensor(){


void start() { void start() {
// register the sensor before using // // 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!"); logger.log("Accelerometer, start!");
} }


z = event.values[2]; z = event.values[2];
betrag = (float) sqrt(x*x + y*y + z*z); betrag = (float) sqrt(x*x + y*y + z*z);
double schwelle = 1.5; double schwelle = 1.5;
//stringBuffer.append("\nBetrag =" + betrag);
//logger.log("Betrag" + betrag);


if (!alarm) { if (!alarm) {
if (betrag > schwelle) { if (betrag > schwelle) {
logger.log("Betragswert immer noch über Schwellwert: " + betrag + "; Alarm bleibt an."); logger.log("Betragswert immer noch über Schwellwert: " + betrag + "; Alarm bleibt an.");
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()); logger.log(stringBuffer.toString());
stringBuffer.delete(0, stringBuffer.length()); stringBuffer.delete(0, stringBuffer.length());
} }

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

logger.log("onCreate"); logger.log("onCreate");
} }


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

beschleunigungssensor.stopDetection();
} }


@Override @Override
if(v == toggleButton1) { if(v == toggleButton1) {
if (toggleButton1.isChecked()) { if (toggleButton1.isChecked()) {
logger.log("ToggleButton is ON"); logger.log("ToggleButton is ON");
//beschleunigungssensor.start();
beschleunigungssensor.startDetection(); beschleunigungssensor.startDetection();
logger.log("Detection started"); logger.log("Detection started");
//logger.log(stringBuffer.toString());


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

Loading…
Cancel
Save