From 95e585cfa5c0e890e5fd7f70c637328a410fcb93 Mon Sep 17 00:00:00 2001 From: conradchen Date: Thu, 21 Jul 2022 17:27:54 +0000 Subject: [PATCH] [Slider] Fix NPE when trying to remove labels when ViewOverlay doesn't exist yet Resolves https://github.com/material-components/material-components-android/issues/2845 PiperOrigin-RevId: 462418275 (cherry picked from commit 41228376193c3a4fd39e3926cbbcfef3af0535b5) --- lib/java/com/google/android/material/slider/BaseSlider.java | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/lib/java/com/google/android/material/slider/BaseSlider.java b/lib/java/com/google/android/material/slider/BaseSlider.java index 71e0ba29c84..8a0ba9d14c8 100644 --- a/lib/java/com/google/android/material/slider/BaseSlider.java +++ b/lib/java/com/google/android/material/slider/BaseSlider.java @@ -1583,6 +1583,9 @@ protected void onVisibilityChanged(@NonNull View changedView, int visibility) { // according to the setting. if (visibility != VISIBLE) { ViewOverlayImpl contentViewOverlay = ViewUtils.getContentViewOverlay(this); + if (contentViewOverlay == null) { + return; + } for (TooltipDrawable label : labels) { contentViewOverlay.remove(label); } @@ -2372,6 +2375,7 @@ public boolean onKeyDown(int keyCode, @NonNull KeyEvent event) { return super.onKeyDown(keyCode, event); } + @Nullable private Boolean onKeyDownNoActiveThumb(int keyCode, @NonNull KeyEvent event) { switch (keyCode) { case KeyEvent.KEYCODE_TAB: @@ -2459,6 +2463,7 @@ private boolean moveFocusInAbsoluteDirection(int direction) { return moveFocus(direction); } + @Nullable private Float calculateIncrementForKey(int keyCode) { // If this is a long press, increase the increment so it will only take around 20 steps. // Otherwise choose the smallest valid increment.