diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml
index 1f0e8cb..2d40793 100644
--- a/app/src/main/AndroidManifest.xml
+++ b/app/src/main/AndroidManifest.xml
@@ -37,7 +37,7 @@
+ android:theme="@style/AppTheme.NoActionBar" />
{
+ AppCompatDelegate.setDefaultNightMode(AppCompatDelegate.MODE_NIGHT_YES)
+ }
+
+ "light" -> {
+ AppCompatDelegate.setDefaultNightMode(AppCompatDelegate.MODE_NIGHT_NO)
+ }
+
+ else -> {
+ AppCompatDelegate.setDefaultNightMode(AppCompatDelegate.MODE_NIGHT_FOLLOW_SYSTEM)
+ }
+ }
}
override val workManagerConfiguration = Configuration.Builder().setMinimumLoggingLevel(Log.INFO).build()
diff --git a/app/src/main/java/org/secuso/privacyfriendly2048/activities/Element.java b/app/src/main/java/org/secuso/privacyfriendly2048/activities/Element.java
index 527c2fa..ed11fe2 100644
--- a/app/src/main/java/org/secuso/privacyfriendly2048/activities/Element.java
+++ b/app/src/main/java/org/secuso/privacyfriendly2048/activities/Element.java
@@ -19,16 +19,16 @@
package org.secuso.privacyfriendly2048.activities;
+import static org.secuso.privacyfriendly2048.helpers.ThemeResolverKt.GetColorInt;
+import static org.secuso.privacyfriendly2048.helpers.ThemeResolverKt.GetColorRes;
+
import android.content.Context;
import android.graphics.drawable.ColorDrawable;
import android.graphics.drawable.Drawable;
import android.graphics.drawable.GradientDrawable;
import android.graphics.drawable.ShapeDrawable;
-import android.preference.PreferenceManager;
import android.view.View;
-import androidx.core.content.ContextCompat;
-
import org.secuso.privacyfriendly2048.R;
/**
@@ -61,11 +61,7 @@ public Element(Context c) {
setAllCaps(false);
setTextSize(textSize);
setBackgroundResource(R.drawable.game_brick);
- if (PreferenceManager.getDefaultSharedPreferences(context).getString("pref_color", "1").equals("1"))
- setColor(context.getResources().getColor(R.color.button_empty));
- else
- setColor(context.getResources().getColor(R.color.button_empty_2));
-
+ setColor(GetColorRes(context, R.attr.buttonEmpty));
}
public void drawItem() {
@@ -80,148 +76,75 @@ public void drawItem() {
setVisibility(View.VISIBLE);
}
- if (PreferenceManager.getDefaultSharedPreferences(context).getString("pref_color", "1").equals("1")) {
- switch (number) {
- case 0:
- setColor(ContextCompat.getColor(context, R.color.button_empty));
- setTextColor(ContextCompat.getColor(context, R.color.black));
- break;
- case 2:
- setColor(ContextCompat.getColor(context, R.color.button2));
- setTextColor(ContextCompat.getColor(context, R.color.black));
- break;
- case 4:
- setColor(ContextCompat.getColor(context, R.color.button4));
- setTextColor(ContextCompat.getColor(context, R.color.black));
- break;
- case 8:
- setColor(ContextCompat.getColor(context, R.color.button8));
- setTextColor(ContextCompat.getColor(context, R.color.white));
- break;
- case 16:
- setColor(ContextCompat.getColor(context, R.color.button16));
- setTextColor(ContextCompat.getColor(context, R.color.white));
- break;
- case 32:
- setColor(ContextCompat.getColor(context, R.color.button32));
- setTextColor(ContextCompat.getColor(context, R.color.white));
- break;
- case 64:
- setColor(ContextCompat.getColor(context, R.color.button64));
- setTextColor(ContextCompat.getColor(context, R.color.white));
- break;
- case 128:
- setColor(ContextCompat.getColor(context, R.color.button128));
- setTextColor(ContextCompat.getColor(context, R.color.white));
- break;
- case 256:
- setColor(ContextCompat.getColor(context, R.color.button256));
- setTextColor(ContextCompat.getColor(context, R.color.white));
- break;
- case 512:
- setColor(ContextCompat.getColor(context, R.color.button512));
- setTextColor(ContextCompat.getColor(context, R.color.white));
- break;
- case 1024:
- setColor(ContextCompat.getColor(context, R.color.button1024));
- setTextColor(ContextCompat.getColor(context, R.color.white));
- break;
- case 2048:
- setColor(ContextCompat.getColor(context, R.color.button2048));
- setTextColor(ContextCompat.getColor(context, R.color.white));
- break;
- case 4096:
- setColor(ContextCompat.getColor(context, R.color.button4096));
- setTextColor(ContextCompat.getColor(context, R.color.black));
- break;
- case 8192:
- setColor(ContextCompat.getColor(context, R.color.button8192));
- setTextColor(ContextCompat.getColor(context, R.color.black));
- break;
- case 16384:
- setColor(ContextCompat.getColor(context, R.color.button16384));
- setTextColor(ContextCompat.getColor(context, R.color.white));
- textSize = textSize * 0.8f;
- setTextSize(textSize);
- break;
- case 32768:
- setColor(ContextCompat.getColor(context, R.color.button32768));
- setTextColor(ContextCompat.getColor(context, R.color.white));
- textSize = textSize * 0.8f;
- setTextSize(textSize);
- break;
- }
- } else {
- switch (number) {
- case 0:
- setColor(R.color.button_empty_2);
- setTextColor(ContextCompat.getColor(context, R.color.black));
- break;
- case 2:
- setColor(ContextCompat.getColor(context, R.color.button2_2));
- setTextColor(ContextCompat.getColor(context, R.color.black));
- break;
- case 4:
- setColor(ContextCompat.getColor(context, R.color.button4_2));
- setTextColor(ContextCompat.getColor(context, R.color.black));
- break;
- case 8:
- setColor(ContextCompat.getColor(context, R.color.button8_2));
- setTextColor(ContextCompat.getColor(context, R.color.white));
- break;
- case 16:
- setColor(ContextCompat.getColor(context, R.color.button16_2));
- setTextColor(ContextCompat.getColor(context, R.color.white));
- break;
- case 32:
- setColor(ContextCompat.getColor(context, R.color.button32_2));
- setTextColor(ContextCompat.getColor(context, R.color.white));
- break;
- case 64:
- setColor(ContextCompat.getColor(context, R.color.button64_2));
- setTextColor(ContextCompat.getColor(context, R.color.white));
- break;
- case 128:
- setColor(ContextCompat.getColor(context, R.color.button128_2));
- setTextColor(ContextCompat.getColor(context, R.color.white));
- break;
- case 256:
- setColor(ContextCompat.getColor(context, R.color.button256_2));
- setTextColor(ContextCompat.getColor(context, R.color.white));
- break;
- case 512:
- setColor(ContextCompat.getColor(context, R.color.button512_2));
- setTextColor(ContextCompat.getColor(context, R.color.white));
- break;
- case 1024:
- setColor(ContextCompat.getColor(context, R.color.button1024_2));
- setTextColor(ContextCompat.getColor(context, R.color.white));
- break;
- case 2048:
- setColor(ContextCompat.getColor(context, R.color.button2048_2));
- setTextColor(ContextCompat.getColor(context, R.color.white));
- break;
- case 4096:
- setColor(ContextCompat.getColor(context, R.color.button4096_2));
- setTextColor(ContextCompat.getColor(context, R.color.white));
- break;
- case 8192:
- setColor(ContextCompat.getColor(context, R.color.button8192_2));
- setTextColor(ContextCompat.getColor(context, R.color.white));
- break;
- case 16384:
- setColor(ContextCompat.getColor(context, R.color.button16384_2));
- setTextColor(ContextCompat.getColor(context, R.color.white));
- textSize = textSize * 0.8f;
- setTextSize(textSize);
- break;
- case 32768:
- setColor(ContextCompat.getColor(context, R.color.button32768_2));
- setTextColor(ContextCompat.getColor(context, R.color.white));
- textSize = textSize * 0.8f;
- setTextSize(textSize);
- break;
- }
+ switch (number) {
+ case 0:
+ setColor(GetColorRes(context, R.attr.buttonEmpty));
+ setTextColor(GetColorInt(context, R.attr.buttonEmptyText));
+ break;
+ case 2:
+ setColor(GetColorRes(context, R.attr.button2));
+ setTextColor(GetColorInt(context, R.attr.button2Text));
+ break;
+ case 4:
+ setColor(GetColorRes(context, R.attr.button4));
+ setTextColor(GetColorInt(context, R.attr.button4Text));
+ break;
+ case 8:
+ setColor(GetColorRes(context, R.attr.button8));
+ setTextColor(GetColorInt(context, R.attr.button8Text));
+ break;
+ case 16:
+ setColor(GetColorRes(context, R.attr.button16));
+ setTextColor(GetColorInt(context, R.attr.button16Text));
+ break;
+ case 32:
+ setColor(GetColorRes(context, R.attr.button32));
+ setTextColor(GetColorInt(context, R.attr.button32Text));
+ break;
+ case 64:
+ setColor(GetColorRes(context, R.attr.button64));
+ setTextColor(GetColorInt(context, R.attr.button64Text));
+ break;
+ case 128:
+ setColor(GetColorRes(context, R.attr.button128));
+ setTextColor(GetColorInt(context, R.attr.button128Text));
+ break;
+ case 256:
+ setColor(GetColorRes(context, R.attr.button256));
+ setTextColor(GetColorInt(context, R.attr.button256Text));
+ break;
+ case 512:
+ setColor(GetColorRes(context, R.attr.button512));
+ setTextColor(GetColorInt(context, R.attr.button512Text));
+ break;
+ case 1024:
+ setColor(GetColorRes(context, R.attr.button1024));
+ setTextColor(GetColorInt(context, R.attr.button1024Text));
+ break;
+ case 2048:
+ setColor(GetColorRes(context, R.attr.button2048));
+ setTextColor(GetColorInt(context, R.attr.button2048Text));
+ break;
+ case 4096:
+ setColor(GetColorRes(context, R.attr.button4096));
+ setTextColor(GetColorInt(context, R.attr.button4096Text));
+ break;
+ case 8192:
+ setColor(GetColorRes(context, R.attr.button8192));
+ setTextColor(GetColorInt(context, R.attr.button8192Text));
+ break;
+ case 16384:
+ setColor(GetColorRes(context, R.attr.button16384));
+ setTextColor(GetColorInt(context, R.attr.button16384Text));
+ textSize = textSize * 0.8f;
+ setTextSize(textSize);
+ break;
+ case 32768:
+ setColor(GetColorRes(context, R.attr.button32768));
+ setTextColor(GetColorInt(context, R.attr.button32768Text));
+ textSize = textSize * 0.8f;
+ setTextSize(textSize);
+ break;
}
}
diff --git a/app/src/main/java/org/secuso/privacyfriendly2048/activities/GameActivity.java b/app/src/main/java/org/secuso/privacyfriendly2048/activities/GameActivity.java
index 1e8ac16..caa3855 100644
--- a/app/src/main/java/org/secuso/privacyfriendly2048/activities/GameActivity.java
+++ b/app/src/main/java/org/secuso/privacyfriendly2048/activities/GameActivity.java
@@ -20,6 +20,7 @@
import android.animation.Animator;
import android.animation.AnimatorListenerAdapter;
+import android.app.Activity;
import android.app.AlertDialog;
import android.content.DialogInterface;
import android.content.Intent;
@@ -117,6 +118,8 @@ public static long record = 0;
public static long startingTime;
public int highestNumber;
+ private Activity myActivity;
+
@Override
public boolean onPrepareOptionsMenu(Menu menu) {
@@ -139,6 +142,7 @@ public void onPause() {
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
+ myActivity = this;
saveState = true;
if (savedInstanceState == null) {
@@ -411,7 +415,7 @@ public boolean onSwipeTop() {
Element[][] temp = deepCopy(elements);
int temp_points = points;
moved = false;
- Element s = new Element(getApplicationContext());
+ Element s = new Element(myActivity);
for (int i = 0; i < elements.length; i++) {
s.number = elements[0][i].number;
@@ -491,7 +495,7 @@ public boolean onSwipeRight() {
Element[][] temp = deepCopy(elements);
int temp_points = points;
moved = false;
- Element s = new Element(getApplicationContext());
+ Element s = new Element(myActivity);
for (int i = 0; i < elements.length; i++) {
s.number = elements[i][elements[i].length - 1].number;
s.posX = i;
@@ -574,7 +578,7 @@ public boolean onSwipeLeft() {
Element[][] temp = deepCopy(elements);
int temp_points = points;
moved = false;
- Element s = new Element(getApplicationContext());
+ Element s = new Element(myActivity);
for (int i = 0; i < elements.length; i++) {
s.number = elements[i][0].number;
s.posX = i;
@@ -655,7 +659,7 @@ public boolean onSwipeBottom() {
Element[][] temp = deepCopy(elements);
int temp_points = points;
moved = false;
- Element s = new Element(getApplicationContext());
+ Element s = new Element(myActivity);
for (int i = 0; i < elements.length; i++) {
s.number = elements[elements[i].length - 1][i].number;
s.posX = elements[i].length - 1;
diff --git a/app/src/main/java/org/secuso/privacyfriendly2048/activities/SettingsActivity.java b/app/src/main/java/org/secuso/privacyfriendly2048/activities/SettingsActivity.java
index f443bb5..81aed3d 100644
--- a/app/src/main/java/org/secuso/privacyfriendly2048/activities/SettingsActivity.java
+++ b/app/src/main/java/org/secuso/privacyfriendly2048/activities/SettingsActivity.java
@@ -23,6 +23,7 @@
import android.annotation.TargetApi;
import android.content.Context;
import android.content.Intent;
+import android.content.SharedPreferences;
import android.content.res.Configuration;
import android.os.Build;
import android.os.Bundle;
@@ -32,6 +33,8 @@
import android.preference.PreferenceManager;
import android.view.MenuItem;
+import androidx.appcompat.app.AppCompatDelegate;
+
import org.secuso.privacyfriendly2048.R;
import org.secuso.privacyfriendly2048.activities.helper.BaseActivity;
@@ -43,7 +46,7 @@
* @author Julian Wadephul and Saskia Jacob
* @version 20180910
*/
-public class SettingsActivity extends BaseActivity {
+public class SettingsActivity extends BaseActivity implements SharedPreferences.OnSharedPreferenceChangeListener {
/**
* A preference value change listener that updates the preference's summary
* to reflect its new value.
@@ -107,6 +110,7 @@ private static void bindPreferenceSummaryToValue(Preference preference) {
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
+ super.mSharedPreferences.registerOnSharedPreferenceChangeListener(this);
setContentView(R.layout.activity_settings);
//setupActionBar();
@@ -114,6 +118,20 @@ protected void onCreate(Bundle savedInstanceState) {
overridePendingTransition(0, 0);
}
+ @Override
+ public void onSharedPreferenceChanged(SharedPreferences sharedPreferences, String key) {
+ if (!key.equals("currentTheme")) return;
+
+ String newValue = sharedPreferences.getString("currentTheme", "system");
+ if (newValue.equals("dark")) {
+ AppCompatDelegate.setDefaultNightMode(AppCompatDelegate.MODE_NIGHT_YES);
+ } else if (newValue.equals("light")) {
+ AppCompatDelegate.setDefaultNightMode(AppCompatDelegate.MODE_NIGHT_NO);
+ } else {
+ AppCompatDelegate.setDefaultNightMode(AppCompatDelegate.MODE_NIGHT_FOLLOW_SYSTEM);
+ }
+ }
+
@Override
protected int getNavigationDrawerID() {
return R.id.nav_settings;
diff --git a/app/src/main/java/org/secuso/privacyfriendly2048/activities/TutorialActivity.java b/app/src/main/java/org/secuso/privacyfriendly2048/activities/TutorialActivity.java
index 4d7dc6a..d5fdb9f 100644
--- a/app/src/main/java/org/secuso/privacyfriendly2048/activities/TutorialActivity.java
+++ b/app/src/main/java/org/secuso/privacyfriendly2048/activities/TutorialActivity.java
@@ -75,7 +75,6 @@ public class TutorialActivity extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
-
setContentView(R.layout.activity_tutorial);
// Making notification bar transparent
diff --git a/app/src/main/java/org/secuso/privacyfriendly2048/helpers/ThemeResolver.kt b/app/src/main/java/org/secuso/privacyfriendly2048/helpers/ThemeResolver.kt
new file mode 100644
index 0000000..1f9550e
--- /dev/null
+++ b/app/src/main/java/org/secuso/privacyfriendly2048/helpers/ThemeResolver.kt
@@ -0,0 +1,31 @@
+package org.secuso.privacyfriendly2048.helpers
+
+import android.content.Context
+import android.preference.PreferenceManager
+import androidx.annotation.ColorInt
+import androidx.annotation.ColorRes
+import org.secuso.privacyfriendly2048.R
+
+@ColorRes
+fun GetColorRes(ctx: Context, res: Int): Int {
+ val prefs = PreferenceManager.getDefaultSharedPreferences(ctx)
+
+ val style: Int
+
+ when (prefs.getString("pref_color", "1")) {
+ "2" -> style = R.style.ThemeOverlay_ColorSchemeOriginal
+ else -> style = R.style.ThemeOverlay_ColorSchemeDefault
+ }
+
+ val ta = ctx.obtainStyledAttributes(style, intArrayOf(res))
+ val resolved = ta.getInt(0, 0)
+ ta.recycle()
+
+ return resolved
+}
+
+@ColorInt
+fun GetColorInt(ctx: Context, res: Int): Int {
+ // TODO: Not sure why this works, investigate
+ return GetColorRes(ctx, res).toInt()
+}
\ No newline at end of file
diff --git a/app/src/main/res/layout/activity_about.xml b/app/src/main/res/layout/activity_about.xml
index 69ce433..edf8cfd 100644
--- a/app/src/main/res/layout/activity_about.xml
+++ b/app/src/main/res/layout/activity_about.xml
@@ -5,13 +5,12 @@
android:id="@+id/main_content"
android:layout_width="match_parent"
android:layout_height="match_parent"
- android:background="#FFFFFF">
+ >
+ >
-
-
- - Standard
- - Original
-
-
- - 1
- - 2
-
-
\ No newline at end of file
diff --git a/app/src/main/res/values-de/strings.xml b/app/src/main/res/values-de/strings.xml
index 15419d6..5a4a9e6 100644
--- a/app/src/main/res/values-de/strings.xml
+++ b/app/src/main/res/values-de/strings.xml
@@ -56,6 +56,11 @@
Animationen aktivieren
Displaysperre aktivieren
Auswahl Farbschema
+ System
+ Hell
+ Dunkel
+ Standard
+ Original
diff --git a/app/src/main/res/values-night/styles.xml b/app/src/main/res/values-night/styles.xml
new file mode 100644
index 0000000..b414be3
--- /dev/null
+++ b/app/src/main/res/values-night/styles.xml
@@ -0,0 +1,16 @@
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/app/src/main/res/values/arrays.xml b/app/src/main/res/values/arrays.xml
index 1601d06..222efe3 100644
--- a/app/src/main/res/values/arrays.xml
+++ b/app/src/main/res/values/arrays.xml
@@ -1,11 +1,22 @@
- - Default
- - Original
+ - @string/settings_color_scheme_default
+ - @string/settings_color_scheme_original
- 1
- 2
+
+
+ - @string/settings_color_system
+ - @string/settings_color_light
+ - @string/settings_color_dark
+
+
+ - system
+ - light
+ - dark
+
\ No newline at end of file
diff --git a/app/src/main/res/values/attrs.xml b/app/src/main/res/values/attrs.xml
new file mode 100644
index 0000000..b5ba2c6
--- /dev/null
+++ b/app/src/main/res/values/attrs.xml
@@ -0,0 +1,36 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml
index d649ccd..7fa3230 100644
--- a/app/src/main/res/values/strings.xml
+++ b/app/src/main/res/values/strings.xml
@@ -62,7 +62,11 @@
Activate Animation
Activate Screen Lock
Select Color Scheme
-
+ System
+ Light
+ Dark
+ Default
+ Original
Start New Game
diff --git a/app/src/main/res/values/styles.xml b/app/src/main/res/values/styles.xml
index 393bb5b..abbc255 100644
--- a/app/src/main/res/values/styles.xml
+++ b/app/src/main/res/values/styles.xml
@@ -1,25 +1,102 @@
+
+
-
+
+
+
+
-
-
+
diff --git a/app/src/main/res/xml/pref_general.xml b/app/src/main/res/xml/pref_general.xml
index 7f1ae95..fd3054b 100644
--- a/app/src/main/res/xml/pref_general.xml
+++ b/app/src/main/res/xml/pref_general.xml
@@ -1,5 +1,14 @@
+
+