Skip to content

Commit

Permalink
ADD: added banner ad, interstital ad and video ad
Browse files Browse the repository at this point in the history
  • Loading branch information
bxute committed Apr 11, 2018
1 parent 2044fc4 commit 72e6767
Show file tree
Hide file tree
Showing 13 changed files with 384 additions and 8 deletions.
5 changes: 5 additions & 0 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,13 @@ dependencies {
implementation 'com.jakewharton:butterknife:8.8.1'
annotationProcessor 'com.jakewharton:butterknife-compiler:8.8.1'
androidTestImplementation 'com.android.support.test:runner:1.0.1'
implementation 'com.google.android.gms:play-services-ads:12.0.1'
androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.1'
}






apply plugin: 'com.google.gms.google-services'
9 changes: 6 additions & 3 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -8,18 +8,21 @@
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:name=".KitiAppMain"
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="@style/AppTheme">
<activity android:name=".HomeActivity">

</activity>
<activity android:name=".HomeActivity" />
<activity android:name=".LoginActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />

<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity android:name=".BannerAdActivity" />
<activity android:name=".InterstitalAdActivity" />
<activity android:name=".VideoAdActivity"></activity>
</application>

</manifest>
65 changes: 65 additions & 0 deletions app/src/main/java/app/kiti/com/kitiapp/BannerAdActivity.java
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.
}
};

}
19 changes: 19 additions & 0 deletions app/src/main/java/app/kiti/com/kitiapp/HomeActivity.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package app.kiti.com.kitiapp;

import android.content.Intent;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;

Expand All @@ -9,5 +10,23 @@ public class HomeActivity extends AppCompatActivity {
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_home);
toVideoAd();
}

private void toBanner() {
Intent i = new Intent(this, BannerAdActivity.class);
startActivity(i);
}

private void toInterst() {
Intent i = new Intent(this, InterstitalAdActivity.class);
startActivity(i);
}

private void toVideoAd() {
Intent i = new Intent(this, VideoAdActivity.class);
startActivity(i);
}


}
77 changes: 77 additions & 0 deletions app/src/main/java/app/kiti/com/kitiapp/InterstitalAdActivity.java
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.
}
};

}
24 changes: 24 additions & 0 deletions app/src/main/java/app/kiti/com/kitiapp/KitiAppMain.java
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;
}

}
22 changes: 17 additions & 5 deletions app/src/main/java/app/kiti/com/kitiapp/LoginActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,15 +19,20 @@
import com.google.firebase.auth.FirebaseUser;
import com.google.firebase.auth.PhoneAuthCredential;
import com.google.firebase.auth.PhoneAuthProvider;

import java.util.concurrent.TimeUnit;

import butterknife.BindView;
import butterknife.ButterKnife;

public class LoginActivity extends AppCompatActivity {

@BindView(R.id.phone_numberEt) EditText phoneNumberEt;
@BindView(R.id.otp) EditText otp;
@BindView(R.id.loginButton) Button loginButton;
@BindView(R.id.phone_numberEt)
EditText phoneNumberEt;
@BindView(R.id.otp)
EditText otp;
@BindView(R.id.loginButton)
Button loginButton;
private String mVerificationId;
private PhoneAuthProvider.ForceResendingToken mResendToken;
private String TAG = LoginActivity.class.getSimpleName();
Expand Down Expand Up @@ -87,6 +92,12 @@ protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_login);
ButterKnife.bind(this);
// last login check
if (PreferenceManager.getInstance().isLoggedIn()) {
navigateToHomePage();
return;
}

mAuth = FirebaseAuth.getInstance();
loginButton.setOnClickListener(new View.OnClickListener() {
@Override
Expand All @@ -96,7 +107,7 @@ public void onClick(View v) {
});
}

private void verifyPhoneNumber(String phone){
private void verifyPhoneNumber(String phone) {
PhoneAuthProvider.getInstance().verifyPhoneNumber(
phone, // Phone number to verify
60, // Timeout duration
Expand All @@ -117,6 +128,7 @@ public void onComplete(@NonNull Task<AuthResult> task) {

FirebaseUser user = task.getResult().getUser();
navigateToHomePage();
PreferenceManager.getInstance().setLoggedIn(true);
// ...
} else {
// Sign in failed, display a message and update the UI
Expand All @@ -130,7 +142,7 @@ public void onComplete(@NonNull Task<AuthResult> task) {
}

private void navigateToHomePage() {
Intent homeIntent = new Intent(this,HomeActivity.class);
Intent homeIntent = new Intent(this, HomeActivity.class);
startActivity(homeIntent);
}

Expand Down
46 changes: 46 additions & 0 deletions app/src/main/java/app/kiti/com/kitiapp/PreferenceManager.java
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);
}

}
Loading

0 comments on commit 72e6767

Please sign in to comment.