Search in sources :

Example 1 with TouchInterceptingFrameLayout

use of org.thoughtcrime.securesms.util.views.TouchInterceptingFrameLayout in project Signal-Android by WhisperSystems.

the class PictureInPictureGestureHelper method applyTo.

@SuppressLint("ClickableViewAccessibility")
public static PictureInPictureGestureHelper applyTo(@NonNull View child) {
    TouchInterceptingFrameLayout parent = (TouchInterceptingFrameLayout) child.getParent();
    PictureInPictureGestureHelper helper = new PictureInPictureGestureHelper(parent, child);
    GestureDetectorCompat gestureDetector = new GestureDetectorCompat(child.getContext(), helper);
    parent.setOnInterceptTouchEventListener((event) -> {
        final int action = event.getAction();
        final int pointerIndex = (action & MotionEvent.ACTION_POINTER_INDEX_MASK) >> MotionEvent.ACTION_POINTER_INDEX_SHIFT;
        if (pointerIndex > 0) {
            return false;
        }
        if (helper.velocityTracker == null) {
            helper.velocityTracker = VelocityTracker.obtain();
        }
        helper.velocityTracker.addMovement(event);
        return false;
    });
    parent.setOnTouchListener((v, event) -> {
        if (helper.velocityTracker != null) {
            helper.velocityTracker.recycle();
            helper.velocityTracker = null;
        }
        return false;
    });
    child.setOnTouchListener((v, event) -> {
        boolean handled = gestureDetector.onTouchEvent(event);
        if (event.getActionMasked() == MotionEvent.ACTION_UP || event.getActionMasked() == MotionEvent.ACTION_CANCEL) {
            if (!handled) {
                handled = helper.onGestureFinished(event);
            }
            if (helper.velocityTracker != null) {
                helper.velocityTracker.recycle();
                helper.velocityTracker = null;
            }
        }
        return handled;
    });
    return helper;
}
Also used : TouchInterceptingFrameLayout(org.thoughtcrime.securesms.util.views.TouchInterceptingFrameLayout) GestureDetectorCompat(androidx.core.view.GestureDetectorCompat) Point(android.graphics.Point) SuppressLint(android.annotation.SuppressLint) SuppressLint(android.annotation.SuppressLint)

Example 2 with TouchInterceptingFrameLayout

use of org.thoughtcrime.securesms.util.views.TouchInterceptingFrameLayout in project Signal-Android by signalapp.

the class PictureInPictureGestureHelper method applyTo.

@SuppressLint("ClickableViewAccessibility")
public static PictureInPictureGestureHelper applyTo(@NonNull View child) {
    TouchInterceptingFrameLayout parent = (TouchInterceptingFrameLayout) child.getParent();
    PictureInPictureGestureHelper helper = new PictureInPictureGestureHelper(parent, child);
    GestureDetectorCompat gestureDetector = new GestureDetectorCompat(child.getContext(), helper);
    parent.setOnInterceptTouchEventListener((event) -> {
        final int action = event.getAction();
        final int pointerIndex = (action & MotionEvent.ACTION_POINTER_INDEX_MASK) >> MotionEvent.ACTION_POINTER_INDEX_SHIFT;
        if (pointerIndex > 0) {
            return false;
        }
        if (helper.velocityTracker == null) {
            helper.velocityTracker = VelocityTracker.obtain();
        }
        helper.velocityTracker.addMovement(event);
        return false;
    });
    parent.setOnTouchListener((v, event) -> {
        if (helper.velocityTracker != null) {
            helper.velocityTracker.recycle();
            helper.velocityTracker = null;
        }
        return false;
    });
    child.setOnTouchListener((v, event) -> {
        boolean handled = gestureDetector.onTouchEvent(event);
        if (event.getActionMasked() == MotionEvent.ACTION_UP || event.getActionMasked() == MotionEvent.ACTION_CANCEL) {
            if (!handled) {
                handled = helper.onGestureFinished(event);
            }
            if (helper.velocityTracker != null) {
                helper.velocityTracker.recycle();
                helper.velocityTracker = null;
            }
        }
        return handled;
    });
    return helper;
}
Also used : TouchInterceptingFrameLayout(org.thoughtcrime.securesms.util.views.TouchInterceptingFrameLayout) GestureDetectorCompat(androidx.core.view.GestureDetectorCompat) Point(android.graphics.Point) SuppressLint(android.annotation.SuppressLint) SuppressLint(android.annotation.SuppressLint)

Aggregations

SuppressLint (android.annotation.SuppressLint)2 Point (android.graphics.Point)2 GestureDetectorCompat (androidx.core.view.GestureDetectorCompat)2 TouchInterceptingFrameLayout (org.thoughtcrime.securesms.util.views.TouchInterceptingFrameLayout)2