Skip to content

Commit 653b33b

Browse files
committed
FocusOverlayView: Avoid accessing restricted API
Signed-off-by: Aayush Gupta <aayushgupta219@gmail.com>
1 parent 5eb5f75 commit 653b33b

2 files changed

Lines changed: 40 additions & 2 deletions

File tree

app/src/main/java/org/schabi/newpipe/views/FocusOverlayView.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,6 @@
4040
import androidx.annotation.NonNull;
4141
import androidx.annotation.Nullable;
4242
import androidx.annotation.RequiresApi;
43-
import androidx.appcompat.view.WindowCallbackWrapper;
4443

4544
import org.schabi.newpipe.R;
4645

@@ -232,7 +231,7 @@ private static void setupOverlay(final Window window, final FocusOverlayView ove
232231
// Unfortunately many such forms of "scrolling" do not count as scrolling for purpose
233232
// of dispatching ViewTreeObserver callbacks, so we have to intercept them by directly
234233
// receiving keys from Window.
235-
window.setCallback(new WindowCallbackWrapper(window.getCallback()) {
234+
window.setCallback(new SimpleWindowCallback(window.getCallback()) {
236235
@Override
237236
public boolean dispatchKeyEvent(final KeyEvent event) {
238237
final boolean res = super.dispatchKeyEvent(event);
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
/*
2+
* SPDX-FileCopyrightText: 2026 NewPipe e.V. <https://newpipe-ev.de>
3+
* SPDX-License-Identifier: GPL-3.0-or-later
4+
*/
5+
6+
package org.schabi.newpipe.views
7+
8+
import android.os.Build
9+
import android.view.KeyEvent
10+
import android.view.KeyboardShortcutGroup
11+
import android.view.Menu
12+
import android.view.Window
13+
import androidx.annotation.RequiresApi
14+
15+
/**
16+
* Simple window callback class to allow intercepting key events
17+
* @see FocusOverlayView.setupOverlay
18+
*/
19+
open class SimpleWindowCallback(private val baseCallback: Window.Callback) :
20+
Window.Callback by baseCallback {
21+
22+
override fun dispatchKeyEvent(event: KeyEvent?): Boolean {
23+
return baseCallback.dispatchKeyEvent(event)
24+
}
25+
26+
@RequiresApi(Build.VERSION_CODES.O)
27+
override fun onPointerCaptureChanged(hasCapture: Boolean) {
28+
baseCallback.onPointerCaptureChanged(hasCapture)
29+
}
30+
31+
@RequiresApi(Build.VERSION_CODES.N)
32+
override fun onProvideKeyboardShortcuts(
33+
data: List<KeyboardShortcutGroup?>?,
34+
menu: Menu?,
35+
deviceId: Int
36+
) {
37+
baseCallback.onProvideKeyboardShortcuts(data, menu, deviceId)
38+
}
39+
}

0 commit comments

Comments
 (0)