diff --git a/.idea/compiler.xml b/.idea/compiler.xml deleted file mode 100644 index 96cc43e..0000000 --- a/.idea/compiler.xml +++ /dev/null @@ -1,22 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/.idea/copyright/profiles_settings.xml b/.idea/copyright/profiles_settings.xml deleted file mode 100644 index e7bedf3..0000000 --- a/.idea/copyright/profiles_settings.xml +++ /dev/null @@ -1,3 +0,0 @@ - - - \ No newline at end of file diff --git a/.idea/gradle.xml b/.idea/gradle.xml deleted file mode 100644 index 723a125..0000000 --- a/.idea/gradle.xml +++ /dev/null @@ -1,22 +0,0 @@ - - - - - - \ No newline at end of file diff --git a/.idea/kotlinc.xml b/.idea/kotlinc.xml deleted file mode 100644 index 0026255..0000000 --- a/.idea/kotlinc.xml +++ /dev/null @@ -1,10 +0,0 @@ - - - - - - \ No newline at end of file diff --git a/.idea/markdown-navigator/profiles_settings.xml b/.idea/markdown-navigator/profiles_settings.xml deleted file mode 100644 index 57927c5..0000000 --- a/.idea/markdown-navigator/profiles_settings.xml +++ /dev/null @@ -1,3 +0,0 @@ - - - \ No newline at end of file diff --git a/.idea/misc.xml b/.idea/misc.xml deleted file mode 100644 index 4ffd5bd..0000000 --- a/.idea/misc.xml +++ /dev/null @@ -1,102 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/.idea/modules.xml b/.idea/modules.xml deleted file mode 100644 index b4df6c5..0000000 --- a/.idea/modules.xml +++ /dev/null @@ -1,13 +0,0 @@ - - - - - - - - - - - - - \ No newline at end of file diff --git a/.idea/runConfigurations.xml b/.idea/runConfigurations.xml deleted file mode 100644 index 7f68460..0000000 --- a/.idea/runConfigurations.xml +++ /dev/null @@ -1,12 +0,0 @@ - - - - - - \ No newline at end of file diff --git a/README.md b/README.md new file mode 100644 index 0000000..9605e55 --- /dev/null +++ b/README.md @@ -0,0 +1,375 @@ +# video intelligence Android SDK integration documentation + +1. [SDK Integration](https://github.com/vi-ai/vi-android-sdk#step-1--include-the-vimobileadssdk-library-in-your-application) +2. [Instream Ads](https://github.com/vi-ai/vi-android-sdk#requesting-ads-how-to-serve-in-stream-ads-using-the-vi-sdk) +3. [Interstitial Ads](https://github.com/vi-ai/vi-android-sdk#requesting-ads-how-to-serve-interstitial-ads-using-the-vi-sdk) +4. [Ads Mediation](https://github.com/vi-ai/vi-android-sdk#client-side-mediation-how-to-enable-ad-mediation-support) +5. [External Trackers](https://github.com/vi-ai/vi-android-sdk#external-tracker-how-add-external-trackers-for-viadssdk) + +## Step 1 | Include the ViMobileAdsSDK library in your application. + +To add ViMobileAdsSDK to your application, is required to add our maven repository link and dependency. + +```groovy +repositories { + maven { + url 'https://maven.vi.ai/repository/mobileads-public/' + } +} + +dependencies { + compile('ai.vi.mobileads:mobileads:x.y.z') { + transitive true + } +} +``` + +*please replace x.y.z to current SDK version* + +Finally, our SDK has a required dependency on Google Play Services Ads, so please make sure to include it in your app’s list of dependencies. + +```groovy +dependencies { + compile 'com.google.android.gms:play-services-ads:10.2.0' +} +``` + +Our SDK requires the INTERNET permission, and the (optional) location services permission. +Add this permissions to AndroidManifest.xml + +```xml + + + +``` +___ +## Step 2 | Initialize ViMobileAdsSdk + +Initialize our SDK as early as possible by calling the init method on the singleton instance and passing in a +reference to the Application object, where mApp is a reference to the Application: +```java +import ai.vi.mobileads.api.ViSdk; + +ViSdk.init(this); +``` + +Ideally you should call start within the onCreate method of your app’s Application +subclass. For example: + +```java +import android.app.Application; +import ai.vi.mobileads.api.ViSdk; + +public class MyApplication extends Application { + + @Override + public void onCreate() { + super.onCreate(); + ViSdk.init(this); + } +} +``` + +If you are an SDK rather than app developer, you should initialize us as soon as you are able to access the +Application object. + +If you will try to get ViSdk singleton instance (ViSdk.getInstance()) before call init SDK wil throw IllegalStateException("SDK currently not initialized"); + +___ +# Requesting Ads: How to serve In-Stream Ads using the vi SDK + +## Step 1 | Add ViAdView into your UI + +Put ViAdView into your layout +```xml + + + + + +``` +or create it by self and add into current layout +___ +## Step 2 | Initialize viVideoAd and load an ad +Create ViAdPlacement with the placement id from console +```java +import ai.vi.mobileads.api.ViAdPlacement; + +ViAdPlacement placement = ViAdPlacement.create("Your placement id from console"); +``` +Initialize the ViAdManager with the placement code from console + +```java +import ai.vi.mobileads.api.ViVideoAd; + +ViVideoAd videoAdManager = ViSdk.getInstance().createVideoAd(placement, adView); +``` +If you want to get notification about AD workflow you should create ```ViVideoAd``` with Callback + +```java +import ai.vi.mobileads.api.ViVideoAd; + +ViVideoAd viVideoAd = ViSdk.getInstance().createVideoAd(placement, viAdView, new ViAdCallback() { + @Override + public void onAdEvent(ViAdEvent viAdEvent) { + switch (viAdEvent.type){ + case AD_PAUSED:{ + //notifies that ad is paused + break; + } + case AD_CLICKED: { + //notifies that user click into curent ad + break; + } + case AD_CLOSE: { + //notifies that ad is closed + break; + } + case AD_COMPLETED:{ + //notifies that ad playback completed + break; + } + case AD_LOADED:{ + //notifies that ad loaded and ready for play + //you can start ad playback by videoAdManager.startAd() + break; + } + case AD_RESUMED:{ + //notifies that ad is resumed + break; + } + case AD_STARTED:{ + //notifies that ad playback started + } + } + } + + @Override + public void onAdError(ViAdError viAdError) { + switch (viAdError.type){ + case AD_PLAYBACK_ERROR:{ + //notifies about ad playback error + break; + } + case AD_LOADING_ERROR:{ + //notifies about ad loading error + } + } + } + }); +``` + +Load ad +```java +viVideoAd.loadAd(); +``` +Load ad with **auto start** playback when ad is ready +```java +viVideoAd.loadAd(true); +``` +___ +## Step 3 | Ad playback control + +Pause current ad playback +```java +viVideoAd.pause(); +``` +Resume current ad playback +```java +viVideoAd.resume(); +``` +Close current ad +```java +viVideoAd.closeAd(); +``` +___ +# Requesting Ads: How to serve Interstitial Ads using the vi SDK + +## Step 1 | Add the Interstitial activity to your manifest + +```xml + +``` + +## Step 2 | Initialize ViInterstitialAd and load the ad + +```java +ViinterstitalAd interstitialAd = ViSdk.getinstance().createinterstitialAd(placement, new ViAdCallback() { + @Override + public void onAdEvent(ViAdEvent event) { + //All add events arrive here + } + @Override + public void onAdError(ViAdError error){ + + } + }); +interstitialAd.loadAd(); +``` + +Note that for Interstitial ads, we cannot load the ad and automatically begin its playback. Rather, you control when the ad starts playing. + +When the ad has finished loading, you will receive the ```AD_LOADED``` event in the onAdEvent method of ViAdCallback. Note that you will not be able to trigger ```startAd()``` before the ad has finished loading. This is because Interstitial ads are cached before the ```AD_LOADED``` event is triggered, guaranteeing that the ad will start immediately after the Interstitial Activity is called. + +## Step 3 | Display the ad + +```java +interstitialAd.startAd(); +``` + +You can also trigger the ad immediately after it completes loading by triggering it in the callback + +````java +@Override +public void onAdEvent(ViAdEvent event) { + if(event.type = ViAdEvent.ViAdEventType.AD_LOADED){ + if(interstitialAd =! null) { + //You'll get notified that the ad is loaded and ready + interstitialAd.startAd(); + } + } +} +```` + +## Step 4 | Controlling Ad state + +You can check if the ad has been downloaded and is ready for playback. + +````java +interstitialAd.isReady(); +```` + +Also keep in mid that all Interstitial Ads are cached. Please call ```closeAd()``` onDestroy of the activity, where ```loadAd()``` was called. + +````java +interstitialAd.closeAd(); +```` +___ +# Client Side Mediation: How to enable Ad mediation support + +ViMobileAds SDK supports three ad providers: +1. AdMob +2. MoPub +3. Facebook + +## Step 1 | Add adapter dependency + +In order to enable client side ad mediation, we have provided an adapter for each individual ad provider. Should you wish to mediate a specific ad provider, all you would need to do is add the required adapter as a dependency to your project. + +```groovy +dependencies { + + //AdMob mediation adapter + compile('ai.vi.mobileads:admob-adapter:x.y.z') { + transitive true + } + + //Facebook mediation adapter + compile('ai.vi.mobileads:facebook-adapter:x.y.z') { + transitive true + } + + //MoPub mediation adapter + compile('ai.vi.mobileads:mopub-adapter:x.y.z') { + transitive true + } +} +``` + +*please replace x.y.z to current SDK version (adapters are supported from version 2.0.0 and above)* + +## Step 2 | Register mediation adapter in ViAd + +Mediation adapters should be added to Vi Ads where you want mediation to be present. Here is simple facebook example : + +```java +ViAdPlacement viAdPlacement = ViAdPlacement.create("Vi Ad placementId"); +ViIntersititalAd viInterstitialAd = ViSdk.getInstance().createInterstitialAd(viAdPlacement, this); +ViIntersititalAd viInterstitialAd.registerMediatedAdapter(new FacebookViInterstitialMediationAdapter(this, "Facebook placement ID")); +``` + +That’s it. When there is no available vi Direct demand, the Facebook ad will be sourced and displayed in your application + +___ +# External tracker: How add external trackers for ViAdsSDK + +ViAdSDK provides ability to add global trackers on all events that happens within the SDK. This tracking should be registered once after SDK initialization. +This can be achieved with implementation of ``` ViExternalAdTracker ``` interface. + +```java +ViSdk.getInstance().registerExternalAdapter(new ViExternalAdTracker() { + @Override + public void adStart(String placementId) { + + } + + @Override + public void adComplete(String placementId) { + + } + + @Override + public void adPaused(String placementId) { + + } + + @Override + public void adResumed(String placementId) { + + } + + @Override + public void adSkip(String placementId) { + + } + + @Override + public void adError(String placementId) { + + } + + @Override + public void adClicked(String placementId) { + + } + + @Override + public void adVolumeChanged(String placementId, boolean isMuted) { + + } + }); + +``` + +For all events, the placementID determines on which placement the event occurred. +Apart from custom events, the vi SDK also includes a pre-built adapter for ```count.ly``` analytics. + + +## Step 1 | Add count.ly adapter as dependency +```groovy +compile('ai.vi.mobileads:countly-adapter:x.y.z') { + transitive true +} +``` +*please replace x.y.z to current SDK version (adapters are supported from version 2.0.0 and above)* + + +## Step 2 | Register count.ly adapter + +```java +import ai.vi.mobileads.adapter.countly.ViMobileAdsCountlyTracker; + +ViSdk.getInstance().registerExternalAdapter(new ViMobileAdsCountlyTracker()); +``` + diff --git a/instream/src/test/java/ai/vi/samples/instream/ExampleUnitTest.java b/instream/src/test/java/ai/vi/samples/instream/ExampleUnitTest.java deleted file mode 100644 index 8ce0715..0000000 --- a/instream/src/test/java/ai/vi/samples/instream/ExampleUnitTest.java +++ /dev/null @@ -1,17 +0,0 @@ -package ai.vi.samples.instream; - -import org.junit.Test; - -import static org.junit.Assert.*; - -/** - * Example local unit test, which will execute on the development machine (host). - * - * @see Testing documentation - */ -public class ExampleUnitTest { - @Test - public void addition_isCorrect() throws Exception { - assertEquals(4, 2 + 2); - } -} \ No newline at end of file diff --git a/interstitial/src/test/java/ai/vi/samples/androidsamples/ExampleUnitTest.java b/interstitial/src/test/java/ai/vi/samples/androidsamples/ExampleUnitTest.java deleted file mode 100644 index 1aa1dfa..0000000 --- a/interstitial/src/test/java/ai/vi/samples/androidsamples/ExampleUnitTest.java +++ /dev/null @@ -1,17 +0,0 @@ -package ai.vi.samples.androidsamples; - -import org.junit.Test; - -import static org.junit.Assert.*; - -/** - * Example local unit test, which will execute on the development machine (host). - * - * @see Testing documentation - */ -public class ExampleUnitTest { - @Test - public void addition_isCorrect() throws Exception { - assertEquals(4, 2 + 2); - } -} \ No newline at end of file diff --git a/libs/analytics/2.0.0/countly-adapter-2.0.0.aar b/libs/analytics/2.0.0/countly-adapter-2.0.0.aar new file mode 100644 index 0000000..faa9a06 Binary files /dev/null and b/libs/analytics/2.0.0/countly-adapter-2.0.0.aar differ diff --git a/libs/mediation/2.0.0/admob-adapter-2.0.0.aar b/libs/mediation/2.0.0/admob-adapter-2.0.0.aar new file mode 100644 index 0000000..b4ac73c Binary files /dev/null and b/libs/mediation/2.0.0/admob-adapter-2.0.0.aar differ diff --git a/libs/mediation/2.0.0/facebook-adapter-2.0.0.aar b/libs/mediation/2.0.0/facebook-adapter-2.0.0.aar new file mode 100644 index 0000000..1860e53 Binary files /dev/null and b/libs/mediation/2.0.0/facebook-adapter-2.0.0.aar differ diff --git a/libs/mediation/2.0.0/mopub-adapter-2.0.0.aar b/libs/mediation/2.0.0/mopub-adapter-2.0.0.aar new file mode 100644 index 0000000..8f42b7c Binary files /dev/null and b/libs/mediation/2.0.0/mopub-adapter-2.0.0.aar differ diff --git a/libs/sdk/1.0.0/mobileads-1.0.0.aar b/libs/sdk/1.0.0/mobileads-1.0.0.aar new file mode 100644 index 0000000..b573c5b Binary files /dev/null and b/libs/sdk/1.0.0/mobileads-1.0.0.aar differ diff --git a/libs/sdk/2.0.0/mobileads-2.0.0.aar b/libs/sdk/2.0.0/mobileads-2.0.0.aar new file mode 100644 index 0000000..15cb048 Binary files /dev/null and b/libs/sdk/2.0.0/mobileads-2.0.0.aar differ diff --git a/mediationadmob/src/test/java/ai/vi/samples/mediationmopub/ExampleUnitTest.java b/mediationadmob/src/test/java/ai/vi/samples/mediationmopub/ExampleUnitTest.java deleted file mode 100644 index d0bebdd..0000000 --- a/mediationadmob/src/test/java/ai/vi/samples/mediationmopub/ExampleUnitTest.java +++ /dev/null @@ -1,17 +0,0 @@ -package ai.vi.samples.mediationmopub; - -import org.junit.Test; - -import static org.junit.Assert.*; - -/** - * Example local unit test, which will execute on the development machine (host). - * - * @see Testing documentation - */ -public class ExampleUnitTest { - @Test - public void addition_isCorrect() throws Exception { - assertEquals(4, 2 + 2); - } -} \ No newline at end of file diff --git a/mediationfacebook/src/test/java/ai/vi/samples/mediationmopub/ExampleUnitTest.java b/mediationfacebook/src/test/java/ai/vi/samples/mediationmopub/ExampleUnitTest.java deleted file mode 100644 index d0bebdd..0000000 --- a/mediationfacebook/src/test/java/ai/vi/samples/mediationmopub/ExampleUnitTest.java +++ /dev/null @@ -1,17 +0,0 @@ -package ai.vi.samples.mediationmopub; - -import org.junit.Test; - -import static org.junit.Assert.*; - -/** - * Example local unit test, which will execute on the development machine (host). - * - * @see Testing documentation - */ -public class ExampleUnitTest { - @Test - public void addition_isCorrect() throws Exception { - assertEquals(4, 2 + 2); - } -} \ No newline at end of file diff --git a/mediationmopub/src/test/java/ai/vi/samples/mediationmopub/ExampleUnitTest.java b/mediationmopub/src/test/java/ai/vi/samples/mediationmopub/ExampleUnitTest.java deleted file mode 100644 index d0bebdd..0000000 --- a/mediationmopub/src/test/java/ai/vi/samples/mediationmopub/ExampleUnitTest.java +++ /dev/null @@ -1,17 +0,0 @@ -package ai.vi.samples.mediationmopub; - -import org.junit.Test; - -import static org.junit.Assert.*; - -/** - * Example local unit test, which will execute on the development machine (host). - * - * @see Testing documentation - */ -public class ExampleUnitTest { - @Test - public void addition_isCorrect() throws Exception { - assertEquals(4, 2 + 2); - } -} \ No newline at end of file diff --git a/instream/.gitignore b/samples/externaltracker/.gitignore similarity index 100% rename from instream/.gitignore rename to samples/externaltracker/.gitignore diff --git a/samples/externaltracker/build.gradle b/samples/externaltracker/build.gradle new file mode 100644 index 0000000..7fa3ba3 --- /dev/null +++ b/samples/externaltracker/build.gradle @@ -0,0 +1,46 @@ +apply plugin: 'com.android.application' + +android { + compileSdkVersion 26 + buildToolsVersion "26.0.0" + + defaultConfig { + applicationId "ai.vi.samples.instream" + minSdkVersion 16 + targetSdkVersion 26 + versionCode 1 + versionName "1.0" + + testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner" + + } + buildTypes { + release { + minifyEnabled false + proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' + } + } +} + +repositories { + maven { url 'https://maven.vi.ai/repository/mobileads-public/' } +} + +dependencies { + androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', { + exclude group: 'com.android.support', module: 'support-annotations' + }) + compile 'com.android.support:appcompat-v7:26.+' + compile 'com.android.support.constraint:constraint-layout:1.0.2' + testCompile 'junit:junit:4.12' + + compile('ai.vi.mobileads:mobileads:2.0.0') { + transitive true + } + + compile('ai.vi.mobileads:countly-adapter:2.0.0') { + transitive true + } + + compile 'com.google.android.gms:play-services-ads:10.2.0' +} diff --git a/instream/proguard-rules.pro b/samples/externaltracker/proguard-rules.pro similarity index 100% rename from instream/proguard-rules.pro rename to samples/externaltracker/proguard-rules.pro diff --git a/samples/externaltracker/src/main/AndroidManifest.xml b/samples/externaltracker/src/main/AndroidManifest.xml new file mode 100644 index 0000000..16c0285 --- /dev/null +++ b/samples/externaltracker/src/main/AndroidManifest.xml @@ -0,0 +1,21 @@ + + + + + + + + + + + + + + \ No newline at end of file diff --git a/samples/externaltracker/src/main/java/ai/vi/samples/instream/ExternalTrackerSampleApp.java b/samples/externaltracker/src/main/java/ai/vi/samples/instream/ExternalTrackerSampleApp.java new file mode 100644 index 0000000..2b8417c --- /dev/null +++ b/samples/externaltracker/src/main/java/ai/vi/samples/instream/ExternalTrackerSampleApp.java @@ -0,0 +1,22 @@ +package ai.vi.samples.instream; + +import android.app.Application; + +import ai.vi.mobileads.adapter.countly.ViMobileAdsCountlyTracker; +import ai.vi.mobileads.api.ViSdk; +import ly.count.android.sdk.Countly; +import ly.count.android.sdk.DeviceId; + +public class ExternalTrackerSampleApp extends Application { + + @Override + public void onCreate() { + super.onCreate(); + + ViSdk.init(this); + + Countly.sharedInstance().init(this, "Server URL", "App Key", null, DeviceId.Type.ADVERTISING_ID); + + ViSdk.getInstance().registerExternalAdapter(new ViMobileAdsCountlyTracker()); + } +} diff --git a/instream/src/main/java/ai/vi/samples/instream/MainActivity.java b/samples/externaltracker/src/main/java/ai/vi/samples/instream/MainActivity.java similarity index 100% rename from instream/src/main/java/ai/vi/samples/instream/MainActivity.java rename to samples/externaltracker/src/main/java/ai/vi/samples/instream/MainActivity.java diff --git a/instream/src/main/res/layout/instream_activity.xml b/samples/externaltracker/src/main/res/layout/instream_activity.xml similarity index 100% rename from instream/src/main/res/layout/instream_activity.xml rename to samples/externaltracker/src/main/res/layout/instream_activity.xml diff --git a/instream/src/main/res/mipmap-hdpi/ic_launcher.png b/samples/externaltracker/src/main/res/mipmap-hdpi/ic_launcher.png similarity index 100% rename from instream/src/main/res/mipmap-hdpi/ic_launcher.png rename to samples/externaltracker/src/main/res/mipmap-hdpi/ic_launcher.png diff --git a/instream/src/main/res/mipmap-hdpi/ic_launcher_round.png b/samples/externaltracker/src/main/res/mipmap-hdpi/ic_launcher_round.png similarity index 100% rename from instream/src/main/res/mipmap-hdpi/ic_launcher_round.png rename to samples/externaltracker/src/main/res/mipmap-hdpi/ic_launcher_round.png diff --git a/instream/src/main/res/mipmap-mdpi/ic_launcher.png b/samples/externaltracker/src/main/res/mipmap-mdpi/ic_launcher.png similarity index 100% rename from instream/src/main/res/mipmap-mdpi/ic_launcher.png rename to samples/externaltracker/src/main/res/mipmap-mdpi/ic_launcher.png diff --git a/instream/src/main/res/mipmap-mdpi/ic_launcher_round.png b/samples/externaltracker/src/main/res/mipmap-mdpi/ic_launcher_round.png similarity index 100% rename from instream/src/main/res/mipmap-mdpi/ic_launcher_round.png rename to samples/externaltracker/src/main/res/mipmap-mdpi/ic_launcher_round.png diff --git a/instream/src/main/res/mipmap-xhdpi/ic_launcher.png b/samples/externaltracker/src/main/res/mipmap-xhdpi/ic_launcher.png similarity index 100% rename from instream/src/main/res/mipmap-xhdpi/ic_launcher.png rename to samples/externaltracker/src/main/res/mipmap-xhdpi/ic_launcher.png diff --git a/instream/src/main/res/mipmap-xhdpi/ic_launcher_round.png b/samples/externaltracker/src/main/res/mipmap-xhdpi/ic_launcher_round.png similarity index 100% rename from instream/src/main/res/mipmap-xhdpi/ic_launcher_round.png rename to samples/externaltracker/src/main/res/mipmap-xhdpi/ic_launcher_round.png diff --git a/instream/src/main/res/mipmap-xxhdpi/ic_launcher.png b/samples/externaltracker/src/main/res/mipmap-xxhdpi/ic_launcher.png similarity index 100% rename from instream/src/main/res/mipmap-xxhdpi/ic_launcher.png rename to samples/externaltracker/src/main/res/mipmap-xxhdpi/ic_launcher.png diff --git a/instream/src/main/res/mipmap-xxhdpi/ic_launcher_round.png b/samples/externaltracker/src/main/res/mipmap-xxhdpi/ic_launcher_round.png similarity index 100% rename from instream/src/main/res/mipmap-xxhdpi/ic_launcher_round.png rename to samples/externaltracker/src/main/res/mipmap-xxhdpi/ic_launcher_round.png diff --git a/instream/src/main/res/mipmap-xxxhdpi/ic_launcher.png b/samples/externaltracker/src/main/res/mipmap-xxxhdpi/ic_launcher.png similarity index 100% rename from instream/src/main/res/mipmap-xxxhdpi/ic_launcher.png rename to samples/externaltracker/src/main/res/mipmap-xxxhdpi/ic_launcher.png diff --git a/instream/src/main/res/mipmap-xxxhdpi/ic_launcher_round.png b/samples/externaltracker/src/main/res/mipmap-xxxhdpi/ic_launcher_round.png similarity index 100% rename from instream/src/main/res/mipmap-xxxhdpi/ic_launcher_round.png rename to samples/externaltracker/src/main/res/mipmap-xxxhdpi/ic_launcher_round.png diff --git a/instream/src/main/res/raw/trailer_480p.mp4 b/samples/externaltracker/src/main/res/raw/trailer_480p.mp4 similarity index 100% rename from instream/src/main/res/raw/trailer_480p.mp4 rename to samples/externaltracker/src/main/res/raw/trailer_480p.mp4 diff --git a/instream/src/main/res/values/colors.xml b/samples/externaltracker/src/main/res/values/colors.xml similarity index 100% rename from instream/src/main/res/values/colors.xml rename to samples/externaltracker/src/main/res/values/colors.xml diff --git a/samples/externaltracker/src/main/res/values/strings.xml b/samples/externaltracker/src/main/res/values/strings.xml new file mode 100644 index 0000000..ec90401 --- /dev/null +++ b/samples/externaltracker/src/main/res/values/strings.xml @@ -0,0 +1,3 @@ + + External Tracker Sample + diff --git a/instream/src/main/res/values/styles.xml b/samples/externaltracker/src/main/res/values/styles.xml similarity index 100% rename from instream/src/main/res/values/styles.xml rename to samples/externaltracker/src/main/res/values/styles.xml diff --git a/interstitial/.gitignore b/samples/instream/.gitignore similarity index 100% rename from interstitial/.gitignore rename to samples/instream/.gitignore diff --git a/instream/build.gradle b/samples/instream/build.gradle similarity index 100% rename from instream/build.gradle rename to samples/instream/build.gradle diff --git a/interstitial/proguard-rules.pro b/samples/instream/proguard-rules.pro similarity index 100% rename from interstitial/proguard-rules.pro rename to samples/instream/proguard-rules.pro diff --git a/instream/src/androidTest/java/ai/vi/samples/instream/ExampleInstrumentedTest.java b/samples/instream/src/androidTest/java/ai/vi/samples/instream/ExampleInstrumentedTest.java similarity index 100% rename from instream/src/androidTest/java/ai/vi/samples/instream/ExampleInstrumentedTest.java rename to samples/instream/src/androidTest/java/ai/vi/samples/instream/ExampleInstrumentedTest.java diff --git a/instream/src/main/AndroidManifest.xml b/samples/instream/src/main/AndroidManifest.xml similarity index 100% rename from instream/src/main/AndroidManifest.xml rename to samples/instream/src/main/AndroidManifest.xml diff --git a/instream/src/main/java/ai/vi/samples/instream/InstreamSampleApp.java b/samples/instream/src/main/java/ai/vi/samples/instream/InstreamSampleApp.java similarity index 86% rename from instream/src/main/java/ai/vi/samples/instream/InstreamSampleApp.java rename to samples/instream/src/main/java/ai/vi/samples/instream/InstreamSampleApp.java index f8ea6a9..f77b7f9 100644 --- a/instream/src/main/java/ai/vi/samples/instream/InstreamSampleApp.java +++ b/samples/instream/src/main/java/ai/vi/samples/instream/InstreamSampleApp.java @@ -4,9 +4,6 @@ import ai.vi.mobileads.api.ViSdk; -/** - * @author Alexey Yur (ay@vi.ai) - */ public class InstreamSampleApp extends Application { diff --git a/samples/instream/src/main/java/ai/vi/samples/instream/MainActivity.java b/samples/instream/src/main/java/ai/vi/samples/instream/MainActivity.java new file mode 100644 index 0000000..5fbbaba --- /dev/null +++ b/samples/instream/src/main/java/ai/vi/samples/instream/MainActivity.java @@ -0,0 +1,113 @@ +package ai.vi.samples.instream; + +import android.media.MediaPlayer; +import android.net.Uri; +import android.support.v7.app.AppCompatActivity; +import android.os.Bundle; +import android.util.Log; +import android.view.View; +import android.widget.Button; +import android.widget.VideoView; + +import ai.vi.mobileads.api.ViAdCallback; +import ai.vi.mobileads.api.ViAdError; +import ai.vi.mobileads.api.ViAdEvent; +import ai.vi.mobileads.api.ViAdPlacement; +import ai.vi.mobileads.api.ViAdView; +import ai.vi.mobileads.api.ViSdk; +import ai.vi.mobileads.api.ViVideoAd; + +public class MainActivity extends AppCompatActivity implements ViAdCallback { + + private static final String LOG_TAG = MainActivity.class.getSimpleName(); + + private String bunnyVideoPath; + + private Button playAd; + + private ViAdView viAdView; + private ViVideoAd viVideoAd; + private VideoView videoView; + + private boolean isCacheEnabled = true; + private boolean isAutoPlay = false; + + @Override + protected void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + setContentView(R.layout.instream_activity); + bunnyVideoPath = "android.resource://" + getPackageName() + "/" + R.raw.trailer_480p; + + playAd = (Button) findViewById(R.id.play_ad); + videoView = (VideoView) findViewById(R.id.video_view); + viAdView = (ViAdView) findViewById(R.id.ad_view); + + ViAdPlacement placement = ViAdPlacement.create("Instream placementId"); + viVideoAd = ViSdk.getInstance().createVideoAd(placement, viAdView, this); + viVideoAd.setCacheEnable(isCacheEnabled); + viVideoAd.loadAd(isAutoPlay); + + playAd.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View v) { + if(viVideoAd.isReady()) { + viAdView.setVisibility(View.VISIBLE); + viVideoAd.startAd(); + } + } + }); + } + + private void playVideo() { + videoView.setVideoURI(Uri.parse(bunnyVideoPath)); + videoView.setOnPreparedListener(new MediaPlayer.OnPreparedListener() { + @Override + public void onPrepared(MediaPlayer mp) { + videoView.start(); + } + }); + } + + @Override + public void onAdEvent(ViAdEvent viAdEvent) { + Log.d(LOG_TAG, viAdEvent.type.toString()); + + switch (viAdEvent.type){ + case AD_PAUSED:{ + break; + } + case AD_CLICKED: { + break; + } + case AD_CLOSE: + case AD_COMPLETED:{ + viAdView.setVisibility(View.GONE); + playVideo(); + break; + } + case AD_LOADED:{ + break; + } + case AD_RESUMED:{ + break; + } + case AD_STARTED:{ + + } + } + } + + @Override + public void onAdError(ViAdError viAdError) { + Log.d(LOG_TAG, viAdError.type.toString()); + + switch (viAdError.type){ + case AD_PLAYBACK_ERROR:{ + break; + } + case AD_LOADING_ERROR:{ + + } + } + } +} diff --git a/samples/instream/src/main/res/layout/instream_activity.xml b/samples/instream/src/main/res/layout/instream_activity.xml new file mode 100644 index 0000000..790c654 --- /dev/null +++ b/samples/instream/src/main/res/layout/instream_activity.xml @@ -0,0 +1,54 @@ + + + + + + + + + + + + + + +