1
0
mirror of https://github.com/moparisthebest/k-9 synced 2024-12-25 09:08:49 -05:00

+toggle option in message view to change message display theme (dark,light) permanently (Issue 1674)

This commit is contained in:
Bernhard Redl 2012-09-14 02:25:39 +02:00
parent 93be25bf37
commit 76d8e11703
8 changed files with 65 additions and 4 deletions

View File

@ -72,4 +72,9 @@
android:title="@string/select_text_action"
android:showAsAction="never"
/>
<item
android:id="@+id/toggle_message_view_theme"
android:title="@string/message_view_theme_action_dark"
android:showAsAction="never"
/>
</menu>

View File

@ -164,6 +164,9 @@ http://k9mail.googlecode.com/
<string name="hide_full_header_action">Hide full header</string>
<string name="select_text_action">Select text</string>
<string name="message_view_theme_action_dark">Change background to black</string>
<string name="message_view_theme_action_light">Change background to white</string>
<string name="mark_as_unread_action">Mark as unread</string>
<string name="add_cc_bcc_action">Add Cc/Bcc</string>
<string name="read_receipt">Read receipt</string>

View File

@ -78,6 +78,7 @@ public class K9 extends Application {
private static String language = "";
private static int theme = THEME_LIGHT;
private static int messageViewTheme = THEME_LIGHT;
private static final FontSizes fontSizes = new FontSizes();
@ -458,6 +459,7 @@ public class K9 extends Application {
editor.putString("language", language);
editor.putInt("theme", theme);
editor.putInt("messageViewTheme", messageViewTheme);
editor.putBoolean("useGalleryBugWorkaround", useGalleryBugWorkaround);
editor.putBoolean("confirmDelete", mConfirmDelete);
@ -661,6 +663,8 @@ public class K9 extends Application {
theme = THEME_LIGHT;
}
K9.setK9Theme(theme);
K9.setK9MessageViewTheme(sprefs.getInt("messageViewTheme", THEME_LIGHT));
}
private void maybeSetupStrictMode() {
@ -727,6 +731,10 @@ public class K9 extends Application {
return getK9ThemeResourceId(theme);
}
public static int getK9MessageViewTheme() {
return messageViewTheme;
}
public static int getK9Theme() {
return theme;
}
@ -735,6 +743,10 @@ public class K9 extends Application {
theme = ntheme;
}
public static void setK9MessageViewTheme(int nMessageViewTheme) {
messageViewTheme = nMessageViewTheme;
}
public static BACKGROUND_OPS getBackgroundOps() {
return backgroundOps;
}

View File

@ -9,7 +9,9 @@ import android.app.Dialog;
import android.app.ProgressDialog;
import android.content.Context;
import android.content.Intent;
import android.content.SharedPreferences.Editor;
import android.net.Uri;
import android.os.AsyncTask;
import android.os.Bundle;
import android.os.Handler;
import android.util.Log;
@ -72,6 +74,8 @@ public class MessageView extends K9Activity implements OnClickListener {
private MessageViewHandler mHandler = new MessageViewHandler();
private StorageManager.StorageListener mStorageListener = new StorageListenerImplementation();
private MenuItem mToggleMessageViewMenu;
/** this variable is used to save the calling AttachmentView
* until the onActivityResult is called.
* => with this reference we can identity the caller
@ -602,6 +606,26 @@ public class MessageView extends K9Activity implements OnClickListener {
startRefileActivity(ACTIVITY_CHOOSE_FOLDER_COPY);
}
private void onToggleColors() {
if (K9.getK9MessageViewTheme() == K9.THEME_DARK) {
K9.setK9MessageViewTheme(K9.THEME_LIGHT);
} else {
K9.setK9MessageViewTheme(K9.THEME_DARK);
}
new AsyncTask<Object, Object, Object>() {
@Override
protected Object doInBackground(Object... params) {
Preferences prefs = Preferences.getPreferences(getApplicationContext());
Editor editor = prefs.getPreferences().edit();
K9.save(editor);
editor.commit();
return null;
}
}.execute();
displayMessage(mMessageReference);
}
private void startRefileActivity(int activity) {
Intent intent = new Intent(this, ChooseFolder.class);
intent.putExtra(ChooseFolder.EXTRA_ACCOUNT, mAccount.getUuid());
@ -788,6 +812,9 @@ public class MessageView extends K9Activity implements OnClickListener {
case R.id.select_text:
mMessageView.beginSelectingText();
break;
case R.id.toggle_message_view_theme:
onToggleColors();
break;
default:
return super.onOptionsItemSelected(item);
}
@ -814,6 +841,14 @@ public class MessageView extends K9Activity implements OnClickListener {
menu.findItem(R.id.move).setVisible(true);
menu.findItem(R.id.archive).setVisible(true);
menu.findItem(R.id.spam).setVisible(true);
mToggleMessageViewMenu = menu.findItem(R.id.toggle_message_view_theme);
if (K9.getK9MessageViewTheme() == K9.THEME_DARK) {
mToggleMessageViewMenu.setTitle(R.string.message_view_theme_action_light);
} else {
mToggleMessageViewMenu.setTitle(R.string.message_view_theme_action_dark);
}
toggleActionsState(menu, true);
if (mNextMessage != null) {

View File

@ -191,6 +191,9 @@ public class GlobalSettings {
s.put("theme", Settings.versions(
new V(1, new ThemeSetting(K9.THEME_LIGHT))
));
s.put("messageViewTheme", Settings.versions(
new V(16, new ThemeSetting(K9.THEME_LIGHT))
));
s.put("useGalleryBugWorkaround", Settings.versions(
new V(1, new GalleryBugWorkaroundSetting())
));

View File

@ -35,7 +35,7 @@ public class Settings {
*
* @see SettingsExporter
*/
public static final int VERSION = 15;
public static final int VERSION = 16;
public static Map<String, Object> validate(int version, Map<String,
TreeMap<Integer, SettingsDescription>> settings,

View File

@ -94,10 +94,13 @@ public class MessageWebView extends TitleBarWebView {
this.setScrollBarStyle(SCROLLBARS_INSIDE_OVERLAY);
this.setLongClickable(true);
if (K9.getK9Theme() == 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);
} else {
// multitoggle requires reset to white
this.setBackgroundColor(0xffffffff);
}
final WebSettings webSettings = this.getSettings();
@ -152,7 +155,7 @@ public class MessageWebView extends TitleBarWebView {
public void setText(String text, String contentType) {
String content = text;
if (K9.getK9Theme() == 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 }" +

View File

@ -720,7 +720,7 @@ public class SingleMessageView extends LinearLayout implements OnClickListener,
showShowPicturesAction(false);
mAttachments.removeAllViews();
mHiddenAttachments.removeAllViews();
mMessageContentView.configure();
/*
* Clear the WebView content
*