Can't receive Motion Events with Window.Callback
Asked Answered
B

0

6

My task is receiving all motion events in android application with good embedding (library variant). I create my Window.Callback wrapper.

public class WindowCallback implements Window.Callback {

private final Window.Callback wrapper;

    public WindowCallback(Window.Callback callback) {        
        this.wrapper = callback;
    }

    @Override
    public boolean dispatchKeyEvent(KeyEvent event) {
         return wrapper.dispatchKeyEvent(event);
    }

    @Override
    public boolean dispatchKeyShortcutEvent(KeyEvent event) {
         return wrapper.dispatchKeyShortcutEvent(event);
    }

    @Override
    public boolean dispatchTouchEvent(MotionEvent event) {        
        return wrapper.dispatchTouchEvent(event);
    }

    // other methods omitted
}

Then, instantiate it in Activity:

final Window window = getWindow();
final Window.Callback windowCallback = window.getCallback();
final WindowCallback callbackWrapper = new WindowCallback(windowCallback);
window.setCallback(interceptCallback);

But when I have Toolbar in Activity, this Toolbar capture Window.Callback in method setActionBar(Toolbar) or setSupportActionBar(Toolbar). Code snippet from framework Activity:

if (toolbar != null) {
        final ToolbarActionBar tbab = new ToolbarActionBar(toolbar, getTitle(), this);
        mActionBar = tbab;
        mWindow.setCallback(tbab.getWrappedWindowCallback());

And ToolbarActionBar from support library:

ToolbarActionBar(Toolbar toolbar, CharSequence title, Callback windowCallback) {
    this.mDecorToolbar = new ToolbarWidgetWrapper(toolbar, false);
    this.mWindowCallback = new ToolbarActionBar.ToolbarCallbackWrapper(windowCallback);
    this.mDecorToolbar.setWindowCallback(this.mWindowCallback);
    toolbar.setOnMenuItemClickListener(this.mMenuClicker);
    this.mDecorToolbar.setWindowTitle(title);
}

Question is - How to check when Toolbar catch Window.Callback, but without creating base activity and extending from it. This check should execute not very frequently. (OnGlobalLayoutListener not our case)

Blench answered 19/3, 2019 at 14:51 Comment(2)
what do you mean by captures? overrides? did you try first setting the toolbar and then setting the custom window callback to set it last?Elurd
Our realization use method Window.getCallback, but Toolbar from support library use original callback in initialization time. And our wrapped callback stop receive events. And we try set custom callback after setActionBar(toolbar) - it works. We want to create universal realization (library version) and don't worry about place of our library initialization.Blench

© 2022 - 2024 — McMap. All rights reserved.