(int height, int maxHeight, float size, Pair<Integer, Integer> position, boolean force_light, IWebView intf)
| 105 | } |
| 106 | |
| 107 | void init(int height, int maxHeight, float size, Pair<Integer, Integer> position, boolean force_light, IWebView intf) { |
| 108 | Log.i("Init height=" + height + "/" + maxHeight + " size=" + size + |
| 109 | " viewport=" + viewportHeight + |
| 110 | " accelerated=" + isHardwareAccelerated()); |
| 111 | |
| 112 | if (maxHeight == 0) { |
| 113 | Log.e("WebView max height zero"); |
| 114 | maxHeight = getResources().getDisplayMetrics().heightPixels; |
| 115 | } |
| 116 | |
| 117 | this.height = (height == 0 ? getMinimumHeight() : height); |
| 118 | this.maxHeight = maxHeight; |
| 119 | |
| 120 | setInitialScale(size == 0 ? 0 : Math.round(size * 100)); |
| 121 | |
| 122 | if (position != null) { |
| 123 | setScrollX(position.first); |
| 124 | setScrollY(position.second); |
| 125 | } |
| 126 | |
| 127 | final Context context = getContext(); |
| 128 | SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context); |
| 129 | boolean compact = prefs.getBoolean("compact", false); |
| 130 | int zoom = prefs.getInt("view_zoom", compact ? 0 : 1); |
| 131 | boolean browser_zoom = (prefs.getBoolean("browser_zoom", false) && BuildConfig.DEBUG); |
| 132 | int message_zoom = prefs.getInt("message_zoom", 100); |
| 133 | boolean monospaced = prefs.getBoolean("monospaced", false); |
| 134 | |
| 135 | WebSettings settings = getSettings(); |
| 136 | |
| 137 | boolean dark = Helper.isDarkTheme(context); |
| 138 | |
| 139 | // https://developer.android.com/reference/android/webkit/WebSettings#setAlgorithmicDarkeningAllowed(boolean) |
| 140 | // https://developer.mozilla.org/en-US/docs/Web/CSS/@media/prefers-color-scheme |
| 141 | boolean canDarken = WebViewEx.isFeatureSupported(context, WebViewFeature.ALGORITHMIC_DARKENING); |
| 142 | if (canDarken) |
| 143 | WebSettingsCompat.setAlgorithmicDarkeningAllowed(settings, dark && !force_light); |
| 144 | setBackgroundColor(canDarken && dark && !force_light ? Color.TRANSPARENT : Color.WHITE); |
| 145 | |
| 146 | float fontSize = 16f /* Default */ * |
| 147 | (browser_zoom ? 1f : message_zoom / 100f); |
| 148 | if (zoom == 0 /* small */) |
| 149 | fontSize *= HtmlHelper.FONT_SMALL; |
| 150 | else if (zoom == 2 /* large */) |
| 151 | fontSize *= HtmlHelper.FONT_LARGE; |
| 152 | |
| 153 | settings.setDefaultFontSize(Math.round(fontSize)); |
| 154 | settings.setDefaultFixedFontSize(Math.round(fontSize)); |
| 155 | |
| 156 | if (monospaced) |
| 157 | settings.setStandardFontFamily("monospace"); |
| 158 | |
| 159 | this.intf = intf; |
| 160 | |
| 161 | setWebViewClient(new WebViewClient() { |
| 162 | @Override |
| 163 | public void onPageStarted(WebView view, String url, Bitmap favicon) { |
| 164 | Log.i("Started url=" + url); |
no test coverage detected