正在查看: Clash Legends v0.0.1 应用的 URLImageParser.java JAVA 源代码文件
本页面展示 JAVA 反编译生成的源代码文件,支持语法高亮显示。 仅供安全研究与技术分析使用,严禁用于任何非法用途。请遵守相关法律法规。
正在查看: Clash Legends v0.0.1 应用的 URLImageParser.java JAVA 源代码文件
本页面展示 JAVA 反编译生成的源代码文件,支持语法高亮显示。 仅供安全研究与技术分析使用,严禁用于任何非法用途。请遵守相关法律法规。
package com.clash.legends.utils;
import android.content.Context;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.drawable.BitmapDrawable;
import android.graphics.drawable.Drawable;
import android.os.AsyncTask;
import android.text.Html;
import android.util.Base64;
import android.view.View;
import java.io.InputStream;
import java.net.URL;
public class URLImageParser implements Html.ImageGetter {
View container;
Context context;
public URLImageParser(View container, Context context) {
this.context = context;
this.container = container;
}
@Override
public Drawable getDrawable(String source) {
if (source.matches("data:image.*base64.*")) {
String base_64_source = source.replaceAll("data:image.*base64", "");
byte[] data = Base64.decode(base_64_source, 0);
Bitmap bitmap = BitmapFactory.decodeByteArray(data, 0, data.length);
Drawable image = new BitmapDrawable(this.context.getResources(), bitmap);
image.setBounds(0, 0, image.getIntrinsicWidth() + 0, image.getIntrinsicHeight() + 0);
return image;
}
URLDrawable urlDrawable = new URLDrawable();
ImageGetterAsyncTask asyncTask = new ImageGetterAsyncTask(urlDrawable);
asyncTask.execute(source);
return urlDrawable;
}
public class ImageGetterAsyncTask extends AsyncTask<String, Void, Drawable> {
URLDrawable urlDrawable;
public ImageGetterAsyncTask(URLDrawable d) {
this.urlDrawable = d;
}
@Override
public Drawable doInBackground(String... params) {
String source = params[0];
return fetchDrawable(source);
}
@Override
public void onPostExecute(Drawable result) {
this.urlDrawable.setBounds(0, 0, result.getIntrinsicWidth() + 0, result.getIntrinsicHeight() + 0);
this.urlDrawable.drawable = result;
URLImageParser.this.container.invalidate();
}
public Drawable fetchDrawable(String urlString) {
try {
InputStream is = (InputStream) new URL(urlString).getContent();
Drawable drawable = Drawable.createFromStream(is, "src");
drawable.setBounds(0, 0, drawable.getIntrinsicWidth() + 0, drawable.getIntrinsicHeight() + 0);
return drawable;
} catch (Exception e) {
return null;
}
}
}
}