Saturday, 30 March 2019

Can't receive Motion Events with Window.Callback

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)



from Can't receive Motion Events with Window.Callback

No comments:

Post a Comment