Clear BitMap Cache - koush ion - android

i would like to clear bitmap cache but i am not sure how to clear the bit map .
I am using Koush Ion library to load the picture
try {
bitmap = Ion.with(context).load(URLimage).withBitmap().asBitmap().get();
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (ExecutionException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
i need to clear the bitmap cache everytime i click on a button.
Thanks in advance

Use Ion.getDefault(context).getCache().clear() to clear the file cache.
Use Ion.getDefault(context).getBitmapCache().clear() to clear the in-memory bitmap cache.
See the source for the respective methods at:
https://github.com/koush/AndroidAsync/blob/master/AndroidAsync/src/com/koushikdutta/async/util/FileCache.java#L292
https://github.com/koush/ion/blob/master/ion/src/com/koushikdutta/ion/bitmap/IonBitmapCache.java#L63
Ion.dump() will NOT clear the cache. It will simply print some debug information to the log. You can look up the source code for it, too.

try this may help,,i used this code for clearing my network data cache;
Ion.getDefault(context).configure().getResponseCache().clear()

Related

Android: ImageView load from URL

Tried many ways in the internet but my imageView still display blank of the image.
Wish to retrieve the image from url (download or refer it) but seems I missed out something.
I have activated the INTERNET permission in manifest.
icon.setImageResource(R.drawable.portrait_user);
try {
URL url = new URL("https://fbcdn-profile-a.akamaihd.net/hprofile-ak-xpf1/t1.0-1/c0.0.50.50/p50x50/1499583_10202305028778787_1063740680_n.jpg");
InputStream content = (InputStream)url.getContent();
Bitmap d = BitmapFactory.decodeStream(content);
icon.setImageBitmap(d);
} catch (MalformedURLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
Doing network I/O on the main application thread like this will crash your app on Android 4.0+.
Most likely, you will be better served using a third-party library that can download the image for you in the background and update the ImageView when it is ready. Picasso and Universal Image Loader are two of the more popular libraries for this.

How to set a background template to a pdf using iText library in android?

I wanna set a background Template(image) in my pdf that generated by iText Library,something like this:
Click too see the image
I tried to use something like the code below:
PdfReader reader = new PdfReader("./assets/sarbargandroid.pdf");
PdfImportedPage page = writer.getImportedPage(reader, 1);
PdfContentByte cb = writer.getDirectContent();
cb.addTemplate(page, 0.0, 0.0);
but it did not work in android because .addtemplate() methode needs some awt library!
and I tried addimage stuff like this:
private void setBackground(Chapter document) {
ByteArrayOutputStream stream = new ByteArrayOutputStream();
Bitmap bitmap = BitmapFactory.decodeResource(context.getResources(), R.drawable.sarbarg);
bitmap.compress(Bitmap.CompressFormat.JPEG , 100, stream);
Image img;
try {
img = Image.getInstance(stream.toByteArray());
img.setAbsolutePosition(0, 0);
document.add(img);
} catch (BadElementException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (MalformedURLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (DocumentException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
But it did't work correctly because the image does not fit the page and it create a pdf like this:
Click too see image
How can I do this correctly? anyone help me??
There are several things wrong with your question and that may explain why nobody answers. I'll tell you what's wrong and then maybe you can create a new question.
You say:
it did not work in android because .addtemplate() methode needs some awt library!
If the addTemplate() method needs an AWT library, then you are using iText. When working on Android, you should use iTextG: http://itextpdf.com/product/itextg
You are using PdfReader which makes people assume that you want to add a background image to an existing document. This would imply that you use PdfStamper, yet your code looks like you're using PdfWriter. That's a contradiction.
Your setBackground() method takes a Chapter as parameter to which you add an image. This is counter-intuitive:
- If you'd want to add a background image to an existing document, you'd never use the Chapter object.
- If you'd want to add a background image to every page of a PDF that is created from scratch, you'd use a page event.
Another major problem is that you create the image and add it as-is. You didn't scale it to fit the page.
Also: if you add an image in the background of an existing PDF. Parts of that image may be covered by opaque shapes that are present in the original document.

how to use guardianproject's android ffmpeg library?

First, this is my first time "playing" with ffmpeg, so please bear with me.
Generally, i dont understand ffmpeg even a little bit. So i did lot, lot of researches (and also trial & error) and i finally found this project and its library
So i was successfully created the ffmpeg and sox binary file, and i put it in the raw folder at the library project (from the link i shared).
Now, i want to use the library for my project, but i still cant do it. I tried to use some methods in the FfmpegController like combineAudioAndVideo and more but its not working (yet).
I dont post the error here since i still do my trial&errors (and the error change regularly) but im getting tired now.
EDIT
This is what i did :
private FfmpegController ffController;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
File file = new File(Uri.parse("android.resource://com.my.package/" + R.raw.test).getPath());
try {
ffController = new FfmpegController(this, file);
} catch (FileNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
MediaDesc desc = ffController.combineAudioAndVideo(R.raw.test, R.raw.musictest, "test.mp4", null);
}
The combineAudioAndVideo always error because wrong parameters. It needs MediaDesc but i dont know how to do it.
I will be very happy if you can share your working code if you have done the ffmpeg processing with this library.

how to make Android ImageView downloading image gradually

I am building an application that downloads and displays several images. Everything is going well.
But i want it display an image as soon as it downloading. Not when its done downloading. I'm pretty sure it's called something like Interlaced, since i use PNGs.
This is part of code i've done to download and display an image :
private class DownloadTask extends AsyncTask<String, Integer, Bitmap> {
#Override
protected void onPostExecute(Bitmap result) {
ivGambar.setImageBitmap(result);// ivGambar is an ImageView
pbDetail.setVisibility(View.INVISIBLE);
}
#Override
protected Bitmap doInBackground(String... pa) {
try {
return BitmapFactory.decodeStream((InputStream) new URL(pa[0])
.getContent());
} catch (MalformedURLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return null;
}
}
Is it can be done in Android? How?
Thank you.
I don't know exactly, but you can try to read progressively from the URL and then decode the stream even if it is incomplete, then doing it as you read from the stream, storing it in a buffer.
You can use URL.openStream() to get the stream, copy progressively the contents in a byte array (growing it if needed) and then use BitmapFactory.decodeByteArray to get the decoded partial bitmap (if the data is enough of course).
You could even use ByteArrayOutputStream as a buffer.
Be careful not to do this too often as it may slow down everything massively.

Check if method exists

I want to check if the method Camera.Parameters.getHorizontalViewAngle() exists on the device (it's only available from API 8 and my min SDK API is 7). I tried to use "reflection", as explained here, but it catches an error saying the number of arguments is wrong:
java.lang.IllegalArgumentException: wrong number of arguments
Anybody could help?
Camera camera;
camera = Camera.open();
Parameters params = camera.getParameters();
Method m = Camera.Parameters.class.getMethod("getHorizontalViewAngle", new Class[] {} );
float hVA = 0;
try {
m.invoke(params, hVA);
} catch (IllegalArgumentException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IllegalAccessException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (InvocationTargetException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
m.invoke(params, hVA);
should be
m.invoke(params, null);
Camera.Parameters.getHorizontalViewAngle() doesn't take any arguments and the above line has the argument hVA. If you're looking for the return variable do hVA = m.invoke(params, null);
Personally, I recommend conditional class loading, where you isolate the new-API code in a class that you only touch on a compatible device. I only use reflection for really lightweight stuff (e.g., finding the right CONTENT_URI value to use for Contacts or ContactsContract).
For example, this sample project uses two implementations of an abstract class to handle finding a Camera object -- on a Gingerbread device, it tries to use a front-facing camera.
Or, this sample project shows using the action bar on Honeycomb, including putting a custom View in it, while still maintaining backwards compatibility to older versions of Android.
I know this is a hack, but why can't you put the first call to the method in a try/catch of it's own, and nest the rest of your try/catch code in there. If the outer catch executes, the method doesn't exist.

Categories

Resources