8370
8370

Reputation: 153

Activity Transitions + ImageView (Android)

I am using activities transitions in Android with the next:

ActivityOptionsCompat options = ActivityOptionsCompat
  .makeSceneTransitionAnimation(activity, view, "image");

activity.startActivity(intent, options.toBundle());

And I am sharing two ImageView:

In Activity A:

<android.support.v7.widget.AppCompatImageView android:id="@+id/iv_image"
   android:transitionName="image"
   android:layout_width="match_parent"
   android:scaleType="centerCrop"
   android:layout_height="150dp"/>

In Activity B:

<android.support.v7.widget.AppCompatImageView android:id="@+id/fullscreen_content"
    android:transitionName="image"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:gravity="center"/>

The problem is that when I start my Activity B, I have to fill the ImageView with a Bitmap:

String name = getIntent().getStringExtra(IMAGE_NAME_EXTRA);
ImageStorageManagement imageStorageManagement = new ImageStorageManagement(this);
Bitmap image = imageStorageManagement.decodeImage(name, 640, 480);

mContentView.setImageBitmap(image);

My ´decodeImage´ method looks like this:

public Bitmap decodeImage(String name, int reqWidth, int reqHeight) {
    File f = new File(getImagesDirectory(), name);
    String path = f.getAbsolutePath();

    final BitmapFactory.Options options = new BitmapFactory.Options();
    options.inJustDecodeBounds = true;
    BitmapFactory.decodeFile(path, options);

    options.inSampleSize = calculateInSampleSize(options, reqWidth, reqHeight);

   options.inJustDecodeBounds = false;
   return BitmapFactory.decodeFile(path, options);
  }

And of course, it freezes the app around one second and breaks the fluid movement. I have tried using Picasso, but as it loads the bitmap asynchronous, the transition is not played because there is not an image set yet when it occurs.

Having all of these, how am I supposed to read the images from the internal storage? I am pretty new to all of these animation stuff and have no idea about if I am doing it right.

+info: I have to say, the images have their original size (Big), I tried with the decoding method to make them smaller, but I am not sure it's quite a good idea.

Upvotes: 0

Views: 541

Answers (1)

ngatirauks
ngatirauks

Reputation: 799

You could probably best use a URI and then pass that between activities instead of the bitmap itself.

Especially as passing via a bundle you'll run into the 1Mb limit.

I have done the same using Picasso and Glide, by just passing URI references.

Upvotes: 1

Related Questions