From 86c71a5abb03849682d549e4e82578190c533614 Mon Sep 17 00:00:00 2001 From: JG-Cody Date: Thu, 10 Jun 2021 21:36:52 +0200 Subject: [PATCH] added five fully functional themes =D --- app/src/main/AndroidManifest.xml | 6 +- .../de/jg_cody/Teraplex/MainActivity.java | 27 +- .../Einstellungen/EinstellungenFragment.java | 97 +++++-- .../drawable/button_theme_green_yellow.xml | 39 +++ .../button_theme_orange_turquoise.xml | 39 +++ .../res/drawable/button_theme_pink_green.xml | 39 +++ .../res/drawable/button_theme_red_blue.xml | 39 +++ .../res/drawable/button_theme_yellow_blue.xml | 39 +++ app/src/main/res/drawable/toolbartop.xml | 4 +- app/src/main/res/layout-v23/app_bar_main.xml | 4 +- app/src/main/res/layout/app_bar_main.xml | 4 +- .../res/layout/fragment_einstellungen.xml | 240 ++++++++++++------ app/src/main/res/values-night/themes.xml | 140 +++++++++- app/src/main/res/values/colors.xml | 5 + app/src/main/res/values/strings.xml | 2 +- app/src/main/res/values/themes.xml | 126 ++++++++- 16 files changed, 718 insertions(+), 132 deletions(-) create mode 100644 app/src/main/res/drawable/button_theme_green_yellow.xml create mode 100644 app/src/main/res/drawable/button_theme_orange_turquoise.xml create mode 100644 app/src/main/res/drawable/button_theme_pink_green.xml create mode 100644 app/src/main/res/drawable/button_theme_red_blue.xml create mode 100644 app/src/main/res/drawable/button_theme_yellow_blue.xml diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index 317b647..535b7c3 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -13,13 +13,13 @@ android:label="@string/app_name" android:roundIcon="@mipmap/ic_launcher_round" android:supportsRtl="true" - android:theme="@style/Theme.Teraplex"> + android:theme="@style/Theme.red_blue"> + android:theme="@style/Theme.red_blue.NoActionBar"> @@ -32,7 +32,7 @@ android:resizeableActivity="false" android:name=".MainActivity" android:label="@string/app_name" - android:theme="@style/Theme.Teraplex.NoActionBar"> + android:theme="@style/Theme.red_blue.NoActionBar"> diff --git a/app/src/main/java/de/jg_cody/Teraplex/MainActivity.java b/app/src/main/java/de/jg_cody/Teraplex/MainActivity.java index fbdab3d..bfd9a9a 100644 --- a/app/src/main/java/de/jg_cody/Teraplex/MainActivity.java +++ b/app/src/main/java/de/jg_cody/Teraplex/MainActivity.java @@ -86,6 +86,23 @@ public class MainActivity extends AppCompatActivity implements AddButtonDialog.A config.locale = locale; getBaseContext().getResources().updateConfiguration(config, getBaseContext().getResources().getDisplayMetrics()); + String Theme = p.getString("Theme", "RED_BLUE"); + if (Theme.equals("RED_BLUE")) { + setTheme(R.style.Theme_red_blue); + } + if (Theme.equals("GREEN_YELLOW")) { + setTheme(R.style.Theme_green_yellow); + } + if (Theme.equals("ORANGE_TURQUOISE")) { + setTheme(R.style.Theme_orange_turquoise); + } + if (Theme.equals("YELLOW_BLUE")) { + setTheme(R.style.Theme_yellow_blue); + } + if (Theme.equals("PINK_GREEN")) { + setTheme(R.style.Theme_pink_green); + } + setContentView(R.layout.activity_main); Toolbar toolbar = findViewById(R.id.toolbar); @@ -257,11 +274,11 @@ public class MainActivity extends AppCompatActivity implements AddButtonDialog.A cursor.close(); // String picturePath contains the path of selected Image try { - InputStream Background= getContentResolver().openInputStream(selectedImage); + InputStream Background = getContentResolver().openInputStream(selectedImage); ByteArrayOutputStream bOut = new ByteArrayOutputStream(); int len; byte[] buf = new byte[1024]; - while((len = Background.read(buf)) > 0) { + while ((len = Background.read(buf)) > 0) { bOut.write(buf, 0, len); } Background.close(); @@ -277,6 +294,7 @@ public class MainActivity extends AppCompatActivity implements AddButtonDialog.A } } + @RequiresApi(api = Build.VERSION_CODES.O) private void loadBackground() { SharedPreferences p = getSharedPreferences("appsettings", Activity.MODE_PRIVATE); @@ -286,6 +304,7 @@ public class MainActivity extends AppCompatActivity implements AddButtonDialog.A I.setImageBitmap(BitmapFactory.decodeByteArray(BA, 0, BA.length)); } + public static int getScreenWidth() { return Resources.getSystem().getDisplayMetrics().widthPixels; } @@ -293,8 +312,9 @@ public class MainActivity extends AppCompatActivity implements AddButtonDialog.A public static int getScreenHeight() { return Resources.getSystem().getDisplayMetrics().heightPixels; } + public static Bitmap scaleCenterCrop(Bitmap source, int newHeight, - int newWidth) { + int newWidth) { int sourceWidth = source.getWidth(); int sourceHeight = source.getHeight(); @@ -319,6 +339,7 @@ public class MainActivity extends AppCompatActivity implements AddButtonDialog.A return dest; } + public static Bitmap createImage(int width, int height, int color) { Bitmap bitmap = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888); Canvas canvas = new Canvas(bitmap); diff --git a/app/src/main/java/de/jg_cody/Teraplex/ui/Einstellungen/EinstellungenFragment.java b/app/src/main/java/de/jg_cody/Teraplex/ui/Einstellungen/EinstellungenFragment.java index 743f04d..068abe4 100644 --- a/app/src/main/java/de/jg_cody/Teraplex/ui/Einstellungen/EinstellungenFragment.java +++ b/app/src/main/java/de/jg_cody/Teraplex/ui/Einstellungen/EinstellungenFragment.java @@ -37,7 +37,6 @@ import static android.content.Context.MODE_PRIVATE; public class EinstellungenFragment extends Fragment { private EinstellungenViewModel einstellungenViewModel; - Button button_colorpicker; @RequiresApi(api = Build.VERSION_CODES.O) public View onCreateView(@NonNull LayoutInflater inflater, @@ -53,27 +52,6 @@ public class EinstellungenFragment extends Fragment { 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.setOnClickListener(new View.OnClickListener() { - @Override - public void onClick(View v) { - - try { - Toast.makeText(getContext(), "Colorpicker", Toast.LENGTH_SHORT).show(); - final ColorPickerView picker = new ColorPickerView(getContext()); - picker.setColor(0xff12345); - AlertDialog mDialog = new AlertDialog.Builder(getContext()).setView(picker).setTitle(R.string.colorpicker).setPositiveButton(R.string.ok, new DialogInterface.OnClickListener() { - @Override - public void onClick(DialogInterface dialog, int which) { - - } - }).create(); - mDialog.getWindow().setBackgroundDrawableResource(R.drawable.button_round); - mDialog.show(); - } catch (Exception e) { - } - } - }); Button Language = root.findViewById(R.id.button_language); Language.setOnClickListener(new View.OnClickListener() { @Override @@ -124,8 +102,77 @@ public class EinstellungenFragment extends Fragment { } }); + Button theme1 = root.findViewById(R.id.button_theme_red_blue); + theme1.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View view) { + Toast.makeText(getContext(), "Theme1", Toast.LENGTH_SHORT).show(); + SharedPreferences.Editor editor = getContext().getSharedPreferences("appsettings", MODE_PRIVATE).edit(); + editor.putString("Theme", "RED_BLUE"); + editor.apply(); + startActivity(getActivity().getIntent()); + getActivity().finish(); + } + }); + Button theme2 = root.findViewById(R.id.button_theme_green_yellow); + theme2.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View view) { + Toast.makeText(getContext(), "Theme2", Toast.LENGTH_SHORT).show(); + SharedPreferences.Editor editor = getContext().getSharedPreferences("appsettings", MODE_PRIVATE).edit(); + editor.putString("Theme", "GREEN_YELLOW"); + editor.apply(); + startActivity(getActivity().getIntent()); + getActivity().finish(); + + + } + }); + Button theme3 = root.findViewById(R.id.button_theme_orange_turquoise); + theme3.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View view) { + Toast.makeText(getContext(), "Theme3", Toast.LENGTH_SHORT).show(); + SharedPreferences.Editor editor = getContext().getSharedPreferences("appsettings", MODE_PRIVATE).edit(); + editor.putString("Theme", "ORANGE_TURQUOISE"); + editor.apply(); + startActivity(getActivity().getIntent()); + getActivity().finish(); + + + } + }); + Button theme4 = root.findViewById(R.id.button_theme_yellow_blue); + theme4.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View view) { + Toast.makeText(getContext(), "Theme4", Toast.LENGTH_SHORT).show(); + SharedPreferences.Editor editor = getContext().getSharedPreferences("appsettings", MODE_PRIVATE).edit(); + editor.putString("Theme", "YELLOW_BLUE"); + editor.apply(); + startActivity(getActivity().getIntent()); + getActivity().finish(); + + + } + }); + Button theme5 = root.findViewById(R.id.button_theme_pink_green); + theme5.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View view) { + Toast.makeText(getContext(), "Theme5", Toast.LENGTH_SHORT).show(); + SharedPreferences.Editor editor = getContext().getSharedPreferences("appsettings", MODE_PRIVATE).edit(); + editor.putString("Theme", "PINK_GREEN"); + editor.apply(); + startActivity(getActivity().getIntent()); + getActivity().finish(); + + + } + }); + return root; } @@ -158,7 +205,7 @@ public class EinstellungenFragment extends Fragment { } private void showChangeBackgroundDialog() { - final String[] listItems = {"FARBE","GRADIENT", "GRAFIK", "RESET BACKGROUND"}; + final String[] listItems = {"FARBE", "GRADIENT", "GRAFIK", "RESET BACKGROUND"}; AlertDialog.Builder mBuilder = new AlertDialog.Builder(getContext()); mBuilder.setTitle("CHOOSE BACKGROUND-TYPE"); mBuilder.setSingleChoiceItems(listItems, -5, new DialogInterface.OnClickListener() { @@ -189,7 +236,6 @@ public class EinstellungenFragment extends Fragment { public void onClick(DialogInterface dialog, int which) { - } }).create(); mDialog.getWindow().setBackgroundDrawableResource(R.drawable.button_round); @@ -224,4 +270,7 @@ public class EinstellungenFragment extends Fragment { editor.putString("Language", lang); editor.apply(); } + + + } \ No newline at end of file diff --git a/app/src/main/res/drawable/button_theme_green_yellow.xml b/app/src/main/res/drawable/button_theme_green_yellow.xml new file mode 100644 index 0000000..170c290 --- /dev/null +++ b/app/src/main/res/drawable/button_theme_green_yellow.xml @@ -0,0 +1,39 @@ + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/app/src/main/res/drawable/button_theme_orange_turquoise.xml b/app/src/main/res/drawable/button_theme_orange_turquoise.xml new file mode 100644 index 0000000..44bad14 --- /dev/null +++ b/app/src/main/res/drawable/button_theme_orange_turquoise.xml @@ -0,0 +1,39 @@ + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/app/src/main/res/drawable/button_theme_pink_green.xml b/app/src/main/res/drawable/button_theme_pink_green.xml new file mode 100644 index 0000000..d3f7a15 --- /dev/null +++ b/app/src/main/res/drawable/button_theme_pink_green.xml @@ -0,0 +1,39 @@ + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/app/src/main/res/drawable/button_theme_red_blue.xml b/app/src/main/res/drawable/button_theme_red_blue.xml new file mode 100644 index 0000000..e384d78 --- /dev/null +++ b/app/src/main/res/drawable/button_theme_red_blue.xml @@ -0,0 +1,39 @@ + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/app/src/main/res/drawable/button_theme_yellow_blue.xml b/app/src/main/res/drawable/button_theme_yellow_blue.xml new file mode 100644 index 0000000..40e2140 --- /dev/null +++ b/app/src/main/res/drawable/button_theme_yellow_blue.xml @@ -0,0 +1,39 @@ + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/app/src/main/res/drawable/toolbartop.xml b/app/src/main/res/drawable/toolbartop.xml index 839d98d..3c4792b 100644 --- a/app/src/main/res/drawable/toolbartop.xml +++ b/app/src/main/res/drawable/toolbartop.xml @@ -7,8 +7,8 @@ android:color="#FFFFFF" /> + android:endColor="?attr/colorPrimary" + android:startColor="?attr/colorSecondary" /> + android:theme="@style/Theme.red_blue.AppBarOverlay"> @@ -46,6 +46,6 @@ android:layout_height="?attr/actionBarSize" android:background="?attr/colorPrimary" app:layout_anchorGravity="center" - app:popupTheme="@style/Theme.Teraplex.PopupOverlay" /> + app:popupTheme="@style/Theme.red_blue.PopupOverlay" /> \ No newline at end of file diff --git a/app/src/main/res/layout/app_bar_main.xml b/app/src/main/res/layout/app_bar_main.xml index 02003f5..f03a3ee 100644 --- a/app/src/main/res/layout/app_bar_main.xml +++ b/app/src/main/res/layout/app_bar_main.xml @@ -10,7 +10,7 @@ android:id="@+id/appBarLayout" android:layout_width="match_parent" android:layout_height="wrap_content" - android:theme="@style/Theme.Teraplex.AppBarOverlay"> + android:theme="@style/Theme.red_blue.AppBarOverlay"> @@ -31,6 +31,6 @@ android:layout_height="?attr/actionBarSize" android:background="?attr/colorPrimary" app:layout_anchorGravity="center" - app:popupTheme="@style/Theme.Teraplex.PopupOverlay" /> + app:popupTheme="@style/Theme.red_blue.PopupOverlay" /> \ No newline at end of file diff --git a/app/src/main/res/layout/fragment_einstellungen.xml b/app/src/main/res/layout/fragment_einstellungen.xml index 8a8a897..820a8bf 100644 --- a/app/src/main/res/layout/fragment_einstellungen.xml +++ b/app/src/main/res/layout/fragment_einstellungen.xml @@ -4,10 +4,7 @@ xmlns:app="http://schemas.android.com/apk/res-auto" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" - android:clickable="true" - android:layout_height="match_parent" - tools:context=".ui.Einstellungen.EinstellungenFragment"> - + android:layout_height="match_parent"> + + + + + - + + app:layout_constraintTop_toTopOf="@+id/button_theme_red_blue" /> - + - +