@Override public void onActivityResult(int requestCode, int resultCode, Intent data) { super.onActivityResult(requestCode, resultCode, data); InputStream imageStream = null; try { try { if (resultCode == Activity.RESULT_OK) { if (requestCode == REQUEST_CAMERA_CODE) { File profilePhotoFile = profilePhotoFile(); if (profilePhotoFile != null && profilePhotoFile.exists()) { imageStream = new FileInputStream(profilePhotoFile); profilePhotoFileChanged(imageStream); } } else if (requestCode == REQUEST_GALLERY_CODE) { Uri selectedImage = data.getData(); imageStream = getActivity().getContentResolver().openInputStream(selectedImage); profilePhotoFileChanged(imageStream); } } } finally { if (imageStream != null) { imageStream.close(); } } } catch (IOException e) { throw new RuntimeException(e); } }
@Override public void setCurrentUser(User currentUser) { super.setCurrentUser(currentUser); User user = this.getCurrentUser(); if (null != user) { CrmOperations crmOperations = crmOperationsProvider.get(); if (user.isProfilePhotoImported()) { ProfilePhoto profilePhoto = crmOperations.getUserProfilePhoto(); byte[] profilePhotoBytes = profilePhoto.getBytes(); Bitmap bm = BitmapFactory.decodeByteArray(profilePhotoBytes, 0, profilePhotoBytes.length); userProfileImageView.setImageBitmap(bm); String editYourProfilePhoto = getActivity().getString(R.string.edit_profile_photo); changeProfilePhotoButton.setText(String.format(editYourProfilePhoto, user.getFirstName())); } } }