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

Commit c492e822 authored by Ben Lin's avatar Ben Lin
Browse files

Fix a bug where context menu keeps popping up as we move cursor.

Previously, since there was not a clear code path for TouchEvents for
mEmptyView, we wrote one just for this specific class. However now with
everything in one class (ListeningGestureDetector), it makes sense to
receive events and just delegate them to UserInputHandler#onTouchEvent.

Bug: 30781381
Change-Id: Ied38fa92bbe3a2b12bba79a5cce5760eb73d1127
parent dbcccd65
Loading
Loading
Loading
Loading
+7 −11
Original line number Diff line number Diff line
@@ -25,11 +25,9 @@ import android.view.MotionEvent;
import android.view.View;
import android.view.View.OnTouchListener;

import com.android.documentsui.Events;

// Previously we listened to events with one class, only to bounce them forward
// to GestureDetector. We're still doing that here, but with a single class
// that reduces overall complexity in our glue code.
// Receives event meant for both directory and empty view, and either pass them to
// {@link UserInputHandler} for simple gestures (Single Tap, Long-Press), or intercept them for
// other types of gestures (drag n' drop)
final class ListeningGestureDetector extends GestureDetector
        implements OnItemTouchListener, OnTouchListener {

@@ -51,7 +49,7 @@ final class ListeningGestureDetector extends GestureDetector
        if (itemView != null && mDragHelper.onTouch(itemView,  e)) {
            return true;
        }
        // Forward unhandled events to the GestureDetector.
        // Forward unhandled events to UserInputHandler.
        return onTouchEvent(e);
    }

@@ -68,12 +66,10 @@ final class ListeningGestureDetector extends GestureDetector
    @Override
    public void onRequestDisallowInterceptTouchEvent(boolean disallowIntercept) {}

    // For mEmptyView right-click context menu
    // For mEmptyView events
    @Override
    public boolean onTouch(View v, MotionEvent event) {
        if (event.getButtonState() == MotionEvent.BUTTON_SECONDARY) {
            return mInputHandler.onRightClick(event);
        }
        return false;
        // Pass events to UserInputHandler.
        return onTouchEvent(event);
    }
}
 No newline at end of file