-
Notifications
You must be signed in to change notification settings - Fork 17
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
ADD: added banner ad, interstital ad and video ad
- Loading branch information
Showing
13 changed files
with
384 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
65 changes: 65 additions & 0 deletions
65
app/src/main/java/app/kiti/com/kitiapp/BannerAdActivity.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
package app.kiti.com.kitiapp; | ||
|
||
import android.support.v7.app.AppCompatActivity; | ||
import android.os.Bundle; | ||
import android.util.Log; | ||
import android.view.View; | ||
|
||
import com.google.android.gms.ads.AdListener; | ||
import com.google.android.gms.ads.AdRequest; | ||
import com.google.android.gms.ads.AdView; | ||
import com.google.android.gms.ads.MobileAds; | ||
|
||
public class BannerAdActivity extends AppCompatActivity { | ||
|
||
private AdView mAdView; | ||
public static final String TAG = BannerAdActivity.class.getSimpleName(); | ||
|
||
@Override | ||
protected void onCreate(Bundle savedInstanceState) { | ||
super.onCreate(savedInstanceState); | ||
setContentView(R.layout.activity_banner_ad); | ||
init(); | ||
} | ||
|
||
private void init() { | ||
MobileAds.initialize(this, getResources().getString(R.string.admob_test_app_id)); | ||
mAdView = findViewById(R.id.adView); | ||
AdRequest adRequest = new AdRequest.Builder().build(); | ||
mAdView.loadAd(adRequest); | ||
mAdView.setAdListener(adListener); | ||
} | ||
|
||
private AdListener adListener = new AdListener() { | ||
@Override | ||
public void onAdLoaded() { | ||
// Code to be executed when an ad finishes loading. | ||
Log.d(TAG,"Ad Loaded"); | ||
} | ||
|
||
@Override | ||
public void onAdFailedToLoad(int errorCode) { | ||
// Code to be executed when an ad request fails. | ||
Log.d(TAG,"Failed to Load ad"); | ||
} | ||
|
||
@Override | ||
public void onAdOpened() { | ||
// Code to be executed when an ad opens an overlay that | ||
// covers the screen. | ||
Log.d(TAG,"Ad Opened"); | ||
} | ||
|
||
@Override | ||
public void onAdLeftApplication() { | ||
// Code to be executed when the user has left the app. | ||
} | ||
|
||
@Override | ||
public void onAdClosed() { | ||
// Code to be executed when when the user is about to return | ||
// to the app after tapping on an ad. | ||
} | ||
}; | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
77 changes: 77 additions & 0 deletions
77
app/src/main/java/app/kiti/com/kitiapp/InterstitalAdActivity.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
package app.kiti.com.kitiapp; | ||
|
||
import android.support.v7.app.AppCompatActivity; | ||
import android.os.Bundle; | ||
import android.util.Log; | ||
|
||
import com.google.android.gms.ads.AdListener; | ||
import com.google.android.gms.ads.AdRequest; | ||
import com.google.android.gms.ads.InterstitialAd; | ||
import com.google.android.gms.ads.MobileAds; | ||
|
||
public class InterstitalAdActivity extends AppCompatActivity { | ||
|
||
public static final String TAG = InterstitalAdActivity.class.getSimpleName(); | ||
private InterstitialAd mInterstitialAd; | ||
|
||
@Override | ||
protected void onCreate(Bundle savedInstanceState) { | ||
super.onCreate(savedInstanceState); | ||
setContentView(R.layout.activity_interstital_ad); | ||
init(); | ||
showAd(); | ||
} | ||
|
||
private void showAd() { | ||
if (mInterstitialAd.isLoaded()) { | ||
mInterstitialAd.show(); | ||
} else { | ||
Log.d("TAG", "The interstitial wasn't loaded yet."); | ||
} | ||
|
||
} | ||
|
||
private void init() { | ||
|
||
MobileAds.initialize(this, getResources().getString(R.string.admob_test_app_id)); | ||
mInterstitialAd = new InterstitialAd(this); | ||
mInterstitialAd.setAdUnitId("ca-app-pub-3940256099942544/1033173712"); | ||
mInterstitialAd.loadAd(new AdRequest.Builder().build()); | ||
mInterstitialAd.setAdListener(adListener); | ||
|
||
} | ||
|
||
private AdListener adListener = new AdListener() { | ||
@Override | ||
public void onAdLoaded() { | ||
// Code to be executed when an ad finishes loading. | ||
Log.d(TAG, "Ad Loaded"); | ||
mInterstitialAd.show(); | ||
} | ||
|
||
@Override | ||
public void onAdFailedToLoad(int errorCode) { | ||
// Code to be executed when an ad request fails. | ||
Log.d(TAG, "Failed to Load ad"); | ||
} | ||
|
||
@Override | ||
public void onAdOpened() { | ||
// Code to be executed when an ad opens an overlay that | ||
// covers the screen. | ||
Log.d(TAG, "Ad Opened"); | ||
} | ||
|
||
@Override | ||
public void onAdLeftApplication() { | ||
// Code to be executed when the user has left the app. | ||
} | ||
|
||
@Override | ||
public void onAdClosed() { | ||
// Code to be executed when when the user is about to return | ||
// to the app after tapping on an ad. | ||
} | ||
}; | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
package app.kiti.com.kitiapp; | ||
|
||
import android.app.Application; | ||
import android.content.Context; | ||
|
||
/** | ||
* Created by Ankit on 4/11/2018. | ||
*/ | ||
|
||
public class KitiAppMain extends Application { | ||
|
||
private static Context context; | ||
|
||
@Override | ||
public void onCreate() { | ||
super.onCreate(); | ||
this.context = this; | ||
} | ||
|
||
public static Context getContext() { | ||
return context; | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
46 changes: 46 additions & 0 deletions
46
app/src/main/java/app/kiti/com/kitiapp/PreferenceManager.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
package app.kiti.com.kitiapp; | ||
|
||
import android.content.Context; | ||
import android.content.SharedPreferences; | ||
import android.util.Log; | ||
|
||
/** | ||
* Created by Ankit on 4/11/2018. | ||
*/ | ||
|
||
public class PreferenceManager { | ||
|
||
private static SharedPreferences preferences; | ||
private static SharedPreferences.Editor editor; | ||
private static PreferenceManager mInstance; | ||
private static final String PREF_NAME = "kiti_pref"; | ||
|
||
public PreferenceManager() { | ||
|
||
preferences = KitiAppMain.getContext().getSharedPreferences(PREF_NAME, Context.MODE_PRIVATE); | ||
editor = preferences.edit(); | ||
|
||
} | ||
|
||
public static PreferenceManager getInstance() { | ||
if (mInstance == null) { | ||
mInstance = new PreferenceManager(); | ||
} | ||
return mInstance; | ||
} | ||
|
||
public void clearPreferences() { | ||
editor.clear(); | ||
editor.apply(); | ||
} | ||
|
||
public void setLoggedIn(boolean loggedIn) { | ||
editor.putBoolean("isLoggedIn", loggedIn); | ||
editor.apply(); | ||
} | ||
|
||
public boolean isLoggedIn() { | ||
return preferences.getBoolean("isLoggedIn", false); | ||
} | ||
|
||
} |
Oops, something went wrong.