4399游戏盒 v7.2.1.31版本的 MD5 值为:951717f45e3fda95c8a358caf4ca93e1
以下内容为反编译后的 ImageProvide.java 源代码,内容仅作参考
package com.m4399.support.utils;
import android.animation.ObjectAnimator;
import android.content.Context;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.drawable.Drawable;
import android.net.Uri;
import android.os.Build;
import android.text.TextUtils;
import android.view.View;
import android.widget.ImageView;
import com.bumptech.glide.GenericTransitionOptions;
import com.bumptech.glide.Glide;
import com.bumptech.glide.Priority;
import com.bumptech.glide.RequestBuilder;
import com.bumptech.glide.RequestManager;
import com.bumptech.glide.integration.webp.decoder.WebpDrawable;
import com.bumptech.glide.integration.webp.decoder.WebpDrawableTransformation;
import com.bumptech.glide.load.DataSource;
import com.bumptech.glide.load.Key;
import com.bumptech.glide.load.MultiTransformation;
import com.bumptech.glide.load.engine.DiskCacheStrategy;
import com.bumptech.glide.load.engine.GlideException;
import com.bumptech.glide.load.model.GlideUrl;
import com.bumptech.glide.load.model.LazyHeaders;
import com.bumptech.glide.load.resource.bitmap.BitmapTransformation;
import com.bumptech.glide.load.resource.bitmap.CenterCrop;
import com.bumptech.glide.load.resource.bitmap.FitCenter;
import com.bumptech.glide.request.RequestListener;
import com.bumptech.glide.request.RequestOptions;
import com.bumptech.glide.request.target.Target;
import com.bumptech.glide.request.transition.ViewPropertyTransition;
import com.bumptech.glide.signature.ObjectKey;
import com.framework.config.Config;
import com.framework.config.SysConfigKey;
import com.framework.manager.network.NetworkStatusManager;
import com.framework.utils.ActivityStateUtils;
import com.framework.utils.UrlUtils;
import com.igexin.push.config.c;
import com.m4399.support.R;
import java.io.File;
import java.util.UUID;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.TimeoutException;
import rx.Observable;
import rx.android.schedulers.AndroidSchedulers;
import rx.functions.Action1;
import rx.functions.Func1;
import rx.schedulers.Schedulers;
import timber.log.Timber;
public class ImageProvide {
private static IUrlIntercepter gdT;
private BitmapTransformation[] VA;
private float VH;
private int Vv;
private int gdP;
private ImageRequestListener gdQ;
private String gdR;
private Key gdS;
protected Context mContext;
protected File mFile;
protected String mImageUrl;
protected Drawable mPlaceholderDrawable;
protected int mPlaceholderId;
private Uri mUri;
private boolean Vw = true;
private boolean Vx = false;
private boolean Vy = true;
private boolean Vz = true;
private boolean VB = false;
private int VC = 0;
private int VD = 0;
private int VE = -1;
private int VF = 0;
private Priority VI = Priority.NORMAL;
private boolean VJ = false;
public interface IUrlIntercepter {
String onIntercept(String str);
}
public interface ImageRequestListener<R> {
void onBefore();
boolean onException(Exception exc);
boolean onResourceReady(R r, boolean z, boolean z2);
}
public ImageProvide(Context context) {
this.mContext = context;
}
public static void setUrlIntercepter(IUrlIntercepter iUrlIntercepter) {
gdT = iUrlIntercepter;
}
public static ImageProvide with(Context context) {
return new ImageProvide(context);
}
public ImageProvide load(String str) {
IUrlIntercepter iUrlIntercepter = gdT;
if (iUrlIntercepter != null) {
this.mImageUrl = iUrlIntercepter.onIntercept(str);
} else {
this.mImageUrl = str;
}
return this;
}
public ImageProvide load(File file) {
this.mFile = file;
return this;
}
public ImageProvide load(Uri uri) {
this.mUri = uri;
return this;
}
public ImageProvide asBitmap() {
this.VF = 1;
return this;
}
public ImageProvide asGif() {
this.VF = 2;
return this;
}
public ImageProvide withSignatureKey(Key key) {
this.gdS = key;
return this;
}
public ImageProvide asDrawable() {
this.VF = 3;
return this;
}
public ImageProvide asFile() {
this.VF = 4;
return this;
}
public ImageProvide placeholder(int i) {
this.mPlaceholderId = i;
return this;
}
public ImageProvide placeholder(Drawable drawable) {
this.mPlaceholderDrawable = drawable;
return this;
}
public ImageProvide error(int i) {
this.Vv = i;
return this;
}
public ImageProvide diskCacheable(boolean z) {
this.Vw = z;
return this;
}
public ImageProvide isOnlyCacheSource(boolean z) {
this.Vx = z;
return this;
}
public ImageProvide memoryCacheable(boolean z) {
this.Vy = z;
return this;
}
public ImageProvide animate(boolean z) {
this.VB = z;
return this;
}
public ImageProvide override(int i, int i2) {
this.VC = i;
this.VD = i2;
return this;
}
public ImageProvide rotateTrans(int i) {
this.gdP = i;
return this;
}
public ImageProvide listener(ImageRequestListener imageRequestListener) {
this.gdQ = imageRequestListener;
return this;
}
public ImageProvide fitCenter() {
this.VE = 2;
return this;
}
public ImageProvide centerCrop() {
this.VE = 1;
return this;
}
public ImageProvide transform(BitmapTransformation... bitmapTransformationArr) {
this.VA = bitmapTransformationArr;
return this;
}
public ImageProvide wifiLoad(boolean z) {
this.Vz = z;
return this;
}
public ImageProvide thumbnail(float f) {
this.VH = f;
return this;
}
public ImageProvide retryUrl(String str) {
this.gdR = str;
return this;
}
public ImageProvide priority(Priority priority) {
if (priority != null) {
this.VI = priority;
}
return this;
}
public ImageProvide into(ImageView imageView) {
if (imageView == null) {
return this;
}
imageView.setTag(R.id.glide_image_url, this.mImageUrl);
RequestBuilder requestBuilder = null;
try {
requestBuilder = requestPrepare();
} catch (Throwable th) {
Timber.e(th.toString(), new Object[0]);
}
if (requestBuilder == null) {
int i = this.Vv;
if (i > 0) {
imageView.setImageResource(i);
} else {
int i2 = this.mPlaceholderId;
if (i2 > 0) {
imageView.setImageResource(i2);
} else {
Drawable drawable = this.mPlaceholderDrawable;
if (drawable != null) {
imageView.setImageDrawable(drawable);
}
}
}
} else {
requestBuilder.into(imageView);
}
return this;
}
public ImageProvide into(Target target) {
RequestBuilder requestPrepare = requestPrepare();
if (requestPrepare != null) {
requestPrepare.into((RequestBuilder) target);
}
return this;
}
public ImageProvide into(int i, int i2) {
RequestBuilder requestPrepare;
if (i > 0 && i2 > 0 && (requestPrepare = requestPrepare()) != null) {
requestPrepare.into(i, i2);
}
return this;
}
public File downloadFile() throws InterruptedException, ExecutionException, TimeoutException {
if (this.VC == 0) {
this.VC = Integer.MIN_VALUE;
}
if (this.VD == 0) {
this.VD = Integer.MIN_VALUE;
}
RequestBuilder eP = eP(true);
if (eP == null) {
return null;
}
return eP.downloadOnly(this.VC, this.VD).get(60L, TimeUnit.SECONDS);
}
public ImageProvide dontAnimate(boolean z) {
this.VJ = z;
return this;
}
public void asyncDownload() {
Observable.just("").observeOn(Schedulers.io()).map(new Func1<String, File>() {
@Override
public File call(String str) {
try {
return ImageProvide.this.downloadFile();
} catch (InterruptedException e) {
e.printStackTrace();
return null;
} catch (ExecutionException e2) {
e2.printStackTrace();
return null;
} catch (TimeoutException e3) {
e3.printStackTrace();
return null;
}
}
}).observeOn(AndroidSchedulers.mainThread()).subscribe(new Action1<File>() {
@Override
public void call(File file) {
if (ImageProvide.this.gdQ != null) {
if (ImageProvide.this.VF != 1) {
ImageProvide.this.gdQ.onResourceReady(file, false, true);
return;
}
Bitmap bitmap = null;
try {
bitmap = BitmapFactory.decodeFile(file.getAbsolutePath());
} catch (Throwable th) {
th.printStackTrace();
}
ImageProvide.this.gdQ.onResourceReady(bitmap, false, true);
}
}
});
}
private RequestBuilder eP(boolean z) {
Context context;
RequestBuilder asFile;
int i;
if ((TextUtils.isEmpty(this.mImageUrl) && this.mFile == null && this.mUri == null) || (context = this.mContext) == null || ActivityStateUtils.isDestroy(context)) {
return null;
}
if (this.Vz && !TextUtils.isEmpty(this.mImageUrl) && UrlUtils.isHttpUrl(this.mImageUrl)) {
boolean booleanValue = ((Boolean) Config.getValue(SysConfigKey.IS_WIFI_LOAD_IMAGE)).booleanValue();
if (!(NetworkStatusManager.getCurrentNetwork().getNetworkType() == 999) && booleanValue) {
return null;
}
}
RequestManager with = Glide.with(this.mContext);
if (z || (i = this.VF) == 4) {
asFile = with.asFile();
} else if (i == 1) {
asFile = with.asBitmap();
} else if (i == 2) {
asFile = with.asGif();
} else if (i == 3) {
asFile = with.asDrawable();
} else {
asFile = with.asDrawable();
}
RequestOptions requestOptions = new RequestOptions();
Key key = this.gdS;
if (key != null) {
requestOptions.signature(key);
}
asFile.apply(requestOptions);
if (!TextUtils.isEmpty(this.mImageUrl)) {
if (UrlUtils.isHttpUrl(this.mImageUrl)) {
if (!TextUtils.isEmpty(this.gdR)) {
asFile.error(Glide.with(this.mContext).load((Object) new GlideUrl(this.gdR, new LazyHeaders.Builder().addHeader("referer", "http://www.4399.com").build())));
}
asFile.load((Object) new GlideUrl(this.mImageUrl, new LazyHeaders.Builder().addHeader("referer", "http://www.4399.com").build()));
} else {
asFile.load(this.mImageUrl);
}
} else {
Uri uri = this.mUri;
if (uri != null) {
asFile.load(uri);
} else {
asFile.load(this.mFile);
}
}
ImageRequestListener imageRequestListener = this.gdQ;
if (imageRequestListener != null) {
imageRequestListener.onBefore();
asFile.listener(new RequestListener<Object>() {
@Override
public boolean onLoadFailed(GlideException glideException, Object obj, Target<Object> target, boolean z2) {
return ImageProvide.this.gdQ.onException(glideException);
}
@Override
public boolean onResourceReady(Object obj, Object obj2, Target<Object> target, DataSource dataSource, boolean z2) {
return ImageProvide.this.gdQ.onResourceReady(obj, dataSource == DataSource.MEMORY_CACHE, z2);
}
});
}
return asFile;
}
public RequestBuilder requestPrepare() {
int i;
RequestBuilder eP = eP(false);
if (eP == null) {
return null;
}
RequestOptions requestOptions = new RequestOptions();
Key key = this.gdS;
if (key != null) {
requestOptions.signature(key);
}
if (this.Vw) {
if (this.Vx) {
requestOptions.diskCacheStrategy(DiskCacheStrategy.DATA);
} else {
requestOptions.diskCacheStrategy(DiskCacheStrategy.ALL);
}
} else {
requestOptions.diskCacheStrategy(DiskCacheStrategy.NONE).signature(new ObjectKey(UUID.randomUUID().toString()));
}
requestOptions.skipMemoryCache(!this.Vy);
int i2 = this.VC;
if (i2 != 0 && (i = this.VD) != 0) {
requestOptions.override(i2, i);
}
int i3 = this.gdP;
if (i3 > 0) {
requestOptions.transform(new GlideCornersTransform(i3, 15, 1));
}
int i4 = this.VE;
if (i4 == 2) {
requestOptions.transform(Bitmap.class, new FitCenter());
requestOptions.transform(WebpDrawable.class, new WebpDrawableTransformation(new FitCenter()));
} else if (i4 == 1) {
requestOptions.transform(Bitmap.class, new CenterCrop());
requestOptions.transform(WebpDrawable.class, new WebpDrawableTransformation(new CenterCrop()));
}
float f = this.VH;
if (f > 0.0f) {
eP.thumbnail(f);
}
if (this.VB) {
eP.transition(GenericTransitionOptions.with(new ViewPropertyTransition.Animator() {
@Override
public void animate(View view) {
if (Build.VERSION.SDK_INT >= 11) {
view.setAlpha(0.0f);
ObjectAnimator ofFloat = ObjectAnimator.ofFloat(view, "alpha", 0.0f, 1.0f);
ofFloat.setDuration(c.j);
ofFloat.start();
}
}
}));
} else {
eP.transition(GenericTransitionOptions.withNoTransition());
}
if (this.VJ) {
requestOptions.dontAnimate();
}
int i5 = this.mPlaceholderId;
if (i5 > 0) {
requestOptions.placeholder(i5);
try {
if (this.mPlaceholderDrawable == null && this.mContext != null) {
this.mPlaceholderDrawable = this.mContext.getResources().getDrawable(this.mPlaceholderId);
}
} catch (Throwable th) {
Timber.e(th.toString(), new Object[0]);
}
}
Drawable drawable = this.mPlaceholderDrawable;
if (drawable != null) {
requestOptions.placeholder(drawable);
}
int i6 = this.Vv;
if (i6 > 0) {
requestOptions.error(i6);
}
requestOptions.priority(this.VI);
BitmapTransformation[] bitmapTransformationArr = this.VA;
if (bitmapTransformationArr != null) {
if (bitmapTransformationArr.length > 1) {
requestOptions.transform(Bitmap.class, new MultiTransformation(bitmapTransformationArr));
requestOptions.transform(WebpDrawable.class, new WebpDrawableTransformation(new MultiTransformation(this.VA)));
} else {
requestOptions.transform(Bitmap.class, bitmapTransformationArr[0]);
requestOptions.transform(WebpDrawable.class, new WebpDrawableTransformation(this.VA[0]));
}
}
eP.apply(requestOptions);
return eP;
}
public void clear(View view) {
if (ActivityStateUtils.isDestroy(this.mContext)) {
return;
}
Glide.with(this.mContext).clear(view);
}
}