As mentioned in the question, when I was going through the Sourcecode of android ImageView I saw the variable private Matrix mDrawMatrix = null;
which has class level scope and the value of the variable is again assigned to a final variable in a member function(final Matrix matrix = mDrawMatrix;)
. Here is the function ,
private boolean isFilledByImage() {
if (mDrawable == null) {
return false;
}
final Rect bounds = mDrawable.getBounds();
final Matrix matrix = mDrawMatrix;
if (matrix == null) {
return bounds.left <= 0 && bounds.top <= 0 && bounds.right >= getWidth()
&& bounds.bottom >= getHeight();
} else if (matrix.rectStaysRect()) {
final RectF boundsSrc = mTempSrc;
final RectF boundsDst = mTempDst;
boundsSrc.set(bounds);
matrix.mapRect(boundsDst, boundsSrc);
return boundsDst.left <= 0 && boundsDst.top <= 0 && boundsDst.right >= getWidth()
&& boundsDst.bottom >= getHeight();
} else {
// If the matrix doesn't map to a rectangle, assume the worst.
return false;
}
}
the value of mMatrix is again assigned to a final variable inside the function. Is there any advantage in assigning a variable like that.
99% of us don't know who wrote the code for image view, But if it is a coding practice or if it has any advantages or if someone have an explanation :-) please share it. Thanks in advance from a curious coder. :-)