package de.oklein.android.ueberwachungssystem; | |||||
import android.content.Context; | |||||
import androidx.test.platform.app.InstrumentationRegistry; | |||||
import androidx.test.ext.junit.runners.AndroidJUnit4; | |||||
import org.junit.Test; | |||||
import org.junit.runner.RunWith; | |||||
import static org.junit.Assert.*; | |||||
/** | |||||
* Instrumented test, which will execute on an Android device. | |||||
* | |||||
* @see <a href="http://d.android.com/tools/testing">Testing documentation</a> | |||||
*/ | |||||
@RunWith(AndroidJUnit4.class) | |||||
public class ExampleInstrumentedTest { | |||||
@Test | |||||
public void useAppContext() { | |||||
// Context of the app under test. | |||||
Context appContext = InstrumentationRegistry.getInstrumentation().getTargetContext(); | |||||
assertEquals("de.oklein.android.ueberwachungssystem", appContext.getPackageName()); | |||||
} | |||||
} |
package de.oklein.android.ueberwachungssystem.Logger; | |||||
package com.example.ueberwachungssystem.Logger; | |||||
import android.util.Log; | import android.util.Log; | ||||
import android.widget.TextView; | import android.widget.TextView; |
package com.example.ueberwachungssystem; | 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 androidx.appcompat.app.AppCompatActivity; | ||||
import android.os.Bundle; | 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; | |||||
public class MainActivity extends AppCompatActivity { | |||||
import com.example.ueberwachungssystem.Detection.DetectionReport; | |||||
import com.example.ueberwachungssystem.Detection.Detector; | |||||
import com.example.ueberwachungssystem.Detection.VideoDetector; | |||||
import org.w3c.dom.Text; | |||||
@ExperimentalGetImage | |||||
public class MainActivity extends AppCompatActivity implements View.OnClickListener { | |||||
private Fragment aktuellesFragment; | |||||
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); | |||||
} | |||||
@Override | @Override | ||||
protected void onCreate(Bundle savedInstanceState) { | protected void onCreate(Bundle savedInstanceState) { | ||||
super.onCreate(savedInstanceState); | super.onCreate(savedInstanceState); | ||||
setTitle(this.getClass().getSimpleName()); | |||||
setContentView(R.layout.activity_main); | 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(); | |||||
} | |||||
} | |||||
} | |||||
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 ; | |||||
} | |||||
} | |||||
public static class Fragment1 extends Fragment { | |||||
private String text; | |||||
private final static String KEY_TEXT = "KEY_TEXT"; | |||||
private void log(String nachricht) { | |||||
Log.d(this.getClass().getSimpleName(), nachricht); | |||||
} | |||||
@Override | |||||
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle bundle) { | |||||
log("onCreateView"); | |||||
View view = inflater.inflate(R.layout.fragment1, container, false); | |||||
TextView Sensor = (TextView) view.findViewById(R.id.Sensor); | |||||
Sensor.setText(text); | |||||
return view; | |||||
} | |||||
public static Fragment1 erstellen(String text) { | |||||
Fragment1 fragment = new Fragment1(); | |||||
Bundle b = new Bundle(); | |||||
b.putString(KEY_TEXT, text); | |||||
fragment.setArguments(b); | |||||
return fragment; | |||||
} | |||||
@Override | |||||
public void onCreate(Bundle bundle) { | |||||
super .onCreate(bundle); | |||||
Bundle args = getArguments(); | |||||
if (args != null ) { | |||||
text = args.getString(KEY_TEXT); | |||||
log("onCreate: text=" + text); | |||||
} else { | |||||
log("onCreate"); | |||||
} | |||||
} | |||||
} | |||||
public static class Fragment2 extends Fragment { | |||||
private String text; | |||||
private final static String KEY_TEXT = "KEY_TEXT" ; | |||||
private void log(String nachricht) { | |||||
Log.d(this.getClass().getSimpleName(), nachricht); | |||||
} | |||||
@Override | |||||
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle bundle) { | |||||
log( "onCreateView" ); | |||||
View view = inflater.inflate(R.layout.fragment2, container, false ); | |||||
TextView Sensor = (TextView) view.findViewById(R.id.Sensor); | |||||
Sensor.setText(text); | |||||
return view; | |||||
} | |||||
public static Fragment2 erstellen(String text) { | |||||
Fragment2 fragment = new Fragment2(); | |||||
Bundle b = new Bundle(); | |||||
b.putString(KEY_TEXT, text); | |||||
fragment.setArguments(b); | |||||
return fragment; | |||||
} | |||||
@Override | |||||
public void onCreate(Bundle bundle) { | |||||
super.onCreate(bundle); | |||||
Bundle args = getArguments(); | |||||
if (args != null) { | |||||
text = args.getString(KEY_TEXT); | |||||
log("onCreate: text=" + text); | |||||
} else { | |||||
log("onCreate"); | |||||
} | |||||
} | |||||
} | |||||
public static class Fragment3 extends Fragment { | |||||
private String text; | |||||
private final static String KEY_TEXT = "KEY_TEXT" ; | |||||
private void log(String nachricht) { | |||||
Log.d(this.getClass().getSimpleName(), nachricht); | |||||
} | |||||
@Override | |||||
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle bundle) { | |||||
log( "onCreateView" ); | |||||
View view = inflater.inflate(R.layout.fragment2, container, false ); | |||||
TextView Sensor = (TextView) view.findViewById(R.id.Sensor); | |||||
Sensor.setText(text); | |||||
return view; | |||||
} | |||||
public static Fragment3 erstellen(String text) { | |||||
Fragment3 fragment = new Fragment3(); | |||||
Bundle b = new Bundle(); | |||||
b.putString(KEY_TEXT, text); | |||||
fragment.setArguments(b); | |||||
return fragment; | |||||
} | |||||
@Override | |||||
public void onCreate(Bundle bundle) { | |||||
super.onCreate(bundle); | |||||
Bundle args = getArguments(); | |||||
if (args != null) { | |||||
text = args.getString(KEY_TEXT); | |||||
log("onCreate: text=" + text); | |||||
} else { | |||||
log("onCreate"); | |||||
} | |||||
} | |||||
} | } | ||||
} | } |
package de.oklein.android.ueberwachungssystem; | |||||
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 org.w3c.dom.Text; | |||||
public class MainActivity extends AppCompatActivity { | |||||
private Fragment aktuellesFragment; | |||||
private TextView alarm; | |||||
private String text = "Das ist ein Alarm des Sensors"; | |||||
private void log(String nachricht) { | |||||
Log.d(this.getClass().getSimpleName(), nachricht); | |||||
} | |||||
@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); | |||||
} | |||||
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 ; | |||||
} | |||||
} | |||||
public static class Fragment1 extends Fragment { | |||||
private String text; | |||||
private final static String KEY_TEXT = "KEY_TEXT"; | |||||
private void log(String nachricht) { | |||||
Log.d(this.getClass().getSimpleName(), nachricht); | |||||
} | |||||
@Override | |||||
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle bundle) { | |||||
log("onCreateView"); | |||||
View view = inflater.inflate(R.layout.fragment1, container, false); | |||||
TextView Sensor = (TextView) view.findViewById(R.id.Sensor); | |||||
Sensor.setText(text); | |||||
return view; | |||||
} | |||||
public static Fragment1 erstellen(String text) { | |||||
Fragment1 fragment = new Fragment1(); | |||||
Bundle b = new Bundle(); | |||||
b.putString(KEY_TEXT, text); | |||||
fragment.setArguments(b); | |||||
return fragment; | |||||
} | |||||
@Override | |||||
public void onCreate(Bundle bundle) { | |||||
super .onCreate(bundle); | |||||
Bundle args = getArguments(); | |||||
if (args != null ) { | |||||
text = args.getString(KEY_TEXT); | |||||
log("onCreate: text=" + text); | |||||
} else { | |||||
log("onCreate"); | |||||
} | |||||
} | |||||
} | |||||
public static class Fragment2 extends Fragment { | |||||
private String text; | |||||
private final static String KEY_TEXT = "KEY_TEXT" ; | |||||
private void log(String nachricht) { | |||||
Log.d(this.getClass().getSimpleName(), nachricht); | |||||
} | |||||
@Override | |||||
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle bundle) { | |||||
log( "onCreateView" ); | |||||
View view = inflater.inflate(R.layout.fragment2, container, false ); | |||||
TextView Sensor = (TextView) view.findViewById(R.id.Sensor); | |||||
Sensor.setText(text); | |||||
return view; | |||||
} | |||||
public static Fragment2 erstellen(String text) { | |||||
Fragment2 fragment = new Fragment2(); | |||||
Bundle b = new Bundle(); | |||||
b.putString(KEY_TEXT, text); | |||||
fragment.setArguments(b); | |||||
return fragment; | |||||
} | |||||
@Override | |||||
public void onCreate(Bundle bundle) { | |||||
super.onCreate(bundle); | |||||
Bundle args = getArguments(); | |||||
if (args != null) { | |||||
text = args.getString(KEY_TEXT); | |||||
log("onCreate: text=" + text); | |||||
} else { | |||||
log("onCreate"); | |||||
} | |||||
} | |||||
} | |||||
public static class Fragment3 extends Fragment { | |||||
private String text; | |||||
private final static String KEY_TEXT = "KEY_TEXT" ; | |||||
private void log(String nachricht) { | |||||
Log.d(this.getClass().getSimpleName(), nachricht); | |||||
} | |||||
@Override | |||||
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle bundle) { | |||||
log( "onCreateView" ); | |||||
View view = inflater.inflate(R.layout.fragment2, container, false ); | |||||
TextView Sensor = (TextView) view.findViewById(R.id.Sensor); | |||||
Sensor.setText(text); | |||||
return view; | |||||
} | |||||
public static Fragment3 erstellen(String text) { | |||||
Fragment3 fragment = new Fragment3(); | |||||
Bundle b = new Bundle(); | |||||
b.putString(KEY_TEXT, text); | |||||
fragment.setArguments(b); | |||||
return fragment; | |||||
} | |||||
@Override | |||||
public void onCreate(Bundle bundle) { | |||||
super.onCreate(bundle); | |||||
Bundle args = getArguments(); | |||||
if (args != null) { | |||||
text = args.getString(KEY_TEXT); | |||||
log("onCreate: text=" + text); | |||||
} else { | |||||
log("onCreate"); | |||||
} | |||||
} | |||||
} | |||||
} |
android:layout_height="match_parent" | android:layout_height="match_parent" | ||||
android:background="@android:color/holo_green_dark" | android:background="@android:color/holo_green_dark" | ||||
android:visibility="visible" | android:visibility="visible" | ||||
tools:context="de.oklein.android.ueberwachungssystem.MainActivity" | |||||
tools:context="com.example.ueberwachungssystem.MainActivity" | |||||
tools:visibility="visible"> | tools:visibility="visible"> | ||||
<ToggleButton | <ToggleButton | ||||
android:id="@+id/frame" | android:id="@+id/frame" | ||||
android:layout_width="match_parent" | android:layout_width="match_parent" | ||||
android:layout_height="200dp" | android:layout_height="200dp" | ||||
android:layout_below="@+id/btnZwischen" | |||||
android:layout_below="@+id/btnAufnahme" | |||||
android:layout_alignParentStart="true"> | android:layout_alignParentStart="true"> | ||||
</FrameLayout> | </FrameLayout> | ||||
package de.oklein.android.ueberwachungssystem; | |||||
import org.junit.Test; | |||||
import static org.junit.Assert.*; | |||||
/** | |||||
* Example local unit test, which will execute on the development machine (host). | |||||
* | |||||
* @see <a href="http://d.android.com/tools/testing">Testing documentation</a> | |||||
*/ | |||||
public class ExampleUnitTest { | |||||
@Test | |||||
public void addition_isCorrect() { | |||||
assertEquals(4, 2 + 2); | |||||
} | |||||
} |