Skip to content

Commit

Permalink
Update theme switch
Browse files Browse the repository at this point in the history
  • Loading branch information
billthefarmer committed Oct 24, 2023
1 parent e14d08a commit 725fa78
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 10 deletions.
17 changes: 12 additions & 5 deletions src/main/java/org/billthefarmer/tuner/SettingsFragment.java
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@

import android.app.ActionBar;
import android.app.Dialog;
import android.content.Intent;
import android.content.SharedPreferences;
import android.graphics.drawable.Drawable;
import android.os.Build;
Expand Down Expand Up @@ -135,8 +136,7 @@ public void onCreate(Bundle savedInstanceState)
preference = (ListPreference) findPreference(Tuner.PREF_TEMPER);
v = Integer.valueOf(preference.getValue());
preference = (ListPreference) findPreference(Tuner.PREF_KEY);
if (v == getActivity().getResources()
.getInteger(R.integer.default_temper))
if (v == getResources().getInteger(R.integer.default_temper))
{
preference.setEnabled(false);
preference.setValueIndex(0);
Expand Down Expand Up @@ -186,8 +186,7 @@ public boolean onPreferenceTreeClick(PreferenceScreen preferenceScreen,
ActionBar actionBar = dialog.getActionBar();
actionBar.setDisplayHomeAsUpEnabled(true);
Toolbar toolbar = dialog.findViewById
(dialog.getContext().getResources().getIdentifier
("action_bar", "id", "android"));
(getResources().getIdentifier("action_bar", "id", "android"));
toolbar.setNavigationOnClickListener((v) ->
{
dialog.dismiss();
Expand Down Expand Up @@ -304,7 +303,15 @@ public void onSharedPreferenceChanged(SharedPreferences preferences,

if (key.equals(Tuner.PREF_THEME))
{
if (Build.VERSION.SDK_INT != Build.VERSION_CODES.M)
if (Build.VERSION.SDK_INT == Build.VERSION_CODES.M)
{
Intent intent = new
Intent(getActivity(), getActivity().getClass());
getActivity().startActivity(intent);
getActivity().finish();
}

else
getActivity().recreate();
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/org/billthefarmer/tuner/Status.java
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ public Status(Context context, AttributeSet attrs)
resources = getResources();

final TypedArray typedArray =
context.obtainStyledAttributes(attrs, R.styleable.Tuner, 0, 0);
context.obtainStyledAttributes(attrs, R.styleable.Tuner);

textColour =
typedArray.getColor(R.styleable.Tuner_TextColour,
Expand Down
23 changes: 20 additions & 3 deletions src/main/java/org/billthefarmer/tuner/Tuner.java
Original file line number Diff line number Diff line change
Expand Up @@ -656,7 +656,14 @@ public boolean onLongClick(View v)
if (++theme > BLACK)
theme = LIGHT;

if (Build.VERSION.SDK_INT != Build.VERSION_CODES.M)
if (Build.VERSION.SDK_INT == Build.VERSION_CODES.M)
{
Intent intent = new Intent(this, getClass());
startActivity(intent);
finish();
}

else
recreate();
break;

Expand Down Expand Up @@ -757,8 +764,18 @@ protected void onResume()
getPreferences();

// Change theme
if (current != theme && Build.VERSION.SDK_INT != Build.VERSION_CODES.M)
recreate();
if (current != theme)
{
if (Build.VERSION.SDK_INT == Build.VERSION_CODES.M)
{
Intent intent = new Intent(this, getClass());
startActivity(intent);
finish();
}

else
recreate();
}

// Load custom temperaments
loadCustomTemperaments();
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/org/billthefarmer/tuner/TunerView.java
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ protected TunerView(Context context, AttributeSet attrs)
resources = getResources();

final TypedArray typedArray =
context.obtainStyledAttributes(attrs, R.styleable.Tuner, 0, 0);
context.obtainStyledAttributes(attrs, R.styleable.Tuner);

textColour =
typedArray.getColor(R.styleable.Tuner_TextColour,
Expand Down

0 comments on commit 725fa78

Please sign in to comment.