Merge remote-tracking branch 'origin/zwicki_branch'

# Conflicts:
#	app/src/main/java/de/jg_cody/Teraplex/ui/Flur/FlurFragment.java
This commit is contained in:
JG-Cody 2021-06-27 16:32:00 +02:00
commit 7f1460ffa7
11 changed files with 147 additions and 100 deletions

View File

@ -1,6 +1,7 @@
package de.jg_cody.Teraplex;
import android.app.Dialog;
import android.app.Fragment;
import android.content.Context;
import android.content.DialogInterface;
import android.os.Bundle;
@ -8,17 +9,21 @@ import android.app.AlertDialog;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.ArrayAdapter;
import android.widget.EditText;
import androidx.fragment.app.DialogFragment;
import java.util.ArrayList;
import de.jg_cody.Teraplex.ui.Flur.FlurFragment;
import de.jg_cody.Teraplex.ui.rooms.ListItem;
import de.jg_cody.Teraplex.ui.rooms.*;
public class AddButtonDialogSingle extends DialogFragment {
private EditText editTextUsername;
private EditText editTextPassword;
private EditText command, name, button_name;
private AddButtonDialogListener listener;
private EditText editText_command, editText_name, editText_button_name;
private AddButtonDialogListenerSingle listener;
private FlurFragment frag;
/**
*
@ -31,9 +36,9 @@ public class AddButtonDialogSingle extends DialogFragment {
LayoutInflater inflater = getActivity().getLayoutInflater();
View view = inflater.inflate(R.layout.addbuttondialog_single, null);
command = getActivity().findViewById(R.id.dialogSingle_editText_command);
name = getActivity().findViewById(R.id.dialogSingle_editText_name);
button_name = getActivity().findViewById(R.id.dialogSingle_editText_buttonName);
editText_command = view.findViewById(R.id.dialogSingle_editText_command);
editText_name = view.findViewById(R.id.dialogSingle_editText_name);
editText_button_name = view.findViewById(R.id.dialogSingle_editText_buttonName);
builder.setView(view)
@ -47,9 +52,10 @@ public class AddButtonDialogSingle extends DialogFragment {
.setPositiveButton("ADD", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialogInterface, int i) {
String username = editTextUsername.getText().toString();
String password = editTextPassword.getText().toString();
listener.applyTexts(username, password);
String command = editText_command.getText().toString();
String name = editText_name.getText().toString();
String button = editText_button_name.getText().toString();
listener.applyTextsSingle(name,command,button);
}
});
@ -59,33 +65,33 @@ public class AddButtonDialogSingle extends DialogFragment {
return mDialog;
}
public void setFragment(FlurFragment frag)
{
this.frag = frag;
}
public FlurFragment getFragment()
{
return frag;
}
@Override
public void onAttach(Context context) {
super.onAttach(context);
try {
listener = (AddButtonDialogListener) context;
} catch (ClassCastException e) {
throw new ClassCastException(context.toString() +
try {
listener = (AddButtonDialogListenerSingle) frag;
} catch (ClassCastException e) {
throw new ClassCastException(frag.toString() +
"must implement ExampleDialogListener");
}
}
public interface AddButtonDialogListenerSingle {
void applyTextsSingle(String name, String command, String button);
}
public interface AddButtonDialogListener {
void applyTexts(String username, String password);
}
public String getName()
{
return name.getText().toString();
}
public String getButtonName()
{
return button_name.getText().toString();
}
public String getCommand()
{
return command.getText().toString();
}
}

View File

@ -11,11 +11,14 @@ import android.widget.EditText;
import androidx.fragment.app.DialogFragment;
import de.jg_cody.Teraplex.ui.Flur.FlurFragment;
public class AddButtonsDialogDouble extends DialogFragment {
private AddButtonsDialogListener listener;
private AddButtonsDialogListenerDouble listener;
private EditText name, command1, button1, command2, button2;
private FlurFragment frag;
@Override
public Dialog onCreateDialog(Bundle savedInstanceState) {
@ -44,44 +47,33 @@ public class AddButtonsDialogDouble extends DialogFragment {
command2 = getActivity().findViewById(R.id.dialogDouble_editText_command2);
button1 = getActivity().findViewById(R.id.dialogDouble_editText_button1);
button2 = getActivity().findViewById(R.id.dialogDouble_editText_button2);
AlertDialog mDialog = builder.create();
mDialog.getWindow().setBackgroundDrawableResource(R.drawable.button_round);
return mDialog;
}
public void setFragment(FlurFragment frag) {
this.frag = frag;
}
public FlurFragment getFragment() {
return frag;
}
@Override
public void onAttach(Context context) {
super.onAttach(context);
try {
listener = (AddButtonsDialogListener) context;
listener = (AddButtonsDialogListenerDouble) frag;
} catch (ClassCastException e) {
}
}
public interface AddButtonsDialogListener {
void applyTexts(String username, String password);
}
public String getName()
{
return name.getText().toString();
}
public String getCommand1()
{
return command1.getText().toString();
}
public String getButton1()
{
return button1.getText().toString();
}
public String getCommand2()
{
return command2.getText().toString();
}
public String getButton2()
{
return button2.getText().toString();
public interface AddButtonsDialogListenerDouble {
void applyTextsDouble(String name, String command1, String command2, String button1, String button2);
}
}

View File

@ -1,7 +1,9 @@
package de.jg_cody.Teraplex;
import android.app.Activity;
import android.app.AlertDialog;
import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent;
import android.content.SharedPreferences;
import android.content.res.Configuration;
@ -27,6 +29,7 @@ import android.view.MenuItem;
import android.view.View;
import android.view.WindowManager;
import android.widget.ImageView;
import android.widget.ListView;
import androidx.annotation.RequiresApi;
import androidx.appcompat.app.AppCompatActivity;
@ -44,19 +47,30 @@ import com.google.android.material.navigation.NavigationView;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.util.ArrayList;
import java.util.Base64;
import java.util.Locale;
import java.util.Objects;
import de.jg_cody.Teraplex.ui.Credits.CreditsFragment;
import de.jg_cody.Teraplex.ui.Einstellungen.EinstellungenFragment;
import de.jg_cody.Teraplex.ui.Konsole.KonsoleFragment;
import de.jg_cody.Teraplex.ui.home.HomeFragment;
import de.jg_cody.Teraplex.ui.rooms.ListAdapter;
import de.jg_cody.Teraplex.ui.rooms.ListItem;
import de.jg_cody.Teraplex.ui.rooms.ListItemDouble;
import de.jg_cody.Teraplex.ui.rooms.ListItemSingle;
public class MainActivity extends AppCompatActivity implements AddButtonDialogSingle.AddButtonDialogListener {
public class MainActivity extends AppCompatActivity {
public static int RESULT_LOAD_IMAGE = 0;
private AppBarConfiguration mAppBarConfiguration;
ListAdapter listAdapter;
ListView listView;
ArrayList<ListItem> items;
@RequiresApi(api = Build.VERSION_CODES.LOLLIPOP)
@Override
protected void onCreate(Bundle savedInstanceState) {
@ -132,9 +146,19 @@ public class MainActivity extends AppCompatActivity implements AddButtonDialogSi
NavigationUI.setupWithNavController(navigationView, navController);
}
/*static public class DemoPreferenceFragment extends PreferenceFragmentCompat {
@Override
public void onCreatePreferences(Bundle savedInstanceState, String rootKey) {
@ -186,11 +210,6 @@ public class MainActivity extends AppCompatActivity implements AddButtonDialogSi
@Override
public void applyTexts(String username, String password) {
}
public void menurighttopeinstellungen(MenuItem i) {
EinstellungenFragment pef = new EinstellungenFragment();
FragmentTransaction transaction = getSupportFragmentManager().beginTransaction();
@ -313,4 +332,6 @@ public class MainActivity extends AppCompatActivity implements AddButtonDialogSi
canvas.drawRect(0F, 0F, (float) width, (float) height, paint);
return bitmap;
}
}

View File

@ -1,12 +1,17 @@
package de.jg_cody.Teraplex.ui.Flur;
import android.app.Activity;
import android.app.AlertDialog;
import android.content.DialogInterface;
import android.content.SharedPreferences;
import android.graphics.BitmapFactory;
import android.graphics.drawable.BitmapDrawable;
import android.os.Build;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.ListView;
import androidx.annotation.NonNull;
@ -17,16 +22,15 @@ import androidx.lifecycle.ViewModelProvider;
import com.google.android.material.floatingactionbutton.FloatingActionButton;
import java.util.ArrayList;
import java.util.Base64;
import java.util.Objects;
import de.jg_cody.Teraplex.AddButtonDialogSingle;
import de.jg_cody.Teraplex.AddButtonsDialogDouble;
import de.jg_cody.Teraplex.Cricketer;
import de.jg_cody.Teraplex.MainActivity;
import de.jg_cody.Teraplex.R;
import de.jg_cody.Teraplex.ui.rooms.ListAdapter;
import de.jg_cody.Teraplex.ui.rooms.ListItem;
import de.jg_cody.Teraplex.ui.rooms.ListItemDouble;
import de.jg_cody.Teraplex.ui.rooms.ListItemSingle;
import de.jg_cody.Teraplex.ui.rooms.*;
public class FlurFragment extends Fragment{
@ -49,14 +53,14 @@ public class FlurFragment extends Fragment{
flurViewModel =
new ViewModelProvider(this).get(FlurViewModel.class);
View root = inflater.inflate(R.layout.fragment_flur, container, false);
/* SharedPreferences p = requireContext().getSharedPreferences("appsettings", Activity.MODE_PRIVATE);
SharedPreferences p = requireContext().getSharedPreferences("appsettings", Activity.MODE_PRIVATE);
String Background = p.getString("Background", null);
if (Background != null) {
ImageView I = root.findViewById(R.id.Background);
byte[] BA = Base64.getDecoder().decode(Background);
I.setImageDrawable(new BitmapDrawable(getResources(), MainActivity.scaleCenterCrop(BitmapFactory.decodeByteArray(BA, 0, BA.length), MainActivity.getScreenHeight(), MainActivity.getScreenWidth())));
I.setScaleType(ImageView.ScaleType.CENTER_CROP);
} */
}
@ -108,7 +112,7 @@ public class FlurFragment extends Fragment{
}
public void openDialog1() {
AddButtonDialogSingle addButtonDialogSingle = new AddButtonDialogSingle();
addButtonDialogSingle.show(requireActivity().getSupportFragmentManager(), "example dialog");
addButtonDialogSingle.show(getActivity().getSupportFragmentManager(), "example dialog");
items.add(new ListItemSingle(addButtonDialogSingle.getCommand(),1, addButtonDialogSingle.getName(), addButtonDialogSingle.getButtonName()));
listAdapter.notifyDataSetChanged();
@ -117,7 +121,7 @@ public class FlurFragment extends Fragment{
public void openDialog2() {
AddButtonsDialogDouble addButtonsDialogDouble = new AddButtonsDialogDouble();
addButtonsDialogDouble.show(requireActivity().getSupportFragmentManager(), "example dialog");
addButtonsDialogDouble.show(getActivity().getSupportFragmentManager(), "example dialog");
items.add(new ListItemDouble(2,addButtonsDialogDouble.getName(), addButtonsDialogDouble.getCommand1(), addButtonsDialogDouble.getCommand2(), addButtonsDialogDouble.getButton1(), addButtonsDialogDouble.getButton2()));
listAdapter.notifyDataSetChanged();
}

View File

@ -48,29 +48,38 @@ public class ListAdapter extends ArrayAdapter {
ListItem listViewItem = objects.get(position);
int listViewItemType = getItemViewType(position);
String[] s = listViewItem.getStrings();
if (convertView == null) {
if (listViewItemType == SINGLEBUTTON) {
convertView = LayoutInflater.from(getContext()).inflate(R.layout.singlebutton, null);
Button bRun = convertView.findViewById(R.id.bRun);
Button text = convertView.findViewById(R.id.TEXT);
bRun.setText(listViewItem.getText());
Button bRun = convertView.findViewById(R.id.singleButton_button);
Button text = convertView.findViewById(R.id.singleButton_text);
bRun.setText(s[2]);
text.setText(s[0]);
//text.setText(listViewItemType.get)
viewHolder = new ViewHolderSingleButton(bRun , listViewItem.getText());
convertView.setTag(viewHolder);
//viewHolder = new ViewHolderSingleButton(bRun , listViewItem.getText());
//convertView.setTag(viewHolder);
}
else if (listViewItemType == DOUBLEBUTTON) {
convertView = LayoutInflater.from(getContext()).inflate(R.layout.doublebutton, null);
Button bLeft = (Button) convertView.findViewById(R.id.bLeft);
Button bRight = (Button) convertView.findViewById(R.id.bRight);
Button bLeft = (Button) convertView.findViewById(R.id.doubleButton_bLeft);
Button bRight = (Button) convertView.findViewById(R.id.doubleButton_bRight);
Button text = (Button) convertView.findViewById(R.id.doubleButton_text);
viewHolder = new ViewHolderDoubleButton(bLeft,bRight,listViewItem.getText());
bLeft.setText(s[3]);
bRight.setText(s[4]);
text.setText(s[0]);
convertView.setTag(viewHolder);
//viewHolder = new ViewHolderDoubleButton(bLeft,bRight,listViewItem.getText());
//convertView.setTag(viewHolder);
}
}

View File

@ -1,6 +1,6 @@
package de.jg_cody.Teraplex.ui.rooms;
public class ListItem {
public abstract class ListItem {
private String text;
private int type;
@ -10,13 +10,7 @@ public class ListItem {
public String getText() {
return text;
}
public void setText(String text) {
this.text = text;
}
abstract public String[] getStrings();
public int getType() {
return type;

View File

@ -52,4 +52,9 @@ public class ListItemDouble extends ListItem{
return button2;
}
@Override
public String[] getStrings() {
String[] s = {name, command1, command2, button1,button2};
return s;
}
}

View File

@ -2,12 +2,14 @@ package de.jg_cody.Teraplex.ui.rooms;
public class ListItemSingle extends ListItem{
String buttonName;
String command;
String name;
public ListItemSingle(String command, int type, String buttonName, String name) {
public ListItemSingle(int type, String name,String command,String buttonName ) {
super(type);
this.name = name;
this.buttonName = buttonName;
this.command = command;
}
public void setButtonName(String buttonName)
@ -26,4 +28,18 @@ public class ListItemSingle extends ListItem{
{
return name;
}
public void setCommand(String command)
{
this.command = command;
}
public String getCommand()
{
return command;
}
@Override
public String[] getStrings() {
String[] s = {name, command, buttonName};
return s;
}
}

View File

@ -9,7 +9,7 @@
<Button
android:id="@+id/bLeft"
android:id="@+id/doubleButton_bLeft"
android:layout_width="100dp"
android:layout_height="40dp"
android:layout_margin="5dp"
@ -21,20 +21,19 @@
app:backgroundTint="@null" />
<Button
android:id="@+id/TEXT"
android:id="@+id/doubleButton_text"
android:layout_width="100dp"
android:layout_height="40dp"
android:layout_margin="5dp"
android:layout_marginTop="5dp"
android:layout_weight="1"
android:background="@drawable/button_middle"
android:insetLeft="25dp"
android:insetRight="25dp"
android:text="Button2"
android:text="Button1"
app:backgroundTint="@null" />
<Button
android:id="@+id/bRight"
android:id="@+id/doubleButton_bRight"
android:layout_width="100dp"
android:layout_height="40dp"
android:layout_margin="5dp"

View File

@ -1,6 +1,7 @@
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/fragment_flur"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity">
@ -19,8 +20,8 @@
<ListView
android:id="@+id/listView"
android:layout_width="wrap_content"
android:layout_height="742dp"
android:visibility="visible"/>
android:layout_height="match_parent"
android:visibility="visible" />
</FrameLayout>

View File

@ -8,8 +8,8 @@
<Button
android:id="@+id/TEXT"
android:layout_width="220dp"
android:id="@+id/singleButton_text"
android:layout_width="200dp"
android:layout_height="40dp"
android:layout_margin="5dp"
android:layout_marginTop="5dp"
@ -17,11 +17,11 @@
android:background="@drawable/button_left"
android:insetLeft="25dp"
android:insetRight="25dp"
android:text="Beschriftung"
android:text="TEXT"
app:backgroundTint="@null" />
<Button
android:id="@+id/bRun"
android:id="@+id/singleButton_button"
android:layout_width="100dp"
android:layout_height="40dp"
android:layout_margin="5dp"
@ -29,7 +29,7 @@
android:background="@drawable/button_right"
android:insetLeft="25dp"
android:insetRight="25dp"
android:text="1234"
android:text="Button2"
app:backgroundTint="@null" />
<ImageView