1
0
mirror of https://github.com/moparisthebest/k-9 synced 2024-12-24 08:38:51 -05:00

Convert theme setting value to an enum.

This commit is contained in:
Danny Baumann 2013-02-06 20:08:57 +01:00 committed by cketti
parent bd154c4c0f
commit 8f3e61feab
10 changed files with 64 additions and 61 deletions

View File

@ -44,10 +44,6 @@ import com.fsck.k9.service.ShutdownReceiver;
import com.fsck.k9.service.StorageGoneReceiver;
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
* available and ready (Android invokes Application.onCreate() after other
@ -99,9 +95,9 @@ public class K9 extends Application {
}
private static String language = "";
private static int theme = THEME_LIGHT;
private static int messageViewTheme = THEME_GLOBAL;
private static int composerTheme = THEME_GLOBAL;
private static Theme theme = Theme.LIGHT;
private static Theme messageViewTheme = Theme.USE_GLOBAL;
private static Theme composerTheme = Theme.USE_GLOBAL;
private static boolean useFixedMessageTheme = true;
private static final FontSizes fontSizes = new FontSizes();
@ -525,9 +521,9 @@ public class K9 extends Application {
editor.putBoolean("batchButtonsUnselect", mBatchButtonsUnselect);
editor.putString("language", language);
editor.putInt("theme", theme);
editor.putInt("messageViewTheme", messageViewTheme);
editor.putInt("messageComposeTheme", composerTheme);
editor.putInt("theme", theme.ordinal());
editor.putInt("messageViewTheme", messageViewTheme.ordinal());
editor.putInt("messageComposeTheme", composerTheme.ordinal());
editor.putBoolean("fixedMessageViewTheme", useFixedMessageTheme);
editor.putBoolean("useGalleryBugWorkaround", useGalleryBugWorkaround);
@ -771,20 +767,20 @@ public class K9 extends Application {
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
// necessary.
if (theme == THEME_DARK || theme == android.R.style.Theme) {
theme = THEME_DARK;
if (themeValue == Theme.DARK.ordinal() || themeValue == android.R.style.Theme) {
K9.setK9Theme(Theme.DARK);
} 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.setK9ComposerThemeSetting(sprefs.getInt("messageComposeTheme", THEME_GLOBAL));
}
private void maybeSetupStrictMode() {
@ -843,40 +839,47 @@ public class K9 extends Application {
language = nlanguage;
}
public static int getK9ThemeResourceId(int themeId) {
return (themeId == THEME_LIGHT) ? R.style.Theme_K9_Light : R.style.Theme_K9_Dark;
public enum Theme {
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() {
return getK9ThemeResourceId(theme);
}
public static int getK9MessageViewTheme() {
return messageViewTheme == THEME_GLOBAL ? theme : messageViewTheme;
public static Theme getK9MessageViewTheme() {
return messageViewTheme == Theme.USE_GLOBAL ? theme : messageViewTheme;
}
public static int getK9MessageViewThemeSetting() {
public static Theme getK9MessageViewThemeSetting() {
return messageViewTheme;
}
public static int getK9ComposerTheme() {
return composerTheme == THEME_GLOBAL ? theme : composerTheme;
public static Theme getK9ComposerTheme() {
return composerTheme == Theme.USE_GLOBAL ? theme : composerTheme;
}
public static int getK9ComposerThemeSetting() {
public static Theme getK9ComposerThemeSetting() {
return composerTheme;
}
public static int getK9Theme() {
public static Theme getK9Theme() {
return theme;
}
public static void setK9Theme(int ntheme) {
assert ntheme != THEME_GLOBAL;
theme = ntheme;
public static void setK9Theme(Theme ntheme) {
if (ntheme != Theme.USE_GLOBAL) {
theme = ntheme;
}
}
public static void setK9MessageViewThemeSetting(int nMessageViewTheme) {
public static void setK9MessageViewThemeSetting(Theme nMessageViewTheme) {
messageViewTheme = nMessageViewTheme;
}
@ -884,13 +887,13 @@ public class K9 extends Application {
return useFixedMessageTheme;
}
public static void setK9ComposerThemeSetting(int compTheme) {
public static void setK9ComposerThemeSetting(Theme compTheme) {
composerTheme = compTheme;
}
public static void setUseFixedMessageViewTheme(boolean useFixed) {
useFixedMessageTheme = useFixed;
if (!useFixedMessageTheme && messageViewTheme == THEME_GLOBAL) {
if (!useFixedMessageTheme && messageViewTheme == Theme.USE_GLOBAL) {
messageViewTheme = theme;
}
}

View File

@ -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
// causes PreferenceScreens to have a black background.
// http://code.google.com/p/android/issues/detail?id=4611
setTheme(K9.getK9ThemeResourceId(K9.THEME_DARK));
setTheme(K9.getK9ThemeResourceId(K9.Theme.DARK));
} else {
setTheme(K9.getK9ThemeResourceId());
}

View File

@ -554,7 +554,7 @@ public class MessageCompose extends K9Activity implements OnClickListener {
mMessageContentView = (EditText)findViewById(R.id.message_content);
mMessageContentView.getInputExtras(true).putBoolean("allowEmoji", true);
if (K9.getK9ComposerThemeSetting() != K9.THEME_GLOBAL) {
if (K9.getK9ComposerThemeSetting() != K9.Theme.USE_GLOBAL) {
ContextThemeWrapper wrapper = new ContextThemeWrapper(this,
K9.getK9ThemeResourceId(K9.getK9ComposerTheme()));
TypedValue outValue = new TypedValue();
@ -2381,7 +2381,7 @@ public class MessageCompose extends K9Activity implements OnClickListener {
.create();
case DIALOG_CHOOSE_IDENTITY:
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_Dark);
Builder builder = new AlertDialog.Builder(context);

View File

@ -961,7 +961,7 @@ public class MessageList extends K9FragmentActivity implements MessageListFragme
toggleTheme.setVisible(false);
} else {
// 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);
} else {
toggleTheme.setTitle(R.string.message_view_theme_action_dark);
@ -1424,10 +1424,10 @@ public class MessageList extends K9FragmentActivity implements MessageListFragme
}
private void onToggleTheme() {
if (K9.getK9MessageViewTheme() == K9.THEME_DARK) {
K9.setK9MessageViewThemeSetting(K9.THEME_LIGHT);
if (K9.getK9MessageViewTheme() == K9.Theme.DARK) {
K9.setK9MessageViewThemeSetting(K9.Theme.LIGHT);
} else {
K9.setK9MessageViewThemeSetting(K9.THEME_DARK);
K9.setK9MessageViewThemeSetting(K9.Theme.DARK);
}
new Thread(new Runnable() {

View File

@ -38,7 +38,7 @@ public class NotificationDeleteConfirmation extends Activity {
public void onCreate(Bundle 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);
final Preferences preferences = Preferences.getPreferences(this);

View File

@ -446,21 +446,21 @@ public class Prefs extends K9PreferenceActivity {
mSplitViewMode.getEntries(), mSplitViewMode.getEntryValues());
}
private static String themeIdToName(int theme) {
private static String themeIdToName(K9.Theme theme) {
switch (theme) {
case K9.THEME_DARK: return "dark";
case K9.THEME_GLOBAL: return "global";
case DARK: return "dark";
case USE_GLOBAL: return "global";
default: return "light";
}
}
private static int themeNameToId(String theme) {
private static K9.Theme themeNameToId(String theme) {
if (TextUtils.equals(theme, "dark")) {
return K9.THEME_DARK;
return K9.Theme.DARK;
} else if (TextUtils.equals(theme, "global")) {
return K9.THEME_GLOBAL;
return K9.Theme.USE_GLOBAL;
} else {
return K9.THEME_LIGHT;
return K9.Theme.LIGHT;
}
}

View File

@ -1880,7 +1880,7 @@ public class MessageListFragment extends SherlockFragment implements OnItemClick
Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
//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(160, 160, 160);

View File

@ -185,10 +185,10 @@ public class GlobalSettings {
new V(1, new BooleanSetting(false))
));
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(
new V(16, new ThemeSetting(K9.THEME_LIGHT))
new V(16, new ThemeSetting(K9.Theme.LIGHT.ordinal()))
));
s.put("useGalleryBugWorkaround", Settings.versions(
new V(1, new GalleryBugWorkaroundSetting())
@ -363,14 +363,14 @@ public class GlobalSettings {
public Object fromString(String value) throws InvalidSettingValueException {
try {
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,
// but don't use the database upgrade mechanism to update the values. So
// we have to deal with the old format here.
theme == android.R.style.Theme_Light) {
return K9.THEME_LIGHT;
} else if (theme == K9.THEME_DARK || theme == android.R.style.Theme) {
return K9.THEME_DARK;
return K9.Theme.LIGHT;
} else if (theme == K9.Theme.DARK.ordinal() || theme == android.R.style.Theme) {
return K9.Theme.DARK;
}
} catch (NumberFormatException e) { /* do nothing */ }
@ -380,9 +380,9 @@ public class GlobalSettings {
@Override
public Object fromPrettyString(String value) throws InvalidSettingValueException {
if (THEME_LIGHT.equals(value)) {
return K9.THEME_LIGHT;
return K9.Theme.LIGHT;
} else if (THEME_DARK.equals(value)) {
return K9.THEME_DARK;
return K9.Theme.DARK;
}
throw new InvalidSettingValueException();
@ -390,7 +390,7 @@ public class GlobalSettings {
@Override
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;
}
}

View File

@ -123,7 +123,7 @@ public class RemoteControlService extends CoreService {
String theme = intent.getStringExtra(K9_THEME);
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();

View File

@ -94,7 +94,7 @@ public class MessageWebView extends TitleBarWebView {
this.setScrollBarStyle(SCROLLBARS_INSIDE_OVERLAY);
this.setLongClickable(true);
if (K9.getK9MessageViewTheme() == K9.THEME_DARK) {
if (K9.getK9MessageViewTheme() == K9.Theme.DARK) {
// Black theme should get a black webview background
// we'll set the background of the messages on load
this.setBackgroundColor(0xff000000);
@ -152,7 +152,7 @@ public class MessageWebView extends TitleBarWebView {
public void setText(String text, String contentType) {
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>
// but it's less wrong than trying to edit the html stream
content = "<style>* { background: black ! important; color: white !important }" +