android.support.v4.view.ViewParentCompat Java Examples

The following examples show how to use android.support.v4.view.ViewParentCompat. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: NestedChildHelper.java    From customview-samples with Apache License 2.0 5 votes vote down vote up
/**
 * Stop a nested scroll in progress.
 *
 * <p>This is a delegate method. Call it from your {@link android.view.View View} subclass
 * method/{@link android.support.v4.view.NestedScrollingChild2} interface method with the same
 * signature to implement the standard policy.</p>
 */
public void stopNestedScroll(@ViewCompat.NestedScrollType int type) {
    ViewParent parent = getNestedScrollingParentForType(type);
    if (parent != null) {
        ViewParentCompat.onStopNestedScroll(parent, mView, type);
        setNestedScrollingParentForType(type, null);
    }
}
 
Example #2
Source File: NestedChildHelper.java    From customview-samples with Apache License 2.0 5 votes vote down vote up
public boolean dispatchNestedScroll(int dxConsumed, int dyConsumed,
                                    int dxUnconsumed, int dyUnconsumed, @Nullable int[] offsetInWindow,
                                    @ViewCompat.NestedScrollType int type) {
    if (isNestedScrollingEnabled()) {
        //获取实现了NestedScrollingParent2或NestedScrollingParent的祖辈控件,如果没有则为null
        final ViewParent parent = getNestedScrollingParentForType(type);
        if (parent == null) {
            //没有实现NestedScrollingParent2或NestedScrollingParent的祖辈控件,则不作任何处理
            return false;
        }

        if (dxConsumed != 0 || dyConsumed != 0 || dxUnconsumed != 0 || dyUnconsumed != 0) {
            int startX = 0;
            int startY = 0;
            if (offsetInWindow != null) {
                mView.getLocationInWindow(offsetInWindow);
                startX = offsetInWindow[0];
                startY = offsetInWindow[1];
            }

            //将嵌套滑动事件分发给祖辈控件的onNestedScroll方法
            ViewParentCompat.onNestedScroll(parent, mView, dxConsumed,
                    dyConsumed, dxUnconsumed, dyUnconsumed, type);

            if (offsetInWindow != null) {
                mView.getLocationInWindow(offsetInWindow);
                offsetInWindow[0] -= startX;
                offsetInWindow[1] -= startY;
            }
            return true;
        } else if (offsetInWindow != null) {
            // No motion, no dispatch. Keep offsetInWindow up to date.
            offsetInWindow[0] = 0;
            offsetInWindow[1] = 0;
        }
    }
    return false;
}
 
Example #3
Source File: NestedChildHelper.java    From customview-samples with Apache License 2.0 5 votes vote down vote up
/**
 * Dispatch a nested fling operation to the current nested scrolling parent.
 *
 * <p>This is a delegate method. Call it from your {@link android.view.View View} subclass
 * method/{@link android.support.v4.view.NestedScrollingChild} interface method with the same
 * signature to implement the standard policy.</p>
 *
 * @return true if the parent consumed the nested fling
 */
public boolean dispatchNestedFling(float velocityX, float velocityY, boolean consumed) {
    if (isNestedScrollingEnabled()) {
        ViewParent parent = getNestedScrollingParentForType(TYPE_TOUCH);
        if (parent != null) {
            return ViewParentCompat.onNestedFling(parent, mView, velocityX,
                    velocityY, consumed);
        }
    }
    return false;
}
 
Example #4
Source File: NestedChildHelper.java    From customview-samples with Apache License 2.0 5 votes vote down vote up
/**
 * Dispatch a nested pre-fling operation to the current nested scrolling parent.
 *
 * <p>This is a delegate method. Call it from your {@link android.view.View View} subclass
 * method/{@link android.support.v4.view.NestedScrollingChild} interface method with the same
 * signature to implement the standard policy.</p>
 *
 * @return true if the parent consumed the nested fling
 */
public boolean dispatchNestedPreFling(float velocityX, float velocityY) {
    if (isNestedScrollingEnabled()) {
        ViewParent parent = getNestedScrollingParentForType(TYPE_TOUCH);
        if (parent != null) {
            return ViewParentCompat.onNestedPreFling(parent, mView, velocityX,
                    velocityY);
        }
    }
    return false;
}
 
Example #5
Source File: ExploreByTouchHelper.java    From letv with Apache License 2.0 5 votes vote down vote up
public boolean sendEventForVirtualView(int virtualViewId, int eventType) {
    if (virtualViewId == Integer.MIN_VALUE || !this.mManager.isEnabled()) {
        return false;
    }
    ViewParent parent = this.mView.getParent();
    if (parent == null) {
        return false;
    }
    return ViewParentCompat.requestSendAccessibilityEvent(parent, this.mView, createEvent(virtualViewId, eventType));
}
 
Example #6
Source File: ExploreByTouchHelper.java    From MiBandDecompiled with Apache License 2.0 5 votes vote down vote up
public boolean sendEventForVirtualView(int l, int i1)
{
    android.view.ViewParent viewparent;
    if (l != 0x80000000 && g.isEnabled())
    {
        if ((viewparent = h.getParent()) != null)
        {
            AccessibilityEvent accessibilityevent = a(l, i1);
            return ViewParentCompat.requestSendAccessibilityEvent(viewparent, h, accessibilityevent);
        }
    }
    return false;
}
 
Example #7
Source File: NestedChildHelper.java    From customview-samples with Apache License 2.0 4 votes vote down vote up
public boolean dispatchNestedPreScroll(int dx, int dy, @Nullable int[] consumed,
                                       @Nullable int[] offsetInWindow, @ViewCompat.NestedScrollType int type) {
    if (isNestedScrollingEnabled()) {
        //获取实现了NestedScrollingParent2或NestedScrollingParent的祖辈控件,如果没有则为null
        final ViewParent parent = getNestedScrollingParentForType(type);
        if (parent == null) {
            //没有实现NestedScrollingParent2或NestedScrollingParent的祖辈控件,则不作任何处理
            return false;
        }

        if (dx != 0 || dy != 0) {
            int startX = 0;
            int startY = 0;
            if (offsetInWindow != null) {
                mView.getLocationInWindow(offsetInWindow);
                startX = offsetInWindow[0];
                startY = offsetInWindow[1];
            }

            if (consumed == null) {
                if (mTempNestedScrollConsumed == null) {
                    mTempNestedScrollConsumed = new int[2];
                }
                consumed = mTempNestedScrollConsumed;
            }
            consumed[0] = 0;
            consumed[1] = 0;

            //将嵌套滑动事件分发给祖辈控件的onNestedPreScroll方法
            ViewParentCompat.onNestedPreScroll(parent, mView, dx, dy, consumed, type);

            if (offsetInWindow != null) {
                mView.getLocationInWindow(offsetInWindow);
                offsetInWindow[0] -= startX;
                offsetInWindow[1] -= startY;
            }
            return consumed[0] != 0 || consumed[1] != 0;
        } else if (offsetInWindow != null) {
            offsetInWindow[0] = 0;
            offsetInWindow[1] = 0;
        }
    }
    return false;
}
 
Example #8
Source File: ExploreByTouchHelper.java    From adt-leanback-support with Apache License 2.0 3 votes vote down vote up
/**
 * Populates an event of the specified type with information about an item
 * and attempts to send it up through the view hierarchy.
 * <p>
 * You should call this method after performing a user action that normally
 * fires an accessibility event, such as clicking on an item.
 *
 * <pre>public void performItemClick(T item) {
 *   ...
 *   sendEventForVirtualViewId(item.id, AccessibilityEvent.TYPE_VIEW_CLICKED);
 * }
 * </pre>
 *
 * @param virtualViewId The virtual view id for which to send an event.
 * @param eventType The type of event to send.
 * @return true if the event was sent successfully.
 */
public boolean sendEventForVirtualView(int virtualViewId, int eventType) {
    if ((virtualViewId == INVALID_ID) || !mManager.isEnabled()) {
        return false;
    }

    final ViewParent parent = mView.getParent();
    if (parent == null) {
        return false;
    }

    final AccessibilityEvent event = createEvent(virtualViewId, eventType);
    return ViewParentCompat.requestSendAccessibilityEvent(parent, mView, event);
}
 
Example #9
Source File: ExploreByTouchHelper.java    From android-recipes-app with Apache License 2.0 3 votes vote down vote up
/**
 * Populates an event of the specified type with information about an item
 * and attempts to send it up through the view hierarchy.
 * <p>
 * You should call this method after performing a user action that normally
 * fires an accessibility event, such as clicking on an item.
 *
 * <pre>public void performItemClick(T item) {
 *   ...
 *   sendEventForVirtualViewId(item.id, AccessibilityEvent.TYPE_VIEW_CLICKED);
 * }
 * </pre>
 *
 * @param virtualViewId The virtual view id for which to send an event.
 * @param eventType The type of event to send.
 * @return true if the event was sent successfully.
 */
public boolean sendEventForVirtualView(int virtualViewId, int eventType) {
    if ((virtualViewId == INVALID_ID) || !mManager.isEnabled()) {
        return false;
    }

    final ViewParent parent = mView.getParent();
    if (parent == null) {
        return false;
    }

    final AccessibilityEvent event = createEvent(virtualViewId, eventType);
    return ViewParentCompat.requestSendAccessibilityEvent(parent, mView, event);
}
 
Example #10
Source File: ExploreByTouchHelper.java    From V.FlyoutTest with MIT License 3 votes vote down vote up
/**
 * Populates an event of the specified type with information about an item
 * and attempts to send it up through the view hierarchy.
 * <p>
 * You should call this method after performing a user action that normally
 * fires an accessibility event, such as clicking on an item.
 *
 * <pre>public void performItemClick(T item) {
 *   ...
 *   sendEventForVirtualViewId(item.id, AccessibilityEvent.TYPE_VIEW_CLICKED);
 * }
 * </pre>
 *
 * @param virtualViewId The virtual view id for which to send an event.
 * @param eventType The type of event to send.
 * @return true if the event was sent successfully.
 */
public boolean sendEventForVirtualView(int virtualViewId, int eventType) {
    if ((virtualViewId == INVALID_ID) || !mManager.isEnabled()) {
        return false;
    }

    final ViewParent parent = mView.getParent();
    if (parent == null) {
        return false;
    }

    final AccessibilityEvent event = createEvent(virtualViewId, eventType);
    return ViewParentCompat.requestSendAccessibilityEvent(parent, mView, event);
}
 
Example #11
Source File: ExploreByTouchHelper.java    From guideshow with MIT License 3 votes vote down vote up
/**
 * Populates an event of the specified type with information about an item
 * and attempts to send it up through the view hierarchy.
 * <p>
 * You should call this method after performing a user action that normally
 * fires an accessibility event, such as clicking on an item.
 *
 * <pre>public void performItemClick(T item) {
 *   ...
 *   sendEventForVirtualViewId(item.id, AccessibilityEvent.TYPE_VIEW_CLICKED);
 * }
 * </pre>
 *
 * @param virtualViewId The virtual view id for which to send an event.
 * @param eventType The type of event to send.
 * @return true if the event was sent successfully.
 */
public boolean sendEventForVirtualView(int virtualViewId, int eventType) {
    if ((virtualViewId == INVALID_ID) || !mManager.isEnabled()) {
        return false;
    }

    final ViewParent parent = mView.getParent();
    if (parent == null) {
        return false;
    }

    final AccessibilityEvent event = createEvent(virtualViewId, eventType);
    return ViewParentCompat.requestSendAccessibilityEvent(parent, mView, event);
}