summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorlinyuh <linyuh@google.com>2017-11-23 03:51:05 +0000
committerandroid-build-merger <android-build-merger@google.com>2017-11-23 03:51:05 +0000
commite027e72a1260e2145b73b80ab5c3356af953e877 (patch)
treedb634a8c4f15f081c637fb85f36f43755a3dee87
parent373105604c7bfe26790493613b03cb8e6f2a4a1f (diff)
parent5b6d823a45fe56cf9c36e5b00908831049c1d827 (diff)
Merge "Fix the crash caused by DialpadView's OnPreDrawListener."
am: 5b6d823a45 Change-Id: I329aa9a9e953d37f190144a6b3bfbad22eb82a4b
-rw-r--r--java/com/android/dialer/dialpadview/DialpadView.java18
1 files changed, 17 insertions, 1 deletions
diff --git a/java/com/android/dialer/dialpadview/DialpadView.java b/java/com/android/dialer/dialpadview/DialpadView.java
index 1d48066ad..e7e3c7cc2 100644
--- a/java/com/android/dialer/dialpadview/DialpadView.java
+++ b/java/com/android/dialer/dialpadview/DialpadView.java
@@ -503,10 +503,26 @@ public class DialpadView extends LinearLayout {
@Override
public boolean onPreDraw() {
if (!shouldAdjustKeySizes()) {
- return true; // Return true to proceed with the current drawing pass.
+ // Return true to proceed with the current drawing pass.
+ // Note that we must NOT remove this listener here. The fact that we don't need to adjust
+ // keys at the moment doesn't mean they won't need adjustments in the future. For example,
+ // when DialpadFragment is hidden, all keys are of the same size (0) and nothing needs to be
+ // done. Removing the listener will cost us the ability to adjust them when they reappear.
+ // It is only safe to remove the listener after adjusting keys for the first time. See the
+ // comment below for more details.
+ return true;
}
adjustKeySizes();
+
+ // After all keys are adjusted for the first time, no more adjustments will be needed during
+ // the rest of DialpadView's lifecycle. It is therefore safe to remove this listener.
+ // Another important reason for removing the listener is that it can be triggered AFTER a
+ // device orientation change but BEFORE DialpadView's onDetachedFromWindow() and
+ // onFinishInflate() are called, i.e., the listener will attempt to adjust the layout before
+ // it is inflated, which results in a crash.
+ getViewTreeObserver().removeOnPreDrawListener(this);
+
return false; // Return false to cancel the current drawing pass.
}