Allow apps to handle ad clicked/tapped events

Issue: #3106

-------------
Created by MOE: https://github.com/google/moe
MOE_MIGRATED_REVID=163455563
This commit is contained in:
andrewlewis 2017-07-28 04:45:52 -07:00 committed by Oliver Woodman
parent 8e7a52483a
commit ad5c8af019
2 changed files with 59 additions and 1 deletions

View File

@ -61,7 +61,7 @@ public final class ImaAdsLoader implements Player.EventListener, VideoAdPlayer,
/**
* Listener for ad loader events. All methods are called on the main thread.
*/
public interface EventListener {
/* package */ interface EventListener {
/**
* Called when the ad playback state has been updated.
@ -77,6 +77,16 @@ public final class ImaAdsLoader implements Player.EventListener, VideoAdPlayer,
*/
void onLoadError(IOException error);
/**
* Called when the user clicks through an ad (for example, following a 'learn more' link).
*/
void onAdClicked();
/**
* Called when the user taps a non-clickthrough part of an ad.
*/
void onAdTapped();
}
static {
@ -337,6 +347,16 @@ public final class ImaAdsLoader implements Player.EventListener, VideoAdPlayer,
imaPausedContent = true;
pauseContentInternal();
break;
case TAPPED:
if (eventListener != null) {
eventListener.onAdTapped();
}
break;
case CLICKED:
if (eventListener != null) {
eventListener.onAdClicked();
}
break;
case CONTENT_RESUME_REQUESTED:
imaPausedContent = false;
resumeContentInternal();

View File

@ -53,6 +53,16 @@ public final class ImaAdsMediaSource implements MediaSource {
*/
void onAdLoadError(IOException error);
/**
* Called when the user clicks through an ad (for example, following a 'learn more' link).
*/
void onAdClicked();
/**
* Called when the user taps a non-clickthrough part of an ad.
*/
void onAdTapped();
}
private static final String TAG = "ImaAdsMediaSource";
@ -305,6 +315,34 @@ public final class ImaAdsMediaSource implements MediaSource {
});
}
@Override
public void onAdClicked() {
if (eventHandler != null && eventListener != null) {
eventHandler.post(new Runnable() {
@Override
public void run() {
if (!released) {
eventListener.onAdClicked();
}
}
});
}
}
@Override
public void onAdTapped() {
if (eventHandler != null && eventListener != null) {
eventHandler.post(new Runnable() {
@Override
public void run() {
if (!released) {
eventListener.onAdTapped();
}
}
});
}
}
}
}