code bereinigt und nach vorschlag von android studio angepasst

This commit is contained in:
JG-Cody 2021-06-11 21:18:28 +02:00
parent fa70aad80e
commit b33ad3df96
13 changed files with 92 additions and 76 deletions

View File

@ -48,6 +48,7 @@ import java.io.IOException;
import java.io.InputStream; import java.io.InputStream;
import java.util.Base64; import java.util.Base64;
import java.util.Locale; import java.util.Locale;
import java.util.Objects;
import de.jg_cody.Teraplex.ui.Credits.CreditsFragment; import de.jg_cody.Teraplex.ui.Credits.CreditsFragment;
import de.jg_cody.Teraplex.ui.Einstellungen.EinstellungenFragment; import de.jg_cody.Teraplex.ui.Einstellungen.EinstellungenFragment;
@ -238,7 +239,7 @@ public class MainActivity extends AppCompatActivity implements AddButtonDialog.A
} }
private void showChooseElement() { private void showChooseElement() {
final String[] listItems = {"SINGLE BUTTON", "DOUBLE BUTTON", "OPTION3"}; final String[] listItems = {"SINGLE BUTTON", "DOUBLE BUTTON", "ÜBERSCHRIFT", "PLATZHALTER"};
AlertDialog.Builder mBuilder = new AlertDialog.Builder(MainActivity.this); AlertDialog.Builder mBuilder = new AlertDialog.Builder(MainActivity.this);
mBuilder.setTitle("CHOOSE ELEMENT"); mBuilder.setTitle("CHOOSE ELEMENT");
mBuilder.setSingleChoiceItems(listItems, -5, new DialogInterface.OnClickListener() { mBuilder.setSingleChoiceItems(listItems, -5, new DialogInterface.OnClickListener() {
@ -250,12 +251,15 @@ public class MainActivity extends AppCompatActivity implements AddButtonDialog.A
openDialog2(); openDialog2();
} else if (i == 2) { } else if (i == 2) {
} else if (i == 3) {
} }
dialogInterface.dismiss(); dialogInterface.dismiss();
} }
}); });
AlertDialog mDialog = mBuilder.create(); AlertDialog mDialog = mBuilder.create();
mDialog.getWindow().setBackgroundDrawableResource(R.drawable.button_round); Objects.requireNonNull(mDialog.getWindow()).setBackgroundDrawableResource(R.drawable.button_round);
mDialog.show(); mDialog.show();
} }

View File

@ -31,7 +31,7 @@ public class CreditsFragment extends Fragment {
creditsViewModel = creditsViewModel =
new ViewModelProvider(this).get(CreditsViewModel.class); new ViewModelProvider(this).get(CreditsViewModel.class);
View root = inflater.inflate(R.layout.fragment_credits, container, false); View root = inflater.inflate(R.layout.fragment_credits, container, false);
SharedPreferences p = getContext().getSharedPreferences("appsettings", Activity.MODE_PRIVATE); SharedPreferences p = requireContext().getSharedPreferences("appsettings", Activity.MODE_PRIVATE);
String Background = p.getString("Background", null); String Background = p.getString("Background", null);
if (Background != null) { if (Background != null) {
ImageView I = root.findViewById(R.id.Background); ImageView I = root.findViewById(R.id.Background);

View File

@ -28,6 +28,7 @@ import com.rarepebble.colorpicker.ColorPickerView;
import java.util.Base64; import java.util.Base64;
import java.util.Locale; import java.util.Locale;
import java.util.Objects;
import de.jg_cody.Teraplex.MainActivity; import de.jg_cody.Teraplex.MainActivity;
import de.jg_cody.Teraplex.R; import de.jg_cody.Teraplex.R;
@ -44,7 +45,7 @@ public class EinstellungenFragment extends Fragment {
einstellungenViewModel = einstellungenViewModel =
new ViewModelProvider(this).get(EinstellungenViewModel.class); new ViewModelProvider(this).get(EinstellungenViewModel.class);
View root = inflater.inflate(R.layout.fragment_einstellungen, container, false); View root = inflater.inflate(R.layout.fragment_einstellungen, container, false);
SharedPreferences p = getContext().getSharedPreferences("appsettings", Activity.MODE_PRIVATE); SharedPreferences p = requireContext().getSharedPreferences("appsettings", Activity.MODE_PRIVATE);
String Background = p.getString("Background", null); String Background = p.getString("Background", null);
if (Background != null) { if (Background != null) {
ImageView I = root.findViewById(R.id.Background); ImageView I = root.findViewById(R.id.Background);
@ -75,10 +76,10 @@ public class EinstellungenFragment extends Fragment {
.setPositiveButton(android.R.string.yes, new DialogInterface.OnClickListener() { .setPositiveButton(android.R.string.yes, new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int which) { public void onClick(DialogInterface dialog, int which) {
try { try {
getContext().getSharedPreferences("appsettings", Context.MODE_PRIVATE).edit().clear().commit(); requireContext().getSharedPreferences("appsettings", Context.MODE_PRIVATE).edit().clear().apply();
startActivity(getActivity().getIntent()); startActivity(requireActivity().getIntent());
getActivity().finish(); requireActivity().finish();
} catch (Exception e) { } catch (Exception ignored) {
} }
// Continue with delete operation // Continue with delete operation
@ -88,7 +89,7 @@ public class EinstellungenFragment extends Fragment {
// A null listener allows the button to dismiss the dialog and take no further action. // A null listener allows the button to dismiss the dialog and take no further action.
.setNegativeButton(android.R.string.no, null) .setNegativeButton(android.R.string.no, null)
.create(); .create();
mDialog.getWindow().setBackgroundDrawableResource(R.drawable.button_round); Objects.requireNonNull(mDialog.getWindow()).setBackgroundDrawableResource(R.drawable.button_round);
mDialog.show(); mDialog.show();
} }
@ -107,11 +108,11 @@ public class EinstellungenFragment extends Fragment {
@Override @Override
public void onClick(View view) { public void onClick(View view) {
Toast.makeText(getContext(), "Theme1", Toast.LENGTH_SHORT).show(); Toast.makeText(getContext(), "Theme1", Toast.LENGTH_SHORT).show();
SharedPreferences.Editor editor = getContext().getSharedPreferences("appsettings", MODE_PRIVATE).edit(); SharedPreferences.Editor editor = requireContext().getSharedPreferences("appsettings", MODE_PRIVATE).edit();
editor.putString("Theme", "RED_BLUE"); editor.putString("Theme", "RED_BLUE");
editor.apply(); editor.apply();
startActivity(getActivity().getIntent()); startActivity(requireActivity().getIntent());
getActivity().finish(); requireActivity().finish();
} }
@ -121,11 +122,11 @@ public class EinstellungenFragment extends Fragment {
@Override @Override
public void onClick(View view) { public void onClick(View view) {
Toast.makeText(getContext(), "Theme2", Toast.LENGTH_SHORT).show(); Toast.makeText(getContext(), "Theme2", Toast.LENGTH_SHORT).show();
SharedPreferences.Editor editor = getContext().getSharedPreferences("appsettings", MODE_PRIVATE).edit(); SharedPreferences.Editor editor = requireContext().getSharedPreferences("appsettings", MODE_PRIVATE).edit();
editor.putString("Theme", "GREEN_YELLOW"); editor.putString("Theme", "GREEN_YELLOW");
editor.apply(); editor.apply();
startActivity(getActivity().getIntent()); startActivity(requireActivity().getIntent());
getActivity().finish(); requireActivity().finish();
} }
@ -135,11 +136,11 @@ public class EinstellungenFragment extends Fragment {
@Override @Override
public void onClick(View view) { public void onClick(View view) {
Toast.makeText(getContext(), "Theme3", Toast.LENGTH_SHORT).show(); Toast.makeText(getContext(), "Theme3", Toast.LENGTH_SHORT).show();
SharedPreferences.Editor editor = getContext().getSharedPreferences("appsettings", MODE_PRIVATE).edit(); SharedPreferences.Editor editor = requireContext().getSharedPreferences("appsettings", MODE_PRIVATE).edit();
editor.putString("Theme", "ORANGE_TURQUOISE"); editor.putString("Theme", "ORANGE_TURQUOISE");
editor.apply(); editor.apply();
startActivity(getActivity().getIntent()); startActivity(requireActivity().getIntent());
getActivity().finish(); requireActivity().finish();
} }
@ -149,11 +150,11 @@ public class EinstellungenFragment extends Fragment {
@Override @Override
public void onClick(View view) { public void onClick(View view) {
Toast.makeText(getContext(), "Theme4", Toast.LENGTH_SHORT).show(); Toast.makeText(getContext(), "Theme4", Toast.LENGTH_SHORT).show();
SharedPreferences.Editor editor = getContext().getSharedPreferences("appsettings", MODE_PRIVATE).edit(); SharedPreferences.Editor editor = requireContext().getSharedPreferences("appsettings", MODE_PRIVATE).edit();
editor.putString("Theme", "YELLOW_BLUE"); editor.putString("Theme", "YELLOW_BLUE");
editor.apply(); editor.apply();
startActivity(getActivity().getIntent()); startActivity(requireActivity().getIntent());
getActivity().finish(); requireActivity().finish();
} }
@ -163,11 +164,11 @@ public class EinstellungenFragment extends Fragment {
@Override @Override
public void onClick(View view) { public void onClick(View view) {
Toast.makeText(getContext(), "Theme5", Toast.LENGTH_SHORT).show(); Toast.makeText(getContext(), "Theme5", Toast.LENGTH_SHORT).show();
SharedPreferences.Editor editor = getContext().getSharedPreferences("appsettings", MODE_PRIVATE).edit(); SharedPreferences.Editor editor = requireContext().getSharedPreferences("appsettings", MODE_PRIVATE).edit();
editor.putString("Theme", "PINK_GREEN"); editor.putString("Theme", "PINK_GREEN");
editor.apply(); editor.apply();
startActivity(getActivity().getIntent()); startActivity(requireActivity().getIntent());
getActivity().finish(); requireActivity().finish();
} }
@ -185,22 +186,22 @@ public class EinstellungenFragment extends Fragment {
public void onClick(DialogInterface dialogInterface, int i) { public void onClick(DialogInterface dialogInterface, int i) {
if (i == 0) { if (i == 0) {
setLocale("de"); setLocale("de");
startActivity(getActivity().getIntent()); startActivity(requireActivity().getIntent());
getActivity().finish(); requireActivity().finish();
} else if (i == 1) { } else if (i == 1) {
setLocale("en"); setLocale("en");
startActivity(getActivity().getIntent()); startActivity(requireActivity().getIntent());
getActivity().finish(); requireActivity().finish();
} else if (i == 2) { } else if (i == 2) {
setLocale("tlh"); setLocale("tlh");
startActivity(getActivity().getIntent()); startActivity(requireActivity().getIntent());
getActivity().finish(); requireActivity().finish();
} }
dialogInterface.dismiss(); dialogInterface.dismiss();
} }
}); });
AlertDialog mDialog = mBuilder.create(); AlertDialog mDialog = mBuilder.create();
mDialog.getWindow().setBackgroundDrawableResource(R.drawable.button_round); Objects.requireNonNull(mDialog.getWindow()).setBackgroundDrawableResource(R.drawable.button_round);
mDialog.show(); mDialog.show();
} }
@ -222,7 +223,7 @@ public class EinstellungenFragment extends Fragment {
} }
}).create(); }).create();
mDialog.getWindow().setBackgroundDrawableResource(R.drawable.button_round); Objects.requireNonNull(mDialog.getWindow()).setBackgroundDrawableResource(R.drawable.button_round);
mDialog.show(); mDialog.show();
} catch (Exception e) { } catch (Exception e) {
} }
@ -238,25 +239,25 @@ public class EinstellungenFragment extends Fragment {
} }
}).create(); }).create();
mDialog.getWindow().setBackgroundDrawableResource(R.drawable.button_round); Objects.requireNonNull(mDialog.getWindow()).setBackgroundDrawableResource(R.drawable.button_round);
mDialog.show(); mDialog.show();
} catch (Exception e) { } catch (Exception ignored) {
} }
} else if (i == 2) { } else if (i == 2) {
Intent a = new Intent( Intent a = new Intent(
Intent.ACTION_PICK, android.provider.MediaStore.Images.Media.EXTERNAL_CONTENT_URI); Intent.ACTION_PICK, android.provider.MediaStore.Images.Media.EXTERNAL_CONTENT_URI);
getActivity().startActivityForResult(a, MainActivity.RESULT_LOAD_IMAGE); requireActivity().startActivityForResult(a, MainActivity.RESULT_LOAD_IMAGE);
} else if (i == 3) { } else if (i == 3) {
getContext().getSharedPreferences("appsettings", Context.MODE_PRIVATE).edit().remove("Background").commit(); requireContext().getSharedPreferences("appsettings", Context.MODE_PRIVATE).edit().remove("Background").apply();
startActivity(getActivity().getIntent()); startActivity(requireActivity().getIntent());
getActivity().finish(); requireActivity().finish();
} }
dialogInterface.dismiss(); dialogInterface.dismiss();
} }
}); });
AlertDialog mDialog = mBuilder.create(); AlertDialog mDialog = mBuilder.create();
mDialog.getWindow().setBackgroundDrawableResource(R.drawable.button_round); Objects.requireNonNull(mDialog.getWindow()).setBackgroundDrawableResource(R.drawable.button_round);
mDialog.show(); mDialog.show();
} }
@ -265,8 +266,8 @@ public class EinstellungenFragment extends Fragment {
Locale.setDefault(locale); Locale.setDefault(locale);
Configuration config = new Configuration(); Configuration config = new Configuration();
config.locale = locale; config.locale = locale;
getContext().getResources().updateConfiguration(config, getContext().getResources().getDisplayMetrics()); requireContext().getResources().updateConfiguration(config, requireContext().getResources().getDisplayMetrics());
SharedPreferences.Editor editor = getContext().getSharedPreferences("appsettings", MODE_PRIVATE).edit(); SharedPreferences.Editor editor = requireContext().getSharedPreferences("appsettings", MODE_PRIVATE).edit();
editor.putString("Language", lang); editor.putString("Language", lang);
editor.apply(); editor.apply();
} }

View File

@ -26,6 +26,7 @@ import androidx.lifecycle.ViewModelProvider;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Base64; import java.util.Base64;
import java.util.List; import java.util.List;
import java.util.Objects;
import de.jg_cody.Teraplex.ActivityCricketers; import de.jg_cody.Teraplex.ActivityCricketers;
import de.jg_cody.Teraplex.Cricketer; import de.jg_cody.Teraplex.Cricketer;
@ -50,7 +51,7 @@ public class FlurFragment extends Fragment implements View.OnClickListener {
flurViewModel = flurViewModel =
new ViewModelProvider(this).get(FlurViewModel.class); new ViewModelProvider(this).get(FlurViewModel.class);
View root = inflater.inflate(R.layout.fragment_flur, container, false); View root = inflater.inflate(R.layout.fragment_flur, container, false);
SharedPreferences p = getContext().getSharedPreferences("appsettings", Activity.MODE_PRIVATE); SharedPreferences p = requireContext().getSharedPreferences("appsettings", Activity.MODE_PRIVATE);
String Background = p.getString("Background", null); String Background = p.getString("Background", null);
if (Background != null) { if (Background != null) {
ImageView I = root.findViewById(R.id.Background); ImageView I = root.findViewById(R.id.Background);
@ -154,7 +155,7 @@ public class FlurFragment extends Fragment implements View.OnClickListener {
AppCompatSpinner spinnerTeam = (AppCompatSpinner)cricketerView.findViewById(R.id.spinner_team); AppCompatSpinner spinnerTeam = (AppCompatSpinner)cricketerView.findViewById(R.id.spinner_team);
ImageView imageClose = (ImageView)cricketerView.findViewById(R.id.image_remove); ImageView imageClose = (ImageView)cricketerView.findViewById(R.id.image_remove);
ArrayAdapter arrayAdapter = new ArrayAdapter(getContext(),android.R.layout.simple_spinner_item,teamList); ArrayAdapter arrayAdapter = new ArrayAdapter(requireContext(),android.R.layout.simple_spinner_item,teamList);
spinnerTeam.setAdapter(arrayAdapter); spinnerTeam.setAdapter(arrayAdapter);
imageClose.setOnClickListener(new View.OnClickListener() { imageClose.setOnClickListener(new View.OnClickListener() {

View File

@ -23,6 +23,7 @@ import androidx.fragment.app.Fragment;
import androidx.lifecycle.ViewModelProvider; import androidx.lifecycle.ViewModelProvider;
import java.util.Base64; import java.util.Base64;
import java.util.Objects;
import de.jg_cody.Teraplex.MainActivity; import de.jg_cody.Teraplex.MainActivity;
import de.jg_cody.Teraplex.R; import de.jg_cody.Teraplex.R;
@ -49,7 +50,7 @@ public class KonsoleFragment extends Fragment {
konsoleViewModel = konsoleViewModel =
new ViewModelProvider(this).get(KonsoleViewModel.class); new ViewModelProvider(this).get(KonsoleViewModel.class);
View root = inflater.inflate(R.layout.fragment_konsole, container, false); View root = inflater.inflate(R.layout.fragment_konsole, container, false);
SharedPreferences p = getContext().getSharedPreferences("appsettings", Activity.MODE_PRIVATE); SharedPreferences p = requireContext().getSharedPreferences("appsettings", Activity.MODE_PRIVATE);
String Background = p.getString("Background", null); String Background = p.getString("Background", null);
if (Background != null) { if (Background != null) {
ImageView I = root.findViewById(R.id.Background); ImageView I = root.findViewById(R.id.Background);
@ -71,7 +72,7 @@ public class KonsoleFragment extends Fragment {
Toast.makeText(root.getContext(), command, Toast.LENGTH_SHORT).show(); Toast.makeText(root.getContext(), command, Toast.LENGTH_SHORT).show();
SSH_connection.executeRemoteCommand(ip, user, password, command); SSH_connection.executeRemoteCommand(ip, user, password, command);
} }
} catch (Exception e) { } catch (Exception ignored) {
} }
} }
@ -105,7 +106,7 @@ public class KonsoleFragment extends Fragment {
// A null listener allows the button to dismiss the dialog and take no further action. // A null listener allows the button to dismiss the dialog and take no further action.
.setNegativeButton(android.R.string.no, null) .setNegativeButton(android.R.string.no, null)
.create(); .create();
mDialog.getWindow().setBackgroundDrawableResource(R.drawable.button_round); Objects.requireNonNull(mDialog.getWindow()).setBackgroundDrawableResource(R.drawable.button_round);
mDialog.show(); mDialog.show();
@ -133,7 +134,7 @@ public class KonsoleFragment extends Fragment {
mp.start(); mp.start();
Toast.makeText(getContext(), "Server wird heruntergefahren...", Toast.LENGTH_SHORT).show(); Toast.makeText(getContext(), "Server wird heruntergefahren...", Toast.LENGTH_SHORT).show();
SSH_connection.executeRemoteCommand(ip, user, password, "shutdown now"); SSH_connection.executeRemoteCommand(ip, user, password, "shutdown now");
} catch (Exception e) { } catch (Exception ignored) {
} }
// Continue with delete operation // Continue with delete operation
@ -143,7 +144,7 @@ public class KonsoleFragment extends Fragment {
// A null listener allows the button to dismiss the dialog and take no further action. // A null listener allows the button to dismiss the dialog and take no further action.
.setNegativeButton(android.R.string.no, null) .setNegativeButton(android.R.string.no, null)
.create(); .create();
mDialog.getWindow().setBackgroundDrawableResource(R.drawable.button_round); Objects.requireNonNull(mDialog.getWindow()).setBackgroundDrawableResource(R.drawable.button_round);
mDialog.show(); mDialog.show();
} }

View File

@ -41,7 +41,7 @@ public class SchlafzimmerFragment extends Fragment {
@RequiresApi(api = Build.VERSION_CODES.O) @RequiresApi(api = Build.VERSION_CODES.O)
public View onCreateView(@NonNull LayoutInflater inflater, public View onCreateView(@NonNull LayoutInflater inflater,
ViewGroup container, Bundle savedInstanceState) { ViewGroup container, Bundle savedInstanceState) {
SharedPreferences prefs = getContext().getSharedPreferences("appsettings", Context.MODE_PRIVATE); SharedPreferences prefs = requireContext().getSharedPreferences("appsettings", Context.MODE_PRIVATE);
user = prefs.getString("user", null); user = prefs.getString("user", null);
password = prefs.getString("password", null); password = prefs.getString("password", null);
ip = prefs.getString("ip", null); ip = prefs.getString("ip", null);
@ -49,7 +49,7 @@ public class SchlafzimmerFragment extends Fragment {
schlafzimmerViewModel = schlafzimmerViewModel =
new ViewModelProvider(this).get(SchlafzimmerViewModel.class); new ViewModelProvider(this).get(SchlafzimmerViewModel.class);
View root = inflater.inflate(R.layout.fragment_schlafzimmer, container, false); View root = inflater.inflate(R.layout.fragment_schlafzimmer, container, false);
SharedPreferences p = getContext().getSharedPreferences("appsettings", Activity.MODE_PRIVATE); SharedPreferences p = requireContext().getSharedPreferences("appsettings", Activity.MODE_PRIVATE);
String Background = p.getString("Background", null); String Background = p.getString("Background", null);
if (Background != null) { if (Background != null) {
ImageView I = root.findViewById(R.id.Background); ImageView I = root.findViewById(R.id.Background);
@ -67,7 +67,7 @@ public class SchlafzimmerFragment extends Fragment {
try { try {
Toast.makeText(getContext(), "Lampe wird ausgeschaltet...", Toast.LENGTH_SHORT).show(); Toast.makeText(getContext(), "Lampe wird ausgeschaltet...", Toast.LENGTH_SHORT).show();
SSH_connection.executeRemoteCommand(ip, user, password, "sudo /root/raspberry-remote/send 11111 4 0"); SSH_connection.executeRemoteCommand(ip, user, password, "sudo /root/raspberry-remote/send 11111 4 0");
} catch (Exception e) { } catch (Exception ignored) {
} }
} }
@ -80,7 +80,7 @@ public class SchlafzimmerFragment extends Fragment {
try { try {
Toast.makeText(getContext(), "Lampe wird angeschaltet...", Toast.LENGTH_SHORT).show(); Toast.makeText(getContext(), "Lampe wird angeschaltet...", Toast.LENGTH_SHORT).show();
SSH_connection.executeRemoteCommand(ip, user, password, "sudo /root/raspberry-remote/send 11111 4 1"); SSH_connection.executeRemoteCommand(ip, user, password, "sudo /root/raspberry-remote/send 11111 4 1");
} catch (Exception e) { } catch (Exception ignored) {
} }
} }
@ -93,7 +93,7 @@ public class SchlafzimmerFragment extends Fragment {
try { try {
Toast.makeText(getContext(), "Lampe wird ausgeschaltet...", Toast.LENGTH_SHORT).show(); Toast.makeText(getContext(), "Lampe wird ausgeschaltet...", Toast.LENGTH_SHORT).show();
SSH_connection.executeRemoteCommand(ip, user, password, "sudo /root/raspberry-remote/send 11111 2 0"); SSH_connection.executeRemoteCommand(ip, user, password, "sudo /root/raspberry-remote/send 11111 2 0");
} catch (Exception e) { } catch (Exception ignored) {
} }
} }
@ -106,7 +106,7 @@ public class SchlafzimmerFragment extends Fragment {
try { try {
Toast.makeText(getContext(), "Lampe wird angeschaltet...", Toast.LENGTH_SHORT).show(); Toast.makeText(getContext(), "Lampe wird angeschaltet...", Toast.LENGTH_SHORT).show();
SSH_connection.executeRemoteCommand(ip, user, password, "sudo /root/raspberry-remote/send 11111 2 1"); SSH_connection.executeRemoteCommand(ip, user, password, "sudo /root/raspberry-remote/send 11111 2 1");
} catch (Exception e) { } catch (Exception ignored) {
} }
} }
@ -119,7 +119,7 @@ public class SchlafzimmerFragment extends Fragment {
try { try {
Toast.makeText(getContext(), "Lampe wird ausgeschaltet...", Toast.LENGTH_SHORT).show(); Toast.makeText(getContext(), "Lampe wird ausgeschaltet...", Toast.LENGTH_SHORT).show();
SSH_connection.executeRemoteCommand(ip, user, password, "sudo /root/raspberry-remote/send 11111 3 0"); SSH_connection.executeRemoteCommand(ip, user, password, "sudo /root/raspberry-remote/send 11111 3 0");
} catch (Exception e) { } catch (Exception ignored) {
} }
} }
@ -132,7 +132,7 @@ public class SchlafzimmerFragment extends Fragment {
try { try {
Toast.makeText(getContext(), "Lampe wird angeschaltet...", Toast.LENGTH_SHORT).show(); Toast.makeText(getContext(), "Lampe wird angeschaltet...", Toast.LENGTH_SHORT).show();
SSH_connection.executeRemoteCommand(ip, user, password, "sudo /root/raspberry-remote/send 11111 3 1"); SSH_connection.executeRemoteCommand(ip, user, password, "sudo /root/raspberry-remote/send 11111 3 1");
} catch (Exception e) { } catch (Exception ignored) {
} }
} }

View File

@ -47,7 +47,7 @@ public class HomeFragment extends Fragment {
@RequiresApi(api = Build.VERSION_CODES.O) @RequiresApi(api = Build.VERSION_CODES.O)
public View onCreateView(@NonNull LayoutInflater inflater, public View onCreateView(@NonNull LayoutInflater inflater,
ViewGroup container, Bundle savedInstanceState) { ViewGroup container, Bundle savedInstanceState) {
SharedPreferences prefs = getContext().getSharedPreferences("appsettings", Context.MODE_PRIVATE); SharedPreferences prefs = requireContext().getSharedPreferences("appsettings", Context.MODE_PRIVATE);
user = prefs.getString("user", null); user = prefs.getString("user", null);
password = prefs.getString("password", null); password = prefs.getString("password", null);
ip = prefs.getString("ip", null); ip = prefs.getString("ip", null);
@ -55,7 +55,7 @@ public class HomeFragment extends Fragment {
homeViewModel = homeViewModel =
new ViewModelProvider(this).get(HomeViewModel.class); new ViewModelProvider(this).get(HomeViewModel.class);
View root = inflater.inflate(R.layout.fragment_home, container, false); View root = inflater.inflate(R.layout.fragment_home, container, false);
SharedPreferences p = getContext().getSharedPreferences("appsettings", Activity.MODE_PRIVATE); SharedPreferences p = requireContext().getSharedPreferences("appsettings", Activity.MODE_PRIVATE);
String Background = p.getString("Background", null); String Background = p.getString("Background", null);
if (Background != null) { if (Background != null) {
ImageView I = root.findViewById(R.id.Background); ImageView I = root.findViewById(R.id.Background);
@ -74,7 +74,7 @@ public class HomeFragment extends Fragment {
passwordInput = (EditText) root.findViewById(R.id.loginpasswordInput); passwordInput = (EditText) root.findViewById(R.id.loginpasswordInput);
ipInput = (EditText) root.findViewById(R.id.ipInput); ipInput = (EditText) root.findViewById(R.id.ipInput);
loginButton = (Button) root.findViewById(R.id.loginButton); loginButton = (Button) root.findViewById(R.id.loginButton);
SharedPreferences t = getContext().getSharedPreferences("appsettings", Context.MODE_PRIVATE); SharedPreferences t = requireContext().getSharedPreferences("appsettings", Context.MODE_PRIVATE);
if (user == null || ip == null) { if (user == null || ip == null) {
loginButton.setVisibility(View.VISIBLE); loginButton.setVisibility(View.VISIBLE);
} else { } else {
@ -92,7 +92,7 @@ public class HomeFragment extends Fragment {
user = userInput.getText().toString(); user = userInput.getText().toString();
password = passwordInput.getText().toString(); password = passwordInput.getText().toString();
ip = ipInput.getText().toString(); ip = ipInput.getText().toString();
SharedPreferences p = getContext().getSharedPreferences("appsettings", Context.MODE_PRIVATE); SharedPreferences p = requireContext().getSharedPreferences("appsettings", Context.MODE_PRIVATE);
p.edit().putString("user", user).putString("password", password).putString("ip", ip).apply(); p.edit().putString("user", user).putString("password", password).putString("ip", ip).apply();
Toast.makeText(getContext(), getString(R.string.login_saved), Toast.LENGTH_SHORT).show(); Toast.makeText(getContext(), getString(R.string.login_saved), Toast.LENGTH_SHORT).show();
if (user == null || ip == null) { if (user == null || ip == null) {
@ -120,9 +120,9 @@ public class HomeFragment extends Fragment {
logoutButton.setOnClickListener(new View.OnClickListener() { logoutButton.setOnClickListener(new View.OnClickListener() {
@Override @Override
public void onClick(View v) { public void onClick(View v) {
getContext().getSharedPreferences("appsettings", Context.MODE_PRIVATE).edit().remove("ip").remove("user").remove("password").commit(); requireContext().getSharedPreferences("appsettings", Context.MODE_PRIVATE).edit().remove("ip").remove("user").remove("password").apply();
startActivity(getActivity().getIntent()); startActivity(requireActivity().getIntent());
getActivity().finish(); requireActivity().finish();
} }
}); });
wlan_aus_Button = (Button) root.findViewById(R.id.wlan_aus); wlan_aus_Button = (Button) root.findViewById(R.id.wlan_aus);

View File

@ -35,7 +35,7 @@ public class IntroFragment extends Fragment {
// Build your video Uri // Build your video Uri
Uri uri = Uri.parse("android.resource://" // First start with this, Uri uri = Uri.parse("android.resource://" // First start with this,
+ getContext().getPackageName() // then retrieve your package name, + requireContext().getPackageName() // then retrieve your package name,
+ "/" // add a slash, + "/" // add a slash,
+ R.raw.intro); // and then finally add your video resource. Make sure it is stored + R.raw.intro); // and then finally add your video resource. Make sure it is stored
// in the raw folder. // in the raw folder.

View File

@ -18,6 +18,7 @@ import androidx.fragment.app.Fragment;
import androidx.lifecycle.ViewModelProvider; import androidx.lifecycle.ViewModelProvider;
import java.util.Base64; import java.util.Base64;
import java.util.Objects;
import de.jg_cody.Teraplex.MainActivity; import de.jg_cody.Teraplex.MainActivity;
import de.jg_cody.Teraplex.R; import de.jg_cody.Teraplex.R;
@ -33,7 +34,7 @@ public class ZeitsteuerungFragment extends Fragment {
zeitsteuerungViewModel = zeitsteuerungViewModel =
new ViewModelProvider(this).get(ZeitsteuerungViewModel.class); new ViewModelProvider(this).get(ZeitsteuerungViewModel.class);
View root = inflater.inflate(R.layout.fragment_zeitsteuerung, container, false); View root = inflater.inflate(R.layout.fragment_zeitsteuerung, container, false);
SharedPreferences p = getContext().getSharedPreferences("appsettings", Activity.MODE_PRIVATE); SharedPreferences p = requireContext().getSharedPreferences("appsettings", Activity.MODE_PRIVATE);
String Background = p.getString("Background", null); String Background = p.getString("Background", null);
if (Background != null) { if (Background != null) {
ImageView I = root.findViewById(R.id.Background); ImageView I = root.findViewById(R.id.Background);

View File

@ -6,6 +6,7 @@
android:layout_width="match_parent" android:layout_width="match_parent"
android:clickable="true" android:clickable="true"
android:layout_height="match_parent" android:layout_height="match_parent"
android:hapticFeedbackEnabled="true"
tools:context=".ui.home.HomeFragment"> tools:context=".ui.home.HomeFragment">
<ImageView <ImageView
@ -95,7 +96,7 @@
android:textColor="@color/mtrl_btn_text_color_selector" android:textColor="@color/mtrl_btn_text_color_selector"
android:textColorHint="@color/mtrl_btn_text_color_selector" android:textColorHint="@color/mtrl_btn_text_color_selector"
app:layout_constraintEnd_toEndOf="@+id/text_home" app:layout_constraintEnd_toEndOf="@+id/text_home"
app:layout_constraintHorizontal_bias="0.497" app:layout_constraintHorizontal_bias="0.5"
app:layout_constraintStart_toStartOf="@+id/text_home" app:layout_constraintStart_toStartOf="@+id/text_home"
app:layout_constraintTop_toBottomOf="@+id/login_data" /> app:layout_constraintTop_toBottomOf="@+id/login_data" />
@ -111,7 +112,7 @@
android:textColor="@color/mtrl_btn_text_color_selector" android:textColor="@color/mtrl_btn_text_color_selector"
android:textColorHint="@color/mtrl_btn_text_color_selector" android:textColorHint="@color/mtrl_btn_text_color_selector"
app:layout_constraintEnd_toEndOf="@+id/text_home" app:layout_constraintEnd_toEndOf="@+id/text_home"
app:layout_constraintHorizontal_bias="0.497" app:layout_constraintHorizontal_bias="0.5"
app:layout_constraintStart_toStartOf="@+id/text_home" app:layout_constraintStart_toStartOf="@+id/text_home"
app:layout_constraintTop_toBottomOf="@+id/ipInput" /> app:layout_constraintTop_toBottomOf="@+id/ipInput" />
@ -126,7 +127,7 @@
android:textColor="@color/mtrl_btn_text_color_selector" android:textColor="@color/mtrl_btn_text_color_selector"
android:textColorHint="@color/mtrl_btn_text_color_selector" android:textColorHint="@color/mtrl_btn_text_color_selector"
app:layout_constraintEnd_toEndOf="@+id/text_home" app:layout_constraintEnd_toEndOf="@+id/text_home"
app:layout_constraintHorizontal_bias="0.497" app:layout_constraintHorizontal_bias="0.5"
app:layout_constraintStart_toStartOf="@+id/text_home" app:layout_constraintStart_toStartOf="@+id/text_home"
app:layout_constraintTop_toBottomOf="@+id/loginuserInput" /> app:layout_constraintTop_toBottomOf="@+id/loginuserInput" />

View File

@ -1,4 +1,4 @@
<resources xmlns:tools="http://schemas.android.com/tools"> <resources xmlns:tools="http://schemas.android.com/tools" xmlns:android="http://schemas.android.com/apk/res/android">
<!-- Base application theme. --> <!-- Base application theme. -->
<style name="Theme.red_blue" parent="Theme.MaterialComponents.DayNight.DarkActionBar"> <style name="Theme.red_blue" parent="Theme.MaterialComponents.DayNight.DarkActionBar">
<!-- Primary brand color. --> <!-- Primary brand color. -->
@ -18,6 +18,8 @@
<!-- Status bar color. --> <!-- Status bar color. -->
<item name="android:statusBarColor" tools:targetApi="l">?attr/colorPrimaryVariant</item> <item name="android:statusBarColor" tools:targetApi="l">?attr/colorPrimaryVariant</item>
<!-- Customize your theme here. --> <!-- Customize your theme here. -->
<item name="colorControlActivated">@color/red</item>
</style> </style>
<style name="Theme.red_blue.NoActionBar"> <style name="Theme.red_blue.NoActionBar">
@ -87,6 +89,7 @@
<!-- Status bar color. --> <!-- Status bar color. -->
<item name="android:statusBarColor" tools:targetApi="l">?attr/colorPrimaryVariant</item> <item name="android:statusBarColor" tools:targetApi="l">?attr/colorPrimaryVariant</item>
<!-- Customize your theme here. --> <!-- Customize your theme here. -->
<item name="colorControlActivated">@color/green</item>
</style> </style>
<style name="Theme.orange_turquoise" parent="Theme.MaterialComponents.DayNight.DarkActionBar"> <style name="Theme.orange_turquoise" parent="Theme.MaterialComponents.DayNight.DarkActionBar">
@ -107,6 +110,7 @@
<!-- Status bar color. --> <!-- Status bar color. -->
<item name="android:statusBarColor" tools:targetApi="l">?attr/colorPrimaryVariant</item> <item name="android:statusBarColor" tools:targetApi="l">?attr/colorPrimaryVariant</item>
<!-- Customize your theme here. --> <!-- Customize your theme here. -->
<item name="colorControlActivated">@color/orange</item>
</style> </style>
<style name="Theme.yellow_blue" parent="Theme.MaterialComponents.DayNight.DarkActionBar"> <style name="Theme.yellow_blue" parent="Theme.MaterialComponents.DayNight.DarkActionBar">
@ -127,6 +131,7 @@
<!-- Status bar color. --> <!-- Status bar color. -->
<item name="android:statusBarColor" tools:targetApi="l">?attr/colorPrimaryVariant</item> <item name="android:statusBarColor" tools:targetApi="l">?attr/colorPrimaryVariant</item>
<!-- Customize your theme here. --> <!-- Customize your theme here. -->
<item name="colorControlActivated">@color/yellow</item>
</style> </style>
<style name="Theme.pink_green" parent="Theme.MaterialComponents.DayNight.DarkActionBar"> <style name="Theme.pink_green" parent="Theme.MaterialComponents.DayNight.DarkActionBar">
@ -147,6 +152,7 @@
<!-- Status bar color. --> <!-- Status bar color. -->
<item name="android:statusBarColor" tools:targetApi="l">?attr/colorPrimaryVariant</item> <item name="android:statusBarColor" tools:targetApi="l">?attr/colorPrimaryVariant</item>
<!-- Customize your theme here. --> <!-- Customize your theme here. -->
<item name="colorControlActivated">@color/pink</item>
</style> </style>
</resources> </resources>

View File

@ -43,17 +43,17 @@
//settings //settings
<string name="farben">COLORS</string> <string name="farben">COLORS</string>
<string name="hintergrund">BACKGROUND</string> <string name="hintergrund">BACKGROUND</string>
<string name="button_hintergrund_wählen">CHOOSE BACKGROUND</string> <string name="button_hintergrund_wählen">"CHOOSE\nBACKGROUND"</string>
<string name="sprache">LANGUAGE</string> <string name="sprache">LANGUAGE</string>
<string name="einstellungen_zurücksetzen">RESET SETTINGS</string> <string name="einstellungen_zurücksetzen">RESET SETTINGS</string>
<string name="button_zurücksetzen">RESET</string> <string name="button_zurücksetzen">RESET</string>
<string name="themes">COLORSCHEME</string> <string name="themes">COLORSCHEME</string>
<string name="red_blue">RED\nBLUE</string> <string name="red_blue">"RED\nBLUE"</string>
<string name="green_yellow">GREEN\nYELLOW</string> <string name="green_yellow">"GREEN\nYELLOW"</string>
<string name="orange_turquoise">ORANGE\nTURQUOISE</string> <string name="orange_turquoise">"ORANGE\nTURQUOISE"</string>
<string name="yellow_blue">YELLOW\nBLUE</string> <string name="yellow_blue">"YELLOW\nBLUE"</string>
<string name="pink_green">PINK\nGREEN</string> <string name="pink_green">"PINK\nGREEN"</string>
<string name="reset_app">RESET\nAPP</string> <string name="reset_app">RESET APP</string>
<string name="are_you_sure_to_reset">ARE YOU SURE YOU WANT TO RESET THE APP AND DELETE ALL YOUR SETTINGS?</string> <string name="are_you_sure_to_reset">ARE YOU SURE YOU WANT TO RESET THE APP AND DELETE ALL YOUR SETTINGS?</string>
//credits //credits

View File

@ -18,6 +18,7 @@
<!-- Status bar color. --> <!-- Status bar color. -->
<item name="android:statusBarColor" tools:targetApi="l">?attr/colorPrimaryVariant</item> <item name="android:statusBarColor" tools:targetApi="l">?attr/colorPrimaryVariant</item>
<!-- Customize your theme here. --> <!-- Customize your theme here. -->
<item name="android:itemBackground">@drawable/button_round</item>
</style> </style>
<style name="Theme.red_blue.NoActionBar"> <style name="Theme.red_blue.NoActionBar">