Skip to content

Commit e2853c4

Browse files
Nicholas Ventimigliacopybara-github
authored andcommitted
Updated native ad option snippets.
PiperOrigin-RevId: 925465584
1 parent f2f6a37 commit e2853c4

2 files changed

Lines changed: 123 additions & 0 deletions

File tree

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
// Copyright 2026 Google LLC
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License");
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
//
7+
// https://www.apache.org/licenses/LICENSE-2.0
8+
//
9+
// Unless required by applicable law or agreed to in writing, software
10+
// distributed under the License is distributed on an "AS IS" BASIS,
11+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
// See the License for the specific language governing permissions and
13+
// limitations under the License.
14+
15+
package com.google.android.gms.snippets;
16+
17+
import android.content.Context;
18+
import android.util.Log;
19+
import com.google.android.gms.ads.AdListener;
20+
import com.google.android.gms.ads.AdLoader;
21+
import com.google.android.gms.ads.nativead.NativeAdOptions;
22+
23+
/** Java code snippets for the developer guide. */
24+
final class AdManagerNativeAdOptionsSnippets {
25+
26+
private static final String AD_UNIT_ID = "/21775744923/example/native";
27+
private static final String TAG = "AdManagerNativeAdOptionsSnippets";
28+
29+
private void setCustomClickGesture(Context context) {
30+
// [START set_custom_click_gesture]
31+
NativeAdOptions adOptions =
32+
new NativeAdOptions.Builder()
33+
.enableCustomClickGestureDirection(
34+
NativeAdOptions.SWIPE_GESTURE_DIRECTION_RIGHT, /* tapsAllowed= */ true)
35+
.build();
36+
37+
// gestures enabled.
38+
AdLoader.Builder builder =
39+
new AdLoader.Builder(context, AD_UNIT_ID).withNativeAdOptions(adOptions);
40+
// [END set_custom_click_gesture]
41+
}
42+
43+
private void setSwipeGesture(Context context) {
44+
// [START set_swipe_gesture]
45+
AdLoader adLoader =
46+
new AdLoader.Builder(context, AD_UNIT_ID)
47+
.withAdListener(
48+
new AdListener() {
49+
// Called when a swipe gesture click is recorded.
50+
@Override
51+
public void onAdSwipeGestureClicked() {
52+
Log.d(TAG, "A swipe gesture click has occurred.");
53+
}
54+
55+
@Override
56+
public void onAdClicked() {
57+
Log.d(TAG, "A swipe gesture click or a tap click has occurred.");
58+
}
59+
})
60+
.build();
61+
// [END set_swipe_gesture]
62+
}
63+
}
Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
// Copyright 2026 Google LLC
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License");
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
//
7+
// https://www.apache.org/licenses/LICENSE-2.0
8+
//
9+
// Unless required by applicable law or agreed to in writing, software
10+
// distributed under the License is distributed on an "AS IS" BASIS,
11+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
// See the License for the specific language governing permissions and
13+
// limitations under the License.
14+
15+
package com.google.android.gms.snippets
16+
17+
import android.content.Context
18+
import android.util.Log
19+
import com.google.android.gms.ads.AdListener
20+
import com.google.android.gms.ads.AdLoader
21+
import com.google.android.gms.ads.nativead.NativeAdOptions
22+
23+
/** Kotlin code snippets for the developer guide. */
24+
class AdManagerNativeAdOptionsSnippets {
25+
26+
private fun setCustomClickGesture(context: Context) {
27+
// [START set_custom_click_gesture]
28+
val adOptions =
29+
NativeAdOptions.Builder()
30+
.enableCustomClickGestureDirection(NativeAdOptions.SWIPE_GESTURE_DIRECTION_RIGHT, true)
31+
.build()
32+
33+
val builder = AdLoader.Builder(context, AD_UNIT_ID).withNativeAdOptions(adOptions)
34+
// [END set_custom_click_gesture]
35+
}
36+
37+
private fun setSwipeGesture(context: Context) {
38+
// [START set_swipe_gesture]
39+
val adLoader =
40+
AdLoader.Builder(context, AD_UNIT_ID)
41+
.withAdListener(
42+
object : AdListener() {
43+
override fun onAdSwipeGestureClicked() {
44+
Log.d(TAG, "A swipe gesture click has occurred.")
45+
}
46+
47+
override fun onAdClicked() {
48+
Log.d(TAG, "A swipe gesture click or a tap click has occurred.")
49+
}
50+
}
51+
)
52+
.build()
53+
// [END set_swipe_gesture]
54+
}
55+
56+
private companion object {
57+
const val AD_UNIT_ID = "/21775744923/example/native"
58+
const val TAG = "AdManagerNativeAdOptionsSnippets"
59+
}
60+
}

0 commit comments

Comments
 (0)