Add option to download with external program. https://redmine.stoutner.com/issues/333
[PrivacyBrowser.git] / app / src / main / java / com / stoutner / privacybrowser / fragments / GuideTabFragment.java
index 2a9d0666f17eef6fdd8cd116291b03210fa608ff..d22006cd2eb0efb288bd549adeccd96c54e4c0f0 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright © 2016-2017 Soren Stoutner <soren@stoutner.com>.
+ * Copyright © 2016-2018 Soren Stoutner <soren@stoutner.com>.
  *
  * This file is part of Privacy Browser <https://www.stoutner.com/privacy-browser>.
  *
@@ -19,9 +19,9 @@
 
 package com.stoutner.privacybrowser.fragments;
 
-import android.graphics.ColorMatrixColorFilter;
-import android.graphics.Paint;
+import android.annotation.SuppressLint;
 import android.os.Bundle;
+import android.support.annotation.NonNull;
 import android.support.v4.app.Fragment;
 import android.view.LayoutInflater;
 import android.view.View;
@@ -35,90 +35,136 @@ public class GuideTabFragment extends Fragment {
     // `tabNumber` is used in `onCreate()` and `onCreateView()`.
     private int tabNumber;
 
-    // GuideTabFragment.createTab stores the tab number in the bundle arguments so it can be referenced from onCreate().
+    // Store the tab number in the arguments bundle.
     public static GuideTabFragment createTab (int tab) {
-        Bundle thisTabArguments = new Bundle();
-        thisTabArguments.putInt("Tab", tab);
+        // Create a bundle.
+        Bundle bundle = new Bundle();
 
-        GuideTabFragment thisTab = new GuideTabFragment();
-        thisTab.setArguments(thisTabArguments);
-        return thisTab;
+        // Store the tab number in the bundle.
+        bundle.putInt("Tab", tab);
+
+        // Add the bundle to the fragment.
+        GuideTabFragment guideTabFragment = new GuideTabFragment();
+        guideTabFragment.setArguments(bundle);
+
+        // Return the new fragment.
+        return guideTabFragment;
     }
 
     @Override
     public void onCreate(Bundle savedInstanceState) {
+        // Run the default commands.
         super.onCreate(savedInstanceState);
 
-        // Store the tab number in `tabNumber`.
+        // Remove the lint warning that `getArguments()` might be null.
+        assert getArguments() != null;
+
+        // Store the tab number in a class variable.
         tabNumber = getArguments().getInt("Tab");
     }
 
+    @SuppressLint("SetJavaScriptEnabled")
     @Override
-    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
+    public View onCreateView(@NonNull LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
         // Setting false at the end of inflater.inflate does not attach the inflated layout as a child of container.  The fragment will take care of attaching the root automatically.
         View tabLayout = inflater.inflate(R.layout.bare_webview, container, false);
 
         // Get a handle for `tabWebView`.
         WebView tabWebView = (WebView) tabLayout;
 
-        // Filter the colors if `darkTheme` is `true`.
-        if (MainWebViewActivity.darkTheme) {
-            // Initialize `darkPaint`.
-            Paint darkPaint = new Paint();
-
-            // Setup a float array that inverts and tempers the colors (no hard whites or blacks).
-            float[] darkFilterFloatArray = {
-                    -.8f, 0, 0, 0, 255,  // Red.
-                    0, -.8f, 0, 0, 255,  // Green.
-                    0, 0, -.8f, 0, 255,  // Blue.
-                    0, 0, 0, .8f, 0      // Alpha.
-            };
-
-            // Set `darkPaint` to use `darkFilterFloatArray`.
-            darkPaint.setColorFilter(new ColorMatrixColorFilter(darkFilterFloatArray));
-
-            // Apply `darkPaint` to `tabWebView`.
-            tabWebView.setLayerType(View.LAYER_TYPE_HARDWARE, darkPaint);
-        } else {
-            // Reset `tabWebView` to use the normal colors.
-            tabWebView.setLayerType(View.LAYER_TYPE_HARDWARE, null);
-        }
-
-        // Tab numbers start at 0.
-        switch (tabNumber) {
-            case 0:
-                tabWebView.loadUrl("file:///android_asset/" + getString(R.string.android_asset_path) + "/guide_overview.html");
-                break;
-
-            case 1:
-                tabWebView.loadUrl("file:///android_asset/" + getString(R.string.android_asset_path) + "/guide_javascript.html");
-                break;
-
-            case 2:
-                tabWebView.loadUrl("file:///android_asset/" + getString(R.string.android_asset_path) + "/guide_local_storage.html");
-                break;
-
-            case 3:
-                tabWebView.loadUrl("file:///android_asset/" + getString(R.string.android_asset_path) + "/guide_user_agent.html");
-                break;
-
-            case 4:
-                tabWebView.loadUrl("file:///android_asset/" + getString(R.string.android_asset_path) + "/guide_domain_settings.html");
-                break;
-
-            case 5:
-                tabWebView.loadUrl("file:///android_asset/" + getString(R.string.android_asset_path) + "/guide_ssl_certificate_pinning.html");
-                break;
-
-            case 6:
-                tabWebView.loadUrl("file:///android_asset/" + getString(R.string.android_asset_path) + "/guide_tor.html");
-                break;
-
-            case 7:
-                tabWebView.loadUrl("file:///android_asset/" + getString(R.string.android_asset_path) + "/guide_tracking_ids.html");
-                break;
+        // Load the tabs according to the theme.
+        if (MainWebViewActivity.darkTheme) {  // The dark theme is applied.
+            // Set the background color.  The deprecated `.getColor()` must be used until API >= 23.
+            //noinspection deprecation
+            tabWebView.setBackgroundColor(getResources().getColor(R.color.gray_850));
+
+            // Tab numbers start at 0.
+            switch (tabNumber) {
+                case 0:
+                    tabWebView.loadUrl("file:///android_asset/" + getString(R.string.android_asset_path) + "/guide_overview_dark.html");
+                    break;
+
+                case 1:
+                    tabWebView.loadUrl("file:///android_asset/" + getString(R.string.android_asset_path) + "/guide_javascript_dark.html");
+                    break;
+
+                case 2:
+                    tabWebView.loadUrl("file:///android_asset/" + getString(R.string.android_asset_path) + "/guide_local_storage_dark.html");
+                    break;
+
+                case 3:
+                    tabWebView.loadUrl("file:///android_asset/" + getString(R.string.android_asset_path) + "/guide_user_agent_dark.html");
+                    break;
+
+                case 4:
+                    tabWebView.loadUrl("file:///android_asset/" + getString(R.string.android_asset_path) + "/guide_requests_dark.html");
+                    break;
+
+                case 5:
+                    tabWebView.loadUrl("file:///android_asset/" + getString(R.string.android_asset_path) + "/guide_domain_settings_dark.html");
+                    break;
+
+                case 6:
+                    tabWebView.loadUrl("file:///android_asset/" + getString(R.string.android_asset_path) + "/guide_ssl_certificates_dark.html");
+                    break;
+
+                case 7:
+                    tabWebView.loadUrl("file:///android_asset/" + getString(R.string.android_asset_path) + "/guide_tor_dark.html");
+                    break;
+
+                case 8:
+                    tabWebView.loadUrl("file:///android_asset/" + getString(R.string.android_asset_path) + "/guide_tracking_ids_dark.html");
+                    break;
+
+                case 9:
+                    tabWebView.loadUrl("file:///android_asset/" + getString(R.string.android_asset_path) + "/guide_bookmarks_dark.html");
+                    break;
+            }
+        } else {  // The light theme is applied.
+            // Tab numbers start at 0.
+            switch (tabNumber) {
+                case 0:
+                    tabWebView.loadUrl("file:///android_asset/" + getString(R.string.android_asset_path) + "/guide_overview_light.html");
+                    break;
+
+                case 1:
+                    tabWebView.loadUrl("file:///android_asset/" + getString(R.string.android_asset_path) + "/guide_javascript_light.html");
+                    break;
+
+                case 2:
+                    tabWebView.loadUrl("file:///android_asset/" + getString(R.string.android_asset_path) + "/guide_local_storage_light.html");
+                    break;
+
+                case 3:
+                    tabWebView.loadUrl("file:///android_asset/" + getString(R.string.android_asset_path) + "/guide_user_agent_light.html");
+                    break;
+
+                case 4:
+                    tabWebView.loadUrl("file:///android_asset/" + getString(R.string.android_asset_path) + "/guide_requests_light.html");
+                    break;
+
+                case 5:
+                    tabWebView.loadUrl("file:///android_asset/" + getString(R.string.android_asset_path) + "/guide_domain_settings_light.html");
+                    break;
+
+                case 6:
+                    tabWebView.loadUrl("file:///android_asset/" + getString(R.string.android_asset_path) + "/guide_ssl_certificates_light.html");
+                    break;
+
+                case 7:
+                    tabWebView.loadUrl("file:///android_asset/" + getString(R.string.android_asset_path) + "/guide_tor_light.html");
+                    break;
+
+                case 8:
+                    tabWebView.loadUrl("file:///android_asset/" + getString(R.string.android_asset_path) + "/guide_tracking_ids_light.html");
+                    break;
+
+                case 9:
+                    tabWebView.loadUrl("file:///android_asset/" + getString(R.string.android_asset_path) + "/guide_bookmarks_light.html");
+            }
         }
 
+        // Return the formatted `tabLayout`.
         return tabLayout;
     }
-}
+}
\ No newline at end of file