Skip to content

Commit

Permalink
Add system theme
Browse files Browse the repository at this point in the history
  • Loading branch information
billthefarmer committed May 21, 2023
1 parent 418b78d commit c4dd91f
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 5 deletions.
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ android {
}

lintOptions {
disable 'IconDensities', 'ClickableViewAccessibility',
disable 'IconDensities', 'ClickableViewAccessibility', 'AndroidGradlePluginVersion',
'CustomViewStyleable', 'TypographyFractions', 'OldTargetApi',
'NonConstantResourceId', 'ExpiredTargetSdkVersion', 'MissingInflatedId'
// abortOnError false
Expand Down
18 changes: 18 additions & 0 deletions src/main/java/org/billthefarmer/tuner/Settings.java
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
import android.app.ActionBar;
import android.app.Activity;
import android.content.SharedPreferences;
import android.content.res.Configuration;
import android.os.Bundle;
import android.preference.PreferenceManager;
import android.view.MenuItem;
Expand All @@ -46,6 +47,10 @@ protected void onCreate(Bundle savedInstanceState)

int theme = Integer.parseInt(preferences.getString(Tuner.PREF_THEME,
"0"));

Configuration config = getResources().getConfiguration();
int night = config.uiMode & Configuration.UI_MODE_NIGHT_MASK;

switch (theme)
{
case Tuner.LIGHT:
Expand All @@ -56,6 +61,19 @@ protected void onCreate(Bundle savedInstanceState)
setTheme(R.style.AppDarkTheme);
break;

case Tuner.SYSTEM:
switch (night)
{
case Configuration.UI_MODE_NIGHT_NO:
setTheme(R.style.AppTheme);
break;

case Configuration.UI_MODE_NIGHT_YES:
setTheme(R.style.AppDarkTheme);
break;
}
break;

case Tuner.WHITE:
setTheme(R.style.AppWhiteTheme);
break;
Expand Down
25 changes: 21 additions & 4 deletions src/main/java/org/billthefarmer/tuner/Tuner.java
Original file line number Diff line number Diff line change
Expand Up @@ -276,10 +276,11 @@ public class Tuner extends Activity
1.585609487, 1.676104963, 1.779786472, 1.881364210},
};

public final static int LIGHT = 0;
public final static int DARK = 1;
public final static int WHITE = 2;
public final static int BLACK = 3;
public final static int LIGHT = 0;
public final static int DARK = 1;
public final static int SYSTEM = 2;
public final static int WHITE = 3;
public final static int BLACK = 4;

private double temperaments[][];
private String names[];
Expand Down Expand Up @@ -308,6 +309,9 @@ protected void onCreate(Bundle savedInstanceState)
// Get preferences
getPreferences();

Configuration config = getResources().getConfiguration();
int night = config.uiMode & Configuration.UI_MODE_NIGHT_MASK;

switch (theme)
{
case LIGHT:
Expand All @@ -318,6 +322,19 @@ protected void onCreate(Bundle savedInstanceState)
setTheme(R.style.AppDarkTheme);
break;

case SYSTEM:
switch (night)
{
case Configuration.UI_MODE_NIGHT_NO:
setTheme(R.style.AppTheme);
break;

case Configuration.UI_MODE_NIGHT_YES:
setTheme(R.style.AppDarkTheme);
break;
}
break;

case WHITE:
setTheme(R.style.AppWhiteTheme);
break;
Expand Down
2 changes: 2 additions & 0 deletions src/main/res/values/arrays.xml
Original file line number Diff line number Diff line change
Expand Up @@ -188,6 +188,7 @@
<string-array name="pref_theme_entries">
<item>Light</item>
<item>Dark</item>
<item>System</item>
<item>White</item>
<item>Black</item>
</string-array>
Expand All @@ -196,6 +197,7 @@
<item>1</item>
<item>2</item>
<item>3</item>
<item>4</item>
</string-array>

<integer-array name="sample_rates">
Expand Down

0 comments on commit c4dd91f

Please sign in to comment.