X-Git-Url: https://gitweb.stoutner.com/?a=blobdiff_plain;f=app%2Fsrc%2Fmain%2Fjava%2Fcom%2Fstoutner%2Fprivacybrowser%2FMainWebViewActivity.java;h=3c442d1c1052f1babd87d479e6a6c89db272459b;hb=cdb15b51501bd5fe266c4a3cfc53443810015c6f;hp=f2f8b040d5f0c4bf880ead557ce42da68c9c0bcb;hpb=7db44ba42c42745594e96b198be77c29c586920e;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 f2f8b040..3c442d1c 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. @@ -702,8 +702,11 @@ public class MainWebViewActivity extends AppCompatActivity implements Navigation public void onConfigurationChanged(Configuration newConfig) { super.onConfigurationChanged(newConfig); - // 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 in the free flavor by BannerAd.reloadAfterRotate(). + adView = findViewById(R.id.adView); } @Override @@ -749,6 +752,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();