|
|
@@ -28,6 +28,7 @@ public class DetailImageGetter implements Html.ImageGetter {
|
|
|
private int maxWidth;
|
|
|
private TextView textView;
|
|
|
private String content;
|
|
|
+
|
|
|
public DetailImageGetter(TextView textView, String content, int maxWidth) {
|
|
|
this.textView = textView;
|
|
|
this.content = content;
|
|
|
@@ -37,23 +38,19 @@ public class DetailImageGetter implements Html.ImageGetter {
|
|
|
|
|
|
//非表情图片尝试充满TextView显示
|
|
|
public static final boolean IMG_FULL = true;
|
|
|
+
|
|
|
@Override
|
|
|
public Drawable getDrawable(final String source) {
|
|
|
Resources resources = SheepApp.getInstance().getResources();
|
|
|
- int id = resources.getIdentifier(source, "mipmap", BuildConfig.APPLICATION_ID);
|
|
|
- if(id > 0) {
|
|
|
- Drawable drawable = resources.getDrawable(id);
|
|
|
- drawable.setBounds(0, 0, textSize, textSize);
|
|
|
- return drawable;
|
|
|
- } else {
|
|
|
+ if (source.startsWith("http")) {
|
|
|
String path = CacheImageUtil.getCacheImg(source);
|
|
|
- if(path != null){
|
|
|
+ if (path != null) {
|
|
|
Drawable drawable = Drawable.createFromPath(path);
|
|
|
- if(drawable != null){
|
|
|
+ if (drawable != null) {
|
|
|
int minimumWidth = drawable.getMinimumWidth();
|
|
|
int minimumHeight = drawable.getMinimumHeight();
|
|
|
int imgWidth, imgHeight, imgLeft = 0;
|
|
|
- if(IMG_FULL){
|
|
|
+ if (IMG_FULL) {
|
|
|
imgWidth = maxWidth;
|
|
|
imgHeight = minimumHeight * maxWidth / minimumWidth;
|
|
|
} else {
|
|
|
@@ -71,16 +68,23 @@ public class DetailImageGetter implements Html.ImageGetter {
|
|
|
return drawable;
|
|
|
}
|
|
|
}
|
|
|
- Drawable drawable = resources.getDrawable(R.drawable.loading_01);
|
|
|
- drawable.setBounds(0, 0, drawable.getIntrinsicWidth(), drawable.getIntrinsicHeight());
|
|
|
- CacheImageUtil.cacheImg(source, new Action1<File>() {
|
|
|
- @Override
|
|
|
- public void call(File file) {
|
|
|
- if(file != null)
|
|
|
- ViewUtil.setH5ImgText(textView, content, maxWidth);
|
|
|
- }
|
|
|
- });
|
|
|
- return drawable;
|
|
|
+ } else {
|
|
|
+ int id = resources.getIdentifier(source, "mipmap", BuildConfig.APPLICATION_ID);
|
|
|
+ if (id > 0) {
|
|
|
+ Drawable drawable = resources.getDrawable(id);
|
|
|
+ drawable.setBounds(0, 0, textSize, textSize);
|
|
|
+ return drawable;
|
|
|
+ }
|
|
|
}
|
|
|
+ Drawable drawable = resources.getDrawable(R.drawable.loading_01);
|
|
|
+ drawable.setBounds(0, 0, drawable.getIntrinsicWidth(), drawable.getIntrinsicHeight());
|
|
|
+ CacheImageUtil.cacheImg(source, new Action1<File>() {
|
|
|
+ @Override
|
|
|
+ public void call(File file) {
|
|
|
+ if (file != null)
|
|
|
+ ViewUtil.setH5ImgText(textView, content, maxWidth);
|
|
|
+ }
|
|
|
+ });
|
|
|
+ return drawable;
|
|
|
}
|
|
|
}
|