2 * Copyright © 2016-2017 Soren Stoutner <soren@stoutner.com>.
4 * This file is part of Privacy Browser <https://www.stoutner.com/privacy-browser>.
6 * Privacy Browser is free software: you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation, either version 3 of the License, or
9 * (at your option) any later version.
11 * Privacy Browser is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with Privacy Browser. If not, see <http://www.gnu.org/licenses/>.
20 package com.stoutner.privacybrowser;
22 import android.content.Context;
23 import android.support.v7.app.AppCompatActivity;
24 import android.view.View;
25 import android.widget.RelativeLayout;
27 import com.google.android.gms.ads.AdRequest;
28 import com.google.android.gms.ads.AdSize;
29 import com.google.android.gms.ads.AdView;
31 public class BannerAd extends AppCompatActivity{
32 public static void requestAd(View view) {
33 // Cast view to an AdView.
34 AdView adView = (AdView) view;
37 AdRequest adRequest = new AdRequest.Builder().build();
38 adView.loadAd(adRequest);
41 public static void reloadAfterRotate (View view, Context applicationContext, String ad_id) {
42 // Cast `view` to an `AdView`.
43 AdView adView = (AdView) view;
45 // Save the layout parameters.
46 RelativeLayout.LayoutParams adViewLayoutParameters = (RelativeLayout.LayoutParams) adView.getLayoutParams();
48 // Remove the `AdView`.
49 RelativeLayout adViewParentLayout = (RelativeLayout) adView.getParent();
50 adViewParentLayout.removeView(adView);
52 // Setup the new `AdView`.
53 adView = new AdView(applicationContext);
54 adView.setAdSize(AdSize.SMART_BANNER);
55 adView.setAdUnitId(ad_id);
56 adView.setId(R.id.adview);
57 adView.setLayoutParams(adViewLayoutParameters);
59 // Display the new `AdView`.
60 adViewParentLayout.addView(adView);
63 AdRequest adRequest = new AdRequest.Builder().build();
64 adView.loadAd(adRequest);
67 public static void hideAd(View view) {
68 // Cast `view` to an `AdView`.
69 AdView adView = (AdView) view;
72 adView.setVisibility(View.GONE);
75 public static void showAd(View view) {
76 // Cast `view` to an `AdView`.
77 AdView adView = (AdView) view;
80 adView.setVisibility(View.VISIBLE);
83 public static void pauseAd(View view) {
84 // Cast `view` to an `AdView`.
85 AdView adView = (AdView) view;
87 // Pause the `AdView`.
91 public static void resumeAd(View view) {
92 // Cast `view` to an `AdView`.
93 AdView adView = (AdView) view;
95 // Resume the `AdView`.