Use style to adapt WebView for dark themes

pull/155/head
M66B 6 years ago
parent 5be86b443e
commit 769e625a15

@ -29,7 +29,6 @@ For authorizing:
* A [bug in Android](https://issuetracker.google.com/issues/62427912) "*... ActivityRecord not found for ...*" sometimes causes a crash after updating FairEmail.
* ~~A [bug in Google Drive](https://issuetracker.google.com/issues/126362828) causes files exported to Google Drive to be empty.~~
* "*... Couldn't read row ...*" causes sometimes a crash. This could be caused by a bug in the [Room Persistence Library](https://developer.android.com/topic/libraries/architecture/room) but more likely indicates a corrupt database.
* "*... Unable to create layer ...*" causes a crash on some devices when inverting the colors of an original message due to a [bug in AndroidX](https://bugs.chromium.org/p/chromium/issues/detail?id=578150)
## Planned features
@ -1393,10 +1392,6 @@ FairEmail already tries to workaround these bugs, but if this fail you'll need t
~~The original message is shown as the sender has sent it, including all colors.~~
~~Changing the background color would not only make the original view not original anymore, it can also result in unreadable messages.~~
Recent versions of FairEmail can invert all colors of the original message when using a dark or black theme.
You can turn this on the advanced settings.
Be aware that this can cause [crashes](https://bugs.chromium.org/p/chromium/issues/detail?id=578150) on some devices.
<br />
<a name="faq82"></a>

@ -36,8 +36,6 @@ import android.content.pm.PackageManager;
import android.content.res.ColorStateList;
import android.database.Cursor;
import android.graphics.Color;
import android.graphics.ColorMatrixColorFilter;
import android.graphics.Paint;
import android.graphics.Rect;
import android.graphics.Typeface;
import android.graphics.drawable.Drawable;
@ -150,7 +148,6 @@ public class AdapterMessage extends RecyclerView.Adapter<AdapterMessage.ViewHold
private boolean preview;
private boolean autohtml;
private boolean autoimages;
private boolean invert;
private boolean authentication;
private boolean debug;
@ -1402,13 +1399,6 @@ public class AdapterMessage extends RecyclerView.Adapter<AdapterMessage.ViewHold
}
};
if (dark && invert) {
// https://bugs.chromium.org/p/chromium/issues/detail?id=578150
Paint paint = new Paint();
paint.setColorFilter(new ColorMatrixColorFilter(Helper.MATRIX_NEGATIVE));
webView.setLayerType(View.LAYER_TYPE_HARDWARE, paint);
}
webView.setWebViewClient(new WebViewClient() {
public boolean shouldOverrideUrlLoading(WebView view, String url) {
Log.i("Open url=" + url);
@ -1484,6 +1474,7 @@ public class AdapterMessage extends RecyclerView.Adapter<AdapterMessage.ViewHold
final WebView webView = (WebView) vwBody;
webView.loadUrl("about:blank");
webView.setBackgroundColor(Color.TRANSPARENT);
WebSettings settings = webView.getSettings();
settings.setUseWideViewPort(true);
@ -1507,11 +1498,13 @@ public class AdapterMessage extends RecyclerView.Adapter<AdapterMessage.ViewHold
if (TextUtils.isEmpty(html)) {
Bundle args = new Bundle();
args.putLong("id", message.id);
args.putBoolean("dark", dark);
new SimpleTask<OriginalMessage>() {
@Override
protected OriginalMessage onExecute(Context context, Bundle args) throws IOException {
long id = args.getLong("id");
boolean dark = args.getBoolean("dark");
DB db = DB.getInstance(context);
EntityMessage message = db.message().getMessage(id);
@ -1523,6 +1516,11 @@ public class AdapterMessage extends RecyclerView.Adapter<AdapterMessage.ViewHold
original.html = HtmlHelper.getHtmlEmbedded(context, id, original.html);
original.html = HtmlHelper.removeTracking(context, original.html);
if (dark)
original.html = "<style type=\"text/css\">" +
"* { background: #000000 !important; color: #FFFFFF !important }" +
"</style>" + original.html;
Document doc = Jsoup.parse(original.html);
original.has_images = (doc.select("img").size() > 0);
@ -3069,7 +3067,6 @@ public class AdapterMessage extends RecyclerView.Adapter<AdapterMessage.ViewHold
this.autohtml = prefs.getBoolean("autohtml", false);
this.autoimages = prefs.getBoolean("autoimages", false);
this.authentication = prefs.getBoolean("authentication", false);
this.invert = prefs.getBoolean("invert", false);
this.debug = prefs.getBoolean("debug", false);
this.textSize = Helper.getTextSize(context, zoom);

@ -86,7 +86,6 @@ public class FragmentOptions extends FragmentBase implements SharedPreferences.O
private SwitchCompat swMonospaced;
private SwitchCompat swHtml;
private SwitchCompat swImages;
private SwitchCompat swInvert;
private SwitchCompat swActionbar;
private SwitchCompat swPull;
@ -121,7 +120,7 @@ public class FragmentOptions extends FragmentBase implements SharedPreferences.O
static String[] OPTIONS_RESTART = new String[]{
"startup", "date", "threading", "avatars", "identicons", "name_email", "subject_italic", "flags", "preview",
"addresses", "monospaced", "autohtml", "autoimages", "invert", "actionbar",
"addresses", "monospaced", "autohtml", "autoimages", "actionbar",
"pull", "swipenav", "autoexpand", "autoclose", "autonext",
"authentication", "debug"
};
@ -130,7 +129,7 @@ public class FragmentOptions extends FragmentBase implements SharedPreferences.O
"enabled", "schedule_start", "schedule_end",
"metered", "download", "roaming",
"startup", "date", "threading", "avatars", "identicons", "name_email", "subject_italic", "flags", "preview",
"addresses", "monospaced", "autohtml", "autoimages", "invert", "actionbar",
"addresses", "monospaced", "autohtml", "autoimages", "actionbar",
"pull", "swipenav", "autoexpand", "autoclose", "autonext", "collapse", "autoread", "automove",
"autoresize", "resize", "prefix_once", "autosend",
"notify_preview", "search_local", "light", "sound",
@ -172,7 +171,6 @@ public class FragmentOptions extends FragmentBase implements SharedPreferences.O
swMonospaced = view.findViewById(R.id.swMonospaced);
swHtml = view.findViewById(R.id.swHtml);
swImages = view.findViewById(R.id.swImages);
swInvert = view.findViewById(R.id.swInvert);
swActionbar = view.findViewById(R.id.swActionbar);
swPull = view.findViewById(R.id.swPull);
@ -392,13 +390,6 @@ public class FragmentOptions extends FragmentBase implements SharedPreferences.O
}
});
swInvert.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
@Override
public void onCheckedChanged(CompoundButton compoundButton, boolean checked) {
prefs.edit().putBoolean("invert", checked).apply();
}
});
swActionbar.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
@Override
public void onCheckedChanged(CompoundButton compoundButton, boolean checked) {
@ -695,7 +686,6 @@ public class FragmentOptions extends FragmentBase implements SharedPreferences.O
swMonospaced.setChecked(prefs.getBoolean("monospaced", false));
swHtml.setChecked(prefs.getBoolean("autohtml", false));
swImages.setChecked(prefs.getBoolean("autoimages", false));
swInvert.setChecked(prefs.getBoolean("invert", false));
swActionbar.setChecked(prefs.getBoolean("actionbar", true));
swPull.setChecked(prefs.getBoolean("pull", true));

@ -132,13 +132,6 @@ public class Helper {
static final float LOW_LIGHT = 0.6f;
static final float[] MATRIX_NEGATIVE = new float[]{
-1, 0, 0, 0, 255, // red
0, -1, 0, 0, 255, // green
0, 0, -1, 0, 255, // blue
0, 0, 0, 1, 0 // alpha
};
static final String FAQ_URI = "https://github.com/M66B/open-source-email/blob/master/FAQ.md";
static ThreadFactory backgroundThreadFactory = new ThreadFactory() {

@ -509,31 +509,6 @@
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/swImages" />
<androidx.appcompat.widget.SwitchCompat
android:id="@+id/swInvert"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginStart="12dp"
android:layout_marginTop="12dp"
android:layout_marginEnd="12dp"
android:text="@string/title_advanced_invert"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/tvImagesHint"
app:switchPadding="12dp" />
<TextView
android:id="@+id/tvInvertHint"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginStart="12dp"
android:layout_marginEnd="60dp"
android:text="@string/title_advanced_crash_hint"
android:textAppearance="@style/TextAppearance.AppCompat.Small"
android:textStyle="italic"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/swInvert" />
<androidx.appcompat.widget.SwitchCompat
android:id="@+id/swActionbar"
android:layout_width="match_parent"
@ -543,7 +518,7 @@
android:layout_marginEnd="12dp"
android:text="@string/title_advanced_actionbar"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/tvInvertHint"
app:layout_constraintTop_toBottomOf="@id/tvImagesHint"
app:switchPadding="12dp" />
<TextView

@ -176,7 +176,6 @@
<string name="title_advanced_monospaced">Use monospaced font for message text</string>
<string name="title_advanced_html">Automatically show original message for known contacts</string>
<string name="title_advanced_images">Automatically show images for known contacts</string>
<string name="title_advanced_invert">Invert colors of original message when using a dark theme</string>
<string name="title_advanced_actionbar">Conversation action bar</string>
<string name="title_advanced_pull_refresh">Pull down to refresh</string>
@ -214,7 +213,6 @@
<string name="title_advanced_name_email_hint">When disabled only names will be shown when available</string>
<string name="title_advanced_flags_hint">Note that starred messages will always be kept locally</string>
<string name="title_advanced_preview_hint">Only available when message text was downloaded</string>
<string name="title_advanced_crash_hint">Enabling this option can cause crashes</string>
<string name="title_advanced_autoexpand_hint">Automatically open message when there is just one message or just one unread message in a conversation</string>
<string name="title_advanced_autocollapse_hint">Multiple expanded messages will always be closed on \'back\'</string>

Loading…
Cancel
Save