Skip to content

Commit

Permalink
Merge pull request #26 from deifyed/feature/master/darkmode
Browse files Browse the repository at this point in the history
#16 Add dark mode
  • Loading branch information
udenr authored Sep 3, 2024
2 parents bb1d202 + 94e1f54 commit 5f90011
Show file tree
Hide file tree
Showing 18 changed files with 319 additions and 182 deletions.
2 changes: 1 addition & 1 deletion app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
<activity
android:name=".activities.MainActivity"
android:label="@string/app_name"
android:theme="@style/AppTheme.NoActionBar"></activity>
android:theme="@style/AppTheme.NoActionBar" />
<activity
android:name=".activities.AboutActivity"
android:label="@string/about"
Expand Down
19 changes: 18 additions & 1 deletion app/src/main/java/org/secuso/privacyfriendly2048/PF2048.kt
Original file line number Diff line number Diff line change
Expand Up @@ -17,17 +17,34 @@
package org.secuso.privacyfriendly2048

import android.app.Application
import android.preference.PreferenceManager
import android.util.Log
import androidx.appcompat.app.AppCompatDelegate
import androidx.work.Configuration
import org.secuso.privacyfriendly2048.backup.BackupCreator
import org.secuso.privacyfriendly2048.backup.BackupRestorer
import org.secuso.privacyfriendlybackup.api.pfa.BackupManager

class PF2048 : Application(), Configuration.Provider {
override fun onCreate() {
super.onCreate()
BackupManager.backupCreator = BackupCreator()
BackupManager.backupRestorer = BackupRestorer()
super.onCreate()

when (PreferenceManager.getDefaultSharedPreferences(applicationContext)
.getString("currentTheme", "system")) {
"dark" -> {
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()
Expand Down
223 changes: 73 additions & 150 deletions app/src/main/java/org/secuso/privacyfriendly2048/activities/Element.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;

/**
Expand Down Expand Up @@ -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() {
Expand All @@ -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;
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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) {
Expand All @@ -139,6 +142,7 @@ public void onPause() {
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);

myActivity = this;
saveState = true;

if (savedInstanceState == null) {
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down
Loading

0 comments on commit 5f90011

Please sign in to comment.