Browse Source

removed Fragment classes from MainActivity

koLayoutTest
Oliver Kleinecke 1 year ago
parent
commit
746eec18ba

+ 48
- 0
app/src/main/java/com/example/ueberwachungssystem/Fragments/Fragment1.java View File

@@ -0,0 +1,48 @@
package com.example.ueberwachungssystem.Fragments;

import android.os.Bundle;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import androidx.fragment.app.Fragment;

import com.example.ueberwachungssystem.R;

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

+ 46
- 0
app/src/main/java/com/example/ueberwachungssystem/Fragments/Fragment2.java View File

@@ -0,0 +1,46 @@
package com.example.ueberwachungssystem.Fragments;

import android.os.Bundle;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import androidx.fragment.app.Fragment;

import com.example.ueberwachungssystem.R;

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

+ 46
- 0
app/src/main/java/com/example/ueberwachungssystem/Fragments/Fragment3.java View File

@@ -0,0 +1,46 @@
package com.example.ueberwachungssystem.Fragments;

import android.os.Bundle;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import androidx.fragment.app.Fragment;

import com.example.ueberwachungssystem.R;

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

+ 11
- 105
app/src/main/java/com/example/ueberwachungssystem/MainActivity.java View File

@@ -20,11 +20,19 @@ 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";
@@ -84,18 +92,18 @@ public class MainActivity extends AppCompatActivity implements View.OnClickListe
public void onClickZeigeFragment1(View view) {
Button button = (Button) view;
log(button.getText() + " ausgewählt");
zeigeFragment(Fragment1.erstellen("Fragment 1 wurde angeklickt"));
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"));
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"));
zeigeFragment(fragment3.erstellen("Fragment 3 wurde angeklickt"));
}

public void onClickEntferneFragment(View view) {
@@ -115,106 +123,4 @@ public class MainActivity extends AppCompatActivity implements View.OnClickListe
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");
}
}
}
}

Loading…
Cancel
Save