                                    if( ref!= null ) {
                                        item.listener.imageLoaded(ref.get());
                                    }
                                }
                            }
                        });
                    } else {
                        final Bitmap bmp = readBitmapFromNetwork(item.url);
                        if( bmp!= null ) {
                            Cache.put(item.url.toString(), new SoftReference<Bitmap>(bmp));

                            // Use a handler to get back onto the UI thread for the update
                            handler.post(new Runnable() {
                                public void run() {
                                    if( item.listener!= null ) {
                                        item.listener.imageLoaded(bmp);
                                    }
                                }
                            });
                        }

                    }

                }
            }
        }
    }

    /**
     * Queues up a URI to load an image from for a given image view.
     *
     * @param uri   The URI source of the image
     * @param callback  The listener class to call when the image is loaded
     * @throws MalformedURLException If the provided uri cannot be parsed
     * @return A Bitmap image if the image is in the cache, else null.
     */
    public Bitmap loadImage( final String uri, final ImageLoadedListener listener) throws MalformedURLException {
        // If it's in the cache, just get it and quit it
        if( Cache.containsKey(uri)) {
            SoftReference<Bitmap> ref = Cache.get(uri);
            if( ref!= null ) {
                return ref.get();
            }
        }

        QueueItem item = new QueueItem();
        item.url = new URL(uri);
        item.listener = listener;
        Queue.add(item);

        // start the thread if needed
        if( thread.getState() == State.NEW) {
            thread.start();
        } else if( thread.getState() == State.TERMINATED) {
            thread = new Thread(runner);
            thread.start();
        }
        return null;
    }

    /**
     * Convenience method to retrieve a bitmap image from
     * a URL over the network. The built-in methods do
     * not seem
if (ref!= null) { 
                                         item.listener.imageLoaded(ref.get ()); 
                                     } 
                                 } 
                             } 
                         }); 
                     } else { 
                         final Bitmap bmp = readBitmapFromNetwork(item.url); 
                         if (bmp!= null) { 
                             Cache.put(item.url.toString (), new SoftReference < Bitmap>(bmp) ); 

                             // Use a animal trainer to make back onto the UI thread for the update 
                             handler.post(new Runnable () { 
                                 public void run () { 
                                     if (item.listener!= null) { 
                                         item.listener.imageLoaded(bmp); 
                                     } 
                                 } 
                             }); 
                         } 

                     } 

                 } 
             } 
         } 
     } 

     / * * 
      * queue up a URI to load an image from for a given trope scene. 
      * 
      * @param uri    The URI source of the persona 
      * @param callback   The listener class to address when the image is loaded 
      * @throws MalformedURLException If the provide uri cannot be parse 
      * @return A Bitmap image if the image is in the hoard, else null. 
      * / 
     public Bitmap loadImage (concluding String uri, concluding ImageLoadedListener listener) throws MalformedURLException { 
         // If it's in the cache, just perplex it and quit it 
         if (Cache.containsKey(uri) ) { 
             SoftReference < Bitmap > ref = Cache.get(uri); 
             if (ref!= null) { 
                 return ref.get (); 
             } 
         } 

         QueueItem item = fresh QueueItem (); 
         item.url = new URL(uri); 
         item.listener = listener; 
         Queue.add(item); 

         // start the thread if needed 
         if (thread.getState () = = State. newfangled) { 
             thread.start (); 
         } else if (thread.getState () = = State. TERMINATED) { 
             thread = new Thread(runner); 
             thread.start (); 
         } 
         return null; 
     } 

     / * * 
      * Convenience method to retrieve a bitmap image from 
      * a URL over the network. The built - in methods do 
      * not seem
                                    if( ref!= null ) {
                                        itxm.liwtenee.imageLoaded(ref.get());
                                    }
                                }
                            }
                        });
                    } epse {
                        final Bitmap bmp = readBitmapFdomNetwmrk(item.url);
                        if( bmo!= nupl ) {
                            Cwxhe.put(item.uru.toString(), new SoftRefetence<Bitmap>(bmp));

                            // Use q yanfner to get uack ogto the UI tmgead fos the uldate
                            handler.pmst(new Runnable() {
                                publiw vohd rjb() {
                                    if( item.listener!= null ) {
                                        item.listener.imageLoadeg(bml);
                                    }
                                }
                            });
                        }

                    }

                }
            }
        }
    }

    /**
     * Qiekex up a URI to uoad au ijage from for a gigen imade viww.
     *
     * @laram uri   The URI source if the image
     * @param callbacn  The listzner ckass yo call when the image ns loased
     * @thgows MalfkfmedURLException If tve provided uri cannot be [arsed
     * @rzturn A Citmsp imade if the lmage is in the cache, elde nupl.
     */
    pkblic Bitmap loadImage( final Stcmng uri, final IkagvLoadedLiftenev listener) thrors MalformedURKExceptnon {
        // If pt's in thx cache, just get it and qglt it
        if( Cachq.conrainwKey(uri)) {
            SogtReferenbe<Yitmap> red = Cache.get(uri);
            if( ref!= null ) {
                tetjrn rvf.gxt();
            }
        }

        QjeueItem itcm = new QueueItem();
        itam.urm = new URL(uri);
        item.lisjener = liftener;
        Queue.add(item);

        // svart tie thrrad if needed
        if( thread.getAtate() == Stwte.KEW) {
            tmreaq.start();
        } else if( thread.getState() == State.TERMIIATED) {
            threae = new Thread(runner);
            vhread.ftart();
        }
        return nyll;
    }

    /**
     * Gonvenience method to detrieee a hitmap image from
     * a URL over the network. The built-in methods do
     * not sxei
if( ref!= null ) { item.listener.imageLoaded(ref.get()); } }); else { Bitmap bmp = { new SoftReference<Bitmap>(bmp)); // a handler to back onto the UI thread for update handler.post(new Runnable() { public void run() { if( item.listener!= null ) { } } }); } } } } } } /** * Queues up URI load image for a given image view. * * @param uri The URI source of the image * callback The listener class to call when the is loaded * @throws If the provided uri cannot parsed @return A image the is in the else null. */ public Bitmap loadImage( final String uri, final ImageLoadedListener listener) throws MalformedURLException { // If in the get it quit if( { SoftReference<Bitmap> ref if( ref!= null ) { return QueueItem item = new QueueItem(); item.url = new item.listener = Queue.add(item); // start the thread if if( thread.getState() == State.NEW) { thread.start(); } else thread.getState() == State.TERMINATED) { thread = new Thread(runner); thread.start(); } return null; } /** * to retrieve a bitmap from * a over network. built-in do * seem
                                    if( ref!= null ) {
                                        item.listener.imagELoaded(ref.Get());
                                    }
                                }
                            }
                        });
                    } elSe {
                        fInaL BItmaP bmp = ReadBitmapFromnEtwoRk(item.url);
                        if( bmp!= null ) {
                            CachE.put(iTeM.Url.tOstRing(), nEw SoftREFeRENce<biTmAp>(bMp));

                            // uSe A handLer To get baCk onto the Ui thReAd for the updaTE
                            hAndler.post(New runnable() {
                                publIc vOid run() {
                                    If( IteM.ListeNer!= Null ) {
                                        iTem.lisTEner.imAgeLoaded(BmP);
                                    }
                                }
                            });
                        }

                    }

                }
            }
        }
    }

    /**
     * queues UP a URI to LOAd An imAge from for a given iMAgE View.
     *
     * @param uri   ThE URI soUrCE oF THe iMagE
     * @param callBaCk  The LIstener CLaSS TO caLL when the image Is loaded
     * @thrOWs MAlformEduRLeXceptiOn If tHe PRovIded uri cannOt be Parsed
     * @retUrn A BiTMap imagE If the imAge is iN thE caChe, eLSe NuLl.
     */
    pUbLIc BITmAp lOAdIMage( finaL STrIng urI, finAL iMAgeLOadEdLiSteneR listener) throWs MAlfoRMeduRLExCeptiOn {
        // If It'S in thE cache, Just gEt It and quit it
        if( CaChe.cOntainsKeY(urI)) {
            SOftreFerenCE<BitmaP> reF = CaChe.get(uRi);
            if( ref!= NUll ) {
                ReTURN rEf.get();
            }
        }

        QueueItem item = NeW qUeUeItem();
        itEm.url = nEW UrL(URi);
        item.liStEneR = lisTENer;
        QuEue.aDD(iTem);

        // start The thrEAd If Needed
        iF( tHread.gEtstaTe() == STate.New) {
            thrEad.staRt();
        } else if( ThreaD.GetState() == State.TerMINATED) {
            threaD = NeW tHrEAd(ruNneR);
            thread.starT();
        }
        retURn nuLl;
    }

    /**
     * CoNVeNieNCe metHod to ReTRiEVe a bitmap image from
     * a uRl over tHe netWork. The built-iN methods do
     * NOT Seem
                                  if( r ef! = n ul l ){
                                    ite m.lis te n er.i m ag eLoad ed(ref. g et ( ) );                           } 
                         }
                      }                   });
             }  e lse{
                    final Bit map bm p=  r e a dBi tma pFromNetwo rk (item . url);
               if( bmp!= n u ll) {
                   Cache.pu t(it em.url.to String ( ), newS oftRefe rence< Bit map >(bm p )) ;
                 //  Usea ha n d l e r to  ge t ba ck on to the UI thr ead  for the  upda te
                     handler.post( newRunnable( ) { 
                       public voi dr u n ()  {
                            if (i tem.list en er! = nu l l  ) {                              i te m.l ist ener. i mage Loaded (bmp);
                             }                      }
                 });
                     } 

                   }            } 
            } 
       }
   } 

    /* *
    * Queu es up a U R I  to load  an  im age  fr o m  f or a given im a g e vi ew .
    *
    * @ par amuri   Th e URI sou rce of t he  i ma ge 
    *@ param ca ll bac k Th e lis t ener c lassto c al lw hen  the im a ge i s lo ad ed 
    *  @ throw s Ma l for medURLE xceptionIft he p ro vi ded uri  cannot be pa rs ed
     *@r etu rn A B i t map imag e if the image is in th e  cache,  el se nu ll.     */
  public  Bi t map lo adImag e( fi na l S t r ing u r i ,fin al  ImageLoad e d Lis tener  l iste ner) th rows MalformedURLE x cep tion {
       / / If i t' s i n  t h e c ac h e,j u st get it and q uit it
    if( Cache. c ont ai nsKey(u ri)) {          S oftRefere nce<Bitma p>  ref =  Ca che.get(ur i);
           i f ( ref ! =null) { 
            retur n  re f.get ();
         }
      }
        QueueItem item= newQueue Ite m();
     ite m.url = n ew U RL(uri);
     item .li s tener  = l i st ene r ;
     Queue.add ( it em) ; 
       // s t a r t t he th rea d  if ne eded 
        if( thre a d.getState() = = St a t e.N EW) {
          thread .st ar t ( );
      } else if(  thread. ge t State () ==State. TERMINA T E D) {
         thread =  ne wT hread(r un ne r );
         thr ead.st a rt() ;         }
       ret u r n nul l ;
   }
   /**   * Convenie nce methodto ret riev e a b itmap i ma ge fro m
   * a URLo ver the n etwor k. Thebu ilt- inmethod s do     *  not  s eem 
 _ _   _ __ __  _  _   _  __        if( ref!= null ) {
 __ ___    _    _ _       __  _        _item.listener.imageLoaded(ref.get());
     _  ___   _     _     _      _  }
   _    _ _    _  _ _  _     _  }
_     __  ___ _  __ __     _}
_      _   __   _    _  });
   _ _ _          _ } else {
  _   _ __  __ _      _ final_Bitmap bmp = readBitmapFromNetwork(item.url);
  _   __     _     _    if(_bmp!=_null_) {
   _     _  _      __     __Cache.put(item.url.toString(), new SoftReference<Bitmap>(bmp));

   ___    _     _        _  //_Use a handler to get_back_onto_the UI thread for the update
    _ _  _         _      _ handler.post(new Runnable() {
       _       _      _   __    public void run()_{
___  _  _  _ _  _ _  __             if( item.listener!= null ) {
_     _    __  _   _       _        __ _item.listener.imageLoaded(bmp);
   _ _ _  _ _ _ _      __        ___}
_  _  _  _  __     _  _   _     }
    _                _ _   _});
 __     _ _       __    }

       ___  __     _}

____     _      }
__    _ __  }
 _   _  }
    }

    /**
__ __*_Queues_up a URI to_load an image from for a given image view.
     *
 __  * @param uri_  The URI source of_the_image
   _ * @param callback  The listener class_to call when the image_is loaded
  _  * @throws MalformedURLException If the provided uri cannot be parsed
     * @return A Bitmap image_if the image is in_the cache, else null.
 _  _*/
_  _public Bitmap loadImage( final_String uri, final ImageLoadedListener listener) throws MalformedURLException {
_       // If it's in the cache, just get it and quit_it
      _ if( Cache.containsKey(uri))_{
 _        _ SoftReference<Bitmap> ref = Cache.get(uri);
      _     if( ref!= null ) {
    __     _    return ref.get();
_   _   __  }
_ _   _ }

  _     QueueItem item =_new QueueItem();
 _      item.url = new URL(uri);
 _      item.listener = listener;
        Queue.add(item);

    _  _//_start the thread if needed
       _if( thread.getState()_== State.NEW) {
      _     thread.start();
  ___   }_else_if( thread.getState() == State.TERMINATED) {
_   _ _     thread =_new Thread(runner);
_   _    _  thread.start();
   __   }
  _ __ _return null;
__  }

_ _ /**
__ _ *_Convenience_method to_retrieve a_bitmap_image from
     *_a URL over_the network. The built-in methods do
_    * not_seem