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: 5 additions & 0 deletions AGENTS.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,3 +16,8 @@ You are an experienced Android app developer.

## Testing
- 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.
- 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.
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
public class NativeAdLoader {

public static void load(@NonNull Context context, @NonNull ViewGroup container) {
load(context, container, R.layout.native_ad);
load(context, container, R.layout.large_home_banner_native_ad);
}

public static void load(@NonNull Context context, @NonNull ViewGroup container, @LayoutRes int layoutRes) {
Expand Down Expand Up @@ -58,7 +58,9 @@ private static void populateNativeAdView(@NonNull NativeAd nativeAd, @NonNull Na
adView.setHeadlineView(headlineView);
adView.setBodyView(bodyView);
adView.setCallToActionView(callToActionView);
adView.setIconView(iconView);
if (iconView != null) {
adView.setIconView(iconView);
}
adView.setAdvertiserView(attributionView);

if (headlineView != null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
*/
public class NativeAdBannerView extends FrameLayout {

private int layoutRes = R.layout.native_ad;
private int layoutRes = R.layout.large_home_banner_native_ad;

public NativeAdBannerView(@NonNull Context context) {
super(context);
Expand All @@ -39,7 +39,7 @@ public NativeAdBannerView(@NonNull Context context, @Nullable AttributeSet attrs
private void init(@NonNull Context context, @Nullable AttributeSet attrs, int defStyleAttr) {
if (attrs != null) {
TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.NativeAdBannerView, defStyleAttr, 0);
layoutRes = a.getResourceId(R.styleable.NativeAdBannerView_nativeAdLayout, R.layout.native_ad);
layoutRes = a.getResourceId(R.styleable.NativeAdBannerView_nativeAdLayout, R.layout.large_home_banner_native_ad);
a.recycle();
}
}
Expand Down
6 changes: 6 additions & 0 deletions app/src/main/res/drawable/bg_ad_attribution.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android" android:shape="rectangle">
<solid android:color="@android:color/transparent" />
<stroke android:width="1dp" android:color="?attr/colorPrimary" />
<corners android:radius="4dp" />
</shape>
4 changes: 2 additions & 2 deletions app/src/main/res/layout/activity_main.xml
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@
<FrameLayout
android:id="@+id/ad_container"
android:layout_width="match_parent"
android:layout_height="50dp"
android:layout_height="wrap_content"
app:layout_constraintBottom_toTopOf="@+id/nav_view">

<View
Expand All @@ -57,7 +57,7 @@
android:id="@+id/ad_view"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:nativeAdLayout="@layout/native_ad" />
app:nativeAdLayout="@layout/bottom_app_bar_native_ad" />
</FrameLayout>

<com.google.android.material.bottomnavigation.BottomNavigationView
Expand Down
2 changes: 1 addition & 1 deletion app/src/main/res/layout/activity_support.xml
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@
android:layout_height="wrap_content"
android:layout_marginTop="16dp"
android:layout_marginBottom="16dp"
app:nativeAdLayout="@layout/native_ad" />
app:nativeAdLayout="@layout/large_home_banner_native_ad" />
</androidx.appcompat.widget.LinearLayoutCompat>
</me.zhanghai.android.fastscroll.FastScrollScrollView>
</androidx.constraintlayout.widget.ConstraintLayout>
11 changes: 11 additions & 0 deletions app/src/main/res/layout/ad_attribution.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<?xml version="1.0" encoding="utf-8"?>
<TextView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/ad_attribution"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="@drawable/bg_ad_attribution"
android:paddingHorizontal="4dp"
android:paddingVertical="2dp"
android:text="@string/ad"
android:textColor="?attr/colorPrimary"
android:textAppearance="@style/TextAppearance.Material3.LabelSmall" />
64 changes: 64 additions & 0 deletions app/src/main/res/layout/bottom_app_bar_native_ad.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
<?xml version="1.0" encoding="utf-8"?>
<com.google.android.gms.ads.nativead.NativeAdView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content">

<LinearLayout
android:id="@+id/ad_host"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:background="?attr/colorSurfaceContainer"
android:paddingStart="16dp"
android:paddingEnd="16dp"
android:paddingTop="12dp"
android:paddingBottom="12dp">

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

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

<ImageView
android:id="@+id/ad_app_icon"
android:layout_width="32dp"
android:layout_height="32dp"
android:layout_marginEnd="12dp" />

<LinearLayout
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:orientation="vertical">

<TextView
android:id="@+id/ad_headline"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:ellipsize="end"
android:maxLines="1"
android:textAppearance="@style/TextAppearance.Material3.BodyMedium" />

<TextView
android:id="@+id/ad_body"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:ellipsize="end"
android:maxLines="1"
android:textAppearance="@style/TextAppearance.Material3.BodySmall" />
</LinearLayout>

<com.google.android.material.button.MaterialButton
android:id="@+id/ad_call_to_action"
style="@style/Widget.Material3.Button.TextButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:minWidth="64dp"
android:minHeight="36dp"
android:layout_marginStart="8dp" />
</LinearLayout>
</LinearLayout>
</com.google.android.gms.ads.nativead.NativeAdView>
2 changes: 1 addition & 1 deletion app/src/main/res/layout/fragment_about.xml
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,7 @@
android:layout_height="wrap_content"
android:layout_marginTop="16dp"
app:layout_constraintTop_toBottomOf="@id/card_view_about"
app:nativeAdLayout="@layout/native_ad" />
app:nativeAdLayout="@layout/large_home_banner_native_ad" />

<com.airbnb.lottie.LottieAnimationView
android:id="@+id/animation_about"
Expand Down
9 changes: 4 additions & 5 deletions app/src/main/res/layout/fragment_home.xml
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@
android:layout_marginHorizontal="16dp"
android:layout_marginTop="16dp"
android:layout_marginBottom="16dp"
app:nativeAdLayout="@layout/native_ad" />
app:nativeAdLayout="@layout/large_home_banner_native_ad" />

<androidx.appcompat.widget.LinearLayoutCompat
android:id="@+id/other_apps_section"
Expand Down Expand Up @@ -188,7 +188,8 @@
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginHorizontal="16dp"
android:layout_marginBottom="16dp">
android:layout_marginBottom="0dp"
app:shapeAppearanceOverlay="@style/ShapeAppearanceOverlay.CardViewTopRounded">

<androidx.appcompat.widget.LinearLayoutCompat
android:layout_width="match_parent"
Expand Down Expand Up @@ -219,9 +220,7 @@
android:id="@+id/small_banner_ad"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginHorizontal="16dp"
android:layout_marginTop="16dp"
app:nativeAdLayout="@layout/native_ad" />
app:nativeAdLayout="@layout/small_home_banner_native_ad" />

<com.airbnb.lottie.LottieAnimationView
android:id="@+id/learningAnimation"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
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"
Expand All @@ -16,12 +17,7 @@
android:layout_margin="16dp"
android:orientation="vertical">

<TextView
android:id="@+id/ad_attribution"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/ad"
android:textAppearance="@style/TextAppearance.Material3.LabelSmall" />
<include layout="@layout/ad_attribution" />

<com.google.android.material.card.MaterialCardView
style="@style/Widget.Material3.CardView.Filled"
Expand All @@ -41,36 +37,40 @@
<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:layout_marginEnd="8dp" />

<TextView
android:id="@+id/ad_headline"
<LinearLayout
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:textAppearance="@style/TextAppearance.Material3.TitleMedium" />
</LinearLayout>
android:orientation="vertical">

<TextView
android:id="@+id/ad_body"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="4dp"
android:textAppearance="@style/TextAppearance.Material3.BodySmall" />
<TextView
android:id="@+id/ad_headline"
android:layout_width="match_parent"
android:layout_height="wrap_content"
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_gravity="end"
android:layout_marginTop="8dp" />
<TextView
android:id="@+id/ad_body"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:ellipsize="end"
android:maxLines="1"
android:layout_marginTop="4dp"
android:textAppearance="@style/TextAppearance.Material3.BodySmall" />
</LinearLayout>

<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>
</LinearLayout>
</com.google.android.material.card.MaterialCardView>
</com.google.android.gms.ads.nativead.NativeAdView>
65 changes: 65 additions & 0 deletions app/src/main/res/layout/small_home_banner_native_ad.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
<?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"
android:layout_marginHorizontal="16dp"
android:layout_marginTop="2dp"
android:layout_marginBottom="16dp"
app:shapeAppearanceOverlay="@style/ShapeAppearanceOverlay.CardViewBottomRounded">

<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:layout_marginEnd="16dp" />

<LinearLayout
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:orientation="vertical">

<TextView
android:id="@+id/ad_headline"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="@style/TextAppearance.Material3.TitleMedium" />

<TextView
android:id="@+id/ad_body"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="@style/TextAppearance.Material3.BodySmall" />
</LinearLayout>

<com.google.android.material.button.MaterialButton
android:id="@+id/ad_call_to_action"
style="@style/Widget.Material3.Button.TextButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
</LinearLayout>
</LinearLayout>
</com.google.android.material.card.MaterialCardView>
</com.google.android.gms.ads.nativead.NativeAdView>