FairEmail/app/src/main/java/eu/faircode/email/FragmentDialogOpenFull.java

99 lines
3.6 KiB
Java
Raw Normal View History

2022-02-06 10:03:36 +00:00
package eu.faircode.email;
/*
This file is part of FairEmail.
FairEmail is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
FairEmail is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with FairEmail. If not, see <http://www.gnu.org/licenses/>.
2023-01-01 07:52:55 +00:00
Copyright 2018-2023 by Marcel Bokhorst (M66B)
2022-02-06 10:03:36 +00:00
*/
import static android.view.ViewGroup.LayoutParams.MATCH_PARENT;
import android.app.Dialog;
import android.content.Context;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.webkit.WebSettings;
import android.webkit.WebView;
import androidx.annotation.Nullable;
import androidx.fragment.app.DialogFragment;
import androidx.webkit.WebSettingsCompat;
import androidx.webkit.WebViewFeature;
import java.nio.charset.StandardCharsets;
public class FragmentDialogOpenFull extends FragmentDialogBase {
@Override
public void onCreate(@Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setStyle(DialogFragment.STYLE_NORMAL, R.style.fullScreenDialog);
}
@Override
public void onStart() {
super.onStart();
Dialog dialog = getDialog();
if (dialog != null)
dialog.getWindow().setLayout(MATCH_PARENT, MATCH_PARENT);
}
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
Bundle args = getArguments();
String html = args.getString("html");
boolean overview_mode = args.getBoolean("overview_mode");
boolean safe_browsing = args.getBoolean("safe_browsing");
boolean force_light = args.getBoolean("force_light");
final Context context = getContext();
View view = inflater.inflate(R.layout.fragment_open_full, container, false);
WebView wv = view.findViewById(R.id.wv);
WebSettings settings = wv.getSettings();
settings.setUserAgentString(WebViewEx.getUserAgent(context, wv));
settings.setUseWideViewPort(true);
settings.setLoadWithOverviewMode(overview_mode);
settings.setBuiltInZoomControls(true);
settings.setDisplayZoomControls(false);
settings.setLayoutAlgorithm(WebSettings.LayoutAlgorithm.TEXT_AUTOSIZING);
settings.setAllowFileAccess(false);
settings.setCacheMode(WebSettings.LOAD_CACHE_ELSE_NETWORK);
settings.setMixedContentMode(WebSettings.MIXED_CONTENT_ALWAYS_ALLOW);
if (WebViewEx.isFeatureSupported(context, WebViewFeature.SAFE_BROWSING_ENABLE))
2022-02-13 20:55:55 +00:00
WebSettingsCompat.setSafeBrowsingEnabled(settings, safe_browsing);
2022-02-06 10:03:36 +00:00
boolean dark = (Helper.isDarkTheme(context) && !force_light);
boolean canDarken = WebViewEx.isFeatureSupported(context, WebViewFeature.ALGORITHMIC_DARKENING);
2022-11-09 21:28:59 +00:00
if (canDarken)
2022-06-11 11:14:28 +00:00
WebSettingsCompat.setAlgorithmicDarkeningAllowed(settings, dark);
2022-02-06 10:03:36 +00:00
settings.setLoadsImagesAutomatically(true);
settings.setBlockNetworkLoads(false);
settings.setBlockNetworkImage(false);
wv.loadDataWithBaseURL(null, html, "text/html", StandardCharsets.UTF_8.name(), null);
return view;
}
}