X-Git-Url: https://gitweb.stoutner.com/?a=blobdiff_plain;f=app%2Fsrc%2Fmain%2Fjava%2Fcom%2Fstoutner%2Fprivacybrowser%2Factivities%2FViewHeadersActivity.kt;fp=app%2Fsrc%2Fmain%2Fjava%2Fcom%2Fstoutner%2Fprivacybrowser%2Factivities%2FViewHeadersActivity.kt;h=145ced5d4d1e9ee568a523fe44d1801487bf84e2;hb=99d687b50a4f750f0ca1f865b665931eecf511b5;hp=c8878c5fa772a4e53b824155ad4eb6ccbdfe8a3a;hpb=9a15b265860ef93cf1648c0bc30036895681f46a;p=PrivacyBrowserAndroid.git diff --git a/app/src/main/java/com/stoutner/privacybrowser/activities/ViewHeadersActivity.kt b/app/src/main/java/com/stoutner/privacybrowser/activities/ViewHeadersActivity.kt index c8878c5f..145ced5d 100644 --- a/app/src/main/java/com/stoutner/privacybrowser/activities/ViewHeadersActivity.kt +++ b/app/src/main/java/com/stoutner/privacybrowser/activities/ViewHeadersActivity.kt @@ -146,27 +146,23 @@ class ViewHeadersActivity: AppCompatActivity(), UntrustedSslCertificateListener responseBodyTitleTextView = findViewById(R.id.response_body_title_textview) val responseBodyTextView = findViewById(R.id.response_body_textview) - // Populate the URL text box. - urlEditText.setText(currentUrl) - // Initialize the gray foreground color spans for highlighting the URLs. initialGrayColorSpan = ForegroundColorSpan(getColor(R.color.gray_500)) finalGrayColorSpan = ForegroundColorSpan(getColor(R.color.gray_500)) redColorSpan = ForegroundColorSpan(getColor(R.color.red_text)) - // Apply text highlighting to the URL. - UrlHelper.highlightSyntax(urlEditText, initialGrayColorSpan, finalGrayColorSpan, redColorSpan) - // Get a handle for the input method manager, which is used to hide the keyboard. val inputMethodManager = (getSystemService(INPUT_METHOD_SERVICE) as InputMethodManager) // Remove the formatting from the URL when the user is editing the text. urlEditText.onFocusChangeListener = OnFocusChangeListener { _: View?, hasFocus: Boolean -> if (hasFocus) { // The user is editing the URL text box. - // Remove the highlighting. - urlEditText.text.removeSpan(redColorSpan) - urlEditText.text.removeSpan(initialGrayColorSpan) - urlEditText.text.removeSpan(finalGrayColorSpan) + // Get the foreground color spans. + val foregroundColorSpans: Array = urlEditText.text.getSpans(0, urlEditText.text.length, ForegroundColorSpan::class.java) + + // Remove each foreground color span that highlights the text. + for (foregroundColorSpan in foregroundColorSpans) + urlEditText.text.removeSpan(foregroundColorSpan) } else { // The user has stopped editing the URL text box. // Hide the soft keyboard. inputMethodManager.hideSoftInputFromWindow(urlEditText.windowToken, 0) @@ -174,11 +170,20 @@ class ViewHeadersActivity: AppCompatActivity(), UntrustedSslCertificateListener // Move to the beginning of the string. urlEditText.setSelection(0) + // Store the URL text in the intent, so update layout uses the new text if the app is restarted. + intent.putExtra(CURRENT_URL, urlEditText.text.toString()) + // Reapply the highlighting. UrlHelper.highlightSyntax(urlEditText, initialGrayColorSpan, finalGrayColorSpan, redColorSpan) } } + // Populate the URL text box. + urlEditText.setText(currentUrl) + + // Apply the initial text highlighting to the URL. + UrlHelper.highlightSyntax(urlEditText, initialGrayColorSpan, finalGrayColorSpan, redColorSpan) + // Set the refresh color scheme according to the theme. swipeRefreshLayout.setColorSchemeResources(R.color.blue_text)