Idle Tower v2.48版本的 MD5 值为:56f20496f6a85726b376356ed2ecee23
以下内容为反编译后的 Yodo1NativeAdView.java 源代码,内容仅作参考
package com.yodo1.mas.mediation.yodo1.kit;
import android.content.Context;
import android.content.Intent;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.net.Uri;
import android.os.Handler;
import android.os.Looper;
import android.util.AttributeSet;
import android.view.View;
import android.widget.Button;
import android.widget.FrameLayout;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;
import androidx.constraintlayout.widget.ConstraintLayout;
import com.google.firebase.analytics.FirebaseAnalytics;
import com.kidoz.events.EventParameters;
import com.yodo1.mas.Yodo1MasLog;
import com.yodo1.mas.mediation.yodo1.Yodo1MasYodo1Adapter;
import com.yodo1.mas.nativeads.Yodo1MasNativeAdViewBuilder;
import com.yodo1.mas.utils.Yodo1MasNativeUtil;
import java.io.IOException;
import okhttp3.Call;
import okhttp3.Callback;
import okhttp3.OkHttpClient;
import okhttp3.Request;
import okhttp3.Response;
public class Yodo1NativeAdView extends ConstraintLayout {
private static final String TAG = "[Yodo1NativeAdView]";
private Yodo1MasNativeAdViewBuilder builder;
private Bitmap contentBitmap;
private View contentView;
private final Handler handler;
private Bitmap iconBitmap;
private OnYodo1NativeAdViewListener listener;
public interface OnYodo1NativeAdViewListener {
void onNativeAdClicked(Yodo1NativeAdView yodo1NativeAdView);
void onNativeAdLoadFailedListener(Exception exc);
void onNativeAdLoadSuccessListener(Yodo1NativeAdView yodo1NativeAdView);
}
public Yodo1NativeAdView(Context context) {
super(context);
this.handler = new Handler(Looper.getMainLooper());
}
public Yodo1NativeAdView(Context context, AttributeSet attributeSet) {
super(context, attributeSet);
this.handler = new Handler(Looper.getMainLooper());
}
public Yodo1NativeAdView(Context context, AttributeSet attributeSet, int i) {
super(context, attributeSet, i);
this.handler = new Handler(Looper.getMainLooper());
}
public boolean isAdvertLoaded() {
return (this.iconBitmap == null || this.contentBitmap == null) ? false : true;
}
public void buildContentView(View view, Yodo1MasNativeAdViewBuilder yodo1MasNativeAdViewBuilder) {
if (isAdvertLoaded()) {
return;
}
this.builder = yodo1MasNativeAdViewBuilder;
this.contentView = view;
this.contentView.setLayoutParams(new ConstraintLayout.LayoutParams(-1, -1));
addView(this.contentView);
}
public void loadAd(String str) {
if (this.contentView == null) {
ConstraintLayout.LayoutParams layoutParams = new ConstraintLayout.LayoutParams(-1, -1);
if (str == null || (!str.equals("small") && !str.equals(FirebaseAnalytics.Param.MEDIUM))) {
str = FirebaseAnalytics.Param.MEDIUM;
}
if (str.equals("small")) {
this.builder = Yodo1NativeSmallAdView.builder();
this.contentView = new Yodo1NativeSmallAdView(getContext());
} else {
this.builder = Yodo1NativeMediumAdView.builder();
this.contentView = new Yodo1NativeMediumAdView(getContext());
}
this.contentView.setLayoutParams(layoutParams);
addView(this.contentView);
}
loadIcon();
loadContent();
setTitleView();
setBodyView();
setAdvertiserView();
setCtaView();
}
public void setListener(OnYodo1NativeAdViewListener onYodo1NativeAdViewListener) {
this.listener = onYodo1NativeAdViewListener;
}
private void loadIcon() {
new OkHttpClient().newCall(new Request.Builder().url("https://docs.yodo1.com/media/ad-test-resource/ad-banner-icon.png").build()).enqueue(new Callback() {
@Override
public void onFailure(Call call, final IOException iOException) {
Yodo1NativeAdView.this.handler.post(new Runnable() {
@Override
public void run() {
if (Yodo1NativeAdView.this.listener != null) {
Yodo1NativeAdView.this.listener.onNativeAdLoadFailedListener(iOException);
}
}
});
}
@Override
public void onResponse(Call call, Response response) {
Yodo1NativeAdView.this.iconBitmap = BitmapFactory.decodeStream(response.body() != null ? response.body().byteStream() : null);
Yodo1MasLog.d(Yodo1NativeAdView.TAG, "Thread: " + Thread.currentThread().getName());
Yodo1NativeAdView.this.handler.post(new Runnable() {
@Override
public void run() {
Yodo1MasLog.d(Yodo1NativeAdView.TAG, "Thread Runnable: " + Thread.currentThread().getName());
Yodo1NativeAdView.this.setIconView();
Yodo1NativeAdView.this.callload();
}
});
}
});
}
private void loadContent() {
new OkHttpClient().newCall(new Request.Builder().url("https://docs.yodo1.com/media/ad-test-resource/ad-native-ads.png").build()).enqueue(new Callback() {
@Override
public void onFailure(Call call, final IOException iOException) {
Yodo1NativeAdView.this.handler.post(new Runnable() {
@Override
public void run() {
if (Yodo1NativeAdView.this.listener != null) {
Yodo1NativeAdView.this.listener.onNativeAdLoadFailedListener(iOException);
}
}
});
}
@Override
public void onResponse(Call call, Response response) {
Yodo1NativeAdView.this.contentBitmap = BitmapFactory.decodeStream(response.body() != null ? response.body().byteStream() : null);
Yodo1MasLog.d(Yodo1NativeAdView.TAG, "Thread: " + Thread.currentThread().getName());
Yodo1NativeAdView.this.handler.post(new Runnable() {
@Override
public void run() {
Yodo1MasLog.d(Yodo1NativeAdView.TAG, "Thread Runnable: " + Thread.currentThread().getName());
Yodo1NativeAdView.this.setMediaContentView();
Yodo1NativeAdView.this.callload();
}
});
}
});
}
public void callload() {
OnYodo1NativeAdViewListener onYodo1NativeAdViewListener;
if (this.iconBitmap == null || this.contentBitmap == null || (onYodo1NativeAdViewListener = this.listener) == null) {
return;
}
onYodo1NativeAdViewListener.onNativeAdLoadSuccessListener(this);
}
public void setIconView() {
Yodo1MasNativeAdViewBuilder yodo1MasNativeAdViewBuilder;
View view = this.contentView;
if (view == null || (yodo1MasNativeAdViewBuilder = this.builder) == null) {
return;
}
View findViewById = view.findViewById(yodo1MasNativeAdViewBuilder.getIconImageViewId());
if (findViewById instanceof ImageView) {
((ImageView) findViewById).setImageBitmap(this.iconBitmap);
}
}
private void setTitleView() {
Yodo1MasNativeAdViewBuilder yodo1MasNativeAdViewBuilder;
View view = this.contentView;
if (view == null || (yodo1MasNativeAdViewBuilder = this.builder) == null) {
return;
}
View findViewById = view.findViewById(yodo1MasNativeAdViewBuilder.getTitleTextViewId());
if (findViewById instanceof TextView) {
((TextView) findViewById).setText("Yodo1 Test Ad");
}
}
private void setBodyView() {
Yodo1MasNativeAdViewBuilder yodo1MasNativeAdViewBuilder;
View view = this.contentView;
if (view == null || (yodo1MasNativeAdViewBuilder = this.builder) == null) {
return;
}
View findViewById = view.findViewById(yodo1MasNativeAdViewBuilder.getBodyTextViewId());
if (findViewById instanceof TextView) {
((TextView) findViewById).setText("Sponsored By Yodo1");
}
}
private void setAdvertiserView() {
Yodo1MasNativeAdViewBuilder yodo1MasNativeAdViewBuilder;
View view = this.contentView;
if (view == null || (yodo1MasNativeAdViewBuilder = this.builder) == null) {
return;
}
View findViewById = view.findViewById(yodo1MasNativeAdViewBuilder.getAdvertiserTextViewId());
if (findViewById instanceof TextView) {
((TextView) findViewById).setText("This is a Yodo1 Test Ad");
}
}
public void setMediaContentView() {
Yodo1MasNativeAdViewBuilder yodo1MasNativeAdViewBuilder;
View view = this.contentView;
if (view == null || (yodo1MasNativeAdViewBuilder = this.builder) == null) {
return;
}
View findViewById = view.findViewById(yodo1MasNativeAdViewBuilder.getMediaContentViewGroupId());
if (findViewById instanceof FrameLayout) {
FrameLayout frameLayout = (FrameLayout) findViewById;
frameLayout.removeAllViews();
FrameLayout.LayoutParams layoutParams = new FrameLayout.LayoutParams(-1, -1);
ImageView imageView = new ImageView(getContext());
imageView.setLayoutParams(layoutParams);
frameLayout.addView(imageView);
imageView.setImageBitmap(this.contentBitmap);
}
}
private void setCtaView() {
Yodo1MasNativeAdViewBuilder yodo1MasNativeAdViewBuilder;
View view = this.contentView;
if (view == null || (yodo1MasNativeAdViewBuilder = this.builder) == null) {
return;
}
View findViewById = view.findViewById(yodo1MasNativeAdViewBuilder.getCallToActionButtonId());
if (findViewById instanceof Button) {
Button button = (Button) findViewById;
button.setText(EventParameters.ACTION_CLICK);
button.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view2) {
Intent intent = new Intent("android.intent.action.VIEW");
intent.setData(Uri.parse(Yodo1MasYodo1Adapter.YODO1_WEB_URL));
Yodo1NativeAdView.this.getContext().startActivity(intent);
if (Yodo1NativeAdView.this.listener != null) {
Yodo1NativeAdView.this.listener.onNativeAdClicked(Yodo1NativeAdView.this);
}
}
});
}
}
static class Yodo1NativeSmallAdView extends ConstraintLayout {
private static Yodo1MasNativeAdViewBuilder builder;
public Yodo1NativeSmallAdView(Context context) {
super(context);
initView();
}
public Yodo1NativeSmallAdView(Context context, AttributeSet attributeSet) {
super(context, attributeSet);
initView();
}
public Yodo1NativeSmallAdView(Context context, AttributeSet attributeSet, int i) {
super(context, attributeSet, i);
initView();
}
public static Yodo1MasNativeAdViewBuilder builder() {
if (builder == null) {
Yodo1MasNativeAdViewBuilder yodo1MasNativeAdViewBuilder = new Yodo1MasNativeAdViewBuilder();
builder = yodo1MasNativeAdViewBuilder;
yodo1MasNativeAdViewBuilder.setIconImageViewId(View.generateViewId());
builder.setTitleTextViewId(View.generateViewId());
builder.setBodyTextViewId(View.generateViewId());
builder.setAdvertiserTextViewId(View.generateViewId());
builder.setOptionsContentViewGroupId(View.generateViewId());
builder.setMediaContentViewGroupId(View.generateViewId());
builder.setCallToActionButtonId(View.generateViewId());
}
return builder;
}
private void initView() {
Yodo1MasNativeAdViewBuilder builder2 = builder();
int dp2px = Yodo1MasNativeUtil.dp2px(getContext(), 5.0f);
ConstraintLayout.LayoutParams layoutParams = new ConstraintLayout.LayoutParams(0, -1);
layoutParams.topToTop = 0;
layoutParams.topMargin = dp2px;
layoutParams.bottomToBottom = 0;
layoutParams.bottomMargin = dp2px;
layoutParams.leftToLeft = 0;
layoutParams.leftMargin = dp2px;
layoutParams.dimensionRatio = "5:3";
FrameLayout frameLayout = new FrameLayout(getContext());
frameLayout.setId(builder2.getMediaContentViewGroupId());
frameLayout.setLayoutParams(layoutParams);
addView(frameLayout);
ConstraintLayout.LayoutParams layoutParams2 = new ConstraintLayout.LayoutParams(0, Yodo1MasNativeUtil.dp2px(getContext(), 40.0f));
layoutParams2.leftToRight = frameLayout.getId();
layoutParams2.leftMargin = dp2px;
layoutParams2.rightToRight = 0;
layoutParams2.rightMargin = dp2px;
layoutParams2.bottomToBottom = 0;
layoutParams2.bottomMargin = dp2px;
Button button = new Button(getContext());
button.setId(builder2.getCallToActionButtonId());
button.setLayoutParams(layoutParams2);
button.setAllCaps(false);
addView(button);
ConstraintLayout.LayoutParams layoutParams3 = new ConstraintLayout.LayoutParams(0, -2);
layoutParams3.topToTop = 0;
layoutParams3.topMargin = dp2px;
layoutParams3.bottomToTop = button.getId();
layoutParams3.bottomMargin = dp2px;
layoutParams3.leftToRight = frameLayout.getId();
layoutParams3.leftMargin = dp2px;
layoutParams3.rightToRight = 0;
layoutParams3.rightMargin = dp2px;
LinearLayout linearLayout = new LinearLayout(getContext());
linearLayout.setOrientation(1);
linearLayout.setLayoutParams(layoutParams3);
addView(linearLayout);
LinearLayout.LayoutParams layoutParams4 = new LinearLayout.LayoutParams(-1, -2);
TextView textView = new TextView(getContext());
textView.setId(builder2.getTitleTextViewId());
textView.setLayoutParams(layoutParams4);
linearLayout.addView(textView);
LinearLayout.LayoutParams layoutParams5 = new LinearLayout.LayoutParams(-1, -2);
layoutParams5.topMargin = dp2px / 2;
TextView textView2 = new TextView(getContext());
textView2.setId(builder2.getAdvertiserTextViewId());
textView2.setLayoutParams(layoutParams5);
linearLayout.addView(textView2);
}
}
static class Yodo1NativeMediumAdView extends ConstraintLayout {
private static Yodo1MasNativeAdViewBuilder builder;
public Yodo1NativeMediumAdView(Context context) {
super(context);
initView();
}
public Yodo1NativeMediumAdView(Context context, AttributeSet attributeSet) {
super(context, attributeSet);
initView();
}
public Yodo1NativeMediumAdView(Context context, AttributeSet attributeSet, int i) {
super(context, attributeSet, i);
initView();
}
public static Yodo1MasNativeAdViewBuilder builder() {
if (builder == null) {
Yodo1MasNativeAdViewBuilder yodo1MasNativeAdViewBuilder = new Yodo1MasNativeAdViewBuilder();
builder = yodo1MasNativeAdViewBuilder;
yodo1MasNativeAdViewBuilder.setIconImageViewId(View.generateViewId());
builder.setTitleTextViewId(View.generateViewId());
builder.setBodyTextViewId(View.generateViewId());
builder.setAdvertiserTextViewId(View.generateViewId());
builder.setOptionsContentViewGroupId(View.generateViewId());
builder.setMediaContentViewGroupId(View.generateViewId());
builder.setCallToActionButtonId(View.generateViewId());
}
return builder;
}
private void initView() {
Yodo1MasNativeAdViewBuilder builder2 = builder();
int dp2px = Yodo1MasNativeUtil.dp2px(getContext(), 5.0f);
ConstraintLayout.LayoutParams layoutParams = new ConstraintLayout.LayoutParams(-1, -2);
layoutParams.topMargin = dp2px;
layoutParams.topToTop = 0;
layoutParams.leftMargin = dp2px;
layoutParams.leftToLeft = 0;
layoutParams.rightMargin = dp2px;
layoutParams.rightToRight = 0;
ConstraintLayout constraintLayout = new ConstraintLayout(getContext());
constraintLayout.setId(View.generateViewId());
constraintLayout.setLayoutParams(layoutParams);
addView(constraintLayout);
ConstraintLayout.LayoutParams layoutParams2 = new ConstraintLayout.LayoutParams(Yodo1MasNativeUtil.dp2px(getContext(), 60.0f), Yodo1MasNativeUtil.dp2px(getContext(), 60.0f));
layoutParams2.topToTop = 0;
layoutParams2.bottomToBottom = 0;
layoutParams2.leftToLeft = 0;
ImageView imageView = new ImageView(getContext());
imageView.setId(builder2.getIconImageViewId());
imageView.setLayoutParams(layoutParams2);
imageView.setScaleType(ImageView.ScaleType.CENTER);
constraintLayout.addView(imageView);
ConstraintLayout.LayoutParams layoutParams3 = new ConstraintLayout.LayoutParams(0, -2);
layoutParams3.topToTop = 0;
layoutParams3.bottomToBottom = 0;
layoutParams3.leftToRight = imageView.getId();
layoutParams3.leftMargin = dp2px;
layoutParams3.rightToRight = 0;
LinearLayout linearLayout = new LinearLayout(getContext());
linearLayout.setLayoutParams(layoutParams3);
linearLayout.setOrientation(1);
constraintLayout.addView(linearLayout);
ConstraintLayout.LayoutParams layoutParams4 = new ConstraintLayout.LayoutParams(-1, -2);
TextView textView = new TextView(getContext());
textView.setId(builder2.getTitleTextViewId());
textView.setLayoutParams(layoutParams4);
linearLayout.addView(textView);
ConstraintLayout.LayoutParams layoutParams5 = new ConstraintLayout.LayoutParams(-1, -2);
int i = dp2px / 2;
layoutParams5.topMargin = i;
TextView textView2 = new TextView(getContext());
textView2.setId(builder2.getBodyTextViewId());
textView2.setLayoutParams(layoutParams5);
linearLayout.addView(textView2);
ConstraintLayout.LayoutParams layoutParams6 = new ConstraintLayout.LayoutParams(-1, -2);
layoutParams6.topMargin = i;
layoutParams6.topToBottom = constraintLayout.getId();
layoutParams6.leftMargin = dp2px;
layoutParams6.leftToLeft = 0;
layoutParams6.rightMargin = dp2px;
layoutParams6.rightToRight = 0;
TextView textView3 = new TextView(getContext());
textView3.setId(builder2.getAdvertiserTextViewId());
textView3.setLayoutParams(layoutParams6);
addView(textView3);
ConstraintLayout.LayoutParams layoutParams7 = new ConstraintLayout.LayoutParams(-1, Yodo1MasNativeUtil.dp2px(getContext(), 45.0f));
layoutParams7.leftMargin = dp2px;
layoutParams7.leftToLeft = 0;
layoutParams7.rightMargin = dp2px;
layoutParams7.rightToRight = 0;
layoutParams7.bottomMargin = dp2px;
layoutParams7.bottomToBottom = 0;
Button button = new Button(getContext());
button.setId(builder2.getCallToActionButtonId());
button.setLayoutParams(layoutParams7);
button.setAllCaps(false);
addView(button);
ConstraintLayout.LayoutParams layoutParams8 = new ConstraintLayout.LayoutParams(-1, 0);
layoutParams8.topMargin = dp2px;
layoutParams8.topToBottom = textView3.getId();
layoutParams8.leftMargin = dp2px;
layoutParams8.leftToLeft = 0;
layoutParams8.rightMargin = dp2px;
layoutParams8.rightToRight = 0;
layoutParams8.bottomMargin = dp2px;
layoutParams8.bottomToTop = button.getId();
FrameLayout frameLayout = new FrameLayout(getContext());
frameLayout.setId(builder2.getMediaContentViewGroupId());
frameLayout.setLayoutParams(layoutParams8);
addView(frameLayout);
}
}
}