From a6f04afbc9b944ac5e4e5d4b846d173bba0c27c1 Mon Sep 17 00:00:00 2001 From: Robin Lee Date: Wed, 31 Aug 2016 13:56:46 +0100 Subject: [PATCH] Tidy up PhoneStatusBar deeply nested Runnables Change-Id: I07dae5fbe8360e467169e7d2d61492a804bcaf41 --- .../statusbar/phone/PhoneStatusBar.java | 77 ++++++++++--------- 1 file changed, 40 insertions(+), 37 deletions(-) diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/phone/PhoneStatusBar.java b/packages/SystemUI/src/com/android/systemui/statusbar/phone/PhoneStatusBar.java index d2bb40565ec4d..fc3b024541333 100644 --- a/packages/SystemUI/src/com/android/systemui/statusbar/phone/PhoneStatusBar.java +++ b/packages/SystemUI/src/com/android/systemui/statusbar/phone/PhoneStatusBar.java @@ -4654,44 +4654,47 @@ public class PhoneStatusBar extends BaseStatusBar implements DemoMode, final Runnable clickPendingViewRunnable = new Runnable() { @Override public void run() { - if (mPendingWorkRemoteInputView != null) { - final View pendingWorkRemoteInputView = mPendingWorkRemoteInputView; - ViewParent p = pendingWorkRemoteInputView.getParent(); - while (p != null) { - if (p instanceof ExpandableNotificationRow) { - final ExpandableNotificationRow row = (ExpandableNotificationRow) p; - ViewParent viewParent = row.getParent(); - if (viewParent instanceof NotificationStackScrollLayout) { - final NotificationStackScrollLayout scrollLayout = - (NotificationStackScrollLayout) viewParent; - row.makeActionsVisibile(); - row.post(new Runnable() { - @Override - public void run() { - final Runnable finishScrollingCallback = new Runnable() - { - @Override - public void run() { - mPendingWorkRemoteInputView.callOnClick(); - mPendingWorkRemoteInputView = null; - scrollLayout.setFinishScrollingCallback(null); - } - }; - if (scrollLayout.scrollTo(row)) { - // It scrolls! So call it when it's finished. - scrollLayout.setFinishScrollingCallback( - finishScrollingCallback); - } else { - // It does not scroll, so call it now! - finishScrollingCallback.run(); - } - } - }); - } - break; - } - p = p.getParent(); + final View pendingWorkRemoteInputView = mPendingWorkRemoteInputView; + if (pendingWorkRemoteInputView == null) { + return; + } + + // Climb up the hierarchy until we get to the container for this row. + ViewParent p = pendingWorkRemoteInputView.getParent(); + while (!(p instanceof ExpandableNotificationRow)) { + if (p == null) { + return; } + p = p.getParent(); + } + + final ExpandableNotificationRow row = (ExpandableNotificationRow) p; + ViewParent viewParent = row.getParent(); + if (viewParent instanceof NotificationStackScrollLayout) { + final NotificationStackScrollLayout scrollLayout = + (NotificationStackScrollLayout) viewParent; + row.makeActionsVisibile(); + row.post(new Runnable() { + @Override + public void run() { + final Runnable finishScrollingCallback = new Runnable() { + @Override + public void run() { + mPendingWorkRemoteInputView.callOnClick(); + mPendingWorkRemoteInputView = null; + scrollLayout.setFinishScrollingCallback(null); + } + }; + if (scrollLayout.scrollTo(row)) { + // It scrolls! So call it when it's finished. + scrollLayout.setFinishScrollingCallback( + finishScrollingCallback); + } else { + // It does not scroll, so call it now! + finishScrollingCallback.run(); + } + } + }); } } };