@Override protected Bitmap doInBackground(Object... params) { iv = (ImageView) params[0]; thumbnailPath = (String) params[1]; localFullSizePath = (String) params[2]; ctx = (Context) params[3]; remotePath = (String) params[4]; Bitmap result = ImageUtils.decodeScaleImage(localFullSizePath, 160, 160); if (result == null && remotePath != null) { OSSData avatar = OssManager.getInstance().downLoadData(remotePath); try { byte[] data = avatar.get(); if (data != null) { result = BitmapFactory.decodeByteArray(data, 0, data.length); ImageCache.getInstance().put(localFullSizePath, result); result = ImageUtils.decodeScaleImage(localFullSizePath, 160, 160); } } catch (OSSException e) { e.printStackTrace(); return null; } } return result; }
@Override protected void onPostExecute(Bitmap result) { if (result != null) { iv.setImageBitmap(result); ImageCache.getInstance().put(thumbnailPath, result); iv.setOnClickListener( new OnClickListener() { @Override public void onClick(View v) { if (thumbnailPath != null) { Intent intent = new Intent(ctx, ShowBigImgActivity.class); File file = new File(localFullSizePath); if (file.exists()) { Uri uri = Uri.fromFile(file); intent.putExtra("uri", uri); } else { // The local full size pic does not exist yet. // ShowBigImage needs to download it from the server // first intent.putExtra("remotepath", remotePath); } /*if (message != null && message.direct == EMMessage.Direct.RECEIVE && !message.isAcked) { message.isAcked = true; try { // 看了大图后发个已读回执给对方 EMChatManager.getInstance().ackMessageRead(message.getFrom(), message.getMsgId()); } catch (Exception e) { e.printStackTrace(); } }*/ ctx.startActivity(intent); } } }); } }