|
| 1 | +// Copyright 2025 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 | + // /21775744923/example/native is a sample ad unit ID that has custom click |
| 38 | + // gestures enabled. |
| 39 | + AdLoader.Builder builder = |
| 40 | + new AdLoader.Builder(context, AD_UNIT_ID).withNativeAdOptions(adOptions); |
| 41 | + // [END set_custom_click_gesture] |
| 42 | + } |
| 43 | + |
| 44 | + private void setSwipeGesture(Context context) { |
| 45 | + // [START set_swipe_gesture] |
| 46 | + AdLoader adLoader = |
| 47 | + new AdLoader.Builder(context, AD_UNIT_ID) |
| 48 | + .withAdListener( |
| 49 | + new AdListener() { |
| 50 | + // Called when a swipe gesture click is recorded. |
| 51 | + @Override |
| 52 | + public void onAdSwipeGestureClicked() { |
| 53 | + // Called when a swipe gesture click is recorded. |
| 54 | + Log.d(TAG, "A swipe gesture click has occurred."); |
| 55 | + } |
| 56 | + |
| 57 | + @Override |
| 58 | + public void onAdClicked() { |
| 59 | + // Called when a swipe gesture click or a tap click is recorded, as |
| 60 | + // configured in NativeAdOptions. |
| 61 | + Log.d(TAG, "A swipe gesture click or a tap click has occurred."); |
| 62 | + } |
| 63 | + }) |
| 64 | + .build(); |
| 65 | + // [END set_swipe_gesture] |
| 66 | + } |
| 67 | +} |
0 commit comments