【发布时间】:2011-12-08 14:14:57
【问题描述】:
我有一个画布,我在其中显示一个图像在中心。此图像是通过 url 下载的。实际上还有更多的图片要下载,这意味着如果用户点击右我必须显示下一张图片如果左,我必须从背面显示另一张图片。我有存储url图像的字符串数组。我想在后台下载上一张和下一张图片。该怎么做?
【问题讨论】:
标签: java-me midp j2mepolish midp-2.0
我有一个画布,我在其中显示一个图像在中心。此图像是通过 url 下载的。实际上还有更多的图片要下载,这意味着如果用户点击右我必须显示下一张图片如果左,我必须从背面显示另一张图片。我有存储url图像的字符串数组。我想在后台下载上一张和下一张图片。该怎么做?
【问题讨论】:
标签: java-me midp j2mepolish midp-2.0
以下是您需要考虑的一些问题,以使此要求适用于各种设备
列表还在继续.....
牢记上述一组问题,您将通过建设性的回答来解决您的问题,那就是创建一个网络 IO 管理器和一个缓存管理器。
interface NetworkIoItem {
Object sourceComponent;
public void onImageDownload(Image image) {
//Trigger the source
}
}
.
class NetworkIoManager extends Threads {
Vector pendingRequestQueue;
:
:
public void run() {
//Wait on the pending request queue
//Process all the elements in pending request queue
//and again wait on this queue
}
}
.
class CacheManager {
Vector cachedContent;
public boolean checkIfCached() {
//Check in the cachedContent whether
//this image exists if so return true;
}
public Image fetchImage() {
//Check if the image is cached
//if so return this cached image
//else push a NetworkIoItem object to
//NetworkIOManager pending queue
}
}
现在对于每个图像(当前、左或右)调用CacheManager.fetchImage(),此方法将负责为您提供缓存或从服务器下载的图像。同样的方法,如果图像没有被缓存,它会将NetworkIoItem 对象添加到NetworkIoManager pendingQueue 并下载它。下载完成后会触发NetworkIoItem.onImageDownload(...) 方法。
您可以使用J2ME Polish's Touch 功能下载NetworkIoManager 中的图像
通过使用这种方法,您将对请求 URL 进行异步图像提取。
【讨论】:
做一些类似的事情..
Thread t = new Thread(new Runnable(){
public void run() {
// Your code to download image here as you were doing earlier,
// for previous and next image
}
});
t.start();
【讨论】: