X-Git-Url: https://gitweb.stoutner.com/?p=PrivacyBrowserAndroid.git;a=blobdiff_plain;f=app%2Fsrc%2Fmain%2Fjava%2Fcom%2Fstoutner%2Fprivacybrowser%2FMainWebViewActivity.java;h=9e2d04966bea426ec9b6f00cce75ddb015cfb235;hp=f2f8b040d5f0c4bf880ead557ce42da68c9c0bcb;hb=77756d29db4d52a35a3999f67b101e22525c97e2;hpb=7db44ba42c42745594e96b198be77c29c586920e diff --git a/app/src/main/java/com/stoutner/privacybrowser/MainWebViewActivity.java b/app/src/main/java/com/stoutner/privacybrowser/MainWebViewActivity.java index f2f8b040..9e2d0496 100644 --- a/app/src/main/java/com/stoutner/privacybrowser/MainWebViewActivity.java +++ b/app/src/main/java/com/stoutner/privacybrowser/MainWebViewActivity.java @@ -101,9 +101,10 @@ public class MainWebViewActivity extends AppCompatActivity implements Navigation private String formattedUrlString; // privacyIcon is used in onCreateOptionsMenu() and updatePrivacyIcon(). private MenuItem privacyIcon; - // urlTextBox is used in onCreate(), onOptionsItemSelected(), and loadUrlFromTextBox(). private EditText urlTextBox; + // adView is used in onCreate() and onConfigurationChanged(). + private View adView; @Override // 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. @@ -121,9 +122,6 @@ public class MainWebViewActivity extends AppCompatActivity implements Navigation // We need to use the SupportActionBar from android.support.v7.app.ActionBar until the minimum API is >= 21. final ActionBar appBar = getSupportActionBar(); - // Setup AdView for the free flavor. - final View adView = findViewById(R.id.adView); - // Implement swipe to refresh swipeToRefresh = (SwipeRefreshLayout) findViewById(R.id.swipeRefreshLayout); swipeToRefresh.setColorSchemeResources(R.color.blue); @@ -403,10 +401,12 @@ public class MainWebViewActivity extends AppCompatActivity implements Navigation // Load the initial website. mainWebView.loadUrl(formattedUrlString); - // Load the ad if this is the free flavor. + // Initialize AdView for the free flavor and request an ad. If this is not the free flavor BannerAd.requestAd() does nothing. + adView = findViewById(R.id.adView); BannerAd.requestAd(adView); } + @Override protected void onNewIntent(Intent intent) { // Sets the new intent as the activity intent, so that any future getIntent()s pick up this one instead of creating a new activity. @@ -704,6 +704,12 @@ public class MainWebViewActivity extends AppCompatActivity implements Navigation // Update the status of the drawerToggle icon. drawerToggle.onConfigurationChanged(newConfig); + + // Reload the ad if this is the free flavor. + BannerAd.reloadAfterRotate(adView, getApplicationContext(), getString(R.string.ad_id)); + + // Reinitialize the adView variable, as the View will have been removed and readded. + adView = findViewById(R.id.adView); } @Override @@ -749,6 +755,22 @@ public class MainWebViewActivity extends AppCompatActivity implements Navigation } } + @Override + public void onPause() { + // We need to pause the adView or it will continue to consume resources in the background on the free flavor. + BannerAd.pauseAd(adView); + + super.onPause(); + } + + @Override + public void onResume() { + super.onResume(); + + // We need to resume the adView for the free flavor. + BannerAd.resumeAd(adView); + } + private void loadUrlFromTextBox() throws UnsupportedEncodingException { // Get the text from urlTextBox and convert it to a string. String unformattedUrlString = urlTextBox.getText().toString();