HttpQueue : 실제 구현된 것과는 다른 명칭이지만, 큐보다는 스택에 가깝다.
What this snippet does is the following:
- Given a HTTPThread and a priority, insert it into the queue appropriately
(higher priority means it goes in the front of the queue) - Pull an HTTPThread off the queue (front of the line) and run it
- When that thread is done, let the Handler know so that the HTTPThread can be notified that it's done
- Go back to step one.
This class is very simple--any first-year CS student should be able to understand what it does and why it works.
If you don't understand it, however, please let me know and I can clarify.
HttpThread
HTTPThread is also very simple--it's a subclass of a standard Java thread which,
given a target URL and a local file path, ( 목적지 주소 와 저장 파일 폴더 )
will download the remote file to the local file ( 리모트 파일을 로컬파일로 다운로드 한다.)
and notify the Handler when it's done.
That's it.
RemoteView
RemoteImageView is a subclass of the standard ImageView widget, but with extra functionality.
To summarize:
- Display a given local image as a placeholder
- See if the image has already been cached so that we can skip the network. If so, replace the image and finish.
- If not, put in a request to load a given URL.
- Wait patiently.
- Once the image has been downloaded, the Handler will notify the RemoteImageView to load the now-cached image.
LazyAdapter
To manage all of these interactions, we have the final piece of the puzzle:
LazyAdapter. The relevant portion is very small:
Alright, so what we have in the first part is simply code to determine whether or not
we're flinging and see if we should load the image or not (when performing a "fling",
we don't want to load since those images won't matter in about half a second :-).
setViewImage(), however, is important because it is called when the Adapter tries to load the desired image.
This behavior is overridden to tell the RemoteImageView to get in line and start getting loaded.
We also replace the image with a placeholder since views are recycled and
we don't want to display a recycled image while the new one downloads.
http://evancharlton.com/thoughts/lazy-loading-images-in-a-listview/ Evan Charlton
'0.일반개발' 카테고리의 다른 글
네이버 Flash 2010 04 (0) | 2010.09.13 |
---|---|
안드로이드 3차원 좌표계 (0) | 2010.09.13 |
안드로이드에서 SQLite DB 사용하기 (0) | 2010.09.10 |
멀티터치 (0) | 2010.09.10 |
SurfaceView (0) | 2010.09.09 |