X-Git-Url: https://gitweb.stoutner.com/?p=PrivacyBrowserAndroid.git;a=blobdiff_plain;f=app%2Fsrc%2Fmain%2Fjava%2Fcom%2Fstoutner%2Fprivacybrowser%2Factivities%2FViewSourceActivity.java;h=229bcf28ade37a7c7e51beb1ae1d1e7774003a7c;hp=bcb94c18ef74a1776c7cc59fcfd1d90fd4cf3b0b;hb=81179d84ced6b43360d42a4b44eb8fb329532ff4;hpb=729652a6a06a8c1bf6244c56089a9c0db84e283e diff --git a/app/src/main/java/com/stoutner/privacybrowser/activities/ViewSourceActivity.java b/app/src/main/java/com/stoutner/privacybrowser/activities/ViewSourceActivity.java index bcb94c18..229bcf28 100644 --- a/app/src/main/java/com/stoutner/privacybrowser/activities/ViewSourceActivity.java +++ b/app/src/main/java/com/stoutner/privacybrowser/activities/ViewSourceActivity.java @@ -20,10 +20,11 @@ package com.stoutner.privacybrowser.activities; import android.app.Activity; -import android.app.DialogFragment; import android.content.Context; import android.content.Intent; +import android.content.SharedPreferences; import android.os.Bundle; +import android.preference.PreferenceManager; import android.text.Spanned; import android.text.style.ForegroundColorSpan; import android.view.KeyEvent; @@ -34,10 +35,12 @@ import android.view.WindowManager; import android.view.inputmethod.InputMethodManager; import android.widget.EditText; +import androidx.annotation.NonNull; import androidx.appcompat.app.ActionBar; import androidx.appcompat.app.AppCompatActivity; import androidx.appcompat.widget.Toolbar; // The AndroidX toolbar must be used until the minimum API is >= 21. import androidx.core.app.NavUtils; +import androidx.fragment.app.DialogFragment; import androidx.swiperefreshlayout.widget.SwipeRefreshLayout; import com.stoutner.privacybrowser.R; @@ -55,13 +58,20 @@ public class ViewSourceActivity extends AppCompatActivity { @Override protected void onCreate(Bundle savedInstanceState) { + // Get a handle for the shared preferences. + SharedPreferences sharedPreferences = PreferenceManager.getDefaultSharedPreferences(getApplicationContext()); + + // Get the screenshot and theme preferences. + boolean allowScreenshots = sharedPreferences.getBoolean("allow_screenshots", false); + boolean darkTheme = sharedPreferences.getBoolean("dark_theme", false); + // Disable screenshots if not allowed. - if (!MainWebViewActivity.allowScreenshots) { + if (!allowScreenshots) { getWindow().addFlags(WindowManager.LayoutParams.FLAG_SECURE); } // Set the theme. - if (MainWebViewActivity.darkTheme) { + if (darkTheme) { setTheme(R.style.PrivacyBrowserDark); } else { setTheme(R.style.PrivacyBrowserLight); @@ -73,8 +83,9 @@ public class ViewSourceActivity extends AppCompatActivity { // Get the launching intent Intent intent = getIntent(); - // Get the user agent. + // Get the information from the intent. String userAgent = intent.getStringExtra("user_agent"); + String currentUrl = intent.getStringExtra("current_url"); // Store a handle for the current activity. activity = this; @@ -99,11 +110,8 @@ public class ViewSourceActivity extends AppCompatActivity { // Get a handle for the url text box. EditText urlEditText = findViewById(R.id.url_edittext); - // Get the formatted URL string from the main activity. - String formattedUrlString = MainWebViewActivity.formattedUrlString; - // Populate the URL text box. - urlEditText.setText(formattedUrlString); + urlEditText.setText(currentUrl); // Initialize the foreground color spans for highlighting the URLs. We have to use the deprecated `getColor()` until API >= 23. redColorSpan = new ForegroundColorSpan(getResources().getColor(R.color.red_a700)); @@ -164,8 +172,10 @@ public class ViewSourceActivity extends AppCompatActivity { } }); - // Implement swipe to refresh. + // Get a handle for the swipe refresh layout. SwipeRefreshLayout swipeRefreshLayout = findViewById(R.id.view_source_swiperefreshlayout); + + // Implement swipe to refresh. swipeRefreshLayout.setOnRefreshListener(() -> { // Get the URL. String url = urlEditText.getText().toString(); @@ -180,7 +190,7 @@ public class ViewSourceActivity extends AppCompatActivity { }); // Set the swipe to refresh color according to the theme. - if (MainWebViewActivity.darkTheme) { + if (darkTheme) { swipeRefreshLayout.setColorSchemeResources(R.color.blue_600); swipeRefreshLayout.setProgressBackgroundColorSchemeResource(R.color.gray_800); } else { @@ -188,8 +198,8 @@ public class ViewSourceActivity extends AppCompatActivity { } // Get the source using an AsyncTask if the URL begins with `http`. - if (formattedUrlString.startsWith("http")) { - new GetSource(this, userAgent).execute(formattedUrlString); + if ((currentUrl != null) && currentUrl.startsWith("http")) { + new GetSource(this, userAgent).execute(currentUrl); } } @@ -203,12 +213,12 @@ public class ViewSourceActivity extends AppCompatActivity { } @Override - public boolean onOptionsItemSelected(MenuItem menuItem) { + public boolean onOptionsItemSelected(@NonNull MenuItem menuItem) { // Get a handle for the about alert dialog. DialogFragment aboutDialogFragment = new AboutViewSourceDialog(); // Show the about alert dialog. - aboutDialogFragment.show(getFragmentManager(), getString(R.string.about)); + aboutDialogFragment.show(getSupportFragmentManager(), getString(R.string.about)); // Consume the event. return true;