added custom background option

This commit is contained in:
JG-Cody 2021-06-02 21:12:07 +02:00
parent 316a04df19
commit 1b12a92fbb
18 changed files with 289 additions and 58 deletions

View File

@ -4,6 +4,9 @@
<uses-permission android:name="android.permission.INTERNET" /> <uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" /> <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.VIBRATE"/> <uses-permission android:name="android.permission.VIBRATE"/>
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE"/>
<uses-permission android:name="android.permission."/>
<application <application
android:allowBackup="true" android:allowBackup="true"
android:icon="@mipmap/ic_launcher" android:icon="@mipmap/ic_launcher"

View File

@ -2,14 +2,21 @@ package de.jg_cody.Teraplex;
import android.app.Activity; import android.app.Activity;
import android.app.AlertDialog; import android.app.AlertDialog;
import android.content.Context;
import android.content.DialogInterface; import android.content.DialogInterface;
import android.content.Intent; import android.content.Intent;
import android.content.SharedPreferences; import android.content.SharedPreferences;
import android.content.res.Configuration; import android.content.res.Configuration;
import android.content.res.Resources; import android.content.res.Resources;
import android.database.Cursor;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.Canvas;
import android.graphics.RectF;
import android.net.Uri; import android.net.Uri;
import android.os.Build; import android.os.Build;
import android.os.Bundle; import android.os.Bundle;
import android.provider.MediaStore;
import android.text.SpannableString; import android.text.SpannableString;
import android.text.style.ForegroundColorSpan; import android.text.style.ForegroundColorSpan;
import android.util.Log; import android.util.Log;
@ -17,8 +24,10 @@ import android.util.TypedValue;
import android.view.Menu; import android.view.Menu;
import android.view.MenuItem; import android.view.MenuItem;
import android.view.View; import android.view.View;
import android.widget.ImageView;
import android.widget.Toast; import android.widget.Toast;
import androidx.annotation.RequiresApi;
import androidx.appcompat.app.AppCompatActivity; import androidx.appcompat.app.AppCompatActivity;
import androidx.appcompat.widget.Toolbar; import androidx.appcompat.widget.Toolbar;
import androidx.drawerlayout.widget.DrawerLayout; import androidx.drawerlayout.widget.DrawerLayout;
@ -31,6 +40,10 @@ import androidx.navigation.ui.NavigationUI;
import com.google.android.material.floatingactionbutton.FloatingActionButton; import com.google.android.material.floatingactionbutton.FloatingActionButton;
import com.google.android.material.navigation.NavigationView; import com.google.android.material.navigation.NavigationView;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.util.Base64;
import java.util.Locale; import java.util.Locale;
import de.jg_cody.Teraplex.ui.Credits.CreditsFragment; import de.jg_cody.Teraplex.ui.Credits.CreditsFragment;
@ -40,7 +53,7 @@ import de.jg_cody.Teraplex.ui.home.HomeFragment;
public class MainActivity extends AppCompatActivity implements AddButtonDialog.AddButtonDialogListener { public class MainActivity extends AppCompatActivity implements AddButtonDialog.AddButtonDialogListener {
public static int RESULT_LOAD_IMAGE = 0;
private AppBarConfiguration mAppBarConfiguration; private AppBarConfiguration mAppBarConfiguration;
@Override @Override
@ -188,6 +201,13 @@ public class MainActivity extends AppCompatActivity implements AddButtonDialog.A
startActivity(in); startActivity(in);
} }
public void menurighttoplogout(MenuItem i) {
Toast.makeText(this, "LOGOUT", Toast.LENGTH_LONG).show();
getSharedPreferences("appsettings", Context.MODE_PRIVATE).edit().remove("ip").remove("user").remove("password").commit();
startActivity(getIntent());
finish();
}
public void menurighttopschliessen(MenuItem i) { public void menurighttopschliessen(MenuItem i) {
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.LOLLIPOP) { if (Build.VERSION.SDK_INT < Build.VERSION_CODES.LOLLIPOP) {
finishAffinity(); finishAffinity();
@ -195,6 +215,7 @@ public class MainActivity extends AppCompatActivity implements AddButtonDialog.A
finishAndRemoveTask(); finishAndRemoveTask();
} }
} }
private void showChooseElement() { private void showChooseElement() {
final String[] listItems = {"SINGLE BUTTON", "DOUBLE BUTTON", "OPTION3"}; final String[] listItems = {"SINGLE BUTTON", "DOUBLE BUTTON", "OPTION3"};
AlertDialog.Builder mBuilder = new AlertDialog.Builder(MainActivity.this); AlertDialog.Builder mBuilder = new AlertDialog.Builder(MainActivity.this);
@ -216,4 +237,81 @@ public class MainActivity extends AppCompatActivity implements AddButtonDialog.A
mDialog.show(); mDialog.show();
} }
@RequiresApi(api = Build.VERSION_CODES.O)
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
if (requestCode == RESULT_LOAD_IMAGE && resultCode == RESULT_OK && null != data) {
Uri selectedImage = data.getData();
String[] filePathColumn = {MediaStore.Images.Media.DATA};
Cursor cursor = getContentResolver().query(selectedImage,
filePathColumn, null, null, null);
cursor.moveToFirst();
int columnIndex = cursor.getColumnIndex(filePathColumn[0]);
String picturePath = cursor.getString(columnIndex);
cursor.close();
// String picturePath contains the path of selected Image
try {
InputStream Background= getContentResolver().openInputStream(selectedImage);
ByteArrayOutputStream bOut = new ByteArrayOutputStream();
int len;
byte[] buf = new byte[1024];
while((len = Background.read(buf)) > 0) {
bOut.write(buf, 0, len);
}
Background.close();
SharedPreferences p = getSharedPreferences("appsettings", Context.MODE_PRIVATE);
p.edit().putString("Background", Base64.getEncoder().encodeToString(bOut.toByteArray())).apply();
loadBackground();
startActivity(getIntent());
finish();
} catch (IOException e) {
e.printStackTrace();
}
}
}
@RequiresApi(api = Build.VERSION_CODES.O)
private void loadBackground() {
SharedPreferences p = getSharedPreferences("appsettings", Activity.MODE_PRIVATE);
String Background = p.getString("Background", null);
ImageView I = findViewById(R.id.Background);
byte[] BA = Base64.getDecoder().decode(Background);
I.setImageBitmap(BitmapFactory.decodeByteArray(BA, 0, BA.length));
}
public static int getScreenWidth() {
return Resources.getSystem().getDisplayMetrics().widthPixels;
}
public static int getScreenHeight() {
return Resources.getSystem().getDisplayMetrics().heightPixels;
}
public static Bitmap scaleCenterCrop(Bitmap source, int newHeight,
int newWidth) {
int sourceWidth = source.getWidth();
int sourceHeight = source.getHeight();
float xScale = (float) newWidth / sourceWidth;
float yScale = (float) newHeight / sourceHeight;
float scale = Math.max(xScale, yScale);
// Now get the size of the source bitmap when scaled
float scaledWidth = scale * sourceWidth;
float scaledHeight = scale * sourceHeight;
float left = (newWidth - scaledWidth) / 2;
float top = (newHeight - scaledHeight) / 2;
RectF targetRect = new RectF(left, top, left + scaledWidth, top
+ scaledHeight);//from ww w .j a va 2s. co m
Bitmap dest = Bitmap.createBitmap(newWidth, newHeight,
source.getConfig());
Canvas canvas = new Canvas(dest);
canvas.drawBitmap(source, null, targetRect, null);
return dest;
}
} }

View File

@ -1,26 +1,44 @@
package de.jg_cody.Teraplex.ui.Credits; package de.jg_cody.Teraplex.ui.Credits;
import android.app.Activity;
import android.content.SharedPreferences;
import android.graphics.BitmapFactory;
import android.graphics.drawable.BitmapDrawable;
import android.os.Build;
import android.os.Bundle; import android.os.Bundle;
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.ImageView;
import androidx.annotation.NonNull; import androidx.annotation.NonNull;
import androidx.annotation.RequiresApi;
import androidx.fragment.app.Fragment; import androidx.fragment.app.Fragment;
import androidx.lifecycle.ViewModelProvider; import androidx.lifecycle.ViewModelProvider;
import java.util.Base64;
import de.jg_cody.Teraplex.MainActivity;
import de.jg_cody.Teraplex.R; import de.jg_cody.Teraplex.R;
public class CreditsFragment extends Fragment { public class CreditsFragment extends Fragment {
private CreditsViewModel creditsViewModel; private CreditsViewModel creditsViewModel;
@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) {
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);
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);
}
return root; return root;
} }
} }

View File

@ -1,25 +1,34 @@
package de.jg_cody.Teraplex.ui.Einstellungen; package de.jg_cody.Teraplex.ui.Einstellungen;
import android.app.Activity;
import android.app.AlertDialog; import android.app.AlertDialog;
import android.content.Context; import android.content.Context;
import android.content.DialogInterface; import android.content.DialogInterface;
import android.content.Intent;
import android.content.SharedPreferences; import android.content.SharedPreferences;
import android.content.res.Configuration; import android.content.res.Configuration;
import android.graphics.BitmapFactory;
import android.graphics.drawable.BitmapDrawable;
import android.os.Build;
import android.os.Bundle; import android.os.Bundle;
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.ImageView;
import android.widget.Toast; import android.widget.Toast;
import androidx.annotation.NonNull; import androidx.annotation.NonNull;
import androidx.annotation.RequiresApi;
import androidx.fragment.app.Fragment; import androidx.fragment.app.Fragment;
import androidx.lifecycle.ViewModelProvider; import androidx.lifecycle.ViewModelProvider;
import com.rarepebble.colorpicker.ColorPickerView; import com.rarepebble.colorpicker.ColorPickerView;
import java.util.Base64;
import java.util.Locale; import java.util.Locale;
import de.jg_cody.Teraplex.MainActivity;
import de.jg_cody.Teraplex.R; import de.jg_cody.Teraplex.R;
import static android.content.Context.MODE_PRIVATE; import static android.content.Context.MODE_PRIVATE;
@ -29,11 +38,20 @@ public class EinstellungenFragment extends Fragment {
private EinstellungenViewModel einstellungenViewModel; private EinstellungenViewModel einstellungenViewModel;
Button button_colorpicker; Button button_colorpicker;
@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) {
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);
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);
}
button_colorpicker = (Button) root.findViewById(R.id.button_colorpicker); button_colorpicker = (Button) root.findViewById(R.id.button_colorpicker);
button_colorpicker.setOnClickListener(new View.OnClickListener() { button_colorpicker.setOnClickListener(new View.OnClickListener() {
@Override @Override
@ -91,6 +109,16 @@ public class EinstellungenFragment extends Fragment {
} }
}); });
Button choose_background = root.findViewById(R.id.button_pickimage);
choose_background.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
Intent i = new Intent(
Intent.ACTION_PICK, android.provider.MediaStore.Images.Media.EXTERNAL_CONTENT_URI);
getActivity().startActivityForResult(i, MainActivity.RESULT_LOAD_IMAGE);
}
});
return root; return root;

View File

@ -1,22 +1,15 @@
package de.jg_cody.Teraplex.ui.Flur; package de.jg_cody.Teraplex.ui.Flur;
import android.app.Activity;
import android.content.Intent;
import android.content.SharedPreferences;
import android.graphics.BitmapFactory;
import android.graphics.drawable.BitmapDrawable;
import android.os.Build;
import android.os.Bundle; import android.os.Bundle;
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 androidx.annotation.NonNull;
import androidx.fragment.app.Fragment;
import androidx.lifecycle.ViewModelProvider;
import de.jg_cody.Teraplex.ActivityCricketers;
import de.jg_cody.Teraplex.Cricketer;
import de.jg_cody.Teraplex.R;
import androidx.appcompat.widget.AppCompatSpinner;
import android.content.Intent;
import android.widget.ArrayAdapter; import android.widget.ArrayAdapter;
import android.widget.Button; import android.widget.Button;
import android.widget.EditText; import android.widget.EditText;
@ -24,9 +17,21 @@ import android.widget.ImageView;
import android.widget.LinearLayout; import android.widget.LinearLayout;
import android.widget.Toast; import android.widget.Toast;
import androidx.annotation.NonNull;
import androidx.annotation.RequiresApi;
import androidx.appcompat.widget.AppCompatSpinner;
import androidx.fragment.app.Fragment;
import androidx.lifecycle.ViewModelProvider;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Base64;
import java.util.List; import java.util.List;
import de.jg_cody.Teraplex.ActivityCricketers;
import de.jg_cody.Teraplex.Cricketer;
import de.jg_cody.Teraplex.MainActivity;
import de.jg_cody.Teraplex.R;
public class FlurFragment extends Fragment implements View.OnClickListener { public class FlurFragment extends Fragment implements View.OnClickListener {
@ -39,11 +44,20 @@ public class FlurFragment extends Fragment implements View.OnClickListener {
List<String> teamList = new ArrayList<>(); List<String> teamList = new ArrayList<>();
ArrayList<Cricketer> cricketersList = new ArrayList<>(); ArrayList<Cricketer> cricketersList = new ArrayList<>();
@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) {
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);
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);
}
layoutList = root.findViewById(R.id.layout_list); layoutList = root.findViewById(R.id.layout_list);
buttonAdd = root.findViewById(R.id.button_add); buttonAdd = root.findViewById(R.id.button_add);

View File

@ -1,19 +1,29 @@
package de.jg_cody.Teraplex.ui.Konsole; package de.jg_cody.Teraplex.ui.Konsole;
import android.app.Activity;
import android.app.AlertDialog; import android.app.AlertDialog;
import android.content.DialogInterface; 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.os.Bundle;
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.EditText;
import android.widget.ImageView;
import android.widget.Toast; import android.widget.Toast;
import androidx.annotation.NonNull; import androidx.annotation.NonNull;
import androidx.annotation.RequiresApi;
import androidx.fragment.app.Fragment; import androidx.fragment.app.Fragment;
import androidx.lifecycle.ViewModelProvider; import androidx.lifecycle.ViewModelProvider;
import java.util.Base64;
import de.jg_cody.Teraplex.MainActivity;
import de.jg_cody.Teraplex.R; import de.jg_cody.Teraplex.R;
import de.jg_cody.Teraplex.SSH_connection; import de.jg_cody.Teraplex.SSH_connection;
@ -32,11 +42,20 @@ public class KonsoleFragment extends Fragment {
private KonsoleViewModel konsoleViewModel; private KonsoleViewModel konsoleViewModel;
@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) {
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);
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);
}
befehlInput = (EditText) root.findViewById(R.id.befehlInput); befehlInput = (EditText) root.findViewById(R.id.befehlInput);
SendCommandButton = (Button) root.findViewById(R.id.SendCommandButton); SendCommandButton = (Button) root.findViewById(R.id.SendCommandButton);
SendCommandButton.setOnClickListener(new View.OnClickListener() { SendCommandButton.setOnClickListener(new View.OnClickListener() {

View File

@ -1,21 +1,30 @@
package de.jg_cody.Teraplex.ui.Schlafzimmer; package de.jg_cody.Teraplex.ui.Schlafzimmer;
import android.app.Activity;
import android.content.Context; import android.content.Context;
import android.content.SharedPreferences; import android.content.SharedPreferences;
import android.graphics.BitmapFactory;
import android.graphics.drawable.BitmapDrawable;
import android.os.Build;
import android.os.Bundle; import android.os.Bundle;
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.ImageView;
import android.widget.TextView; import android.widget.TextView;
import android.widget.Toast; import android.widget.Toast;
import androidx.annotation.NonNull; import androidx.annotation.NonNull;
import androidx.annotation.Nullable; import androidx.annotation.Nullable;
import androidx.annotation.RequiresApi;
import androidx.fragment.app.Fragment; import androidx.fragment.app.Fragment;
import androidx.lifecycle.Observer; import androidx.lifecycle.Observer;
import androidx.lifecycle.ViewModelProvider; import androidx.lifecycle.ViewModelProvider;
import java.util.Base64;
import de.jg_cody.Teraplex.MainActivity;
import de.jg_cody.Teraplex.R; import de.jg_cody.Teraplex.R;
import de.jg_cody.Teraplex.SSH_connection; import de.jg_cody.Teraplex.SSH_connection;
@ -32,6 +41,7 @@ public class SchlafzimmerFragment extends Fragment {
private SchlafzimmerViewModel schlafzimmerViewModel; private SchlafzimmerViewModel schlafzimmerViewModel;
@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 = getContext().getSharedPreferences("appsettings", Context.MODE_PRIVATE);
@ -42,6 +52,14 @@ 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);
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);
}
final TextView textView = root.findViewById(R.id.text_schlafzimmer); final TextView textView = root.findViewById(R.id.text_schlafzimmer);
schlafzimmerViewModel.getText().observe(getViewLifecycleOwner(), new Observer<String>() { schlafzimmerViewModel.getText().observe(getViewLifecycleOwner(), new Observer<String>() {
@Override @Override

View File

@ -1,20 +1,29 @@
package de.jg_cody.Teraplex.ui.home; package de.jg_cody.Teraplex.ui.home;
import android.app.Activity;
import android.content.Context; import android.content.Context;
import android.content.SharedPreferences; import android.content.SharedPreferences;
import android.graphics.BitmapFactory;
import android.graphics.drawable.BitmapDrawable;
import android.os.Build;
import android.os.Bundle; import android.os.Bundle;
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.EditText;
import android.widget.ImageView;
import android.widget.TextView; import android.widget.TextView;
import android.widget.Toast; import android.widget.Toast;
import androidx.annotation.NonNull; import androidx.annotation.NonNull;
import androidx.annotation.RequiresApi;
import androidx.fragment.app.Fragment; import androidx.fragment.app.Fragment;
import androidx.lifecycle.ViewModelProvider; import androidx.lifecycle.ViewModelProvider;
import java.util.Base64;
import de.jg_cody.Teraplex.MainActivity;
import de.jg_cody.Teraplex.R; import de.jg_cody.Teraplex.R;
import de.jg_cody.Teraplex.SSH_connection; import de.jg_cody.Teraplex.SSH_connection;
@ -34,6 +43,7 @@ public class HomeFragment extends Fragment {
private HomeViewModel homeViewModel; private HomeViewModel homeViewModel;
@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 = getContext().getSharedPreferences("appsettings", Context.MODE_PRIVATE);
@ -44,6 +54,14 @@ 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);
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);
}
final TextView textView = root.findViewById(R.id.text_home); final TextView textView = root.findViewById(R.id.text_home);
final TextView login_data = root.findViewById(R.id.login_data); final TextView login_data = root.findViewById(R.id.login_data);
if (user == null || ip == null) { if (user == null || ip == null) {

View File

@ -1,28 +1,47 @@
package de.jg_cody.Teraplex.ui.kueche; package de.jg_cody.Teraplex.ui.kueche;
import android.app.Activity;
import android.content.SharedPreferences;
import android.graphics.BitmapFactory;
import android.graphics.drawable.BitmapDrawable;
import android.os.Build;
import android.os.Bundle; import android.os.Bundle;
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.ImageView;
import android.widget.TextView; import android.widget.TextView;
import androidx.annotation.NonNull; import androidx.annotation.NonNull;
import androidx.annotation.Nullable; import androidx.annotation.Nullable;
import androidx.annotation.RequiresApi;
import androidx.fragment.app.Fragment; import androidx.fragment.app.Fragment;
import androidx.lifecycle.Observer; import androidx.lifecycle.Observer;
import androidx.lifecycle.ViewModelProvider; import androidx.lifecycle.ViewModelProvider;
import java.util.Base64;
import de.jg_cody.Teraplex.MainActivity;
import de.jg_cody.Teraplex.R; import de.jg_cody.Teraplex.R;
public class KuecheFragment extends Fragment { public class KuecheFragment extends Fragment {
private KuecheViewModel kuecheViewModel; private KuecheViewModel kuecheViewModel;
@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) {
kuecheViewModel = kuecheViewModel =
new ViewModelProvider(this).get(KuecheViewModel.class); new ViewModelProvider(this).get(KuecheViewModel.class);
View root = inflater.inflate(R.layout.fragment_kueche, container, false); View root = inflater.inflate(R.layout.fragment_kueche, container, false);
SharedPreferences p = getContext().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);
}
final TextView textView = root.findViewById(R.id.text_kueche); final TextView textView = root.findViewById(R.id.text_kueche);
kuecheViewModel.getText().observe(getViewLifecycleOwner(), new Observer<String>() { kuecheViewModel.getText().observe(getViewLifecycleOwner(), new Observer<String>() {
@Override @Override

View File

@ -1,15 +1,25 @@
package de.jg_cody.Teraplex.ui.zeitsteuerung; package de.jg_cody.Teraplex.ui.zeitsteuerung;
import android.app.Activity;
import android.content.SharedPreferences;
import android.graphics.BitmapFactory;
import android.graphics.drawable.BitmapDrawable;
import android.os.Build;
import android.os.Bundle; import android.os.Bundle;
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.ImageView;
import android.widget.TimePicker; import android.widget.TimePicker;
import androidx.annotation.NonNull; import androidx.annotation.NonNull;
import androidx.annotation.RequiresApi;
import androidx.fragment.app.Fragment; import androidx.fragment.app.Fragment;
import androidx.lifecycle.ViewModelProvider; import androidx.lifecycle.ViewModelProvider;
import java.util.Base64;
import de.jg_cody.Teraplex.MainActivity;
import de.jg_cody.Teraplex.R; import de.jg_cody.Teraplex.R;
public class ZeitsteuerungFragment extends Fragment { public class ZeitsteuerungFragment extends Fragment {
@ -17,11 +27,20 @@ public class ZeitsteuerungFragment extends Fragment {
private ZeitsteuerungViewModel zeitsteuerungViewModel; private ZeitsteuerungViewModel zeitsteuerungViewModel;
TimePicker timePicker; TimePicker timePicker;
@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) {
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);
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);
}
TimePicker timePicker = (TimePicker) root.findViewById(R.id.timePicker); TimePicker timePicker = (TimePicker) root.findViewById(R.id.timePicker);
timePicker.setIs24HourView(true); timePicker.setIs24HourView(true);
return root; return root;

View File

@ -15,7 +15,7 @@
android:src="@drawable/background" android:src="@drawable/background"
app:layout_constraintBottom_toBottomOf="parent" app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent" app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.727" app:layout_constraintHorizontal_bias="0.5"
app:layout_constraintStart_toStartOf="parent" app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_bias="0.0" /> app:layout_constraintVertical_bias="0.0" />
@ -74,7 +74,7 @@
app:layout_constraintBottom_toBottomOf="parent" app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent" app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent" app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="@+id/Background" /> app:layout_constraintTop_toTopOf="parent" />
<TextView <TextView
android:id="@+id/nightmode" android:id="@+id/nightmode"
@ -119,7 +119,7 @@
app:layout_constraintTop_toBottomOf="@+id/sprache" /> app:layout_constraintTop_toBottomOf="@+id/sprache" />
<Button <Button
android:id="@+id/button_pickimage2" android:id="@+id/button_pickimage"
android:layout_width="wrap_content" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:text="@string/button_hintergrund_wählen" android:text="@string/button_hintergrund_wählen"

View File

@ -4,10 +4,21 @@
xmlns:app="http://schemas.android.com/apk/res-auto" xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="match_parent" android:layout_height="match_parent"
android:background="@drawable/background"
android:orientation="vertical" android:orientation="vertical"
tools:context=".MainActivity"> tools:context=".MainActivity">
<ImageView
android:id="@+id/Background"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:scaleType="centerCrop"
android:src="@drawable/background"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.5"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_bias="0.0" />
<Space <Space
android:layout_width="match_parent" android:layout_width="match_parent"

View File

@ -2,6 +2,8 @@
xmlns:android="http://schemas.android.com/apk/res/android" xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"> xmlns:app="http://schemas.android.com/apk/res-auto">
<TextView <TextView
android:id="@+id/text_kueche" android:id="@+id/text_kueche"
android:layout_width="match_parent" android:layout_width="match_parent"

View File

@ -7,7 +7,7 @@
tools:context=".ui.home.HomeFragment"> tools:context=".ui.home.HomeFragment">
<ImageView <ImageView
android:id="@+id/Background" android:id="@+id/LoginBackground"
android:layout_width="wrap_content" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:src="@drawable/teraplex_login" android:src="@drawable/teraplex_login"

View File

@ -7,17 +7,5 @@
android:layout_height="match_parent" android:layout_height="match_parent"
tools:context=".ui.kueche.KuecheFragment"> tools:context=".ui.kueche.KuecheFragment">
<ImageView
android:id="@+id/Background"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:scaleType="centerCrop"
android:src="@drawable/background"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.5"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_bias="0.0" />
</androidx.constraintlayout.widget.ConstraintLayout> </androidx.constraintlayout.widget.ConstraintLayout>

View File

@ -7,19 +7,6 @@
android:layout_height="match_parent" android:layout_height="match_parent"
tools:context=".ui.Schlafzimmer.SchlafzimmerFragment"> tools:context=".ui.Schlafzimmer.SchlafzimmerFragment">
<ImageView
android:id="@+id/Background"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:scaleType="centerCrop"
android:src="@drawable/background"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.5"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_bias="0.0" />
<Button <Button
android:id="@+id/schlafzimmeru3an" android:id="@+id/schlafzimmeru3an"
android:layout_width="wrap_content" android:layout_width="wrap_content"

View File

@ -7,18 +7,6 @@
android:layout_height="match_parent" android:layout_height="match_parent"
tools:context=".ui.zeitsteuerung.ZeitsteuerungFragment"> tools:context=".ui.zeitsteuerung.ZeitsteuerungFragment">
<ImageView
android:id="@+id/Background"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:scaleType="centerCrop"
android:src="@drawable/background"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.5"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_bias="0.0" />
<EditText <EditText
android:id="@+id/befehlInput2" android:id="@+id/befehlInput2"

View File

@ -34,6 +34,7 @@
<item <item
android:id="@+id/logout" android:id="@+id/logout"
android:icon="@drawable/ic_menu_share" android:icon="@drawable/ic_menu_share"
android:onClick="menurighttoplogout"
android:orderInCategory="100" android:orderInCategory="100"
android:title="@string/menu_logout" android:title="@string/menu_logout"
app:showAsAction="never" /> app:showAsAction="never" />