]> gitweb.stoutner.com Git - PrivacyBrowserAndroid.git/blobdiff - app/src/main/java/com/stoutner/privacybrowser/MainWebViewActivity.java
Update icons. Release 1.0.
[PrivacyBrowserAndroid.git] / app / src / main / java / com / stoutner / privacybrowser / MainWebViewActivity.java
index 5d2307338092869f09aa82b47f3a7f3273772dfd..78138237289cf308b1588c84d539fa25512985de 100644 (file)
@@ -31,6 +31,7 @@ import android.os.Build;
 import android.os.Bundle;
 import android.preference.PreferenceManager;
 import android.support.v4.app.DialogFragment;
+import android.support.v4.widget.SwipeRefreshLayout;
 import android.support.v7.app.ActionBar;
 import android.support.v7.app.AppCompatActivity;
 import android.support.v7.app.AppCompatDialogFragment;
@@ -40,7 +41,6 @@ import android.view.KeyEvent;
 import android.view.Menu;
 import android.view.MenuItem;
 import android.view.View;
-import android.view.Window;
 import android.view.inputmethod.InputMethodManager;
 import android.webkit.CookieManager;
 import android.webkit.DownloadListener;
@@ -53,6 +53,10 @@ import android.widget.FrameLayout;
 import android.widget.ImageView;
 import android.widget.ProgressBar;
 import android.widget.Toast;
+
+import com.google.android.gms.ads.AdRequest;
+import com.google.android.gms.ads.AdView;
+
 import java.io.UnsupportedEncodingException;
 import java.net.MalformedURLException;
 import java.net.URL;
@@ -90,14 +94,9 @@ public class MainWebViewActivity extends AppCompatActivity implements CreateHome
     private EditText urlTextBox;
 
     @Override
-    // Remove Android Studio's warning about the dangers of using SetJavaScriptEnabled.
+    // Remove Android Studio's warning about the dangers of using SetJavaScriptEnabled.  The whole premise of Privacy Browser is built around an understanding of these dangers.
     @SuppressLint("SetJavaScriptEnabled")
     protected void onCreate(Bundle savedInstanceState) {
-        // Window.FEATURE_ACTION_BAR_OVERLAY must be enabled to set the app bar to HideOnContentScroll.  It must be set before any content is added to the activity.
-        if (Build.VERSION.SDK_INT >= 11) {
-            requestWindowFeature(Window.FEATURE_ACTION_BAR_OVERLAY);
-        }
-
         super.onCreate(savedInstanceState);
         setContentView(R.layout.activity_webview);
 
@@ -110,19 +109,22 @@ public class MainWebViewActivity extends AppCompatActivity implements CreateHome
         // We need to use the SupportActionBar from android.support.v7.app.ActionBar until the minimum API is >= 21.
         final ActionBar appBar = getSupportActionBar();
 
-        mainWebView = (WebView) findViewById(R.id.mainWebView);
+        // Setup the AdView for the free flavor.
+        final AdView adView = (AdView) findViewById(R.id.adView);
 
-        if (appBar != null) {
-            /* TODO Enable app bar scrolling.
-            // Scroll the app bar, but only if the API supports overlay mode (>= 11).
-            if (Build.VERSION.SDK_INT >= 11) {
-                appBar.setHideOnContentScrollEnabled(true);
+        // Implement swipe to refresh
+        final SwipeRefreshLayout swipeToRefresh = (SwipeRefreshLayout) findViewById(R.id.swipeRefreshLayout);
+        swipeToRefresh.setColorSchemeResources(R.color.blue);
+        swipeToRefresh.setOnRefreshListener(new SwipeRefreshLayout.OnRefreshListener() {
+            @Override
+            public void onRefresh() {
+                mainWebView.reload();
             }
-            */
+        });
 
-            // Remove the title from the app bar.
-            appBar.setDisplayShowTitleEnabled(false);
+        mainWebView = (WebView) findViewById(R.id.mainWebView);
 
+        if (appBar != null) {
             // Add the custom url_bar layout, which shows the favoriteIcon, urlTextBar, and progressBar.
             appBar.setCustomView(R.layout.url_bar);
             appBar.setDisplayOptions(ActionBar.DISPLAY_SHOW_CUSTOM);
@@ -189,6 +191,9 @@ public class MainWebViewActivity extends AppCompatActivity implements CreateHome
                         progressBar.setVisibility(View.VISIBLE);
                     } else {
                         progressBar.setVisibility(View.GONE);
+
+                        //Stop the SwipeToRefresh indicator if it is running
+                        swipeToRefresh.setRefreshing(false);
                     }
                 }
             }
@@ -213,11 +218,18 @@ public class MainWebViewActivity extends AppCompatActivity implements CreateHome
                     appBar.hide();
                 }
 
+                // Show the fullScreenVideoFrameLayout.
                 fullScreenVideoFrameLayout.addView(view);
                 fullScreenVideoFrameLayout.setVisibility(View.VISIBLE);
 
+                // Hide the mainWebView.
                 mainWebView.setVisibility(View.GONE);
 
+                // Hide the add if this is the free flavor.
+                if (getString(R.string.free_flavor).equals("true")) {
+                    adView.setVisibility(View.GONE);
+                }
+
                 /* SYSTEM_UI_FLAG_HIDE_NAVIGATION hides the navigation bars on the bottom or right of the screen.
                 ** SYSTEM_UI_FLAG_FULLSCREEN hides the status bar across the top of the screen.
                 ** SYSTEM_UI_FLAG_IMMERSIVE_STICKY makes the navigation and status bars ghosted overlays and automatically rehides them.
@@ -245,8 +257,15 @@ public class MainWebViewActivity extends AppCompatActivity implements CreateHome
                     appBar.show();
                 }
 
+                // Show the mainWebView.
                 mainWebView.setVisibility(View.VISIBLE);
 
+                // Show the adView if this is the free flavor.
+                if (getString(R.string.free_flavor).equals("true")) {
+                    adView.setVisibility(View.VISIBLE);
+                }
+
+                // Hide the fullScreenVideoFrameLayout.
                 fullScreenVideoFrameLayout.removeAllViews();
                 fullScreenVideoFrameLayout.setVisibility(View.GONE);
             }
@@ -269,7 +288,7 @@ public class MainWebViewActivity extends AppCompatActivity implements CreateHome
                 }
 
                 downloadManager.enqueue(requestUri);
-                Toast.makeText(mainWebViewActivity, "Download started", Toast.LENGTH_SHORT).show();
+                Toast.makeText(mainWebViewActivity, R.string.download_started, Toast.LENGTH_SHORT).show();
             }
         });
 
@@ -325,6 +344,12 @@ public class MainWebViewActivity extends AppCompatActivity implements CreateHome
 
         // Load the initial website.
         mainWebView.loadUrl(formattedUrlString);
+
+        // Load the ad if this is the free flavor.
+        if (getString(R.string.free_flavor).equals("true")) {
+            AdRequest adRequest = new AdRequest.Builder().build();
+            adView.loadAd(adRequest);
+        }
     }
 
     @Override
@@ -340,6 +365,9 @@ public class MainWebViewActivity extends AppCompatActivity implements CreateHome
 
         // Load the website.
         mainWebView.loadUrl(formattedUrlString);
+
+        // Clear the keyboard if displayed and remove the focus on the urlTextBar if it has it.
+        mainWebView.requestFocus();
     }
 
     @Override
@@ -435,7 +463,7 @@ public class MainWebViewActivity extends AppCompatActivity implements CreateHome
                         }
                     } else {
                         menuItem.setIcon(R.drawable.privacy_mode);
-                        Toast.makeText(getApplicationContext(), "Privacy Mode", Toast.LENGTH_SHORT).show();
+                        Toast.makeText(getApplicationContext(), R.string.privacy_mode, Toast.LENGTH_SHORT).show();
                     }
                 } else {
                     javaScriptEnabled = true;
@@ -456,7 +484,7 @@ public class MainWebViewActivity extends AppCompatActivity implements CreateHome
                     // Update the toggleJavaScript icon and display a toast message if appropriate.
                     if (!javaScriptEnabled && !cookiesEnabled) {
                         toggleJavaScript.setIcon(R.drawable.privacy_mode);
-                        Toast.makeText(getApplicationContext(), "Privacy Mode", Toast.LENGTH_SHORT).show();
+                        Toast.makeText(getApplicationContext(), R.string.privacy_mode, Toast.LENGTH_SHORT).show();
                     } else {
                         if (cookiesEnabled) {
                             toggleJavaScript.setIcon(R.drawable.warning);
@@ -504,7 +532,7 @@ public class MainWebViewActivity extends AppCompatActivity implements CreateHome
                     // Update the toggleJavaScript icon and display a toast message if appropriate.
                     if (!javaScriptEnabled && !domStorageEnabled) {
                         toggleJavaScript.setIcon(R.drawable.privacy_mode);
-                        Toast.makeText(getApplicationContext(), "Privacy Mode", Toast.LENGTH_SHORT).show();
+                        Toast.makeText(getApplicationContext(), R.string.privacy_mode, Toast.LENGTH_SHORT).show();
                     } else {
                         if (domStorageEnabled) {
                             toggleJavaScript.setIcon(R.drawable.warning);
@@ -563,10 +591,6 @@ public class MainWebViewActivity extends AppCompatActivity implements CreateHome
                 mainWebView.loadUrl(homepage);
                 return true;
 
-            case R.id.refresh:
-                mainWebView.reload();
-                return true;
-
             case R.id.back:
                 mainWebView.goBack();
                 return true;