+ // Place the headers string in a clip data.
+ val headersClipData = ClipData.newPlainText(getString(R.string.view_headers), headersString)
+
+ // Place the clip data on the clipboard.
+ clipboardManager.setPrimaryClip(headersClipData)
+
+ // Display a snackbar if the API <= 32 (Android 12L). Beginning in Android 13 the OS displays a notification that covers up the snackbar.
+ if (Build.VERSION.SDK_INT <= 32)
+ Snackbar.make(urlEditText, R.string.headers_copied, Snackbar.LENGTH_SHORT).show()
+
+ // Consume the event.
+ return true
+ }
+
+ R.id.share_headers -> { // Share the headers.
+ // Get the headers string.
+ val headersString = getHeadersString()
+
+ // Create a share intent.
+ val shareIntent = Intent(Intent.ACTION_SEND)
+
+ // Add the headers string to the intent.
+ shareIntent.putExtra(Intent.EXTRA_TEXT, headersString)
+
+ // Set the MIME type.
+ shareIntent.type = "text/plain"
+
+ // Set the intent to open in a new task.
+ shareIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK)
+
+ // Make it so.
+ startActivity(Intent.createChooser(shareIntent, getString(R.string.share)))
+
+ // Consume the event.
+ return true
+ }
+
+ R.id.save_headers -> { // Save the headers as a text file.
+ // Get the current URL.
+ val currentUrlString = urlEditText.text.toString()
+
+ // Get a URI for the current URL.
+ val currentUri = Uri.parse(currentUrlString)
+
+ // Get the current domain name.
+ val currentDomainName = currentUri.host
+
+ // Open the file picker.
+ saveTextActivityResultLauncher.launch(getString(R.string.headers_txt, currentDomainName))
+
+ // Consume the event.
+ return true
+ }
+
+ R.id.about_view_headers -> { // Display the about dialog.
+ // Instantiate the about dialog fragment.
+ val aboutDialogFragment = AboutViewHeadersDialog()
+
+ // Show the about alert dialog.
+ aboutDialogFragment.show(supportFragmentManager, getString(R.string.about))
+
+ // Consume the event.
+ return true
+ }
+
+ else -> { // The home button was selected.
+ // Run the parents class on return.
+ return super.onOptionsItemSelected(menuItem)
+ }
+ }