Question

From Users
Details

I would like to load a large/complex svg image file into my imageView. Loading the svg takes time to load on my HTC Desire S and Lenovo a60. About 5 Second and 10 seconds respectively.

Right now my app becomes unresponsive for about 5 seconds until the imageView is fully loaded

I load the image using this simple code..

 

 

svg = SVGParser.getSVGFromResource(getResources(), R.raw.gf);
    mImageView.setImageDrawable(svg.createPictureDrawable());

 

I was looking something like (webView)

 

webView.setWebViewClient(new WebViewClientEx(MainActivity.this, DEBUG) {

 @Override
        public void onPageFinished(final WebView view, String url) {
 ...........
 .............}
 });

 

which I used in my previous project...

Finally my questions:

1.) What is the best approach to make the app look responsive?

I was planning to use asynctask but don't know how to use it... Is it applicable here?

2.) Is there listener after the image is fully loaded?

My approach here is to show the progressDialog by the time I load the imageView and hide it after the imageView has fully loaded.

another other suggestions which you think is better to use for showing/hiding progressDialog ? Thanks!

Answers

    A= 1
    Answer

    Use an async task here. (a Loader would work aswell but async task is a bit easier to explain.)

     private class LoadSVGTask extends AsyncTask<Integer, Void, Drawable> {
    
      protected Drawable doInBackground(Integer... res) {
      mProgressBar.setVisibility(View.Visible);
      svg = SVGParser.getSVGFromResource(getResources(),res); 
      Drawable d = svg.createPictureDrawable();
      return d;
     }
    
     // gets executed in main thread
     protected void onPostExecute(Drawable result) {
     mProgressBar.setVisibility(View.Gone);
         mImageView.setImageDrawable(result);
     }
    }

    Launch the Task with:

    new LoaderSVGTask().execute(R.raw.gf, null, null);

Give  Answer

Login for give Answer