Use safe access to OnPreDrawListener.

Bug 32472451

It is important to remove an OnPreDrawListener from the correct
ViewTreeObserver. When a View is added to the view hierarchy, the
initial ViewTreeObserver is not active. The listener must then be
removed from the current OnPreDrawListener. When a View has been
removed from the hierarchy, it is important to remove the listener
from the orignal ViewTreeObserver.

Test: gradlew connectedCheck in fragments/

Change-Id: I8ca2e7537542e5a3ba12273f9bd6897aca88dda0
3 files changed