My use case is to have a ViewPager showing a series of PhotoView instances, where paging through the images should keep the last state of zoom and pan.
PhotoView instances are created by the PagerAdapter
public View instantiateItem(ViewGroup viewGroup, int position) {
PhotoView photoView = new PhotoView(viewGroup.getContext());
viewGroup.addView(photoView, LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT);
Glide.with(viewGroup.getContext())//
.load(getImageUri(position))
.into(photoView);
return photoView;
}
I'm attaching a "OnMatrixChangedListener" to the PhotoView and storing the PhotoViewAttacher#mSuppMatrix.
The issue I have is to find the right moment to apply to stored mSuppMatrix.
- ViewPager#onPageSelected fires regardless of the ViewGroup state, ie. the PhotoView might still be drawing, or Glide might even still be loading
- Glide#RequestListener (onResourceReady) fires when the Drawable is ready, but apparently BEFORE running PhotoView#setImageDrawable
- Even overriding PhotoView#setImageDrawable and applying the mSuppMatrix after calling super.setImageDrawable is too early, as later a layout() call results in the PhotoViewAttacher running reset(), thus invalidating the mSuppMatrix
So given a target "mSuppMatrix " holding zoom/pan information, and using the combo of ViewPager + PhotoView + Glide, what is the best listener/event handler to apply the mSuppMatrix ?