Skip to content

Commit

Permalink
Updated Release Notes and SDK version - v5.1.1
Browse files Browse the repository at this point in the history
  • Loading branch information
avohraa committed Feb 25, 2019
1 parent 91c60ab commit 26434d7
Show file tree
Hide file tree
Showing 8 changed files with 350 additions and 75 deletions.
8 changes: 8 additions & 0 deletions RELEASE-NOTES.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,11 @@
## 5.1.1

### New Features
+ MS-3220: Added Countdown Timer to Interstitial Ads

### Bug Fixes
+ MS-3755: Fixed Assertion Error that occurred while initializing Settings

## 5.1

### Mediation partner upgrades/changes
Expand Down
2 changes: 1 addition & 1 deletion sdk/build.gradle
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// Project properties
version = "5.1"
version = "5.1.1"
group='com.appnexus.opensdk'

// Android build
Expand Down
14 changes: 7 additions & 7 deletions sdk/src/com/appnexus/opensdk/AdView.java
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@
import android.view.ViewGroup;
import android.webkit.WebView;
import android.widget.FrameLayout;
import android.widget.ImageButton;

import com.appnexus.opensdk.ut.UTConstants;
import com.appnexus.opensdk.ut.UTRequestParameters;
Expand Down Expand Up @@ -358,7 +357,7 @@ protected void setShouldResizeParent(boolean shouldResizeParent) {
* MRAID functions and variables
*/
boolean mraid_is_closing = false;
ImageButton close_button;
CircularProgressBar close_button;
@SuppressLint("StaticFieldLeak")
static FrameLayout mraidFullscreenContainer;
@SuppressLint("StaticFieldLeak")
Expand Down Expand Up @@ -427,7 +426,8 @@ protected void mraidFullscreenExpand(final MRAIDImplementation caller, boolean u
fslayout.addView(caller.owner);

if (close_button == null) {
close_button = ViewUtil.createCloseButton(this.getContext(), use_custom_close);
close_button = ViewUtil.createCircularProgressBar(this.getContext());
ViewUtil.showCloseButton(close_button, use_custom_close);
close_button.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Expand Down Expand Up @@ -461,7 +461,8 @@ void expand(int w, int h, boolean custom_close,
MRAIDChangeSize(w, h);

// Add a stock close_button button to the top right corner
close_button = ViewUtil.createCloseButton(this.getContext(), custom_close);
close_button = ViewUtil.createCircularProgressBar(this.getContext());
ViewUtil.showCloseButton(close_button, custom_close);
FrameLayout.LayoutParams blp = (LayoutParams) close_button.getLayoutParams();

// place the close button at the top right of the adview if it isn't fullscreen
Expand Down Expand Up @@ -505,7 +506,7 @@ void resize(int w, int h, int offset_x, int offset_y, MRAIDImplementation.CUSTOM
buttonPxSideLength = (int) (50 * scale);
}

close_button = new ImageButton(this.getContext()) {
close_button = new CircularProgressBar(this.getContext(), null, android.R.attr.indeterminateOnly) {

@SuppressWarnings("deprecation")
@SuppressLint({"NewApi", "DrawAllocation"})
Expand Down Expand Up @@ -570,8 +571,7 @@ public void run() {
}
});

close_button.setImageDrawable(getResources().getDrawable(
android.R.drawable.ic_menu_close_clear_cancel));
ViewUtil.showCloseButton(close_button, false);
}
}
};
Expand Down
139 changes: 139 additions & 0 deletions sdk/src/com/appnexus/opensdk/CircularProgressBar.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,139 @@
package com.appnexus.opensdk;

import android.content.Context;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
import android.graphics.Paint.Style;
import android.graphics.RectF;
import android.graphics.Typeface;
import android.os.Build;
import android.text.Html;
import android.text.TextUtils;
import android.util.AttributeSet;
import android.view.View;
import android.widget.ProgressBar;

import com.appnexus.opensdk.utils.ViewUtil;

public class CircularProgressBar extends ProgressBar{

private static final double DEFAULT_STROKE_WIDTH = 2.5;
private static final int TITLE_FONT_SIZE = 14;
private static final String CLOSE_X = "×";
private int GRAY = Color.parseColor("#787878");
private int WHITE = Color.parseColor("#ffffff");
private static final int CROSS_X_FONT_SIZE = 24;

private String title = "";

private int strokeWidth = 0;

private final RectF circleBounds = new RectF();
private final Paint progressColorPaint = new Paint();
private final Paint strokeColorPaint = new Paint();
private final Paint backgroundColorPaint = new Paint();
private final Paint titlePaint = new Paint();

public CircularProgressBar(Context context) {
super(context);
initializeCountdownView(null, 0);
}

public CircularProgressBar(Context context, AttributeSet attrs) {
super(context, attrs);
initializeCountdownView(attrs, 0);
}

public CircularProgressBar(Context context, AttributeSet attrs, int defStyle) {
super(context, attrs, defStyle);
initializeCountdownView(attrs, defStyle);
}

public void initializeCountdownView(AttributeSet attrs, int style){
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) {
setLayerType(View.LAYER_TYPE_SOFTWARE, null);
}

strokeWidth = ViewUtil.getValueInPixel(this.getContext(), DEFAULT_STROKE_WIDTH) + 1;

progressColorPaint.setColor(WHITE);
strokeColorPaint.setColor(GRAY);
backgroundColorPaint.setColor(WHITE);
titlePaint.setColor(GRAY);

progressColorPaint.setAntiAlias(true);
progressColorPaint.setStyle(Style.STROKE);
progressColorPaint.setStrokeWidth(strokeWidth);

strokeColorPaint.setAntiAlias(true);
strokeColorPaint.setStyle(Style.STROKE);
strokeColorPaint.setStrokeWidth(strokeWidth);

backgroundColorPaint.setAntiAlias(true);
backgroundColorPaint.setStyle(Style.FILL);
backgroundColorPaint.setStrokeWidth(strokeWidth);

titlePaint.setTextSize(TITLE_FONT_SIZE);
titlePaint.setStyle(Style.FILL);
titlePaint.setAntiAlias(true);
titlePaint.setTypeface(Typeface.create(Typeface.MONOSPACE, Typeface.BOLD));
}

@Override
protected synchronized void onDraw(Canvas canvas) {
canvas.drawArc(circleBounds, 0, 360, false, backgroundColorPaint);
canvas.drawArc(circleBounds, 0, 360, false, strokeColorPaint);
float scale = getMax() > 0 ? (float)getProgress()/getMax() * 360: 0;
canvas.drawArc(circleBounds, 270, -scale, false, progressColorPaint);

if (!TextUtils.isEmpty(title)){
int x = (int)(getMeasuredWidth()/2 - titlePaint.measureText(title) / 2);
int y = getMeasuredHeight()/2;

float titleHeight = Math.abs(titlePaint.descent() + titlePaint.ascent());
y += titleHeight/ 2;
canvas.drawText(title, x, y, titlePaint);
}
super.onDraw(canvas);
}

@Override
protected void onMeasure(final int widthMeasureSpec, final int heightMeasureSpec) {
final int height = getDefaultSize(getSuggestedMinimumHeight(), heightMeasureSpec);
final int width = getDefaultSize(getSuggestedMinimumWidth(), widthMeasureSpec);
final int min = Math.min(width, height);
setMeasuredDimension(min + 2 * strokeWidth, min + 2 * strokeWidth);

circleBounds.set(strokeWidth, strokeWidth, min + strokeWidth, min + strokeWidth);
}

@Override
public synchronized void setProgress(int progress) {
super.setProgress(progress);
invalidate();
}

public synchronized void setTitle(String title){
if(title.equalsIgnoreCase("X")){
this.title = Html.fromHtml(CLOSE_X).toString();
titlePaint.setTextSize(ViewUtil.getValueInPixel(this.getContext(), CROSS_X_FONT_SIZE));
}else{
this.title = title;
titlePaint.setTextSize(ViewUtil.getValueInPixel(this.getContext(), TITLE_FONT_SIZE));
}
invalidate();
}


public String getTitle(){
return title;
}

public void setTransparent() {
GRAY = Color.parseColor("#00000000");
WHITE = Color.parseColor("#00000000");
initializeCountdownView(null, 0);
invalidate();
}
}
117 changes: 70 additions & 47 deletions sdk/src/com/appnexus/opensdk/InterstitialAdActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,28 +19,27 @@
import android.app.Activity;
import android.content.MutableContextWrapper;
import android.os.Handler;
import android.os.Message;
import android.view.View;
import android.view.ViewGroup;
import android.webkit.WebView;
import android.widget.FrameLayout;
import android.widget.ImageButton;

import com.appnexus.opensdk.utils.ANCountdownTimer;
import com.appnexus.opensdk.utils.Clog;
import com.appnexus.opensdk.utils.Settings;
import com.appnexus.opensdk.utils.ViewUtil;

import java.lang.ref.WeakReference;

class InterstitialAdActivity implements AdActivity.AdActivityImplementation {
private Activity adActivity;
private AdWebView webView;

private FrameLayout layout;
private long now;
private InterstitialAdView adView;
private static final int CLOSE_BUTTON_MESSAGE_ID = 8000;
private ImageButton closeButton;
public static final int COUNTDOWN_INTERVAL = 1;
private CircularProgressBar countdownWidget;
private ANCountdownTimer countdownTimer;
private Handler autoDismissHandler;

public InterstitialAdActivity(Activity adActivity) {
this.adActivity = adActivity;
Expand All @@ -57,29 +56,82 @@ public void create() {
System.currentTimeMillis());
setIAdView(InterstitialAdView.INTERSTITIALADVIEW_TO_USE);

// Add a close button after a delay.
int dismissAdDelay = adActivity.getIntent().getIntExtra(
InterstitialAdView.INTENT_KEY_AUTODISMISS_DELAY,
-1);
int dismissAdInterval = dismissAdDelay * 1000;


int closeButtonDelay = adActivity.getIntent().getIntExtra(
InterstitialAdView.INTENT_KEY_CLOSE_BUTTON_DELAY,
Settings.DEFAULT_INTERSTITIAL_CLOSE_BUTTON_DELAY);

displayCountdownWidget(dismissAdInterval, closeButtonDelay);

new CloseButtonHandler(this).sendEmptyMessageDelayed(CLOSE_BUTTON_MESSAGE_ID, closeButtonDelay);

int dismissAdDelay = adActivity.getIntent().getIntExtra(
InterstitialAdView.INTENT_KEY_AUTODISMISS_DELAY,
-1);

if (adView != null && dismissAdDelay > -1) {
final Handler handler = new Handler();
handler.postDelayed(new Runnable() {
autoDismissHandler = new Handler();
autoDismissHandler.postDelayed(new Runnable() {
@Override
public void run() {
dismissInterstitial();
}
}, dismissAdDelay * 1000);
}, dismissAdInterval);
}
}

private void displayCountdownWidget(int dismissAdInterval, int closeButtonDelay) {

// If the ad will auto-dismiss before the closeButtonDelay is hit, then show the countdown timer based on dismissAdInterval
if ((dismissAdInterval > 0) && dismissAdInterval <= closeButtonDelay)
closeButtonDelay = dismissAdInterval;
Clog.e("displayCountdownWidget", closeButtonDelay + "");

countdownWidget = ViewUtil.createCircularProgressBar(adActivity);
layout.addView(countdownWidget);
countdownWidget.setMax(closeButtonDelay);
countdownWidget.setProgress(closeButtonDelay);
countdownWidget.setVisibility(View.VISIBLE);
countdownWidget.bringToFront();

startCountdownTimer(closeButtonDelay);
}

private void startCountdownTimer(final long closeButtonDelay) {
countdownTimer = new ANCountdownTimer(closeButtonDelay, COUNTDOWN_INTERVAL) {
@Override
public void onTick(long leftTimeInMilliseconds) {
if (countdownWidget != null) {
countdownWidget.setProgress((int) leftTimeInMilliseconds);
int seconds = (int) (leftTimeInMilliseconds / 1000) + 1;
countdownWidget.setTitle(String.valueOf(seconds));
}
}

@Override
public void onFinish() {
showCloseButton();
}
};
countdownTimer.startTimer();
}

private void showCloseButton() {
if (countdownWidget != null) {
if (!webView.isMRAIDUseCustomClose()) {
countdownWidget.setProgress(0);
countdownWidget.setTitle("X");
} else {
countdownWidget.setTransparent();
}
countdownWidget.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
dismissInterstitial();
}
});
}
}

@Override
public void backPressed() {
Expand All @@ -105,7 +157,6 @@ public void destroy() {

@Override
public void interacted() {
addCloseButton();
}


Expand Down Expand Up @@ -159,43 +210,15 @@ private void setIAdView(InterstitialAdView av) {
layout.addView(webView);
}

// add the close button if it hasn't been added already
private void addCloseButton() {
if ((layout == null) || (closeButton != null)) return;
boolean customClose = false;
if (webView != null) {
customClose = webView.isMRAIDUseCustomClose();
}
closeButton = ViewUtil.createCloseButton(adActivity, customClose);
closeButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
dismissInterstitial();
}
});
layout.addView(closeButton);
}

private void dismissInterstitial() {
if (adActivity != null) {
if (adView != null && adView.getAdDispatcher() != null) {
adView.getAdDispatcher().onAdCollapsed();
}
if (autoDismissHandler != null) {
autoDismissHandler.removeCallbacksAndMessages(null);
}
adActivity.finish();
}
}

static class CloseButtonHandler extends Handler {
WeakReference<InterstitialAdActivity> weakReferenceIAA;

public CloseButtonHandler(InterstitialAdActivity a) {
weakReferenceIAA = new WeakReference<InterstitialAdActivity>(a);
}

@Override
public void handleMessage(Message msg) {
InterstitialAdActivity iAA = weakReferenceIAA.get();
if (msg.what == CLOSE_BUTTON_MESSAGE_ID && iAA != null) iAA.addCloseButton();
}
}
}
Loading

0 comments on commit 26434d7

Please sign in to comment.