|
|
@@ -1,126 +1,17 @@ |
|
|
|
package com.example.ueberwachungssystem; |
|
|
|
|
|
|
|
import androidx.annotation.NonNull; |
|
|
|
|
|
|
|
import androidx.camera.core.ExperimentalGetImage; |
|
|
|
import androidx.fragment.app.Fragment; |
|
|
|
import androidx.fragment.app.FragmentTransaction; |
|
|
|
import androidx.appcompat.app.AppCompatActivity; |
|
|
|
|
|
|
|
import android.os.Bundle; |
|
|
|
import android.util.Log; |
|
|
|
import android.view.LayoutInflater; |
|
|
|
import android.view.View; |
|
|
|
import android.view.ViewGroup; |
|
|
|
import android.widget.Button; |
|
|
|
import android.widget.EditText; |
|
|
|
import android.widget.ScrollView; |
|
|
|
import android.widget.TextView; |
|
|
|
import android.widget.ToggleButton; |
|
|
|
|
|
|
|
import com.example.ueberwachungssystem.Detection.DetectionReport; |
|
|
|
import com.example.ueberwachungssystem.Detection.Detector; |
|
|
|
import com.example.ueberwachungssystem.Detection.VideoDetector; |
|
|
|
import com.example.ueberwachungssystem.Fragments.Fragment1; |
|
|
|
import com.example.ueberwachungssystem.Fragments.Fragment2; |
|
|
|
import com.example.ueberwachungssystem.Fragments.Fragment3; |
|
|
|
|
|
|
|
import org.w3c.dom.Text; |
|
|
|
|
|
|
|
@ExperimentalGetImage |
|
|
|
public class MainActivity extends AppCompatActivity implements View.OnClickListener { |
|
|
|
private Fragment aktuellesFragment; |
|
|
|
private Fragment1 fragment1; |
|
|
|
private Fragment2 fragment2; |
|
|
|
private Fragment3 fragment3; |
|
|
|
|
|
|
|
WifiCommunication communication; |
|
|
|
private TextView alarm; |
|
|
|
private String text = "Das ist ein Alarm des Sensors"; |
|
|
|
//Buttons |
|
|
|
private ToggleButton toggleKamera; |
|
|
|
private ToggleButton btnAudio; |
|
|
|
private ToggleButton btnBewegung; |
|
|
|
//Detektoren |
|
|
|
VideoDetector vd = new VideoDetector(this); |
|
|
|
private void log(String nachricht) { |
|
|
|
Log.d(this.getClass().getSimpleName(), nachricht); |
|
|
|
} |
|
|
|
public class MainActivity extends AppCompatActivity{ |
|
|
|
|
|
|
|
@Override |
|
|
|
protected void onCreate(Bundle savedInstanceState) { |
|
|
|
super.onCreate(savedInstanceState); |
|
|
|
setTitle(this.getClass().getSimpleName()); |
|
|
|
setContentView(R.layout.activity_main); |
|
|
|
alarm = findViewById(R.id.Alarm); |
|
|
|
alarm.setText(text); |
|
|
|
toggleKamera = findViewById(R.id.toggleKamera); |
|
|
|
toggleKamera.setOnClickListener(this); |
|
|
|
vd.setOnDetectionListener(new Detector.OnDetectionListener() { |
|
|
|
@Override |
|
|
|
public void onDetection(@NonNull DetectionReport detectionReport) { |
|
|
|
DetectionReport dr = detectionReport; |
|
|
|
String drString = dr.toString(); |
|
|
|
} |
|
|
|
}); |
|
|
|
|
|
|
|
//boolean isRunning = vd.isRunning(); |
|
|
|
|
|
|
|
} |
|
|
|
@Override |
|
|
|
public void onClick(View v) { |
|
|
|
if (v == toggleKamera) { |
|
|
|
if (toggleKamera.isChecked()) { |
|
|
|
vd.startDetection(); |
|
|
|
} else { |
|
|
|
vd.stopDetection(); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
@Override |
|
|
|
protected void onPause() { |
|
|
|
super.onPause(); |
|
|
|
communication.stopCommunication(); |
|
|
|
} |
|
|
|
|
|
|
|
@Override |
|
|
|
protected void onResume() { |
|
|
|
super.onResume(); |
|
|
|
communication = new WifiCommunication(1234); |
|
|
|
} |
|
|
|
|
|
|
|
public void onClickZeigeFragment1(View view) { |
|
|
|
Button button = (Button) view; |
|
|
|
log(button.getText() + " ausgewählt"); |
|
|
|
zeigeFragment(fragment1.erstellen("Fragment 1 wurde angeklickt")); |
|
|
|
} |
|
|
|
public void onClickZeigeFragment2(View view) { |
|
|
|
Button button = (Button) view; |
|
|
|
log(button.getText() + " ausgewählt"); |
|
|
|
zeigeFragment(fragment2.erstellen("Fragment 2 wurde angeklickt")); |
|
|
|
} |
|
|
|
|
|
|
|
public void onClickZeigeFragment3(View view) { |
|
|
|
Button button = (Button) view; |
|
|
|
log(button.getText() + " ausgewählt"); |
|
|
|
zeigeFragment(fragment3.erstellen("Fragment 3 wurde angeklickt")); |
|
|
|
} |
|
|
|
|
|
|
|
public void onClickEntferneFragment(View view) { |
|
|
|
entferneFragment(); |
|
|
|
} |
|
|
|
private void zeigeFragment(Fragment fragment) { |
|
|
|
FragmentTransaction ft = getSupportFragmentManager().beginTransaction(); |
|
|
|
ft.replace(R.id.frame, fragment); |
|
|
|
ft.commit(); |
|
|
|
aktuellesFragment = fragment; |
|
|
|
} |
|
|
|
private void entferneFragment() { |
|
|
|
if (aktuellesFragment != null) { |
|
|
|
FragmentTransaction ft = getSupportFragmentManager().beginTransaction(); |
|
|
|
ft.remove(aktuellesFragment); |
|
|
|
ft.commit(); |
|
|
|
aktuellesFragment = null ; |
|
|
|
} |
|
|
|
} |
|
|
|
} |