]> gitweb.stoutner.com Git - PrivacyBrowserAndroid.git/blobdiff - app/src/main/java/com/stoutner/privacybrowser/activities/LogcatActivity.kt
Bump the target API to 36. https://redmine.stoutner.com/issues/1283
[PrivacyBrowserAndroid.git] / app / src / main / java / com / stoutner / privacybrowser / activities / LogcatActivity.kt
index 214ebf2149aaa6d9bf931ce3d6bec7f1b256b181..d430634302b8db5f1f0171df1733754eb1ee97af 100644 (file)
@@ -1,20 +1,20 @@
-/*
- * Copyright 2019-2024 Soren Stoutner <soren@stoutner.com>.
+/* SPDX-License-Identifier: GPL-3.0-or-later
+ * SPDX-FileCopyrightText: 2019-2025 Soren Stoutner <soren@stoutner.com>
  *
  * 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
- * the Free Software Foundation, either version 3 of the License, or
- * (at your option) any later version.
+ * This program 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.
  *
- * Privacy Browser Android 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.
+ * This program 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 Privacy Browser Android.  If not, see <http://www.gnu.org/licenses/>.
+ * You should have received a copy of the GNU General Public License along with
+ * this program.  If not, see <https://www.gnu.org/licenses/>.
  */
 
 package com.stoutner.privacybrowser.activities
@@ -62,7 +62,7 @@ import java.io.InputStreamReader
 import java.nio.charset.StandardCharsets
 
 // Define the class constants.
-private const val SCROLL_Y = "A"
+private const val SCROLL_Y = "scroll_y"
 
 class LogcatActivity : AppCompatActivity() {
     // Declare the class variables.
@@ -139,9 +139,9 @@ class LogcatActivity : AppCompatActivity() {
 
         // Get handles for the views.
         toolbar = findViewById(R.id.toolbar)
-        val searchCountTextView = findViewById<TextView>(R.id.search_count_textview)
         searchLinearLayout = findViewById(R.id.search_linearlayout)
         searchEditText = findViewById(R.id.search_edittext)
+        val searchCountTextView = findViewById<TextView>(R.id.search_count_textview)
         swipeRefreshLayout = findViewById(R.id.swiperefreshlayout)
         logcatWebView = findViewById(R.id.logcat_webview)
 
@@ -246,7 +246,7 @@ class LogcatActivity : AppCompatActivity() {
 
     override fun onOptionsItemSelected(menuItem: MenuItem): Boolean {
         // Run the commands that correlate to the selected menu item.
-        return when (menuItem.itemId) {
+        when (menuItem.itemId) {
             R.id.search -> {  // Search was selected.
                 // Set the minimum height of the search linear layout to match the toolbar.
                 searchLinearLayout.minimumHeight = toolbar.height
@@ -273,7 +273,7 @@ class LogcatActivity : AppCompatActivity() {
                 logcatWebView.resumeTimers()
 
                 // Consume the event.
-                true
+                return true
             }
 
             R.id.copy -> {  // Copy was selected.
@@ -291,7 +291,7 @@ class LogcatActivity : AppCompatActivity() {
                     Snackbar.make(logcatWebView, R.string.logcat_copied, Snackbar.LENGTH_SHORT).show()
 
                 // Consume the event.
-                true
+                return true
             }
 
             R.id.save -> {  // Save was selected.
@@ -299,7 +299,7 @@ class LogcatActivity : AppCompatActivity() {
                 saveLogcatActivityResultLauncher.launch(getString(R.string.privacy_browser_logcat_txt, BuildConfig.VERSION_NAME))
 
                 // Consume the event.
-                true
+                return true
             }
 
             R.id.clear -> {  // Clear was selected.
@@ -317,40 +317,22 @@ class LogcatActivity : AppCompatActivity() {
                 }
 
                 // Consume the event.
-                true
+                return true
             }
 
-            else -> {  // The home button was pushed.
+            else -> {  // The home button was selected.
                 // Do not consume the event.  The system will process the home command.
-                super.onOptionsItemSelected(menuItem)
+                return super.onOptionsItemSelected(menuItem)
             }
         }
     }
 
-    public override fun onSaveInstanceState(savedInstanceState: Bundle) {
+    public override fun onSaveInstanceState(outState: Bundle) {
         // Run the default commands.
-        super.onSaveInstanceState(savedInstanceState)
+        super.onSaveInstanceState(outState)
 
         // Store the scroll Y position in the bundle.
-        savedInstanceState.putInt(SCROLL_Y, logcatWebView.scrollY)
-    }
-
-    // The view parameter cannot be removed because it is called from the layout onClick.
-    fun closeSearch(@Suppress("UNUSED_PARAMETER")view: View?) {
-        // Delete the contents of the search edit text.
-        searchEditText.text = null
-
-        // Clear the highlighted phrases in the logcat WebView.
-        logcatWebView.clearMatches()
-
-        // Hide the search linear layout.
-        searchLinearLayout.visibility = View.GONE
-
-        // Show the toolbar.
-        toolbar.visibility = View.VISIBLE
-
-        // Hide the keyboard.
-        inputMethodManager.hideSoftInputFromWindow(toolbar.windowToken, 0)
+        outState.putInt(SCROLL_Y, logcatWebView.scrollY)
     }
 
     private fun populateLogcat() {
@@ -449,6 +431,24 @@ class LogcatActivity : AppCompatActivity() {
         swipeRefreshLayout.isRefreshing = false
     }
 
+    // The view parameter cannot be removed because it is called from the layout onClick.
+    fun closeSearch(@Suppress("UNUSED_PARAMETER")view: View?) {
+        // Delete the contents of the search edit text.
+        searchEditText.text = null
+
+        // Clear the highlighted phrases in the logcat WebView.
+        logcatWebView.clearMatches()
+
+        // Hide the search linear layout.
+        searchLinearLayout.visibility = View.GONE
+
+        // Show the toolbar.
+        toolbar.visibility = View.VISIBLE
+
+        // Hide the keyboard.
+        inputMethodManager.hideSoftInputFromWindow(toolbar.windowToken, 0)
+    }
+
     // The view parameter cannot be removed because it is called from the layout onClick.
     fun searchNext(@Suppress("UNUSED_PARAMETER")view: View?) {
         // Go to the next highlighted phrase on the page. `true` goes forwards instead of backwards.