Search in sources :

Example 11 with GestureDetectorCompat

use of androidx.core.view.GestureDetectorCompat 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

GestureDetectorCompat (androidx.core.view.GestureDetectorCompat)11 SuppressLint (android.annotation.SuppressLint)3 MotionEvent (android.view.MotionEvent)3 Point (android.graphics.Point)2 View (android.view.View)2 Message (com.applozic.mobicomkit.api.conversation.Message)2 AlRichMessage (com.applozic.mobicomkit.uiwidgets.conversation.richmessaging.AlRichMessage)2 TouchInterceptingFrameLayout (org.thoughtcrime.securesms.util.views.TouchInterceptingFrameLayout)2 Context (android.content.Context)1 Intent (android.content.Intent)1 Configuration (android.content.res.Configuration)1 TypedArray (android.content.res.TypedArray)1 Bitmap (android.graphics.Bitmap)1 Paint (android.graphics.Paint)1 RectF (android.graphics.RectF)1 GradientDrawable (android.graphics.drawable.GradientDrawable)1 Bundle (android.os.Bundle)1 CountDownTimer (android.os.CountDownTimer)1 ResultReceiver (android.os.ResultReceiver)1 Editable (android.text.Editable)1