*
* Download cookie code contributed 2017 Hendrik Knackstedt. Copyright assigned to Soren Stoutner <soren@stoutner.com>.
*
- * This file is part of Privacy Browser Android <https://www.stoutner.com/privacy-browser-android>.
+ * This file is part of Privacy Browser Android <https://www.stoutner.com/privacy-browser-android/>.
*
* Privacy Browser Android is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
private lateinit var findOnPageLinearLayout: LinearLayout
private lateinit var fullScreenVideoFrameLayout: FrameLayout
private lateinit var initialGrayColorSpan: ForegroundColorSpan
+ private lateinit var inputMethodManager: InputMethodManager
private lateinit var navigationBackMenuItem: MenuItem
private lateinit var navigationForwardMenuItem: MenuItem
private lateinit var navigationHistoryMenuItem: MenuItem
// Set the focus on the find on page edit text.
findOnPageEditText.requestFocus()
- // Get a handle for the input method manager.
- val inputMethodManager = (getSystemService(INPUT_METHOD_SERVICE) as InputMethodManager)
-
// Display the keyboard. `0` sets no input flags.
inputMethodManager.showSoftInput(findOnPageEditText, 0)
}, 200)
// Show the toolbar.
toolbar.visibility = View.VISIBLE
- // Get a handle for the input method manager.
- val inputMethodManager = (getSystemService(INPUT_METHOD_SERVICE) as InputMethodManager)
-
// Hide the keyboard.
inputMethodManager.hideSoftInputFromWindow(toolbar.windowToken, 0)
}
@SuppressLint("ClickableViewAccessibility")
private fun initializeApp() {
// Get a handle for the input method.
- val inputMethodManager = (getSystemService(INPUT_METHOD_SERVICE) as InputMethodManager)
+ inputMethodManager = (getSystemService(INPUT_METHOD_SERVICE) as InputMethodManager)
// Initialize the color spans for highlighting the URLs.
initialGrayColorSpan = ForegroundColorSpan(getColor(R.color.gray_500))
// Search for the string on the page whenever a character changes in the find on page edit text.
findOnPageEditText.addTextChangedListener(object : TextWatcher {
- override fun beforeTextChanged(s: CharSequence, start: Int, count: Int, after: Int) {}
+ override fun beforeTextChanged(charSequence: CharSequence, start: Int, count: Int, after: Int) {
+ // Do nothing.
+ }
- override fun onTextChanged(s: CharSequence, start: Int, before: Int, count: Int) {}
+ override fun onTextChanged(charSequence: CharSequence, start: Int, before: Int, count: Int) {
+ // Do nothing.
+ }
- override fun afterTextChanged(s: Editable) {
+ override fun afterTextChanged(editable: Editable) {
// Search for the text in the WebView if it is not null. Sometimes on resume after a period of non-use the WebView will be null.
currentWebView?.findAllAsync(findOnPageEditText.text.toString())
}
}
}
- // Get a handle for the input method manager.
- val inputMethodManager = getSystemService(INPUT_METHOD_SERVICE) as InputMethodManager
-
// Set the app bar scrolling.
nestedScrollWebView.isNestedScrollingEnabled = scrollAppBar
// Instantiate an HTTP authentication dialog.
val httpAuthenticationDialogFragment = HttpAuthenticationDialog.displayDialog(host, realm, nestedScrollWebView.webViewFragmentId)
- // Show the HTTP authentication dialog.
- httpAuthenticationDialogFragment.show(supportFragmentManager, getString(R.string.http_authentication))
+ // Try to show the dialog. WebView can receive an HTTP authentication request even after the app has been paused. Attempting to display a dialog in that state leads to a crash.
+ try {
+ // Show the HTTP authentication dialog.
+ httpAuthenticationDialogFragment.show(supportFragmentManager, getString(R.string.http_authentication))
+ } catch (exception: Exception) { // The dialog could not be shown.
+ // Add the dialog to the pending dialog array list. It will be displayed in `onStart()`.
+ pendingDialogsArrayList.add(PendingDialogDataClass(httpAuthenticationDialogFragment, getString(R.string.http_authentication)))
+ }
}
override fun onPageStarted(webView: WebView, url: String, favicon: Bitmap?) {
// Instantiate an SSL certificate error alert dialog.
val sslCertificateErrorDialogFragment = SslCertificateErrorDialog.displayDialog(error, nestedScrollWebView.webViewFragmentId)
- // Try to show the dialog. The SSL error handler continues to function even when the WebView is paused. Attempting to display a dialog in that state leads to a crash.
+ // Try to show the dialog. The SSL error handler continues to function even when the app has been stopped. Attempting to display a dialog in that state leads to a crash.
try {
// Show the SSL certificate error dialog.
sslCertificateErrorDialogFragment.show(supportFragmentManager, getString(R.string.ssl_certificate_error))
// Update the privacy icons. `true` redraws the icons in the app bar.
updatePrivacyIcons(true)
- // Get a handle for the input method manager.
- val inputMethodManager = (getSystemService(INPUT_METHOD_SERVICE) as InputMethodManager)
-
// Get the current URL.
val urlString = currentWebView!!.url