Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,8 @@ protected void onCreate(Bundle savedInstanceState) {
supportViewModel = new ViewModelProvider(this).get(SupportViewModel.class);

AdRequest adRequest = supportViewModel.initMobileAds();
binding.largeBannerAd.loadAd(adRequest);
binding.supportNativeAd.loadAd(adRequest);
binding.bannerAdView.loadAd(adRequest);

binding.buttonWebAd.setOnClickListener(v ->
startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse("https://bit.ly/3p8bpjj"))));
Expand Down
22 changes: 18 additions & 4 deletions app/src/main/res/layout/activity_support.xml
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:ads="http://schemas.android.com/apk/res-auto"
android:id="@+id/container"
android:layout_width="match_parent"
android:layout_height="match_parent">
Expand Down Expand Up @@ -29,7 +30,8 @@
style="@style/Widget.Material3.CardView.Outlined"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="24dp">
android:layout_margin="24dp"
app:cardCornerRadius="24dp">

<androidx.appcompat.widget.LinearLayoutCompat
android:layout_width="match_parent"
Expand Down Expand Up @@ -121,12 +123,24 @@
app:layout_rowWeight="1" />

<com.d4rk.androidtutorials.java.ads.views.NativeAdBannerView
android:id="@+id/large_banner_ad"
android:id="@+id/support_native_ad"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginStart="24dp"
android:layout_marginTop="16dp"
android:layout_marginEnd="24dp"
app:nativeAdLayout="@layout/ad_support" />

<com.google.android.gms.ads.AdView
android:id="@+id/banner_ad_view"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginStart="24dp"
android:layout_marginTop="16dp"
android:layout_marginBottom="16dp"
app:nativeAdLayout="@layout/ad_home_banner_large" />
android:layout_marginEnd="24dp"
android:layout_marginBottom="24dp"
ads:adSize="FULL_BANNER"
ads:adUnitId="@string/ad_banner_unit_id" />
</androidx.appcompat.widget.LinearLayoutCompat>
</me.zhanghai.android.fastscroll.FastScrollScrollView>
</androidx.constraintlayout.widget.ConstraintLayout>
75 changes: 75 additions & 0 deletions app/src/main/res/layout/ad_support.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
<?xml version="1.0" encoding="utf-8"?>
<com.google.android.gms.ads.nativead.NativeAdView xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="wrap_content">

<com.google.android.material.card.MaterialCardView
android:id="@+id/ad_card"
style="@style/Widget.Material3.CardView.Outlined"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:cardCornerRadius="24dp">

<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:padding="16dp">

<include layout="@layout/ad_attribution" />

<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="8dp"
android:gravity="center_vertical"
android:orientation="horizontal">

<ImageView
android:id="@+id/ad_app_icon"
android:layout_width="40dp"
android:layout_height="40dp"
android:contentDescription="@null" />

<TextView
android:id="@+id/ad_headline"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginStart="8dp"
android:layout_weight="1"
android:ellipsize="end"
android:maxLines="1"
android:textAppearance="@style/TextAppearance.Material3.TitleMedium" />

<com.google.android.material.button.MaterialButton
android:id="@+id/ad_call_to_action"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="8dp" />
</LinearLayout>

<com.google.android.material.card.MaterialCardView
android:id="@+id/media_card"
style="@style/Widget.Material3.CardView.Filled"
android:layout_width="match_parent"
android:layout_height="180dp"
android:layout_marginTop="8dp"
android:layout_marginBottom="8dp"
app:cardCornerRadius="12dp">

<com.google.android.gms.ads.nativead.MediaView
android:id="@+id/ad_media"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:scaleType="centerCrop" />
</com.google.android.material.card.MaterialCardView>

<TextView
android:id="@+id/ad_body"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textAppearance="@style/TextAppearance.Material3.BodySmall" />
</LinearLayout>
</com.google.android.material.card.MaterialCardView>
</com.google.android.gms.ads.nativead.NativeAdView>