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;
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;
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;
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);
// 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);
progressBar.setVisibility(View.VISIBLE);
} else {
progressBar.setVisibility(View.GONE);
+
+ //Stop the SwipeToRefresh indicator if it is running
+ swipeToRefresh.setRefreshing(false);
}
}
}
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.
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);
}
}
downloadManager.enqueue(requestUri);
- Toast.makeText(mainWebViewActivity, "Download started", Toast.LENGTH_SHORT).show();
+ Toast.makeText(mainWebViewActivity, R.string.download_started, Toast.LENGTH_SHORT).show();
}
});
// 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
// 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
}
} 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;
// 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);
// 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);
mainWebView.loadUrl(homepage);
return true;
- case R.id.refresh:
- mainWebView.reload();
- return true;
-
case R.id.back:
mainWebView.goBack();
return true;