MD5 校验值:27cf44ec6e0720408f5ef017a90a3331
MoPubCustomEventNative.java 文件包含反编译后的源代码,请注意,该内容仅供学习和参考使用,不得用于非法用途。
package com.mopub.nativeads; import android.content.Context; import android.view.View; import com.mopub.common.DataKeys; import com.mopub.common.VisibleForTesting; import com.mopub.common.logging.MoPubLog; import com.mopub.common.util.Numbers; import com.mopub.nativeads.CustomEventNative; import com.mopub.nativeads.NativeImageHelper; import java.util.ArrayList; import java.util.HashSet; import java.util.Iterator; import java.util.List; import java.util.Locale; import java.util.Map; import java.util.Set; import org.json.JSONArray; import org.json.JSONObject; public class MoPubCustomEventNative extends CustomEventNative { @Override public void a(Context context, CustomEventNative.CustomEventNativeListener customEventNativeListener, Map<String, Object> map, Map<String, String> map2) { Object obj = map.get(DataKeys.JSON_BODY_KEY); if (!(obj instanceof JSONObject)) { customEventNativeListener.onNativeAdFailed(NativeErrorCode.INVALID_RESPONSE); return; } MoPubStaticNativeAd moPubStaticNativeAd = new MoPubStaticNativeAd(context, (JSONObject) obj, new ImpressionTracker(context), new NativeClickHandler(context), customEventNativeListener); if (map2.containsKey(DataKeys.IMPRESSION_MIN_VISIBLE_PERCENT)) { try { moPubStaticNativeAd.setImpressionMinPercentageViewed(Integer.parseInt(map2.get(DataKeys.IMPRESSION_MIN_VISIBLE_PERCENT))); } catch (NumberFormatException e) { MoPubLog.d("Unable to format min visible percent: " + map2.get(DataKeys.IMPRESSION_MIN_VISIBLE_PERCENT)); } } if (map2.containsKey(DataKeys.IMPRESSION_VISIBLE_MS)) { try { moPubStaticNativeAd.setImpressionMinTimeViewed(Integer.parseInt(map2.get(DataKeys.IMPRESSION_VISIBLE_MS))); } catch (NumberFormatException e2) { MoPubLog.d("Unable to format min time: " + map2.get(DataKeys.IMPRESSION_VISIBLE_MS)); } } if (map2.containsKey(DataKeys.IMPRESSION_MIN_VISIBLE_PX)) { try { moPubStaticNativeAd.setImpressionMinVisiblePx(Integer.valueOf(Integer.parseInt(map2.get(DataKeys.IMPRESSION_MIN_VISIBLE_PX)))); } catch (NumberFormatException e3) { MoPubLog.d("Unable to format min visible px: " + map2.get(DataKeys.IMPRESSION_MIN_VISIBLE_PX)); } } try { moPubStaticNativeAd.e(); } catch (IllegalArgumentException e4) { customEventNativeListener.onNativeAdFailed(NativeErrorCode.UNSPECIFIED); } } static class MoPubStaticNativeAd extends StaticNativeAd { private final Context a; private final CustomEventNative.CustomEventNativeListener b; private final JSONObject c; private final ImpressionTracker d; private final NativeClickHandler e; public enum Parameter { IMPRESSION_TRACKER("imptracker", true), CLICK_TRACKER("clktracker", true), TITLE("title", false), TEXT("text", false), MAIN_IMAGE("mainimage", false), ICON_IMAGE("iconimage", false), CLICK_DESTINATION("clk", false), FALLBACK("fallback", false), CALL_TO_ACTION("ctatext", false), STAR_RATING("starrating", false); @VisibleForTesting static final Set<String> requiredKeys = new HashSet(); final String name; final boolean required; static { for (Parameter parameter : values()) { if (parameter.required) { requiredKeys.add(parameter.name); } } } Parameter(String str, boolean z) { this.name = str; this.required = z; } static Parameter from(String str) { for (Parameter parameter : values()) { if (parameter.name.equals(str)) { return parameter; } } return null; } } MoPubStaticNativeAd(Context context, JSONObject jSONObject, ImpressionTracker impressionTracker, NativeClickHandler nativeClickHandler, CustomEventNative.CustomEventNativeListener customEventNativeListener) { this.c = jSONObject; this.a = context.getApplicationContext(); this.d = impressionTracker; this.e = nativeClickHandler; this.b = customEventNativeListener; } void e() throws IllegalArgumentException { if (!a(this.c)) { throw new IllegalArgumentException("JSONObject did not contain required keys."); } Iterator<String> keys = this.c.keys(); while (keys.hasNext()) { String next = keys.next(); Parameter from = Parameter.from(next); if (from != null) { try { a(from, this.c.opt(next)); } catch (ClassCastException e) { throw new IllegalArgumentException("JSONObject key (" + next + ") contained unexpected value."); } } else { addExtra(next, this.c.opt(next)); } } setPrivacyInformationIconClickThroughUrl("https://www.mopub.com/optout"); NativeImageHelper.preCacheImages(this.a, g(), new NativeImageHelper.ImageListener() { @Override public void onImagesCached() { MoPubStaticNativeAd.this.b.onNativeAdLoaded(MoPubStaticNativeAd.this); } @Override public void onImagesFailedToCache(NativeErrorCode nativeErrorCode) { MoPubStaticNativeAd.this.b.onNativeAdFailed(nativeErrorCode); } }); } private boolean a(JSONObject jSONObject) { HashSet hashSet = new HashSet(); Iterator<String> keys = jSONObject.keys(); while (keys.hasNext()) { hashSet.add(keys.next()); } return hashSet.containsAll(Parameter.requiredKeys); } private void a(Parameter parameter, Object obj) throws ClassCastException { try { switch (parameter) { case MAIN_IMAGE: setMainImageUrl((String) obj); break; case ICON_IMAGE: setIconImageUrl((String) obj); break; case IMPRESSION_TRACKER: a(obj); break; case CLICK_DESTINATION: setClickDestinationUrl((String) obj); break; case CLICK_TRACKER: c(obj); break; case CALL_TO_ACTION: setCallToAction((String) obj); break; case TITLE: setTitle((String) obj); break; case TEXT: setText((String) obj); break; case STAR_RATING: setStarRating(Numbers.parseDouble(obj)); break; default: MoPubLog.d("Unable to add JSON key to internal mapping: " + parameter.name); break; } } catch (ClassCastException e) { if (!parameter.required) { MoPubLog.d("Ignoring class cast exception for optional key: " + parameter.name); return; } throw e; } } private void c(Object obj) { if (obj instanceof JSONArray) { b(obj); } else { addClickTracker((String) obj); } } private boolean a(String str) { return str != null && str.toLowerCase(Locale.US).endsWith("image"); } List<String> f() { ArrayList arrayList = new ArrayList(getExtras().size()); for (Map.Entry<String, Object> entry : getExtras().entrySet()) { if (a(entry.getKey()) && (entry.getValue() instanceof String)) { arrayList.add((String) entry.getValue()); } } return arrayList; } List<String> g() { ArrayList arrayList = new ArrayList(); if (getMainImageUrl() != null) { arrayList.add(getMainImageUrl()); } if (getIconImageUrl() != null) { arrayList.add(getIconImageUrl()); } arrayList.addAll(f()); return arrayList; } @Override public void prepare(View view) { this.d.addView(view, this); this.e.setOnClickListener(view, this); } @Override public void clear(View view) { this.d.removeView(view); this.e.clearOnClickListener(view); } @Override public void destroy() { this.d.destroy(); } @Override public void recordImpression(View view) { a(); } @Override public void handleClick(View view) { b(); this.e.openClickDestinationUrl(getClickDestinationUrl(), view); } } }