Skip to content

Commit 0980eb7

Browse files
committed
Initial commit
0 parents  commit 0980eb7

File tree

34 files changed

+1020
-0
lines changed

34 files changed

+1020
-0
lines changed

.gitignore

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
*.iml
2+
.gradle
3+
/local.properties
4+
/.idea/workspace.xml
5+
/.idea/libraries
6+
.DS_Store
7+
/build
8+
/captures
9+
.externalNativeBuild

.idea/compiler.xml

Lines changed: 22 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.idea/copyright/profiles_settings.xml

Lines changed: 3 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.idea/gradle.xml

Lines changed: 19 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.idea/misc.xml

Lines changed: 62 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.idea/modules.xml

Lines changed: 9 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.idea/runConfigurations.xml

Lines changed: 12 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

AdsManager.java

Lines changed: 173 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,173 @@
1+
package com.fochmobile.inc.adsmanager;
2+
3+
import android.content.Context;
4+
import android.util.Log;
5+
import android.view.View;
6+
7+
import com.google.android.gms.ads.AdListener;
8+
import com.google.android.gms.ads.AdRequest;
9+
import com.google.android.gms.ads.AdView;
10+
import com.google.android.gms.ads.InterstitialAd;
11+
import com.google.android.gms.ads.NativeExpressAdView;
12+
13+
/**
14+
* ADS MANAGER Class: An open source Java class.
15+
* @Author ESSARE AYOUB
16+
* @Created on January 2017
17+
* @Company FochMobile Inc (c) By ESSARE AYOUB
18+
* @Copyright (c) 2017 | All RIGHTS RESERVED :v
19+
* @Url: https://gist.github.com/Ess-Soft/5ded8943dc248111e4fef41460ed931e
20+
*/
21+
22+
public class AdsManager{
23+
24+
// Your Admob Interstitial ID here !!
25+
private static final String ADMOB_INTERSTITIAL_ID = "ca-app-pub-xxxxxxxxxxxxxxxxxxxxx";
26+
private Context mContext;
27+
private InterstitialAd interstitialAd;
28+
29+
/**
30+
* Main Constructor for initializing class
31+
* It takes only one parameter 'Context'
32+
* @param context
33+
* Context is for accessing app resources such
34+
* as strings.xml etc...
35+
*/
36+
public AdsManager(Context context){
37+
mContext = context;
38+
}
39+
40+
/**
41+
* This Method loads ads in AdView
42+
* The AdView can be passed from any
43+
* Class or Activity as parameter
44+
* @param adView
45+
*/
46+
public void LoadAdsBannerWithInterstitial(final AdView adView){
47+
if(adView != null) {
48+
AdRequest adRequest = new AdRequest.Builder().build();
49+
adView.loadAd(adRequest);
50+
}
51+
// AdView will be hidden from the activity until it loads.
52+
adView.setVisibility(View.INVISIBLE);
53+
adView.setAdListener(new AdListener() {
54+
@Override
55+
public void onAdClosed() {
56+
super.onAdClosed();
57+
Log.d("==> Banner Ad:", " Closed by user!");
58+
}
59+
60+
@Override
61+
public void onAdFailedToLoad(int i) {
62+
super.onAdFailedToLoad(i);
63+
Log.d("==> Banner Ad:", " Failed to load!");
64+
}
65+
66+
@Override
67+
public void onAdOpened() {
68+
super.onAdOpened();
69+
Log.d("==> Banner Ad:", " Clicked by user!");
70+
}
71+
72+
@Override
73+
public void onAdLoaded() {
74+
super.onAdLoaded();
75+
Log.d("==> Banner Ad:", " Loaded successfully!");
76+
adView.setVisibility(View.VISIBLE);
77+
}
78+
79+
});
80+
// Just load INTERSTITIAL Ads
81+
LoadInterstitial();
82+
83+
}
84+
85+
/**
86+
* This Method loads ads in NativeExpressAdView
87+
* The NativeExpressAdView can be passed from any
88+
* Class or Activity as parameter
89+
* @param nativeExpressAdView
90+
*/
91+
public void LoadAdsNativeWithInterstitial(final NativeExpressAdView nativeExpressAdView){
92+
if(nativeExpressAdView != null){
93+
nativeExpressAdView.loadAd(new AdRequest.Builder().build());
94+
}
95+
nativeExpressAdView.setVisibility(View.GONE);
96+
nativeExpressAdView.setAdListener(new AdListener() {
97+
@Override
98+
public void onAdClosed() {
99+
super.onAdClosed();
100+
}
101+
102+
@Override
103+
public void onAdFailedToLoad(int i) {
104+
super.onAdFailedToLoad(i);
105+
}
106+
107+
@Override
108+
public void onAdOpened() {
109+
super.onAdOpened();
110+
}
111+
112+
@Override
113+
public void onAdLoaded() {
114+
super.onAdLoaded();
115+
nativeExpressAdView.setVisibility(View.VISIBLE);
116+
}
117+
});
118+
119+
LoadInterstitial();
120+
121+
122+
}
123+
124+
/**
125+
* This Method loads interstitial ads
126+
* but keep it on memory until ShowInterstitial()
127+
* is called then the Interstitial ads will popup in full screen mode
128+
*/
129+
public void LoadInterstitial(){
130+
interstitialAd = new InterstitialAd(mContext);
131+
interstitialAd.setAdUnitId(ADMOB_INTERSTITIAL_ID);
132+
interstitialAd.loadAd(new AdRequest.Builder().build());
133+
interstitialAd.setAdListener(new AdListener() {
134+
@Override
135+
public void onAdClosed() {
136+
super.onAdClosed();
137+
Log.d("==> Interstitial Ad:", " Closed by user");
138+
}
139+
140+
@Override
141+
public void onAdFailedToLoad(int i) {
142+
super.onAdFailedToLoad(i);
143+
Log.d("==> Interstitial Ad:", " Failed to load");
144+
}
145+
146+
@Override
147+
public void onAdOpened() {
148+
super.onAdOpened();
149+
Log.d("==> Interstitial Ad:", " Opened by user");
150+
}
151+
152+
@Override
153+
public void onAdLoaded() {
154+
super.onAdLoaded();
155+
Log.d("==> Interstitial Ad:", " Loaded successfully");
156+
}
157+
});
158+
}
159+
160+
/**
161+
* This method shows the interstitial ads on the screen in fullScreen
162+
* NOTICE: Please call LoadInterstitial() method first or ShowInterstitial()
163+
* would be null
164+
*/
165+
public void ShowInterstitial(){
166+
if(interstitialAd != null && interstitialAd.isLoaded()){
167+
interstitialAd.show();
168+
}
169+
// Reload interstitial after ShowInterstitial is called.
170+
LoadInterstitial();
171+
}
172+
173+
}

app/.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
/build

app/build.gradle

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
apply plugin: 'com.android.application'
2+
3+
android {
4+
compileSdkVersion 25
5+
buildToolsVersion "25.0.2"
6+
defaultConfig {
7+
applicationId "com.fochmobile.inc.adstestingproject"
8+
minSdkVersion 14
9+
targetSdkVersion 25
10+
versionCode 1
11+
versionName "1.0"
12+
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
13+
}
14+
buildTypes {
15+
release {
16+
minifyEnabled false
17+
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
18+
}
19+
}
20+
}
21+
22+
dependencies {
23+
compile fileTree(dir: 'libs', include: ['*.jar'])
24+
androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', {
25+
exclude group: 'com.android.support', module: 'support-annotations'
26+
})
27+
compile 'com.android.support:appcompat-v7:25.1.0'
28+
testCompile 'junit:junit:4.12'
29+
compile 'com.google.android.gms:play-services-ads:10.0.1'
30+
}

0 commit comments

Comments
 (0)