Wolves Themes v1.0版本的 MD5 值为:cddc92b47f6b7c4a195c9625507eb51c
以下内容为反编译后的 MoPubView.java 源代码,内容仅作参考
package com.mopub.mobileads;
import android.app.Activity;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
import android.location.Location;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.text.TextUtils;
import android.util.AttributeSet;
import android.view.View;
import android.webkit.WebViewDatabase;
import android.widget.FrameLayout;
import com.mopub.common.AdFormat;
import com.mopub.common.AdReport;
import com.mopub.common.logging.MoPubLog;
import com.mopub.common.util.ManifestUtils;
import com.mopub.common.util.Reflection;
import com.mopub.common.util.Visibility;
import com.mopub.mobileads.factories.AdViewControllerFactory;
import java.util.Map;
import java.util.TreeMap;
public class MoPubView extends FrameLayout {
private static final String CUSTOM_EVENT_BANNER_ADAPTER_FACTORY = "com.mopub.mobileads.factories.CustomEventBannerAdapterFactory";
@Nullable
protected AdViewController mAdViewController;
private BannerAdListener mBannerAdListener;
private Context mContext;
protected Object mCustomEventBannerAdapter;
private BroadcastReceiver mScreenStateReceiver;
private int mScreenVisibility;
public interface BannerAdListener {
void onBannerClicked(MoPubView moPubView);
void onBannerCollapsed(MoPubView moPubView);
void onBannerExpanded(MoPubView moPubView);
void onBannerFailed(MoPubView moPubView, MoPubErrorCode moPubErrorCode);
void onBannerLoaded(MoPubView moPubView);
}
public MoPubView(Context context) {
this(context, null);
}
public MoPubView(Context context, AttributeSet attributeSet) {
super(context, attributeSet);
ManifestUtils.checkWebViewActivitiesDeclared(context);
this.mContext = context;
this.mScreenVisibility = getVisibility();
setHorizontalScrollBarEnabled(false);
setVerticalScrollBarEnabled(false);
try {
if (WebViewDatabase.getInstance(context) == null) {
MoPubLog.e("Disabling MoPub. Local cache file is inaccessible so MoPub will fail if we try to create a WebView. Details of this Android bug found at:https://code.google.com/p/android/issues/detail?id=10789");
} else {
this.mAdViewController = AdViewControllerFactory.create(context, this);
}
} catch (Exception e) {
MoPubLog.e("Disabling MoPub due to no WebView, or it's being updated", e);
}
}
private void invalidateAdapter() {
if (this.mCustomEventBannerAdapter != null) {
try {
new Reflection.MethodBuilder(this.mCustomEventBannerAdapter, "invalidate").setAccessible().execute();
} catch (Exception e) {
MoPubLog.e("Error invalidating adapter", e);
}
}
}
private void registerScreenStateBroadcastReceiver() {
this.mScreenStateReceiver = new BroadcastReceiver() {
@Override
public void onReceive(Context context, Intent intent) {
MoPubView moPubView;
int i;
if (!Visibility.isScreenVisible(MoPubView.this.mScreenVisibility) || intent == null) {
return;
}
String action = intent.getAction();
if ("android.intent.action.USER_PRESENT".equals(action)) {
moPubView = MoPubView.this;
i = 0;
} else if (!"android.intent.action.SCREEN_OFF".equals(action)) {
return;
} else {
moPubView = MoPubView.this;
i = 8;
}
moPubView.setAdVisibility(i);
}
};
IntentFilter intentFilter = new IntentFilter("android.intent.action.SCREEN_OFF");
intentFilter.addAction("android.intent.action.USER_PRESENT");
this.mContext.registerReceiver(this.mScreenStateReceiver, intentFilter);
}
public void setAdVisibility(int i) {
if (this.mAdViewController == null) {
return;
}
if (Visibility.isScreenVisible(i)) {
this.mAdViewController.resumeRefresh();
} else {
this.mAdViewController.pauseRefresh();
}
}
private void unregisterScreenStateBroadcastReceiver() {
try {
this.mContext.unregisterReceiver(this.mScreenStateReceiver);
} catch (Exception unused) {
MoPubLog.d("Failed to unregister screen state broadcast receiver (never registered).");
}
}
protected void adClicked() {
if (this.mBannerAdListener != null) {
this.mBannerAdListener.onBannerClicked(this);
}
}
public void adClosed() {
if (this.mBannerAdListener != null) {
this.mBannerAdListener.onBannerCollapsed(this);
}
}
public void adFailed(MoPubErrorCode moPubErrorCode) {
if (this.mBannerAdListener != null) {
this.mBannerAdListener.onBannerFailed(this, moPubErrorCode);
}
}
protected void adLoaded() {
MoPubLog.d("adLoaded");
if (this.mBannerAdListener != null) {
this.mBannerAdListener.onBannerLoaded(this);
}
}
public void adPresentedOverlay() {
if (this.mBannerAdListener != null) {
this.mBannerAdListener.onBannerExpanded(this);
}
}
public void destroy() {
removeAllViews();
if (this.mAdViewController != null) {
this.mAdViewController.cleanup();
this.mAdViewController = null;
}
if (this.mCustomEventBannerAdapter != null) {
invalidateAdapter();
this.mCustomEventBannerAdapter = null;
}
}
public void forceRefresh() {
if (this.mCustomEventBannerAdapter != null) {
invalidateAdapter();
this.mCustomEventBannerAdapter = null;
}
if (this.mAdViewController != null) {
this.mAdViewController.forceRefresh();
}
}
public Activity getActivity() {
return (Activity) this.mContext;
}
public AdFormat getAdFormat() {
return AdFormat.BANNER;
}
public int getAdHeight() {
if (this.mAdViewController != null) {
return this.mAdViewController.getAdHeight();
}
return 0;
}
public Integer getAdTimeoutDelay() {
if (this.mAdViewController != null) {
return this.mAdViewController.getAdTimeoutDelay();
}
return null;
}
public String getAdUnitId() {
if (this.mAdViewController != null) {
return this.mAdViewController.getAdUnitId();
}
return null;
}
public AdViewController getAdViewController() {
return this.mAdViewController;
}
public int getAdWidth() {
if (this.mAdViewController != null) {
return this.mAdViewController.getAdWidth();
}
return 0;
}
public boolean getAutorefreshEnabled() {
if (this.mAdViewController != null) {
return this.mAdViewController.getCurrentAutoRefreshStatus();
}
MoPubLog.d("Can't get autorefresh status for destroyed MoPubView. Returning false.");
return false;
}
public BannerAdListener getBannerAdListener() {
return this.mBannerAdListener;
}
@Deprecated
public String getClickTrackingUrl() {
return null;
}
public String getKeywords() {
if (this.mAdViewController != null) {
return this.mAdViewController.getKeywords();
}
return null;
}
public Map<String, Object> getLocalExtras() {
return this.mAdViewController != null ? this.mAdViewController.getLocalExtras() : new TreeMap();
}
public Location getLocation() {
if (this.mAdViewController != null) {
return this.mAdViewController.getLocation();
}
return null;
}
@Deprecated
public String getResponseString() {
return null;
}
public boolean getTesting() {
if (this.mAdViewController != null) {
return this.mAdViewController.getTesting();
}
MoPubLog.d("Can't get testing status for destroyed MoPubView. Returning false.");
return false;
}
public void loadAd() {
if (this.mAdViewController != null) {
this.mAdViewController.loadAd();
}
}
public void loadCustomEvent(String str, Map<String, String> map) {
if (this.mAdViewController == null) {
return;
}
if (TextUtils.isEmpty(str)) {
MoPubLog.d("Couldn't invoke custom event because the server did not specify one.");
loadFailUrl(MoPubErrorCode.ADAPTER_NOT_FOUND);
return;
}
if (this.mCustomEventBannerAdapter != null) {
invalidateAdapter();
}
MoPubLog.d("Loading custom event adapter.");
if (!Reflection.classFound(CUSTOM_EVENT_BANNER_ADAPTER_FACTORY)) {
MoPubLog.e("Could not load custom event -- missing banner module");
return;
}
try {
this.mCustomEventBannerAdapter = new Reflection.MethodBuilder(null, "create").setStatic(Class.forName(CUSTOM_EVENT_BANNER_ADAPTER_FACTORY)).addParam(MoPubView.class, this).addParam(String.class, str).addParam(Map.class, map).addParam(Long.TYPE, Long.valueOf(this.mAdViewController.getBroadcastIdentifier())).addParam(AdReport.class, this.mAdViewController.getAdReport()).execute();
new Reflection.MethodBuilder(this.mCustomEventBannerAdapter, "loadAd").setAccessible().execute();
} catch (Exception e) {
MoPubLog.e("Error loading custom event", e);
}
}
public boolean loadFailUrl(@NonNull MoPubErrorCode moPubErrorCode) {
if (this.mAdViewController == null) {
return false;
}
return this.mAdViewController.loadFailUrl(moPubErrorCode);
}
public void nativeAdLoaded() {
if (this.mAdViewController != null) {
this.mAdViewController.scheduleRefreshTimerIfEnabled();
}
adLoaded();
}
@Override
protected void onWindowVisibilityChanged(int i) {
if (Visibility.hasScreenVisibilityChanged(this.mScreenVisibility, i)) {
this.mScreenVisibility = i;
setAdVisibility(this.mScreenVisibility);
}
}
public void registerClick() {
if (this.mAdViewController != null) {
this.mAdViewController.registerClick();
adClicked();
}
}
public void setAdContentView(View view) {
if (this.mAdViewController != null) {
this.mAdViewController.setAdContentView(view);
}
}
public void setAdUnitId(String str) {
if (this.mAdViewController != null) {
this.mAdViewController.setAdUnitId(str);
}
}
public void setAutorefreshEnabled(boolean z) {
if (this.mAdViewController != null) {
this.mAdViewController.setShouldAllowAutoRefresh(z);
}
}
public void setBannerAdListener(BannerAdListener bannerAdListener) {
this.mBannerAdListener = bannerAdListener;
}
public void setKeywords(String str) {
if (this.mAdViewController != null) {
this.mAdViewController.setKeywords(str);
}
}
public void setLocalExtras(Map<String, Object> map) {
if (this.mAdViewController != null) {
this.mAdViewController.setLocalExtras(map);
}
}
public void setLocation(Location location) {
if (this.mAdViewController != null) {
this.mAdViewController.setLocation(location);
}
}
public void setTesting(boolean z) {
if (this.mAdViewController != null) {
this.mAdViewController.setTesting(z);
}
}
@Deprecated
public void setTimeout(int i) {
}
public void trackNativeImpression() {
MoPubLog.d("Tracking impression for native adapter.");
if (this.mAdViewController != null) {
this.mAdViewController.trackImpression();
}
}
}