mirror of
https://github.com/M66B/FairEmail.git
synced 2025-03-04 10:39:25 +00:00
WebView darkening requires Android 10 or later now
This commit is contained in:
parent
7b338ca8ac
commit
74f594c9de
7 changed files with 64 additions and 5 deletions
|
@ -341,7 +341,7 @@ dependencies {
|
|||
def activity_version = "1.5.0" // 1.6.0-alpha03
|
||||
def fragment_version = "1.5.0"
|
||||
def windows_version = "1.0.0" // 1.1.0-alpha01
|
||||
def webkit_version = "1.5.0-alpha01"
|
||||
def webkit_version = "1.5.0-beta01"
|
||||
def recyclerview_version = "1.2.1" // 1.3.0-alpha02
|
||||
def coordinatorlayout_version = "1.2.0"
|
||||
def constraintlayout_version = "2.1.4" // 2.2.0-alpha01
|
||||
|
|
|
@ -24,6 +24,7 @@ import android.content.Context;
|
|||
import android.content.Intent;
|
||||
import android.content.SharedPreferences;
|
||||
import android.net.Uri;
|
||||
import android.os.Build;
|
||||
import android.os.Bundle;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.Menu;
|
||||
|
@ -161,7 +162,7 @@ public class ActivityAMP extends ActivityBase {
|
|||
WebSettings settings = wvAmp.getSettings();
|
||||
boolean dark = (Helper.isDarkTheme(this) && !force_light);
|
||||
boolean canDarken = WebViewEx.isFeatureSupported(this, WebViewFeature.ALGORITHMIC_DARKENING);
|
||||
if (canDarken)
|
||||
if (canDarken && Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q)
|
||||
WebSettingsCompat.setAlgorithmicDarkeningAllowed(settings, dark);
|
||||
}
|
||||
|
||||
|
|
|
@ -6248,6 +6248,25 @@ public class AdapterMessage extends RecyclerView.Adapter<AdapterMessage.ViewHold
|
|||
}
|
||||
|
||||
private void onActionForceLight(TupleMessageEx message) {
|
||||
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.Q) {
|
||||
View view = LayoutInflater.from(context).inflate(R.layout.dialog_dark, null);
|
||||
final Button btnIssue = view.findViewById(R.id.btnIssue);
|
||||
|
||||
btnIssue.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
Uri uri = Uri.parse("https://issuetracker.google.com/issues/237785596");
|
||||
Helper.view(v.getContext(), uri, true);
|
||||
}
|
||||
});
|
||||
|
||||
new AlertDialog.Builder(context)
|
||||
.setView(view)
|
||||
.setNegativeButton(android.R.string.cancel, null)
|
||||
.show();
|
||||
return;
|
||||
}
|
||||
|
||||
if (canDarken) {
|
||||
boolean force_light = !properties.getValue("force_light", message.id);
|
||||
properties.setValue("force_light", message.id, force_light);
|
||||
|
|
|
@ -23,6 +23,7 @@ import static android.view.ViewGroup.LayoutParams.MATCH_PARENT;
|
|||
|
||||
import android.app.Dialog;
|
||||
import android.content.Context;
|
||||
import android.os.Build;
|
||||
import android.os.Bundle;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
|
@ -84,7 +85,7 @@ public class FragmentDialogOpenFull extends FragmentDialogBase {
|
|||
|
||||
boolean dark = (Helper.isDarkTheme(context) && !force_light);
|
||||
boolean canDarken = WebViewEx.isFeatureSupported(context, WebViewFeature.ALGORITHMIC_DARKENING);
|
||||
if (canDarken)
|
||||
if (canDarken && Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q)
|
||||
WebSettingsCompat.setAlgorithmicDarkeningAllowed(settings, dark);
|
||||
|
||||
settings.setLoadsImagesAutomatically(true);
|
||||
|
|
|
@ -121,7 +121,7 @@ public class WebViewEx extends WebView implements DownloadListener, View.OnLongC
|
|||
// https://developer.android.com/reference/android/webkit/WebSettings#setAlgorithmicDarkeningAllowed(boolean)
|
||||
// https://developer.mozilla.org/en-US/docs/Web/CSS/@media/prefers-color-scheme
|
||||
boolean canDarken = WebViewEx.isFeatureSupported(context, WebViewFeature.ALGORITHMIC_DARKENING);
|
||||
if (canDarken)
|
||||
if (canDarken && Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q)
|
||||
WebSettingsCompat.setAlgorithmicDarkeningAllowed(settings, dark && !force_light);
|
||||
setBackgroundColor(canDarken && dark && !force_light ? Color.TRANSPARENT : Color.WHITE);
|
||||
|
||||
|
@ -368,7 +368,10 @@ public class WebViewEx extends WebView implements DownloadListener, View.OnLongC
|
|||
}
|
||||
|
||||
public static boolean isFeatureSupported(Context context, String feature) {
|
||||
if (WebViewFeature.ALGORITHMIC_DARKENING.equals(feature))
|
||||
if (WebViewFeature.ALGORITHMIC_DARKENING.equals(feature)) {
|
||||
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.Q)
|
||||
return false;
|
||||
|
||||
try {
|
||||
PackageInfo pkg = WebViewCompat.getCurrentWebViewPackage(context);
|
||||
if (pkg != null && pkg.versionCode / 100000 < 5005) // Version 102.*
|
||||
|
@ -376,6 +379,7 @@ public class WebViewEx extends WebView implements DownloadListener, View.OnLongC
|
|||
} catch (Throwable ex) {
|
||||
Log.e(ex);
|
||||
}
|
||||
}
|
||||
|
||||
try {
|
||||
return WebViewFeature.isFeatureSupported(feature);
|
||||
|
|
32
app/src/main/res/layout/dialog_dark.xml
Normal file
32
app/src/main/res/layout/dialog_dark.xml
Normal file
|
@ -0,0 +1,32 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<eu.faircode.email.ScrollViewEx xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:app="http://schemas.android.com/apk/res-auto"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:padding="24dp"
|
||||
android:scrollbarStyle="outsideOverlay">
|
||||
|
||||
<androidx.constraintlayout.widget.ConstraintLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content">
|
||||
|
||||
<TextView
|
||||
android:id="@+id/tvMessage"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="@string/title_compat_dark"
|
||||
android:textAppearance="@style/TextAppearance.AppCompat.Medium"
|
||||
android:textColor="?android:attr/textColorPrimary"
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintTop_toTopOf="parent" />
|
||||
|
||||
<Button
|
||||
android:id="@+id/btnIssue"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginTop="12dp"
|
||||
android:text="@string/title_info"
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintTop_toBottomOf="@+id/tvMessage" />
|
||||
</androidx.constraintlayout.widget.ConstraintLayout>
|
||||
</eu.faircode.email.ScrollViewEx>
|
|
@ -1989,6 +1989,8 @@
|
|||
<string name="title_widget_background">Background color</string>
|
||||
<string name="title_widget_day_night">Follow dark system theme</string>
|
||||
|
||||
<string name="title_compat_dark">Google removed dark mode for Android versions before version 10</string>
|
||||
|
||||
<string name="title_accessibility_collapsed">Collapsed</string>
|
||||
<string name="title_accessibility_expanded">Expanded</string>
|
||||
<string name="title_accessibility_seen">Read</string>
|
||||
|
|
Loading…
Add table
Reference in a new issue