Java Code Examples for android.view.MotionEvent#ACTION_HOVER_EXIT

The following examples show how to use android.view.MotionEvent#ACTION_HOVER_EXIT . 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: CompositorViewHolder.java    From delion with Apache License 2.0 6 votes vote down vote up
private void setContentViewMotionEventOffsets(MotionEvent e, boolean canClear) {
    // TODO(dtrainor): Factor this out to LayoutDriver.
    if (e == null || mTabVisible == null) return;

    ContentViewCore contentViewCore = mTabVisible.getContentViewCore();
    if (contentViewCore == null) return;

    int actionMasked = e.getActionMasked();

    if (SPenSupport.isSPenSupported(getContext())) {
        actionMasked = SPenSupport.convertSPenEventAction(actionMasked);
    }

    if (actionMasked == MotionEvent.ACTION_DOWN
            || actionMasked == MotionEvent.ACTION_HOVER_ENTER) {
        if (mLayoutManager != null) mLayoutManager.getViewportPixel(mCacheViewport);
        contentViewCore.setCurrentMotionEventOffsets(-mCacheViewport.left, -mCacheViewport.top);
    } else if (canClear && (actionMasked == MotionEvent.ACTION_UP
                                   || actionMasked == MotionEvent.ACTION_CANCEL
                                   || actionMasked == MotionEvent.ACTION_HOVER_EXIT)) {
        contentViewCore.setCurrentMotionEventOffsets(0.f, 0.f);
    }
}
 
Example 2
Source File: LockPatternViewEx.java    From android-lockpattern with Apache License 2.0 6 votes vote down vote up
@Override
public boolean onHoverEvent(MotionEvent event) {
    if (((AccessibilityManager) getContext().getSystemService(
            Context.ACCESSIBILITY_SERVICE)).isTouchExplorationEnabled()) {
        final int action = event.getAction();
        switch (action) {
        case MotionEvent.ACTION_HOVER_ENTER:
            event.setAction(MotionEvent.ACTION_DOWN);
            break;
        case MotionEvent.ACTION_HOVER_MOVE:
            event.setAction(MotionEvent.ACTION_MOVE);
            break;
        case MotionEvent.ACTION_HOVER_EXIT:
            event.setAction(MotionEvent.ACTION_UP);
            break;
        }
        onTouchEvent(event);
        event.setAction(action);
    }
    return super.onHoverEvent(event);
}
 
Example 3
Source File: UsMotionEvent.java    From walt with Apache License 2.0 6 votes vote down vote up
public static String actionToString(int action) {
    switch (action) {
        case MotionEvent.ACTION_DOWN:
            return "ACTION_DOWN";
        case MotionEvent.ACTION_UP:
            return "ACTION_UP";
        case MotionEvent.ACTION_CANCEL:
            return "ACTION_CANCEL";
        case MotionEvent.ACTION_OUTSIDE:
            return "ACTION_OUTSIDE";
        case MotionEvent.ACTION_MOVE:
            return "ACTION_MOVE";
        case MotionEvent.ACTION_HOVER_MOVE:
            return "ACTION_HOVER_MOVE";
        case MotionEvent.ACTION_SCROLL:
            return "ACTION_SCROLL";
        case MotionEvent.ACTION_HOVER_ENTER:
            return "ACTION_HOVER_ENTER";
        case MotionEvent.ACTION_HOVER_EXIT:
            return "ACTION_HOVER_EXIT";
    }
    return "UNKNOWN_ACTION";
}
 
Example 4
Source File: MaterialLockView.java    From MaterialPatternllockView with Apache License 2.0 6 votes vote down vote up
@Override
public boolean onHoverEvent(MotionEvent event) {
    if (((AccessibilityManager) getContext().getSystemService(
            Context.ACCESSIBILITY_SERVICE)).isTouchExplorationEnabled()) {
        final int action = event.getAction();
        switch (action) {
            case MotionEvent.ACTION_HOVER_ENTER:
                event.setAction(MotionEvent.ACTION_DOWN);
                break;
            case MotionEvent.ACTION_HOVER_MOVE:
                event.setAction(MotionEvent.ACTION_MOVE);
                break;
            case MotionEvent.ACTION_HOVER_EXIT:
                event.setAction(MotionEvent.ACTION_UP);
                break;
        }
        onTouchEvent(event);
        event.setAction(action);
    }
    return super.onHoverEvent(event);
}
 
Example 5
Source File: CompositorViewHolder.java    From 365browser with Apache License 2.0 6 votes vote down vote up
private void setContentViewMotionEventOffsets(MotionEvent e, boolean canClear) {
    // TODO(dtrainor): Factor this out to LayoutDriver.
    if (e == null || mTabVisible == null) return;

    ContentViewCore contentViewCore = mTabVisible.getContentViewCore();
    if (contentViewCore == null) return;

    int actionMasked = SPenSupport.convertSPenEventAction(e.getActionMasked());

    if (actionMasked == MotionEvent.ACTION_DOWN
            || actionMasked == MotionEvent.ACTION_HOVER_ENTER) {
        if (mLayoutManager != null) mLayoutManager.getViewportPixel(mCacheViewport);
        contentViewCore.setCurrentTouchEventOffsets(-mCacheViewport.left, -mCacheViewport.top);
    } else if (canClear && (actionMasked == MotionEvent.ACTION_UP
                                   || actionMasked == MotionEvent.ACTION_CANCEL
                                   || actionMasked == MotionEvent.ACTION_HOVER_EXIT)) {
        contentViewCore.setCurrentTouchEventOffsets(0.f, 0.f);
    }
}
 
Example 6
Source File: MaterialTapTargetPrompt.java    From MaterialTapTargetPrompt with Apache License 2.0 6 votes vote down vote up
@Override
public boolean onHoverEvent(MotionEvent event) {
    if (mAccessibilityManager.isTouchExplorationEnabled() && event.getPointerCount() == 1) {
        final int action = event.getAction();
        switch (action) {
            case MotionEvent.ACTION_HOVER_ENTER: {
                event.setAction(MotionEvent.ACTION_DOWN);
            } break;
            case MotionEvent.ACTION_HOVER_MOVE: {
                event.setAction(MotionEvent.ACTION_MOVE);
            } break;
            case MotionEvent.ACTION_HOVER_EXIT: {
                event.setAction(MotionEvent.ACTION_UP);
            } break;
        }
        return onTouchEvent(event);
    }
    return super.onHoverEvent(event);
}
 
Example 7
Source File: LayoutManager.java    From 365browser with Apache License 2.0 6 votes vote down vote up
private PointF getMotionOffsets(MotionEvent e) {
    int actionMasked = SPenSupport.convertSPenEventAction(e.getActionMasked());

    if (actionMasked == MotionEvent.ACTION_DOWN
            || actionMasked == MotionEvent.ACTION_HOVER_ENTER) {
        getViewportPixel(mCachedRect);

        mCachedPoint.set(-mCachedRect.left, -mCachedRect.top);
        return mCachedPoint;
    } else if (actionMasked == MotionEvent.ACTION_UP
            || actionMasked == MotionEvent.ACTION_CANCEL
            || actionMasked == MotionEvent.ACTION_HOVER_EXIT) {
        mCachedPoint.set(0, 0);
        return mCachedPoint;
    }

    return null;
}
 
Example 8
Source File: PatternLockView.java    From PatternLockView with Apache License 2.0 6 votes vote down vote up
@Override
public boolean onHoverEvent(MotionEvent event) {
    if (((AccessibilityManager) getContext().getSystemService(
            Context.ACCESSIBILITY_SERVICE)).isTouchExplorationEnabled()) {
        final int action = event.getAction();
        switch (action) {
            case MotionEvent.ACTION_HOVER_ENTER:
                event.setAction(MotionEvent.ACTION_DOWN);
                break;
            case MotionEvent.ACTION_HOVER_MOVE:
                event.setAction(MotionEvent.ACTION_MOVE);
                break;
            case MotionEvent.ACTION_HOVER_EXIT:
                event.setAction(MotionEvent.ACTION_UP);
                break;
        }
        onTouchEvent(event);
        event.setAction(action);
    }
    return super.onHoverEvent(event);
}
 
Example 9
Source File: GlowPadView.java    From CSipSimple with GNU General Public License v3.0 6 votes vote down vote up
@Override
public boolean onHoverEvent(MotionEvent event) {
    if (((AccessibilityManager) getContext().getSystemService(Context.ACCESSIBILITY_SERVICE)).isTouchExplorationEnabled()) {
        final int action = event.getAction();
        switch (action) {
            case MotionEvent.ACTION_HOVER_ENTER:
                event.setAction(MotionEvent.ACTION_DOWN);
                break;
            case MotionEvent.ACTION_HOVER_MOVE:
                event.setAction(MotionEvent.ACTION_MOVE);
                break;
            case MotionEvent.ACTION_HOVER_EXIT:
                event.setAction(MotionEvent.ACTION_UP);
                break;
        }
        onTouchEvent(event);
        event.setAction(action);
    }
    super.onHoverEvent(event);
    return true;
}
 
Example 10
Source File: ExploreByTouchHelper.java    From brailleback with Apache License 2.0 6 votes vote down vote up
/**
 * Dispatches hover {@link MotionEvent}s to the virtual view hierarchy when
 * the Explore by Touch feature is enabled.
 * <p>
 * This method should be called by overriding
 * {@link View#dispatchHoverEvent}:
 *
 * <pre>
 * &#64;Override
 * public boolean dispatchHoverEvent(MotionEvent event) {
 *   if (mHelper.dispatchHoverEvent(this, event) {
 *     return true;
 *   }
 *   return super.dispatchHoverEvent(event);
 * }
 * </pre>
 *
 * @param event The hover event to dispatch to the virtual view hierarchy.
 * @return Whether the hover event was handled.
 */
public boolean dispatchHoverEvent(MotionEvent event) {
    if (!mManager.isTouchExplorationEnabled()) {
        return false;
    }

    int virtualViewId = getVirtualViewIdAt(event.getX(), event.getY());
    if (virtualViewId == INVALID_ID) {
        virtualViewId = ROOT_ID;
    }

    switch (event.getAction()) {
        case MotionEvent.ACTION_HOVER_ENTER:
        case MotionEvent.ACTION_HOVER_MOVE:
            setHoveredVirtualViewId(virtualViewId);
            break;
        case MotionEvent.ACTION_HOVER_EXIT:
            setHoveredVirtualViewId(virtualViewId);
            break;
    }

    return true;
}
 
Example 11
Source File: TouchExplorationHelper.java    From DateTimepicker with Apache License 2.0 6 votes vote down vote up
@Override
public boolean onHover(View view, MotionEvent event) {
    if (!mManager.isTouchExplorationEnabled()) {
        return false;
    }

    switch (event.getAction()) {
        case MotionEvent.ACTION_HOVER_ENTER:
        case MotionEvent.ACTION_HOVER_MOVE:
            final T item = getItemAt(event.getX(), event.getY());
            setCurrentItem(item);
            return true;
        case MotionEvent.ACTION_HOVER_EXIT:
            setCurrentItem(null);
            return true;
    }

    return false;
}
 
Example 12
Source File: CompositorViewHolder.java    From AndroidChromium with Apache License 2.0 6 votes vote down vote up
private void setContentViewMotionEventOffsets(MotionEvent e, boolean canClear) {
    // TODO(dtrainor): Factor this out to LayoutDriver.
    if (e == null || mTabVisible == null) return;

    ContentViewCore contentViewCore = mTabVisible.getContentViewCore();
    if (contentViewCore == null) return;

    int actionMasked = e.getActionMasked();

    if (SPenSupport.isSPenSupported(getContext())) {
        actionMasked = SPenSupport.convertSPenEventAction(actionMasked);
    }

    if (actionMasked == MotionEvent.ACTION_DOWN
            || actionMasked == MotionEvent.ACTION_HOVER_ENTER) {
        if (mLayoutManager != null) mLayoutManager.getViewportPixel(mCacheViewport);
        contentViewCore.setCurrentTouchEventOffsets(-mCacheViewport.left, -mCacheViewport.top);
    } else if (canClear && (actionMasked == MotionEvent.ACTION_UP
                                   || actionMasked == MotionEvent.ACTION_CANCEL
                                   || actionMasked == MotionEvent.ACTION_HOVER_EXIT)) {
        contentViewCore.setCurrentTouchEventOffsets(0.f, 0.f);
    }
}
 
Example 13
Source File: UIButton.java    From FirefoxReality with Mozilla Public License 2.0 5 votes vote down vote up
@Override
public boolean onHoverEvent(MotionEvent event) {
    if (getTooltipText() != null) {
        if (event.getAction() == MotionEvent.ACTION_HOVER_ENTER) {
            postDelayed(mShowTooltipRunnable, mTooltipDelay);

        } else if (event.getAction() == MotionEvent.ACTION_HOVER_EXIT) {
            removeCallbacks(mShowTooltipRunnable);
            post(mHideTooltipRunnable);
        }
    }

    return super.onHoverEvent(event);
}
 
Example 14
Source File: CustomScrollView.java    From FirefoxReality with Mozilla Public License 2.0 5 votes vote down vote up
private boolean onHoverEventInternal(@NonNull MotionEvent event) {
    final int action = event.getActionMasked();
    switch (action) {
        case MotionEvent.ACTION_HOVER_ENTER:
        case MotionEvent.ACTION_HOVER_MOVE: {
            setHoveredThumb(true);
            return true;
        }
        case MotionEvent.ACTION_HOVER_EXIT: {
            setHoveredThumb(false);
            return true;
        }
    }
    return false;
}
 
Example 15
Source File: NumberPicker.java    From DateTimePicker with Apache License 2.0 4 votes vote down vote up
@Override
protected boolean dispatchHoverEvent(MotionEvent event) {
    if (!mHasSelectorWheel) {
        return super.dispatchHoverEvent(event);
    }
    AccessibilityManager accessibilityManager = (AccessibilityManager) getContext().getSystemService(Context.ACCESSIBILITY_SERVICE);
    //if (AccessibilityManager.getInstance(mContext).isEnabled()) {
    if (accessibilityManager != null && accessibilityManager.isEnabled()) {
        final int eventY = (int) event.getY();
        final int hoveredVirtualViewId;
        if (eventY < mTopSelectionDividerTop) {
            hoveredVirtualViewId = AccessibilityNodeProviderImpl.VIRTUAL_VIEW_ID_DECREMENT;
        } else if (eventY > mBottomSelectionDividerBottom) {
            hoveredVirtualViewId = AccessibilityNodeProviderImpl.VIRTUAL_VIEW_ID_INCREMENT;
        } else {
            hoveredVirtualViewId = AccessibilityNodeProviderImpl.VIRTUAL_VIEW_ID_INPUT;
        }
        final int action = event.getActionMasked();
        AccessibilityNodeProviderImpl provider =
                (AccessibilityNodeProviderImpl) getAccessibilityNodeProvider();
        switch (action) {
            case MotionEvent.ACTION_HOVER_ENTER: {
                provider.sendAccessibilityEventForVirtualView(hoveredVirtualViewId,
                        AccessibilityEvent.TYPE_VIEW_HOVER_ENTER);
                mLastHoveredChildVirtualViewId = hoveredVirtualViewId;
                provider.performAction(hoveredVirtualViewId,
                        AccessibilityNodeInfo.ACTION_ACCESSIBILITY_FOCUS, null);
            }
            break;
            case MotionEvent.ACTION_HOVER_MOVE: {
                if (mLastHoveredChildVirtualViewId != hoveredVirtualViewId
                        && mLastHoveredChildVirtualViewId != View.NO_ID) {
                    provider.sendAccessibilityEventForVirtualView(
                            mLastHoveredChildVirtualViewId,
                            AccessibilityEvent.TYPE_VIEW_HOVER_EXIT);
                    provider.sendAccessibilityEventForVirtualView(hoveredVirtualViewId,
                            AccessibilityEvent.TYPE_VIEW_HOVER_ENTER);
                    mLastHoveredChildVirtualViewId = hoveredVirtualViewId;
                    provider.performAction(hoveredVirtualViewId,
                            AccessibilityNodeInfo.ACTION_ACCESSIBILITY_FOCUS, null);
                }
            }
            break;
            case MotionEvent.ACTION_HOVER_EXIT: {
                provider.sendAccessibilityEventForVirtualView(hoveredVirtualViewId,
                        AccessibilityEvent.TYPE_VIEW_HOVER_EXIT);
                mLastHoveredChildVirtualViewId = View.NO_ID;
            }
            break;
        }
    }
    return false;
}
 
Example 16
Source File: NumberPicker.java    From zen4android with MIT License 4 votes vote down vote up
@Override
protected boolean dispatchHoverEvent(MotionEvent event) {
    if (!mHasSelectorWheel) {
        return super.dispatchHoverEvent(event);
    }

    if (((AccessibilityManager) getContext().getSystemService(Context.ACCESSIBILITY_SERVICE)).isEnabled()) {
        final int eventY = (int) event.getY();
        final int hoveredVirtualViewId;
        if (eventY < mTopSelectionDividerTop) {
            hoveredVirtualViewId = AccessibilityNodeProviderImpl.VIRTUAL_VIEW_ID_DECREMENT;
        } else if (eventY > mBottomSelectionDividerBottom) {
            hoveredVirtualViewId = AccessibilityNodeProviderImpl.VIRTUAL_VIEW_ID_INCREMENT;
        } else {
            hoveredVirtualViewId = AccessibilityNodeProviderImpl.VIRTUAL_VIEW_ID_INPUT;
        }
        final int action = event.getAction() & MotionEvent.ACTION_MASK;
        SupportAccessibilityNodeProvider provider = getSupportAccessibilityNodeProvider();

        switch (action) {
            case MotionEvent.ACTION_HOVER_ENTER: {
                provider.sendAccessibilityEventForVirtualView(hoveredVirtualViewId,
                        AccessibilityEvent.TYPE_VIEW_HOVER_ENTER);
                mLastHoveredChildVirtualViewId = hoveredVirtualViewId;
                provider.performAction(hoveredVirtualViewId,
                        AccessibilityNodeInfo.ACTION_ACCESSIBILITY_FOCUS, null);
            } break;
            case MotionEvent.ACTION_HOVER_MOVE: {
                if (mLastHoveredChildVirtualViewId != hoveredVirtualViewId
                        && mLastHoveredChildVirtualViewId != View.NO_ID) {
                    provider.sendAccessibilityEventForVirtualView(
                            mLastHoveredChildVirtualViewId,
                            AccessibilityEvent.TYPE_VIEW_HOVER_EXIT);
                    provider.sendAccessibilityEventForVirtualView(hoveredVirtualViewId,
                            AccessibilityEvent.TYPE_VIEW_HOVER_ENTER);
                    mLastHoveredChildVirtualViewId = hoveredVirtualViewId;
                    provider.performAction(hoveredVirtualViewId,
                            AccessibilityNodeInfo.ACTION_ACCESSIBILITY_FOCUS, null);
                }
            } break;
            case MotionEvent.ACTION_HOVER_EXIT: {
                provider.sendAccessibilityEventForVirtualView(hoveredVirtualViewId,
                        AccessibilityEvent.TYPE_VIEW_HOVER_EXIT);
                mLastHoveredChildVirtualViewId = View.NO_ID;
            } break;
        }
    }
    return false;
}
 
Example 17
Source File: NumberPicker.java    From ticdesign with Apache License 2.0 4 votes vote down vote up
@Override
protected boolean dispatchHoverEvent(MotionEvent event) {
    if (!mHasSelectorWheel) {
        return super.dispatchHoverEvent(event);
    }
    if (((AccessibilityManager) getContext().getSystemService(Context.ACCESSIBILITY_SERVICE)).isEnabled()) {
        final int eventY = (int) event.getY();
        final int hoveredVirtualViewId;
        if (eventY < mTopSelectionDividerTop) {
            hoveredVirtualViewId = AccessibilityNodeProviderImpl.VIRTUAL_VIEW_ID_DECREMENT;
        } else if (eventY > mBottomSelectionDividerBottom) {
            hoveredVirtualViewId = AccessibilityNodeProviderImpl.VIRTUAL_VIEW_ID_INCREMENT;
        } else {
            hoveredVirtualViewId = AccessibilityNodeProviderImpl.VIRTUAL_VIEW_ID_INPUT;
        }
        final int action = event.getActionMasked();
        AccessibilityNodeProviderImpl provider =
            (AccessibilityNodeProviderImpl) getAccessibilityNodeProvider();
        switch (action) {
            case MotionEvent.ACTION_HOVER_ENTER: {
                provider.sendAccessibilityEventForVirtualView(hoveredVirtualViewId,
                        AccessibilityEvent.TYPE_VIEW_HOVER_ENTER);
                mLastHoveredChildVirtualViewId = hoveredVirtualViewId;
                provider.performAction(hoveredVirtualViewId,
                        AccessibilityNodeInfo.ACTION_ACCESSIBILITY_FOCUS, null);
            } break;
            case MotionEvent.ACTION_HOVER_MOVE: {
                if (mLastHoveredChildVirtualViewId != hoveredVirtualViewId
                        && mLastHoveredChildVirtualViewId != View.NO_ID) {
                    provider.sendAccessibilityEventForVirtualView(
                            mLastHoveredChildVirtualViewId,
                            AccessibilityEvent.TYPE_VIEW_HOVER_EXIT);
                    provider.sendAccessibilityEventForVirtualView(hoveredVirtualViewId,
                            AccessibilityEvent.TYPE_VIEW_HOVER_ENTER);
                    mLastHoveredChildVirtualViewId = hoveredVirtualViewId;
                    provider.performAction(hoveredVirtualViewId,
                            AccessibilityNodeInfo.ACTION_ACCESSIBILITY_FOCUS, null);
                }
            } break;
            case MotionEvent.ACTION_HOVER_EXIT: {
                provider.sendAccessibilityEventForVirtualView(hoveredVirtualViewId,
                        AccessibilityEvent.TYPE_VIEW_HOVER_EXIT);
                mLastHoveredChildVirtualViewId = View.NO_ID;
            } break;
        }
    }
    return false;
}
 
Example 18
Source File: SuggestionStripView.java    From openboard with GNU General Public License v3.0 4 votes vote down vote up
@Override
public boolean onTouchEvent(final MotionEvent me) {
    if (!mMoreSuggestionsView.isShowingInParent()) {
        // Ignore any touch event while more suggestions panel hasn't been shown.
        // Detecting sliding up is done at {@link #onInterceptTouchEvent}.
        return true;
    }
    // In the sliding input mode. {@link MotionEvent} should be forwarded to
    // {@link MoreSuggestionsView}.
    final int index = me.getActionIndex();
    final int x = mMoreSuggestionsView.translateX((int)me.getX(index));
    final int y = mMoreSuggestionsView.translateY((int)me.getY(index));
    me.setLocation(x, y);
    if (!mNeedsToTransformTouchEventToHoverEvent) {
        mMoreSuggestionsView.onTouchEvent(me);
        return true;
    }
    // In sliding suggestion mode with accessibility mode on, a touch event should be
    // transformed to a hover event.
    final int width = mMoreSuggestionsView.getWidth();
    final int height = mMoreSuggestionsView.getHeight();
    final boolean onMoreSuggestions = (x >= 0 && x < width && y >= 0 && y < height);
    if (!onMoreSuggestions && !mIsDispatchingHoverEventToMoreSuggestions) {
        // Just drop this touch event because dispatching hover event isn't started yet and
        // the touch event isn't on {@link MoreSuggestionsView}.
        return true;
    }
    final int hoverAction;
    if (onMoreSuggestions && !mIsDispatchingHoverEventToMoreSuggestions) {
        // Transform this touch event to a hover enter event and start dispatching a hover
        // event to {@link MoreSuggestionsView}.
        mIsDispatchingHoverEventToMoreSuggestions = true;
        hoverAction = MotionEvent.ACTION_HOVER_ENTER;
    } else if (me.getActionMasked() == MotionEvent.ACTION_UP) {
        // Transform this touch event to a hover exit event and stop dispatching a hover event
        // after this.
        mIsDispatchingHoverEventToMoreSuggestions = false;
        mNeedsToTransformTouchEventToHoverEvent = false;
        hoverAction = MotionEvent.ACTION_HOVER_EXIT;
    } else {
        // Transform this touch event to a hover move event.
        hoverAction = MotionEvent.ACTION_HOVER_MOVE;
    }
    me.setAction(hoverAction);
    mMoreSuggestionsView.onHoverEvent(me);
    return true;
}
 
Example 19
Source File: MenuPopupWindow.java    From android_9.0.0_r45 with Apache License 2.0 4 votes vote down vote up
@Override
public boolean onHoverEvent(MotionEvent ev) {
    // Dispatch any changes in hovered item index to the listener.
    if (mHoverListener != null) {
        // The adapter may be wrapped. Adjust the index if necessary.
        final int headersCount;
        final MenuAdapter menuAdapter;
        final ListAdapter adapter = getAdapter();
        if (adapter instanceof HeaderViewListAdapter) {
            final HeaderViewListAdapter headerAdapter = (HeaderViewListAdapter) adapter;
            headersCount = headerAdapter.getHeadersCount();
            menuAdapter = (MenuAdapter) headerAdapter.getWrappedAdapter();
        } else {
            headersCount = 0;
            menuAdapter = (MenuAdapter) adapter;
        }

        // Find the menu item for the view at the event coordinates.
        MenuItem menuItem = null;
        if (ev.getAction() != MotionEvent.ACTION_HOVER_EXIT) {
            final int position = pointToPosition((int) ev.getX(), (int) ev.getY());
            if (position != INVALID_POSITION) {
                final int itemPosition = position - headersCount;
                if (itemPosition >= 0 && itemPosition < menuAdapter.getCount()) {
                    menuItem = menuAdapter.getItem(itemPosition);
                }
            }
        }

        final MenuItem oldMenuItem = mHoveredMenuItem;
        if (oldMenuItem != menuItem) {
            final MenuBuilder menu = menuAdapter.getAdapterMenu();
            if (oldMenuItem != null) {
                mHoverListener.onItemHoverExit(menu, oldMenuItem);
            }

            mHoveredMenuItem = menuItem;

            if (menuItem != null) {
                mHoverListener.onItemHoverEnter(menu, menuItem);
            }
        }
    }

    return super.onHoverEvent(ev);
}
 
Example 20
Source File: AccessibilityUtils.java    From AOSP-Kayboard-7.1.2 with Apache License 2.0 3 votes vote down vote up
/**
 * Returns {@true} if the provided event is a touch exploration (e.g. hover)
 * event. This is used to determine whether the event should be processed by
 * the touch exploration code within the keyboard.
 *
 * @param event The event to check.
 * @return {@true} is the event is a touch exploration event
 */
public static boolean isTouchExplorationEvent(final MotionEvent event) {
    final int action = event.getAction();
    return action == MotionEvent.ACTION_HOVER_ENTER
            || action == MotionEvent.ACTION_HOVER_EXIT
            || action == MotionEvent.ACTION_HOVER_MOVE;
}