So Im using ImageGetter to display the images from JSON blog posts. Im getting the correct source in the log but the URL changes when it reaches setBounds. Any ideas?
Code:
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_blog_view);
Intent intent = getIntent();
Uri blogUri = intent.getData();
mPost = blogUri.toString();
mUrl = getIntent().getStringExtra("mUrl");
TextView textView = (TextView) findViewById(R.id.scrollView1);
textView.setText(Html.fromHtml(mPost, imgGetter, null));
}
private ImageGetter imgGetter = new ImageGetter(){
@Override
public Drawable getDrawable(String source){
Drawable drawable = Drawable.createFromPath(source);
try {
drawable.setBounds(0, 0, drawable.getIntrinsicWidth(), drawable.getIntrinsicHeight());
}catch (NullPointerException e){
logException(e);
}
return drawable;
}
};
The "source" before the try is
http://www.domain.com/images_blog/feature.png
but in the catch the error is:
Unable to decode stream:
java.io.FileNotFoundException: /http:/www.domain.com/images_blog/feature.png : open failed: ENOENT (No such file or directory)
This answer may help someone. I used Jsoup to extract
<Img/>
tag out of the string then i show the image inImageView
and<p>
inTextview
. Results was according to what i needed. Also i used Universal Image Loader Libaray to load images inImageView
Then i added view programmatically to the layout in my case layout was the linearlayout so i made a helper class and passed content,html string and linear layout as the parameter.add jsoup in your project.
Here some snippet.
I hope my answer will help someone.
If you have mTV (I mean TextView), you can calculate based on its dimensions (mTv.getWidth() and mTv.getHeight()) and dimension of created bitmap (bitmap.getWidth() and bitmap.getHeight()) and set these values as new dimensions of TextView (mTv).
the easiest solution is:
there is one not quite elegant way to re-layout a TextView after image downloading:
if anybody knows better solution please let me know