X-Git-Url: https://gitweb.stoutner.com/?a=blobdiff_plain;f=app%2Fsrc%2Fmain%2Fjava%2Fcom%2Fstoutner%2Fprivacybrowser%2FMainWebViewActivity.java;h=2919a2229d3297bc5baa13f1a19587ac6805deb6;hb=cdbd0fea022e075e46906307cbf889cac5325dd5;hp=5d2307338092869f09aa82b47f3a7f3273772dfd;hpb=81aeaac4229700db3255a6d6c02a8bda18b403e6;p=PrivacyBrowserAndroid.git diff --git a/app/src/main/java/com/stoutner/privacybrowser/MainWebViewActivity.java b/app/src/main/java/com/stoutner/privacybrowser/MainWebViewActivity.java index 5d230733..2919a222 100644 --- a/app/src/main/java/com/stoutner/privacybrowser/MainWebViewActivity.java +++ b/app/src/main/java/com/stoutner/privacybrowser/MainWebViewActivity.java @@ -1,7 +1,7 @@ /** * Copyright 2015-2016 Soren Stoutner . * - * This file is part of Privacy Browser. + * This file is part of Privacy Browser . * * Privacy Browser is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -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,7 @@ import android.widget.FrameLayout; import android.widget.ImageView; import android.widget.ProgressBar; import android.widget.Toast; + import java.io.UnsupportedEncodingException; import java.net.MalformedURLException; import java.net.URL; @@ -90,14 +91,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 +106,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 AdView for the free flavor. + final View 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 +188,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 +215,16 @@ 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 ad if this is the free flavor. + BannerAd.hideAd(adView); + /* 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 +252,13 @@ public class MainWebViewActivity extends AppCompatActivity implements CreateHome appBar.show(); } + // Show the mainWebView. mainWebView.setVisibility(View.VISIBLE); + // Show the ad if this is the free flavor. + BannerAd.showAd(adView); + + // Hide the fullScreenVideoFrameLayout. fullScreenVideoFrameLayout.removeAllViews(); fullScreenVideoFrameLayout.setVisibility(View.GONE); } @@ -269,7 +281,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(); } }); @@ -306,7 +318,7 @@ public class MainWebViewActivity extends AppCompatActivity implements CreateHome cookieManager = CookieManager.getInstance(); cookieManager.setAcceptCookie(cookiesEnabled); - // Set hompage initial status. + // Set homepage initial status. homepage = savedPreferences.getString("homepage", "https://www.duckduckgo.com"); // Get the intent information that started the app. @@ -325,6 +337,9 @@ public class MainWebViewActivity extends AppCompatActivity implements CreateHome // Load the initial website. mainWebView.loadUrl(formattedUrlString); + + // Load the ad if this is the free flavor. + BannerAd.requestAd(adView); } @Override @@ -340,6 +355,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 +453,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 +474,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 +522,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); @@ -551,22 +569,18 @@ public class MainWebViewActivity extends AppCompatActivity implements CreateHome case R.id.downloads: // Launch the system Download Manager. - Intent downloadManangerIntent = new Intent(DownloadManager.ACTION_VIEW_DOWNLOADS); + Intent downloadManagerIntent = new Intent(DownloadManager.ACTION_VIEW_DOWNLOADS); // Launch as a new task so that Download Manager and Privacy Browser show as separate windows in the recent tasks list. - downloadManangerIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK); + downloadManagerIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK); - startActivity(downloadManangerIntent); + startActivity(downloadManagerIntent); return true; case R.id.home: mainWebView.loadUrl(homepage); return true; - case R.id.refresh: - mainWebView.reload(); - return true; - case R.id.back: mainWebView.goBack(); return true; @@ -659,7 +673,7 @@ public class MainWebViewActivity extends AppCompatActivity implements CreateHome } } - public void loadUrlFromTextBox() throws UnsupportedEncodingException { + private void loadUrlFromTextBox() throws UnsupportedEncodingException { // Get the text from urlTextBox and convert it to a string. String unformattedUrlString = urlTextBox.getText().toString(); URL unformattedUrl = null;