prepared for editing existing buttons

added dialogs + loading information into edittexts
prepared for data export and import
added dialogs for exportsettings
This commit is contained in:
JG-Cody 2021-08-13 20:07:25 +02:00
parent 975243e1e2
commit 71bb4d576c
12 changed files with 276 additions and 34 deletions

View File

@ -49,7 +49,7 @@ public class AddButtonDialogSingle extends DialogFragment {
} }
}) })
.setPositiveButton("ADD", new DialogInterface.OnClickListener() { .setPositiveButton(R.string.add, new DialogInterface.OnClickListener() {
@Override @Override
public void onClick(DialogInterface dialogInterface, int i) { public void onClick(DialogInterface dialogInterface, int i) {
String command = editText_command.getText().toString(); String command = editText_command.getText().toString();

View File

@ -36,7 +36,7 @@ public class AddButtonsDialogDouble extends DialogFragment {
builder.setView(view) builder.setView(view)
.setTitle("ON/OFF BUTTON") .setTitle("ON/OFF BUTTON")
.setNegativeButton(getString(R.string.cancel), null) .setNegativeButton(getString(R.string.cancel), null)
.setPositiveButton("ADD", new DialogInterface.OnClickListener() { .setPositiveButton(R.string.add, new DialogInterface.OnClickListener() {
@Override @Override
public void onClick(DialogInterface dialogInterface, int i) { public void onClick(DialogInterface dialogInterface, int i) {
String command1 = editText_command1.getText().toString(); String command1 = editText_command1.getText().toString();

View File

@ -39,12 +39,13 @@ public class AddHeadlineDialog extends DialogFragment {
editText_name = view.findViewById(R.id.dialogheadline_editText_name); editText_name = view.findViewById(R.id.dialogheadline_editText_name);
builder.setView(view) builder.setView(view)
.setTitle("SINGLE BUTTON") .setTitle(R.string.heading)
.setNegativeButton(getString(R.string.cancel), (dialogInterface, i) -> { .setNegativeButton(R.string.cancel, (dialogInterface, i) -> {
}) })
.setPositiveButton("ADD", (dialogInterface, i) -> { .setPositiveButton(R.string.add, (dialogInterface, i) -> {
String headline = editText_name.getText().toString(); String headline = editText_name.getText().toString();
if(headline.isEmpty()){ if(headline.isEmpty()){
MediaPlayer mp = MediaPlayer.create(getContext(), R.raw.state_change_confirm_up); MediaPlayer mp = MediaPlayer.create(getContext(), R.raw.state_change_confirm_up);

View File

@ -186,7 +186,7 @@ public class MainActivity extends AppCompatActivity {
mBuilder.setView(view) mBuilder.setView(view)
.setTitle(R.string.menu_add); .setTitle(R.string.menu_add);
mBuilder.setPositiveButton(R.string.ok, new DialogInterface.OnClickListener() { mBuilder.setPositiveButton(R.string.add, new DialogInterface.OnClickListener() {
@Override @Override
public void onClick(DialogInterface dialog, int which) { public void onClick(DialogInterface dialog, int which) {
Vibrator vr = (Vibrator) getSystemService(Context.VIBRATOR_SERVICE); Vibrator vr = (Vibrator) getSystemService(Context.VIBRATOR_SERVICE);

View File

@ -17,6 +17,7 @@ import android.view.LayoutInflater;
import android.view.View; import android.view.View;
import android.view.ViewGroup; import android.view.ViewGroup;
import android.widget.Button; import android.widget.Button;
import android.widget.EditText;
import android.widget.ImageView; import android.widget.ImageView;
import androidx.annotation.NonNull; import androidx.annotation.NonNull;
@ -33,6 +34,7 @@ import static android.content.Context.MODE_PRIVATE;
public class SettingsFragment extends Fragment { public class SettingsFragment extends Fragment {
private EditText editExportFile_name;
private SettingsViewModel settingsViewModel; private SettingsViewModel settingsViewModel;
public View onCreateView(@NonNull LayoutInflater inflater, public View onCreateView(@NonNull LayoutInflater inflater,
@ -67,7 +69,16 @@ public class SettingsFragment extends Fragment {
assert vr != null; assert vr != null;
vr.vibrate(100); vr.vibrate(100);
showExportDialog(); showExportDialog();
}
});
Button Import = root.findViewById(R.id.button_import);
Import.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
Vibrator vr = (Vibrator) requireContext().getSystemService(Context.VIBRATOR_SERVICE);
assert vr != null;
vr.vibrate(100);
showImportDialog();
} }
}); });
Button Reset = root.findViewById(R.id.button_reset); Button Reset = root.findViewById(R.id.button_reset);
@ -283,9 +294,9 @@ public class SettingsFragment extends Fragment {
final String[] listItems = {"EXPORT BACKGROUND", "EXPORT LANGUAGESETTINGS", "EXPORT THEMESETTINGS", "EXPORT TABS"}; final String[] listItems = {"EXPORT BACKGROUND", "EXPORT LANGUAGESETTINGS", "EXPORT THEMESETTINGS", "EXPORT TABS"};
AlertDialog.Builder mBuilder = new AlertDialog.Builder(getContext()); AlertDialog.Builder mBuilder = new AlertDialog.Builder(getContext());
mBuilder.setTitle(getString(R.string.export_settings)); mBuilder.setTitle(getString(R.string.export_settings));
mBuilder.setMultiChoiceItems(listItems, selection, new DialogInterface.OnClickListener() { mBuilder.setMultiChoiceItems(listItems, null, new DialogInterface.OnMultiChoiceClickListener() {
@Override @Override
public void onClick(DialogInterface dialogInterface, int i) { public void onClick(DialogInterface dialogInterface, int i, boolean b) {
Vibrator vr = (Vibrator) requireContext().getSystemService(Context.VIBRATOR_SERVICE); Vibrator vr = (Vibrator) requireContext().getSystemService(Context.VIBRATOR_SERVICE);
assert vr != null; assert vr != null;
vr.vibrate(100); vr.vibrate(100);
@ -298,7 +309,57 @@ public class SettingsFragment extends Fragment {
} else if (i == 3) { } else if (i == 3) {
} }
dialogInterface.dismiss(); }
});
mBuilder.setPositiveButton(getString(R.string.button_export), new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialogInterface, int i) {
AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
LayoutInflater inflater = requireActivity().getLayoutInflater();
View view = inflater.inflate(R.layout.exportdialog, null);
editExportFile_name = view.findViewById(R.id.dialogexport_editText_name);
builder.setView(view)
.setTitle("SINGLE BUTTON")
.setNegativeButton(getString(R.string.cancel), (dialogExport, r) -> {
})
.setPositiveButton(R.string.button_export, (dialogExport, r) -> {
String headline = editExportFile_name.getText().toString();
if(headline.isEmpty()){
MediaPlayer mp = MediaPlayer.create(getContext(), R.raw.state_change_confirm_up);
mp.start();
AlertDialog mDialog = new AlertDialog.Builder(getContext())
.setTitle(getString(R.string.invalid))
.setMessage(getString(R.string.inputfields_cant_be_empty))
// Specifying a listener allows you to take an action before dismissing the dialog.
// The dialog is automatically dismissed when a dialog button is clicked.
.setPositiveButton(android.R.string.yes, null )
.create();
Objects.requireNonNull(mDialog.getWindow()).setBackgroundDrawableResource(R.drawable.button_round);
mDialog.getWindow().getAttributes().windowAnimations = R.style.DialogAnimation; //style id
mDialog.show();
return;
}
});
AlertDialog mDialog = builder.create();
Objects.requireNonNull(mDialog.getWindow()).setBackgroundDrawableResource(R.drawable.button_round);
mDialog.getWindow().getAttributes().windowAnimations = R.style.DialogAnimation; //style id
mDialog.show();
}
}
);
mBuilder.setNegativeButton(getString(R.string.cancel), new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialogInterface, int i) {
} }
}); });
AlertDialog mDialog = mBuilder.create(); AlertDialog mDialog = mBuilder.create();
@ -306,6 +367,10 @@ public class SettingsFragment extends Fragment {
mDialog.getWindow().getAttributes().windowAnimations = R.style.DialogAnimation; //style id mDialog.getWindow().getAttributes().windowAnimations = R.style.DialogAnimation; //style id
mDialog.show(); mDialog.show();
} }
private void showImportDialog() {
Intent a = new Intent(
Intent.ACTION_PICK, android.provider.MediaStore.Images.Media.EXTERNAL_CONTENT_URI);
requireActivity().startActivityForResult(a, MainActivity.RESULT_LOAD_IMAGE);
}
} }

View File

@ -1,12 +1,15 @@
package de.jg_cody.Teraplex.ui.tabs; package de.jg_cody.Teraplex.ui.tabs;
import android.app.AlertDialog;
import android.content.Context; import android.content.Context;
import android.content.DialogInterface;
import android.media.MediaPlayer;
import android.view.LayoutInflater; import android.view.LayoutInflater;
import android.view.View; import android.view.View;
import android.view.ViewGroup; import android.view.ViewGroup;
import android.widget.Button; import android.widget.Button;
import android.widget.EditText;
import android.widget.ImageView; import android.widget.ImageView;
import android.widget.Toast;
import androidx.annotation.NonNull; import androidx.annotation.NonNull;
import androidx.recyclerview.widget.RecyclerView; import androidx.recyclerview.widget.RecyclerView;
@ -16,12 +19,20 @@ import org.json.JSONException;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Collections; import java.util.Collections;
import java.util.Objects;
import de.jg_cody.Teraplex.AddButtonsDialogDouble;
import de.jg_cody.Teraplex.MainActivity; import de.jg_cody.Teraplex.MainActivity;
import de.jg_cody.Teraplex.R; import de.jg_cody.Teraplex.R;
public class ListAdapter extends RecyclerView.Adapter<ListAdapter.ListItemViewHolder> { public class ListAdapter extends RecyclerView.Adapter<ListAdapter.ListItemViewHolder> {
private AddButtonsDialogDouble.AddButtonsDialogListenerDouble listener;
private EditText editText_name, editText_command, editText_command1, editText_button1, editText_command2, editText_button2, editText_button_name;
private TabsFragment frag;
ListAdapter listAdapter;
public static final int public static final int
SINGLEBUTTON = 0, SINGLEBUTTON = 0,
DOUBLEBUTTON = 1, DOUBLEBUTTON = 1,
@ -143,30 +154,162 @@ public class ListAdapter extends RecyclerView.Adapter<ListAdapter.ListItemViewHo
Edit.setOnClickListener(new View.OnClickListener() { Edit.setOnClickListener(new View.OnClickListener() {
@Override @Override
public void onClick(View v) { public void onClick(View v) {
switch(item.getType()) { switch (item.getType()) {
case SINGLEBUTTON: case SINGLEBUTTON: {
{ AlertDialog.Builder mBuilder = new AlertDialog.Builder(v.getContext());
Toast.makeText(v.getContext(), "SINGLEBUTTON",Toast.LENGTH_LONG).show();
View view = inflater.inflate(R.layout.addbuttondialog_single, null);
editText_command = view.findViewById(R.id.dialogSingle_editText_command);
editText_command.setText(strings[1]);
editText_name = view.findViewById(R.id.dialogheadline_editText_name);
editText_name.setText(strings[0]);
editText_button_name = view.findViewById(R.id.dialogSingle_editText_buttonName);
editText_button_name.setText(strings[2]);
mBuilder.setView(view)
.setTitle("SINGLE BUTTON")
.setNegativeButton(R.string.cancel, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialogInterface, int i) {
}
})
.setPositiveButton(R.string.add, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialogInterface, int i) {
String command = editText_command.getText().toString();
String name = editText_name.getText().toString();
String button = editText_button_name.getText().toString();
if(command.isEmpty()||button.isEmpty()||name.isEmpty()){
MediaPlayer mp = MediaPlayer.create(v.getContext(), R.raw.state_change_confirm_up);
mp.start();
AlertDialog mDialog = new AlertDialog.Builder(v.getContext())
.setTitle(R.string.invalid)
.setMessage(R.string.inputfields_cant_be_empty)
// Specifying a listener allows you to take an action before dismissing the dialog.
// The dialog is automatically dismissed when a dialog button is clicked.
.setPositiveButton(android.R.string.yes, null )
.create();
Objects.requireNonNull(mDialog.getWindow()).setBackgroundDrawableResource(R.drawable.button_round);
mDialog.getWindow().getAttributes().windowAnimations = R.style.DialogAnimation; //style id
mDialog.show();
return;
}
}
});
AlertDialog mDialog = mBuilder.create();
Objects.requireNonNull(mDialog.getWindow()).setBackgroundDrawableResource(R.drawable.button_round);
mDialog.getWindow().getAttributes().windowAnimations = R.style.DialogAnimation; //style id
mDialog.show();
break; break;
} }
case DOUBLEBUTTON: case DOUBLEBUTTON: {
{
Toast.makeText(v.getContext(), "DOUBLEBUTTON",Toast.LENGTH_LONG).show(); AlertDialog.Builder mBuilder = new AlertDialog.Builder(v.getContext());
View view = inflater.inflate(R.layout.addbuttonsdialog_double, null);
mBuilder.setView(view)
.setTitle("ON/OFF BUTTON")
.setNegativeButton(R.string.cancel, null)
.setPositiveButton(R.string.add, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialogInterface, int i) {
String command1 = editText_command1.getText().toString();
String command2 = editText_command2.getText().toString();
String name = editText_name.getText().toString();
String button1 = editText_button1.getText().toString();
String button2 = editText_button2.getText().toString();
if (command1.isEmpty() || command2.isEmpty() || name.isEmpty() || button1.isEmpty() || button2.isEmpty()) {
MediaPlayer mp = MediaPlayer.create(v.getContext(), R.raw.state_change_confirm_up);
mp.start();
AlertDialog mDialog = new AlertDialog.Builder(v.getContext())
.setTitle(R.string.invalid)
.setMessage(R.string.inputfields_cant_be_empty)
// Specifying a listener allows you to take an action before dismissing the dialog.
// The dialog is automatically dismissed when a dialog button is clicked.
.setPositiveButton(android.R.string.yes, null)
.create();
Objects.requireNonNull(mDialog.getWindow()).setBackgroundDrawableResource(R.drawable.button_round);
mDialog.getWindow().getAttributes().windowAnimations = R.style.DialogAnimation; //style id
mDialog.show();
return;
}
listener.applyTextsDouble(name, command1, command2, button1, button2);
}
});
editText_name = view.findViewById(R.id.dialogDouble_editText_name);
editText_name.setText(strings[0]);
editText_command1 = view.findViewById(R.id.dialogDouble_editText_command1);
editText_command1.setText(strings[1]);
editText_command2 = view.findViewById(R.id.dialogDouble_editText_command2);
editText_command2.setText(strings[2]);
editText_button1 = view.findViewById(R.id.dialogDouble_editText_button1);
editText_button1.setText(strings[3]);
editText_button2 = view.findViewById(R.id.dialogDouble_editText_button2);
editText_button2.setText(strings[4]);
AlertDialog mDialog = mBuilder.create();
Objects.requireNonNull(mDialog.getWindow()).setBackgroundDrawableResource(R.drawable.button_round);
mDialog.getWindow().getAttributes().windowAnimations = R.style.DialogAnimation; //style id
mDialog.show();
break; break;
} }
case SPACE: case HEADLINE: {
{ AlertDialog.Builder builder = new AlertDialog.Builder(v.getContext());
Toast.makeText(v.getContext(), "SPACE",Toast.LENGTH_LONG).show();
break; View view = inflater.inflate(R.layout.addheadlinedialog, null);
}
case HEADLINE: editText_name = view.findViewById(R.id.dialogheadline_editText_name);
{ editText_name.setText(strings[0]);
Toast.makeText(v.getContext(), "HEADLINE",Toast.LENGTH_LONG).show();
builder.setView(view)
.setTitle(R.string.heading)
.setNegativeButton(R.string.cancel, (dialogInterface, i) -> {
})
.setPositiveButton(R.string.add, (dialogInterface, i) -> {
String headline = editText_name.getText().toString();
if(headline.isEmpty()){
MediaPlayer mp = MediaPlayer.create(v.getContext(), R.raw.state_change_confirm_up);
mp.start();
AlertDialog mDialog = new AlertDialog.Builder(v.getContext())
.setTitle(R.string.invalid)
.setMessage(R.string.inputfields_cant_be_empty)
// Specifying a listener allows you to take an action before dismissing the dialog.
// The dialog is automatically dismissed when a dialog button is clicked.
.setPositiveButton(android.R.string.yes, null )
.create();
Objects.requireNonNull(mDialog.getWindow()).setBackgroundDrawableResource(R.drawable.button_round);
mDialog.getWindow().getAttributes().windowAnimations = R.style.DialogAnimation; //style id
mDialog.show();
return;
}
});
AlertDialog mDialog = builder.create();
Objects.requireNonNull(mDialog.getWindow()).setBackgroundDrawableResource(R.drawable.button_round);
mDialog.getWindow().getAttributes().windowAnimations = R.style.DialogAnimation; //style id
mDialog.show();
break; break;
} }
} }
}
}); }});
switch(item.getType()) { switch(item.getType()) {
case SINGLEBUTTON: case SINGLEBUTTON:
{ {
@ -223,4 +366,6 @@ public class ListAdapter extends RecyclerView.Adapter<ListAdapter.ListItemViewHo
} }
} }
} }

View File

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

View File

@ -0,0 +1,16 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:padding="16dp"
android:orientation="vertical" >
<EditText
android:id="@+id/dialogexport_editText_name"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:ems="10"
android:hint="FILENAME"
android:inputType="textPersonName" />
</LinearLayout>

View File

@ -21,8 +21,8 @@
<ImageView <ImageView
android:id="@+id/image_edit" android:id="@+id/image_edit"
android:layout_width="40dp" android:layout_width="30dp"
android:layout_height="40dp" android:layout_height="30dp"
android:layout_gravity="center" android:layout_gravity="center"
android:layout_margin="5dp" android:layout_margin="5dp"
android:layout_weight="0" android:layout_weight="0"

View File

@ -30,8 +30,8 @@
<ImageView <ImageView
android:id="@+id/image_edit" android:id="@+id/image_edit"
android:layout_width="40dp" android:layout_width="30dp"
android:layout_height="40dp" android:layout_height="30dp"
android:layout_gravity="center" android:layout_gravity="center"
android:layout_margin="5dp" android:layout_margin="5dp"
android:layout_weight="0" android:layout_weight="0"

View File

@ -11,6 +11,20 @@
android:layout_height="40dp" android:layout_height="40dp"
android:layout_weight="1" /> android:layout_weight="1" />
<ImageView
android:id="@+id/image_edit"
android:layout_width="00dp"
android:layout_height="00dp"
android:layout_gravity="center"
android:layout_margin="5dp"
android:layout_weight="0"
android:visibility="gone"
app:srcCompat="@drawable/mode_edit_black_24dp"
app:tint="?attr/colorOnPrimary"
tools:ignore="VectorDrawableCompat">
</ImageView>
<ImageView <ImageView
android:id="@+id/image_remove" android:id="@+id/image_remove"
android:layout_width="40dp" android:layout_width="40dp"

View File

@ -85,6 +85,7 @@
<string name="yes">YES</string> <string name="yes">YES</string>
<string name="no">NO</string> <string name="no">NO</string>
<string name="ok">OK</string> <string name="ok">OK</string>
<string name="add">ADD</string>
<string name="cancel">CANCEL</string> <string name="cancel">CANCEL</string>
<string name="invalid">INVALID INPUT</string> <string name="invalid">INVALID INPUT</string>
<string name="tabname">TABNAME</string> <string name="tabname">TABNAME</string>