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
5 changes: 3 additions & 2 deletions AGENTS.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ You are an experienced Android app developer.
- Run `./gradlew test` before committing changes.

## Native ads
- Native ad XML layouts should wrap their content in a `MaterialCardView` with the ID `ad_card` using `@style/Widget.Material3.CardView.Outlined` and appropriate rounded corner overlays.
- Native ad XML layouts should wrap their content in a `MaterialCardView` with the ID `ad_card` using a Material3 card style and appropriate rounded corner overlays.
- Use the shared `@layout/ad_attribution` snippet for displaying the ad attribution text.
- Place the attribution include as the first child of the ad card and override its padding or text color attributes to fit each layout.
- Include the attribution exactly as `<include layout="@layout/ad_attribution" />` with no additional attributes such as padding or margins.
- Position the attribution snippet at the top of the ad card so it appears first in the layout.
100 changes: 100 additions & 0 deletions app/src/main/res/layout/about_native_ad.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
<?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.Elevated"
app:shapeAppearanceOverlay="@style/ShapeAppearanceOverlay.CardViewBottomRounded"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginHorizontal="24dp"
app:cardUseCompatPadding="false"
app:cardPreventCornerOverlap="true">

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

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

<androidx.constraintlayout.widget.ConstraintLayout
android:id="@+id/ad_host"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="8dp">

<com.google.android.material.card.MaterialCardView
android:id="@+id/media_card"
android:layout_width="96dp"
android:layout_height="96dp"
app:cardCornerRadius="16dp"
app:cardUseCompatPadding="false"
app:cardPreventCornerOverlap="true"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintStart_toStartOf="parent">

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

<TextView
android:id="@+id/ad_headline"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginStart="12dp"
android:ellipsize="end"
android:maxLines="1"
android:textAppearance="@style/TextAppearance.Material3.TitleMedium"
app:layout_constraintTop_toTopOf="@id/media_card"
app:layout_constraintStart_toEndOf="@id/media_card"
app:layout_constraintEnd_toEndOf="parent" />

<TextView
android:id="@+id/ad_body"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:ellipsize="end"
android:maxLines="2"
android:textAppearance="@style/TextAppearance.Material3.BodySmall"
app:layout_constraintStart_toStartOf="@id/ad_headline"
app:layout_constraintEnd_toEndOf="@id/ad_headline"
app:layout_constraintTop_toBottomOf="@id/ad_headline" />

<me.zhanghai.android.materialratingbar.MaterialRatingBar
android:id="@+id/ad_stars"
style="@style/Widget.MaterialRatingBar.RatingBar.Small"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:isIndicator="true"
android:numStars="5"
android:stepSize="0.5"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toStartOf="@id/ad_call_to_action"
app:layout_constraintStart_toStartOf="@id/ad_headline"
app:layout_constraintTop_toBottomOf="@id/ad_body" />

<com.google.android.material.button.MaterialButton
android:id="@+id/ad_call_to_action"
android:layout_width="wrap_content"
android:layout_height="40dp"
android:minWidth="88dp"
android:layout_marginStart="12dp"
android:layout_marginTop="8dp"
android:paddingHorizontal="12dp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toEndOf="@id/ad_stars"
app:layout_constraintTop_toBottomOf="@id/ad_body"
app:layout_constraintHorizontal_chainStyle="packed" />

</androidx.constraintlayout.widget.ConstraintLayout>
</LinearLayout>
</com.google.android.material.card.MaterialCardView>
</com.google.android.gms.ads.nativead.NativeAdView>

2 changes: 1 addition & 1 deletion app/src/main/res/layout/activity_main.xml
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@
<com.d4rk.androidtutorials.java.ads.views.NativeAdBannerView
android:id="@+id/ad_view"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_height="wrap_content"
app:nativeAdLayout="@layout/bottom_app_bar_native_ad" />
</FrameLayout>

Expand Down
4 changes: 2 additions & 2 deletions app/src/main/res/layout/bottom_app_bar_native_ad.xml
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,8 @@
style="@style/Widget.Material3.Button.TextButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:minWidth="64dp"
android:minHeight="36dp"
android:minWidth="88dp"
android:minHeight="40dp"
android:layout_marginStart="8dp" />
</LinearLayout>
</LinearLayout>
Expand Down
9 changes: 5 additions & 4 deletions app/src/main/res/layout/fragment_about.xml
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,11 @@
<com.google.android.material.card.MaterialCardView
android:id="@+id/card_view_about"
style="@style/Widget.Material3.CardView.Elevated"
app:shapeAppearanceOverlay="@style/ShapeAppearanceOverlay.CardViewTopRounded"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="24dp"
app:cardCornerRadius="24dp"
android:layout_marginHorizontal="24dp"
android:layout_marginTop="24dp"
app:layout_constraintTop_toTopOf="parent">

<androidx.constraintlayout.widget.ConstraintLayout
Expand Down Expand Up @@ -172,9 +173,9 @@
android:id="@+id/ad_view"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="16dp"
android:layout_marginTop="2dp"
app:layout_constraintTop_toBottomOf="@id/card_view_about"
app:nativeAdLayout="@layout/large_home_banner_native_ad" />
app:nativeAdLayout="@layout/about_native_ad" />

<com.airbnb.lottie.LottieAnimationView
android:id="@+id/animation_about"
Expand Down