+
+ override fun updateFontSize(dialogFragment: DialogFragment) {
+ // Get the dialog.
+ val dialog = dialogFragment.dialog!!
+
+ // Get a handle for the font size edit text.
+ val fontSizeEditText = dialog.findViewById<EditText>(R.id.font_size_edittext)
+
+ // Initialize the new font size variable with the current font size.
+ var newFontSize = currentWebView!!.settings.textZoom
+
+ // Get the font size from the edit text.
+ try {
+ newFontSize = fontSizeEditText.text.toString().toInt()
+ } catch (exception: Exception) {
+ // If the edit text does not contain a valid font size do nothing.
+ }
+
+ // Apply the new font size.
+ currentWebView!!.settings.textZoom = newFontSize
+ }
+
+ private fun updatePrivacyIcons(runInvalidateOptionsMenu: Boolean) {
+ // Only update the privacy icons if the options menu and the current WebView have already been populated.
+ if ((optionsMenu != null) && (currentWebView != null)) {
+ // Update the privacy icon.
+ if (currentWebView!!.settings.javaScriptEnabled) // JavaScript is enabled.
+ optionsPrivacyMenuItem.setIcon(R.drawable.javascript_enabled)
+ else if (currentWebView!!.acceptCookies) // JavaScript is disabled but cookies are enabled.
+ optionsPrivacyMenuItem.setIcon(R.drawable.warning)
+ else // All the dangerous features are disabled.
+ optionsPrivacyMenuItem.setIcon(R.drawable.privacy_mode)
+
+ // Update the cookies icon.
+ if (currentWebView!!.acceptCookies)
+ optionsCookiesMenuItem.setIcon(R.drawable.cookies_enabled)
+ else
+ optionsCookiesMenuItem.setIcon(R.drawable.cookies_disabled)
+
+ // Update the refresh icon.
+ if (optionsRefreshMenuItem.title == getString(R.string.refresh)) // The refresh icon is displayed.
+ optionsRefreshMenuItem.setIcon(R.drawable.refresh_enabled)
+ else // The stop icon is displayed.
+ optionsRefreshMenuItem.setIcon(R.drawable.close_blue)
+
+ // `invalidateOptionsMenu()` calls `onPrepareOptionsMenu()` and redraws the icons in the app bar.
+ if (runInvalidateOptionsMenu)
+ invalidateOptionsMenu()
+ }
+ }
+
+ fun updateUrlEditTextAfterDelay() {
+ // Create a handler to update the URL edit box.
+ val urlEditTextUpdateHandler = Handler(Looper.getMainLooper())
+
+ // Create a runnable to update the URL edit box.
+ val urlEditTextUpdateRunnable = Runnable {
+ // Update the URL edit text.
+ urlEditText.setText(currentWebView!!.url)
+
+ // Disable the wide viewport if the source is being viewed.
+ if (currentWebView!!.url!!.startsWith("view-source:"))
+ currentWebView!!.settings.useWideViewPort = false
+ }
+
+ // Update the URL edit text after 50 milliseconds, so that the WebView has enough time to navigate to the new URL.
+ urlEditTextUpdateHandler.postDelayed(urlEditTextUpdateRunnable, 50)
+ }