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

Commit 0bff3df0 authored by Alan Viverette's avatar Alan Viverette Committed by Android (Google) Code Review
Browse files

Merge "Make AbsActionBarView eat touch/hover events"

parents 81d74743 82d31d45
Loading
Loading
Loading
Loading
+55 −0
Original line number Diff line number Diff line
@@ -19,6 +19,7 @@ import com.android.internal.R;

import android.util.TypedValue;
import android.view.ContextThemeWrapper;
import android.view.MotionEvent;
import android.widget.ActionMenuPresenter;
import android.widget.ActionMenuView;

@@ -53,6 +54,9 @@ public abstract class AbsActionBarView extends ViewGroup {

    protected Animator mVisibilityAnim;

    private boolean mEatingTouch;
    private boolean mEatingHover;

    public AbsActionBarView(Context context) {
        this(context, null);
    }
@@ -97,6 +101,57 @@ public abstract class AbsActionBarView extends ViewGroup {
        }
    }

    @Override
    public boolean onTouchEvent(MotionEvent ev) {
        // ActionBarViews 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;
    }

    @Override
    public boolean onHoverEvent(MotionEvent ev) {
        // Same deal as onTouchEvent() above. Eat all hover events, but still
        // respect the touch event dispatch contract.

        final int action = ev.getActionMasked();
        if (action == MotionEvent.ACTION_HOVER_ENTER) {
            mEatingHover = false;
        }

        if (!mEatingHover) {
            final boolean handled = super.onHoverEvent(ev);
            if (action == MotionEvent.ACTION_HOVER_ENTER && !handled) {
                mEatingHover = true;
            }
        }

        if (action == MotionEvent.ACTION_HOVER_EXIT
                || action == MotionEvent.ACTION_CANCEL) {
            mEatingHover = false;
        }

        return true;
    }

    /**
     * Sets whether the bar should be split right now, no questions asked.
     * @param split true if the bar should split