Skip to content

Commit

Permalink
Updated samples. Added test placementIds.
Browse files Browse the repository at this point in the history
  • Loading branch information
ay-vi committed Jan 19, 2018
1 parent a520081 commit 7d0d711
Show file tree
Hide file tree
Showing 86 changed files with 604 additions and 120 deletions.
23 changes: 23 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,27 @@ public class MyApplication extends Application {
}
```

For development you can enable debug mode by adding ```ViOptions``` to ```ViSdk.init()``` method:

```java
import android.app.Application;
import ai.vi.mobileads.api.ViSdk;
import ai.vi.mobileads.api.ViOptions;

public class MyApplication extends Application {

@Override
public void onCreate() {
super.onCreate();

ViOptions viOptions = new ViOptions();
viOptions.setDebuggable(true);

ViSdk.init(this, viOptions);
}
}
```

If you are an SDK rather than app developer, you should initialize us as soon as you are able to access the
Application object.

Expand Down Expand Up @@ -373,3 +394,5 @@ import ai.vi.mobileads.adapter.countly.ViMobileAdsCountlyTracker;
ViSdk.getInstance().registerExternalAdapter(new ViMobileAdsCountlyTracker());
```

# Documentation
Java API docs of can be found [here](https://cdn.rawgit.com/vi-ai/vi-android-sdk/2d641d21/libs/sdk/2.0.0/docs/index.html)
4 changes: 0 additions & 4 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ buildscript {
repositories {
jcenter()
}
ext.kotlin_version = '1.1.1'

dependencies {
classpath 'com.android.tools.build:gradle:2.3.3'
Expand All @@ -19,9 +18,6 @@ buildscript {
allprojects {
repositories {
jcenter()
flatDir {
dirs 'libs'
}
}
}

Expand Down
2 changes: 1 addition & 1 deletion samples/externaltracker/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ android {
buildToolsVersion "26.0.0"

defaultConfig {
applicationId "ai.vi.samples.instream"
applicationId "ai.vi.samples.externaltracker"
minSdkVersion 16
targetSdkVersion 26
versionCode 1
Expand Down
4 changes: 2 additions & 2 deletions samples/externaltracker/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,13 @@
package="ai.vi.samples.instream">

<application android:allowBackup="true"
android:name=".ExternalTrackerSampleApp"
android:name="ai.vi.samples.externaltracker.ExternalTrackerSampleApp"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="@style/AppTheme">
<activity android:name=".MainActivity">
<activity android:name="ai.vi.samples.externaltracker.MainActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />

Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
package ai.vi.samples.instream;
package ai.vi.samples.externaltracker;

import android.app.Application;

import ai.vi.mobileads.adapter.countly.ViMobileAdsCountlyTracker;
import ai.vi.mobileads.api.ViOptions;
import ai.vi.mobileads.api.ViSdk;
import ly.count.android.sdk.Countly;
import ly.count.android.sdk.DeviceId;
Expand All @@ -13,9 +14,12 @@ public class ExternalTrackerSampleApp extends Application {
public void onCreate() {
super.onCreate();

ViSdk.init(this);
ViOptions viOptions = new ViOptions();
viOptions.setDebuggable(true); //Remove for production

Countly.sharedInstance().init(this, "Server URL", "App Key", null, DeviceId.Type.ADVERTISING_ID);
ViSdk.init(this, viOptions);

Countly.sharedInstance().init(this, "Server URL", "App Key", null, DeviceId.Type.ADVERTISING_ID); //Before launch please fill correct data

ViSdk.getInstance().registerExternalAdapter(new ViMobileAdsCountlyTracker());
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package ai.vi.samples.instream;
package ai.vi.samples.externaltracker;

import android.media.MediaPlayer;
import android.net.Uri;
Expand All @@ -16,6 +16,7 @@
import ai.vi.mobileads.api.ViAdView;
import ai.vi.mobileads.api.ViSdk;
import ai.vi.mobileads.api.ViVideoAd;
import ai.vi.samples.instream.R;

public class MainActivity extends AppCompatActivity implements ViAdCallback {

Expand All @@ -42,7 +43,9 @@ protected void onCreate(Bundle savedInstanceState) {
videoView = (VideoView) findViewById(R.id.video_view);
viAdView = (ViAdView) findViewById(R.id.ad_view);

ViAdPlacement placement = ViAdPlacement.create("Instream placementId");
String placementId = "pltuaisg4nafb0tdac2"; //This placement is for test only, to receive personal placementId please register at https://vi.ai/publisher-video-monetization/

ViAdPlacement placement = ViAdPlacement.create(placementId);
viVideoAd = ViSdk.getInstance().createVideoAd(placement, viAdView, this);
viVideoAd.setCacheEnable(isCacheEnabled);
viVideoAd.loadAd(isAutoPlay);
Expand Down
Binary file modified samples/externaltracker/src/main/res/mipmap-hdpi/ic_launcher.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified samples/externaltracker/src/main/res/mipmap-mdpi/ic_launcher.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified samples/externaltracker/src/main/res/mipmap-xhdpi/ic_launcher.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified samples/externaltracker/src/main/res/mipmap-xxhdpi/ic_launcher.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
3 changes: 2 additions & 1 deletion samples/instream/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="@style/AppTheme">
<activity android:name=".MainActivity">
<activity android:name=".MainActivity"
android:configChanges="orientation|screenSize">
<intent-filter>
<action android:name="android.intent.action.MAIN" />

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import android.app.Application;

import ai.vi.mobileads.api.ViOptions;
import ai.vi.mobileads.api.ViSdk;


Expand All @@ -11,6 +12,9 @@ public class InstreamSampleApp extends Application {
public void onCreate() {
super.onCreate();

ViSdk.init(this);
ViOptions viOptions = new ViOptions();
viOptions.setDebuggable(true); //Remove for production

ViSdk.init(this, viOptions);
}
}
Original file line number Diff line number Diff line change
@@ -1,12 +1,17 @@
package ai.vi.samples.instream;

import android.content.res.Configuration;
import android.media.MediaPlayer;
import android.net.Uri;
import android.support.constraint.ConstraintLayout;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.view.ViewTreeObserver;
import android.widget.Button;
import android.widget.RelativeLayout;
import android.widget.Toast;
import android.widget.VideoView;

import ai.vi.mobileads.api.ViAdCallback;
Expand All @@ -24,10 +29,12 @@ public class MainActivity extends AppCompatActivity implements ViAdCallback {
private String bunnyVideoPath;

private Button playAd;
private Button loadAd;

private ViAdView viAdView;
private ViVideoAd viVideoAd;
private VideoView videoView;
private RelativeLayout videoHolder;

private boolean isCacheEnabled = true;
private boolean isAutoPlay = false;
Expand All @@ -39,37 +46,62 @@ protected void onCreate(Bundle savedInstanceState) {
bunnyVideoPath = "android.resource://" + getPackageName() + "/" + R.raw.trailer_480p;

playAd = (Button) findViewById(R.id.play_ad);
loadAd = (Button) findViewById(R.id.load_ad);
videoView = (VideoView) findViewById(R.id.video_view);
viAdView = (ViAdView) findViewById(R.id.ad_view);
videoHolder = (RelativeLayout) findViewById(R.id.video_holder);

ViAdPlacement placement = ViAdPlacement.create("Instream placementId");
String placementId = "pltdaysgxk6bliwd3n1"; //This placement is for test only, to receive personal placementId please register at https://vi.ai/publisher-video-monetization/

ViAdPlacement placement = ViAdPlacement.create(placementId);
viVideoAd = ViSdk.getInstance().createVideoAd(placement, viAdView, this);
viVideoAd.setCacheEnable(isCacheEnabled);
viVideoAd.loadAd(isAutoPlay);

videoView.setVideoURI(Uri.parse(bunnyVideoPath));
playAd.setEnabled(false);

loadAd.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
if(!viVideoAd.isReady() && !viVideoAd.isLoading()) {
viVideoAd.loadAd(isAutoPlay);
} else {
Toast.makeText(MainActivity.this, "Ad is ready or loading", Toast.LENGTH_SHORT).show();
}
}
});

playAd.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
if(viVideoAd.isReady()) {
playAd.setEnabled(false);
if(videoView.isPlaying()) {
videoView.pause();
}

viAdView.setVisibility(View.VISIBLE);
viVideoAd.startAd();
} else {
Toast.makeText(MainActivity.this, "Ad not loaded", Toast.LENGTH_SHORT).show();
}
}
});

handleVideoPlayback();
}

private void playVideo() {
videoView.setVideoURI(Uri.parse(bunnyVideoPath));
videoView.setOnPreparedListener(new MediaPlayer.OnPreparedListener() {
@Override
public void onPrepared(MediaPlayer mp) {
videoView.start();
}
});
private void handleVideoPlayback() {
if(videoView.getCurrentPosition() > videoView.getDuration()) {
videoView.seekTo(0);
}

videoView.start();
}

@Override
public void onAdEvent(ViAdEvent viAdEvent) {
Toast.makeText(MainActivity.this, "ViAdEvent: " + viAdEvent.type, Toast.LENGTH_SHORT).show();
Log.d(LOG_TAG, viAdEvent.type.toString());

switch (viAdEvent.type){
Expand All @@ -82,10 +114,11 @@ public void onAdEvent(ViAdEvent viAdEvent) {
case AD_CLOSE:
case AD_COMPLETED:{
viAdView.setVisibility(View.GONE);
playVideo();
handleVideoPlayback();
break;
}
case AD_LOADED:{
playAd.setEnabled(true);
break;
}
case AD_RESUMED:{
Expand All @@ -99,6 +132,7 @@ public void onAdEvent(ViAdEvent viAdEvent) {

@Override
public void onAdError(ViAdError viAdError) {
Toast.makeText(MainActivity.this, "ViAdError: " + viAdError.message, Toast.LENGTH_SHORT).show();
Log.d(LOG_TAG, viAdError.type.toString());

switch (viAdError.type){
Expand All @@ -110,4 +144,41 @@ public void onAdError(ViAdError viAdError) {
}
}
}

@Override
public void onConfigurationChanged(final Configuration newConfig) {
super.onConfigurationChanged(newConfig);
handleAdViewSize(newConfig.orientation);
}

private void handleAdViewSize(final int orientation){
final View parentView = (View) videoHolder.getParent();
final int oldWidht = parentView.getWidth();
final int oldHeight = parentView.getHeight();

videoHolder.getViewTreeObserver().addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() {
@Override
public void onGlobalLayout() {
if(oldWidht == parentView.getWidth() && oldHeight == parentView.getHeight()){
return;
}

videoHolder.getViewTreeObserver().removeOnGlobalLayoutListener(this);

ConstraintLayout.LayoutParams clp = (ConstraintLayout.LayoutParams) videoHolder.getLayoutParams();
final View parentView = (View) videoHolder.getParent();

float parentAspect = (float) parentView.getWidth() / (float) parentView.getHeight();
float fullHdAspect = 16f / 9f;

if(orientation == Configuration.ORIENTATION_LANDSCAPE && parentAspect > fullHdAspect){
clp.dimensionRatio = "W, 16:9";
} else {
clp.dimensionRatio = "H, 16:9";
}

videoHolder.setLayoutParams(clp);
}
});
}
}
14 changes: 12 additions & 2 deletions samples/instream/src/main/res/layout/instream_activity.xml
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,10 @@
android:id="@+id/video_holder"
android:layout_width="0dp"
android:layout_height="0dp"
android:layout_marginTop="8dp"
android:layout_marginTop="0dp"
android:background="@color/colorPrimary"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintDimensionRatio="H,16:9"
app:layout_constraintHorizontal_bias="0.0"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toTopOf="parent">
Expand Down Expand Up @@ -49,6 +48,17 @@
app:layout_constraintTop_toTopOf="parent"
android:layout_marginStart="8dp" />

<Button
android:id="@+id/load_ad"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="8dp"
android:layout_marginTop="8dp"
android:text="Load ad"
app:layout_constraintLeft_toRightOf="@id/play_ad"
app:layout_constraintTop_toTopOf="parent"
android:layout_marginStart="8dp" />

</android.support.constraint.ConstraintLayout>

</android.support.v4.widget.DrawerLayout>
Binary file modified samples/instream/src/main/res/mipmap-hdpi/ic_launcher.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified samples/instream/src/main/res/mipmap-hdpi/ic_launcher_round.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified samples/instream/src/main/res/mipmap-mdpi/ic_launcher.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified samples/instream/src/main/res/mipmap-mdpi/ic_launcher_round.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified samples/instream/src/main/res/mipmap-xhdpi/ic_launcher.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified samples/instream/src/main/res/mipmap-xhdpi/ic_launcher_round.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified samples/instream/src/main/res/mipmap-xxhdpi/ic_launcher.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified samples/instream/src/main/res/mipmap-xxxhdpi/ic_launcher.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

import android.app.Application;

import ai.vi.mobileads.api.ViExternalAdTracker;
import ai.vi.mobileads.api.ViOptions;
import ai.vi.mobileads.api.ViSdk;


Expand All @@ -12,6 +12,9 @@ public class InterstitialSampleApp extends Application {
public void onCreate() {
super.onCreate();

ViSdk.init(this);
ViOptions viOptions = new ViOptions();
viOptions.setDebuggable(true); //Remove for production

ViSdk.init(this, viOptions);
}
}
Loading

0 comments on commit 7d0d711

Please sign in to comment.