/** * 此方法直接在LruCache中增加一个键值对 * * @param targetID 用户名 * @param path 头像路径 */ public void putUserAvatar(String targetID, String path, int size) { if (path != null) { Bitmap bitmap = BitmapLoader.getBitmapFromFile(path, size, size); if (bitmap != null) { addBitmapToMemoryCache(targetID, bitmap); } } }
/** * 初始化用户头像缓存 * * @param userIDList 用户ID List * @param length 头像宽高 * @param callBack 缓存回调 */ public void setAvatarCache( final List<String> userIDList, final int length, final cacheAvatarCallBack callBack) { final Handler handler = new Handler() { @Override public void handleMessage(android.os.Message msg) { super.handleMessage(msg); if (msg.getData() != null) { callBack.onCacheAvatarCallBack(msg.getData().getInt("status", -1)); } } }; for (final String userID : userIDList) { // 若为CurrentUser,直接获取本地的头像(CurrentUser本地头像为最新) if (userID.equals(JMessageClient.getMyInfo().getUserName())) { File file = JMessageClient.getMyInfo().getAvatar(); if (file == null || !file.exists()) { continue; } else { Bitmap bitmap = BitmapLoader.getBitmapFromFile(file.getAbsolutePath(), length, length); if (null != bitmap) { mMemoryCache.put(userID, bitmap); } continue; } } else if (mMemoryCache.get(userID) != null) { continue; } else { JMessageClient.getUserInfo( userID, new GetUserInfoCallback(false) { @Override public void gotResult(int i, String s, UserInfo userInfo) { if (i == 0) { File file = userInfo.getAvatar(); if (file != null) { Bitmap bitmap = BitmapLoader.getBitmapFromFile(file.getAbsolutePath(), length, length); addBitmapToMemoryCache(userID, bitmap); } else { // Bitmap bitmap = // BitmapLoader.getBitmapFromFile(getR.drawable.head_icon, length, length); } android.os.Message msg = handler.obtainMessage(); Bundle bundle = new Bundle(); bundle.putInt("status", 0); msg.setData(bundle); msg.sendToTarget(); } } }); } } }
/** Updates the view with all relevant details about that file. */ public void updateFileDetails() { if (mFile != null && mAccount != null && mLayout == R.layout.file_details_fragment) { // set file details setFilename(mFile.getFileName()); setFiletype(DisplayUtils.convertMIMEtoPrettyPrint(mFile.getMimetype())); setFilesize(mFile.getFileLength()); if (ocVersionSupportsTimeCreated()) { setTimeCreated(mFile.getCreationTimestamp()); } setTimeModified(mFile.getModificationTimestamp()); CheckBox cb = (CheckBox) getView().findViewById(R.id.fdKeepInSync); cb.setChecked(mFile.keepInSync()); // configure UI for depending upon local state of the file // if (FileDownloader.isDownloading(mAccount, mFile.getRemotePath()) || // FileUploader.isUploading(mAccount, mFile.getRemotePath())) { FileDownloaderBinder downloaderBinder = mContainerActivity.getFileDownloaderBinder(); FileUploaderBinder uploaderBinder = mContainerActivity.getFileUploaderBinder(); if ((downloaderBinder != null && downloaderBinder.isDownloading(mAccount, mFile)) || (uploaderBinder != null && uploaderBinder.isUploading(mAccount, mFile))) { setButtonsForTransferring(); } else if (mFile.isDown()) { // Update preview if (mFile.getMimetype().startsWith("image/")) { BitmapLoader bl = new BitmapLoader(); bl.execute(new String[] {mFile.getStoragePath()}); } setButtonsForDown(); } else { setButtonsForRemote(); } } }