1
0
mirror of https://github.com/TeamNewPipe/NewPipe synced 2024-06-26 07:03:20 +00:00

Merge pull request #3920 from chdir/invisible_focus_fix

Fix lingering focus highlight overlay
This commit is contained in:
Tobias Groza 2020-07-22 14:28:47 +02:00 committed by GitHub
commit 53ffc82fe2
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -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(@NonNull 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());