@Override protected Bitmap doInBackground(Void... params) { if (imageView == null || url == null) { return bitmap; } if (Logger.isDebug()) Log.i(LOG_TAG, "Get Header image from remote!"); try { Bitmap newBitmap = ImageUtil.getBitmapByUrl(url); /** 加入cache中* */ if (newBitmap != null) { // 生成mini图 Bitmap scaleBitmap = ImageUtil.scaleBitmapTo(newBitmap, SheJiaoMaoApplication.getSmallAvatarSize()); Bitmap roundBitmap = ImageUtil.getRoundedCornerBitmap(scaleBitmap); if (scaleBitmap != newBitmap) { scaleBitmap.recycle(); } CachedImage resultWrap = new CachedImage(roundBitmap); if (isMini) { bitmap = roundBitmap; } imageInfo.setCacheType(CachedImageKey.IMAGE_HEAD_MINI); imageCache.put(imageInfo, resultWrap); // 生成normal图 scaleBitmap = ImageUtil.scaleBitmapTo(newBitmap, SheJiaoMaoApplication.getNormalAvatarSize()); roundBitmap = ImageUtil.getRoundedCornerBitmap(scaleBitmap); scaleBitmap.recycle(); resultWrap = new CachedImage(roundBitmap); imageInfo.setCacheType(CachedImageKey.IMAGE_HEAD_NORMAL); imageCache.put(imageInfo, resultWrap); newBitmap.recycle(); if (!isMini) { bitmap = roundBitmap; } } } catch (LibException e) { if (Logger.isDebug()) Log.e(LOG_TAG, e.getMessage(), e); } return bitmap; }
@Override protected User doInBackground(Void... params) { if (image == null) { return null; } Weibo microBlog = GlobalVars.getMicroBlog(accountId); if (microBlog == null) { return null; } User user = null; try { if (image != null) { String fileExtension = FileUtil.getFileExtensionFromName(image.getName()); int size = ImageQuality.Low.getSize(); ImageQuality quality = sheJiaoMao.getImageUploadQuality(); if (quality == ImageQuality.High || GlobalVars.NET_TYPE == NetType.WIFI) { size = ImageQuality.High.getSize(); } else if (quality == ImageQuality.Middle || quality == ImageQuality.Low) { size = quality.getSize(); if (Logger.isDebug()) Log.d(TAG, "prefix size: " + size); // 对低速网络进行压缩 if (GlobalVars.NET_TYPE == NetType.MOBILE_GPRS || GlobalVars.NET_TYPE == NetType.MOBILE_EDGE) { size = ImageQuality.Low.getSize(); } } String destName = ImageCache.getTempFolder() + File.separator + System.currentTimeMillis() + "." + fileExtension; File dest = new File(destName); boolean isSuccess = ImageUtil.scaleImageFile(image, dest, size); if (isSuccess) { image = dest; } user = microBlog.updateProfileImage(image); } } catch (LibException e) { if (Logger.isDebug()) Log.e(TAG, "Task", e); resultMsg = ResourceBook.getResultCodeValue(e.getErrorCode(), context); } return user; }
public ImageLoad4HeadTask(ImageView imageView, String url, boolean isMini) { this.imageView = imageView; this.url = url; this.isMini = isMini; imageCache = (ImageCache) CacheManager.getInstance().getCache(ImageCache.class.getName()); if (StringUtil.isNotEmpty(url)) { if (isMini) { imageInfo = new CachedImageKey(url, CachedImageKey.IMAGE_HEAD_MINI); } else { imageInfo = new CachedImageKey(url, CachedImageKey.IMAGE_HEAD_NORMAL); } if ((wrap = imageCache.get(imageInfo)) != null) { bitmap = wrap.getWrap(); isHit = true; } } }