Gallery(LazyLoadingの使用)でProgressバーを設定するには?

私はプロジェクトでFedors LazyLoadを使用しています。

私がしたいのはギャラリーにプレースホルダ画像を表示するのではなく、このコードを変更して各画像のロード用にProgressBarを表示する方法があるかどうかを知りたい場合です。

public class ImageLoader {

MemoryCache memoryCache=new MemoryCache();
FileCache fileCache;
private Map imageViews=Collections.synchronizedMap(new WeakHashMap());

public ImageLoader(Context context){
    //Make the background thead low priority. This way it will not affect the UI performance
    photoLoaderThread.setPriority(Thread.NORM_PRIORITY-1);

    fileCache=new FileCache(context);
}
// Getting reference to the stub picture
final int stub_id=R.drawable.stub;
public void DisplayImage(String url, Activity activity, ImageView imageView)
{
    imageViews.put(imageView, url);
    Bitmap bitmap=memoryCache.get(url);
    if(bitmap!=null){
        imageView.setImageBitmap(bitmap);
    Log.e(url, " Was in cache");
    }
    else
    {
         Log.e(url, " Was NOT in cache");
        queuePhoto(url, activity, imageView);
//If images arent in cache i set the stub, instead i would like to set a ProgressBar.
        imageView.setImageResource(stub_id);
    }    
0

1 答え

注:このコードはコンパイル可能ではありません。これはあなたにアイデアを提供するだけです。

  1. Make displayImage() return some value like indicating the number of images that are in the cache

  2. I guess you are using it in a getView()

    public View getView(int position, View convertView, ViewGroup parent) {
    View vi = convertView;
    if(convertView == null){
        vi = inflater.inflate(R.layout.galitem, null);
    ImageView image=(ImageView)vi.findViewById(R.id.galimage);
    int queueLength = imageLoader.DisplayImage(data[position], activity, image);
    if(queueLength > threshold) 
    {
        Message message = new Message();   
        message.what = TestHandler.SHOW_THE_DAMN_SPINNER_PROGRESS;       
        activity.myHandler.sendMessage(message);             
    }  
    }
    
    return vi;    
    }
    

ImageLoaderを変更する

          class PhotosLoader extends Thread {
            @Override
            public void run() {
                try {
                    while (true) {
                        //thread waits until there are any images to load in the queue
                        if (photosQueue.photosToLoad.size() == 0)
                            synchronized (photosQueue.photosToLoad) {
                                photosQueue.photosToLoad.wait();
                            }
                        if (photosQueue.photosToLoad.size() != 0) {
                            PhotoToLoad photoToLoad;
                            synchronized (photosQueue.photosToLoad) {
                                photoToLoad = photosQueue.photosToLoad
                                        .pop();
                            }
                            Bitmap bmp = getBitmap(photoToLoad.url);
                            cache.put(photoToLoad.url, bmp);
                            if (((String) photoToLoad.imageView.getTag())
                                    .equals(photoToLoad.url)) {
                                BitmapDisplayer bd = new BitmapDisplayer(
                                        bmp, photoToLoad.imageView);
                                Activity a = (Activity) photoToLoad.imageView
                                        .getContext();
                                a.runOnUiThread(bd);
                                Message message = new Message();   
                                message.what = TestHandler.REMOVE_PROGRESS_BAR;       
                                a.myHandler.sendMessage(message);    
                            }

                        }
                        if (Thread.interrupted())
                            break;
                    }
                } catch (InterruptedException e) {
                    //allow thread to exit
                }
            }
        }
  1. In your activity,

     Handler myHandler = new Handler() { 
    
     ProgressDialog dialog = null; 
     public void handleMessage(Message msg) {   
     switch (msg.what) {   
     case TestHandler.SHOW_THE_DAMN_SPINNER_PROGRESS:   
              dialog  = ProgressDialog.show(this, "Working..", "Reloading cache", true,
                            false);
    
      break;   
    
        case TestHandler.REMOVE_PROGRESS_BAR: 
        dialog.dismiss();
        break;  
               }   
        super.handleMessage(msg);   
          }   
     };
    
1
追加された