13Poker by gametower unlimited gems v0.4版本的 MD5 值为:51324fc0f195c34821074948ab266846
以下内容为反编译后的 MMAdView.java 源代码,内容仅作参考
package com.millennialmedia.android;
import android.app.Activity;
import android.content.Context;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.os.Parcelable;
import android.text.TextUtils;
import android.util.AttributeSet;
import android.view.MotionEvent;
import android.view.View;
import android.view.ViewGroup;
import android.view.ViewParent;
import android.view.Window;
import android.view.animation.AlphaAnimation;
import android.view.animation.Animation;
import android.view.animation.TranslateAnimation;
import android.widget.ImageView;
import android.widget.RelativeLayout;
import com.adsdk.sdk.mraid.AdView;
import com.millennialmedia.android.MMAdImpl;
import com.millennialmedia.android.MMLayout;
import com.millennialmedia.android.MMSDK;
import com.millennialmedia.android.Utils;
import java.io.File;
import java.io.FileOutputStream;
import java.io.InputStream;
import java.io.OutputStream;
import java.lang.reflect.Method;
import java.net.HttpURLConnection;
import java.net.URL;
import java.util.Map;
import java.util.Random;
public final class MMAdView extends MMLayout implements View.OnClickListener, Animation.AnimationListener {
static final int DEFAULT_RESIZE_PARAM_VALUES = -50;
public static final int TRANSITION_DOWN = 3;
public static final int TRANSITION_FADE = 1;
public static final int TRANSITION_NONE = 0;
public static final int TRANSITION_RANDOM = 4;
public static final int TRANSITION_UP = 2;
int height;
int oldHeight;
int oldWidth;
ImageView refreshAnimationimageView;
int transitionType;
ResizeView view;
int width;
@Override
public void addBlackView() {
super.addBlackView();
}
@Override
public String getApid() {
return super.getApid();
}
@Override
public boolean getIgnoresDensityScaling() {
return super.getIgnoresDensityScaling();
}
@Override
public RequestListener getListener() {
return super.getListener();
}
@Override
public MMRequest getMMRequest() {
return super.getMMRequest();
}
@Override
public boolean onTouchEvent(MotionEvent x0) {
return super.onTouchEvent(x0);
}
@Override
public void removeBlackView() {
super.removeBlackView();
}
@Override
public void setApid(String x0) {
super.setApid(x0);
}
@Override
public void setIgnoresDensityScaling(boolean x0) {
super.setIgnoresDensityScaling(x0);
}
@Override
public void setListener(RequestListener x0) {
super.setListener(x0);
}
@Override
public void setMMRequest(MMRequest x0) {
super.setMMRequest(x0);
}
public MMAdView(Context context) {
super(context);
this.transitionType = 4;
this.height = 0;
this.width = 0;
this.oldHeight = DEFAULT_RESIZE_PARAM_VALUES;
this.oldWidth = DEFAULT_RESIZE_PARAM_VALUES;
this.adImpl = new MMAdViewMMAdImpl(context);
init(context);
}
@Deprecated
public MMAdView(Context context, AttributeSet attrs) {
this(context, attrs, 0);
}
@Deprecated
public MMAdView(Context context, AttributeSet attrs, int defStyle) {
super(context, attrs, defStyle);
this.transitionType = 4;
this.height = 0;
this.width = 0;
this.oldHeight = DEFAULT_RESIZE_PARAM_VALUES;
this.oldWidth = DEFAULT_RESIZE_PARAM_VALUES;
if (!isInEditMode()) {
MMSDK.Log.d("Creating MMAdView from XML layout.");
this.adImpl = new MMAdViewMMAdImpl(context);
if (attrs != null) {
setApid(attrs.getAttributeValue("http://millennialmedia.com/android/schema", "apid"));
this.adImpl.ignoreDensityScaling = attrs.getAttributeBooleanValue("http://millennialmedia.com/android/schema", "ignoreDensityScaling", false);
String heightIn = attrs.getAttributeValue("http://millennialmedia.com/android/schema", "height");
String widthIn = attrs.getAttributeValue("http://millennialmedia.com/android/schema", "width");
try {
if (!TextUtils.isEmpty(heightIn)) {
this.height = Integer.parseInt(heightIn);
}
if (!TextUtils.isEmpty(widthIn)) {
this.width = Integer.parseInt(widthIn);
}
} catch (NumberFormatException e) {
}
if (this.adImpl.mmRequest != null) {
this.adImpl.mmRequest.age = attrs.getAttributeValue("http://millennialmedia.com/android/schema", MMRequest.KEY_AGE);
this.adImpl.mmRequest.children = attrs.getAttributeValue("http://millennialmedia.com/android/schema", MMRequest.KEY_CHILDREN);
this.adImpl.mmRequest.education = attrs.getAttributeValue("http://millennialmedia.com/android/schema", MMRequest.KEY_EDUCATION);
this.adImpl.mmRequest.ethnicity = attrs.getAttributeValue("http://millennialmedia.com/android/schema", MMRequest.KEY_ETHNICITY);
this.adImpl.mmRequest.gender = attrs.getAttributeValue("http://millennialmedia.com/android/schema", MMRequest.KEY_GENDER);
this.adImpl.mmRequest.income = attrs.getAttributeValue("http://millennialmedia.com/android/schema", MMRequest.KEY_INCOME);
this.adImpl.mmRequest.keywords = attrs.getAttributeValue("http://millennialmedia.com/android/schema", MMRequest.KEY_KEYWORDS);
this.adImpl.mmRequest.orientation = attrs.getAttributeValue("http://millennialmedia.com/android/schema", MMRequest.KEY_ORIENTATION);
this.adImpl.mmRequest.marital = attrs.getAttributeValue("http://millennialmedia.com/android/schema", MMRequest.KEY_MARITAL_STATUS);
this.adImpl.mmRequest.politics = attrs.getAttributeValue("http://millennialmedia.com/android/schema", MMRequest.KEY_POLITICS);
this.adImpl.mmRequest.vendor = attrs.getAttributeValue("http://millennialmedia.com/android/schema", MMRequest.KEY_VENDOR);
this.adImpl.mmRequest.zip = attrs.getAttributeValue("http://millennialmedia.com/android/schema", "zip");
}
this.goalId = attrs.getAttributeValue("http://millennialmedia.com/android/schema", "goalId");
}
this.adImpl.xmlLayout = true;
init(context);
return;
}
initEclipseAd(context);
}
@Override
public void setBackgroundColor(int color) {
super.setBackgroundColor(color);
if (this.adImpl != null && this.adImpl.controller != null && this.adImpl.controller.webView != null) {
this.adImpl.controller.webView.setBackgroundColor(color);
}
}
private void init(Context context) {
setBackgroundColor(0);
this.adImpl.adType = AdView.AD_ORIENTATION_BOTH;
setOnClickListener(this);
setFocusable(true);
this.refreshAnimationimageView = new ImageView(context);
this.refreshAnimationimageView.setScaleType(ImageView.ScaleType.FIT_XY);
this.refreshAnimationimageView.setVisibility(8);
addView(this.refreshAnimationimageView, new RelativeLayout.LayoutParams(-2, -2));
setLayoutParams(new RelativeLayout.LayoutParams(-2, -2));
}
private void initEclipseAd(Context context) {
ImageView logoForXML = new ImageView(context);
InputStream is = null;
OutputStream out = null;
try {
String dir = System.getProperty("java.io.tmpdir");
if (dir != null && !dir.endsWith(File.separator)) {
dir = dir + File.separator;
}
File file = new File(dir + "millenial355jns6u3l1nmedia.png");
if (!file.exists()) {
HttpURLConnection conn = (HttpURLConnection) new URL("http://images.millennialmedia.com/9513/192134.gif").openConnection();
conn.setDoOutput(true);
conn.setConnectTimeout(10000);
conn.connect();
is = conn.getInputStream();
OutputStream out2 = new FileOutputStream(file);
try {
byte[] buffer = new byte[1024];
while (true) {
int bytesRead = is.read(buffer);
if (bytesRead <= 0) {
break;
}
out2.write(buffer, 0, bytesRead);
}
out = out2;
} catch (Exception e) {
out = out2;
if (is != null) {
try {
is.close();
} catch (Exception e2) {
}
}
if (out != null) {
out.close();
}
addView(logoForXML);
} catch (Throwable th) {
th = th;
out = out2;
if (is != null) {
try {
is.close();
} catch (Exception e3) {
throw th;
}
}
if (out != null) {
out.close();
}
throw th;
}
}
Bitmap bmp = BitmapFactory.decodeFile(file.getAbsolutePath());
if (logoForXML != null && bmp != null) {
logoForXML.setImageBitmap(bmp);
}
if (is != null) {
try {
is.close();
} catch (Exception e4) {
}
}
if (out != null) {
out.close();
}
} catch (Exception e5) {
} catch (Throwable th2) {
th = th2;
}
addView(logoForXML);
}
@Override
@Deprecated
public void onClick(View v) {
MMSDK.Log.d("On click for " + v.getId() + " view, " + v + " adimpl" + this.adImpl);
onTouchEvent(MotionEvent.obtain(0L, System.currentTimeMillis(), 1, 0.0f, 0.0f, 0));
}
@Override
protected void onLayout(boolean changed, int left, int top, int right, int bottom) {
super.onLayout(changed, left, top, right, bottom);
Utils.ThreadUtils.execute(new Runnable() {
@Override
public void run() {
float density = MMAdView.this.getContext().getResources().getDisplayMetrics().density;
if (MMAdView.this.width <= 0) {
MMAdView.this.width = (int) (MMAdView.this.getWidth() / density);
}
if (MMAdView.this.height <= 0) {
MMAdView.this.height = (int) (MMAdView.this.getHeight() / density);
}
}
});
}
public void setHeight(int height) {
this.height = height;
}
public void setWidth(int width) {
this.width = width;
}
public void setTransitionType(int type) {
this.transitionType = type;
}
@Override
void closeAreaTouched() {
this.adImpl.unresizeToDefault();
}
private static class MMAdViewWebViewClientListener extends MMAdImpl.BasicWebViewClientListener {
MMAdViewWebViewClientListener(MMAdImpl adImpl) {
super(adImpl);
}
@Override
public void onPageFinished(String url) {
super.onPageFinished(url);
MMAdImpl adImpl = this.adImplRef.get();
if (adImpl != null && adImpl.isTransitionAnimated()) {
adImpl.animateTransition();
}
}
}
class MMAdViewMMAdImpl extends MMLayout.MMLayoutMMAdImpl {
public MMAdViewMMAdImpl(Context context) {
super(context);
this.mmWebViewClientListener = new MMAdViewWebViewClientListener(this);
}
@Override
public String getRequestFailedAction() {
return MMBroadcastReceiver.ACTION_GETAD_FAILED;
}
@Override
public String getRequestCompletedAction() {
return MMBroadcastReceiver.ACTION_GETAD_SUCCEEDED;
}
@Override
String getReqType() {
return "getad";
}
@Override
public boolean isTransitionAnimated() {
return MMAdView.this.transitionType != 0;
}
@Override
public void prepareTransition(Bitmap bitmap) {
MMAdView.this.refreshAnimationimageView.setImageBitmap(bitmap);
MMAdView.this.refreshAnimationimageView.setVisibility(0);
MMAdView.this.refreshAnimationimageView.bringToFront();
}
@Override
public boolean isBanner() {
return true;
}
@Override
public boolean hasCachedVideoSupport() {
return false;
}
@Override
public void insertUrlAdMetaValues(Map<String, String> paramsMap) {
if (MMAdView.this.height > 0) {
paramsMap.put(MMRequest.KEY_HEIGHT, String.valueOf(MMAdView.this.height));
}
if (MMAdView.this.width > 0) {
paramsMap.put(MMRequest.KEY_WIDTH, String.valueOf(MMAdView.this.width));
}
super.insertUrlAdMetaValues(paramsMap);
}
@Override
public boolean isLifecycleObservable() {
return MMAdView.this.getWindowToken() != null;
}
@Override
public void animateTransition() {
Animation animation;
if (MMAdView.this.refreshAnimationimageView.getDrawable() != null) {
int type = MMAdView.this.transitionType;
if (type == 4) {
Random r = new Random();
type = r.nextInt(4);
}
switch (type) {
case 2:
float height = MMAdView.this.getHeight();
animation = new TranslateAnimation(0.0f, 0.0f, 0.0f, -height);
break;
case 3:
float height2 = MMAdView.this.getHeight();
animation = new TranslateAnimation(0.0f, 0.0f, 0.0f, height2);
break;
default:
animation = new AlphaAnimation(1.0f, 0.0f);
break;
}
animation.setDuration(1000L);
animation.setAnimationListener(MMAdView.this);
animation.setFillEnabled(true);
animation.setFillBefore(true);
animation.setFillAfter(true);
final Animation animFinal = animation;
MMSDK.runOnUiThread(new Runnable() {
@Override
public void run() {
MMAdView.this.refreshAnimationimageView.startAnimation(animFinal);
}
});
}
}
}
@Override
@Deprecated
public void onAnimationStart(Animation animation) {
}
@Override
@Deprecated
public void onAnimationEnd(Animation animation) {
this.refreshAnimationimageView.setVisibility(8);
}
@Override
@Deprecated
public void onAnimationRepeat(Animation animation) {
}
public void getAd() {
if (this.adImpl != null && this.adImpl.requestListener != null) {
getAd(this.adImpl.requestListener);
} else {
getAdInternal();
}
}
public void getAd(RequestListener listener) {
if (this.adImpl != null) {
this.adImpl.requestListener = listener;
}
getAdInternal();
}
private void getAdInternal() {
if (this.adImpl != null) {
this.adImpl.requestAd();
}
}
@Override
public void onWindowFocusChanged(boolean windowInFocus) {
super.onWindowFocusChanged(windowInFocus);
if (windowInFocus && this.adImpl != null && this.adImpl.controller != null) {
if (this.adImpl.controller.webView == null) {
this.adImpl.controller.webView = MMAdImplController.getWebViewFromExistingAdImpl(this.adImpl);
}
if (this.adImpl.controller.webView != null && !this.adImpl.controller.webView.isCurrentParent(this.adImpl.internalId)) {
this.adImpl.controller.webView.removeFromParent();
addView(this.adImpl.controller.webView);
}
}
}
public class ResizeView extends View {
public ResizeView(Context context) {
super(context);
}
@Override
protected Parcelable onSaveInstanceState() {
MMSDK.Log.d("onSaveInstanceState");
attachToContext(MMAdView.this);
return super.onSaveInstanceState();
}
@Override
protected void onRestoreInstanceState(Parcelable state) {
MMSDK.Log.d("onRestoreInstanceState");
MMAdView.this.attachToWindow(MMAdView.this);
super.onRestoreInstanceState(state);
}
synchronized void attachToContext(View view) {
MMAdView.this.detachFromParent(view);
if (getParent() != null && (getParent() instanceof ViewGroup)) {
((ViewGroup) getParent()).addView(view);
}
}
}
public synchronized void detachFromParent(View view) {
if (view != null) {
ViewParent parent = getParent();
if (parent != null && (parent instanceof ViewGroup)) {
ViewGroup group = (ViewGroup) parent;
if (view.getParent() != null) {
group.removeView(view);
}
}
}
}
public synchronized void attachToWindow(View view) {
View decorView;
detachFromParent(view);
Context context = getContext();
if (context != null && (context instanceof Activity)) {
Activity activity = (Activity) context;
Window win = activity.getWindow();
if (win != null && (decorView = win.getDecorView()) != null && (decorView instanceof ViewGroup)) {
ViewGroup group = (ViewGroup) decorView;
group.addView(view);
}
}
}
public synchronized void handleMraidResize(DTOResizeParameters resizeParams) {
ViewParent adViewParent;
this.refreshAnimationimageView.setImageBitmap(null);
if (MMSDK.hasSetTranslationMethod()) {
if (this.view == null) {
this.view = new ResizeView(getContext());
this.view.setId(304025022);
this.view.setLayoutParams(new RelativeLayout.LayoutParams(1, 1));
this.view.setBackgroundColor(0);
}
ViewParent parent = this.view.getParent();
if (parent == null && (adViewParent = getParent()) != null && (adViewParent instanceof ViewGroup)) {
((ViewGroup) adViewParent).addView(this.view);
}
BannerBounds bounds = new BannerBounds(resizeParams);
if (!resizeParams.allowOffScreen) {
bounds.calculateOnScreenBounds();
}
int[] location = new int[2];
getLocationInWindow(location);
attachToWindow(this);
int[] locAfterAttach = new int[2];
getLocationInWindow(locAfterAttach);
setUnresizeParameters();
int xOld = location[0] - locAfterAttach[0];
int yOld = location[1] - locAfterAttach[1];
ViewGroup.LayoutParams layoutParams = getLayoutParams();
bounds.modifyLayoutParams(layoutParams);
callSetTranslationX(bounds.translationX + xOld);
callSetTranslationY(bounds.translationY + yOld);
setCloseArea(resizeParams.customClosePosition);
}
}
public synchronized void handleUnresize() {
if (MMSDK.hasSetTranslationMethod()) {
removeCloseTouchDelegate();
if (!hasDefaultResizeParams()) {
ViewGroup.LayoutParams params = getLayoutParams();
params.width = this.oldWidth;
params.height = this.oldHeight;
callSetTranslationX(0);
callSetTranslationY(0);
this.oldWidth = DEFAULT_RESIZE_PARAM_VALUES;
this.oldHeight = DEFAULT_RESIZE_PARAM_VALUES;
}
if (this.view != null) {
this.isResizing = true;
this.view.attachToContext(this);
ViewParent parent = getParent();
if (parent != null && (parent instanceof ViewGroup)) {
ViewGroup group = (ViewGroup) parent;
if (this.view.getParent() != null) {
group.removeView(this.view);
}
}
this.isResizing = false;
}
}
}
private void callSetTranslationX(int translationX) {
try {
Method method = View.class.getMethod("setTranslationX", Float.TYPE);
method.invoke(this, Integer.valueOf(translationX));
} catch (Exception e) {
}
}
private void callSetTranslationY(int translationY) {
try {
Method method = View.class.getMethod("setTranslationY", Float.TYPE);
method.invoke(this, Integer.valueOf(translationY));
} catch (Exception e) {
}
}
private void setUnresizeParameters() {
if (hasDefaultResizeParams()) {
ViewGroup.LayoutParams oldParams = getLayoutParams();
this.oldWidth = oldParams.width;
this.oldHeight = oldParams.height;
if (this.oldWidth <= 0) {
this.oldWidth = getWidth();
}
if (this.oldHeight <= 0) {
this.oldHeight = getHeight();
}
}
}
private boolean hasDefaultResizeParams() {
return this.oldWidth == DEFAULT_RESIZE_PARAM_VALUES && this.oldHeight == DEFAULT_RESIZE_PARAM_VALUES;
}
public class BannerBounds {
DTOResizeParameters resizeParams;
int translationX;
int translationY;
public BannerBounds(DTOResizeParameters resizeParams) {
this.resizeParams = resizeParams;
this.translationX = resizeParams.offsetX;
this.translationY = resizeParams.offsetY;
}
void calculateOnScreenBounds() {
calculateXBounds();
calculateYBounds();
}
private void calculateXBounds() {
int[] loc = new int[2];
MMAdView.this.getLocationInWindow(loc);
int xLoc = loc[0];
BoundsResult resultX = calculateBounds(xLoc, this.resizeParams.offsetX, this.resizeParams.width, this.resizeParams.xMax);
this.resizeParams.width = resultX.size;
this.translationX = resultX.translation;
}
private void calculateYBounds() {
int[] loc = new int[2];
MMAdView.this.getLocationInWindow(loc);
int yLoc = loc[1];
BoundsResult resultY = calculateBounds(yLoc, this.resizeParams.offsetY, this.resizeParams.height, this.resizeParams.yMax);
this.resizeParams.height = resultY.size;
this.translationY = resultY.translation;
}
private BoundsResult calculateBounds(int screenPos, int offset, int size, int max) {
int newStart = screenPos;
int newSize = size;
if (screenPos + size + offset > max) {
newStart = (max - size) + offset;
if (newStart < 0) {
newStart = 0;
newSize = max;
} else if (newStart + size > max) {
newStart = max - size;
}
} else if (offset > 0) {
newStart = offset;
}
BoundsResult result = new BoundsResult();
result.translation = newStart - screenPos;
result.size = newSize;
return result;
}
public class BoundsResult {
int size;
int translation;
private BoundsResult() {
}
}
public ViewGroup.LayoutParams modifyLayoutParams(ViewGroup.LayoutParams oldParams) {
oldParams.width = this.resizeParams.width;
oldParams.height = this.resizeParams.height;
return oldParams;
}
}
}