Skip to content

Commit 76d21b0

Browse files
Merge pull request #263 from MihaiCristianCondrea/codex/add-native-ad-view-to-help-screen
Add native ad to Help screen FAQ
2 parents 7c02eea + c73a34a commit 76d21b0

File tree

3 files changed

+123
-3
lines changed

3 files changed

+123
-3
lines changed

app/src/main/java/com/d4rk/androidtutorials/java/ui/screens/help/HelpActivity.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515

1616
import com.d4rk.androidtutorials.java.BuildConfig;
1717
import com.d4rk.androidtutorials.java.R;
18+
import com.d4rk.androidtutorials.java.ads.AdUtils;
1819
import com.d4rk.androidtutorials.java.databinding.ActivityHelpBinding;
1920
import com.d4rk.androidtutorials.java.databinding.DialogVersionInfoBinding;
2021
import com.d4rk.androidtutorials.java.ui.components.navigation.BaseActivity;
@@ -37,6 +38,7 @@ protected void onCreate(Bundle savedInstanceState) {
3738
ActivityHelpBinding binding = ActivityHelpBinding.inflate(getLayoutInflater());
3839
setContentView(binding.getRoot());
3940
EdgeToEdgeDelegate.apply(this, binding.getRoot());
41+
AdUtils.loadBanner(binding.faqNativeAd);
4042
helpViewModel = new ViewModelProvider(this).get(HelpViewModel.class);
4143

4244
getSupportFragmentManager().beginTransaction()

app/src/main/res/layout/activity_help.xml

Lines changed: 23 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,10 +25,30 @@
2525
app:layout_constraintBottom_toTopOf="@id/frame_layout_feedback"
2626
app:layout_constraintTop_toBottomOf="@id/text_view_faq">
2727

28-
<FrameLayout
29-
android:id="@+id/frame_layout_faq"
28+
<androidx.constraintlayout.widget.ConstraintLayout
3029
android:layout_width="match_parent"
31-
android:layout_height="match_parent" />
30+
android:layout_height="match_parent"
31+
android:padding="16dp">
32+
33+
<FrameLayout
34+
android:id="@+id/frame_layout_faq"
35+
android:layout_width="0dp"
36+
android:layout_height="0dp"
37+
app:layout_constraintBottom_toTopOf="@id/faq_native_ad"
38+
app:layout_constraintEnd_toEndOf="parent"
39+
app:layout_constraintStart_toStartOf="parent"
40+
app:layout_constraintTop_toTopOf="parent" />
41+
42+
<com.d4rk.androidtutorials.java.ads.views.NativeAdBannerView
43+
android:id="@+id/faq_native_ad"
44+
android:layout_width="0dp"
45+
android:layout_height="wrap_content"
46+
android:layout_marginTop="16dp"
47+
app:layout_constraintBottom_toBottomOf="parent"
48+
app:layout_constraintEnd_toEndOf="parent"
49+
app:layout_constraintStart_toStartOf="parent"
50+
app:nativeAdLayout="@layout/ad_help" />
51+
</androidx.constraintlayout.widget.ConstraintLayout>
3252
</com.google.android.material.card.MaterialCardView>
3353

3454
<FrameLayout
Lines changed: 98 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,98 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<com.google.android.gms.ads.nativead.NativeAdView xmlns:android="http://schemas.android.com/apk/res/android"
3+
xmlns:app="http://schemas.android.com/apk/res-auto"
4+
android:layout_width="match_parent"
5+
android:layout_height="wrap_content">
6+
7+
<com.google.android.material.card.MaterialCardView
8+
android:id="@+id/ad_card"
9+
style="@style/Widget.Material3.CardView.Filled"
10+
android:layout_width="match_parent"
11+
android:layout_height="wrap_content"
12+
app:cardCornerRadius="20dp">
13+
14+
<androidx.appcompat.widget.LinearLayoutCompat
15+
android:layout_width="match_parent"
16+
android:layout_height="wrap_content"
17+
android:orientation="vertical"
18+
android:padding="16dp">
19+
20+
<include layout="@layout/ad_attribution" />
21+
22+
<androidx.appcompat.widget.LinearLayoutCompat
23+
android:layout_width="match_parent"
24+
android:layout_height="wrap_content"
25+
android:layout_marginTop="8dp"
26+
android:gravity="center_vertical"
27+
android:orientation="horizontal">
28+
29+
<androidx.appcompat.widget.AppCompatImageView
30+
android:id="@+id/ad_app_icon"
31+
android:layout_width="48dp"
32+
android:layout_height="48dp"
33+
android:layout_marginEnd="12dp"
34+
android:contentDescription="@null"
35+
android:visibility="gone" />
36+
37+
<androidx.appcompat.widget.LinearLayoutCompat
38+
android:layout_width="0dp"
39+
android:layout_height="wrap_content"
40+
android:layout_weight="1"
41+
android:orientation="vertical">
42+
43+
<com.google.android.material.textview.MaterialTextView
44+
android:id="@+id/ad_headline"
45+
android:layout_width="wrap_content"
46+
android:layout_height="wrap_content"
47+
android:ellipsize="end"
48+
android:maxLines="1"
49+
android:textAppearance="@style/TextAppearance.Material3.TitleMedium" />
50+
51+
<com.google.android.material.textview.MaterialTextView
52+
android:id="@+id/ad_body"
53+
android:layout_width="wrap_content"
54+
android:layout_height="wrap_content"
55+
android:ellipsize="end"
56+
android:maxLines="2"
57+
android:textAppearance="@style/TextAppearance.Material3.BodySmall" />
58+
59+
</androidx.appcompat.widget.LinearLayoutCompat>
60+
61+
<com.google.android.material.button.MaterialButton
62+
android:id="@+id/ad_call_to_action"
63+
style="@style/Widget.Material3.Button.TonalButton"
64+
android:layout_width="wrap_content"
65+
android:layout_height="wrap_content"
66+
android:layout_marginStart="12dp"
67+
android:minWidth="88dp" />
68+
</androidx.appcompat.widget.LinearLayoutCompat>
69+
70+
<com.google.android.material.card.MaterialCardView
71+
android:id="@+id/media_card"
72+
style="@style/Widget.Material3.CardView.Outlined"
73+
android:layout_width="match_parent"
74+
android:layout_height="180dp"
75+
android:layout_marginTop="12dp"
76+
app:cardCornerRadius="16dp">
77+
78+
<FrameLayout
79+
android:layout_width="match_parent"
80+
android:layout_height="match_parent">
81+
82+
<com.google.android.gms.ads.nativead.MediaView
83+
android:id="@+id/ad_media"
84+
android:layout_width="match_parent"
85+
android:layout_height="match_parent"
86+
android:scaleType="centerCrop" />
87+
88+
<com.google.android.gms.ads.nativead.AdChoicesView
89+
android:id="@+id/ad_choices"
90+
android:layout_width="wrap_content"
91+
android:layout_height="wrap_content"
92+
android:layout_gravity="top|end"
93+
android:layout_margin="8dp" />
94+
</FrameLayout>
95+
</com.google.android.material.card.MaterialCardView>
96+
</androidx.appcompat.widget.LinearLayoutCompat>
97+
</com.google.android.material.card.MaterialCardView>
98+
</com.google.android.gms.ads.nativead.NativeAdView>

0 commit comments

Comments
 (0)