コード例 #1
0
  private void loadProjectPhoto() {
    Bitmap bitmap = picassoCache.getPlaceholder(project.getBigPhotoUrl());
    boolean bigPhotoMustBeFetched = bitmap == null;
    if (bigPhotoMustBeFetched) {
      bitmap = picassoCache.getPlaceholder(project.getPhotoUrl());
      boolean placeholderAlreadyFetched = bitmap != null;
      if (placeholderAlreadyFetched) {
        binding.projectPhotoIv.setImageBitmap(bitmap);
      }
    }
    // Make sure that transition starts soon even if image is not ready.
    binding.projectPhotoIv.postDelayed(
        this::supportStartPostponedEnterTransition, MAX_TRANSITION_DELAY);
    Picasso.with(this)
        .load(project.getBigPhotoUrl())
        .resize(imageWidth, imageHeight)
        .onlyScaleDown()
        .centerCrop()
        .transform(PaletteAndAplaTransformation.instance())
        .into(
            binding.projectPhotoIv,
            new Callback() {
              @Override
              public void onSuccess() {
                Bitmap bitmap =
                    ((BitmapDrawable) binding.projectPhotoIv.getDrawable()).getBitmap(); // Ew!
                Palette palette = PaletteAndAplaTransformation.getPalette(bitmap);
                binding.detailsContainer.setBackgroundColor(
                    palette.getDarkVibrantColor(Color.BLACK));
                supportStartPostponedEnterTransition();
              }

              @Override
              public void onError() {
                supportStartPostponedEnterTransition();
              }
            });
  }
コード例 #2
0
  public static void launch(Activity context, Project project, View... sharedViews) {
    final Bundle options;
    if (LUtils.hasL()) {
      options = getSharedElementsBundle(context, sharedViews);
    } else {
      options = new Bundle();
    }
    Intent intent = new Intent(context, ProjectDetailsActivity.class);

    Parcelable wrapped = Parcels.wrap(project);
    intent.putExtra(EXTRA_PROJECT, wrapped);
    // Preload big photo
    Picasso.with(context).load(project.getBigPhotoUrl());
    ActivityCompat.startActivity(context, intent, options);
  }