private XBitmapOptions(int iamgeDefault,BitmapDisplayer bitmapDisplayer) { this.iamgeDefault = iamgeDefault; this.imageResOnLoading = iamgeDefault; this.imageResForEmptyUri = iamgeDefault; this.imageResOnFail = iamgeDefault; this.bitmapDisplayer = bitmapDisplayer; }
/** * * @param url * @param pic * @param radius 不需要缩放 * @param borderColor * @param borderWidth 不需要缩放 */ public void loadRoundBorderImage(String url, ImageView pic,int defaultImg, int radius, int borderColor, int borderWidth) { url = resizeUrl(pic, url); if (isLoad(pic,url)) { DisplayImageOptions options = BitmapOptions.getRoundBorderOpt(0, ScreenUtil.getScalePxValue(radius), borderColor, ScreenUtil.getScalePxValue(borderWidth)); BitmapDisplayer displayer = options.getDisplayer(); ImageLoader.getInstance().displayImage(url, pic,options,getRounderImageLoaderListener(displayer,defaultImg)); } }
public ImageLoadingInfo(String uri, ImageAware imageAware, ImageSize targetSize, String memoryCacheKey, DisplayImageOptions options, ImageLoadingListener listener, ImageLoadingProgressListener progressListener, ReentrantLock loadFromUriLock) { this.uri = uri; this.imageAware = imageAware; this.targetSize = targetSize; this.options = options; this.listener = listener; this.progressListener = progressListener; this.loadFromUriLock = loadFromUriLock; this.memoryCacheKey = memoryCacheKey; mFileTypeStatus = BitmapDisplayer.FILE_TYPE_UNDEFINE; mFilePath = null; }
/** * 构造图片显示的配置选项 * * @param placeHolderImgRes 默认的占位显示图片 * @param emptyUrlImgRes 空链接显示的图片 * @param failedImgRes 加载失败显示的图片 * @param cacheInMemory 是否内存缓存,图片过大,建议不要内存缓存 * @return */ private static DisplayImageOptions constructDisplayOption(String url, int placeHolderImgRes, int emptyUrlImgRes, int failedImgRes, boolean cacheInMemory, BitmapDisplayer displayer) { DisplayImageOptions.Builder bulider = new DisplayImageOptions.Builder(); bulider.cacheOnDisc(true); // 默认开启磁盘缓存 缓存在默认位置 // /sdcard/Android/data/[package_name]/cache bulider.cacheInMemory(cacheInMemory); bulider.resetViewBeforeLoading(true); bulider.bitmapConfig(Bitmap.Config.RGB_565); // bulider.displayer(new FadeInBitmapDisplayer(200));//加载动画 if (displayer != null) { bulider.displayer(displayer); } if (placeHolderImgRes > 0) { bulider.showStubImage(placeHolderImgRes); } if (emptyUrlImgRes > 0) { bulider.showImageForEmptyUri(emptyUrlImgRes); } if (failedImgRes > 0) { bulider.showImageOnFail(failedImgRes); } return bulider.build(); }
/** * 加载显示图片 * * @param imageView 显示图片的组件 * @param url 图片加载的URL * @param placeHolderImg 默认的占位显示图片 * @param emptyUrlImgRes 空链接显示的图片,不定义请置 0 * @param failedImgRes 加载失败显示的图片,不定义请置 0 * @param cacheInMemory 是否将图片缓存到内存中 (大图不建议缓存到内存中) */ public static void loadImage(ImageView imageView, String url, int placeHolderImg, int emptyUrlImgRes, int failedImgRes, boolean cacheInMemory, BitmapDisplayer displayer) { DisplayImageOptions option = constructDisplayOption(url, placeHolderImg, emptyUrlImgRes, failedImgRes, cacheInMemory, displayer); if (Strings.isEmpty(url) || (!url.endsWith(".jpg") && !url.endsWith(".jpeg") && !url.endsWith(".png") && !url.endsWith(".JPG") && !url.endsWith(".JPEG") && !url.endsWith(".PNG"))) { if (placeHolderImg != 0) { imageView.setImageResource(placeHolderImg); } return; } imageLoader.displayImage(url, imageView, option); }
public Builder displayer(BitmapDisplayer bitmapdisplayer) { if (bitmapdisplayer == null) { throw new IllegalArgumentException("displayer can't be null"); } else { q = bitmapdisplayer; return this; } }
public BitmapDisplayer getDisplayer() { return displayer; }
/** Creates default implementation of {@link BitmapDisplayer} - {@link SimpleBitmapDisplayer} */ public static BitmapDisplayer createBitmapDisplayer() { return new SimpleBitmapDisplayer(); }
public BitmapDisplayer getDisplayer() { return this.displayer; }
public static BitmapDisplayer createBitmapDisplayer() { return new SimpleBitmapDisplayer(); }
private BitmapDisplayer getDisplayer() { if (VERSION.SDK_INT >= 9) { return new FadeInBitmapDisplayer(200); } return new SimpleBitmapDisplayer(); }
public static XBitmapOptions getNewInstance(int iamgeDefault,BitmapDisplayer bitmapDisplayer) { return new XBitmapOptions(iamgeDefault,bitmapDisplayer); }
public BitmapDisplayer getBitmapDisplayer() { return bitmapDisplayer; }
/** * @param view * @param status 1-->loading 2-->failed */ private void showImage(View view, int status) { try { if (view != null && view instanceof ImageView) { boolean isShow = false; switch (status) { case 1: isShow = options.checkImageResOnLoading(); break; case 2: isShow = options.checkImageResOnFail(); break; } if (isShow) { Context context = view.getContext(); //得到Resources对象 Resources r = context.getResources(); Bitmap bmp = null; if (status == 1) { bmp = BitmapFactory.decodeResource(r, options.getImageResOnLoading()); } else if (status == 2){ bmp = BitmapFactory.decodeResource(r, options.getImageResOnFail()); } Drawable drawable = null; if (bmp != null) { switch (type) { case 0: // drawable = new BitmapDrawable(bmp); break; case 1: drawable = new CircleDrawable(bmp); break; case 2: BitmapDisplayer bitmapDisplayer = options.getBitmapDisplayer(); if (bitmapDisplayer!=null&& bitmapDisplayer instanceof RoundBorderBitmapDisplayer) drawable = ((RoundBorderBitmapDisplayer) bitmapDisplayer).getImageDrawable(new ImageViewAware((ImageView) view), bmp); break; } } if (drawable != null) { ((ImageView) view).setImageDrawable(drawable); } else { if (bmp != null) { ((ImageView) view).setImageBitmap(bmp); } } } } } catch (Exception e) { e.printStackTrace(); } }
private XImageLoaderListener getRounderImageLoaderListener(BitmapDisplayer displayer,int defaultImageRes) { return XImageLoaderListener.getNewInstance(2,XBitmapOptions.getNewInstance(defaultImageRes,displayer)); }
/** Creates default implementation of {@link com.nostra13.universalimageloader.core.display.BitmapDisplayer} - {@link com.nostra13.universalimageloader.core.display.SimpleBitmapDisplayer} */ public static BitmapDisplayer createBitmapDisplayer() { return new SimpleBitmapDisplayer(); }