com.google.android.gms.common.util.IOUtils Java Examples

The following examples show how to use com.google.android.gms.common.util.IOUtils. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: EditProfileFragment.java    From mollyim-android with GNU General Public License v3.0 5 votes vote down vote up
@Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
  super.onActivityResult(requestCode, resultCode, data);

  if (requestCode == REQUEST_CODE_SELECT_AVATAR && resultCode == RESULT_OK) {

    if (data != null && data.getBooleanExtra("delete", false)) {
      viewModel.setAvatar(null);
      avatar.setImageDrawable(new ResourceContactPhoto(R.drawable.ic_camera_solid_white_24).asDrawable(requireActivity(), getResources().getColor(R.color.grey_400)));
      return;
    }

    SimpleTask.run(() -> {
      try {
        Media       result = data.getParcelableExtra(AvatarSelectionActivity.EXTRA_MEDIA);
        InputStream stream = BlobProvider.getInstance().getStream(requireContext(), result.getUri());

        return IOUtils.readInputStreamFully(stream);
      } catch (IOException ioException) {
        Log.w(TAG, ioException);
        return null;
      }
    },
    (avatarBytes) -> {
      if (avatarBytes != null) {
        viewModel.setAvatar(avatarBytes);
        GlideApp.with(EditProfileFragment.this)
                .load(avatarBytes)
                .skipMemoryCache(true)
                .diskCacheStrategy(DiskCacheStrategy.NONE)
                .circleCrop()
                .into(avatar);
      } else {
        Toast.makeText(requireActivity(), R.string.CreateProfileActivity_error_setting_profile_photo, Toast.LENGTH_LONG).show();
      }
    });
  }
}
 
Example #2
Source File: YTutils.java    From YTPlayer with GNU General Public License v3.0 5 votes vote down vote up
private static void copy(Context context, Uri srcUri, File dstFile) {
    try {
        InputStream inputStream = context.getContentResolver().openInputStream(srcUri);
        if (inputStream == null) return;
        OutputStream outputStream = new FileOutputStream(dstFile);
        IOUtils.copyStream(inputStream, outputStream);
        inputStream.close();
        outputStream.close();
    } catch (IOException e) {
        e.printStackTrace();
    }
}