Search in sources :

Example 86 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 87 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 88 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 89 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)

Example 90 with ViewParent

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

the class ViewPager method arrowScroll.

public boolean arrowScroll(int direction) {
    View currentFocused = findFocus();
    if (currentFocused == this) {
        currentFocused = null;
    } else if (currentFocused != null) {
        boolean isChild = false;
        for (ViewParent parent = currentFocused.getParent(); parent instanceof ViewGroup; parent = parent.getParent()) {
            if (parent == this) {
                isChild = true;
                break;
            }
        }
        if (!isChild) {
            // This would cause the focus search down below to fail in fun ways.
            final StringBuilder sb = new StringBuilder();
            sb.append(currentFocused.getClass().getSimpleName());
            for (ViewParent parent = currentFocused.getParent(); parent instanceof ViewGroup; parent = parent.getParent()) {
                sb.append(" => ").append(parent.getClass().getSimpleName());
            }
            Log.e(TAG, "arrowScroll tried to find focus based on non-child " + "current focused view " + sb.toString());
            currentFocused = null;
        }
    }
    boolean handled = false;
    View nextFocused = FocusFinder.getInstance().findNextFocus(this, currentFocused, direction);
    if (nextFocused != null && nextFocused != currentFocused) {
        if (direction == View.FOCUS_LEFT) {
            // If there is nothing to the left, or this is causing us to
            // jump to the right, then what we really want to do is page left.
            final int nextLeft = getChildRectInPagerCoordinates(mTempRect, nextFocused).left;
            final int currLeft = getChildRectInPagerCoordinates(mTempRect, currentFocused).left;
            if (currentFocused != null && nextLeft >= currLeft) {
                handled = pageLeft();
            } else {
                handled = nextFocused.requestFocus();
            }
        } else if (direction == View.FOCUS_RIGHT) {
            // If there is nothing to the right, or this is causing us to
            // jump to the left, then what we really want to do is page right.
            final int nextLeft = getChildRectInPagerCoordinates(mTempRect, nextFocused).left;
            final int currLeft = getChildRectInPagerCoordinates(mTempRect, currentFocused).left;
            if (currentFocused != null && nextLeft <= currLeft) {
                handled = pageRight();
            } else {
                handled = nextFocused.requestFocus();
            }
        }
    } else if (direction == FOCUS_LEFT || direction == FOCUS_BACKWARD) {
        // Trying to move left and nothing there; try to page.
        handled = pageLeft();
    } else if (direction == FOCUS_RIGHT || direction == FOCUS_FORWARD) {
        // Trying to move right and nothing there; try to page.
        handled = pageRight();
    }
    if (handled) {
        playSoundEffect(SoundEffectConstants.getContantForFocusDirection(direction));
    }
    return handled;
}
Also used : ViewGroup(android.view.ViewGroup) ViewParent(android.view.ViewParent) View(android.view.View)

Aggregations

ViewParent (android.view.ViewParent)409 ViewGroup (android.view.ViewGroup)185 View (android.view.View)156 ImageView (android.widget.ImageView)36 Rect (android.graphics.Rect)32 VelocityTracker (android.view.VelocityTracker)32 TextView (android.widget.TextView)24 FrameLayout (android.widget.FrameLayout)17 SuppressLint (android.annotation.SuppressLint)16 Paint (android.graphics.Paint)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 MotionEvent (android.view.MotionEvent)9 EditText (android.widget.EditText)9