4

I wrote the following code:

Glide.with(this).asBitmap().load(userImageURL).into(new CustomViewTarget<ImageView, Bitmap>(userAvatarImage) {

    @Override
    protected void onResourceCleared(@Nullable Drawable placeholder) {
        progressBarUserAvatar.setVisibility(View.GONE);
        userAvatarImage.setImageBitmap(null);
    }

    @Override
    public void onLoadFailed(@Nullable Drawable errorDrawable) {
        progressBarUserAvatar.setVisibility(View.GONE);
        final Bitmap circleLetterTile = tileProvider.getCircularLetterTile(userFullName);
        userAvatarImage.setImageBitmap(circleLetterTile);
    }

    @Override
    public void onResourceReady(@NonNull Bitmap resource, @Nullable Transition<? super Bitmap> transition) {
        progressBarUserAvatar.setVisibility(View.GONE);
        final Bitmap circleAvatarBitmap = tileProvider.getCircularImage(resource);
        userAvatarImage.setImageBitmap(circleAvatarBitmap);

        userAvatarImage.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent showProfilePictureIntent = new Intent(UserProfileActivity.this, DisplayUserImageActivity.class);
                showProfilePictureIntent.putExtra("userImageURL",userImageURL);

                final String transitionName = ViewCompat.getTransitionName(userAvatarImage);
                ActivityOptionsCompat options = ActivityOptionsCompat.makeSceneTransitionAnimation(
                        UserProfileActivity.this, userAvatarImage, transitionName);
                UserProfileActivity.this.startActivity(showProfilePictureIntent, options.toBundle());
                UserProfileActivity.this.overridePendingTransition(R.anim.fade_in, R.anim.fade_out);
            }
        });
    }
});

It basically displays the user's image using Glide. It also set a onClick listener that opens the image in large mode with black background. Currently, UserProfileActivity is empty (just loads the layout). The problem is that I can't use getTransitionName because it's possible only for api 21. I'm have to use API 16 in my project so it's a problem. What would be the easiest way to achieve it? I looked into previous topics but they all between 2013-2015 so I thought maybe there is a way to do it.

vesii
  • 2,760
  • 4
  • 25
  • 71
  • I think this [post](https://stackoverflow.com/questions/27344357/android-5-activity-transition-on-lower-api) will help you – Mutasim Jun 20 '20 at 20:49
  • @Mutasim Hi! thank you for your reply. I saw this post and tried to code shown in the Youtube video. It's really complicated and nesty. Also it's from 2014 so I thought maybe there is a better solution. – vesii Jun 20 '20 at 20:51

1 Answers1

0

This is not possible to do, using API >21. As you can refer to the official documentation here https://developer.android.com/reference/android/app/ActivityOptions#makeSceneTransitionAnimation(android.app.Activity,%20android.view.View,%20java.lang.String).

I'm not sure, why you don't have warning usage, but do for getTransitionName. Unfortunately it's not supported on early version. As another reference you can check https://www.programcreek.com/java-api-examples/?class=android.app.ActivityOptions&method=makeSceneTransitionAnimation about examples how to use transition animation.

Off topic

You can achieve animation you want by writing own tools with transition animation. It's not so easy, but it's pure view implementation, and you don't need new Android version. For the same reason, you can use Flutter (min version for which is Android 16) and make transition animation (hero animation) with few lines of codes. Because it's out of box implementation.

GensaGames
  • 5,538
  • 4
  • 24
  • 53