Algorithmic darkening requires WebView 102.*

pull/208/head
M66B 3 years ago
parent 251695fb5d
commit eb5f72e466

@ -95,7 +95,7 @@ public class ActivityAMP extends ActivityBase {
settings.setCacheMode(WebSettings.LOAD_CACHE_ELSE_NETWORK);
settings.setMixedContentMode(WebSettings.MIXED_CONTENT_ALWAYS_ALLOW);
if (WebViewEx.isFeatureSupported(WebViewFeature.SAFE_BROWSING_ENABLE))
if (WebViewEx.isFeatureSupported(this, WebViewFeature.SAFE_BROWSING_ENABLE))
WebSettingsCompat.setSafeBrowsingEnabled(settings, safe_browsing);
setDarkMode();
@ -127,7 +127,7 @@ public class ActivityAMP extends ActivityBase {
@Override
public boolean onPrepareOptionsMenu(Menu menu) {
boolean dark = Helper.isDarkTheme(this);
boolean canDarken = WebViewEx.isFeatureSupported(WebViewFeature.ALGORITHMIC_DARKENING);
boolean canDarken = WebViewEx.isFeatureSupported(this, WebViewFeature.ALGORITHMIC_DARKENING);
menu.findItem(R.id.menu_force_light)
.setVisible(dark && canDarken)
.getIcon().setLevel(force_light ? 1 : 0);
@ -160,7 +160,7 @@ public class ActivityAMP extends ActivityBase {
private void setDarkMode() {
WebSettings settings = wvAmp.getSettings();
boolean dark = (Helper.isDarkTheme(this) && !force_light);
boolean canDarken = WebViewEx.isFeatureSupported(WebViewFeature.ALGORITHMIC_DARKENING);
boolean canDarken = WebViewEx.isFeatureSupported(this, WebViewFeature.ALGORITHMIC_DARKENING);
if (canDarken)
WebSettingsCompat.setAlgorithmicDarkeningAllowed(settings, dark);
}

@ -2163,8 +2163,8 @@ public class AdapterMessage extends RecyclerView.Adapter<AdapterMessage.ViewHold
ibSearchText.setVisibility(tools && !outbox && button_search_text && message.content && !full ? View.VISIBLE : View.GONE);
ibSearch.setVisibility(tools && !outbox && button_search && (froms > 0 || tos > 0) ? View.VISIBLE : View.GONE);
ibTranslate.setVisibility(tools && !outbox && button_translate && DeepL.isAvailable(context) && message.content ? View.VISIBLE : View.GONE);
ibForceLight.setVisibility(tools && full && dark && canDarken && button_force_light && message.content ? View.VISIBLE : View.GONE);
ibForceLight.setImageLevel(force_light ? 1 : 0);
ibForceLight.setVisibility(tools && full && dark && button_force_light && message.content ? View.VISIBLE : View.GONE);
ibForceLight.setImageLevel(!canDarken || force_light ? 1 : 0);
ibImportance.setVisibility(tools && button_importance && !outbox && seen ? View.VISIBLE : View.GONE);
ibHide.setVisibility(tools && button_hide && !outbox ? View.VISIBLE : View.GONE);
ibSeen.setVisibility(tools && button_seen && !outbox && seen ? View.VISIBLE : View.GONE);
@ -6226,10 +6226,17 @@ public class AdapterMessage extends RecyclerView.Adapter<AdapterMessage.ViewHold
}
private void onActionForceLight(TupleMessageEx message) {
if (canDarken) {
boolean force_light = !properties.getValue("force_light", message.id);
properties.setValue("force_light", message.id, force_light);
ibForceLight.setImageLevel(force_light ? 1 : 0);
bindBody(message, false);
} else {
Intent update = new Intent(Intent.ACTION_VIEW)
.setData(Uri.parse(Helper.PACKAGE_WEBVIEW))
.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
context.startActivity(update);
}
}
private void onSearchText(TupleMessageEx message) {
@ -7064,7 +7071,7 @@ public class AdapterMessage extends RecyclerView.Adapter<AdapterMessage.ViewHold
debug = prefs.getBoolean("debug", false);
level = prefs.getInt("log_level", Log.getDefaultLogLevel());
this.canDarken = WebViewEx.isFeatureSupported(WebViewFeature.ALGORITHMIC_DARKENING);
this.canDarken = WebViewEx.isFeatureSupported(context, WebViewFeature.ALGORITHMIC_DARKENING);
this.webview_legacy = prefs.getBoolean("webview_legacy", false);
this.show_recent = prefs.getBoolean("show_recent", false);

@ -79,11 +79,11 @@ public class FragmentDialogOpenFull extends FragmentDialogBase {
settings.setCacheMode(WebSettings.LOAD_CACHE_ELSE_NETWORK);
settings.setMixedContentMode(WebSettings.MIXED_CONTENT_ALWAYS_ALLOW);
if (WebViewEx.isFeatureSupported(WebViewFeature.SAFE_BROWSING_ENABLE))
if (WebViewEx.isFeatureSupported(context, WebViewFeature.SAFE_BROWSING_ENABLE))
WebSettingsCompat.setSafeBrowsingEnabled(settings, safe_browsing);
boolean dark = (Helper.isDarkTheme(context) && !force_light);
boolean canDarken = WebViewEx.isFeatureSupported(WebViewFeature.ALGORITHMIC_DARKENING);
boolean canDarken = WebViewEx.isFeatureSupported(context, WebViewFeature.ALGORITHMIC_DARKENING);
if (canDarken)
WebSettingsCompat.setAlgorithmicDarkeningAllowed(settings, dark);

@ -380,7 +380,7 @@ public class FragmentOptionsPrivacy extends FragmentBase implements SharedPrefer
}
});
grpSafeBrowsing.setEnabled(WebViewEx.isFeatureSupported(WebViewFeature.SAFE_BROWSING_ENABLE));
grpSafeBrowsing.setEnabled(WebViewEx.isFeatureSupported(getContext(), WebViewFeature.SAFE_BROWSING_ENABLE));
swLoadEmoji.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
@Override

@ -184,6 +184,7 @@ public class Helper {
static final String PGP_END_MESSAGE = "-----END PGP MESSAGE-----";
static final String PACKAGE_CHROME = "com.android.chrome";
static final String PACKAGE_WEBVIEW = "https://play.google.com/store/apps/details?id=com.google.android.webview";
static final String PRIVACY_URI = "https://email.faircode.eu/privacy/";
static final String XDA_URI = "https://forum.xda-developers.com/showthread.php?t=3824168";
static final String SUPPORT_URI = "https://contact.faircode.eu/";

@ -1985,7 +1985,7 @@ public class Log {
"normal".equals(uiType) ? "" : "!!!"));
sb.append(String.format("Darken support: %b\r\n",
WebViewEx.isFeatureSupported(WebViewFeature.ALGORITHMIC_DARKENING)));
WebViewEx.isFeatureSupported(context, WebViewFeature.ALGORITHMIC_DARKENING)));
sb.append("\r\n");

@ -83,7 +83,7 @@ public class WebViewEx extends WebView implements DownloadListener, View.OnLongC
settings.setCacheMode(WebSettings.LOAD_CACHE_ELSE_NETWORK);
settings.setMixedContentMode(WebSettings.MIXED_CONTENT_ALWAYS_ALLOW);
if (WebViewEx.isFeatureSupported(WebViewFeature.SAFE_BROWSING_ENABLE))
if (WebViewEx.isFeatureSupported(context, WebViewFeature.SAFE_BROWSING_ENABLE))
WebSettingsCompat.setSafeBrowsingEnabled(settings, safe_browsing);
}
@ -120,7 +120,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(WebViewFeature.ALGORITHMIC_DARKENING);
boolean canDarken = WebViewEx.isFeatureSupported(context, WebViewFeature.ALGORITHMIC_DARKENING);
if (canDarken)
WebSettingsCompat.setAlgorithmicDarkeningAllowed(settings, dark && !force_light);
setBackgroundColor(canDarken && dark && !force_light ? Color.TRANSPARENT : Color.WHITE);
@ -354,7 +354,16 @@ public class WebViewEx extends WebView implements DownloadListener, View.OnLongC
return (yscale > 1.01);
}
public static boolean isFeatureSupported(String feature) {
public static boolean isFeatureSupported(Context context, String feature) {
if (WebViewFeature.ALGORITHMIC_DARKENING.equals(feature))
try {
PackageInfo pkg = WebViewCompat.getCurrentWebViewPackage(context);
if (pkg != null && pkg.versionCode / 100000 < 5005) // Version 102.*
return false;
} catch (Throwable ex) {
Log.e(ex);
}
try {
return WebViewFeature.isFeatureSupported(feature);
} catch (Throwable ex) {
@ -403,19 +412,6 @@ public class WebViewEx extends WebView implements DownloadListener, View.OnLongC
return (large ? "Mozilla/5.0" : "Mozilla/5.0 (Mobile)");
}
static int getVersionCode(Context context) {
try {
// version / 100000 > 5005
PackageInfo pkg = WebViewCompat.getCurrentWebViewPackage(context);
if (pkg == null)
return -1;
return pkg.versionCode;
} catch (Throwable ex) {
Log.e(ex);
return -1;
}
}
interface IWebView {
void onSizeChanged(int w, int h, int ow, int oh);

Loading…
Cancel
Save