From 6e73e0b395e71f9c30afb1e0d4390ac80b389170 Mon Sep 17 00:00:00 2001 From: Alexander-- Date: Wed, 22 Jul 2020 06:07:30 +0659 Subject: [PATCH 1/3] Use View.isShown() to avoid focus overlay glitches A View can become focused while being invisible, if it's parent is invisible. Use global draw listener and View.isShown() to catch such cases. --- .../newpipe/views/FocusOverlayView.java | 31 ++++++------------- 1 file changed, 9 insertions(+), 22 deletions(-) diff --git a/app/src/main/java/org/schabi/newpipe/views/FocusOverlayView.java b/app/src/main/java/org/schabi/newpipe/views/FocusOverlayView.java index 1c868f66a..3d9dbc16a 100644 --- a/app/src/main/java/org/schabi/newpipe/views/FocusOverlayView.java +++ b/app/src/main/java/org/schabi/newpipe/views/FocusOverlayView.java @@ -74,44 +74,26 @@ public final class FocusOverlayView extends Drawable implements @Override public void onGlobalFocusChanged(final View oldFocus, final View newFocus) { - int l = focusRect.left; - int r = focusRect.right; - int t = focusRect.top; - int b = focusRect.bottom; - - if (newFocus != null && newFocus.getWidth() > 0 && newFocus.getHeight() > 0) { - newFocus.getGlobalVisibleRect(focusRect); - + if (newFocus != null) { focused = new WeakReference<>(newFocus); } else { - focusRect.setEmpty(); - focused = null; } - if (l != focusRect.left || r != focusRect.right - || t != focusRect.top || b != focusRect.bottom) { - invalidateSelf(); - } - - focused = new WeakReference<>(newFocus); + updateRect(); animator.sendEmptyMessageDelayed(0, 1000); } private void updateRect() { - if (focused == null) { - return; - } - - View focusedView = this.focused.get(); + View focusedView = focused == null ? null : this.focused.get(); int l = focusRect.left; int r = focusRect.right; int t = focusRect.top; int b = focusRect.bottom; - if (focusedView != null) { + if (focusedView != null && isShown(focusedView)) { focusedView.getGlobalVisibleRect(focusRect); } else { focusRect.setEmpty(); @@ -123,6 +105,10 @@ public final class FocusOverlayView extends Drawable implements } } + private boolean isShown(final View view) { + return view.getWidth() != 0 && view.getHeight() != 0 && view.isShown(); + } + @Override public void onDraw() { updateRect(); @@ -223,6 +209,7 @@ public final class FocusOverlayView extends Drawable implements observer.addOnGlobalFocusChangeListener(overlay); observer.addOnGlobalLayoutListener(overlay); observer.addOnTouchModeChangeListener(overlay); + observer.addOnDrawListener(overlay); overlay.setCurrentFocus(decor.getFocusedChild()); From 801267df189455ad43c8aeaf546fe3d3cdcafcd7 Mon Sep 17 00:00:00 2001 From: Alexander-- Date: Wed, 22 Jul 2020 07:57:04 -0400 Subject: [PATCH 2/3] Add @NonNull annotation to method argument Co-authored-by: Tobias Groza --- .../main/java/org/schabi/newpipe/views/FocusOverlayView.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/src/main/java/org/schabi/newpipe/views/FocusOverlayView.java b/app/src/main/java/org/schabi/newpipe/views/FocusOverlayView.java index 3d9dbc16a..bd5ae10e8 100644 --- a/app/src/main/java/org/schabi/newpipe/views/FocusOverlayView.java +++ b/app/src/main/java/org/schabi/newpipe/views/FocusOverlayView.java @@ -105,7 +105,7 @@ public final class FocusOverlayView extends Drawable implements } } - private boolean isShown(final View view) { + private boolean isShown(@NonNull final View view) { return view.getWidth() != 0 && view.getHeight() != 0 && view.isShown(); } From 185a5fad88786d6f6736e369e262c668dd36fad9 Mon Sep 17 00:00:00 2001 From: wb9688 Date: Thu, 23 Jul 2020 13:24:48 +0200 Subject: [PATCH 3/3] Disable shrinkResources --- app/build.gradle | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/build.gradle b/app/build.gradle index b77e6c986..c2083440b 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -50,7 +50,7 @@ android { // TODO: update Gradle version release { minifyEnabled true - shrinkResources true + shrinkResources false proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' archivesBaseName = 'app' }