diff --git a/java/advanced/APIDemo/app/src/main/java/com/google/android/gms/snippets/AdManagerNativeAdOptionsSnippets.java b/java/advanced/APIDemo/app/src/main/java/com/google/android/gms/snippets/AdManagerNativeAdOptionsSnippets.java new file mode 100644 index 00000000..44288ba3 --- /dev/null +++ b/java/advanced/APIDemo/app/src/main/java/com/google/android/gms/snippets/AdManagerNativeAdOptionsSnippets.java @@ -0,0 +1,63 @@ +// Copyright 2026 Google LLC +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// https://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +package com.google.android.gms.snippets; + +import android.content.Context; +import android.util.Log; +import com.google.android.gms.ads.AdListener; +import com.google.android.gms.ads.AdLoader; +import com.google.android.gms.ads.nativead.NativeAdOptions; + +/** Java code snippets for the developer guide. */ +final class AdManagerNativeAdOptionsSnippets { + + private static final String AD_UNIT_ID = "/21775744923/example/native"; + private static final String TAG = "AdManagerNativeAdOptionsSnippets"; + + private void setCustomClickGesture(Context context) { + // [START set_custom_click_gesture] + NativeAdOptions adOptions = + new NativeAdOptions.Builder() + .enableCustomClickGestureDirection( + NativeAdOptions.SWIPE_GESTURE_DIRECTION_RIGHT, /* tapsAllowed= */ true) + .build(); + + // gestures enabled. + AdLoader.Builder builder = + new AdLoader.Builder(context, AD_UNIT_ID).withNativeAdOptions(adOptions); + // [END set_custom_click_gesture] + } + + private void setSwipeGesture(Context context) { + // [START set_swipe_gesture] + AdLoader adLoader = + new AdLoader.Builder(context, AD_UNIT_ID) + .withAdListener( + new AdListener() { + // Called when a swipe gesture click is recorded. + @Override + public void onAdSwipeGestureClicked() { + Log.d(TAG, "A swipe gesture click has occurred."); + } + + @Override + public void onAdClicked() { + Log.d(TAG, "A swipe gesture click or a tap click has occurred."); + } + }) + .build(); + // [END set_swipe_gesture] + } +} diff --git a/kotlin/advanced/APIDemo/app/src/main/java/com/google/android/gms/snippets/AdManagerNativeAdOptionsSnippets.kt b/kotlin/advanced/APIDemo/app/src/main/java/com/google/android/gms/snippets/AdManagerNativeAdOptionsSnippets.kt new file mode 100644 index 00000000..0075343f --- /dev/null +++ b/kotlin/advanced/APIDemo/app/src/main/java/com/google/android/gms/snippets/AdManagerNativeAdOptionsSnippets.kt @@ -0,0 +1,60 @@ +// Copyright 2026 Google LLC +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// https://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +package com.google.android.gms.snippets + +import android.content.Context +import android.util.Log +import com.google.android.gms.ads.AdListener +import com.google.android.gms.ads.AdLoader +import com.google.android.gms.ads.nativead.NativeAdOptions + +/** Kotlin code snippets for the developer guide. */ +class AdManagerNativeAdOptionsSnippets { + + private fun setCustomClickGesture(context: Context) { + // [START set_custom_click_gesture] + val adOptions = + NativeAdOptions.Builder() + .enableCustomClickGestureDirection(NativeAdOptions.SWIPE_GESTURE_DIRECTION_RIGHT, true) + .build() + + val builder = AdLoader.Builder(context, AD_UNIT_ID).withNativeAdOptions(adOptions) + // [END set_custom_click_gesture] + } + + private fun setSwipeGesture(context: Context) { + // [START set_swipe_gesture] + val adLoader = + AdLoader.Builder(context, AD_UNIT_ID) + .withAdListener( + object : AdListener() { + override fun onAdSwipeGestureClicked() { + Log.d(TAG, "A swipe gesture click has occurred.") + } + + override fun onAdClicked() { + Log.d(TAG, "A swipe gesture click or a tap click has occurred.") + } + } + ) + .build() + // [END set_swipe_gesture] + } + + private companion object { + const val AD_UNIT_ID = "/21775744923/example/native" + const val TAG = "AdManagerNativeAdOptionsSnippets" + } +}