Wolves Themes v1.0版本的 MD5 值为:cddc92b47f6b7c4a195c9625507eb51c
以下内容为反编译后的 VungleActivity.java 源代码,内容仅作参考
package com.vungle.warren.ui;
import android.annotation.SuppressLint;
import android.app.Activity;
import android.app.AlertDialog;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent;
import android.content.IntentFilter;
import android.content.res.Configuration;
import android.content.res.Resources;
import android.graphics.Bitmap;
import android.graphics.Rect;
import android.media.AudioManager;
import android.media.MediaPlayer;
import android.net.Uri;
import android.os.Bundle;
import android.os.Handler;
import android.os.PersistableBundle;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.text.TextUtils;
import android.util.DisplayMetrics;
import android.util.Log;
import android.util.TypedValue;
import android.view.ContextThemeWrapper;
import android.view.TouchDelegate;
import android.view.View;
import android.view.ViewTreeObserver;
import android.webkit.WebView;
import android.widget.ImageView;
import android.widget.ProgressBar;
import android.widget.RelativeLayout;
import android.widget.VideoView;
import com.google.android.gms.common.util.CrashUtils;
import com.ironsource.sdk.constants.Constants;
import com.moat.analytics.mobile.vng.ReactiveVideoTracker;
import com.tapjoy.TJAdUnitConstants;
import com.tonyodev.fetch.FetchConst;
import com.vungle.warren.error.VungleException;
import com.vungle.warren.model.Advertisement;
import com.vungle.warren.persistence.GraphicDesigner;
import com.vungle.warren.persistence.PepperidgeFarm;
import com.vungle.warren.presenter.AdvertisementPresenter;
import com.vungle.warren.presenter.AdvertisementPresenterFactory;
import com.vungle.warren.utility.ViewUtility;
import java.net.URISyntaxException;
import java.util.Locale;
public class VungleActivity extends Activity implements AdView, MediaPlayer.OnPreparedListener, MediaPlayer.OnErrorListener {
protected static final double NINE_BY_SIXTEEN_ASPECT_RATIO = 0.5625d;
private static final String PLACEMENT_EXTRA = "placement";
private static final String TAG = "VungleActivity";
private static AdvertisementPresenter.EventListener bus;
private BroadcastReceiver broadcastReciever;
private ImageView closeButton;
private ImageView ctaOverlay;
private AlertDialog dialog;
private MediaPlayer mediaPlayer;
private ImageView muteButton;
private boolean pendingPause;
private AdvertisementPresenter presenter;
private ImageView privacyOverlay;
private ProgressBar progressBar;
private Runnable reportProgress;
private VideoView videoView;
private ReactiveVideoTracker viewabilityTracker;
private WebView webView;
private Handler handler = new Handler();
private int videoPosition = 0;
private boolean muted = false;
private boolean released = false;
public static void setEventListener(AdvertisementPresenter.EventListener listener) {
bus = listener;
}
public static Intent createIntent(@NonNull String placementID, @NonNull Context context) {
Intent ret = new Intent(context, VungleActivity.class);
ret.addFlags(CrashUtils.ErrorDialogData.BINDER_CRASH);
ret.putExtra(PLACEMENT_EXTRA, placementID);
return ret;
}
@Override
@SuppressLint({"SetJavaScriptEnabled"})
protected void onCreate(@Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
requestWindowFeature(1);
Resources resources = getResources();
RelativeLayout parentLayout = new RelativeLayout(this);
RelativeLayout.LayoutParams matchParentLayoutParams = new RelativeLayout.LayoutParams(-1, -1);
parentLayout.setLayoutParams(matchParentLayoutParams);
this.videoView = new VideoView(this);
RelativeLayout.LayoutParams videoViewLayoutParams = new RelativeLayout.LayoutParams(-1, -1);
videoViewLayoutParams.addRule(13);
this.videoView.setLayoutParams(videoViewLayoutParams);
parentLayout.addView(this.videoView, videoViewLayoutParams);
this.webView = new WebView(this);
this.webView.setLayoutParams(matchParentLayoutParams);
parentLayout.addView(this.webView, matchParentLayoutParams);
this.progressBar = new ProgressBar(this, null, 16842872);
int progressBarHeight = (int) TypedValue.applyDimension(1, 4.0f, resources.getDisplayMetrics());
RelativeLayout.LayoutParams progressBarLayoutParams = new RelativeLayout.LayoutParams(-1, progressBarHeight);
progressBarLayoutParams.addRule(12);
this.progressBar.setLayoutParams(progressBarLayoutParams);
this.progressBar.setMax(100);
this.progressBar.setIndeterminate(false);
this.progressBar.setVisibility(4);
parentLayout.addView(this.progressBar);
int imageViewDimension = (int) TypedValue.applyDimension(1, 24.0f, resources.getDisplayMetrics());
RelativeLayout.LayoutParams imageViewLayoutParams = new RelativeLayout.LayoutParams(imageViewDimension, imageViewDimension);
int imageViewMargin = (int) TypedValue.applyDimension(1, 12.0f, resources.getDisplayMetrics());
imageViewLayoutParams.setMargins(imageViewMargin, imageViewMargin, imageViewMargin, imageViewMargin);
this.muteButton = new ImageView(this);
this.muteButton.setImageBitmap(ViewUtility.getBitmap(ViewUtility.Asset.unMute, this));
this.muteButton.setLayoutParams(imageViewLayoutParams);
this.muteButton.setVisibility(8);
parentLayout.addView(this.muteButton);
RelativeLayout.LayoutParams closeLayoutParams = new RelativeLayout.LayoutParams(imageViewDimension, imageViewDimension);
closeLayoutParams.setMargins(imageViewMargin, imageViewMargin, imageViewMargin, imageViewMargin);
this.closeButton = new ImageView(this);
this.closeButton.setImageBitmap(ViewUtility.getBitmap(ViewUtility.Asset.close, this));
closeLayoutParams.addRule(11);
this.closeButton.setLayoutParams(closeLayoutParams);
this.closeButton.setVisibility(8);
parentLayout.addView(this.closeButton);
RelativeLayout.LayoutParams ctaOverlayLayoutParams = new RelativeLayout.LayoutParams(imageViewDimension, imageViewDimension);
ctaOverlayLayoutParams.addRule(12);
ctaOverlayLayoutParams.addRule(11);
ctaOverlayLayoutParams.setMargins(imageViewMargin, imageViewMargin, imageViewMargin, imageViewMargin);
this.ctaOverlay = new ImageView(this);
this.ctaOverlay.setLayoutParams(ctaOverlayLayoutParams);
this.ctaOverlay.setVisibility(8);
parentLayout.addView(this.ctaOverlay);
RelativeLayout.LayoutParams privacyLayoutParams = new RelativeLayout.LayoutParams(imageViewDimension, imageViewDimension);
privacyLayoutParams.addRule(12);
privacyLayoutParams.addRule(9);
privacyLayoutParams.setMargins(imageViewMargin, imageViewMargin, imageViewMargin, imageViewMargin);
this.privacyOverlay = new ImageView(this);
this.privacyOverlay.setLayoutParams(privacyLayoutParams);
this.privacyOverlay.setVisibility(8);
parentLayout.addView(this.privacyOverlay);
setContentView(parentLayout, matchParentLayoutParams);
String user = getIntent().hasExtra("userID") ? getIntent().getStringExtra("userID") : null;
this.presenter = AdvertisementPresenterFactory.getAdRenderer(getIntent().getStringExtra(PLACEMENT_EXTRA), new PepperidgeFarm(this), new GraphicDesigner(), savedInstanceState, user);
if (this.presenter == null) {
if (bus != null) {
bus.onError(new VungleException(10));
}
finish();
return;
}
this.presenter.setEventListener(bus);
this.presenter.attach(this);
this.presenter.prepare();
prepare(savedInstanceState);
}
private void prepare(Bundle savedInstanceState) {
this.videoView.setOnPreparedListener(this);
this.webView.setWebViewClient(this.presenter.getWebViewClient());
this.webView.getSettings().setJavaScriptEnabled(true);
this.webView.addJavascriptInterface(new JavascriptBridge(this.presenter), Constants.JAVASCRIPT_INTERFACE_NAME);
this.videoView.setVisibility(8);
this.webView.setVisibility(8);
}
private void connectBroadcastReceiver() {
this.broadcastReciever = new BroadcastReceiver() {
@Override
public void onReceive(Context context, Intent intent) {
String command = intent.getStringExtra(TJAdUnitConstants.String.COMMAND);
char c = 65535;
switch (command.hashCode()) {
case -482896367:
if (command.equals("closeFlex")) {
c = 0;
break;
}
break;
}
switch (c) {
case 0:
String placementID = intent.getStringExtra(VungleActivity.PLACEMENT_EXTRA);
if (VungleActivity.this.presenter.handleExit(placementID)) {
VungleActivity.this.close();
return;
}
return;
default:
throw new IllegalArgumentException("No such command " + command);
}
}
};
registerReceiver(this.broadcastReciever, new IntentFilter("AdvertisementBus"));
}
@Override
protected void onStart() {
connectBroadcastReceiver();
super.onStart();
}
@Override
protected void onRestart() {
super.onRestart();
if (this.videoView != null) {
this.videoView.seekTo(this.videoPosition);
}
setupPlayerProgressBar();
}
@Override
protected void onStop() {
if (this.reportProgress != null) {
this.handler.removeCallbacks(this.reportProgress);
}
unregisterReceiver(this.broadcastReciever);
super.onStop();
}
@Override
protected void onPause() {
super.onPause();
if (!this.released && this.videoView.isPlaying()) {
this.videoView.pause();
this.videoPosition = this.videoView.getCurrentPosition();
}
this.presenter.stop(isChangingConfigurations(), isFinishing());
}
@Override
protected void onResume() {
super.onResume();
if (!this.videoView.isPlaying() && this.mediaPlayer != null) {
this.videoView.requestFocus();
this.videoView.seekTo(this.videoPosition);
this.videoView.start();
} else {
this.presenter.play();
}
getWindow().getDecorView().setSystemUiVisibility(5894);
}
@Override
public void onConfigurationChanged(Configuration newConfig) {
super.onConfigurationChanged(newConfig);
if (newConfig.orientation == 2) {
Log.d(TAG, "landscape");
} else if (newConfig.orientation == 1) {
Log.d(TAG, "portrait");
}
this.presenter.notifyPropertiesChanged();
}
@Override
@SuppressLint({"ResourceType"})
public void onBackPressed() {
if (this.presenter.handleExit(null)) {
close();
}
}
@Override
public void onRestoreInstanceState(Bundle savedInstanceState, PersistableBundle persistentState) {
super.onRestoreInstanceState(savedInstanceState, persistentState);
if (savedInstanceState != null) {
this.videoPosition = savedInstanceState.getInt("videoPosition");
}
}
@Override
public void onPrepared(MediaPlayer mp) {
this.mediaPlayer = mp;
if (this.muted) {
mp.setVolume(0.0f, 0.0f);
}
mp.start();
this.presenter.initializeViewabilityTracker(mp.getDuration(), this.videoView);
mp.setOnCompletionListener(new MediaPlayer.OnCompletionListener() {
@Override
public void onCompletion(MediaPlayer mp2) {
if (VungleActivity.this.reportProgress != null) {
VungleActivity.this.handler.removeCallbacks(VungleActivity.this.reportProgress);
}
VungleActivity.this.presenter.onProgressUpdate(100);
VungleActivity.this.runOnUiThread(new Runnable() {
@Override
public void run() {
VungleActivity.this.presenter.stopViewabilityTracker();
}
});
}
});
this.presenter.reportAction(TJAdUnitConstants.String.VIDEO_LENGTH, String.format(Locale.ENGLISH, "%d", Integer.valueOf(mp.getDuration())));
setupPlayerProgressBar();
if (this.pendingPause) {
this.pendingPause = false;
this.videoView.pause();
}
}
@Override
protected void onSaveInstanceState(Bundle outState) {
super.onSaveInstanceState(outState);
Log.d("Vungle", "onSaveInstanceState");
outState.putString("save", this.presenter.generateSaveState());
if (this.videoView != null) {
this.videoPosition = this.videoView.getCurrentPosition();
outState.putInt("videoPosition", this.videoPosition);
}
if (this.webView != null) {
this.webView.saveState(outState);
}
}
@Override
protected void onRestoreInstanceState(Bundle savedInstanceState) {
super.onRestoreInstanceState(savedInstanceState);
Log.d("Vungle", "onRestoreInstanceState(" + savedInstanceState + ")");
this.presenter.restoreFromSave(savedInstanceState.getString("save"));
}
@Override
public void updateWindow(boolean isFlexView) {
if (isFlexView) {
DisplayMetrics metrics = new DisplayMetrics();
getWindowManager().getDefaultDisplay().getMetrics(metrics);
int heightPixels = metrics.heightPixels;
int widthPixels = metrics.widthPixels;
int orientation = getResources().getConfiguration().orientation;
RelativeLayout.LayoutParams params = null;
if (orientation == 1) {
getWindow().setGravity(83);
getWindow().setLayout(widthPixels, (int) Math.round(widthPixels * NINE_BY_SIXTEEN_ASPECT_RATIO));
params = new RelativeLayout.LayoutParams(widthPixels, (int) (widthPixels * NINE_BY_SIXTEEN_ASPECT_RATIO));
} else if (orientation == 2) {
getWindow().setLayout((int) Math.round(heightPixels * NINE_BY_SIXTEEN_ASPECT_RATIO), heightPixels);
getWindow().setGravity(85);
params = new RelativeLayout.LayoutParams((int) Math.round(heightPixels * NINE_BY_SIXTEEN_ASPECT_RATIO), heightPixels);
params.addRule(11, -1);
}
this.webView.setLayoutParams(params);
getWindow().addFlags(288);
return;
}
getWindow().setFlags(1024, 1024);
getWindow().getDecorView().setBackgroundColor(-16777216);
}
@Override
public void setVisibility(boolean isVisible) {
}
@Override
public boolean onError(MediaPlayer mediaPlayer, int what, int extra) {
StringBuilder description = new StringBuilder();
switch (what) {
case 1:
description.append("MEDIA_ERROR_UNKNOWN");
break;
case 100:
description.append("MEDIA_ERROR_SERVER_DIED");
break;
default:
description.append("UNKNOWN");
break;
}
description.append(":");
switch (extra) {
case -1010:
description.append("MEDIA_ERROR_UNSUPPORTED");
break;
case -1007:
description.append("MEDIA_ERROR_MALFORMED");
break;
case -1004:
description.append("MEDIA_ERROR_IO");
break;
case FetchConst.ERROR_SERVER_ERROR:
description.append("MEDIA_ERROR_TIMED_OUT");
break;
case 200:
description.append("MEDIA_ERROR_NOT_VALID_FOR_PROGRESSIVE_PLAYBACK");
break;
default:
description.append("MEDIA_ERROR_SYSTEM");
break;
}
this.presenter.reportError(description.toString());
return true;
}
@Override
public void setOrientation(int orientation) {
setRequestedOrientation(orientation);
}
@Override
public void playVideo(Uri uri, boolean startMuted) {
this.videoView.setVisibility(0);
this.videoView.setOnErrorListener(this);
this.videoView.setVideoURI(uri);
this.muted = startMuted;
if (this.muted) {
this.presenter.reportAction("mute", "true");
}
final Bitmap muteBitmap = ViewUtility.getBitmap(ViewUtility.Asset.mute, this);
final Bitmap unMuteBitmap = ViewUtility.getBitmap(ViewUtility.Asset.unMute, this);
Bitmap privacyBitmap = ViewUtility.getBitmap(ViewUtility.Asset.privacy, this);
this.privacyOverlay.setImageBitmap(privacyBitmap);
this.privacyOverlay.setVisibility(0);
this.privacyOverlay.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Intent privacyIntent = new Intent("android.intent.action.VIEW", Uri.parse("https://vungle.com/privacy/"));
VungleActivity.this.startActivity(privacyIntent);
}
});
this.muteButton.setVisibility(0);
this.muteButton.setImageBitmap(this.muted ? muteBitmap : unMuteBitmap);
final AudioManager audioManager = (AudioManager) getSystemService("audio");
this.muteButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
if (!VungleActivity.this.muted) {
VungleActivity.this.mediaPlayer.setVolume(0.0f, 0.0f);
VungleActivity.this.muted = true;
VungleActivity.this.presenter.reportAction("mute", "true");
} else {
int vol = audioManager.getStreamVolume(3);
int maxVol = audioManager.getStreamMaxVolume(3);
float currentVolume = vol / maxVol;
VungleActivity.this.mediaPlayer.setVolume(currentVolume, currentVolume);
VungleActivity.this.muted = false;
VungleActivity.this.presenter.reportAction("unmute", "false");
}
VungleActivity.this.muteButton.setImageBitmap(VungleActivity.this.muted ? muteBitmap : unMuteBitmap);
}
});
this.progressBar.setVisibility(0);
this.progressBar.setMax(this.videoView.getDuration());
this.closeButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
VungleActivity.this.onBackPressed();
}
});
}
@Override
public void showWebsite(String url) {
Log.d(TAG, "loadJs: " + url);
this.webView.loadUrl(url);
this.webView.setVisibility(0);
this.videoView.setVisibility(4);
this.progressBar.setVisibility(8);
this.closeButton.setVisibility(8);
this.muteButton.setVisibility(8);
this.ctaOverlay.setVisibility(8);
}
@Override
public void close() {
if (this.videoView != null && this.videoView.isPlaying()) {
runOnUiThread(new Runnable() {
@Override
public void run() {
VungleActivity.this.presenter.stopViewabilityTracker();
}
});
}
finish();
}
@Override
public void showCloseButton() {
this.closeButton.setVisibility(0);
}
@Override
public void showCTAOverlay(boolean clickEnabled, boolean enabled, final int size) {
if (clickEnabled) {
this.videoView.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
VungleActivity.this.ctaOverlay.setVisibility(0);
VungleActivity.this.ctaOverlay.setImageBitmap(ViewUtility.getBitmap(ViewUtility.Asset.cta, VungleActivity.this));
VungleActivity.this.ctaOverlay.setEnabled(true);
}
});
} else {
this.ctaOverlay.setVisibility(0);
this.ctaOverlay.setImageBitmap(ViewUtility.getBitmap(enabled ? ViewUtility.Asset.cta : ViewUtility.Asset.ctaDisabled, this));
this.ctaOverlay.setEnabled(enabled);
}
if (size == 100) {
this.videoView.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
VungleActivity.this.presenter.reportAction("cta", "");
VungleActivity.this.presenter.handleAction("download");
}
});
} else {
final View parent = (View) this.ctaOverlay.getParent();
ViewTreeObserver vto = this.ctaOverlay.getViewTreeObserver();
vto.addOnPreDrawListener(new ViewTreeObserver.OnPreDrawListener() {
@Override
public boolean onPreDraw() {
VungleActivity.this.ctaOverlay.getViewTreeObserver().removeOnPreDrawListener(this);
final int finalHeight = VungleActivity.this.ctaOverlay.getMeasuredHeight();
final int finalWidth = VungleActivity.this.ctaOverlay.getMeasuredWidth();
parent.post(new Runnable() {
@Override
public void run() {
Rect rect = new Rect();
VungleActivity.this.ctaOverlay.getHitRect(rect);
rect.top -= (finalHeight / 2) * size;
rect.left -= (finalWidth / 2) * size;
rect.bottom += (finalHeight / 2) * size;
rect.right += (finalWidth / 2) * size;
parent.setTouchDelegate(new TouchDelegate(rect, VungleActivity.this.ctaOverlay));
}
});
return true;
}
});
}
this.ctaOverlay.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
VungleActivity.this.presenter.reportAction("cta", "");
VungleActivity.this.presenter.handleAction("download");
}
});
}
@Override
public void open(String url) {
Log.v(TAG, "Opening " + url);
try {
Intent i = Intent.parseUri(url, 0);
startActivity(i);
} catch (URISyntaxException e) {
e.printStackTrace();
}
}
@Override
public void showDialog(String dialogTitle, String dialogBody, String dialogContinue, String dialogClose, final DialogInterface.OnClickListener responseListener) {
AlertDialog.Builder dialogBuilder = new AlertDialog.Builder(new ContextThemeWrapper(this, getApplicationInfo().theme));
if (!TextUtils.isEmpty(dialogTitle)) {
dialogBuilder.setTitle(dialogTitle);
}
if (!TextUtils.isEmpty(dialogBody)) {
dialogBuilder.setMessage(dialogBody);
}
dialogBuilder.setPositiveButton(dialogContinue, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialogInterface, int i) {
VungleActivity.this.pendingPause = false;
VungleActivity.this.dialog.dismiss();
if (!VungleActivity.this.videoView.isPlaying() && VungleActivity.this.mediaPlayer != null) {
VungleActivity.this.videoView.requestFocus();
VungleActivity.this.videoView.seekTo(VungleActivity.this.videoPosition);
VungleActivity.this.videoView.start();
}
VungleActivity.this.getWindow().getDecorView().setSystemUiVisibility(5894);
if (responseListener != null) {
responseListener.onClick(dialogInterface, i);
}
}
});
dialogBuilder.setNegativeButton(dialogClose, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialogInterface, int i) {
VungleActivity.this.pendingPause = false;
VungleActivity.this.dialog.dismiss();
if (!VungleActivity.this.videoView.isPlaying() && VungleActivity.this.mediaPlayer != null) {
VungleActivity.this.videoView.requestFocus();
VungleActivity.this.videoView.seekTo(VungleActivity.this.videoPosition);
VungleActivity.this.videoView.start();
}
if (responseListener != null) {
responseListener.onClick(dialogInterface, i);
}
}
});
dialogBuilder.setCancelable(false);
this.dialog = dialogBuilder.create();
if (this.videoView.isPlaying() && this.mediaPlayer != null) {
this.videoView.pause();
} else {
this.pendingPause = true;
}
this.videoView.pause();
this.videoPosition = this.videoView.getCurrentPosition();
this.dialog.show();
}
private void setupPlayerProgressBar() {
if (this.mediaPlayer != null) {
this.reportProgress = new Runnable() {
Advertisement.Checkpoint checkpoint;
byte checkpointReached = 0;
float duration = -2.0f;
@Override
public void run() {
try {
int position = VungleActivity.this.mediaPlayer.getCurrentPosition();
if (this.duration == -2.0f) {
this.duration = VungleActivity.this.mediaPlayer.getDuration();
}
VungleActivity.this.presenter.reportAction("video_viewed", String.format(Locale.ENGLISH, "%d", Integer.valueOf(position)));
int percent = (int) ((position / this.duration) * 100.0f);
VungleActivity.this.presenter.onProgressUpdate(percent);
VungleActivity.this.progressBar.setMax((int) this.duration);
VungleActivity.this.progressBar.setProgress(position);
VungleActivity.this.handler.postDelayed(this, 1000L);
} catch (IllegalStateException e) {
Log.v(VungleActivity.TAG, "IllegalStateException while reporting progress indicates activity was killed via SIGKILL.");
}
}
};
this.handler.post(this.reportProgress);
}
}
}