Invert webview colors when using dark/black theme

pull/155/head
M66B 6 years ago
parent edcda6a5ae
commit 3dad939bcb

@ -147,7 +147,7 @@ FairEmail follows all the best practices for an email client as decribed in [thi
* [(78) How do I use schedules?](#user-content-faq78)
* [(79) How do I use synchronize on demand (manual)?](#user-content-faq79)
* [(80) How can I fix 'Unable to load BODYSTRUCTURE'?](#user-content-faq80)
* [(81) Can you make the background of the original message dark in the dark theme?](#user-content-faq81)
* [~~(81) Can you make the background of the original message dark in the dark theme?~~](#user-content-faq81)
* [(82) What is a tracking image?](#user-content-faq82)
* [(83) What does 'User is authenticated but not connected' mean?](#user-content-faq83)
* [(84) What are local contacts for?](#user-content-faq84)
@ -1375,10 +1375,12 @@ FairEmail already tries to workaround these bugs, but if this fail you'll need t
<br />
<a name="faq81"></a>
**(81) Can you make the background of the original message dark in the dark theme?**
**~~(81) Can you make the background of the original message dark in the dark theme?~~**
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.
~~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 will invert all colors of the original message when using a dark or black theme.
<br />

@ -36,6 +36,8 @@ 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;
@ -139,6 +141,7 @@ public class AdapterMessage extends RecyclerView.Adapter<AdapterMessage.ViewHold
private boolean suitable;
private IProperties properties;
private boolean dark;
private boolean date;
private boolean threading;
private boolean contacts;
@ -1398,6 +1401,19 @@ public class AdapterMessage extends RecyclerView.Adapter<AdapterMessage.ViewHold
}
};
if (dark) {
float[] 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
};
Paint paint = new Paint();
paint.setColorFilter(new ColorMatrixColorFilter(NEGATIVE));
webView.setLayerType(View.LAYER_TYPE_HARDWARE, paint);
}
webView.setWebViewClient(new WebViewClient() {
public boolean shouldOverrideUrlLoading(WebView view, String url) {
Log.i("Open url=" + url);
@ -3033,6 +3049,9 @@ public class AdapterMessage extends RecyclerView.Adapter<AdapterMessage.ViewHold
this.suitable = Helper.getNetworkState(context).isSuitable();
this.properties = properties;
TypedValue tv = new TypedValue();
context.getTheme().resolveAttribute(R.attr.themeName, tv, true);
this.dark = !"light".equals(tv.string);
this.date = prefs.getBoolean("date", true);
this.threading = prefs.getBoolean("threading", true);

Loading…
Cancel
Save