mirror of
https://github.com/moparisthebest/k-9
synced 2024-11-23 18:02:15 -05:00
Convert theme setting value to an enum.
This commit is contained in:
parent
bd154c4c0f
commit
8f3e61feab
@ -44,10 +44,6 @@ import com.fsck.k9.service.ShutdownReceiver;
|
|||||||
import com.fsck.k9.service.StorageGoneReceiver;
|
import com.fsck.k9.service.StorageGoneReceiver;
|
||||||
|
|
||||||
public class K9 extends Application {
|
public class K9 extends Application {
|
||||||
public static final int THEME_LIGHT = 0;
|
|
||||||
public static final int THEME_DARK = 1;
|
|
||||||
public static final int THEME_GLOBAL = 2;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Components that are interested in knowing when the K9 instance is
|
* Components that are interested in knowing when the K9 instance is
|
||||||
* available and ready (Android invokes Application.onCreate() after other
|
* available and ready (Android invokes Application.onCreate() after other
|
||||||
@ -99,9 +95,9 @@ public class K9 extends Application {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private static String language = "";
|
private static String language = "";
|
||||||
private static int theme = THEME_LIGHT;
|
private static Theme theme = Theme.LIGHT;
|
||||||
private static int messageViewTheme = THEME_GLOBAL;
|
private static Theme messageViewTheme = Theme.USE_GLOBAL;
|
||||||
private static int composerTheme = THEME_GLOBAL;
|
private static Theme composerTheme = Theme.USE_GLOBAL;
|
||||||
private static boolean useFixedMessageTheme = true;
|
private static boolean useFixedMessageTheme = true;
|
||||||
|
|
||||||
private static final FontSizes fontSizes = new FontSizes();
|
private static final FontSizes fontSizes = new FontSizes();
|
||||||
@ -525,9 +521,9 @@ public class K9 extends Application {
|
|||||||
editor.putBoolean("batchButtonsUnselect", mBatchButtonsUnselect);
|
editor.putBoolean("batchButtonsUnselect", mBatchButtonsUnselect);
|
||||||
|
|
||||||
editor.putString("language", language);
|
editor.putString("language", language);
|
||||||
editor.putInt("theme", theme);
|
editor.putInt("theme", theme.ordinal());
|
||||||
editor.putInt("messageViewTheme", messageViewTheme);
|
editor.putInt("messageViewTheme", messageViewTheme.ordinal());
|
||||||
editor.putInt("messageComposeTheme", composerTheme);
|
editor.putInt("messageComposeTheme", composerTheme.ordinal());
|
||||||
editor.putBoolean("fixedMessageViewTheme", useFixedMessageTheme);
|
editor.putBoolean("fixedMessageViewTheme", useFixedMessageTheme);
|
||||||
editor.putBoolean("useGalleryBugWorkaround", useGalleryBugWorkaround);
|
editor.putBoolean("useGalleryBugWorkaround", useGalleryBugWorkaround);
|
||||||
|
|
||||||
@ -771,20 +767,20 @@ public class K9 extends Application {
|
|||||||
|
|
||||||
K9.setK9Language(sprefs.getString("language", ""));
|
K9.setK9Language(sprefs.getString("language", ""));
|
||||||
|
|
||||||
int theme = sprefs.getInt("theme", THEME_LIGHT);
|
int themeValue = sprefs.getInt("theme", Theme.LIGHT.ordinal());
|
||||||
|
|
||||||
// We used to save the resource ID of the theme. So convert that to the new format if
|
// We used to save the resource ID of the theme. So convert that to the new format if
|
||||||
// necessary.
|
// necessary.
|
||||||
if (theme == THEME_DARK || theme == android.R.style.Theme) {
|
if (themeValue == Theme.DARK.ordinal() || themeValue == android.R.style.Theme) {
|
||||||
theme = THEME_DARK;
|
K9.setK9Theme(Theme.DARK);
|
||||||
} else {
|
} else {
|
||||||
theme = THEME_LIGHT;
|
K9.setK9Theme(Theme.LIGHT);
|
||||||
}
|
}
|
||||||
K9.setK9Theme(theme);
|
|
||||||
|
|
||||||
K9.setK9MessageViewThemeSetting(sprefs.getInt("messageViewTheme", THEME_GLOBAL));
|
themeValue = sprefs.getInt("messageViewTheme", Theme.USE_GLOBAL.ordinal());
|
||||||
|
K9.setK9MessageViewThemeSetting(Theme.values()[themeValue]);
|
||||||
|
themeValue = sprefs.getInt("messageComposeTheme", Theme.USE_GLOBAL.ordinal());
|
||||||
|
K9.setK9ComposerThemeSetting(Theme.values()[themeValue]);
|
||||||
K9.setUseFixedMessageViewTheme(sprefs.getBoolean("fixedMessageViewTheme", true));
|
K9.setUseFixedMessageViewTheme(sprefs.getBoolean("fixedMessageViewTheme", true));
|
||||||
K9.setK9ComposerThemeSetting(sprefs.getInt("messageComposeTheme", THEME_GLOBAL));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void maybeSetupStrictMode() {
|
private void maybeSetupStrictMode() {
|
||||||
@ -843,40 +839,47 @@ public class K9 extends Application {
|
|||||||
language = nlanguage;
|
language = nlanguage;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static int getK9ThemeResourceId(int themeId) {
|
public enum Theme {
|
||||||
return (themeId == THEME_LIGHT) ? R.style.Theme_K9_Light : R.style.Theme_K9_Dark;
|
LIGHT,
|
||||||
|
DARK,
|
||||||
|
USE_GLOBAL
|
||||||
|
}
|
||||||
|
|
||||||
|
public static int getK9ThemeResourceId(Theme themeId) {
|
||||||
|
return (themeId == Theme.LIGHT) ? R.style.Theme_K9_Light : R.style.Theme_K9_Dark;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static int getK9ThemeResourceId() {
|
public static int getK9ThemeResourceId() {
|
||||||
return getK9ThemeResourceId(theme);
|
return getK9ThemeResourceId(theme);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static int getK9MessageViewTheme() {
|
public static Theme getK9MessageViewTheme() {
|
||||||
return messageViewTheme == THEME_GLOBAL ? theme : messageViewTheme;
|
return messageViewTheme == Theme.USE_GLOBAL ? theme : messageViewTheme;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static int getK9MessageViewThemeSetting() {
|
public static Theme getK9MessageViewThemeSetting() {
|
||||||
return messageViewTheme;
|
return messageViewTheme;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static int getK9ComposerTheme() {
|
public static Theme getK9ComposerTheme() {
|
||||||
return composerTheme == THEME_GLOBAL ? theme : composerTheme;
|
return composerTheme == Theme.USE_GLOBAL ? theme : composerTheme;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static int getK9ComposerThemeSetting() {
|
public static Theme getK9ComposerThemeSetting() {
|
||||||
return composerTheme;
|
return composerTheme;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static int getK9Theme() {
|
public static Theme getK9Theme() {
|
||||||
return theme;
|
return theme;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void setK9Theme(int ntheme) {
|
public static void setK9Theme(Theme ntheme) {
|
||||||
assert ntheme != THEME_GLOBAL;
|
if (ntheme != Theme.USE_GLOBAL) {
|
||||||
theme = ntheme;
|
theme = ntheme;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public static void setK9MessageViewThemeSetting(int nMessageViewTheme) {
|
public static void setK9MessageViewThemeSetting(Theme nMessageViewTheme) {
|
||||||
messageViewTheme = nMessageViewTheme;
|
messageViewTheme = nMessageViewTheme;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -884,13 +887,13 @@ public class K9 extends Application {
|
|||||||
return useFixedMessageTheme;
|
return useFixedMessageTheme;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void setK9ComposerThemeSetting(int compTheme) {
|
public static void setK9ComposerThemeSetting(Theme compTheme) {
|
||||||
composerTheme = compTheme;
|
composerTheme = compTheme;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void setUseFixedMessageViewTheme(boolean useFixed) {
|
public static void setUseFixedMessageViewTheme(boolean useFixed) {
|
||||||
useFixedMessageTheme = useFixed;
|
useFixedMessageTheme = useFixed;
|
||||||
if (!useFixedMessageTheme && messageViewTheme == THEME_GLOBAL) {
|
if (!useFixedMessageTheme && messageViewTheme == Theme.USE_GLOBAL) {
|
||||||
messageViewTheme = theme;
|
messageViewTheme = theme;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -18,7 +18,7 @@ public class K9PreferenceActivity extends SherlockPreferenceActivity {
|
|||||||
// There's a display bug in all supported Android versions before 4.0 (SDK 14) which
|
// There's a display bug in all supported Android versions before 4.0 (SDK 14) which
|
||||||
// causes PreferenceScreens to have a black background.
|
// causes PreferenceScreens to have a black background.
|
||||||
// http://code.google.com/p/android/issues/detail?id=4611
|
// http://code.google.com/p/android/issues/detail?id=4611
|
||||||
setTheme(K9.getK9ThemeResourceId(K9.THEME_DARK));
|
setTheme(K9.getK9ThemeResourceId(K9.Theme.DARK));
|
||||||
} else {
|
} else {
|
||||||
setTheme(K9.getK9ThemeResourceId());
|
setTheme(K9.getK9ThemeResourceId());
|
||||||
}
|
}
|
||||||
|
@ -554,7 +554,7 @@ public class MessageCompose extends K9Activity implements OnClickListener {
|
|||||||
mMessageContentView = (EditText)findViewById(R.id.message_content);
|
mMessageContentView = (EditText)findViewById(R.id.message_content);
|
||||||
mMessageContentView.getInputExtras(true).putBoolean("allowEmoji", true);
|
mMessageContentView.getInputExtras(true).putBoolean("allowEmoji", true);
|
||||||
|
|
||||||
if (K9.getK9ComposerThemeSetting() != K9.THEME_GLOBAL) {
|
if (K9.getK9ComposerThemeSetting() != K9.Theme.USE_GLOBAL) {
|
||||||
ContextThemeWrapper wrapper = new ContextThemeWrapper(this,
|
ContextThemeWrapper wrapper = new ContextThemeWrapper(this,
|
||||||
K9.getK9ThemeResourceId(K9.getK9ComposerTheme()));
|
K9.getK9ThemeResourceId(K9.getK9ComposerTheme()));
|
||||||
TypedValue outValue = new TypedValue();
|
TypedValue outValue = new TypedValue();
|
||||||
@ -2381,7 +2381,7 @@ public class MessageCompose extends K9Activity implements OnClickListener {
|
|||||||
.create();
|
.create();
|
||||||
case DIALOG_CHOOSE_IDENTITY:
|
case DIALOG_CHOOSE_IDENTITY:
|
||||||
Context context = new ContextThemeWrapper(this,
|
Context context = new ContextThemeWrapper(this,
|
||||||
(K9.getK9Theme() == K9.THEME_LIGHT) ?
|
(K9.getK9Theme() == K9.Theme.LIGHT) ?
|
||||||
R.style.Theme_K9_Dialog_Light :
|
R.style.Theme_K9_Dialog_Light :
|
||||||
R.style.Theme_K9_Dialog_Dark);
|
R.style.Theme_K9_Dialog_Dark);
|
||||||
Builder builder = new AlertDialog.Builder(context);
|
Builder builder = new AlertDialog.Builder(context);
|
||||||
|
@ -961,7 +961,7 @@ public class MessageList extends K9FragmentActivity implements MessageListFragme
|
|||||||
toggleTheme.setVisible(false);
|
toggleTheme.setVisible(false);
|
||||||
} else {
|
} else {
|
||||||
// Set title of menu item to switch to dark/light theme
|
// Set title of menu item to switch to dark/light theme
|
||||||
if (K9.getK9MessageViewTheme() == K9.THEME_DARK) {
|
if (K9.getK9MessageViewTheme() == K9.Theme.DARK) {
|
||||||
toggleTheme.setTitle(R.string.message_view_theme_action_light);
|
toggleTheme.setTitle(R.string.message_view_theme_action_light);
|
||||||
} else {
|
} else {
|
||||||
toggleTheme.setTitle(R.string.message_view_theme_action_dark);
|
toggleTheme.setTitle(R.string.message_view_theme_action_dark);
|
||||||
@ -1424,10 +1424,10 @@ public class MessageList extends K9FragmentActivity implements MessageListFragme
|
|||||||
}
|
}
|
||||||
|
|
||||||
private void onToggleTheme() {
|
private void onToggleTheme() {
|
||||||
if (K9.getK9MessageViewTheme() == K9.THEME_DARK) {
|
if (K9.getK9MessageViewTheme() == K9.Theme.DARK) {
|
||||||
K9.setK9MessageViewThemeSetting(K9.THEME_LIGHT);
|
K9.setK9MessageViewThemeSetting(K9.Theme.LIGHT);
|
||||||
} else {
|
} else {
|
||||||
K9.setK9MessageViewThemeSetting(K9.THEME_DARK);
|
K9.setK9MessageViewThemeSetting(K9.Theme.DARK);
|
||||||
}
|
}
|
||||||
|
|
||||||
new Thread(new Runnable() {
|
new Thread(new Runnable() {
|
||||||
|
@ -38,7 +38,7 @@ public class NotificationDeleteConfirmation extends Activity {
|
|||||||
public void onCreate(Bundle icicle) {
|
public void onCreate(Bundle icicle) {
|
||||||
super.onCreate(icicle);
|
super.onCreate(icicle);
|
||||||
|
|
||||||
setTheme(K9.getK9Theme() == K9.THEME_LIGHT ?
|
setTheme(K9.getK9Theme() == K9.Theme.LIGHT ?
|
||||||
R.style.Theme_K9_Dialog_Translucent_Light : R.style.Theme_K9_Dialog_Translucent_Dark);
|
R.style.Theme_K9_Dialog_Translucent_Light : R.style.Theme_K9_Dialog_Translucent_Dark);
|
||||||
|
|
||||||
final Preferences preferences = Preferences.getPreferences(this);
|
final Preferences preferences = Preferences.getPreferences(this);
|
||||||
|
@ -446,21 +446,21 @@ public class Prefs extends K9PreferenceActivity {
|
|||||||
mSplitViewMode.getEntries(), mSplitViewMode.getEntryValues());
|
mSplitViewMode.getEntries(), mSplitViewMode.getEntryValues());
|
||||||
}
|
}
|
||||||
|
|
||||||
private static String themeIdToName(int theme) {
|
private static String themeIdToName(K9.Theme theme) {
|
||||||
switch (theme) {
|
switch (theme) {
|
||||||
case K9.THEME_DARK: return "dark";
|
case DARK: return "dark";
|
||||||
case K9.THEME_GLOBAL: return "global";
|
case USE_GLOBAL: return "global";
|
||||||
default: return "light";
|
default: return "light";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private static int themeNameToId(String theme) {
|
private static K9.Theme themeNameToId(String theme) {
|
||||||
if (TextUtils.equals(theme, "dark")) {
|
if (TextUtils.equals(theme, "dark")) {
|
||||||
return K9.THEME_DARK;
|
return K9.Theme.DARK;
|
||||||
} else if (TextUtils.equals(theme, "global")) {
|
} else if (TextUtils.equals(theme, "global")) {
|
||||||
return K9.THEME_GLOBAL;
|
return K9.Theme.USE_GLOBAL;
|
||||||
} else {
|
} else {
|
||||||
return K9.THEME_LIGHT;
|
return K9.Theme.LIGHT;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1880,7 +1880,7 @@ public class MessageListFragment extends SherlockFragment implements OnItemClick
|
|||||||
Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
|
Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
|
||||||
|
|
||||||
//TODO: make this part of the theme
|
//TODO: make this part of the theme
|
||||||
int color = (K9.getK9Theme() == K9.THEME_LIGHT) ?
|
int color = (K9.getK9Theme() == K9.Theme.LIGHT) ?
|
||||||
Color.rgb(105, 105, 105) :
|
Color.rgb(105, 105, 105) :
|
||||||
Color.rgb(160, 160, 160);
|
Color.rgb(160, 160, 160);
|
||||||
|
|
||||||
|
@ -185,10 +185,10 @@ public class GlobalSettings {
|
|||||||
new V(1, new BooleanSetting(false))
|
new V(1, new BooleanSetting(false))
|
||||||
));
|
));
|
||||||
s.put("theme", Settings.versions(
|
s.put("theme", Settings.versions(
|
||||||
new V(1, new ThemeSetting(K9.THEME_LIGHT))
|
new V(1, new ThemeSetting(K9.Theme.LIGHT.ordinal()))
|
||||||
));
|
));
|
||||||
s.put("messageViewTheme", Settings.versions(
|
s.put("messageViewTheme", Settings.versions(
|
||||||
new V(16, new ThemeSetting(K9.THEME_LIGHT))
|
new V(16, new ThemeSetting(K9.Theme.LIGHT.ordinal()))
|
||||||
));
|
));
|
||||||
s.put("useGalleryBugWorkaround", Settings.versions(
|
s.put("useGalleryBugWorkaround", Settings.versions(
|
||||||
new V(1, new GalleryBugWorkaroundSetting())
|
new V(1, new GalleryBugWorkaroundSetting())
|
||||||
@ -363,14 +363,14 @@ public class GlobalSettings {
|
|||||||
public Object fromString(String value) throws InvalidSettingValueException {
|
public Object fromString(String value) throws InvalidSettingValueException {
|
||||||
try {
|
try {
|
||||||
Integer theme = Integer.parseInt(value);
|
Integer theme = Integer.parseInt(value);
|
||||||
if (theme == K9.THEME_LIGHT ||
|
if (theme == K9.Theme.LIGHT.ordinal() ||
|
||||||
// We used to store the resource ID of the theme in the preference storage,
|
// We used to store the resource ID of the theme in the preference storage,
|
||||||
// but don't use the database upgrade mechanism to update the values. So
|
// but don't use the database upgrade mechanism to update the values. So
|
||||||
// we have to deal with the old format here.
|
// we have to deal with the old format here.
|
||||||
theme == android.R.style.Theme_Light) {
|
theme == android.R.style.Theme_Light) {
|
||||||
return K9.THEME_LIGHT;
|
return K9.Theme.LIGHT;
|
||||||
} else if (theme == K9.THEME_DARK || theme == android.R.style.Theme) {
|
} else if (theme == K9.Theme.DARK.ordinal() || theme == android.R.style.Theme) {
|
||||||
return K9.THEME_DARK;
|
return K9.Theme.DARK;
|
||||||
}
|
}
|
||||||
} catch (NumberFormatException e) { /* do nothing */ }
|
} catch (NumberFormatException e) { /* do nothing */ }
|
||||||
|
|
||||||
@ -380,9 +380,9 @@ public class GlobalSettings {
|
|||||||
@Override
|
@Override
|
||||||
public Object fromPrettyString(String value) throws InvalidSettingValueException {
|
public Object fromPrettyString(String value) throws InvalidSettingValueException {
|
||||||
if (THEME_LIGHT.equals(value)) {
|
if (THEME_LIGHT.equals(value)) {
|
||||||
return K9.THEME_LIGHT;
|
return K9.Theme.LIGHT;
|
||||||
} else if (THEME_DARK.equals(value)) {
|
} else if (THEME_DARK.equals(value)) {
|
||||||
return K9.THEME_DARK;
|
return K9.Theme.DARK;
|
||||||
}
|
}
|
||||||
|
|
||||||
throw new InvalidSettingValueException();
|
throw new InvalidSettingValueException();
|
||||||
@ -390,7 +390,7 @@ public class GlobalSettings {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String toPrettyString(Object value) {
|
public String toPrettyString(Object value) {
|
||||||
return (((Integer)value).intValue() == K9.THEME_LIGHT) ? THEME_LIGHT : THEME_DARK;
|
return (((Integer)value).intValue() == K9.Theme.LIGHT.ordinal()) ? THEME_LIGHT : THEME_DARK;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -123,7 +123,7 @@ public class RemoteControlService extends CoreService {
|
|||||||
|
|
||||||
String theme = intent.getStringExtra(K9_THEME);
|
String theme = intent.getStringExtra(K9_THEME);
|
||||||
if (theme != null) {
|
if (theme != null) {
|
||||||
K9.setK9Theme(K9RemoteControl.K9_THEME_DARK.equals(theme) ? K9.THEME_DARK : K9.THEME_LIGHT);
|
K9.setK9Theme(K9RemoteControl.K9_THEME_DARK.equals(theme) ? K9.Theme.DARK : K9.Theme.LIGHT);
|
||||||
}
|
}
|
||||||
|
|
||||||
SharedPreferences sPrefs = preferences.getPreferences();
|
SharedPreferences sPrefs = preferences.getPreferences();
|
||||||
|
@ -94,7 +94,7 @@ public class MessageWebView extends TitleBarWebView {
|
|||||||
this.setScrollBarStyle(SCROLLBARS_INSIDE_OVERLAY);
|
this.setScrollBarStyle(SCROLLBARS_INSIDE_OVERLAY);
|
||||||
this.setLongClickable(true);
|
this.setLongClickable(true);
|
||||||
|
|
||||||
if (K9.getK9MessageViewTheme() == K9.THEME_DARK) {
|
if (K9.getK9MessageViewTheme() == K9.Theme.DARK) {
|
||||||
// Black theme should get a black webview background
|
// Black theme should get a black webview background
|
||||||
// we'll set the background of the messages on load
|
// we'll set the background of the messages on load
|
||||||
this.setBackgroundColor(0xff000000);
|
this.setBackgroundColor(0xff000000);
|
||||||
@ -152,7 +152,7 @@ public class MessageWebView extends TitleBarWebView {
|
|||||||
|
|
||||||
public void setText(String text, String contentType) {
|
public void setText(String text, String contentType) {
|
||||||
String content = text;
|
String content = text;
|
||||||
if (K9.getK9MessageViewTheme() == K9.THEME_DARK) {
|
if (K9.getK9MessageViewTheme() == K9.Theme.DARK) {
|
||||||
// It's a little wrong to just throw in the <style> before the opening <html>
|
// It's a little wrong to just throw in the <style> before the opening <html>
|
||||||
// but it's less wrong than trying to edit the html stream
|
// but it's less wrong than trying to edit the html stream
|
||||||
content = "<style>* { background: black ! important; color: white !important }" +
|
content = "<style>* { background: black ! important; color: white !important }" +
|
||||||
|
Loading…
Reference in New Issue
Block a user