├── .gitignore ├── LICENSE ├── README.md ├── mediation └── mopub │ └── com │ ├── mopub │ ├── MopubCustomParamsUtils.java │ ├── mobileads │ │ ├── MyTargetAdapterConfiguration.java │ │ ├── MyTargetMopubCustomEventInterstitial.java │ │ └── MyTargetMopubCustomEventRewardedVideo.java │ └── nativeads │ │ ├── MyTargetAdRenderer.java │ │ └── MyTargetCustomEventNative.java │ └── my │ └── target │ └── ads │ └── mediation │ ├── MyTargetAdapterUtils.java │ └── MyTargetMopubCustomEventBanner.java └── myTargetDemo ├── app ├── .gitignore ├── build.gradle.kts ├── proguard-rules.pro └── src │ ├── androidTest │ ├── AndroidManifest.xml │ └── java │ │ └── com │ │ └── my │ │ └── targetDemoTests │ │ ├── helpers │ │ ├── Constants.kt │ │ ├── DeviceHelper.kt │ │ └── ScreenshotTestRunner.kt │ │ ├── screens │ │ ├── AudioInstreamScreen.kt │ │ ├── BannersScreen.kt │ │ ├── InstreamScreen.kt │ │ ├── InterstitialScreen.kt │ │ ├── MainScreen.kt │ │ ├── NativeScreen.kt │ │ └── WebViewScreen.kt │ │ └── tests │ │ ├── AudioInstreamTest.kt │ │ ├── BannersTest.kt │ │ ├── InstreamTest.kt │ │ ├── InterstitialTest.kt │ │ ├── MainTest.kt │ │ ├── NativeTest.kt │ │ └── TestBase.kt │ └── main │ ├── AndroidManifest.xml │ ├── ic_launcher-web.png │ ├── java │ └── com │ │ └── my │ │ └── targetDemoApp │ │ ├── AdChoicesMenuFactory.kt │ │ ├── AdvertisingType.kt │ │ ├── CustiomAdvertisingType.kt │ │ ├── Extensions.kt │ │ ├── ItemsAdapter.kt │ │ ├── PlusDialogFragment.kt │ │ ├── Saver.kt │ │ ├── activities │ │ ├── AudioInstreamActivity.kt │ │ ├── BannersActivity.kt │ │ ├── InstreamActivity.kt │ │ ├── InterstitialsActivity.kt │ │ ├── MainActivity.kt │ │ ├── NativeAdActivity.kt │ │ ├── NativeAdConfigurationActivity.kt │ │ ├── NativeBannerActivity.kt │ │ └── SimpleBannerActivity.kt │ │ ├── helpers │ │ ├── AdChoicesMenuFactory.kt │ │ ├── BannerHelper.kt │ │ ├── InterstitialHelper.kt │ │ ├── NativeAdHelper.kt │ │ ├── NativeBannerHelper.kt │ │ ├── NativeHelper.kt │ │ └── RewardedHelper.kt │ │ └── player │ │ ├── DefaultPlayerEventListener.kt │ │ ├── ExoTimeBar.kt │ │ └── InstreamAuidoAdPlayerHelper.kt │ └── res │ ├── drawable-v24 │ └── ic_launcher_foreground.xml │ ├── drawable │ ├── button_background_onvideo.xml │ ├── ic_add.xml │ └── ic_launcher_foreground.xml │ ├── layout │ ├── activity_audio_instream.xml │ ├── activity_banners.xml │ ├── activity_interstitials.xml │ ├── activity_main.xml │ ├── activity_native_banners.xml │ ├── activity_native_configuration.xml │ ├── activity_natives.xml │ ├── activity_normal_instream.xml │ ├── activity_simple_banner.xml │ ├── exo_playback_control_view.xml │ ├── fragment_dialog.xml │ ├── item_banner.xml │ ├── item_main.xml │ ├── item_native.xml │ └── item_native_loading.xml │ ├── mipmap-anydpi-v26 │ ├── ic_launcher.xml │ └── ic_launcher_round.xml │ ├── mipmap-hdpi │ ├── ic_launcher.png │ └── ic_launcher_round.png │ ├── mipmap-mdpi │ ├── ic_launcher.png │ └── ic_launcher_round.png │ ├── mipmap-xhdpi │ ├── ic_launcher.png │ └── ic_launcher_round.png │ ├── mipmap-xxhdpi │ ├── ic_launcher.png │ └── ic_launcher_round.png │ ├── mipmap-xxxhdpi │ ├── ic_launcher.png │ └── ic_launcher_round.png │ ├── values │ ├── colors.xml │ ├── dimens.xml │ ├── ic_launcher_background.xml │ ├── integers.xml │ ├── strings.xml │ └── styles.xml │ └── xml │ ├── backup_descriptor.xml │ └── network_security_config.xml ├── build.gradle.kts ├── buildSrc ├── build.gradle.kts └── src │ └── main │ └── kotlin │ ├── sdk_version.kt │ └── versions.kt ├── gradle.properties ├── gradle └── wrapper │ ├── gradle-wrapper.jar │ └── gradle-wrapper.properties ├── gradlew ├── gradlew.bat ├── make.sh └── settings.gradle.kts /.gitignore: -------------------------------------------------------------------------------- 1 | # Built application files 2 | *.apk 3 | *.ap_ 4 | 5 | # Files for the Dalvik VM 6 | *.dex 7 | 8 | # Java class files 9 | *.class 10 | 11 | # Generated files 12 | bin/ 13 | gen/ 14 | 15 | # Gradle files 16 | .gradle/ 17 | build/ 18 | 19 | # Local configuration file (sdk path, etc) 20 | local.properties 21 | 22 | # Proguard folder generated by Eclipse 23 | proguard/ 24 | 25 | # Log Files 26 | *.log 27 | 28 | # Android Studio Navigation editor temp files 29 | .navigation/ 30 | 31 | # Android Studio captures folder 32 | captures/ 33 | 34 | # Screenshots 35 | screenshots/ 36 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | GNU LESSER GENERAL PUBLIC LICENSE 2 | Version 3, 29 June 2007 3 | 4 | Copyright (C) 2007 Free Software Foundation, Inc. 5 | Everyone is permitted to copy and distribute verbatim copies 6 | of this license document, but changing it is not allowed. 7 | 8 | 9 | This version of the GNU Lesser General Public License incorporates 10 | the terms and conditions of version 3 of the GNU General Public 11 | License, supplemented by the additional permissions listed below. 12 | 13 | 0. Additional Definitions. 14 | 15 | As used herein, "this License" refers to version 3 of the GNU Lesser 16 | General Public License, and the "GNU GPL" refers to version 3 of the GNU 17 | General Public License. 18 | 19 | "The Library" refers to a covered work governed by this License, 20 | other than an Application or a Combined Work as defined below. 21 | 22 | An "Application" is any work that makes use of an interface provided 23 | by the Library, but which is not otherwise based on the Library. 24 | Defining a subclass of a class defined by the Library is deemed a mode 25 | of using an interface provided by the Library. 26 | 27 | A "Combined Work" is a work produced by combining or linking an 28 | Application with the Library. The particular version of the Library 29 | with which the Combined Work was made is also called the "Linked 30 | Version". 31 | 32 | The "Minimal Corresponding Source" for a Combined Work means the 33 | Corresponding Source for the Combined Work, excluding any source code 34 | for portions of the Combined Work that, considered in isolation, are 35 | based on the Application, and not on the Linked Version. 36 | 37 | The "Corresponding Application Code" for a Combined Work means the 38 | object code and/or source code for the Application, including any data 39 | and utility programs needed for reproducing the Combined Work from the 40 | Application, but excluding the System Libraries of the Combined Work. 41 | 42 | 1. Exception to Section 3 of the GNU GPL. 43 | 44 | You may convey a covered work under sections 3 and 4 of this License 45 | without being bound by section 3 of the GNU GPL. 46 | 47 | 2. Conveying Modified Versions. 48 | 49 | If you modify a copy of the Library, and, in your modifications, a 50 | facility refers to a function or data to be supplied by an Application 51 | that uses the facility (other than as an argument passed when the 52 | facility is invoked), then you may convey a copy of the modified 53 | version: 54 | 55 | a) under this License, provided that you make a good faith effort to 56 | ensure that, in the event an Application does not supply the 57 | function or data, the facility still operates, and performs 58 | whatever part of its purpose remains meaningful, or 59 | 60 | b) under the GNU GPL, with none of the additional permissions of 61 | this License applicable to that copy. 62 | 63 | 3. Object Code Incorporating Material from Library Header Files. 64 | 65 | The object code form of an Application may incorporate material from 66 | a header file that is part of the Library. You may convey such object 67 | code under terms of your choice, provided that, if the incorporated 68 | material is not limited to numerical parameters, data structure 69 | layouts and accessors, or small macros, inline functions and templates 70 | (ten or fewer lines in length), you do both of the following: 71 | 72 | a) Give prominent notice with each copy of the object code that the 73 | Library is used in it and that the Library and its use are 74 | covered by this License. 75 | 76 | b) Accompany the object code with a copy of the GNU GPL and this license 77 | document. 78 | 79 | 4. Combined Works. 80 | 81 | You may convey a Combined Work under terms of your choice that, 82 | taken together, effectively do not restrict modification of the 83 | portions of the Library contained in the Combined Work and reverse 84 | engineering for debugging such modifications, if you also do each of 85 | the following: 86 | 87 | a) Give prominent notice with each copy of the Combined Work that 88 | the Library is used in it and that the Library and its use are 89 | covered by this License. 90 | 91 | b) Accompany the Combined Work with a copy of the GNU GPL and this license 92 | document. 93 | 94 | c) For a Combined Work that displays copyright notices during 95 | execution, include the copyright notice for the Library among 96 | these notices, as well as a reference directing the user to the 97 | copies of the GNU GPL and this license document. 98 | 99 | d) Do one of the following: 100 | 101 | 0) Convey the Minimal Corresponding Source under the terms of this 102 | License, and the Corresponding Application Code in a form 103 | suitable for, and under terms that permit, the user to 104 | recombine or relink the Application with a modified version of 105 | the Linked Version to produce a modified Combined Work, in the 106 | manner specified by section 6 of the GNU GPL for conveying 107 | Corresponding Source. 108 | 109 | 1) Use a suitable shared library mechanism for linking with the 110 | Library. A suitable mechanism is one that (a) uses at run time 111 | a copy of the Library already present on the user's computer 112 | system, and (b) will operate properly with a modified version 113 | of the Library that is interface-compatible with the Linked 114 | Version. 115 | 116 | e) Provide Installation Information, but only if you would otherwise 117 | be required to provide such information under section 6 of the 118 | GNU GPL, and only to the extent that such information is 119 | necessary to install and execute a modified version of the 120 | Combined Work produced by recombining or relinking the 121 | Application with a modified version of the Linked Version. (If 122 | you use option 4d0, the Installation Information must accompany 123 | the Minimal Corresponding Source and Corresponding Application 124 | Code. If you use option 4d1, you must provide the Installation 125 | Information in the manner specified by section 6 of the GNU GPL 126 | for conveying Corresponding Source.) 127 | 128 | 5. Combined Libraries. 129 | 130 | You may place library facilities that are a work based on the 131 | Library side by side in a single library together with other library 132 | facilities that are not Applications and are not covered by this 133 | License, and convey such a combined library under terms of your 134 | choice, if you do both of the following: 135 | 136 | a) Accompany the combined library with a copy of the same work based 137 | on the Library, uncombined with any other library facilities, 138 | conveyed under the terms of this License. 139 | 140 | b) Give prominent notice with the combined library that part of it 141 | is a work based on the Library, and explaining where to find the 142 | accompanying uncombined form of the same work. 143 | 144 | 6. Revised Versions of the GNU Lesser General Public License. 145 | 146 | The Free Software Foundation may publish revised and/or new versions 147 | of the GNU Lesser General Public License from time to time. Such new 148 | versions will be similar in spirit to the present version, but may 149 | differ in detail to address new problems or concerns. 150 | 151 | Each version is given a distinguishing version number. If the 152 | Library as you received it specifies that a certain numbered version 153 | of the GNU Lesser General Public License "or any later version" 154 | applies to it, you have the option of following the terms and 155 | conditions either of that published version or of any later version 156 | published by the Free Software Foundation. If the Library as you 157 | received it does not specify a version number of the GNU Lesser 158 | General Public License, you may choose any version of the GNU Lesser 159 | General Public License ever published by the Free Software Foundation. 160 | 161 | If the Library as you received it specifies that a proxy can decide 162 | whether future versions of the GNU Lesser General Public License shall 163 | apply, that proxy's public statement of acceptance of any version is 164 | permanent authorization for you to choose that version for the 165 | Library. 166 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # myTarget Android SDK 2 | 3 | ![Platforms][platforms-svg] 4 | [![License][license-svg]][license-link] 5 | [![Maven Central][maven-svg]][maven-link] 6 | 7 | 8 | The myTarget Advertising Network allows developers to monetize their websites and mobile apps using myTarget ads. 9 | After you integrate the myTarget SDK, thousands of myTarget customers will become the target audience for your app or website. 10 | 11 | ## Integrate 12 | 13 | **Installation** 14 | - **[Maven Central][maven-link]** 15 | 16 | Add the following line to your build.gradle file: 17 | ```groovy 18 | dependencies { 19 | //... other dependences 20 | implementation 'com.my.target:mytarget-sdk:5.20.0' 21 | } 22 | ``` 23 | 24 | Integration instructions are available on our [website](https://target.my.com/help/partners/mob/androidsdkstart/en). 25 | 26 | Demo-app with examples of integration available in [myTargetDemo folder](https://github.com/myTargetSDK/mytarget-android/blob/master/myTargetDemo). 27 | 28 | ## Requirements 29 | 30 | Android 4.1 31 | 32 | [license-svg]: https://img.shields.io/badge/license-LGPL-lightgrey.svg 33 | [license-link]: https://github.com/myTargetSDK/mytarget-android/blob/master/LICENSE 34 | 35 | [maven-svg]: https://maven-badges.herokuapp.com/maven-central/com.my.target/mytarget-sdk/badge.svg 36 | [maven-link]: https://search.maven.org/artifact/com.my.target/mytarget-sdk 37 | 38 | [platforms-svg]: https://img.shields.io/badge/platform-Android-lightgrey.svg 39 | -------------------------------------------------------------------------------- /mediation/mopub/com/mopub/MopubCustomParamsUtils.java: -------------------------------------------------------------------------------- 1 | package com.mopub; 2 | 3 | import android.util.Log; 4 | 5 | import com.my.target.common.CustomParams; 6 | 7 | import java.util.Map; 8 | 9 | import androidx.annotation.NonNull; 10 | 11 | public final class MopubCustomParamsUtils 12 | { 13 | private static final String TAG = "MopubCustomParamsUtils"; 14 | public static final String EXTRA_GENDER = "mytarget_gender"; 15 | public static final String EXTRA_AGE = "mytarget_age"; 16 | public static final String EXTRA_VKID = "mytarget_vk_id"; 17 | public static final String EXTRA_OKID = "mytarget_ok_id"; 18 | 19 | public static void mergeExtras(@NonNull Map serverExtras, 20 | @NonNull Map localExtras) 21 | { 22 | for (final String key : localExtras.keySet()) 23 | { 24 | final Object value = localExtras.get(key); 25 | if (value != null && !serverExtras.containsKey(key)) 26 | { 27 | serverExtras.put(key, value.toString()); 28 | } 29 | } 30 | } 31 | 32 | public static void fillCustomParams(@NonNull CustomParams customParams, 33 | @NonNull Map extras) 34 | { 35 | customParams.setCustomParam("mediation", "2"); 36 | 37 | String genderValue = extras.get(EXTRA_GENDER); 38 | if (genderValue != null) 39 | { 40 | int gender = 0; 41 | try 42 | { 43 | gender = Integer.parseInt(genderValue); 44 | } 45 | catch (NumberFormatException ignored) 46 | { 47 | } 48 | if (gender >= 0 && gender < 3) 49 | { 50 | customParams.setGender(gender); 51 | } 52 | else 53 | { 54 | Log.e(TAG, "Wrong mopub extra value: " + EXTRA_GENDER 55 | + " must be 0 (undefined) or 1 (male), or 2 (female)"); 56 | } 57 | } 58 | 59 | String ageValue = extras.get(EXTRA_AGE); 60 | if (ageValue != null) 61 | { 62 | int age = 0; 63 | try 64 | { 65 | age = Integer.parseInt(ageValue); 66 | } 67 | catch (NumberFormatException ignored) 68 | { 69 | } 70 | if (age > 0) 71 | { 72 | customParams.setAge(age); 73 | } 74 | else 75 | { 76 | Log.e(TAG, "Wrong mopub extra value: " + EXTRA_AGE); 77 | } 78 | } 79 | 80 | String vkIdValue = extras.get(EXTRA_VKID); 81 | if (vkIdValue != null) 82 | { 83 | if (vkIdValue.length() > 0) 84 | { 85 | customParams.setVKId(vkIdValue); 86 | } 87 | else 88 | { 89 | Log.e(TAG, "Wrong mopub extra value: " + EXTRA_VKID + " is empty"); 90 | } 91 | } 92 | 93 | String okIdValue = extras.get(EXTRA_OKID); 94 | if (okIdValue != null) 95 | { 96 | if (okIdValue.length() > 0) 97 | { 98 | customParams.setOkId(okIdValue); 99 | } 100 | else 101 | { 102 | Log.e(TAG, "Wrong mopub extra value: " + EXTRA_OKID + " is empty"); 103 | } 104 | } 105 | } 106 | } 107 | -------------------------------------------------------------------------------- /mediation/mopub/com/mopub/mobileads/MyTargetAdapterConfiguration.java: -------------------------------------------------------------------------------- 1 | package com.mopub.mobileads; 2 | 3 | import android.content.Context; 4 | import androidx.annotation.NonNull; 5 | import androidx.annotation.Nullable; 6 | 7 | import com.mopub.common.BaseAdapterConfiguration; 8 | import com.mopub.common.OnNetworkInitializationFinishedListener; 9 | import com.my.target.common.MyTargetVersion; 10 | 11 | import java.util.Map; 12 | 13 | public final class MyTargetAdapterConfiguration extends BaseAdapterConfiguration 14 | { 15 | public static final String SLOT_ID_KEY = "slotId"; 16 | private static final String ADAPTER_VERSION = MyTargetVersion.VERSION + ".0"; 17 | private static final String NETWORK_NAME = "myTarget"; 18 | 19 | @Override 20 | public @NonNull String getAdapterVersion() 21 | { 22 | return ADAPTER_VERSION; 23 | } 24 | 25 | @Override 26 | public @Nullable String getBiddingToken(@NonNull Context context) 27 | { 28 | return null; 29 | } 30 | 31 | @Override 32 | public @NonNull String getMoPubNetworkName() 33 | { 34 | return NETWORK_NAME; 35 | } 36 | 37 | @Override 38 | public @NonNull String getNetworkSdkVersion() 39 | { 40 | return MyTargetVersion.VERSION; 41 | } 42 | 43 | @Override 44 | public void initializeNetwork(@NonNull Context context, @Nullable Map configuration, @NonNull OnNetworkInitializationFinishedListener listener) 45 | { 46 | listener.onNetworkInitializationFinished(MyTargetAdapterConfiguration.class, MoPubErrorCode.ADAPTER_INITIALIZATION_SUCCESS); 47 | } 48 | } 49 | -------------------------------------------------------------------------------- /mediation/mopub/com/mopub/mobileads/MyTargetMopubCustomEventInterstitial.java: -------------------------------------------------------------------------------- 1 | package com.mopub.mobileads; 2 | 3 | import android.app.Activity; 4 | import android.content.Context; 5 | 6 | import com.mopub.MopubCustomParamsUtils; 7 | import com.mopub.common.DataKeys; 8 | import com.mopub.common.LifecycleListener; 9 | import com.mopub.common.logging.MoPubLog; 10 | import com.mopub.common.logging.MoPubLog.AdLogEvent; 11 | import com.mopub.mobileads.AdLifecycleListener.InteractionListener; 12 | import com.mopub.mobileads.AdLifecycleListener.LoadListener; 13 | import com.my.target.ads.InterstitialAd; 14 | import com.my.target.ads.mediation.MyTargetAdapterUtils; 15 | 16 | import java.util.Map; 17 | 18 | import androidx.annotation.NonNull; 19 | import androidx.annotation.Nullable; 20 | 21 | import static com.mopub.common.logging.MoPubLog.AdapterLogEvent.CLICKED; 22 | import static com.mopub.common.logging.MoPubLog.AdapterLogEvent.CUSTOM; 23 | import static com.mopub.common.logging.MoPubLog.AdapterLogEvent.LOAD_ATTEMPTED; 24 | import static com.mopub.common.logging.MoPubLog.AdapterLogEvent.LOAD_FAILED; 25 | import static com.mopub.common.logging.MoPubLog.AdapterLogEvent.LOAD_SUCCESS; 26 | import static com.mopub.common.logging.MoPubLog.AdapterLogEvent.SHOW_ATTEMPTED; 27 | import static com.mopub.common.logging.MoPubLog.AdapterLogEvent.SHOW_SUCCESS; 28 | import static com.mopub.mobileads.MoPubErrorCode.NETWORK_NO_FILL; 29 | 30 | public final class MyTargetMopubCustomEventInterstitial extends BaseAd implements InterstitialAd.InterstitialAdListener 31 | { 32 | private static final String ADAPTER_NAME = MyTargetMopubCustomEventInterstitial.class.getSimpleName(); 33 | private @Nullable InterstitialAd interstitialAd; 34 | private @NonNull String adNetworkId = ""; 35 | 36 | @Override 37 | protected void load(@NonNull final Context context, @NonNull final AdData adData) 38 | { 39 | setAutomaticImpressionAndClickTracking(false); 40 | 41 | final Map extras = adData.getExtras(); 42 | String sslotId = extras.get(MyTargetAdapterConfiguration.SLOT_ID_KEY); 43 | int slotId = MyTargetAdapterUtils.parseSlot(sslotId); 44 | if (slotId < 0) 45 | { 46 | LoadListener loadListener = mLoadListener; 47 | if (loadListener != null) 48 | { 49 | loadListener.onAdLoadFailed(MoPubErrorCode.NETWORK_NO_FILL); 50 | MoPubLog.log(getAdNetworkId(), LOAD_FAILED, ADAPTER_NAME, 51 | MoPubErrorCode.NETWORK_NO_FILL.getIntCode(), MoPubErrorCode.NETWORK_NO_FILL); 52 | } 53 | return; 54 | } 55 | adNetworkId = sslotId != null ? sslotId : ""; 56 | MyTargetAdapterUtils.handleConsent(); 57 | 58 | interstitialAd = new InterstitialAd(slotId, context); 59 | final String adMarkup = extras.get(DataKeys.ADM_KEY); 60 | 61 | MopubCustomParamsUtils.fillCustomParams(interstitialAd.getCustomParams(), extras); 62 | 63 | interstitialAd.setListener(this); 64 | 65 | if (adMarkup == null || adMarkup.length() == 0) 66 | { 67 | interstitialAd.load(); 68 | } 69 | else 70 | { 71 | interstitialAd.loadFromBid(adMarkup); 72 | } 73 | MoPubLog.log(getAdNetworkId(), LOAD_ATTEMPTED, ADAPTER_NAME); 74 | } 75 | 76 | @Override 77 | protected void show() 78 | { 79 | MoPubLog.log(getAdNetworkId(), SHOW_ATTEMPTED, ADAPTER_NAME); 80 | if (interstitialAd != null) 81 | { 82 | interstitialAd.show(); 83 | } 84 | } 85 | 86 | @Override 87 | protected void onInvalidate() 88 | { 89 | if (interstitialAd != null) 90 | { 91 | interstitialAd.setListener(null); 92 | interstitialAd.destroy(); 93 | } 94 | interstitialAd = null; 95 | } 96 | 97 | @Override 98 | protected @Nullable LifecycleListener getLifecycleListener() 99 | { 100 | return null; 101 | } 102 | 103 | @Override 104 | protected @NonNull String getAdNetworkId() 105 | { 106 | return adNetworkId; 107 | } 108 | 109 | @Override 110 | protected boolean checkAndInitializeSdk(@NonNull Activity launcherActivity, @NonNull AdData adData) 111 | { 112 | return false; 113 | } 114 | 115 | @Override 116 | public void onLoad(@NonNull InterstitialAd ad) 117 | { 118 | LoadListener loadListener = mLoadListener; 119 | if (loadListener != null) 120 | { 121 | loadListener.onAdLoaded(); 122 | MoPubLog.log(getAdNetworkId(), LOAD_SUCCESS, ADAPTER_NAME); 123 | } 124 | } 125 | 126 | @Override 127 | public void onNoAd(@NonNull String reason, @NonNull InterstitialAd ad) 128 | { 129 | MoPubLog.log(getAdNetworkId(), CUSTOM, ADAPTER_NAME, "myTarget banner ad failed " + 130 | "to load."); 131 | 132 | MoPubErrorCode code = NETWORK_NO_FILL; 133 | MoPubLog.log(getAdNetworkId(), AdLogEvent.LOAD_FAILED, ADAPTER_NAME, code.getIntCode(), code); 134 | 135 | LoadListener loadListener = mLoadListener; 136 | InteractionListener interactionListener = mInteractionListener; 137 | if (interactionListener == null && loadListener != null) 138 | { 139 | loadListener.onAdLoadFailed(code); 140 | } 141 | else if (interactionListener != null) 142 | { 143 | interactionListener.onAdFailed(code); 144 | } 145 | } 146 | 147 | @Override 148 | public void onClick(@NonNull InterstitialAd ad) 149 | { 150 | MoPubLog.log(getAdNetworkId(), CLICKED, ADAPTER_NAME); 151 | InteractionListener interactionListener = mInteractionListener; 152 | if (interactionListener != null) 153 | { 154 | interactionListener.onAdClicked(); 155 | } 156 | } 157 | 158 | @Override 159 | public void onDismiss(@NonNull InterstitialAd ad) 160 | { 161 | InteractionListener interactionListener = mInteractionListener; 162 | if (interactionListener != null) 163 | { 164 | interactionListener.onAdDismissed(); 165 | } 166 | } 167 | 168 | @Override 169 | public void onVideoCompleted(@NonNull InterstitialAd ad) 170 | { 171 | MoPubLog.log(AdLogEvent.CUSTOM, ADAPTER_NAME, "Video Completed"); 172 | } 173 | 174 | @Override 175 | public void onDisplay(@NonNull InterstitialAd ad) 176 | { 177 | MoPubLog.log(getAdNetworkId(), SHOW_SUCCESS, ADAPTER_NAME); 178 | InteractionListener interactionListener = mInteractionListener; 179 | if (interactionListener != null) 180 | { 181 | interactionListener.onAdShown(); 182 | interactionListener.onAdImpression(); 183 | } 184 | } 185 | } 186 | -------------------------------------------------------------------------------- /mediation/mopub/com/mopub/mobileads/MyTargetMopubCustomEventRewardedVideo.java: -------------------------------------------------------------------------------- 1 | package com.mopub.mobileads; 2 | 3 | import android.app.Activity; 4 | import android.content.Context; 5 | 6 | import com.mopub.MopubCustomParamsUtils; 7 | import com.mopub.common.DataKeys; 8 | import com.mopub.common.LifecycleListener; 9 | import com.mopub.common.MoPubReward; 10 | import com.mopub.common.logging.MoPubLog; 11 | import com.mopub.common.logging.MoPubLog.AdLogEvent; 12 | import com.mopub.mobileads.AdLifecycleListener.InteractionListener; 13 | import com.mopub.mobileads.AdLifecycleListener.LoadListener; 14 | import com.my.target.ads.Reward; 15 | import com.my.target.ads.RewardedAd; 16 | import com.my.target.ads.mediation.MyTargetAdapterUtils; 17 | 18 | import java.util.Map; 19 | 20 | import androidx.annotation.NonNull; 21 | import androidx.annotation.Nullable; 22 | 23 | import static com.mopub.common.logging.MoPubLog.AdapterLogEvent.CLICKED; 24 | import static com.mopub.common.logging.MoPubLog.AdapterLogEvent.CUSTOM; 25 | import static com.mopub.common.logging.MoPubLog.AdapterLogEvent.LOAD_ATTEMPTED; 26 | import static com.mopub.common.logging.MoPubLog.AdapterLogEvent.LOAD_FAILED; 27 | import static com.mopub.common.logging.MoPubLog.AdapterLogEvent.LOAD_SUCCESS; 28 | import static com.mopub.common.logging.MoPubLog.AdapterLogEvent.SHOW_ATTEMPTED; 29 | import static com.mopub.common.logging.MoPubLog.AdapterLogEvent.SHOW_SUCCESS; 30 | import static com.mopub.mobileads.MoPubErrorCode.NETWORK_NO_FILL; 31 | 32 | public final class MyTargetMopubCustomEventRewardedVideo extends BaseAd implements RewardedAd.RewardedAdListener 33 | { 34 | private static final String ADAPTER_NAME = MyTargetMopubCustomEventRewardedVideo.class.getSimpleName(); 35 | private @Nullable RewardedAd rewardedAd; 36 | private @NonNull String adNetworkId = ""; 37 | 38 | @Override 39 | protected void load(@NonNull final Context context, @NonNull final AdData adData) 40 | { 41 | setAutomaticImpressionAndClickTracking(false); 42 | 43 | final Map extras = adData.getExtras(); 44 | String sslotId = extras.get(MyTargetAdapterConfiguration.SLOT_ID_KEY); 45 | int slotId = MyTargetAdapterUtils.parseSlot(sslotId); 46 | if (slotId < 0) 47 | { 48 | LoadListener loadListener = mLoadListener; 49 | if (loadListener != null) 50 | { 51 | loadListener.onAdLoadFailed(MoPubErrorCode.NETWORK_NO_FILL); 52 | MoPubLog.log(getAdNetworkId(), LOAD_FAILED, ADAPTER_NAME, 53 | MoPubErrorCode.NETWORK_NO_FILL.getIntCode(), MoPubErrorCode.NETWORK_NO_FILL); 54 | } 55 | return; 56 | } 57 | adNetworkId = sslotId != null ? sslotId : ""; 58 | MyTargetAdapterUtils.handleConsent(); 59 | 60 | rewardedAd = new RewardedAd(slotId, context); 61 | final String adMarkup = extras.get(DataKeys.ADM_KEY); 62 | 63 | MopubCustomParamsUtils.fillCustomParams(rewardedAd.getCustomParams(), extras); 64 | 65 | rewardedAd.setListener(this); 66 | 67 | if (adMarkup == null || adMarkup.length() == 0) 68 | { 69 | rewardedAd.load(); 70 | } 71 | else 72 | { 73 | rewardedAd.loadFromBid(adMarkup); 74 | } 75 | MoPubLog.log(getAdNetworkId(), LOAD_ATTEMPTED, ADAPTER_NAME); 76 | } 77 | 78 | @Override 79 | protected void show() 80 | { 81 | MoPubLog.log(getAdNetworkId(), SHOW_ATTEMPTED, ADAPTER_NAME); 82 | if (rewardedAd != null) 83 | { 84 | rewardedAd.show(); 85 | } 86 | } 87 | 88 | @Override 89 | protected void onInvalidate() 90 | { 91 | if (rewardedAd != null) 92 | { 93 | rewardedAd.setListener(null); 94 | rewardedAd.destroy(); 95 | } 96 | rewardedAd = null; 97 | } 98 | 99 | @Override 100 | protected @Nullable LifecycleListener getLifecycleListener() 101 | { 102 | return null; 103 | } 104 | 105 | @Override 106 | protected @NonNull String getAdNetworkId() 107 | { 108 | return adNetworkId; 109 | } 110 | 111 | @Override 112 | protected boolean checkAndInitializeSdk(@NonNull Activity launcherActivity, @NonNull AdData adData) 113 | { 114 | return false; 115 | } 116 | 117 | @Override 118 | public void onLoad(@NonNull RewardedAd ad) 119 | { 120 | LoadListener loadListener = mLoadListener; 121 | if (loadListener != null) 122 | { 123 | loadListener.onAdLoaded(); 124 | MoPubLog.log(getAdNetworkId(), LOAD_SUCCESS, ADAPTER_NAME); 125 | } 126 | } 127 | 128 | @Override 129 | public void onNoAd(@NonNull String reason, @NonNull RewardedAd ad) 130 | { 131 | MoPubLog.log(getAdNetworkId(), CUSTOM, ADAPTER_NAME, "myTarget banner ad failed " + 132 | "to load."); 133 | 134 | MoPubErrorCode code = NETWORK_NO_FILL; 135 | MoPubLog.log(getAdNetworkId(), AdLogEvent.LOAD_FAILED, ADAPTER_NAME, code.getIntCode(), code); 136 | 137 | InteractionListener interactionListener = mInteractionListener; 138 | LoadListener loadListener = mLoadListener; 139 | if (interactionListener == null && loadListener != null) 140 | { 141 | loadListener.onAdLoadFailed(code); 142 | } 143 | else if (interactionListener != null) 144 | { 145 | interactionListener.onAdFailed(code); 146 | } 147 | } 148 | 149 | @Override 150 | public void onClick(@NonNull RewardedAd ad) 151 | { 152 | MoPubLog.log(getAdNetworkId(), CLICKED, ADAPTER_NAME); 153 | InteractionListener interactionListener = mInteractionListener; 154 | if (interactionListener != null) 155 | { 156 | interactionListener.onAdClicked(); 157 | } 158 | } 159 | 160 | @Override 161 | public void onDismiss(@NonNull RewardedAd ad) 162 | { 163 | InteractionListener interactionListener = mInteractionListener; 164 | if (interactionListener != null) 165 | { 166 | interactionListener.onAdDismissed(); 167 | } 168 | } 169 | 170 | @Override 171 | public void onReward(@NonNull Reward reward, @NonNull RewardedAd ad) 172 | { 173 | MoPubLog.log(AdLogEvent.CUSTOM, ADAPTER_NAME, "Rewarded"); 174 | InteractionListener interactionListener = mInteractionListener; 175 | if (interactionListener != null) 176 | { 177 | interactionListener.onAdComplete(MoPubReward.success(reward.type, MoPubReward.NO_REWARD_AMOUNT)); 178 | } 179 | } 180 | 181 | @Override 182 | public void onDisplay(@NonNull RewardedAd ad) 183 | { 184 | MoPubLog.log(getAdNetworkId(), SHOW_SUCCESS, ADAPTER_NAME); 185 | InteractionListener interactionListener = mInteractionListener; 186 | if (interactionListener != null) 187 | { 188 | interactionListener.onAdShown(); 189 | interactionListener.onAdImpression(); 190 | } 191 | } 192 | } 193 | -------------------------------------------------------------------------------- /mediation/mopub/com/mopub/nativeads/MyTargetAdRenderer.java: -------------------------------------------------------------------------------- 1 | package com.mopub.nativeads; 2 | 3 | import android.content.Context; 4 | import android.view.LayoutInflater; 5 | import android.view.View; 6 | import android.view.ViewGroup; 7 | import android.widget.TextView; 8 | 9 | import com.mopub.nativeads.MyTargetCustomEventNative.MyTargetNativeAd; 10 | 11 | import java.util.WeakHashMap; 12 | 13 | import androidx.annotation.NonNull; 14 | import androidx.annotation.Nullable; 15 | 16 | public final class MyTargetAdRenderer implements MoPubAdRenderer 17 | { 18 | private final @NonNull MyTargetViewBinder viewBinder; 19 | 20 | @NonNull final WeakHashMap viewHolderMap; 21 | 22 | public MyTargetAdRenderer(@NonNull MyTargetViewBinder binder) 23 | { 24 | viewBinder = binder; 25 | viewHolderMap = new WeakHashMap<>(); 26 | } 27 | 28 | @Override 29 | public @NonNull View createAdView(@NonNull Context context, @Nullable ViewGroup parent) 30 | { 31 | return LayoutInflater 32 | .from(context) 33 | .inflate(viewBinder.layoutId, parent, false); 34 | } 35 | 36 | @Override 37 | public void renderAdView(@NonNull View view, @NonNull MyTargetNativeAd ad) 38 | { 39 | MyTargetNativeViewHolder myTargetNativeViewHolder = viewHolderMap.get(view); 40 | if (myTargetNativeViewHolder == null) 41 | { 42 | myTargetNativeViewHolder = MyTargetNativeViewHolder.fromViewBinder(view, viewBinder); 43 | viewHolderMap.put(view, myTargetNativeViewHolder); 44 | } 45 | 46 | update(myTargetNativeViewHolder, ad); 47 | } 48 | 49 | @Override 50 | public boolean supports(@NonNull BaseNativeAd nativeAd) 51 | { 52 | return nativeAd instanceof MyTargetNativeAd; 53 | } 54 | 55 | private void update(final @NonNull MyTargetNativeViewHolder myTargetNativeViewHolder, 56 | final @NonNull MyTargetNativeAd nativeAd) 57 | { 58 | NativeRendererHelper.addTextView(myTargetNativeViewHolder.getTitleView(), 59 | nativeAd.getTitle()); 60 | NativeRendererHelper.addTextView(myTargetNativeViewHolder.getTextView(), nativeAd.getDescription()); 61 | NativeRendererHelper.addTextView(myTargetNativeViewHolder.getCallToActionView(), 62 | nativeAd.getCallToAction()); 63 | NativeRendererHelper.addTextView(myTargetNativeViewHolder.getAdvertisingLabelView(), 64 | nativeAd.getAdvertisingLabel()); 65 | View rootView = myTargetNativeViewHolder.getMainView(); 66 | NativeRendererHelper.addCtaButton(myTargetNativeViewHolder.getCallToActionView(), 67 | rootView, 68 | nativeAd.getCallToAction()); 69 | if (rootView != null) 70 | { 71 | nativeAd.registerView(rootView); 72 | } 73 | } 74 | 75 | static final class MyTargetNativeViewHolder 76 | { 77 | private @Nullable View mainView; 78 | private @Nullable TextView titleView; 79 | private @Nullable TextView textView; 80 | private @Nullable TextView callToActionView; 81 | private @Nullable TextView advertisingLabelView; 82 | 83 | // Use fromViewBinder instead of a constructor 84 | private MyTargetNativeViewHolder() 85 | { 86 | } 87 | 88 | static @NonNull MyTargetNativeViewHolder fromViewBinder(@Nullable final View view, 89 | @Nullable final MyTargetViewBinder myTargetViewBinder) 90 | { 91 | if (view == null || myTargetViewBinder == null) 92 | { 93 | return new MyTargetNativeViewHolder(); 94 | } 95 | 96 | final MyTargetNativeViewHolder viewHolder = new MyTargetNativeViewHolder(); 97 | viewHolder.mainView = view; 98 | viewHolder.titleView = view.findViewById(myTargetViewBinder.titleId); 99 | viewHolder.textView = view.findViewById(myTargetViewBinder.descriptionId); 100 | viewHolder.callToActionView = 101 | view.findViewById(myTargetViewBinder.callToActionId); 102 | viewHolder.advertisingLabelView = view.findViewById(myTargetViewBinder.advertisingLabelId); 103 | return viewHolder; 104 | } 105 | 106 | public @Nullable View getMainView() 107 | { 108 | return mainView; 109 | } 110 | 111 | public @Nullable TextView getTitleView() 112 | { 113 | return titleView; 114 | } 115 | 116 | public @Nullable TextView getTextView() 117 | { 118 | return textView; 119 | } 120 | 121 | public @Nullable TextView getCallToActionView() 122 | { 123 | return callToActionView; 124 | } 125 | 126 | public @Nullable TextView getAdvertisingLabelView() 127 | { 128 | return advertisingLabelView; 129 | } 130 | } 131 | 132 | public final static class MyTargetViewBinder 133 | { 134 | 135 | final int layoutId; 136 | final int titleId; 137 | final int descriptionId; 138 | final int callToActionId; 139 | final int advertisingLabelId; 140 | 141 | private MyTargetViewBinder(@NonNull final Builder builder) 142 | { 143 | this.layoutId = builder.layoutId; 144 | this.titleId = builder.titleId; 145 | this.descriptionId = builder.descriptionId; 146 | this.callToActionId = builder.callToActionId; 147 | this.advertisingLabelId = builder.advertisingLabelId; 148 | } 149 | 150 | public static class Builder 151 | { 152 | 153 | private final int layoutId; 154 | private int titleId; 155 | private int descriptionId; 156 | private int callToActionId; 157 | private int advertisingLabelId; 158 | 159 | public Builder(final int layoutId) 160 | { 161 | this.layoutId = layoutId; 162 | } 163 | 164 | @NonNull 165 | public final Builder titleId(final int titleId) 166 | { 167 | this.titleId = titleId; 168 | return this; 169 | } 170 | 171 | @NonNull 172 | public final Builder descriptionId(final int descriptionId) 173 | { 174 | this.descriptionId = descriptionId; 175 | return this; 176 | } 177 | 178 | @NonNull 179 | public final Builder callToActionId(final int callToActionId) 180 | { 181 | this.callToActionId = callToActionId; 182 | return this; 183 | } 184 | 185 | @NonNull 186 | public Builder advertisingLabelId(final int advertisingLabelId) 187 | { 188 | this.advertisingLabelId = advertisingLabelId; 189 | return this; 190 | } 191 | 192 | @NonNull 193 | public MyTargetViewBinder build() 194 | { 195 | return new MyTargetViewBinder(this); 196 | } 197 | } 198 | } 199 | } 200 | -------------------------------------------------------------------------------- /mediation/mopub/com/mopub/nativeads/MyTargetCustomEventNative.java: -------------------------------------------------------------------------------- 1 | package com.mopub.nativeads; 2 | 3 | import android.content.Context; 4 | import android.view.View; 5 | 6 | import com.mopub.MopubCustomParamsUtils; 7 | import com.mopub.common.DataKeys; 8 | import com.mopub.common.logging.MoPubLog; 9 | import com.mopub.mobileads.MyTargetAdapterConfiguration; 10 | import com.my.target.ads.mediation.MyTargetAdapterUtils; 11 | import com.my.target.common.CachePolicy; 12 | import com.my.target.nativeads.NativeAd; 13 | import com.my.target.nativeads.banners.NativePromoBanner; 14 | 15 | import java.util.Map; 16 | 17 | import androidx.annotation.NonNull; 18 | import androidx.annotation.Nullable; 19 | 20 | import static com.mopub.common.logging.MoPubLog.AdapterLogEvent.CLICKED; 21 | import static com.mopub.common.logging.MoPubLog.AdapterLogEvent.LOAD_ATTEMPTED; 22 | import static com.mopub.common.logging.MoPubLog.AdapterLogEvent.LOAD_FAILED; 23 | import static com.mopub.common.logging.MoPubLog.AdapterLogEvent.LOAD_SUCCESS; 24 | import static com.mopub.common.logging.MoPubLog.AdapterLogEvent.SHOW_SUCCESS; 25 | import static com.mopub.nativeads.NativeErrorCode.NETWORK_NO_FILL; 26 | 27 | public final class MyTargetCustomEventNative extends CustomEventNative 28 | { 29 | private static final String ADAPTER_NAME = MyTargetCustomEventNative.class.getSimpleName(); 30 | 31 | @Override 32 | protected void loadNativeAd(@NonNull Context context, 33 | @NonNull CustomEventNativeListener customEventNativeListener, 34 | @NonNull Map localExtras, 35 | @NonNull Map extras) 36 | { 37 | String sslotId = extras.get(MyTargetAdapterConfiguration.SLOT_ID_KEY); 38 | int slotId = MyTargetAdapterUtils.parseSlot(sslotId); 39 | if (slotId < 0) 40 | { 41 | customEventNativeListener.onNativeAdFailed(NETWORK_NO_FILL); 42 | MoPubLog.log(sslotId, LOAD_FAILED, ADAPTER_NAME, 43 | NETWORK_NO_FILL.getIntCode(), NETWORK_NO_FILL); 44 | return; 45 | } 46 | 47 | final String bid = extras.get(DataKeys.ADM_KEY); 48 | 49 | MyTargetAdapterUtils.handleConsent(); 50 | 51 | NativeAd nativeAd = new NativeAd(slotId, context); 52 | MopubCustomParamsUtils.mergeExtras(extras,localExtras); 53 | MopubCustomParamsUtils.fillCustomParams(nativeAd.getCustomParams(), extras); 54 | MyTargetNativeAd myTargetNativeAd = new MyTargetNativeAd(nativeAd, customEventNativeListener, bid, sslotId != null ? sslotId : ""); 55 | myTargetNativeAd.loadAd(); 56 | } 57 | 58 | static final class MyTargetNativeAd extends BaseNativeAd implements NativeAd.NativeAdListener 59 | { 60 | 61 | private final @NonNull NativeAd nativeAd; 62 | private final @NonNull CustomEventNativeListener listener; 63 | private final @Nullable String bid; 64 | private @Nullable NativePromoBanner promoBanner; 65 | private @NonNull String adNetworkId = ""; 66 | 67 | public MyTargetNativeAd(@NonNull NativeAd nativeAd, 68 | @NonNull CustomEventNativeListener customEventNativeListener, 69 | @Nullable String bid, 70 | @NonNull String adNetworkId) 71 | { 72 | listener = customEventNativeListener; 73 | this.nativeAd = nativeAd; 74 | this.bid = bid; 75 | this.adNetworkId = adNetworkId; 76 | } 77 | 78 | public void loadAd() 79 | { 80 | nativeAd.setCachePolicy(CachePolicy.NONE); 81 | nativeAd.setListener(this); 82 | if (bid == null || bid.length() == 0) 83 | { 84 | nativeAd.load(); 85 | } 86 | else 87 | { 88 | nativeAd.loadFromBid(bid); 89 | } 90 | MoPubLog.log(adNetworkId, LOAD_ATTEMPTED, ADAPTER_NAME); 91 | } 92 | 93 | final public @Nullable String getAdvertisingLabel() 94 | { 95 | return promoBanner != null ? promoBanner.getAdvertisingLabel() : null; 96 | } 97 | 98 | final public @Nullable String getTitle() 99 | { 100 | return promoBanner != null ? promoBanner.getTitle() : null; 101 | } 102 | 103 | final public @Nullable String getDescription() 104 | { 105 | return promoBanner != null ? promoBanner.getDescription() : null; 106 | } 107 | 108 | final public @Nullable String getCallToAction() 109 | { 110 | return promoBanner != null ? promoBanner.getCtaText() : null; 111 | } 112 | 113 | @Override 114 | public void onLoad(@NonNull NativePromoBanner banner, @NonNull NativeAd ad) 115 | { 116 | if (!nativeAd.equals(ad)) 117 | { 118 | listener.onNativeAdFailed(NETWORK_NO_FILL); 119 | MoPubLog.log(adNetworkId, LOAD_FAILED, ADAPTER_NAME, 120 | NETWORK_NO_FILL.getIntCode(), NETWORK_NO_FILL); 121 | return; 122 | } 123 | 124 | promoBanner = banner; 125 | listener.onNativeAdLoaded(this); 126 | MoPubLog.log(adNetworkId, LOAD_SUCCESS, ADAPTER_NAME); 127 | } 128 | 129 | @Override 130 | public void onNoAd(@NonNull String reason, @NonNull NativeAd ad) 131 | { 132 | NativeErrorCode errorCode = NativeErrorCode.NETWORK_NO_FILL; 133 | MoPubLog.log(adNetworkId, LOAD_FAILED, ADAPTER_NAME, errorCode.getIntCode(), 134 | errorCode); 135 | 136 | listener.onNativeAdFailed(errorCode); 137 | } 138 | 139 | @Override 140 | public void onClick(@NonNull NativeAd ad) 141 | { 142 | notifyAdClicked(); 143 | MoPubLog.log(adNetworkId, CLICKED, ADAPTER_NAME); 144 | } 145 | 146 | @Override 147 | public void onShow(@NonNull NativeAd ad) 148 | { 149 | notifyAdImpressed(); 150 | MoPubLog.log(adNetworkId, SHOW_SUCCESS, ADAPTER_NAME); 151 | } 152 | 153 | @Override 154 | public void onVideoPlay(@NonNull NativeAd ad) 155 | { 156 | } 157 | 158 | @Override 159 | public void onVideoPause(@NonNull NativeAd ad) 160 | { 161 | } 162 | 163 | @Override 164 | public void onVideoComplete(@NonNull NativeAd ad) 165 | { 166 | 167 | } 168 | 169 | @Override 170 | public void prepare(@NonNull View view) 171 | { 172 | 173 | } 174 | 175 | @Override 176 | public void clear(@NonNull View view) 177 | { 178 | nativeAd.unregisterView(); 179 | } 180 | 181 | @Override 182 | public void destroy() 183 | { 184 | } 185 | 186 | public void registerView(@NonNull View view) 187 | { 188 | nativeAd.registerView(view); 189 | } 190 | } 191 | } -------------------------------------------------------------------------------- /mediation/mopub/com/my/target/ads/mediation/MyTargetAdapterUtils.java: -------------------------------------------------------------------------------- 1 | package com.my.target.ads.mediation; 2 | 3 | import com.mopub.common.MoPub; 4 | import com.mopub.common.privacy.ConsentStatus; 5 | import com.mopub.common.privacy.PersonalInfoManager; 6 | import com.my.target.common.MyTargetPrivacy; 7 | 8 | import androidx.annotation.Nullable; 9 | 10 | public final class MyTargetAdapterUtils 11 | { 12 | public static final String SUPPORTED_MOPUB_VERSION = "5.18.0"; 13 | 14 | public static void handleConsent() 15 | { 16 | PersonalInfoManager personalInfoManager = MoPub.getPersonalInformationManager(); 17 | if (personalInfoManager != null) 18 | { 19 | ConsentStatus status = personalInfoManager.getPersonalInfoConsentStatus(); 20 | switch (status) 21 | { 22 | case DNT: 23 | case EXPLICIT_NO: 24 | MyTargetPrivacy.setUserConsent(false); 25 | break; 26 | case EXPLICIT_YES: 27 | MyTargetPrivacy.setUserConsent(true); 28 | break; 29 | default: 30 | break; 31 | } 32 | } 33 | } 34 | 35 | public static int parseSlot(@Nullable String slotString) 36 | { 37 | int slot = -1; 38 | if (slotString == null) 39 | { 40 | return slot; 41 | } 42 | try 43 | { 44 | slot = Integer.parseInt(slotString); 45 | } 46 | catch (NumberFormatException e) 47 | { 48 | e.printStackTrace(); 49 | } 50 | return slot; 51 | } 52 | } 53 | -------------------------------------------------------------------------------- /mediation/mopub/com/my/target/ads/mediation/MyTargetMopubCustomEventBanner.java: -------------------------------------------------------------------------------- 1 | package com.my.target.ads.mediation; 2 | 3 | import android.app.Activity; 4 | import android.content.Context; 5 | import android.view.View; 6 | 7 | import com.mopub.MopubCustomParamsUtils; 8 | import com.mopub.common.DataKeys; 9 | import com.mopub.common.LifecycleListener; 10 | import com.mopub.common.logging.MoPubLog; 11 | import com.mopub.common.util.Views; 12 | import com.mopub.mobileads.AdData; 13 | import com.mopub.mobileads.AdLifecycleListener.InteractionListener; 14 | import com.mopub.mobileads.AdLifecycleListener.LoadListener; 15 | import com.mopub.mobileads.BaseAd; 16 | import com.mopub.mobileads.MoPubErrorCode; 17 | import com.mopub.mobileads.MyTargetAdapterConfiguration; 18 | import com.my.target.ads.MyTargetView; 19 | import com.my.target.ads.MyTargetView.AdSize; 20 | import com.my.target.ads.MyTargetView.MyTargetViewListener; 21 | 22 | import java.util.Map; 23 | 24 | import androidx.annotation.NonNull; 25 | import androidx.annotation.Nullable; 26 | 27 | import static com.mopub.common.logging.MoPubLog.AdapterLogEvent.CLICKED; 28 | import static com.mopub.common.logging.MoPubLog.AdapterLogEvent.CUSTOM; 29 | import static com.mopub.common.logging.MoPubLog.AdapterLogEvent.LOAD_ATTEMPTED; 30 | import static com.mopub.common.logging.MoPubLog.AdapterLogEvent.LOAD_FAILED; 31 | import static com.mopub.common.logging.MoPubLog.AdapterLogEvent.LOAD_SUCCESS; 32 | import static com.mopub.mobileads.MoPubErrorCode.NETWORK_NO_FILL; 33 | 34 | public final class MyTargetMopubCustomEventBanner extends BaseAd implements MyTargetViewListener 35 | { 36 | private static final String ADAPTER_NAME = MyTargetMopubCustomEventBanner.class.getSimpleName(); 37 | 38 | private @Nullable MyTargetView myTargetView; 39 | private @NonNull String adNetworkId = ""; 40 | 41 | @Override 42 | public void onLoad(@NonNull MyTargetView myTargetView) 43 | { 44 | MoPubLog.log(getAdNetworkId(), CUSTOM, ADAPTER_NAME, "myTarget banner ad loaded " + 45 | "successfully. Showing ad..."); 46 | 47 | LoadListener loadListener = mLoadListener; 48 | if (loadListener != null) 49 | { 50 | loadListener.onAdLoaded(); 51 | MoPubLog.log(getAdNetworkId(), LOAD_SUCCESS, ADAPTER_NAME); 52 | } 53 | } 54 | 55 | @Override 56 | public void onNoAd(@NonNull String reason, @NonNull MyTargetView myTargetView) 57 | { 58 | MoPubLog.log(getAdNetworkId(), CUSTOM, ADAPTER_NAME, "myTarget banner ad failed to load."); 59 | 60 | MoPubErrorCode code = NETWORK_NO_FILL; 61 | MoPubLog.log(getAdNetworkId(), LOAD_FAILED, ADAPTER_NAME, code.getIntCode(), code); 62 | 63 | InteractionListener interactionListener = mInteractionListener; 64 | LoadListener loadListener = mLoadListener; 65 | if (interactionListener == null && loadListener != null) 66 | { 67 | loadListener.onAdLoadFailed(code); 68 | } 69 | else if (interactionListener != null) 70 | { 71 | interactionListener.onAdFailed(code); 72 | } 73 | } 74 | 75 | @Override 76 | public void onClick(@NonNull MyTargetView myTargetView) 77 | { 78 | InteractionListener interactionListener = mInteractionListener; 79 | if (interactionListener != null) 80 | { 81 | interactionListener.onAdClicked(); 82 | } 83 | MoPubLog.log(getAdNetworkId(), CLICKED, ADAPTER_NAME); 84 | } 85 | 86 | @Override 87 | public void onShow(@NonNull final MyTargetView myTargetView) 88 | { 89 | MoPubLog.log(getAdNetworkId(), CUSTOM, ADAPTER_NAME, "myTarget banner ad onShow"); 90 | InteractionListener interactionListener = mInteractionListener; 91 | if (interactionListener != null) 92 | { 93 | interactionListener.onAdImpression(); 94 | } 95 | } 96 | 97 | private @Nullable AdSize calculateSize(int width, int height, @NonNull Context context) 98 | { 99 | if (width == 300 && height == 250) 100 | { 101 | return AdSize.ADSIZE_300x250; 102 | } 103 | else if (width == 320 && height == 50) 104 | { 105 | return AdSize.ADSIZE_320x50; 106 | } 107 | else if (width == 728 && height == 90) 108 | { 109 | return AdSize.ADSIZE_728x90; 110 | } 111 | else if (width > 0) 112 | { 113 | return AdSize.getAdSizeForCurrentOrientation(width, context); 114 | } 115 | return null; 116 | } 117 | 118 | @Override 119 | protected void onInvalidate() 120 | { 121 | if (myTargetView != null) 122 | { 123 | Views.removeFromParent(myTargetView); 124 | myTargetView.setListener(null); 125 | myTargetView.destroy(); 126 | myTargetView = null; 127 | } 128 | } 129 | 130 | @Override 131 | protected @Nullable LifecycleListener getLifecycleListener() 132 | { 133 | return null; 134 | } 135 | 136 | @Override 137 | protected @NonNull String getAdNetworkId() 138 | { 139 | return adNetworkId; 140 | } 141 | 142 | @Override 143 | protected boolean checkAndInitializeSdk(@NonNull Activity launcherActivity, @NonNull AdData adData) 144 | { 145 | return false; 146 | } 147 | 148 | @Override 149 | protected @Nullable View getAdView() 150 | { 151 | return myTargetView; 152 | } 153 | 154 | @Override 155 | protected void load(@NonNull Context context, @NonNull AdData adData) 156 | { 157 | setAutomaticImpressionAndClickTracking(false); 158 | 159 | Map extras = adData.getExtras(); 160 | String sslotId = extras.get(MyTargetAdapterConfiguration.SLOT_ID_KEY); 161 | int slotId = MyTargetAdapterUtils.parseSlot(sslotId); 162 | if (slotId < 0) 163 | { 164 | MoPubLog.log(LOAD_FAILED, ADAPTER_NAME, NETWORK_NO_FILL.getIntCode(), NETWORK_NO_FILL); 165 | LoadListener loadListener = mLoadListener; 166 | if (loadListener != null) 167 | { 168 | loadListener.onAdLoadFailed(NETWORK_NO_FILL); 169 | } 170 | return; 171 | } 172 | adNetworkId = sslotId != null ? sslotId : ""; 173 | MyTargetAdapterUtils.handleConsent(); 174 | Integer adHeight = adData.getAdHeight(); 175 | Integer adWidth = adData.getAdWidth(); 176 | AdSize adSize = calculateSize(adWidth == null ? 0 : adWidth, adHeight == null ? 0 : adHeight, context); 177 | 178 | if (myTargetView == null) 179 | { 180 | myTargetView = new MyTargetView(context); 181 | MopubCustomParamsUtils.fillCustomParams(myTargetView.getCustomParams(), extras); 182 | myTargetView.setSlotId(slotId); 183 | if (adSize != null) 184 | { 185 | myTargetView.setAdSize(adSize); 186 | } 187 | myTargetView.setRefreshAd(false); 188 | myTargetView.setListener(this); 189 | } 190 | final String adMarkup = extras.get(DataKeys.ADM_KEY); 191 | if (adMarkup == null || adMarkup.length() == 0) 192 | { 193 | myTargetView.load(); 194 | } 195 | else 196 | { 197 | myTargetView.loadFromBid(adMarkup); 198 | } 199 | MoPubLog.log(getAdNetworkId(), LOAD_ATTEMPTED, ADAPTER_NAME); 200 | } 201 | } 202 | -------------------------------------------------------------------------------- /myTargetDemo/app/.gitignore: -------------------------------------------------------------------------------- 1 | /build 2 | -------------------------------------------------------------------------------- /myTargetDemo/app/build.gradle.kts: -------------------------------------------------------------------------------- 1 | plugins { 2 | id("com.android.application") 3 | id("kotlin-android") 4 | } 5 | 6 | android { 7 | namespace = "com.my.targetDemoApp" 8 | 9 | compileSdk = AndroidSdk.compile 10 | defaultConfig { 11 | applicationId = "com.my.targetDemoApp" 12 | minSdk = AndroidSdk.min 13 | targetSdk = AndroidSdk.target 14 | val ver = findVersionName() 15 | versionName = ver 16 | versionCode = convertVerToCode(ver) 17 | testInstrumentationRunner = "com.my.targetDemoTests.helpers.ScreenshotTestRunner" 18 | vectorDrawables.useSupportLibrary = true 19 | multiDexEnabled = true 20 | } 21 | lint { 22 | abortOnError = true 23 | warningsAsErrors = true 24 | lintConfig = File("../lint.xml") 25 | } 26 | buildTypes { 27 | getByName("release") { 28 | isMinifyEnabled = true 29 | proguardFiles(getDefaultProguardFile("proguard-android.txt"), "proguard-rules.pro") 30 | signingConfig = signingConfigs.getByName("debug") 31 | } 32 | } 33 | compileOptions { 34 | sourceCompatibility = JavaVersion.VERSION_1_8 35 | targetCompatibility = JavaVersion.VERSION_1_8 36 | } 37 | kotlinOptions { 38 | jvmTarget = "1.8" 39 | } 40 | buildFeatures { 41 | viewBinding = true 42 | } 43 | } 44 | 45 | dependencies { 46 | val sdkversion: String? by project 47 | debugImplementation("com.my.target:mytarget-sdk:$SDK_VERSION") 48 | releaseImplementation("com.my.target:mytarget-sdk:$sdkversion") 49 | implementation("org.jetbrains.kotlin:kotlin-stdlib-jdk8:$KOTLIN_VERSION") 50 | implementation("androidx.appcompat:appcompat:${AndroidX.appcompat}") 51 | implementation("com.google.android.material:material:${AndroidX.material}") 52 | implementation("androidx.cardview:cardview:${AndroidX.cardview}") 53 | implementation("androidx.recyclerview:recyclerview:${AndroidX.recyclerview}") 54 | implementation("androidx.constraintlayout:constraintlayout:${AndroidX.constraint}") 55 | implementation("com.google.android.gms:play-services-ads-identifier:${Google.play}") 56 | implementation("com.google.android.exoplayer:exoplayer:${Google.exoplayer}") 57 | implementation("androidx.navigation:navigation-fragment-ktx:${AndroidX.navigation}") 58 | implementation("androidx.navigation:navigation-ui-ktx:${AndroidX.navigation}") 59 | implementation("androidx.preference:preference-ktx:${AndroidX.preference}") 60 | implementation("androidx.multidex:multidex:${AndroidX.multidex}") 61 | 62 | androidTestImplementation("io.qameta.allure:allure-kotlin-model:${Test.allure}") 63 | androidTestImplementation("io.qameta.allure:allure-kotlin-commons:${Test.allure}") 64 | androidTestImplementation("io.qameta.allure:allure-kotlin-junit4:${Test.allure}") 65 | androidTestImplementation("io.qameta.allure:allure-kotlin-android:${Test.allure}") 66 | 67 | androidTestImplementation("junit:junit:${Test.junit}") 68 | androidTestImplementation("androidx.test:core:${Test.core}") 69 | androidTestImplementation("androidx.test:runner:${Test.runner}") 70 | androidTestImplementation("androidx.test:rules:${Test.rules}") 71 | androidTestImplementation("androidx.test.espresso:espresso-core:${Test.espresso}") 72 | androidTestImplementation("androidx.test.espresso:espresso-contrib:${Test.espresso}") { 73 | exclude(group = "org.checkerframework", module = "checker") 74 | } 75 | androidTestImplementation("androidx.test.espresso:espresso-intents:${Test.espresso}") 76 | androidTestImplementation("androidx.test.espresso:espresso-web:${Test.espresso}") 77 | androidTestImplementation("com.adevinta.android:barista:${Test.barista}") { 78 | exclude(group = "com.android.support") 79 | exclude(group = "org.jetbrains.kotlin") 80 | exclude(group = "org.checkerframework", module = "checker") 81 | } 82 | } 83 | 84 | apply(plugin = "shot") 85 | 86 | configure { 87 | appId = "com.my.targetDemoApp" 88 | } 89 | 90 | fun convertVerToCode(versionName: String): Int { 91 | return versionName.split(".") 92 | .take(3) 93 | .mapIndexed { index, s -> 94 | s.toInt() * (when (index) { 95 | 0 -> 1_000_000 96 | 1 -> 1000 97 | else -> 1 98 | }) 99 | } 100 | .sum() 101 | } 102 | 103 | fun findVersionName(): String { 104 | val sdkversion: String? by project 105 | return sdkversion ?: SDK_VERSION 106 | } 107 | -------------------------------------------------------------------------------- /myTargetDemo/app/proguard-rules.pro: -------------------------------------------------------------------------------- 1 | # Add project specific ProGuard rules here. 2 | # You can control the set of applied configuration files using the 3 | # proguardFiles setting in build.gradle. 4 | # 5 | # For more details, see 6 | # http://developer.android.com/guide/developing/tools/proguard.html 7 | 8 | # If your project uses WebView with JS, uncomment the following 9 | # and specify the fully qualified class name to the JavaScript interface 10 | # class: 11 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview { 12 | # public *; 13 | #} 14 | 15 | # Uncomment this to preserve the line number information for 16 | # debugging stack traces. 17 | #-keepattributes SourceFile,LineNumberTable 18 | 19 | # If you keep the line number information, uncomment this to 20 | # hide the original source file name. 21 | #-renamesourcefileattribute SourceFile 22 | -------------------------------------------------------------------------------- /myTargetDemo/app/src/androidTest/AndroidManifest.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 5 | 6 | 7 | 8 | android:requestLegacyExternalStorage="true" 9 | 10 | 11 | -------------------------------------------------------------------------------- /myTargetDemo/app/src/androidTest/java/com/my/targetDemoTests/helpers/Constants.kt: -------------------------------------------------------------------------------- 1 | package com.my.targetDemoTests.helpers 2 | 3 | class Slot { 4 | companion object { 5 | const val standard320x50 = 14170 6 | const val standard300x250 = 64526 7 | const val standard728x90 = 81620 8 | const val interstitialPromo = 6896 9 | const val interstitialVideo = 10138 10 | const val interstitialCarousel = 102652 11 | const val nativeAds = 6590 12 | const val instream = 9525 13 | const val audio_instream = 1208427 14 | } 15 | } 16 | 17 | class Callback { 18 | companion object { 19 | const val load = "[myTarget]: send stat request" 20 | const val pause = "playbackPaused" 21 | const val resume = "playbackResumed" 22 | } 23 | } -------------------------------------------------------------------------------- /myTargetDemo/app/src/androidTest/java/com/my/targetDemoTests/helpers/DeviceHelper.kt: -------------------------------------------------------------------------------- 1 | package com.my.targetDemoTests.helpers 2 | 3 | import androidx.test.InstrumentationRegistry 4 | import androidx.test.uiautomator.BySelector 5 | import androidx.test.uiautomator.UiDevice 6 | import androidx.test.uiautomator.Until 7 | 8 | class DeviceHelper { 9 | var device = UiDevice.getInstance(InstrumentationRegistry.getInstrumentation()) 10 | 11 | fun osVersion(): String { 12 | return device.executeShellCommand("getprop ro.build.version.release") 13 | } 14 | 15 | fun portrait() { 16 | device.unfreezeRotation() 17 | device.setOrientationNatural() 18 | } 19 | 20 | fun wait(element: BySelector, timeout: Long = 5000) { 21 | device.wait(Until.findObject(element), timeout) 22 | } 23 | 24 | fun wait(callback: String, timeout: Long = 5000): Boolean { 25 | val wait = System.currentTimeMillis() + timeout 26 | while (wait > System.currentTimeMillis()) { 27 | if (getLog().contains(callback)) { return true } 28 | } 29 | return false 30 | } 31 | 32 | fun landscape() { 33 | device.unfreezeRotation() 34 | device.setOrientationLeft() 35 | } 36 | 37 | fun isAppRunning(bundleId: String): Boolean { 38 | val result = device.executeShellCommand("shell ps | grep $bundleId") 39 | return !result.isEmpty() 40 | } 41 | 42 | fun closeApp(bundleId: String) { 43 | device.executeShellCommand("shell am force-stop$bundleId") 44 | } 45 | 46 | fun androidId(): String { 47 | return device.executeShellCommand("settings get secure android_id") 48 | } 49 | 50 | fun clearLog() { 51 | device.executeShellCommand("logcat -c") 52 | } 53 | 54 | fun getLog(): String { 55 | return device.executeShellCommand("logcat -d") 56 | } 57 | 58 | fun getLogByTag(tag: String): String { 59 | return device.executeShellCommand("logcat -d *:S $tag") 60 | } 61 | } -------------------------------------------------------------------------------- /myTargetDemo/app/src/androidTest/java/com/my/targetDemoTests/helpers/ScreenshotTestRunner.kt: -------------------------------------------------------------------------------- 1 | package com.my.targetDemoTests.helpers 2 | 3 | import android.os.Bundle 4 | import androidx.test.runner.AndroidJUnitRunner 5 | import com.facebook.testing.screenshot.ScreenshotRunner 6 | import io.qameta.allure.android.runners.AllureAndroidJUnitRunner 7 | 8 | 9 | class ScreenshotTestRunner: AllureAndroidJUnitRunner() { 10 | override fun onCreate(arguments: Bundle) { 11 | ScreenshotRunner.onCreate(this, arguments) 12 | super.onCreate(arguments) 13 | } 14 | 15 | override fun finish(resultCode: Int, results: Bundle) { 16 | ScreenshotRunner.onDestroy() 17 | super.finish(resultCode, results) 18 | } 19 | } -------------------------------------------------------------------------------- /myTargetDemo/app/src/androidTest/java/com/my/targetDemoTests/screens/AudioInstreamScreen.kt: -------------------------------------------------------------------------------- 1 | package com.my.targetDemoTests.screens 2 | 3 | import com.my.targetDemoApp.R 4 | 5 | class AudioInstreamScreen { 6 | val pauseBtn = R.id.btn_pause 7 | val resumeBtn = R.id.btn_resume 8 | val stopBtn = R.id.btn_stop 9 | val loadBtn = R.id.btn_load 10 | val play = R.id.exo_play 11 | val preRollBtn = R.id.btn_start_preroll 12 | val video = R.id.video_frame 13 | } -------------------------------------------------------------------------------- /myTargetDemo/app/src/androidTest/java/com/my/targetDemoTests/screens/BannersScreen.kt: -------------------------------------------------------------------------------- 1 | package com.my.targetDemoTests.screens 2 | 3 | import androidx.test.uiautomator.By 4 | import com.my.targetDemoApp.R 5 | import com.adevinta.android.barista.interaction.BaristaClickInteractions.clickOn 6 | 7 | class BannersScreen: WebViewScreen() { 8 | val adView = By.res("ad_view") 9 | private val rbtAdaptive = R.id.rbt_adaptive 10 | private val rbtHtml = R.id.rbt_html 11 | private val rbt320x50 = R.id.rbt_320x50 12 | private val rbt300x250 = R.id.rbt_300x250 13 | private val rbt728x90 = R.id.rbt_728x90 14 | private val showBtn = R.id.btn_gointerstitial 15 | val banner = R.id.banner_container 16 | 17 | fun showAdaptive() { 18 | clickOn(rbtAdaptive) 19 | clickOn(showBtn) 20 | } 21 | 22 | fun show320x50() { 23 | clickOn(rbt320x50) 24 | clickOn(showBtn) 25 | } 26 | 27 | fun show300x250() { 28 | clickOn(rbt300x250) 29 | clickOn(showBtn) 30 | } 31 | 32 | fun show728x90() { 33 | clickOn(rbt728x90) 34 | clickOn(showBtn) 35 | } 36 | } -------------------------------------------------------------------------------- /myTargetDemo/app/src/androidTest/java/com/my/targetDemoTests/screens/InstreamScreen.kt: -------------------------------------------------------------------------------- 1 | package com.my.targetDemoTests.screens 2 | 3 | import com.my.targetDemoApp.R 4 | 5 | class InstreamScreen { 6 | val pauseBtn = R.id.btn_pause 7 | val resumeBtn = R.id.btn_resume 8 | val stopBtn = R.id.btn_stop 9 | val loadBtn = R.id.btn_load 10 | val play = R.id.exo_play 11 | val ctaBtn = R.id.btn_cta 12 | val skipAllBtn = R.id.btn_skip 13 | val skipBtn = R.id.btn_skip_banner 14 | val video = R.id.video_frame 15 | } -------------------------------------------------------------------------------- /myTargetDemo/app/src/androidTest/java/com/my/targetDemoTests/screens/InterstitialScreen.kt: -------------------------------------------------------------------------------- 1 | package com.my.targetDemoTests.screens 2 | 3 | import androidx.test.uiautomator.By 4 | import com.my.targetDemoApp.R 5 | import com.adevinta.android.barista.interaction.BaristaClickInteractions.clickOn 6 | import com.adevinta.android.barista.interaction.BaristaSleepInteractions.sleep 7 | 8 | class InterstitialScreen : WebViewScreen() { 9 | val adView = By.res("media_view") 10 | val cards = By.res("ad_view") 11 | val image = By.clazz("android.widget.ImageView") 12 | private val rbtPromoStatic = R.id.rbt_promo_static 13 | private val rbtPromoVideo = R.id.rbt_promo_video 14 | private val rbtVideo = R.id.rbt_black_theme 15 | private val rbtVideoStyle2 = R.id.rbt_promo_video_style_2 16 | private val rbtVast = R.id.rbt_vast 17 | private val rbtImage = R.id.rbt_image 18 | private val rbtCards = R.id.rbt_carousel 19 | private val rbtHtml = R.id.rbt_html 20 | private val loadBtn = R.id.btn_load 21 | private val showActivityBtn = R.id.btn_gointerstitial 22 | 23 | fun showWithoutLoad() { 24 | clickOn(showActivityBtn) 25 | } 26 | 27 | fun showPromoStatic() { 28 | clickOn(rbtPromoStatic) 29 | loadAndShow() 30 | } 31 | 32 | fun showPromoVideo() { 33 | clickOn(rbtPromoVideo) 34 | loadAndShow() 35 | } 36 | 37 | fun showPromoCards() { 38 | clickOn(rbtCards) 39 | loadAndShow() 40 | } 41 | 42 | fun showVideo() { 43 | clickOn(rbtVideo) 44 | loadAndShow() 45 | } 46 | 47 | fun showVideoStyle2() { 48 | clickOn(rbtVideoStyle2) 49 | loadAndShow() 50 | } 51 | 52 | fun showVast() { 53 | clickOn(rbtVast) 54 | loadAndShow() 55 | } 56 | 57 | fun showImage() { 58 | clickOn(rbtImage) 59 | loadAndShow() 60 | } 61 | 62 | fun showHtml() { 63 | clickOn(rbtHtml) 64 | loadAndShow() 65 | } 66 | 67 | private fun loadAndShow() { 68 | clickOn(loadBtn) 69 | sleep(1000) 70 | clickOn(showActivityBtn) 71 | } 72 | } -------------------------------------------------------------------------------- /myTargetDemo/app/src/androidTest/java/com/my/targetDemoTests/screens/MainScreen.kt: -------------------------------------------------------------------------------- 1 | package com.my.targetDemoTests.screens 2 | 3 | import androidx.test.espresso.Espresso.onView 4 | import androidx.test.espresso.contrib.RecyclerViewActions.scrollToPosition 5 | import androidx.test.espresso.matcher.ViewMatchers.withId 6 | import androidx.recyclerview.widget.RecyclerView 7 | import com.my.targetDemoApp.R 8 | import com.my.targetDemoTests.helpers.Slot 9 | import com.adevinta.android.barista.interaction.BaristaClickInteractions.clickOn 10 | import com.adevinta.android.barista.interaction.BaristaEditTextInteractions.writeTo 11 | 12 | class MainScreen { 13 | val banners = "Banners" 14 | val interstitial = "Interstitial" 15 | val native = "Native Ads" 16 | val instream = "InStream" 17 | val plus = R.id.fab 18 | private val adType320x50 = R.id.adtype_banner_320x50 19 | private val adType300x250 = R.id.adtype_banner_300x250 20 | private val adType728x90 = R.id.adtype_banner_728x90 21 | private val adTypeInterstitial = R.id.adtype_interstitial 22 | private val adTypeInstream = R.id.adtype_instream 23 | private val adTypeAudioInstream = R.id.adtype_audio_instream 24 | private val adTypeNative = R.id.adtype_native 25 | private val slotId = R.id.editText 26 | private val ok = R.string.ok 27 | val cancel = R.string.cancel 28 | 29 | fun addUnit(slot: Int) { 30 | clickOn(plus) 31 | when(slot) { 32 | Slot.standard320x50 -> clickOn(adType320x50) 33 | Slot.standard300x250 -> clickOn(adType300x250) 34 | Slot.standard728x90 -> clickOn(adType728x90) 35 | Slot.interstitialPromo, 36 | Slot.interstitialVideo, 37 | Slot.interstitialCarousel -> clickOn(adTypeInterstitial) 38 | Slot.instream -> clickOn(adTypeInstream) 39 | Slot.audio_instream -> clickOn(adTypeAudioInstream) 40 | Slot.nativeAds -> clickOn(adTypeNative) 41 | else -> { clickOn(adType320x50) } 42 | } 43 | writeTo(slotId, slot.toString()) 44 | clickOn(ok) 45 | onView(withId(R.id.main_recycler)).perform(scrollToPosition(8)) 46 | 47 | } 48 | 49 | fun addUnitWithoutSlot() { 50 | clickOn(plus) 51 | clickOn(ok) 52 | } 53 | } -------------------------------------------------------------------------------- /myTargetDemo/app/src/androidTest/java/com/my/targetDemoTests/screens/NativeScreen.kt: -------------------------------------------------------------------------------- 1 | package com.my.targetDemoTests.screens 2 | 3 | import androidx.test.uiautomator.By 4 | import com.my.targetDemoApp.R 5 | import com.adevinta.android.barista.interaction.BaristaClickInteractions 6 | 7 | class NativeScreen { 8 | val adView = By.res("com.my.targetDemoApp:id/native_ad_view") 9 | private val rbtVideo = R.id.rbt_video 10 | private val rbtCards = R.id.rbt_cards 11 | private val rbtStatic = R.id.rbt_none 12 | private val showBtn = R.id.btn_gonative 13 | val banner = R.id.nativeads_ad_view 14 | 15 | fun showContentStreamStatic() { 16 | BaristaClickInteractions.clickOn(rbtStatic) 17 | BaristaClickInteractions.clickOn(showBtn) 18 | } 19 | 20 | fun showContentStreamVideo() { 21 | BaristaClickInteractions.clickOn(rbtVideo) 22 | BaristaClickInteractions.clickOn(showBtn) 23 | } 24 | 25 | fun showContentStreamCards() { 26 | BaristaClickInteractions.clickOn(rbtCards) 27 | BaristaClickInteractions.clickOn(showBtn) 28 | } 29 | 30 | } -------------------------------------------------------------------------------- /myTargetDemo/app/src/androidTest/java/com/my/targetDemoTests/screens/WebViewScreen.kt: -------------------------------------------------------------------------------- 1 | package com.my.targetDemoTests.screens 2 | 3 | import androidx.test.uiautomator.By 4 | 5 | open class WebViewScreen { 6 | val webview = By.clazz("android.webkit.WebView") 7 | } -------------------------------------------------------------------------------- /myTargetDemo/app/src/androidTest/java/com/my/targetDemoTests/tests/AudioInstreamTest.kt: -------------------------------------------------------------------------------- 1 | package com.my.targetDemoTests.tests 2 | 3 | import com.facebook.testing.screenshot.Screenshot 4 | import com.my.targetDemoApp.activities.AudioInstreamActivity 5 | import com.my.targetDemoTests.helpers.Callback 6 | import com.my.targetDemoTests.screens.AudioInstreamScreen 7 | import com.adevinta.android.barista.interaction.BaristaClickInteractions.clickOn 8 | import com.adevinta.android.barista.interaction.BaristaSleepInteractions.sleep 9 | import com.adevinta.android.barista.rule.BaristaRule 10 | import io.qameta.allure.android.runners.AllureAndroidJUnit4 11 | import org.junit.Assert.assertFalse 12 | import org.junit.Assert.assertTrue 13 | import org.junit.Before 14 | import org.junit.Rule 15 | import org.junit.Test 16 | import org.junit.runner.RunWith 17 | 18 | @RunWith(AllureAndroidJUnit4::class) 19 | class AudioInstreamTest : TestBase() 20 | { 21 | 22 | @get:Rule 23 | var baristaRule = BaristaRule.create(AudioInstreamActivity::class.java) 24 | 25 | @Before 26 | override fun setUp() 27 | { 28 | super.setUp() 29 | baristaRule.launchActivity() 30 | } 31 | 32 | @Test 33 | fun test_InstreamLoadAdSnapshot() 34 | { 35 | val instreamScreen = AudioInstreamScreen() 36 | clickOn(instreamScreen.pauseBtn) 37 | clickOn(instreamScreen.resumeBtn) 38 | clickOn(instreamScreen.stopBtn) 39 | clickOn(instreamScreen.loadBtn) 40 | clickOn(instreamScreen.video) 41 | sleep(1000) 42 | Screenshot.snapActivity(baristaRule.activityTestRule.activity).record() 43 | } 44 | 45 | @Test 46 | fun test_InstreamPause() 47 | { 48 | val instreamScreen = AudioInstreamScreen() 49 | clickOn(instreamScreen.loadBtn) 50 | device.wait(callback = "[myTarget]: done") 51 | clickOn(instreamScreen.preRollBtn) 52 | sleep(1000) 53 | clickOn(instreamScreen.pauseBtn) 54 | assertTrue(device.wait(callback = Callback.pause)) 55 | } 56 | 57 | @Test 58 | fun test_InstreamResume() 59 | { 60 | val instreamScreen = AudioInstreamScreen() 61 | clickOn(instreamScreen.loadBtn) 62 | sleep(1000) 63 | device.wait(callback = "[myTarget]: done") 64 | clickOn(instreamScreen.preRollBtn) 65 | clickOn(instreamScreen.pauseBtn) 66 | clickOn(instreamScreen.resumeBtn) 67 | assertTrue(device.wait(callback = Callback.resume)) 68 | } 69 | 70 | @Test 71 | fun test_InstreamStop() 72 | { 73 | val instreamScreen = AudioInstreamScreen() 74 | clickOn(instreamScreen.play) 75 | clickOn(instreamScreen.loadBtn) 76 | sleep(3000) 77 | clickOn(instreamScreen.preRollBtn) 78 | sleep(1000) 79 | clickOn(instreamScreen.pauseBtn) 80 | clickOn(instreamScreen.stopBtn) 81 | clickOn(instreamScreen.resumeBtn) 82 | assertFalse(device.wait(callback = Callback.resume, timeout = 3000)) 83 | } 84 | } -------------------------------------------------------------------------------- /myTargetDemo/app/src/androidTest/java/com/my/targetDemoTests/tests/BannersTest.kt: -------------------------------------------------------------------------------- 1 | package com.my.targetDemoTests.tests 2 | 3 | import androidx.test.espresso.web.sugar.Web.onWebView 4 | import com.facebook.testing.screenshot.Screenshot 5 | import com.my.targetDemoApp.activities.BannersActivity 6 | import com.my.targetDemoTests.screens.BannersScreen 7 | import com.adevinta.android.barista.rule.BaristaRule 8 | import io.qameta.allure.android.runners.AllureAndroidJUnit4 9 | import org.junit.Before 10 | import org.junit.Rule 11 | import org.junit.Test 12 | import org.junit.runner.RunWith 13 | 14 | @RunWith(AllureAndroidJUnit4::class) 15 | class BannersTest : TestBase() { 16 | 17 | private val bannersScreen = BannersScreen() 18 | 19 | @get:Rule 20 | var baristaRule = BaristaRule.create(BannersActivity::class.java) 21 | 22 | @Before 23 | override fun setUp() { 24 | super.setUp() 25 | baristaRule.launchActivity() 26 | } 27 | 28 | @Test 29 | fun test_BannersMenuSnapshot() { 30 | Screenshot.snapActivity(baristaRule.activityTestRule.activity) 31 | .record() 32 | } 33 | 34 | @Test 35 | fun test_Show320x50() { 36 | bannersScreen.show320x50() 37 | device.wait(bannersScreen.webview) 38 | onWebView().forceJavascriptEnabled() 39 | } 40 | 41 | @Test 42 | fun test_Show300x250() { 43 | bannersScreen.show300x250() 44 | device.wait(bannersScreen.webview) 45 | onWebView().forceJavascriptEnabled() 46 | } 47 | 48 | @Test 49 | fun test_Show728x90() { 50 | bannersScreen.show728x90() 51 | device.wait(bannersScreen.webview) 52 | onWebView().forceJavascriptEnabled() 53 | } 54 | 55 | @Test 56 | fun test_ShowAdaptive() { 57 | bannersScreen.showAdaptive() 58 | device.wait(bannersScreen.webview) 59 | } 60 | } -------------------------------------------------------------------------------- /myTargetDemo/app/src/androidTest/java/com/my/targetDemoTests/tests/InstreamTest.kt: -------------------------------------------------------------------------------- 1 | package com.my.targetDemoTests.tests 2 | 3 | import com.facebook.testing.screenshot.Screenshot 4 | import com.my.targetDemoApp.activities.InstreamActivity 5 | import com.my.targetDemoTests.helpers.Callback 6 | import com.my.targetDemoTests.screens.InstreamScreen 7 | import com.adevinta.android.barista.interaction.BaristaClickInteractions.clickOn 8 | import com.adevinta.android.barista.interaction.BaristaSleepInteractions.sleep 9 | import com.adevinta.android.barista.rule.BaristaRule 10 | import io.qameta.allure.android.runners.AllureAndroidJUnit4 11 | import org.junit.Assert.assertFalse 12 | import org.junit.Assert.assertTrue 13 | import org.junit.Before 14 | import org.junit.Rule 15 | import org.junit.Test 16 | import org.junit.runner.RunWith 17 | 18 | @RunWith(AllureAndroidJUnit4::class) 19 | class InstreamTest: TestBase() { 20 | 21 | @get:Rule 22 | var baristaRule = BaristaRule.create(InstreamActivity::class.java) 23 | 24 | @Before 25 | override fun setUp() { 26 | super.setUp() 27 | baristaRule.launchActivity() 28 | } 29 | 30 | @Test 31 | fun test_InstreamLoadAdSnapshot() { 32 | val instreamScreen = InstreamScreen() 33 | clickOn(instreamScreen.pauseBtn) 34 | clickOn(instreamScreen.resumeBtn) 35 | clickOn(instreamScreen.stopBtn) 36 | clickOn(instreamScreen.loadBtn) 37 | clickOn(instreamScreen.video) 38 | sleep(1000) 39 | Screenshot.snapActivity(baristaRule.activityTestRule.activity).record() 40 | } 41 | 42 | @Test 43 | fun test_InstreamPause() { 44 | val instreamScreen = InstreamScreen() 45 | clickOn(instreamScreen.loadBtn) 46 | device.wait(callback = "[myTarget]: done") 47 | clickOn(instreamScreen.play) 48 | sleep(1000) 49 | clickOn(instreamScreen.pauseBtn) 50 | assertTrue(device.wait(callback = Callback.pause)) 51 | } 52 | 53 | @Test 54 | fun test_InstreamResume() { 55 | val instreamScreen = InstreamScreen() 56 | clickOn(instreamScreen.loadBtn) 57 | device.wait(callback = "[myTarget]: done") 58 | clickOn(instreamScreen.play) 59 | sleep(1000) 60 | clickOn(instreamScreen.pauseBtn) 61 | clickOn(instreamScreen.resumeBtn) 62 | assertTrue(device.wait(callback = Callback.resume)) 63 | } 64 | 65 | @Test 66 | fun test_InstreamStop() { 67 | val instreamScreen = InstreamScreen() 68 | clickOn(instreamScreen.loadBtn) 69 | sleep(3000) 70 | clickOn(instreamScreen.play) 71 | sleep(1000) 72 | clickOn(instreamScreen.pauseBtn) 73 | clickOn(instreamScreen.stopBtn) 74 | clickOn(instreamScreen.resumeBtn) 75 | assertFalse(device.wait(callback = Callback.resume, timeout = 3000)) 76 | } 77 | 78 | } -------------------------------------------------------------------------------- /myTargetDemo/app/src/androidTest/java/com/my/targetDemoTests/tests/InterstitialTest.kt: -------------------------------------------------------------------------------- 1 | package com.my.targetDemoTests.tests 2 | 3 | import androidx.test.espresso.intent.Intents 4 | import androidx.test.espresso.intent.Intents.intended 5 | import androidx.test.espresso.intent.matcher.IntentMatchers.hasComponent 6 | import androidx.test.espresso.web.sugar.Web.onWebView 7 | import com.facebook.testing.screenshot.Screenshot 8 | import com.my.target.common.MyTargetActivity 9 | import com.my.targetDemoApp.activities.InterstitialsActivity 10 | import com.my.targetDemoTests.helpers.Callback 11 | import com.my.targetDemoTests.screens.InterstitialScreen 12 | import com.adevinta.android.barista.rule.BaristaRule 13 | import io.qameta.allure.android.runners.AllureAndroidJUnit4 14 | import org.junit.After 15 | import org.junit.Before 16 | import org.junit.Rule 17 | import org.junit.Test 18 | import org.junit.runner.RunWith 19 | 20 | @RunWith(AllureAndroidJUnit4::class) 21 | class InterstitialTest: TestBase() { 22 | 23 | @get:Rule 24 | var baristaRule = BaristaRule.create(InterstitialsActivity::class.java) 25 | 26 | @Before 27 | override fun setUp() { 28 | super.setUp() 29 | Intents.init() 30 | baristaRule.launchActivity() 31 | } 32 | 33 | @After 34 | fun tearDown() { 35 | Intents.release() 36 | } 37 | 38 | @Test 39 | fun test_InterstitialMenuSnapshot() { 40 | Screenshot.snapActivity(baristaRule.activityTestRule.activity).record() 41 | } 42 | 43 | @Test 44 | fun test_ShowPromoStatic() { 45 | val interstitialScreen = InterstitialScreen() 46 | interstitialScreen.showPromoStatic() 47 | device.wait(interstitialScreen.adView) 48 | intended(hasComponent(MyTargetActivity::class.java.name)) 49 | } 50 | 51 | @Test 52 | fun test_ShowPromoVideo() { 53 | val interstitialScreen = InterstitialScreen() 54 | interstitialScreen.showPromoVideo() 55 | device.wait(interstitialScreen.adView) 56 | intended(hasComponent(MyTargetActivity::class.java.name)) 57 | } 58 | 59 | @Test 60 | fun test_ShowVideo() { 61 | val interstitialScreen = InterstitialScreen() 62 | interstitialScreen.showVideo() 63 | device.wait(interstitialScreen.adView) 64 | intended(hasComponent(MyTargetActivity::class.java.name)) 65 | } 66 | 67 | @Test 68 | fun test_ShowVideoStyle2() { 69 | val interstitialScreen = InterstitialScreen() 70 | interstitialScreen.showVideoStyle2() 71 | device.wait(interstitialScreen.adView) 72 | intended(hasComponent(MyTargetActivity::class.java.name)) 73 | } 74 | 75 | @Test 76 | fun test_ShowImage() { 77 | val interstitialScreen = InterstitialScreen() 78 | interstitialScreen.showImage() 79 | device.wait(interstitialScreen.image) 80 | intended(hasComponent(MyTargetActivity::class.java.name)) 81 | } 82 | 83 | @Test 84 | fun test_ShowPromoCards() { 85 | val interstitialScreen = InterstitialScreen() 86 | interstitialScreen.showPromoCards() 87 | device.wait(interstitialScreen.cards) 88 | intended(hasComponent(MyTargetActivity::class.java.name)) 89 | } 90 | 91 | @Test 92 | fun test_ShowHtmlCards() { 93 | val interstitialScreen = InterstitialScreen() 94 | interstitialScreen.showHtml() 95 | device.wait(interstitialScreen.webview) 96 | onWebView().forceJavascriptEnabled() 97 | } 98 | 99 | @Test 100 | fun test_ShowFSWithoutLoadSnapshot() { 101 | val interstitialScreen = InterstitialScreen() 102 | interstitialScreen.showWithoutLoad() 103 | device.wait(interstitialScreen.adView, timeout = 3000) 104 | Screenshot.snapActivity(baristaRule.activityTestRule.activity).record() 105 | } 106 | 107 | @Test 108 | fun test_ShowVast() { 109 | val interstitialScreen = InterstitialScreen() 110 | interstitialScreen.showVast() 111 | device.wait(callback = Callback.load) 112 | intended(hasComponent(MyTargetActivity::class.java.name)) 113 | } 114 | } -------------------------------------------------------------------------------- /myTargetDemo/app/src/androidTest/java/com/my/targetDemoTests/tests/NativeTest.kt: -------------------------------------------------------------------------------- 1 | package com.my.targetDemoTests.tests 2 | 3 | import android.view.View 4 | import androidx.recyclerview.widget.RecyclerView 5 | import androidx.test.espresso.Espresso 6 | import androidx.test.espresso.contrib.RecyclerViewActions.scrollToPosition 7 | import androidx.test.espresso.matcher.ViewMatchers.withClassName 8 | import com.facebook.testing.screenshot.Screenshot 9 | import com.my.targetDemoApp.activities.NativeAdActivity 10 | import com.my.targetDemoTests.screens.NativeScreen 11 | import com.adevinta.android.barista.assertion.BaristaVisibilityAssertions.assertDisplayed 12 | import com.adevinta.android.barista.interaction.BaristaSleepInteractions.sleep 13 | import com.adevinta.android.barista.rule.BaristaRule 14 | import org.junit.Before 15 | import org.junit.Rule 16 | import org.junit.Test 17 | import java.util.concurrent.TimeUnit 18 | import androidx.test.espresso.NoMatchingViewException 19 | import androidx.test.espresso.ViewAssertion 20 | import io.qameta.allure.android.runners.AllureAndroidJUnit4 21 | import org.hamcrest.CoreMatchers.* 22 | import org.hamcrest.MatcherAssert.assertThat 23 | import org.junit.runner.RunWith 24 | 25 | @RunWith(AllureAndroidJUnit4::class) 26 | class NativeTest: TestBase() { 27 | 28 | @get:Rule 29 | var baristaRule = BaristaRule.create(NativeAdActivity::class.java) 30 | private val nativeScreen = NativeScreen() 31 | 32 | @Before 33 | override fun setUp() { 34 | super.setUp() 35 | baristaRule.launchActivity() 36 | } 37 | 38 | @Test 39 | fun test_NativeMenuSnapshot() { 40 | Screenshot.snapActivity(baristaRule.activityTestRule.activity).record() 41 | } 42 | 43 | @Test 44 | fun test_ShowContentStreamStatic() { 45 | nativeScreen.showContentStreamStatic() 46 | device.wait(nativeScreen.adView) 47 | assertDisplayed(nativeScreen.banner) 48 | } 49 | 50 | @Test 51 | fun test_ShowContentStreamVideo() { 52 | nativeScreen.showContentStreamVideo() 53 | device.wait(nativeScreen.adView) 54 | assertDisplayed(nativeScreen.banner) 55 | } 56 | 57 | @Test 58 | fun test_ShowContentStreamCards() { 59 | nativeScreen.showContentStreamCards() 60 | device.wait(nativeScreen.adView) 61 | assertDisplayed(nativeScreen.banner) 62 | } 63 | 64 | @Test 65 | fun test_ShowInfiniteFeed() { 66 | nativeScreen.showContentStreamStatic() 67 | device.wait(nativeScreen.adView) 68 | assertRecyclerViewSize(size = 21) 69 | scrollToRecyclerViewPosition(position = 20) 70 | sleep(1, TimeUnit.SECONDS) 71 | assertRecyclerViewSize(size = 41) 72 | scrollToRecyclerViewPosition(position = 40) 73 | sleep(1, TimeUnit.SECONDS) 74 | assertRecyclerViewSize(size = 61) 75 | } 76 | 77 | private fun scrollToRecyclerViewPosition(position: Int) { 78 | Espresso.onView(withClassName(containsString("androidx.recyclerview.widget.RecyclerView"))) 79 | .perform(scrollToPosition(position)) 80 | } 81 | 82 | private fun assertRecyclerViewSize(size: Int) { 83 | Espresso.onView(withClassName(containsString("androidx.recyclerview.widget.RecyclerView"))) 84 | .check(RecyclerViewItemCountAssertion(size)) 85 | } 86 | } 87 | 88 | class RecyclerViewItemCountAssertion(private val expectedCount: Int) : ViewAssertion { 89 | override fun check(view: View, noViewFoundException: NoMatchingViewException?) { 90 | if (noViewFoundException != null) { 91 | throw noViewFoundException 92 | } 93 | val recyclerView = view as RecyclerView 94 | val adapter = recyclerView.adapter 95 | assertThat(adapter!!.itemCount, equalTo(expectedCount)) 96 | } 97 | } -------------------------------------------------------------------------------- /myTargetDemo/app/src/androidTest/java/com/my/targetDemoTests/tests/TestBase.kt: -------------------------------------------------------------------------------- 1 | package com.my.targetDemoTests.tests 2 | 3 | import com.my.targetDemoTests.helpers.DeviceHelper 4 | import org.junit.Before 5 | 6 | open class TestBase { 7 | val device = DeviceHelper() 8 | 9 | @Before 10 | open fun setUp() { 11 | device.clearLog() 12 | } 13 | } -------------------------------------------------------------------------------- /myTargetDemo/app/src/main/AndroidManifest.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 16 | 17 | 20 | 21 | 24 | 25 | 29 | 32 | 33 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 50 | 53 | 54 | 59 | 62 | 63 | 68 | 71 | 72 | 77 | 80 | 81 | 86 | 89 | 90 | 95 | 98 | 99 | 104 | 107 | 108 | 109 | 110 | -------------------------------------------------------------------------------- /myTargetDemo/app/src/main/ic_launcher-web.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/myTargetSDK/mytarget-android/e4bb080b44f81633c2f4bc7f52100f3442cbebea/myTargetDemo/app/src/main/ic_launcher-web.png -------------------------------------------------------------------------------- /myTargetDemo/app/src/main/java/com/my/targetDemoApp/AdChoicesMenuFactory.kt: -------------------------------------------------------------------------------- 1 | package com.my.targetDemoApp 2 | 3 | import android.app.AlertDialog 4 | import android.content.Context 5 | import com.my.target.common.menu.Menu 6 | import com.my.target.common.menu.MenuAction 7 | import com.my.target.common.menu.MenuActionStyle 8 | import com.my.target.common.menu.MenuFactory 9 | 10 | class AdChoicesMenuFactory: MenuFactory 11 | { 12 | override fun createMenu(): Menu { 13 | return object : Menu { 14 | private var listener: Menu.Listener? = null 15 | private var actions: MutableList = ArrayList() 16 | private var dialog: AlertDialog? = null 17 | 18 | override fun setListener(listener: Menu.Listener?) { 19 | this.listener = listener 20 | } 21 | 22 | override fun addAction(action: MenuAction) { 23 | actions.add(action) 24 | } 25 | 26 | override fun present(context: Context) { 27 | val options = actions.map { if (it.style == MenuActionStyle.CANCEL) "Закрыть" else it.title } 28 | 29 | val alertDialog = AlertDialog.Builder(context) 30 | alertDialog.setItems(options.toTypedArray()) { _, which -> listener?.onActionClick(actions[which]) } 31 | alertDialog.setCancelable(false) 32 | 33 | dialog = alertDialog.create() 34 | dialog?.show() 35 | } 36 | 37 | override fun dismiss() { 38 | dialog?.dismiss() 39 | } 40 | } 41 | } 42 | } -------------------------------------------------------------------------------- /myTargetDemo/app/src/main/java/com/my/targetDemoApp/AdvertisingType.kt: -------------------------------------------------------------------------------- 1 | package com.my.targetDemoApp 2 | 3 | enum class AdvertisingType(val defaultSlot: Int) { 4 | STANDARD_BANNER_320X50(794557), 5 | STANDARD_BANNER_300X250(93231), 6 | STANDARD_BANNER_728X90(794557), 7 | STANDARD_BANNER_ADAPTIVE(794557), 8 | 9 | INTERSTITIAL_PROMO_STATIC(6896), 10 | INTERSTITIAL_PROMO_VIDEO(10138), 11 | INTERSTITIAL_PROMO_VIDEO_BLACK(38837), 12 | INTERSTITIAL_IMAGE(6481), 13 | INTERSTITIAL_HTML(93233), 14 | INTERSTITIAL_CAROUSEL(102652), 15 | INTERSTITIAL_VAST(101600), 16 | INTERSTITIAL_STYLE_2(577498), 17 | REWARDED(45101), 18 | 19 | NATIVE_AD(6590), 20 | NATIVE_AD_VIDEO(30150), 21 | NATIVE_AD_CAROUSEL(54923), 22 | 23 | NATIVE_BANNER(708247), 24 | 25 | INSTREAM(9525), 26 | INSTREAM_AUDIO(1208427), 27 | } -------------------------------------------------------------------------------- /myTargetDemo/app/src/main/java/com/my/targetDemoApp/CustiomAdvertisingType.kt: -------------------------------------------------------------------------------- 1 | package com.my.targetDemoApp 2 | 3 | import java.util.* 4 | 5 | class CustomAdvertisingType(val adType: AdType, val slotId: Int?, 6 | val params: String? = null) { 7 | var name = "Custom ${ 8 | adType.toString() 9 | .toLowerCase(Locale.getDefault()) 10 | .replace("_", " ") 11 | }" 12 | 13 | enum class AdType { 14 | STANDARD_320X50, 15 | STANDARD_300X250, 16 | STANDARD_728X90, 17 | STANDARD_ADAPTIVE, 18 | INTERSTITIAL, 19 | REWARDED, 20 | NATIVE_AD, 21 | NATIVE_AD_CONFIGURATIONS, 22 | NATIVE_BANNER, 23 | INSTREAM, 24 | AUDIO_INSTREAM; 25 | } 26 | } -------------------------------------------------------------------------------- /myTargetDemo/app/src/main/java/com/my/targetDemoApp/Extensions.kt: -------------------------------------------------------------------------------- 1 | package com.my.targetDemoApp 2 | 3 | import android.view.ViewGroup 4 | import android.widget.ProgressBar 5 | import android.widget.TextView 6 | import com.google.android.material.snackbar.Snackbar 7 | import com.my.target.common.CustomParams 8 | 9 | fun Snackbar.showLoading(): Snackbar { 10 | val contentLay = this.view.findViewById(R.id.snackbar_text).parent as ViewGroup 11 | val item = ProgressBar(this.view.context) 12 | contentLay.addView(item, 0) 13 | this.show() 14 | return this 15 | } 16 | 17 | fun CustomParams.addParsedString(params: String?) { 18 | if (params == null) { 19 | return 20 | } 21 | try { 22 | params.split("&") 23 | .forEach { 24 | val split = it.split("=") 25 | this.setCustomParam(split[0], split[1]) 26 | } 27 | } 28 | catch (e: Exception) { 29 | } 30 | } -------------------------------------------------------------------------------- /myTargetDemo/app/src/main/java/com/my/targetDemoApp/ItemsAdapter.kt: -------------------------------------------------------------------------------- 1 | package com.my.targetDemoApp 2 | 3 | import android.view.LayoutInflater 4 | import android.view.ViewGroup 5 | import androidx.recyclerview.widget.RecyclerView 6 | import com.my.targetDemoApp.databinding.ItemMainBinding 7 | 8 | class ItemsAdapter(private val onDelete: (Int) -> Unit) : 9 | RecyclerView.Adapter() { 10 | 11 | private var adItems: ArrayList? = null 12 | 13 | override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): MainActivityViewHolder { 14 | return MainActivityViewHolder( 15 | ItemMainBinding.inflate(LayoutInflater.from(parent.context), parent, false)) 16 | } 17 | 18 | override fun getItemCount(): Int { 19 | return adItems?.size ?: 0 20 | } 21 | 22 | override fun onBindViewHolder(holder: MainActivityViewHolder, position: Int) { 23 | adItems?.get(position) 24 | ?.let { holder.bind(it) } 25 | } 26 | 27 | override fun onViewRecycled(holder: MainActivityViewHolder) { 28 | super.onViewRecycled(holder) 29 | holder.containerViewBinding.root.setOnClickListener(null) 30 | } 31 | 32 | fun setItems(types: ArrayList) { 33 | adItems = types 34 | notifyDataSetChanged() 35 | } 36 | 37 | fun addItem(listItem: ListItem) { 38 | adItems?.let { 39 | it.add(listItem) 40 | notifyItemInserted(it.size) 41 | } 42 | } 43 | 44 | fun deleteItem(num: Int) { 45 | val items = adItems ?: return 46 | if (num >= items.size) { 47 | return 48 | } 49 | items.removeAt(num) 50 | adItems = items 51 | notifyItemRemoved(num) 52 | onDelete.invoke(num) 53 | } 54 | 55 | class MainActivityViewHolder(var containerViewBinding: ItemMainBinding) : 56 | RecyclerView.ViewHolder(containerViewBinding.root) { 57 | fun bind(listItem: ListItem) { 58 | containerViewBinding.tvTitle.text = listItem.title 59 | containerViewBinding.tvDescription.text = listItem.description 60 | containerViewBinding.root.setOnClickListener { listItem.onClick.invoke() } 61 | } 62 | } 63 | 64 | class ListItem(var onClick: () -> Unit, var title: String, var description: String) 65 | } 66 | 67 | -------------------------------------------------------------------------------- /myTargetDemo/app/src/main/java/com/my/targetDemoApp/PlusDialogFragment.kt: -------------------------------------------------------------------------------- 1 | package com.my.targetDemoApp 2 | 3 | import android.app.Dialog 4 | import android.content.DialogInterface 5 | import android.os.Bundle 6 | import android.text.TextUtils 7 | import android.view.WindowManager 8 | import android.widget.FrameLayout 9 | import android.widget.Toast 10 | import androidx.appcompat.app.AlertDialog 11 | import androidx.fragment.app.DialogFragment 12 | import com.my.targetDemoApp.databinding.FragmentDialogBinding 13 | 14 | class PlusDialogFragment(val onSave: (CustomAdvertisingType) -> Unit) : DialogFragment() { 15 | private var binding: FragmentDialogBinding? = null 16 | private val cancelListener = DialogInterface.OnClickListener { _, _ -> dismiss() } 17 | 18 | override fun onActivityCreated(savedInstanceState: Bundle?) { 19 | super.onActivityCreated(savedInstanceState) 20 | dialog?.window?.setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_VISIBLE) 21 | } 22 | 23 | override fun onCreateDialog(savedInstanceState: Bundle?): Dialog { 24 | val dialogLayout = FrameLayout(requireContext()) 25 | val binding = FragmentDialogBinding.inflate(layoutInflater, dialogLayout, false) 26 | this.binding = binding 27 | binding.btnOk.setOnClickListener { 28 | val slotId = binding.editText.text?.toString() 29 | ?.toIntOrNull() 30 | if (slotId == null) { 31 | Toast.makeText(requireContext(), "Null slot, cannot save", Toast.LENGTH_SHORT) 32 | .show() 33 | return@setOnClickListener 34 | } 35 | val paramsText: String? = binding.etParams.text?.toString() 36 | if (!paramsText.isNullOrEmpty()) { 37 | if (!validateParams(paramsText)) { 38 | Toast.makeText(requireContext(), 39 | """Wrong custom params, leave blank or format properly 40 | """.trimMargin(), Toast.LENGTH_SHORT) 41 | .show() 42 | return@setOnClickListener 43 | } 44 | } 45 | 46 | val type: CustomAdvertisingType.AdType = 47 | when (binding.rgChooseAd.checkedRadioButtonId) { 48 | R.id.adtype_banner_320x50 -> CustomAdvertisingType.AdType.STANDARD_320X50 49 | R.id.adtype_banner_300x250 -> CustomAdvertisingType.AdType.STANDARD_300X250 50 | R.id.adtype_banner_728x90 -> CustomAdvertisingType.AdType.STANDARD_728X90 51 | R.id.adtype_banner_adaptive -> CustomAdvertisingType.AdType.STANDARD_ADAPTIVE 52 | R.id.adtype_interstitial -> CustomAdvertisingType.AdType.INTERSTITIAL 53 | R.id.adtype_rewarded -> CustomAdvertisingType.AdType.REWARDED 54 | R.id.adtype_instream -> CustomAdvertisingType.AdType.INSTREAM 55 | R.id.adtype_native -> CustomAdvertisingType.AdType.NATIVE_AD 56 | R.id.adtype_native_configurations -> CustomAdvertisingType.AdType.NATIVE_AD_CONFIGURATIONS 57 | R.id.adtype_native_banner -> CustomAdvertisingType.AdType.NATIVE_BANNER 58 | R.id.adtype_audio_instream -> CustomAdvertisingType.AdType.AUDIO_INSTREAM 59 | else -> CustomAdvertisingType.AdType.STANDARD_320X50 60 | } 61 | val checkedAdType = CustomAdvertisingType(type, slotId, paramsText) 62 | val name = binding.etName.text.toString() 63 | if (name.isNotEmpty()) { 64 | checkedAdType.name = name 65 | } 66 | onSave.invoke(checkedAdType) 67 | dismiss() 68 | } 69 | binding.btnCancel.setOnClickListener { dismiss() } 70 | 71 | dialogLayout.addView(binding.root) 72 | 73 | return AlertDialog.Builder(requireActivity()) 74 | .setView(dialogLayout) 75 | .setTitle(R.string.add_ad_title) 76 | .create() 77 | } 78 | 79 | private fun validateParams(paramsText: String): Boolean { 80 | return try { 81 | paramsText.split("&") 82 | .forEach { 83 | val split = it.split("=") 84 | if (split.size != 2) return false 85 | if (TextUtils.isEmpty(split[0])) { 86 | return false 87 | } 88 | } 89 | true 90 | } 91 | catch (e: Exception) { 92 | false 93 | } 94 | } 95 | 96 | override fun onDestroyView() { 97 | super.onDestroyView() 98 | binding = null 99 | } 100 | } 101 | -------------------------------------------------------------------------------- /myTargetDemo/app/src/main/java/com/my/targetDemoApp/Saver.kt: -------------------------------------------------------------------------------- 1 | package com.my.targetDemoApp 2 | 3 | import android.content.Context 4 | import androidx.preference.PreferenceManager 5 | import org.json.JSONArray 6 | import org.json.JSONObject 7 | 8 | class Saver(context: Context) { 9 | 10 | companion object { 11 | const val TAG = "saved_types" 12 | const val AD_TYPE = "ad_type" 13 | const val NAME = "name" 14 | const val ITEMS = "items" 15 | const val PARAMS = "params" 16 | const val SLOT = "slot" 17 | const val DEFAULT = "{\"$ITEMS\":[]}" 18 | } 19 | 20 | private val preferences = PreferenceManager.getDefaultSharedPreferences(context) 21 | 22 | fun save(adType: CustomAdvertisingType) { 23 | val prefs = preferences.getString(TAG, DEFAULT) ?: DEFAULT 24 | val prefsJO = JSONObject(prefs) 25 | val array = prefsJO.getJSONArray(ITEMS) 26 | val itemJO = JSONObject() 27 | itemJO.put(AD_TYPE, adType.adType) 28 | itemJO.put(SLOT, adType.slotId) 29 | itemJO.put(NAME, adType.name) 30 | val params = adType.params 31 | if (params != null) { 32 | itemJO.put(PARAMS, params) 33 | } 34 | array.put(itemJO) 35 | preferences.edit() 36 | .putString(TAG, prefsJO.toString()) 37 | .apply() 38 | } 39 | 40 | fun restore(): Collection? { 41 | val types = ArrayList() 42 | 43 | val prefs = preferences.getString(TAG, DEFAULT) ?: DEFAULT 44 | val prefsJO = JSONObject(prefs) 45 | val array = prefsJO.getJSONArray(ITEMS) 46 | for (i in 0 until array.length()) { 47 | val item = array.getJSONObject(i) 48 | @Suppress("NULLABILITY_MISMATCH_BASED_ON_JAVA_ANNOTATIONS") val params = 49 | item.optString(PARAMS, null) 50 | val type = CustomAdvertisingType( 51 | CustomAdvertisingType.AdType.valueOf(item.getString(AD_TYPE)), 52 | item.getInt(SLOT), params) 53 | type.name = item.getString(NAME) 54 | types.add(type) 55 | } 56 | return types 57 | } 58 | 59 | fun remove(pos: Int) { 60 | if (pos < 0) { 61 | return 62 | } 63 | 64 | val prefs = preferences.getString(TAG, DEFAULT) ?: DEFAULT 65 | var prefsJO = JSONObject(prefs) 66 | val array = prefsJO.getJSONArray(ITEMS) 67 | 68 | val list = ArrayList() 69 | for (i in 0 until array.length()) { 70 | list.add(array.getJSONObject(i)) 71 | } 72 | list.removeAt(pos) 73 | val newArray = JSONArray(list) 74 | 75 | prefsJO = JSONObject() 76 | prefsJO.put(ITEMS, newArray) 77 | 78 | preferences.edit() 79 | .putString(TAG, prefsJO.toString()) 80 | .apply() 81 | } 82 | 83 | } 84 | -------------------------------------------------------------------------------- /myTargetDemo/app/src/main/java/com/my/targetDemoApp/activities/BannersActivity.kt: -------------------------------------------------------------------------------- 1 | package com.my.targetDemoApp.activities 2 | 3 | import android.content.Intent 4 | import android.os.Bundle 5 | import android.view.Gravity.BOTTOM 6 | import android.view.Gravity.CENTER_HORIZONTAL 7 | import android.view.LayoutInflater 8 | import android.view.MenuItem 9 | import android.view.View 10 | import android.view.View.VISIBLE 11 | import android.view.ViewGroup 12 | import android.widget.FrameLayout 13 | import androidx.appcompat.app.AppCompatActivity 14 | import androidx.recyclerview.widget.LinearLayoutManager 15 | import androidx.recyclerview.widget.RecyclerView 16 | import com.my.target.ads.MyTargetView 17 | import com.my.targetDemoApp.AdvertisingType 18 | import com.my.targetDemoApp.R 19 | import com.my.targetDemoApp.databinding.ActivityBannersBinding 20 | import com.my.targetDemoApp.helpers.BannerHelper 21 | import kotlin.math.max 22 | 23 | class BannersActivity : AppCompatActivity() { 24 | 25 | companion object { 26 | const val KEY_SLOT = "key" 27 | const val KEY_SIZE = "size" 28 | const val KEY_PARAMS = "params" 29 | } 30 | 31 | private lateinit var viewBinding: ActivityBannersBinding 32 | 33 | private var bannerHelper: BannerHelper = BannerHelper() 34 | private var bannersAdapter: BannersAdapter = BannersAdapter() 35 | private var customBannerShowing: Boolean = false 36 | 37 | override fun onCreate(savedInstanceState: Bundle?) { 38 | super.onCreate(savedInstanceState) 39 | viewBinding = ActivityBannersBinding.inflate(layoutInflater) 40 | setContentView(viewBinding.root) 41 | 42 | setSupportActionBar(viewBinding.toolbar) 43 | supportActionBar?.setDisplayHomeAsUpEnabled(true) 44 | 45 | val displayMetrics = resources.displayMetrics 46 | viewBinding.rbt728x90.isEnabled = max(displayMetrics.heightPixels / displayMetrics.density, 47 | displayMetrics.widthPixels / displayMetrics.density) > 728 48 | 49 | viewBinding.rbt320x50.isChecked = true 50 | 51 | viewBinding.btnGointerstitial.setOnClickListener { goBanner() } 52 | initFish() 53 | 54 | val customSize = when (intent.getIntExtra(KEY_SIZE, -1)) { 55 | 1 -> MyTargetView.AdSize.ADSIZE_300x250 56 | 2 -> MyTargetView.AdSize.ADSIZE_728x90 57 | 3 -> MyTargetView.AdSize.getAdSizeForCurrentOrientation(this) 58 | else -> MyTargetView.AdSize.ADSIZE_320x50 59 | } 60 | val customSlot = intent.getIntExtra(KEY_SLOT, -1) 61 | if (customSlot >= 0) { 62 | viewBinding.bannerContainer.visibility = VISIBLE 63 | goBanner(customSize, customSlot, intent.getStringExtra(KEY_PARAMS)) 64 | customBannerShowing = true 65 | } 66 | } 67 | 68 | override fun onOptionsItemSelected(item: MenuItem): Boolean { 69 | when (item.itemId) { 70 | android.R.id.home -> { 71 | if (viewBinding.bannerContainer.visibility == VISIBLE) { 72 | closeOverlay() 73 | return true 74 | } 75 | } 76 | } 77 | return super.onOptionsItemSelected(item) 78 | } 79 | 80 | private fun initFish() { 81 | viewBinding.rvFish.layoutManager = LinearLayoutManager(this, RecyclerView.VERTICAL, false) 82 | viewBinding.rvFish.adapter = bannersAdapter 83 | 84 | } 85 | 86 | override fun onBackPressed() { 87 | if (viewBinding.bannerContainer.visibility == VISIBLE) { 88 | closeOverlay() 89 | } 90 | else { 91 | bannerHelper.destroy() 92 | super.onBackPressed() 93 | } 94 | } 95 | 96 | private fun closeOverlay() { 97 | bannerHelper.destroy() 98 | if (customBannerShowing) { 99 | finish() 100 | } 101 | else { 102 | viewBinding.bannerContainer.removeView(bannerHelper.bannerView) 103 | viewBinding.bannerContainer.visibility = View.GONE 104 | } 105 | } 106 | 107 | private fun goBanner() { 108 | if (viewBinding.rbtAdaptiveXml.isChecked) { 109 | startActivity(Intent(this, SimpleBannerActivity::class.java)) 110 | return 111 | } 112 | 113 | var adSize: MyTargetView.AdSize = MyTargetView.AdSize.ADSIZE_320x50 114 | var adType: AdvertisingType = AdvertisingType.STANDARD_BANNER_320X50 115 | when { 116 | viewBinding.rbt300x250.isChecked -> { 117 | adSize = MyTargetView.AdSize.ADSIZE_300x250 118 | adType = AdvertisingType.STANDARD_BANNER_300X250 119 | } 120 | viewBinding.rbt728x90.isChecked -> { 121 | adSize = MyTargetView.AdSize.ADSIZE_728x90 122 | adType = AdvertisingType.STANDARD_BANNER_728X90 123 | } 124 | viewBinding.rbtAdaptive.isChecked -> { 125 | adSize = MyTargetView.AdSize.getAdSizeForCurrentOrientation(this) 126 | adType = AdvertisingType.STANDARD_BANNER_ADAPTIVE 127 | } 128 | } 129 | 130 | goBanner(adSize, adType.defaultSlot, null) 131 | } 132 | 133 | private fun goBanner(adSize: MyTargetView.AdSize, slot: Int, params: String?) { 134 | viewBinding.bannerContainer.removeView(bannerHelper.bannerView) 135 | bannerHelper.destroy() 136 | bannerHelper.load(slot, adSize, params, viewBinding.bannerContainer) { 137 | if (adSize == MyTargetView.AdSize.ADSIZE_300x250) { 138 | showBannerInsideList() 139 | } 140 | else { 141 | showBanner() 142 | } 143 | } 144 | } 145 | 146 | private fun showBanner() { 147 | val lp = FrameLayout.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, 148 | ViewGroup.LayoutParams.WRAP_CONTENT) 149 | lp.gravity = BOTTOM or CENTER_HORIZONTAL 150 | viewBinding.bannerContainer.addView(bannerHelper.bannerView, lp) 151 | viewBinding.bannerContainer.visibility = VISIBLE 152 | } 153 | 154 | private fun showBannerInsideList() { 155 | bannersAdapter.adViewInside = bannerHelper.bannerView 156 | val lp = FrameLayout.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, 157 | ViewGroup.LayoutParams.WRAP_CONTENT) 158 | lp.gravity = BOTTOM or CENTER_HORIZONTAL 159 | viewBinding.bannerContainer.visibility = VISIBLE 160 | bannersAdapter.notifyItemChanged(bannersAdapter.adPosition) 161 | } 162 | 163 | inner class BannersAdapter : RecyclerView.Adapter() { 164 | val adPosition = 3 165 | 166 | var adViewInside: MyTargetView? = null 167 | 168 | override fun onCreateViewHolder(p0: ViewGroup, viewType: Int): RecyclerView.ViewHolder { 169 | val frame = LayoutInflater.from(p0.context) 170 | .inflate(R.layout.item_banner, p0, false) 171 | return object : RecyclerView.ViewHolder(frame) {} 172 | } 173 | 174 | override fun getItemCount(): Int { 175 | return 10 176 | } 177 | 178 | override fun getItemViewType(position: Int): Int { 179 | if (position == adPosition) { 180 | return 1 181 | } 182 | return 0 183 | } 184 | 185 | override fun onBindViewHolder(holder: RecyclerView.ViewHolder, position: Int) { 186 | adViewInside?.let { 187 | if (getItemViewType(position) == 1 && it.parent == null) { 188 | (holder.itemView as FrameLayout?)?.removeAllViews() 189 | (holder.itemView as FrameLayout?)?.addView(it) 190 | } 191 | } 192 | } 193 | 194 | } 195 | } 196 | -------------------------------------------------------------------------------- /myTargetDemo/app/src/main/java/com/my/targetDemoApp/activities/InterstitialsActivity.kt: -------------------------------------------------------------------------------- 1 | package com.my.targetDemoApp.activities 2 | 3 | import android.os.Bundle 4 | import androidx.appcompat.app.AppCompatActivity 5 | import com.my.targetDemoApp.AdvertisingType 6 | import com.my.targetDemoApp.databinding.ActivityInterstitialsBinding 7 | import com.my.targetDemoApp.helpers.InterstitialHelper 8 | 9 | class InterstitialsActivity : AppCompatActivity() { 10 | 11 | private lateinit var binding: ActivityInterstitialsBinding 12 | private lateinit var interstitialHelper: InterstitialHelper 13 | 14 | override fun onCreate(savedInstanceState: Bundle?) { 15 | super.onCreate(savedInstanceState) 16 | binding = ActivityInterstitialsBinding.inflate(layoutInflater) 17 | setContentView(binding.root) 18 | setSupportActionBar(binding.toolbar) 19 | supportActionBar?.setDisplayHomeAsUpEnabled(true) 20 | 21 | interstitialHelper = InterstitialHelper(binding.interstitialsRoot) 22 | 23 | binding.rbtPromoStatic.isChecked = true 24 | 25 | binding.btnLoad.setOnClickListener { load(getAdType()) } 26 | binding.btnGointerstitial.setOnClickListener { goInterstitial() } 27 | } 28 | 29 | private fun load(adType: AdvertisingType) { 30 | interstitialHelper.destroy() 31 | interstitialHelper.init(adType.defaultSlot, params = null) 32 | } 33 | 34 | private fun getAdType(): AdvertisingType { 35 | return when { 36 | binding.rbtPromoStatic.isChecked -> AdvertisingType.INTERSTITIAL_PROMO_STATIC 37 | binding.rbtPromoVideo.isChecked -> AdvertisingType.INTERSTITIAL_PROMO_VIDEO 38 | binding.rbtBlackTheme.isChecked -> AdvertisingType.INTERSTITIAL_PROMO_VIDEO_BLACK 39 | binding.rbtVast.isChecked -> AdvertisingType.INTERSTITIAL_VAST 40 | binding.rbtImage.isChecked -> AdvertisingType.INTERSTITIAL_IMAGE 41 | binding.rbtCarousel.isChecked -> AdvertisingType.INTERSTITIAL_CAROUSEL 42 | binding.rbtHtml.isChecked -> AdvertisingType.INTERSTITIAL_HTML 43 | binding.rbtPromoVideoStyle2.isChecked -> AdvertisingType.INTERSTITIAL_STYLE_2 44 | else -> AdvertisingType.INTERSTITIAL_PROMO_STATIC 45 | } 46 | } 47 | 48 | private fun goInterstitial() { 49 | interstitialHelper.show() 50 | } 51 | } 52 | -------------------------------------------------------------------------------- /myTargetDemo/app/src/main/java/com/my/targetDemoApp/activities/NativeAdActivity.kt: -------------------------------------------------------------------------------- 1 | package com.my.targetDemoApp.activities 2 | 3 | import android.os.Bundle 4 | import android.view.Gravity 5 | import android.view.MenuItem 6 | import android.view.View 7 | import android.view.ViewGroup 8 | import android.widget.FrameLayout 9 | import androidx.appcompat.app.AppCompatActivity 10 | import com.my.targetDemoApp.AdvertisingType 11 | import com.my.targetDemoApp.R 12 | import com.my.targetDemoApp.databinding.ActivityNativesBinding 13 | import com.my.targetDemoApp.helpers.NativeAdHelper 14 | 15 | class NativeAdActivity : AppCompatActivity() { 16 | 17 | private var customBannerShowing: Boolean = false 18 | private lateinit var binding: ActivityNativesBinding 19 | private lateinit var nativeAdHelper: NativeAdHelper 20 | override fun onCreate(savedInstanceState: Bundle?) { 21 | super.onCreate(savedInstanceState) 22 | binding = ActivityNativesBinding.inflate(layoutInflater) 23 | setContentView(binding.root) 24 | 25 | setSupportActionBar(binding.toolbar) 26 | supportActionBar?.setDisplayHomeAsUpEnabled(true) 27 | 28 | binding.rbtNone.isChecked = true 29 | 30 | nativeAdHelper = NativeAdHelper(binding.nativesRoot) 31 | 32 | val customSlot = intent.getIntExtra(KEY_SLOT, -1) 33 | if (customSlot >= 0) { 34 | customBannerShowing = true 35 | loadAndShow(customSlot, intent.getStringExtra(KEY_PARAMS)) 36 | } 37 | 38 | binding.btnGonative.setOnClickListener { loadAndShow(getAdType().defaultSlot, null) } 39 | } 40 | 41 | override fun onOptionsItemSelected(item: MenuItem): Boolean { 42 | when (item.itemId) { 43 | android.R.id.home -> { 44 | if (binding.nativeContainer.visibility == View.VISIBLE && !customBannerShowing) { 45 | closeOverlay() 46 | return true 47 | } 48 | } 49 | } 50 | return super.onOptionsItemSelected(item) 51 | } 52 | 53 | private fun showNativeAd() { 54 | binding.nativeContainer.visibility = View.VISIBLE 55 | binding.llStatus.visibility = View.GONE 56 | val recycler = nativeAdHelper.createRecycler() 57 | 58 | binding.nativeContainer.removeAllViews() 59 | 60 | val lp = FrameLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, 61 | ViewGroup.LayoutParams.MATCH_PARENT) 62 | lp.gravity = Gravity.CENTER 63 | binding.nativeContainer.addView(recycler, 0, lp) 64 | binding.nativeContainer.visibility = View.VISIBLE 65 | } 66 | 67 | override fun onBackPressed() { 68 | if (binding.nativeContainer.visibility == View.VISIBLE) { 69 | closeOverlay() 70 | } 71 | else { 72 | super.onBackPressed() 73 | } 74 | } 75 | 76 | private fun closeOverlay() { 77 | if (customBannerShowing) { 78 | finish() 79 | } 80 | else { 81 | binding.nativeContainer.removeAllViews() 82 | binding.nativeContainer.visibility = View.GONE 83 | binding.llStatus.visibility = View.GONE 84 | } 85 | } 86 | 87 | private fun getAdType(): AdvertisingType { 88 | return when { 89 | binding.rbtVideo.isChecked -> AdvertisingType.NATIVE_AD_VIDEO 90 | binding.rbtCards.isChecked -> AdvertisingType.NATIVE_AD_CAROUSEL 91 | else -> AdvertisingType.NATIVE_AD 92 | } 93 | } 94 | 95 | private fun loadAndShow(customSlot: Int, params: String?) { 96 | binding.nativeContainer.visibility = View.VISIBLE 97 | binding.llStatus.visibility = View.VISIBLE 98 | binding.progressBar.visibility = View.VISIBLE 99 | binding.tvStatus.text = getString(R.string.loading) 100 | nativeAdHelper.load(customSlot, params, binding.nativesRoot, { showNativeAd() }, { 101 | hideNative() 102 | binding.nativeContainer.visibility = View.VISIBLE 103 | binding.llStatus.visibility = View.VISIBLE 104 | binding.progressBar.visibility = View.GONE 105 | val s = String.format(getString(R.string.error_msg), it) 106 | binding.tvStatus.text = s 107 | }) 108 | } 109 | 110 | private fun hideNative() { 111 | binding.nativeContainer.visibility = View.GONE 112 | binding.nativeContainer.removeAllViews() 113 | binding.llStatus.visibility = View.GONE 114 | } 115 | 116 | companion object { 117 | var KEY_SLOT = "slotId" 118 | var KEY_PARAMS = "params" 119 | } 120 | 121 | } 122 | -------------------------------------------------------------------------------- /myTargetDemo/app/src/main/java/com/my/targetDemoApp/activities/NativeAdConfigurationActivity.kt: -------------------------------------------------------------------------------- 1 | package com.my.targetDemoApp.activities 2 | 3 | import android.os.Bundle 4 | import android.util.Log 5 | import android.view.MenuItem 6 | import android.view.View 7 | import androidx.appcompat.app.AppCompatActivity 8 | import com.my.target.common.menu.Menu 9 | import com.my.target.common.menu.MenuFactory 10 | import com.my.target.common.models.IAdLoadingError 11 | import com.my.target.nativeads.AdChoicesPlacement 12 | import com.my.target.nativeads.NativeAd 13 | import com.my.target.nativeads.banners.NativePromoBanner 14 | import com.my.target.nativeads.factories.NativeViewsFactory 15 | import com.my.targetDemoApp.AdvertisingType 16 | import com.my.targetDemoApp.addParsedString 17 | import com.my.targetDemoApp.databinding.ActivityNativeConfigurationBinding 18 | import com.my.targetDemoApp.helpers.AdChoicesMenuFactory 19 | 20 | class NativeAdConfigurationActivity : AppCompatActivity(), NativeAd.NativeAdListener, 21 | NativeAd.NativeAdChoicesOptionListener, MenuFactory 22 | { 23 | private lateinit var binding: ActivityNativeConfigurationBinding 24 | 25 | var nativeAd: NativeAd? = null 26 | var params: String? = null 27 | var nativeAdSlot = -1 28 | 29 | override fun onCreate(savedInstanceState: Bundle?) 30 | { 31 | super.onCreate(savedInstanceState) 32 | binding = ActivityNativeConfigurationBinding.inflate(layoutInflater) 33 | setContentView(binding.root) 34 | 35 | setSupportActionBar(binding.toolbar) 36 | supportActionBar?.setDisplayHomeAsUpEnabled(true) 37 | 38 | params = intent.getStringExtra(KEY_PARAMS) 39 | nativeAdSlot = intent.getIntExtra(KEY_SLOT, AdvertisingType.NATIVE_AD.defaultSlot) 40 | 41 | binding.ibAdhcoicesIcon.setOnClickListener { 42 | nativeAd?.handleAdChoicesClick(this) 43 | } 44 | binding.btnGonative.setOnClickListener { 45 | loadAndShow(nativeAdSlot, params) 46 | } 47 | } 48 | 49 | override fun onOptionsItemSelected(item: MenuItem): Boolean 50 | { 51 | if (binding.nativeRootContainer.visibility == View.VISIBLE) 52 | { 53 | closeOverlay() 54 | return true 55 | } 56 | 57 | return super.onOptionsItemSelected(item) 58 | } 59 | 60 | override fun onBackPressed() 61 | { 62 | if (binding.nativeRootContainer.visibility == View.VISIBLE) 63 | { 64 | closeOverlay() 65 | } else 66 | { 67 | super.onBackPressed() 68 | } 69 | } 70 | 71 | private fun closeOverlay() 72 | { 73 | binding.nativeContainer.removeAllViews() 74 | binding.nativeRootContainer.visibility = View.GONE 75 | binding.llStatus.visibility = View.GONE 76 | } 77 | 78 | private fun loadAndShow(customSlot: Int, params: String?) 79 | { 80 | binding.apply { 81 | val usingCustomAdChoicesView = cbUseCustomAdchoicesView.isChecked 82 | ibAdhcoicesIcon.visibility = if (usingCustomAdChoicesView) View.VISIBLE else View.GONE 83 | nativeRootContainer.visibility = View.VISIBLE 84 | llStatus.visibility = View.VISIBLE 85 | progressBar.visibility = View.VISIBLE 86 | 87 | nativeAd = NativeAd( 88 | customSlot, 89 | if (cbDrawAdchoicesOptions.isChecked) this@NativeAdConfigurationActivity else null, 90 | this@NativeAdConfigurationActivity 91 | ) 92 | 93 | nativeAd?.apply { 94 | listener = this@NativeAdConfigurationActivity 95 | adChoicesOptionListener = if (rbtDontUseOptionsListener.isChecked) null else this@NativeAdConfigurationActivity 96 | adChoicesPlacement = if (usingCustomAdChoicesView) AdChoicesPlacement.DRAWING_MANUAL else AdChoicesPlacement.TOP_RIGHT 97 | customParams.addParsedString(params) 98 | load() 99 | } 100 | } 101 | } 102 | 103 | private fun hideNative() 104 | { 105 | binding.nativeRootContainer.visibility = View.GONE 106 | binding.nativeContainer.removeAllViews() 107 | binding.llStatus.visibility = View.GONE 108 | } 109 | 110 | override fun onLoad(banner: NativePromoBanner, ad: NativeAd) 111 | { 112 | val nativeAdView = NativeViewsFactory.getNativeAdView(this) 113 | nativeAdView.setupView(ad.banner) 114 | 115 | binding.apply { 116 | llStatus.visibility = View.GONE 117 | nativeRootContainer.visibility = View.VISIBLE 118 | nativeContainer.addView(nativeAdView) 119 | ibAdhcoicesIcon.setImageBitmap(ad.banner?.adChoicesIcon?.bitmap) 120 | } 121 | 122 | ad.registerView(nativeAdView) 123 | } 124 | 125 | override fun onNoAd(adLoadingError: IAdLoadingError, ad: NativeAd) 126 | { 127 | Log.d(TAG, "onNoAd() called with: adLoadingError = $adLoadingError, ad = $ad") 128 | hideNative() 129 | } 130 | 131 | override fun onClick(ad: NativeAd) 132 | { 133 | 134 | } 135 | 136 | override fun onShow(ad: NativeAd) 137 | { 138 | 139 | } 140 | 141 | override fun onVideoPlay(ad: NativeAd) 142 | { 143 | 144 | } 145 | 146 | override fun onVideoPause(ad: NativeAd) 147 | { 148 | 149 | } 150 | 151 | override fun onVideoComplete(ad: NativeAd) 152 | { 153 | 154 | } 155 | 156 | override fun createMenu(): Menu 157 | { 158 | return AdChoicesMenuFactory() 159 | } 160 | 161 | override fun onDestroy() 162 | { 163 | nativeAd?.unregisterView() 164 | super.onDestroy() 165 | } 166 | 167 | override fun shouldCloseAutomatically(): Boolean 168 | { 169 | if (binding.rbtAutoClose.isChecked) 170 | { 171 | Log.d(TAG, "shouldCloseAutomatically is true") 172 | return true 173 | } 174 | 175 | if (binding.rbtCloseByDeveloper.isChecked) 176 | { 177 | Log.d(TAG, "shouldCloseAutomatically is false") 178 | return false 179 | } 180 | Log.d(TAG, "shouldCloseAutomatically is false") 181 | return false 182 | } 183 | 184 | override fun onCloseAutomatically(ad: NativeAd) 185 | { 186 | Log.d(TAG, "banner closed automatically") 187 | binding.ibAdhcoicesIcon.visibility = View.GONE 188 | } 189 | 190 | override fun closeIfAutomaticallyDisabled(ad: NativeAd) 191 | { 192 | Log.d(TAG, "banner closed by developer") 193 | hideNative() 194 | } 195 | 196 | companion object 197 | { 198 | private const val TAG = "NativeConfigurations:" 199 | 200 | const val KEY_SLOT = "slotId" 201 | const val KEY_PARAMS = "params" 202 | } 203 | } -------------------------------------------------------------------------------- /myTargetDemo/app/src/main/java/com/my/targetDemoApp/activities/NativeBannerActivity.kt: -------------------------------------------------------------------------------- 1 | package com.my.targetDemoApp.activities 2 | 3 | import android.os.Bundle 4 | import android.view.Gravity 5 | import android.view.View 6 | import android.view.ViewGroup 7 | import android.widget.FrameLayout 8 | import androidx.appcompat.app.AppCompatActivity 9 | import com.my.targetDemoApp.AdvertisingType 10 | import com.my.targetDemoApp.R 11 | import com.my.targetDemoApp.databinding.ActivityNativeBannersBinding 12 | import com.my.targetDemoApp.helpers.NativeBannerHelper 13 | 14 | class NativeBannerActivity : AppCompatActivity() { 15 | 16 | companion object { 17 | var KEY_SLOT = "slotId" 18 | var KEY_PARAMS = "params" 19 | } 20 | 21 | private lateinit var binding: ActivityNativeBannersBinding 22 | private lateinit var nativeBannerHelper: NativeBannerHelper 23 | 24 | override fun onCreate(savedInstanceState: Bundle?) { 25 | super.onCreate(savedInstanceState) 26 | binding = ActivityNativeBannersBinding.inflate(layoutInflater) 27 | setContentView(binding.root) 28 | 29 | setSupportActionBar(binding.toolbar) 30 | supportActionBar?.setDisplayHomeAsUpEnabled(true) 31 | nativeBannerHelper = NativeBannerHelper(binding.nativesRoot) 32 | 33 | val customSlot = intent.getIntExtra(KEY_SLOT, -1) 34 | if (customSlot >= 0) { 35 | loadAndShow(customSlot, intent.getStringExtra(KEY_PARAMS)) 36 | } 37 | else { 38 | loadAndShow(AdvertisingType.NATIVE_BANNER.defaultSlot, null) 39 | } 40 | } 41 | 42 | private fun showNative() { 43 | binding.nativeContainer.visibility = View.VISIBLE 44 | binding.llStatus.visibility = View.GONE 45 | nativeBannerHelper.createRecycler() 46 | 47 | val recycler = nativeBannerHelper.createRecycler() 48 | 49 | binding.nativeContainer.removeAllViews() 50 | 51 | val lp = FrameLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, 52 | ViewGroup.LayoutParams.MATCH_PARENT) 53 | lp.gravity = Gravity.CENTER 54 | binding.nativeContainer.addView(recycler, 0, lp) 55 | binding.nativeContainer.visibility = View.VISIBLE 56 | } 57 | 58 | private fun loadAndShow(customSlot: Int, params: String?) { 59 | binding.nativeContainer.visibility = View.VISIBLE 60 | binding.llStatus.visibility = View.VISIBLE 61 | binding.progressBar.visibility = View.VISIBLE 62 | binding.tvStatus.text = getString(R.string.loading) 63 | nativeBannerHelper.load(customSlot, params, binding.nativesRoot, { showNative() }, { 64 | hideNative() 65 | binding.llStatus.visibility = View.VISIBLE 66 | binding.progressBar.visibility = View.GONE 67 | val s = String.format(getString(R.string.error_msg), it) 68 | binding.tvStatus.text = s 69 | }) 70 | } 71 | 72 | private fun hideNative() { 73 | binding.nativeContainer.visibility = View.GONE 74 | binding.llStatus.visibility = View.GONE 75 | binding.nativeContainer.removeAllViews() 76 | } 77 | 78 | } 79 | -------------------------------------------------------------------------------- /myTargetDemo/app/src/main/java/com/my/targetDemoApp/activities/SimpleBannerActivity.kt: -------------------------------------------------------------------------------- 1 | package com.my.targetDemoApp.activities 2 | 3 | import android.os.Bundle 4 | import android.util.Log 5 | import android.widget.Toast 6 | import androidx.appcompat.app.AppCompatActivity 7 | import com.my.target.ads.MyTargetView 8 | import com.my.target.common.models.IAdLoadingError 9 | import com.my.targetDemoApp.databinding.ActivitySimpleBannerBinding 10 | 11 | class SimpleBannerActivity : AppCompatActivity(), MyTargetView.MyTargetViewListener { 12 | private lateinit var viewBinding: ActivitySimpleBannerBinding 13 | 14 | companion object { 15 | private const val TAG = "SimpleBannerActivity" 16 | } 17 | 18 | override fun onCreate(savedInstanceState: Bundle?) { 19 | super.onCreate(savedInstanceState) 20 | viewBinding = ActivitySimpleBannerBinding.inflate(layoutInflater) 21 | setContentView(viewBinding.root) 22 | setSupportActionBar(viewBinding.toolbar) 23 | supportActionBar?.setDisplayHomeAsUpEnabled(true); 24 | supportActionBar?.setDisplayShowHomeEnabled(true); 25 | viewBinding.targetView.listener = this 26 | viewBinding.targetView.load() 27 | } 28 | 29 | override fun onLoad(p0: MyTargetView) { 30 | Log.d(TAG, "onLoad() called with: p0 = $p0") 31 | toast("onLoad") 32 | } 33 | 34 | override fun onClick(p0: MyTargetView) { 35 | Log.d(TAG, "onClick() called with: p0 = $p0") 36 | } 37 | 38 | override fun onNoAd(adLoadingError: IAdLoadingError, myTargetView: MyTargetView) { 39 | Log.d(TAG, "onNoAd() called with: adLoadingError = $adLoadingError, myTargetView = $myTargetView") 40 | toast("onLoad") 41 | } 42 | 43 | override fun onShow(p0: MyTargetView) { 44 | Log.d(TAG, "onShow() called with: p0 = $p0") 45 | } 46 | 47 | private fun toast(s: String) { 48 | Toast.makeText(this, s, Toast.LENGTH_SHORT) 49 | .show() 50 | } 51 | } -------------------------------------------------------------------------------- /myTargetDemo/app/src/main/java/com/my/targetDemoApp/helpers/AdChoicesMenuFactory.kt: -------------------------------------------------------------------------------- 1 | package com.my.targetDemoApp.helpers 2 | 3 | import android.app.AlertDialog 4 | import android.content.Context 5 | import com.my.target.common.menu.Menu 6 | import com.my.target.common.menu.MenuAction 7 | import com.my.target.common.menu.MenuActionStyle 8 | 9 | class AdChoicesMenuFactory : Menu 10 | { 11 | private var listener: Menu.Listener? = null 12 | private var actions = ArrayList() 13 | private var dialog: AlertDialog? = null 14 | 15 | override fun setListener(listener: Menu.Listener?) 16 | { 17 | this.listener = listener 18 | } 19 | 20 | override fun addAction(action: MenuAction) 21 | { 22 | actions.add(action) 23 | } 24 | 25 | override fun present(context: Context) 26 | { 27 | val options = 28 | actions.map { if (it.style == MenuActionStyle.CANCEL) "Закрыть" else it.title } 29 | 30 | val alertDialog = AlertDialog.Builder(context) 31 | alertDialog.setItems(options.toTypedArray()) { _, which -> listener?.onActionClick(actions[which]) } 32 | alertDialog.setCancelable(false) 33 | 34 | dialog = alertDialog.create() 35 | dialog?.show() 36 | } 37 | 38 | override fun dismiss() 39 | { 40 | dialog?.dismiss() 41 | dialog=null 42 | } 43 | } -------------------------------------------------------------------------------- /myTargetDemo/app/src/main/java/com/my/targetDemoApp/helpers/BannerHelper.kt: -------------------------------------------------------------------------------- 1 | package com.my.targetDemoApp.helpers 2 | 3 | import android.util.Log 4 | import android.view.View 5 | import android.view.ViewGroup 6 | import com.google.android.material.snackbar.Snackbar 7 | import com.my.target.ads.MyTargetView 8 | import com.my.target.common.models.IAdLoadingError 9 | import com.my.targetDemoApp.R 10 | import com.my.targetDemoApp.addParsedString 11 | import com.my.targetDemoApp.showLoading 12 | 13 | class BannerHelper : MyTargetView.MyTargetViewListener { 14 | 15 | companion object 16 | { 17 | const val TAG = "BannerHelper" 18 | } 19 | 20 | var bannerView: MyTargetView? = null 21 | 22 | private var bar: Snackbar? = null 23 | private var afterLoad: (() -> Unit)? = null 24 | private var parent: View? = null 25 | 26 | override fun onLoad(p0: MyTargetView) { 27 | bar?.dismiss() 28 | afterLoad?.invoke() 29 | } 30 | 31 | override fun onClick(p0: MyTargetView) { 32 | } 33 | 34 | override fun onShow(p0: MyTargetView) { 35 | } 36 | 37 | override fun onNoAd(adLoadingError: IAdLoadingError, myTargetView: MyTargetView) { 38 | Log.d(TAG, "onNoAd() called with: adLoadingError = $adLoadingError, myTargetView = $myTargetView") 39 | parent?.let { 40 | Snackbar.make(it, String.format(myTargetView.context.getString(R.string.error_msg), adLoadingError.message), 41 | Snackbar.LENGTH_SHORT) 42 | .show() 43 | } 44 | } 45 | 46 | fun load(defaultSlot: Int, adSize: MyTargetView.AdSize, params: String?, parent: ViewGroup, 47 | function: (() -> Unit)? = null) { 48 | afterLoad = function 49 | bannerView = MyTargetView(parent.context).also { myTargetView -> 50 | myTargetView.setSlotId(defaultSlot) 51 | myTargetView.setAdSize(adSize) 52 | myTargetView.listener = this 53 | myTargetView.customParams.addParsedString(params) 54 | myTargetView.load() 55 | } 56 | this.parent = parent 57 | showLoading(parent) 58 | } 59 | 60 | private fun showLoading(parent: View) { 61 | bar = Snackbar.make(parent, "Loading", Snackbar.LENGTH_INDEFINITE) 62 | .showLoading() 63 | } 64 | 65 | fun destroy() { 66 | bannerView?.destroy() 67 | } 68 | } -------------------------------------------------------------------------------- /myTargetDemo/app/src/main/java/com/my/targetDemoApp/helpers/InterstitialHelper.kt: -------------------------------------------------------------------------------- 1 | package com.my.targetDemoApp.helpers 2 | 3 | import android.util.Log 4 | import android.view.View 5 | import com.google.android.material.snackbar.Snackbar 6 | import com.my.target.ads.InterstitialAd 7 | import com.my.target.common.models.IAdLoadingError 8 | import com.my.targetDemoApp.R 9 | import com.my.targetDemoApp.addParsedString 10 | import com.my.targetDemoApp.showLoading 11 | 12 | class InterstitialHelper(val parent: View) : InterstitialAd.InterstitialAdListener { 13 | 14 | companion object 15 | { 16 | const val TAG = "InterstitialHelper" 17 | } 18 | 19 | private var interstitialAd: InterstitialAd? = null 20 | private var showImmediatly: Boolean = false 21 | private var bar: Snackbar? = null 22 | 23 | override fun onLoad(interstitialAd: InterstitialAd) { 24 | if (showImmediatly) { 25 | bar?.dismiss() 26 | interstitialAd.show() 27 | } 28 | else { 29 | Snackbar.make(parent, "InterstitialAd is loaded", Snackbar.LENGTH_SHORT) 30 | .show() 31 | } 32 | } 33 | 34 | override fun onClick(interstitialAd: InterstitialAd) { 35 | } 36 | 37 | override fun onDisplay(interstitialAd: InterstitialAd) { 38 | } 39 | 40 | override fun onDismiss(interstitialAd: InterstitialAd) { 41 | } 42 | 43 | override fun onNoAd(adLoadingError: IAdLoadingError, ad: InterstitialAd) { 44 | Log.d(TAG, "onNoAd() called with: adLoadingError = $adLoadingError, ad = $ad") 45 | val s = String.format(parent.context.getString(R.string.error_msg), adLoadingError.message) 46 | Snackbar.make(parent, s, Snackbar.LENGTH_SHORT) 47 | .show() 48 | } 49 | 50 | override fun onVideoCompleted(interstitialAd: InterstitialAd) { 51 | } 52 | 53 | fun destroy() { 54 | interstitialAd?.dismiss() 55 | } 56 | 57 | fun init(slot: Int, showImmediatly: Boolean = false, params: String?) { 58 | showLoading(parent) 59 | this.showImmediatly = showImmediatly 60 | interstitialAd = InterstitialAd(slot, parent.context).also { 61 | it.listener = this 62 | it.customParams.addParsedString(params) 63 | it.load() 64 | } 65 | } 66 | 67 | private fun showLoading(parent: View) { 68 | bar = Snackbar.make(parent, "Loading", Snackbar.LENGTH_INDEFINITE) 69 | .showLoading() 70 | } 71 | 72 | fun show() { 73 | interstitialAd?.show() ?: Snackbar.make(parent, "Not loaded yet", Snackbar.LENGTH_SHORT) 74 | .show() 75 | } 76 | } -------------------------------------------------------------------------------- /myTargetDemo/app/src/main/java/com/my/targetDemoApp/helpers/NativeAdHelper.kt: -------------------------------------------------------------------------------- 1 | package com.my.targetDemoApp.helpers 2 | 3 | import android.content.Context 4 | import android.util.Log 5 | import android.view.View 6 | import com.my.target.common.models.IAdLoadingError 7 | import com.my.target.nativeads.NativeAd 8 | import com.my.target.nativeads.banners.NativePromoBanner 9 | import com.my.target.nativeads.factories.NativeViewsFactory 10 | import com.my.target.nativeads.views.NativeAdView 11 | import com.my.targetDemoApp.addParsedString 12 | 13 | class NativeAdHelper(parent: View) : NativeAd.NativeAdListener, 14 | NativeHelper(parent) { 15 | 16 | companion object 17 | { 18 | const val TAG = "NativeAdHelper" 19 | } 20 | 21 | override fun loadAds(slot: Int, params: String?) { 22 | val nativeAd = NativeAd(slot, parent.context) 23 | nativeAd.listener = this 24 | nativeAd.customParams.addParsedString(params) 25 | nativeAd.load() 26 | } 27 | 28 | override fun createAdView(context: Context): NativeAdView { 29 | return NativeViewsFactory.getNativeAdView(context) 30 | } 31 | 32 | override fun setupView(ad: NativeAd, adView: NativeAdView) { 33 | adView.setupView(ad.banner) 34 | } 35 | 36 | override fun registerView(ad: NativeAd, adView: View) { 37 | ad.registerView(adView) 38 | } 39 | 40 | override fun unRegisterView(ad: NativeAd?) { 41 | ad?.unregisterView() 42 | } 43 | 44 | override fun onLoad(banner: NativePromoBanner, nativeAd: NativeAd) { 45 | adCalls++ 46 | nativeList.append(nativeList.size() * 6 + 3, nativeAd) 47 | if (isLoaded()) { 48 | everythingLoaded() 49 | } 50 | } 51 | 52 | override fun onClick(nativeAd: NativeAd) { 53 | } 54 | 55 | override fun onVideoPlay(nativeAd: NativeAd) { 56 | } 57 | 58 | override fun onVideoPause(nativeAd: NativeAd) { 59 | } 60 | 61 | override fun onNoAd(adLoadingError: IAdLoadingError, nativeAd: NativeAd) { 62 | Log.d(TAG, "onNoAd() called with: adLoadingError = $adLoadingError, nativeAd = $nativeAd") 63 | adCalls++ 64 | if (isLoaded()) { 65 | callNoAd(adLoadingError.message) 66 | } 67 | } 68 | 69 | override fun onVideoComplete(nativeAd: NativeAd) { 70 | } 71 | 72 | override fun onShow(nativeAd: NativeAd) { 73 | } 74 | } -------------------------------------------------------------------------------- /myTargetDemo/app/src/main/java/com/my/targetDemoApp/helpers/NativeBannerHelper.kt: -------------------------------------------------------------------------------- 1 | package com.my.targetDemoApp.helpers 2 | 3 | import android.content.Context 4 | import android.util.Log 5 | import android.view.View 6 | import com.my.target.common.models.IAdLoadingError 7 | import com.my.target.nativeads.NativeBannerAd 8 | import com.my.target.nativeads.banners.NativeBanner 9 | import com.my.target.nativeads.factories.NativeViewsFactory 10 | import com.my.target.nativeads.views.NativeBannerAdView 11 | import com.my.targetDemoApp.addParsedString 12 | 13 | class NativeBannerHelper(parent: View) : NativeBannerAd.NativeBannerAdListener, 14 | NativeHelper(parent) { 15 | 16 | companion object 17 | { 18 | const val TAG = "NativeAdHelper" 19 | } 20 | 21 | override fun loadAds(slot: Int, params: String?) { 22 | val nativeAd = NativeBannerAd(slot, parent.context) 23 | nativeAd.listener = this 24 | nativeAd.customParams.addParsedString(params) 25 | nativeAd.load() 26 | } 27 | 28 | override fun createAdView(context: Context): NativeBannerAdView { 29 | return NativeViewsFactory.getNativeBannerAdView(context) 30 | } 31 | 32 | override fun setupView(ad: NativeBannerAd, adView: NativeBannerAdView) { 33 | adView.setupView(ad.banner) 34 | } 35 | 36 | override fun registerView(ad: NativeBannerAd, adView: View) { 37 | ad.registerView(adView) 38 | } 39 | 40 | override fun unRegisterView(ad: NativeBannerAd?) { 41 | ad?.unregisterView() 42 | } 43 | 44 | override fun onLoad(banner: NativeBanner, nativeAd: NativeBannerAd) { 45 | adCalls++ 46 | nativeList.append(nativeList.size() * 6 + 3, nativeAd) 47 | if (isLoaded()) { 48 | everythingLoaded() 49 | } 50 | } 51 | 52 | override fun onClick(nativeAd: NativeBannerAd) { 53 | } 54 | 55 | override fun onNoAd(adLoadingError: IAdLoadingError, nativeAd: NativeBannerAd) { 56 | Log.d(TAG, "onNoAd() called with: adLoadingError = $adLoadingError, nativeAd = $nativeAd") 57 | adCalls++ 58 | if (isLoaded()) { 59 | callNoAd(adLoadingError.message) 60 | } 61 | } 62 | 63 | override fun onShow(nativeAd: NativeBannerAd) { 64 | } 65 | } -------------------------------------------------------------------------------- /myTargetDemo/app/src/main/java/com/my/targetDemoApp/helpers/NativeHelper.kt: -------------------------------------------------------------------------------- 1 | package com.my.targetDemoApp.helpers 2 | 3 | import android.content.Context 4 | import android.view.LayoutInflater 5 | import android.view.View 6 | import android.view.ViewGroup 7 | import androidx.collection.SparseArrayCompat 8 | import androidx.recyclerview.widget.LinearLayoutManager 9 | import androidx.recyclerview.widget.RecyclerView 10 | import com.google.android.material.snackbar.Snackbar 11 | import com.my.target.nativeads.INativeAd 12 | import com.my.targetDemoApp.R 13 | import com.my.targetDemoApp.showLoading 14 | 15 | abstract class NativeHelper(val parent: View) { 16 | 17 | val nativeList = SparseArrayCompat() 18 | var adCalls: Int = 0 19 | var nativeAdCount = NATIVE_AD_CHUNK_SIZE 20 | private var loaded = false 21 | 22 | private var afterLoad: (() -> Unit)? = null 23 | private var afterNoad: ((String) -> Unit)? = null 24 | private var bar: Snackbar? = null 25 | private var slot: Int = 0 26 | private var params: String? = null 27 | private var loadingPosition: Int = 0 28 | 29 | private lateinit var nativeAdapter: NativeAdapter 30 | 31 | abstract fun loadAds(slot: Int, params: String?) 32 | 33 | abstract fun createAdView(context: Context): V 34 | 35 | abstract fun setupView(ad: N, adView: V) 36 | 37 | abstract fun registerView(ad: N, adView: View) 38 | 39 | abstract fun unRegisterView(ad: N?) 40 | 41 | fun createRecycler(): RecyclerView { 42 | val recyclerView = RecyclerView(parent.context) 43 | val layoutManager = LinearLayoutManager(parent.context, LinearLayoutManager.VERTICAL, false) 44 | recyclerView.layoutManager = layoutManager 45 | nativeAdapter = NativeAdapter(nativeList) 46 | recyclerView.adapter = nativeAdapter 47 | recyclerView.addOnScrollListener(ScrollListener(layoutManager) { loadMore() }) 48 | return recyclerView 49 | } 50 | 51 | private fun loadMore() { 52 | if (!isLoaded()) return 53 | afterLoad = { 54 | loadingPosition = nativeAdCount * 4 55 | nativeAdapter.notifyItemChanged(nativeAdCount * 4) 56 | nativeAdapter.notifyItemRangeInserted(nativeAdCount * 4 + 1, NATIVE_AD_CHUNK_SIZE * 4) 57 | } 58 | nativeAdCount += NATIVE_AD_CHUNK_SIZE 59 | repeat(NATIVE_AD_CHUNK_SIZE) { 60 | loadAds(slot,params) 61 | } 62 | } 63 | 64 | fun load(slot: Int, params: String?, view: View, afterLoad: (() -> Unit)?, 65 | afterNoAd: ((String) -> Unit)?) { 66 | this.slot = slot 67 | this.params = params 68 | this.afterLoad = afterLoad 69 | this.afterNoad = afterNoAd 70 | loaded = false 71 | nativeList.clear() 72 | nativeAdCount = NATIVE_AD_CHUNK_SIZE 73 | loadingPosition = nativeAdCount * 4 74 | if (afterLoad == null) showLoading(view) 75 | repeat(nativeAdCount) { 76 | loadAds(slot, params) 77 | } 78 | } 79 | 80 | fun everythingLoaded() { 81 | bar?.dismiss() 82 | loaded = true 83 | afterLoad?.invoke() 84 | } 85 | 86 | fun callNoAd(reason: String) { 87 | if (!nativeList.isEmpty) { 88 | afterLoad?.invoke() 89 | return 90 | } 91 | 92 | bar?.dismiss() 93 | afterNoad?.invoke(reason) 94 | } 95 | 96 | fun isLoaded(): Boolean { 97 | return adCalls >= nativeAdCount 98 | } 99 | 100 | private fun showLoading(parent: View) { 101 | bar = Snackbar.make(parent, "Loading", Snackbar.LENGTH_INDEFINITE) 102 | .showLoading() 103 | } 104 | 105 | abstract class NativeViewHolder(view: View) : RecyclerView.ViewHolder(view) 106 | 107 | class NativeAdViewHolder(var adView: V) : NativeViewHolder(adView) 108 | 109 | class NativeDummyHolder(var view: View) : NativeViewHolder(view) 110 | 111 | class ScrollListener(private val linearLayoutManager: LinearLayoutManager, 112 | private val loadMore: (() -> Unit)) : RecyclerView.OnScrollListener() { 113 | override fun onScrolled(recyclerView: RecyclerView, dx: Int, dy: Int) { 114 | val totalItemCount: Int = linearLayoutManager.itemCount 115 | val lastVisibleItemPosition: Int = linearLayoutManager.findLastVisibleItemPosition() 116 | if (totalItemCount - lastVisibleItemPosition < 4) { 117 | loadMore.invoke() 118 | } 119 | super.onScrolled(recyclerView, dx, dy) 120 | } 121 | } 122 | 123 | inner class NativeAdapter(private var nativeList: SparseArrayCompat) : 124 | RecyclerView.Adapter() { 125 | 126 | override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): NativeViewHolder { 127 | return when (viewType) { 128 | TYPE_AD -> { 129 | val adView = createAdView(parent.context) 130 | 131 | NativeAdViewHolder(adView) 132 | } 133 | TYPE_LOADING -> { 134 | NativeDummyHolder(LayoutInflater.from(parent.context) 135 | .inflate(R.layout.item_native_loading, parent, false) as ViewGroup) 136 | } 137 | else -> { 138 | NativeDummyHolder(LayoutInflater.from(parent.context) 139 | .inflate(R.layout.item_native, parent, false) as ViewGroup) 140 | } 141 | } 142 | } 143 | 144 | override fun getItemCount(): Int { 145 | return nativeAdCount * 4 + 1 146 | } 147 | 148 | override fun getItemViewType(position: Int): Int { 149 | if (nativeList[position] != null) { 150 | return TYPE_AD 151 | } 152 | if (position == loadingPosition) { 153 | return TYPE_LOADING 154 | } 155 | return TYPE_TEXT 156 | } 157 | 158 | override fun onBindViewHolder(holder: NativeViewHolder, position: Int) { 159 | val ad = nativeList[position] ?: return 160 | if (holder is NativeAdViewHolder<*>) { 161 | setupView(ad, holder.adView as V) 162 | registerView(ad, holder.adView) 163 | } 164 | } 165 | 166 | override fun onViewRecycled(holder: NativeViewHolder) { 167 | super.onViewRecycled(holder) 168 | unRegisterView(nativeList.get(holder.adapterPosition)) 169 | } 170 | 171 | override fun onFailedToRecycleView(holder: NativeViewHolder): Boolean { 172 | unRegisterView(nativeList.get(holder.adapterPosition)) 173 | return super.onFailedToRecycleView(holder) 174 | } 175 | } 176 | 177 | companion object { 178 | const val NATIVE_AD_CHUNK_SIZE = 5 179 | const val TYPE_TEXT = 0 180 | const val TYPE_AD = 1 181 | const val TYPE_LOADING = 2 182 | } 183 | } -------------------------------------------------------------------------------- /myTargetDemo/app/src/main/java/com/my/targetDemoApp/helpers/RewardedHelper.kt: -------------------------------------------------------------------------------- 1 | package com.my.targetDemoApp.helpers 2 | 3 | import android.util.Log 4 | import android.view.View 5 | import com.google.android.material.snackbar.Snackbar 6 | import com.my.target.ads.Reward 7 | import com.my.target.ads.RewardedAd 8 | import com.my.target.common.models.IAdLoadingError 9 | import com.my.targetDemoApp.R 10 | import com.my.targetDemoApp.addParsedString 11 | import com.my.targetDemoApp.showLoading 12 | 13 | class RewardedHelper(val parent: View) : RewardedAd.RewardedAdListener { 14 | 15 | companion object 16 | { 17 | const val TAG = "RewardedHelper" 18 | } 19 | 20 | private var rewardedAd: RewardedAd? = null 21 | private var showImmediatly: Boolean = false 22 | private var bar: Snackbar? = null 23 | 24 | override fun onLoad(rewardedAd: RewardedAd) { 25 | if (showImmediatly) { 26 | bar?.dismiss() 27 | rewardedAd.show() 28 | } 29 | else { 30 | Snackbar.make(parent, "RewardedAd is loaded", Snackbar.LENGTH_SHORT) 31 | .show() 32 | } 33 | } 34 | 35 | override fun onClick(rewardedAd: RewardedAd) { 36 | } 37 | 38 | override fun onDisplay(rewardedAd: RewardedAd) { 39 | } 40 | 41 | override fun onDismiss(rewardedAd: RewardedAd) { 42 | } 43 | 44 | override fun onNoAd(adLoadingError: IAdLoadingError, nativeAd: RewardedAd) { 45 | Log.d(TAG, "onNoAd() called with: adLoadingError = $adLoadingError, nativeAd = $nativeAd") 46 | val s = String.format(parent.context.getString(R.string.error_msg), adLoadingError.message) 47 | Snackbar.make(parent, s, Snackbar.LENGTH_SHORT) 48 | .show() 49 | } 50 | 51 | override fun onReward(p0: Reward, p1: RewardedAd) { 52 | Snackbar.make(parent, "Got ${p0.type} reward", Snackbar.LENGTH_SHORT) 53 | .show() 54 | } 55 | 56 | fun destroy() { 57 | rewardedAd?.dismiss() 58 | } 59 | 60 | fun init(slot: Int, showImmediatly: Boolean = false, params: String?) { 61 | showLoading(parent) 62 | this.showImmediatly = showImmediatly 63 | rewardedAd = RewardedAd(slot, parent.context) 64 | rewardedAd?.let { 65 | it.listener = this 66 | it.customParams.addParsedString(params) 67 | it.load() 68 | } 69 | } 70 | 71 | private fun showLoading(parent: View) { 72 | bar = Snackbar.make(parent, "Loading", Snackbar.LENGTH_INDEFINITE) 73 | .showLoading() 74 | } 75 | 76 | fun show() { 77 | rewardedAd?.show() ?: Snackbar.make(parent, "Not loaded yet", Snackbar.LENGTH_SHORT) 78 | .show() 79 | } 80 | } -------------------------------------------------------------------------------- /myTargetDemo/app/src/main/java/com/my/targetDemoApp/player/DefaultPlayerEventListener.kt: -------------------------------------------------------------------------------- 1 | package com.my.targetDemoApp.player 2 | 3 | import com.google.android.exoplayer2.Player 4 | 5 | interface DefaultPlayerEventListener : Player.Listener { 6 | override fun onLoadingChanged(isLoading: Boolean) { 7 | } 8 | 9 | override fun onPositionDiscontinuity(reason: Int) { 10 | } 11 | 12 | override fun onRepeatModeChanged(repeatMode: Int) { 13 | } 14 | 15 | override fun onShuffleModeEnabledChanged(shuffleModeEnabled: Boolean) { 16 | } 17 | 18 | override fun onPlayerStateChanged(playWhenReady: Boolean, playbackState: Int) { 19 | } 20 | } -------------------------------------------------------------------------------- /myTargetDemo/app/src/main/java/com/my/targetDemoApp/player/ExoTimeBar.kt: -------------------------------------------------------------------------------- 1 | package com.my.targetDemoApp.player 2 | 3 | import android.content.Context 4 | import android.util.AttributeSet 5 | import com.google.android.exoplayer2.ui.DefaultTimeBar 6 | 7 | class ExoTimeBar(context: Context, attrs: AttributeSet?) : DefaultTimeBar(context, attrs) { 8 | 9 | override fun setAdGroupTimesMs(adGroupTimesMs: LongArray?, playedAdGroups: BooleanArray?, adGroupCount: Int) { 10 | //nothing 11 | } 12 | 13 | fun setAdGroupTimesSec(adGroupTimesMs: FloatArray) { 14 | val longs = LongArray(adGroupTimesMs.size) 15 | for ((index, value) in adGroupTimesMs.withIndex()) { 16 | longs[index] = (value * 1000).toLong() 17 | } 18 | super.setAdGroupTimesMs(longs, BooleanArray(adGroupTimesMs.size) { true }, adGroupTimesMs.size) 19 | } 20 | 21 | } -------------------------------------------------------------------------------- /myTargetDemo/app/src/main/java/com/my/targetDemoApp/player/InstreamAuidoAdPlayerHelper.kt: -------------------------------------------------------------------------------- 1 | package com.my.targetDemoApp.player 2 | 3 | import android.content.Context 4 | import android.net.Uri 5 | import com.google.android.exoplayer2.ExoPlayer 6 | import com.google.android.exoplayer2.MediaItem 7 | import com.google.android.exoplayer2.PlaybackException 8 | import com.google.android.exoplayer2.Player 9 | import com.google.android.exoplayer2.source.ProgressiveMediaSource 10 | import com.google.android.exoplayer2.upstream.DefaultDataSourceFactory 11 | import com.google.android.exoplayer2.util.Util 12 | 13 | import com.my.target.instreamads.InstreamAudioAdPlayer 14 | 15 | class InstreamAuidoAdPlayerHelper(private val currentExoplayer: ExoPlayer, val context: Context) : InstreamAudioAdPlayer, DefaultPlayerEventListener 16 | { 17 | 18 | private var playerListener: InstreamAudioAdPlayer.AdPlayerListener? = null 19 | private var paused = false 20 | 21 | init 22 | { 23 | currentExoplayer.addListener(this) 24 | } 25 | 26 | override fun onPlayerError(error: PlaybackException) 27 | { 28 | adPlayerListener?.onAdAudioError(error.message ?: "No message") 29 | stopAdAudio() 30 | } 31 | 32 | override fun onPlayerStateChanged(playWhenReady: Boolean, playbackState: Int) 33 | { 34 | 35 | if (playbackState == Player.STATE_ENDED) 36 | { 37 | onAdAudioComplete() 38 | return 39 | } 40 | 41 | if (playbackState != Player.STATE_READY) 42 | { 43 | return 44 | } 45 | 46 | if (!playWhenReady) 47 | { 48 | adPlayerListener?.onAdAudioPaused() 49 | paused = true 50 | return 51 | } 52 | 53 | if (paused) 54 | { 55 | adPlayerListener?.onAdAudioResumed() 56 | paused = false 57 | return 58 | } 59 | 60 | adPlayerListener?.onAdAudioStarted() 61 | } 62 | 63 | override fun pauseAdAudio() 64 | { 65 | currentExoplayer.pause() 66 | adPlayerListener?.onAdAudioPaused() 67 | } 68 | 69 | override fun resumeAdAudio() 70 | { 71 | currentExoplayer.play() 72 | adPlayerListener?.onAdAudioResumed() 73 | } 74 | 75 | override fun stopAdAudio() 76 | { 77 | currentExoplayer.stop() 78 | adPlayerListener?.onAdAudioStopped() 79 | } 80 | 81 | override fun destroy() 82 | { 83 | currentExoplayer.release() 84 | } 85 | 86 | override fun setVolume(volume: Float) 87 | { 88 | currentExoplayer.volume = volume 89 | adPlayerListener?.onVolumeChanged(volume) 90 | } 91 | 92 | override fun getAdPlayerListener(): InstreamAudioAdPlayer.AdPlayerListener? 93 | { 94 | return playerListener 95 | } 96 | 97 | override fun getAdAudioDuration(): Float 98 | { 99 | return currentExoplayer.duration.toFloat() 100 | .div(1000) 101 | } 102 | 103 | override fun getAdAudioPosition(): Float 104 | { 105 | return currentExoplayer.currentPosition.toFloat() 106 | .div(1000) 107 | } 108 | 109 | override fun getCurrentContext(): Context 110 | { 111 | return context 112 | } 113 | 114 | override fun setAdPlayerListener(adPlayerListener: InstreamAudioAdPlayer.AdPlayerListener?) 115 | { 116 | this.playerListener = adPlayerListener; 117 | } 118 | 119 | override fun playAdAudio(uri: Uri) 120 | { 121 | setAudioSource(uri, true) 122 | } 123 | 124 | fun setAudioSource(uri: Uri, playWhenReady: Boolean) 125 | { 126 | val mediaSource = ProgressiveMediaSource.Factory( 127 | DefaultDataSourceFactory(context, Util.getUserAgent(context, "myTarget")) 128 | ) 129 | .createMediaSource(MediaItem.fromUri(uri)) 130 | currentExoplayer.playWhenReady = playWhenReady 131 | currentExoplayer.setMediaSource(mediaSource) 132 | currentExoplayer.prepare() 133 | } 134 | 135 | fun onAdAudioComplete() 136 | { 137 | adPlayerListener?.onAdAudioCompleted() 138 | } 139 | } -------------------------------------------------------------------------------- /myTargetDemo/app/src/main/res/drawable-v24/ic_launcher_foreground.xml: -------------------------------------------------------------------------------- 1 | 6 | 8 | 11 | 14 | 17 | 18 | 19 | -------------------------------------------------------------------------------- /myTargetDemo/app/src/main/res/drawable/button_background_onvideo.xml: -------------------------------------------------------------------------------- 1 | 3 | 4 | 5 | 6 | 9 | -------------------------------------------------------------------------------- /myTargetDemo/app/src/main/res/drawable/ic_add.xml: -------------------------------------------------------------------------------- 1 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /myTargetDemo/app/src/main/res/drawable/ic_launcher_foreground.xml: -------------------------------------------------------------------------------- 1 | 6 | 8 | 11 | 14 | 17 | 18 | 19 | -------------------------------------------------------------------------------- /myTargetDemo/app/src/main/res/layout/activity_banners.xml: -------------------------------------------------------------------------------- 1 | 2 | 8 | 9 | 13 | 14 | 20 | 21 | 22 | 23 | 24 | 31 | 32 | 44 | 45 | 53 | 54 | 59 | 60 | 65 | 66 | 71 | 72 | 77 | 78 | 83 | 84 | 85 | 86 | 87 | 96 | 97 | 103 | 104 | 105 | 106 | 107 | 114 | 115 | 119 | 120 | 121 | 122 | 123 | -------------------------------------------------------------------------------- /myTargetDemo/app/src/main/res/layout/activity_interstitials.xml: -------------------------------------------------------------------------------- 1 | 2 | 8 | 9 | 13 | 14 | 20 | 21 | 22 | 23 | 30 | 31 | 37 | 38 | 51 | 52 | 60 | 61 | 65 | 66 | 71 | 72 | 77 | 78 | 83 | 84 | 89 | 90 | 95 | 96 | 101 | 102 | 107 | 108 | 113 | 114 | 115 | 116 | 117 | 118 | 119 | 127 | 128 | 137 | 138 | 139 | 140 | -------------------------------------------------------------------------------- /myTargetDemo/app/src/main/res/layout/activity_main.xml: -------------------------------------------------------------------------------- 1 | 2 | 8 | 9 | 13 | 14 | 20 | 21 | 22 | 23 | 28 | 29 | 30 | 31 | 38 | 39 | -------------------------------------------------------------------------------- /myTargetDemo/app/src/main/res/layout/activity_native_banners.xml: -------------------------------------------------------------------------------- 1 | 2 | 8 | 9 | 13 | 14 | 20 | 21 | 22 | 23 | 30 | 31 | 32 | 33 | 40 | 41 | 42 | 50 | 51 | 56 | 57 | 63 | 64 | 65 | 66 | -------------------------------------------------------------------------------- /myTargetDemo/app/src/main/res/layout/activity_native_configuration.xml: -------------------------------------------------------------------------------- 1 | 2 | 8 | 9 | 13 | 14 | 20 | 21 | 22 | 23 | 30 | 31 | 43 | 44 | 52 | 53 | 59 | 60 | 65 | 66 | 71 | 72 | 73 | 74 | 82 | 83 | 91 | 92 | 99 | 100 | 101 | 109 | 110 | 119 | 120 | 128 | 129 | 130 | 131 | 132 | 140 | 141 | 146 | 147 | 153 | 154 | 155 | 156 | -------------------------------------------------------------------------------- /myTargetDemo/app/src/main/res/layout/activity_natives.xml: -------------------------------------------------------------------------------- 1 | 2 | 8 | 9 | 13 | 14 | 20 | 21 | 22 | 23 | 30 | 31 | 32 | 46 | 47 | 48 | 56 | 57 | 58 | 63 | 64 | 69 | 70 | 75 | 76 | 77 | 78 | 79 | 88 | 89 | 90 | 91 | 92 | 99 | 100 | 108 | 109 | 114 | 115 | 121 | 122 | 123 | 124 | -------------------------------------------------------------------------------- /myTargetDemo/app/src/main/res/layout/activity_simple_banner.xml: -------------------------------------------------------------------------------- 1 | 2 | 10 | 11 | 15 | 16 | 19 | 20 | 28 | 29 | 30 | -------------------------------------------------------------------------------- /myTargetDemo/app/src/main/res/layout/exo_playback_control_view.xml: -------------------------------------------------------------------------------- 1 | 15 | 22 | 23 | 29 | 30 | 34 | 35 | 39 | 40 | 41 | 42 | 48 | 49 | 59 | 60 | 68 | 69 | 79 | 80 | 81 | 82 | 83 | -------------------------------------------------------------------------------- /myTargetDemo/app/src/main/res/layout/item_banner.xml: -------------------------------------------------------------------------------- 1 | 2 | 6 | 7 | 12 | 13 | -------------------------------------------------------------------------------- /myTargetDemo/app/src/main/res/layout/item_main.xml: -------------------------------------------------------------------------------- 1 | 2 | 13 | 14 | 17 | 18 | 19 | 29 | 30 | 39 | 40 | 48 | 49 | 50 | 51 | -------------------------------------------------------------------------------- /myTargetDemo/app/src/main/res/layout/item_native.xml: -------------------------------------------------------------------------------- 1 | 2 | 9 | 10 | 14 | 15 | -------------------------------------------------------------------------------- /myTargetDemo/app/src/main/res/layout/item_native_loading.xml: -------------------------------------------------------------------------------- 1 | 2 | 9 | 10 | 14 | 15 | -------------------------------------------------------------------------------- /myTargetDemo/app/src/main/res/mipmap-anydpi-v26/ic_launcher.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | -------------------------------------------------------------------------------- /myTargetDemo/app/src/main/res/mipmap-anydpi-v26/ic_launcher_round.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | -------------------------------------------------------------------------------- /myTargetDemo/app/src/main/res/mipmap-hdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/myTargetSDK/mytarget-android/e4bb080b44f81633c2f4bc7f52100f3442cbebea/myTargetDemo/app/src/main/res/mipmap-hdpi/ic_launcher.png -------------------------------------------------------------------------------- /myTargetDemo/app/src/main/res/mipmap-hdpi/ic_launcher_round.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/myTargetSDK/mytarget-android/e4bb080b44f81633c2f4bc7f52100f3442cbebea/myTargetDemo/app/src/main/res/mipmap-hdpi/ic_launcher_round.png -------------------------------------------------------------------------------- /myTargetDemo/app/src/main/res/mipmap-mdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/myTargetSDK/mytarget-android/e4bb080b44f81633c2f4bc7f52100f3442cbebea/myTargetDemo/app/src/main/res/mipmap-mdpi/ic_launcher.png -------------------------------------------------------------------------------- /myTargetDemo/app/src/main/res/mipmap-mdpi/ic_launcher_round.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/myTargetSDK/mytarget-android/e4bb080b44f81633c2f4bc7f52100f3442cbebea/myTargetDemo/app/src/main/res/mipmap-mdpi/ic_launcher_round.png -------------------------------------------------------------------------------- /myTargetDemo/app/src/main/res/mipmap-xhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/myTargetSDK/mytarget-android/e4bb080b44f81633c2f4bc7f52100f3442cbebea/myTargetDemo/app/src/main/res/mipmap-xhdpi/ic_launcher.png -------------------------------------------------------------------------------- /myTargetDemo/app/src/main/res/mipmap-xhdpi/ic_launcher_round.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/myTargetSDK/mytarget-android/e4bb080b44f81633c2f4bc7f52100f3442cbebea/myTargetDemo/app/src/main/res/mipmap-xhdpi/ic_launcher_round.png -------------------------------------------------------------------------------- /myTargetDemo/app/src/main/res/mipmap-xxhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/myTargetSDK/mytarget-android/e4bb080b44f81633c2f4bc7f52100f3442cbebea/myTargetDemo/app/src/main/res/mipmap-xxhdpi/ic_launcher.png -------------------------------------------------------------------------------- /myTargetDemo/app/src/main/res/mipmap-xxhdpi/ic_launcher_round.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/myTargetSDK/mytarget-android/e4bb080b44f81633c2f4bc7f52100f3442cbebea/myTargetDemo/app/src/main/res/mipmap-xxhdpi/ic_launcher_round.png -------------------------------------------------------------------------------- /myTargetDemo/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/myTargetSDK/mytarget-android/e4bb080b44f81633c2f4bc7f52100f3442cbebea/myTargetDemo/app/src/main/res/mipmap-xxxhdpi/ic_launcher.png -------------------------------------------------------------------------------- /myTargetDemo/app/src/main/res/mipmap-xxxhdpi/ic_launcher_round.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/myTargetSDK/mytarget-android/e4bb080b44f81633c2f4bc7f52100f3442cbebea/myTargetDemo/app/src/main/res/mipmap-xxxhdpi/ic_launcher_round.png -------------------------------------------------------------------------------- /myTargetDemo/app/src/main/res/values/colors.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | #FC2C38 4 | #d72833 5 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /myTargetDemo/app/src/main/res/values/dimens.xml: -------------------------------------------------------------------------------- 1 | 2 | 16dp 3 | 8dp 4 | 4dp 5 | 16dp 6 | 7 | -------------------------------------------------------------------------------- /myTargetDemo/app/src/main/res/values/ic_launcher_background.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | #FFFFFF 4 | -------------------------------------------------------------------------------- /myTargetDemo/app/src/main/res/values/integers.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 1 4 | -------------------------------------------------------------------------------- /myTargetDemo/app/src/main/res/values/strings.xml: -------------------------------------------------------------------------------- 1 | 2 | myTarget Demo 3 | Banners 4 | Interstitial 5 | Native Ads 6 | Native Ad configurations 7 | Native Banner Ads 8 | InStream 9 | Audio InStream 10 | 11 | 320x50 and 300x250 banners 12 | Fullscreen banners 13 | Advertisement inside app\'s content 14 | Native Ad AdChoices configurations 15 | Compact advertisement inside app\'s content 16 | Advertisement inside video stream 17 | Advertisement audio inStream 18 | OK 19 | Cancel 20 | Select ad type and enter slot id. 21 | 22 | Banner 320x50 23 | Banner 300x250 24 | Native ad 25 | Native ad configurations 26 | Native Banner ad 27 | Banner 728x90 (tablets only) 28 | Adaptive size 29 | Banner size 30 | 320x50 31 | 300x250 32 | 728x90 (tablets) 33 | Show 34 | Interstitial type 35 | Static promo 36 | Video promo 37 | Video 38 | VAST video 39 | Image 40 | Carousel 41 | Show 42 | N/A 43 | 44 | Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur 45 | Load 46 | Native content 47 | None 48 | Video 49 | Instream params 50 | Fullscreen 51 | Quality 52 | Timeout 53 | Current ad params 54 | Duration 55 | Position 56 | Dimensions 57 | CloseDelay 58 | Allow close 59 | Has pause 60 | Allow pause 61 | Player status 62 | Not loaded 63 | skip banner 64 | skip all 65 | cta 66 | Ad video controls 67 | Ad audio controls 68 | play 69 | pause 70 | resume 71 | stop 72 | preroll 73 | pauseroll 74 | midroll 75 | postroll 76 | Rewarded 77 | Rewarded video banners 78 | Video promo (new style) 79 | Adaptive 80 | Adaptive (xml) 81 | Loading… 82 | Ad wasn\'t loaded, message: %8s 83 | 66039511634340742311 84 | 85 | Ad close mode 86 | Don\'t use adChoices option listener(default by sdk) 87 | Auto close (by sdk) 88 | Close by developer 89 | Show custom adChoices options menu 90 | Use custom adChoices view 91 | 92 | -------------------------------------------------------------------------------- /myTargetDemo/app/src/main/res/values/styles.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 16 | 17 | 21 | 22 | 27 | 28 | 32 | 33 |