Skip to content

Commit

Permalink
feat(banner ad): banner ad added to main menu and gameplay
Browse files Browse the repository at this point in the history
  • Loading branch information
jcrucesdeveloper committed Mar 6, 2023
1 parent 858b3dd commit 2d04ea3
Show file tree
Hide file tree
Showing 8 changed files with 102 additions and 2 deletions.
1 change: 1 addition & 0 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ android {

dependencies {

implementation 'com.google.android.gms:play-services-ads:21.5.0'
implementation 'androidx.appcompat:appcompat:1.4.1'
implementation 'com.google.android.material:material:1.5.0'
implementation 'androidx.constraintlayout:constraintlayout:2.1.3'
Expand Down
4 changes: 4 additions & 0 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,10 @@
android:supportsRtl="true"
android:theme="@style/Theme.MetroMetro">

<meta-data
android:name="com.google.android.gms.ads.APPLICATION_ID"
android:value="ca-app-pub-8814283715092277~7859965067"/>

<activity
android:name=".activities.PlayGameActivity"
android:exported="false"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,11 @@
import androidx.annotation.Nullable;
import androidx.appcompat.app.AppCompatActivity;

import com.google.android.gms.ads.AdRequest;
import com.google.android.gms.ads.AdView;
import com.google.android.gms.ads.MobileAds;
import com.google.android.gms.ads.initialization.InitializationStatus;
import com.google.android.gms.ads.initialization.OnInitializationCompleteListener;
import com.jorgecruces.metrometro.R;
import com.jorgecruces.metrometro.sound.BackgroundMusic;
import com.jorgecruces.metrometro.sound.MediaPlayerReproducer;
Expand All @@ -25,13 +30,29 @@
public class MainActivity extends AppCompatActivity {

private ImageView imageViewMenuLogo;
private AdView mAdView;


@Override
protected void onCreate(@Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
this.imageViewMenuLogo = findViewById(R.id.imageViewLogo);
this.animateFadeInButtons();
this.loadAds();
}

private void loadAds() {

MobileAds.initialize(this, new OnInitializationCompleteListener() {
@Override
public void onInitializationComplete(InitializationStatus initializationStatus) {
}
});

mAdView = findViewById(R.id.adView);
AdRequest adRequest = new AdRequest.Builder().build();
mAdView.loadAd(adRequest);
}


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,11 @@
import android.widget.TextView;
import android.widget.Toast;

import com.google.android.gms.ads.AdRequest;
import com.google.android.gms.ads.AdView;
import com.google.android.gms.ads.MobileAds;
import com.google.android.gms.ads.initialization.InitializationStatus;
import com.google.android.gms.ads.initialization.OnInitializationCompleteListener;
import com.jorgecruces.metrometro.R;
import com.jorgecruces.metrometro.customViews.StationView;
import com.jorgecruces.metrometro.logic.MetroReaderXML;
Expand Down Expand Up @@ -50,6 +55,10 @@ public class PlayGameActivity extends AppCompatActivity {
private MediaPlayer mediaPlayerGameplayGameplay;
private boolean isReproducingGameplayMusic = false;

// Ads

private AdView mAdView;

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
Expand All @@ -59,6 +68,21 @@ protected void onCreate(Bundle savedInstanceState) {
this.initializeLevelViews();
this.setCurrentStationQuestion(this.position);
this.drawStationView(150, this.currentStationName, this.lineColorHex);
this.loadAds();
}


private void loadAds() {

MobileAds.initialize(this, new OnInitializationCompleteListener() {
@Override
public void onInitializationComplete(InitializationStatus initializationStatus) {
}
});

mAdView = findViewById(R.id.adViewGameplay);
AdRequest adRequest = new AdRequest.Builder().build();
mAdView.loadAd(adRequest);
}

@Override
Expand Down
12 changes: 12 additions & 0 deletions app/src/main/res/layout/activity_main.xml
Original file line number Diff line number Diff line change
Expand Up @@ -66,4 +66,16 @@
app:layout_constraintTop_toBottomOf="@+id/imageViewButtonPlay"
app:srcCompat="@drawable/main_menu_configuration" />

<com.google.android.gms.ads.AdView
android:id="@+id/adView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_centerHorizontal="true"
app:adSize="BANNER"
app:adUnitId="ca-app-pub-8814283715092277/1674100165"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
tools:ignore="MissingConstraints"></com.google.android.gms.ads.AdView>
</androidx.constraintlayout.widget.ConstraintLayout>
13 changes: 13 additions & 0 deletions app/src/main/res/layout/activity_menu_metro.xml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,19 @@
android:background="@drawable/lines_metro_background"
tools:context=".activities.MenuMetroActivity">

<com.google.android.gms.ads.AdView
android:id="@+id/adView2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_centerHorizontal="true"
app:adSize="BANNER"
app:adUnitId="ca-app-pub-3940256099942544/6300978111"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
tools:ignore="MissingConstraints"></com.google.android.gms.ads.AdView>

<androidx.recyclerview.widget.RecyclerView
android:id="@+id/menuMetroRecyclerView"
android:layout_width="0dp"
Expand Down
13 changes: 13 additions & 0 deletions app/src/main/res/layout/activity_metro_information.xml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,19 @@
android:background="@drawable/lines_metro_background"
tools:context=".activities.MetroInformationActivity">

<com.google.android.gms.ads.AdView
android:id="@+id/adView3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_centerHorizontal="true"
app:adSize="BANNER"
app:adUnitId="ca-app-pub-3940256099942544/6300978111"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
tools:ignore="MissingConstraints"></com.google.android.gms.ads.AdView>

<ScrollView
android:layout_width="match_parent"
android:layout_height="match_parent">
Expand Down
16 changes: 14 additions & 2 deletions app/src/main/res/layout/activity_play_game.xml
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,25 @@
android:background="@drawable/lines_metro_background"
tools:context=".activities.PlayGameActivity">

<com.google.android.gms.ads.AdView
android:id="@+id/adViewGameplay"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_centerHorizontal="true"
app:adSize="BANNER"
app:adUnitId="ca-app-pub-8814283715092277/7449171029"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"></com.google.android.gms.ads.AdView>


<ImageView
android:id="@+id/imageView"
android:layout_width="72dp"
android:layout_height="61dp"
android:layout_marginStart="16dp"
android:layout_marginTop="24dp"
android:layout_marginTop="52dp"
android:contentDescription="Button"
android:onClick="goBackToMenu"
app:layout_constraintEnd_toStartOf="@+id/textViewTitle"
Expand All @@ -26,7 +38,7 @@
android:id="@+id/textViewTitle"
android:layout_width="0dp"
android:layout_height="59dp"
android:layout_marginTop="24dp"
android:layout_marginTop="52dp"
android:layout_marginEnd="24dp"
android:background="@drawable/gameplay_background_game_line"
android:fontFamily="@font/titiliumweb_bold"
Expand Down

0 comments on commit 2d04ea3

Please sign in to comment.