FocusOverlayView: Avoid accessing restricted API
Signed-off-by: Aayush Gupta <aayushgupta219@gmail.com>
This commit is contained in:
parent
5eb5f7533d
commit
653b33bdb9
@ -40,7 +40,6 @@ import android.view.Window;
|
|||||||
import androidx.annotation.NonNull;
|
import androidx.annotation.NonNull;
|
||||||
import androidx.annotation.Nullable;
|
import androidx.annotation.Nullable;
|
||||||
import androidx.annotation.RequiresApi;
|
import androidx.annotation.RequiresApi;
|
||||||
import androidx.appcompat.view.WindowCallbackWrapper;
|
|
||||||
|
|
||||||
import org.schabi.newpipe.R;
|
import org.schabi.newpipe.R;
|
||||||
|
|
||||||
@ -232,7 +231,7 @@ public final class FocusOverlayView extends Drawable implements
|
|||||||
// Unfortunately many such forms of "scrolling" do not count as scrolling for purpose
|
// Unfortunately many such forms of "scrolling" do not count as scrolling for purpose
|
||||||
// of dispatching ViewTreeObserver callbacks, so we have to intercept them by directly
|
// of dispatching ViewTreeObserver callbacks, so we have to intercept them by directly
|
||||||
// receiving keys from Window.
|
// receiving keys from Window.
|
||||||
window.setCallback(new WindowCallbackWrapper(window.getCallback()) {
|
window.setCallback(new SimpleWindowCallback(window.getCallback()) {
|
||||||
@Override
|
@Override
|
||||||
public boolean dispatchKeyEvent(final KeyEvent event) {
|
public boolean dispatchKeyEvent(final KeyEvent event) {
|
||||||
final boolean res = super.dispatchKeyEvent(event);
|
final boolean res = super.dispatchKeyEvent(event);
|
||||||
|
|||||||
@ -0,0 +1,39 @@
|
|||||||
|
/*
|
||||||
|
* SPDX-FileCopyrightText: 2026 NewPipe e.V. <https://newpipe-ev.de>
|
||||||
|
* SPDX-License-Identifier: GPL-3.0-or-later
|
||||||
|
*/
|
||||||
|
|
||||||
|
package org.schabi.newpipe.views
|
||||||
|
|
||||||
|
import android.os.Build
|
||||||
|
import android.view.KeyEvent
|
||||||
|
import android.view.KeyboardShortcutGroup
|
||||||
|
import android.view.Menu
|
||||||
|
import android.view.Window
|
||||||
|
import androidx.annotation.RequiresApi
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Simple window callback class to allow intercepting key events
|
||||||
|
* @see FocusOverlayView.setupOverlay
|
||||||
|
*/
|
||||||
|
open class SimpleWindowCallback(private val baseCallback: Window.Callback) :
|
||||||
|
Window.Callback by baseCallback {
|
||||||
|
|
||||||
|
override fun dispatchKeyEvent(event: KeyEvent?): Boolean {
|
||||||
|
return baseCallback.dispatchKeyEvent(event)
|
||||||
|
}
|
||||||
|
|
||||||
|
@RequiresApi(Build.VERSION_CODES.O)
|
||||||
|
override fun onPointerCaptureChanged(hasCapture: Boolean) {
|
||||||
|
baseCallback.onPointerCaptureChanged(hasCapture)
|
||||||
|
}
|
||||||
|
|
||||||
|
@RequiresApi(Build.VERSION_CODES.N)
|
||||||
|
override fun onProvideKeyboardShortcuts(
|
||||||
|
data: List<KeyboardShortcutGroup?>?,
|
||||||
|
menu: Menu?,
|
||||||
|
deviceId: Int
|
||||||
|
) {
|
||||||
|
baseCallback.onProvideKeyboardShortcuts(data, menu, deviceId)
|
||||||
|
}
|
||||||
|
}
|
||||||
Loading…
x
Reference in New Issue
Block a user