icon
益源
2023-12-01
**
* Receives the above message, loads photos and then sends a message to
* the main thread to process them.
*/
public boolean handleMessage(Message msg) {
Iterator<FileId> iterator = mPendingRequests.values().iterator();
while (iterator.hasNext()) {
FileId id = iterator.next();
ImageHolder holder = mImageCache.get(id.mPath);
if (holder != null && holder.state == ImageHolder.NEEDED) {
// Assuming atomic behavior
holder.state = ImageHolder.LOADING;
switch (id.mCategory) {
case Apk:
Drawable icon = Util.getApkIcon(mContext, id.mPath);
holder.setImage(icon);
holder.state = BitmapHolder.LOADED;
break;
case Picture:
case Video:
boolean isVideo = id.mCategory == FileCategory.Video;
if (id.mId == 0)
id.mId = getDbId(id.mPath, isVideo);
if (id.mId == 0) {
/*for(int i = 0; i < FILE_ICON_GET_MAX_TIMES; i++){
SystemClock.sleep(FILE_ICON_GET_SLEEP_PERIOD);
id.mId = getDbId(id.mPath, isVideo);
if(id.mId != 0)
break;
}
*/
Log.e("FileIconLoader", "Fail to get dababase id for:" + id.mPath);
}
Bitmap bitmap = null;
try {
if (isVideo) {
bitmap = getVideoThumbnail(id.mId);
} else {
bitmap = getImageThumbnail(id.mId);
}
} catch (Exception e) {
Log.e(TAG, "getVideoThumbnail/getImageThumbnail fail");
}
if (bitmap != null) {
holder.setImage(bitmap);
holder.state = BitmapHolder.LOADED;
} else {
holder.state = ImageHolder.NEEDED;
}
//holder.setImage(isVideo ? getVideoThumbnail(id.mId) : getImageThumbnail(id.mId));
break;
}
//holder.state = BitmapHolder.LOADED;
mImageCache.put(id.mPath, holder);
}
}
mMainThreadHandler.sendEmptyMessage(MESSAGE_ICON_LOADED);
return true;
}
private static final int MICRO_KIND = 3;
private Bitmap getImageThumbnail(long id) {
return Images.Thumbnails.getThumbnail(mContext.getContentResolver(), id, MICRO_KIND, null);
}
private Bitmap getVideoThumbnail(long id) {
return Video.Thumbnails.getThumbnail(mContext.getContentResolver(), id, MICRO_KIND, null);
}
}
}