Search in sources :

Example 6 with ViewParent

use of android.view.ViewParent in project UltimateRecyclerView by cymcsg.

the class SwipeLayout method onInterceptTouchEvent.

@Override
public boolean onInterceptTouchEvent(MotionEvent ev) {
    if (!isSwipeEnabled()) {
        return false;
    }
    if (mClickToClose && getOpenStatus() == Status.Open && isTouchOnSurface(ev)) {
        return true;
    }
    for (SwipeDenier denier : mSwipeDeniers) {
        if (denier != null && denier.shouldDenySwipe(ev)) {
            return false;
        }
    }
    switch(ev.getAction()) {
        case MotionEvent.ACTION_DOWN:
            mDragHelper.processTouchEvent(ev);
            mIsBeingDragged = false;
            sX = ev.getRawX();
            sY = ev.getRawY();
            //if the swipe is in middle state(scrolling), should intercept the touch
            if (getOpenStatus() == Status.Middle) {
                mIsBeingDragged = true;
            }
            break;
        case MotionEvent.ACTION_MOVE:
            boolean beforeCheck = mIsBeingDragged;
            checkCanDrag(ev);
            if (mIsBeingDragged) {
                ViewParent parent = getParent();
                if (parent != null) {
                    parent.requestDisallowInterceptTouchEvent(true);
                }
            }
            if (!beforeCheck && mIsBeingDragged) {
                //useful when swipeLayout wrap a swipeLayout or other gestural layout
                return false;
            }
            break;
        case MotionEvent.ACTION_CANCEL:
        case MotionEvent.ACTION_UP:
            mIsBeingDragged = false;
            mDragHelper.processTouchEvent(ev);
            break;
        default:
            //handle other action, such as ACTION_POINTER_DOWN/UP
            mDragHelper.processTouchEvent(ev);
    }
    return mIsBeingDragged;
}
Also used : ViewParent(android.view.ViewParent)

Example 7 with ViewParent

use of android.view.ViewParent in project UltimateRecyclerView by cymcsg.

the class SwipeLayout method performAdapterViewItemLongClick.

private boolean performAdapterViewItemLongClick() {
    if (getOpenStatus() != Status.Close)
        return false;
    ViewParent t = getParent();
    if (t instanceof AdapterView) {
        AdapterView view = (AdapterView) t;
        int p = view.getPositionForView(SwipeLayout.this);
        if (p == AdapterView.INVALID_POSITION)
            return false;
        long vId = view.getItemIdAtPosition(p);
        boolean handled = false;
        try {
            Method m = AbsListView.class.getDeclaredMethod("performLongPress", View.class, int.class, long.class);
            m.setAccessible(true);
            handled = (boolean) m.invoke(view, SwipeLayout.this, p, vId);
        } catch (Exception e) {
            e.printStackTrace();
            if (view.getOnItemLongClickListener() != null) {
                handled = view.getOnItemLongClickListener().onItemLongClick(view, SwipeLayout.this, p, vId);
            }
            if (handled) {
                view.performHapticFeedback(HapticFeedbackConstants.LONG_PRESS);
            }
        }
        return handled;
    }
    return false;
}
Also used : ViewParent(android.view.ViewParent) AdapterView(android.widget.AdapterView) Method(java.lang.reflect.Method)

Example 8 with ViewParent

use of android.view.ViewParent in project UltimateRecyclerView by cymcsg.

the class SwipeLayout method performAdapterViewItemClick.

private void performAdapterViewItemClick() {
    if (getOpenStatus() != Status.Close)
        return;
    ViewParent t = getParent();
    if (t instanceof AdapterView) {
        AdapterView view = (AdapterView) t;
        int p = view.getPositionForView(SwipeLayout.this);
        if (p != AdapterView.INVALID_POSITION) {
            view.performItemClick(view.getChildAt(p - view.getFirstVisiblePosition()), p, view.getAdapter().getItemId(p));
        }
    }
}
Also used : ViewParent(android.view.ViewParent) AdapterView(android.widget.AdapterView)

Example 9 with ViewParent

use of android.view.ViewParent in project UltimateAndroid by cymcsg.

the class SwipeLayout method onTouchEvent.

@Override
public boolean onTouchEvent(MotionEvent event) {
    if (!isEnabledInAdapterView() || !isEnabled())
        return true;
    if (!isSwipeEnabled())
        return super.onTouchEvent(event);
    int action = event.getActionMasked();
    ViewParent parent = getParent();
    gestureDetector.onTouchEvent(event);
    Status status = getOpenStatus();
    ViewGroup touching = null;
    if (status == Status.Close) {
        touching = getSurfaceView();
    } else if (status == Status.Open) {
        touching = getBottomView();
    }
    switch(action) {
        case MotionEvent.ACTION_DOWN:
            mDragHelper.processTouchEvent(event);
            parent.requestDisallowInterceptTouchEvent(true);
            sX = event.getRawX();
            sY = event.getRawY();
            if (touching != null)
                touching.setPressed(true);
            return true;
        case MotionEvent.ACTION_MOVE:
            {
                if (sX == -1 || sY == -1) {
                    // Trick:
                    // When in nested mode, we need to send a constructed ACTION_DOWN MotionEvent to mDragHelper, to help
                    // it initialize itself.
                    event.setAction(MotionEvent.ACTION_DOWN);
                    mDragHelper.processTouchEvent(event);
                    parent.requestDisallowInterceptTouchEvent(true);
                    sX = event.getRawX();
                    sY = event.getRawY();
                    return true;
                }
                float distanceX = event.getRawX() - sX;
                float distanceY = event.getRawY() - sY;
                float angle = Math.abs(distanceY / distanceX);
                angle = (float) Math.toDegrees(Math.atan(angle));
                boolean doNothing = false;
                if (mDragEdge == DragEdge.Right) {
                    boolean suitable = (status == Status.Open && distanceX > 0) || (status == Status.Close && distanceX < 0);
                    suitable = suitable || (status == Status.Middle);
                    if (angle > 30 || !suitable) {
                        doNothing = true;
                    }
                }
                if (mDragEdge == DragEdge.Left) {
                    boolean suitable = (status == Status.Open && distanceX < 0) || (status == Status.Close && distanceX > 0);
                    suitable = suitable || status == Status.Middle;
                    if (angle > 30 || !suitable) {
                        doNothing = true;
                    }
                }
                if (mDragEdge == DragEdge.Top) {
                    boolean suitable = (status == Status.Open && distanceY < 0) || (status == Status.Close && distanceY > 0);
                    suitable = suitable || status == Status.Middle;
                    if (angle < 60 || !suitable) {
                        doNothing = true;
                    }
                }
                if (mDragEdge == DragEdge.Bottom) {
                    boolean suitable = (status == Status.Open && distanceY > 0) || (status == Status.Close && distanceY < 0);
                    suitable = suitable || status == Status.Middle;
                    if (angle < 60 || !suitable) {
                        doNothing = true;
                    }
                }
                if (doNothing) {
                    parent.requestDisallowInterceptTouchEvent(false);
                    return false;
                } else {
                    if (touching != null) {
                        touching.setPressed(false);
                    }
                    parent.requestDisallowInterceptTouchEvent(true);
                    mDragHelper.processTouchEvent(event);
                }
                break;
            }
        case MotionEvent.ACTION_UP:
        case MotionEvent.ACTION_CANCEL:
            {
                sX = -1;
                sY = -1;
                if (touching != null) {
                    touching.setPressed(false);
                }
            }
        default:
            parent.requestDisallowInterceptTouchEvent(true);
            mDragHelper.processTouchEvent(event);
    }
    return true;
}
Also used : ViewParent(android.view.ViewParent) ViewGroup(android.view.ViewGroup)

Example 10 with ViewParent

use of android.view.ViewParent in project AndroidSwipeLayout by daimajia.

the class SwipeLayout method performAdapterViewItemClick.

private void performAdapterViewItemClick() {
    if (getOpenStatus() != Status.Close)
        return;
    ViewParent t = getParent();
    if (t instanceof AdapterView) {
        AdapterView view = (AdapterView) t;
        int p = view.getPositionForView(SwipeLayout.this);
        if (p != AdapterView.INVALID_POSITION) {
            view.performItemClick(view.getChildAt(p - view.getFirstVisiblePosition()), p, view.getAdapter().getItemId(p));
        }
    }
}
Also used : ViewParent(android.view.ViewParent) AdapterView(android.widget.AdapterView)

Aggregations

ViewParent (android.view.ViewParent)401 ViewGroup (android.view.ViewGroup)184 View (android.view.View)153 ImageView (android.widget.ImageView)36 Rect (android.graphics.Rect)32 VelocityTracker (android.view.VelocityTracker)32 TextView (android.widget.TextView)23 SuppressLint (android.annotation.SuppressLint)15 Paint (android.graphics.Paint)15 FrameLayout (android.widget.FrameLayout)15 AdapterView (android.widget.AdapterView)14 AccessibilityEvent (android.view.accessibility.AccessibilityEvent)13 ViewTreeObserver (android.view.ViewTreeObserver)12 LayoutParams (android.view.WindowManager.LayoutParams)11 Description (org.hamcrest.Description)11 ExpandableNotificationRow (com.android.systemui.statusbar.ExpandableNotificationRow)10 SignalClusterView (com.android.systemui.statusbar.SignalClusterView)10 TypeSafeMatcher (org.hamcrest.TypeSafeMatcher)10 EditText (android.widget.EditText)9 Context (android.content.Context)8