Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 61d15b98 authored by Adam Powell's avatar Adam Powell
Browse files

Make Toolbars eat touch events

Just like action bars, toolbars shouldn't allow touches to fall
through to sibling views that they overlap.

Bug 17483356

Change-Id: I9068e1f9cf3c4226000e0058c371283a997b1bd0
parent a6c52ac6
Loading
Loading
Loading
Loading
+29 −0
Original line number Diff line number Diff line
@@ -33,6 +33,7 @@ import android.view.Gravity;
import android.view.Menu;
import android.view.MenuInflater;
import android.view.MenuItem;
import android.view.MotionEvent;
import android.view.View;
import android.view.ViewGroup;

@@ -132,6 +133,8 @@ public class Toolbar extends ViewGroup {
    private int mTitleTextColor;
    private int mSubtitleTextColor;

    private boolean mEatingTouch;

    // Clear me after use.
    private final ArrayList<View> mTempViews = new ArrayList<View>();

@@ -1061,6 +1064,32 @@ public class Toolbar extends ViewGroup {
        removeCallbacks(mShowOverflowMenuRunnable);
    }

    @Override
    public boolean onTouchEvent(MotionEvent ev) {
        // Toolbars always eat touch events, but should still respect the touch event dispatch
        // contract. If the normal View implementation doesn't want the events, we'll just silently
        // eat the rest of the gesture without reporting the events to the default implementation
        // since that's what it expects.

        final int action = ev.getActionMasked();
        if (action == MotionEvent.ACTION_DOWN) {
            mEatingTouch = false;
        }

        if (!mEatingTouch) {
            final boolean handled = super.onTouchEvent(ev);
            if (action == MotionEvent.ACTION_DOWN && !handled) {
                mEatingTouch = true;
            }
        }

        if (action == MotionEvent.ACTION_UP || action == MotionEvent.ACTION_CANCEL) {
            mEatingTouch = false;
        }

        return true;
    }

    /**
     * @hide
     */