private void checkDrawable ( ) { Drawable drawable = mView . getDrawable ( ) ; if ( mDrawable != drawable ) { /* get the latest View size and ensure that it's been measured */ mViewWidth = mView . getWidth ( ) ; mViewHeight = mView . getHeight ( ) ; if ( mViewWidth > 0 && mViewHeight > 0 ) { mDrawable = drawable ; // don't save until now so above is repeated until measured if ( mDrawable != null ) { mDrawableWidth = mDrawable . getIntrinsicWidth ( ) ; mDrawableHeight = mDrawable . getIntrinsicHeight ( ) ; if ( mDrawableWidth > 0 && mDrawableHeight > 0 ) { // e.g. colors don't have size float widthRatio = ( float ) mViewWidth / mDrawableWidth ; float heightRatio = ( float ) mViewHeight / mDrawableHeight ; mScale = widthRatio > heightRatio ? widthRatio : heightRatio ; } else { // nothing to scale, ensure matrix is skipped mScale = 0.0f ; } } } else { // don't update matrix until View is measured mScale = 0.0f ; } reset ( ) ; } }
Check if the ImageView has a new Drawable and calculate the new scaling if it does .