]> gitweb.stoutner.com Git - PrivacyBrowserAndroid.git/blobdiff - app/src/main/java/com/stoutner/privacybrowser/activities/MainWebViewActivity.java
Modify the intent filters to make it easier for other browsers to share URLs with...
[PrivacyBrowserAndroid.git] / app / src / main / java / com / stoutner / privacybrowser / activities / MainWebViewActivity.java
index e393e31082470dfdedcb4a9fd01e3492bed332dc..ef226d7f5b9c6cbd29613b468ce55f9acae707f1 100644 (file)
@@ -326,7 +326,11 @@ public class MainWebViewActivity extends AppCompatActivity implements CreateBook
     // Declare the class views.
     private DrawerLayout drawerLayout;
     private AppBarLayout appBarLayout;
+    private Toolbar toolbar;
+    private LinearLayout findOnPageLinearLayout;
+    private LinearLayout tabsLinearLayout;
     private TabLayout tabLayout;
+    private SwipeRefreshLayout swipeRefreshLayout;
     private ViewPager webViewPager;
 
     @Override
@@ -394,8 +398,11 @@ public class MainWebViewActivity extends AppCompatActivity implements CreateBook
         // Get handles for the views.
         drawerLayout = findViewById(R.id.drawerlayout);
         appBarLayout = findViewById(R.id.appbar_layout);
-        Toolbar toolbar = findViewById(R.id.toolbar);
+        toolbar = findViewById(R.id.toolbar);
+        findOnPageLinearLayout = findViewById(R.id.find_on_page_linearlayout);
+        tabsLinearLayout = findViewById(R.id.tabs_linearlayout);
         tabLayout = findViewById(R.id.tablayout);
+        swipeRefreshLayout = findViewById(R.id.swiperefreshlayout);
         webViewPager = findViewById(R.id.webviewpager);
 
         // Get a handle for the app compat delegate.
@@ -447,17 +454,18 @@ public class MainWebViewActivity extends AppCompatActivity implements CreateBook
         // Replace the intent that started the app with this one.
         setIntent(intent);
 
-        // Check to see if the app is being restarted.
-        if (savedStateArrayList == null || savedStateArrayList.size() == 0) {  // The activity is running for the first time.
+        // Check to see if the app is being restarted from a saved state.
+        if (savedStateArrayList == null || savedStateArrayList.size() == 0) {  // The activity is not being restarted from a saved state.
             // Get the information from the intent.
             String intentAction = intent.getAction();
             Uri intentUriData = intent.getData();
+            String intentStringExtra = intent.getStringExtra(Intent.EXTRA_TEXT);
 
             // Determine if this is a web search.
             boolean isWebSearch = ((intentAction != null) && intentAction.equals(Intent.ACTION_WEB_SEARCH));
 
             // Only process the URI if it contains data or it is a web search.  If the user pressed the desktop icon after the app was already running the URI will be null.
-            if (intentUriData != null || isWebSearch) {
+            if (intentUriData != null || intentStringExtra != null || isWebSearch) {
                 // Get the shared preferences.
                 SharedPreferences sharedPreferences = PreferenceManager.getDefaultSharedPreferences(this);
 
@@ -478,9 +486,12 @@ public class MainWebViewActivity extends AppCompatActivity implements CreateBook
 
                     // Add the base search URL.
                     url = searchURL + encodedUrlString;
-                } else {  // The intent should contain a URL.
+                } else if (intentUriData != null) {  // The intent contains a URL formatted as a URI.
                     // Set the intent data as the URL.
                     url = intentUriData.toString();
+                } else {  // The intent contains a string, which might be a URL.
+                    // Set the intent string as the URL.
+                    url = intentStringExtra;
                 }
 
                 // Add a new tab if specified in the preferences.
@@ -3583,10 +3594,6 @@ public class MainWebViewActivity extends AppCompatActivity implements CreateBook
         // Get handles for the views that need to be modified.
         FrameLayout rootFrameLayout = findViewById(R.id.root_framelayout);
         ActionBar actionBar = appCompatDelegate.getSupportActionBar();
-        Toolbar toolbar = findViewById(R.id.toolbar);
-        LinearLayout findOnPageLinearLayout = findViewById(R.id.find_on_page_linearlayout);
-        LinearLayout tabsLinearLayout = findViewById(R.id.tabs_linearlayout);
-        SwipeRefreshLayout swipeRefreshLayout = findViewById(R.id.swiperefreshlayout);
 
         // Remove the incorrect lint warning below that the action bar might be null.
         assert actionBar != null;
@@ -4658,7 +4665,7 @@ public class MainWebViewActivity extends AppCompatActivity implements CreateBook
         ultraList = combinedBlocklists.get(4);
         ultraPrivacy = combinedBlocklists.get(5);
 
-        // Check to see if the activity has been restarted.
+        // Check to see if the activity has been restarted with a saved state.
         if ((savedStateArrayList == null) || (savedStateArrayList.size() == 0)) {  // The activity has not been restarted or it was restarted on start to force the night theme.
             // Add the first tab.
             addNewTab("", true);
@@ -4703,12 +4710,13 @@ public class MainWebViewActivity extends AppCompatActivity implements CreateBook
             // Get the information from the intent.
             String intentAction = intent.getAction();
             Uri intentUriData = intent.getData();
+            String intentStringExtra = intent.getStringExtra(Intent.EXTRA_TEXT);
 
             // Determine if this is a web search.
             boolean isWebSearch = ((intentAction != null) && intentAction.equals(Intent.ACTION_WEB_SEARCH));
 
             // Only process the URI if it contains data or it is a web search.  If the user pressed the desktop icon after the app was already running the URI will be null.
-            if (intentUriData != null || isWebSearch) {
+            if (intentUriData != null || intentStringExtra != null || isWebSearch) {
                 // Get the shared preferences.
                 SharedPreferences sharedPreferences = PreferenceManager.getDefaultSharedPreferences(this);
 
@@ -4729,9 +4737,12 @@ public class MainWebViewActivity extends AppCompatActivity implements CreateBook
 
                     // Add the base search URL.
                     url = searchURL + encodedUrlString;
-                } else {  // The intent should contain a URL.
-                    // Set the intent data as the url.
+                } else if (intentUriData != null) {  // The intent contains a URL formatted as a URI.
+                    // Set the intent data as the URL.
                     url = intentUriData.toString();
+                } else {  // The intent contains a string, which might be a URL.
+                    // Set the intent string as the URL.
+                    url = intentStringExtra;
                 }
 
                 // Add a new tab if specified in the preferences.
@@ -5270,8 +5281,14 @@ public class MainWebViewActivity extends AppCompatActivity implements CreateBook
                             // Hide the action bar.
                             actionBar.hide();
 
-                            // If the app bar is not being scrolled, the swipe refresh layout needs to be adjusted.
-                            if (!scrollAppBar) {
+                            // Check to see if the app bar is normally scrolled.
+                            if (scrollAppBar) {  // The app bar is scrolled when it is displayed.
+                                // Get the swipe refresh layout parameters.
+                                CoordinatorLayout.LayoutParams swipeRefreshLayoutParams = (CoordinatorLayout.LayoutParams) swipeRefreshLayout.getLayoutParams();
+
+                                // Remove the off-screen scrolling layout.
+                                swipeRefreshLayoutParams.setBehavior(null);
+                            } else {  // The app bar is not scrolled when it is displayed.
                                 // Remove the padding from the top of the swipe refresh layout.
                                 swipeRefreshLayout.setPadding(0, 0, 0, 0);
 
@@ -5302,8 +5319,14 @@ public class MainWebViewActivity extends AppCompatActivity implements CreateBook
                             // Show the action bar.
                             actionBar.show();
 
-                            // If the app bar is not being scrolled, the swipe refresh layout needs to be adjusted.
-                            if (!scrollAppBar) {
+                            // Check to see if the app bar is normally scrolled.
+                            if (scrollAppBar) {  // The app bar is scrolled when it is displayed.
+                                // Get the swipe refresh layout parameters.
+                                CoordinatorLayout.LayoutParams swipeRefreshLayoutParams = (CoordinatorLayout.LayoutParams) swipeRefreshLayout.getLayoutParams();
+
+                                // Add the off-screen scrolling layout.
+                                swipeRefreshLayoutParams.setBehavior(new AppBarLayout.ScrollingViewBehavior());
+                            } else {  // The app bar is not scrolled when it is displayed.
                                 // The swipe refresh layout must be manually moved below the app bar layout.
                                 swipeRefreshLayout.setPadding(0, appBarHeight, 0, 0);
 
@@ -6400,6 +6423,7 @@ public class MainWebViewActivity extends AppCompatActivity implements CreateBook
             // Get the information from the intent.
             String launchingIntentAction = launchingIntent.getAction();
             Uri launchingIntentUriData = launchingIntent.getData();
+            String launchingIntentStringExtra = launchingIntent.getStringExtra(Intent.EXTRA_TEXT);
 
             // Parse the launching intent URL.
             if ((launchingIntentAction != null) && launchingIntentAction.equals(Intent.ACTION_WEB_SEARCH)) {  // The intent contains a search string.
@@ -6415,13 +6439,12 @@ public class MainWebViewActivity extends AppCompatActivity implements CreateBook
 
                 // Store the web search as the URL to load.
                 urlToLoadString = searchURL + encodedUrlString;
-            } else if (launchingIntentUriData != null){  // The intent contains a URL.
-                // Store the URL.
+            } else if (launchingIntentUriData != null) {  // The launching intent contains a URL formatted as a URI.
+                // Store the URI as a URL.
                 urlToLoadString = launchingIntentUriData.toString();
-
-                // Reset the intent.  This prevents a duplicate tab from being created on a subsequent restart if loading an link from a new intent on restart.
-                // For example, this prevents a duplicate tab if a link is loaded from the Guide after changing the theme in the guide and then changing the theme again in the main activity.
-                setIntent(new Intent());
+            } else if (launchingIntentStringExtra != null) {  // The launching intent contains text that might be a URL.
+                // Store the URL.
+                urlToLoadString = launchingIntentStringExtra;
             } else if (!url.equals("")) {  // The activity has been restarted.
                 // Load the saved URL.
                 urlToLoadString = url;
@@ -6436,6 +6459,10 @@ public class MainWebViewActivity extends AppCompatActivity implements CreateBook
             } else {  // Load the URL.
                 loadUrl(nestedScrollWebView, urlToLoadString);
             }
+
+            // Reset the intent.  This prevents a duplicate tab from being created on a subsequent restart if loading an link from a new intent on restart.
+            // For example, this prevents a duplicate tab if a link is loaded from the Guide after changing the theme in the guide and then changing the theme again in the main activity.
+            setIntent(new Intent());
         } else {  // This is not the first tab.
             // Load the URL.
             loadUrl(nestedScrollWebView, url);