]> gitweb.stoutner.com Git - PrivacyBrowserAndroid.git/blob - app/src/free/java/com/stoutner/privacybrowser/BannerAd.java
Fix loading of bookmarks from the Bookmarks Activity. https://redmine.stoutner.com...
[PrivacyBrowserAndroid.git] / app / src / free / java / com / stoutner / privacybrowser / BannerAd.java
1 /*
2  * Copyright © 2016-2017 Soren Stoutner <soren@stoutner.com>.
3  *
4  * This file is part of Privacy Browser <https://www.stoutner.com/privacy-browser>.
5  *
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.
10  *
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.
15  *
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/>.
18  */
19
20 package com.stoutner.privacybrowser;
21
22 import android.content.Context;
23 import android.support.v7.app.AppCompatActivity;
24 import android.view.View;
25 import android.widget.RelativeLayout;
26
27 import com.google.android.gms.ads.AdRequest;
28 import com.google.android.gms.ads.AdSize;
29 import com.google.android.gms.ads.AdView;
30
31 public class BannerAd extends AppCompatActivity{
32     public static void requestAd(View view) {
33         // Cast view to an AdView.
34         AdView adView = (AdView) view;
35
36         // Load an ad.
37         AdRequest adRequest = new AdRequest.Builder().build();
38         adView.loadAd(adRequest);
39     }
40
41     public static void reloadAfterRotate (View view, Context applicationContext, String ad_id) {
42         // Cast `view` to an `AdView`.
43         AdView adView = (AdView) view;
44
45         // Save the layout parameters.
46         RelativeLayout.LayoutParams adViewLayoutParameters = (RelativeLayout.LayoutParams) adView.getLayoutParams();
47
48         // Remove the `AdView`.
49         RelativeLayout adViewParentLayout = (RelativeLayout) adView.getParent();
50         adViewParentLayout.removeView(adView);
51
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);
58
59         // Display the new `AdView`.
60         adViewParentLayout.addView(adView);
61
62         // Request a new ad.
63         AdRequest adRequest = new AdRequest.Builder().build();
64         adView.loadAd(adRequest);
65     }
66
67     public static void hideAd(View view) {
68         // Cast `view` to an `AdView`.
69         AdView adView = (AdView) view;
70
71         // Hide the ad.
72         adView.setVisibility(View.GONE);
73     }
74
75     public static void showAd(View view) {
76         // Cast `view` to an `AdView`.
77         AdView adView = (AdView) view;
78
79         // Show the ad.
80         adView.setVisibility(View.VISIBLE);
81     }
82
83     public static void pauseAd(View view) {
84         // Cast `view` to an `AdView`.
85         AdView adView = (AdView) view;
86
87         // Pause the `AdView`.
88         adView.pause();
89     }
90
91     public static void resumeAd(View view) {
92         // Cast `view` to an `AdView`.
93         AdView adView = (AdView) view;
94
95         // Resume the `AdView`.
96         adView.resume();
97     }
98 }